diff options
Diffstat (limited to 'sidebar')
-rw-r--r-- | sidebar/Makefile.am | 17 | ||||
l--------- | sidebar/baghiralinkdrag.cpp | 1 | ||||
l--------- | sidebar/baghiralinkdrag.h | 1 | ||||
-rw-r--r-- | sidebar/baghirasidebar.cpp | 68 | ||||
-rw-r--r-- | sidebar/baghirasidebar.desktop | 12 | ||||
-rw-r--r-- | sidebar/baghirasidebar.h | 50 | ||||
-rw-r--r-- | sidebar/baghirasidebar_add.desktop | 10 | ||||
-rw-r--r-- | sidebar/baghirasidebariface.h | 35 | ||||
-rw-r--r-- | sidebar/configure.in.in | 2 | ||||
-rw-r--r-- | sidebar/dndlistbox.cpp | 685 | ||||
-rw-r--r-- | sidebar/dndlistbox.h | 126 | ||||
-rw-r--r-- | sidebar/eject.xbm | 9 | ||||
-rw-r--r-- | sidebar/linkconfig.ui | 187 | ||||
-rw-r--r-- | sidebar/linkview.cpp | 199 | ||||
-rw-r--r-- | sidebar/linkview.h | 46 | ||||
-rw-r--r-- | sidebar/listboxlink.cpp | 78 | ||||
-rw-r--r-- | sidebar/listboxlink.h | 64 | ||||
-rw-r--r-- | sidebar/lock.xbm | 9 |
18 files changed, 1599 insertions, 0 deletions
diff --git a/sidebar/Makefile.am b/sidebar/Makefile.am new file mode 100644 index 0000000..779e77d --- /dev/null +++ b/sidebar/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES= $(all_includes) +METASOURCES = AUTO + +kde_module_LTLIBRARIES=konqsidebar_baghirasidebar.la +include_HEADERS = baghirasidebar.h linkview.h listboxlink.h dndlistbox.h baghirasidebariface.h +noinst_HEADERS = baghiralinkdrag.h baghirasidebar.h linkview.h listboxlink.h dndlistbox.h baghirasidebariface.h + +konqsidebar_baghirasidebar_la_SOURCES = baghiralinkdrag.cpp baghirasidebar.cpp linkview.cpp listboxlink.cpp dndlistbox.cpp linkconfig.ui baghirasidebariface.skel +konqsidebar_baghirasidebar_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -lkonqsidebarplugin +konqsidebar_baghirasidebar_la_LIBADD = $(LIB_KPARTS) $(LIB_KFILE) + +baghirasidebar_entry_DATA = baghirasidebar.desktop +baghirasidebar_entrydir = $(kde_datadir)/konqsidebartng/entries +baghirasidebar_add_DATA = baghirasidebar_add.desktop +baghirasidebar_adddir = $(kde_datadir)/konqsidebartng/add +poof_DATA = ../imagebase/poof.png +poofdir = $(kde_datadir)/baghira diff --git a/sidebar/baghiralinkdrag.cpp b/sidebar/baghiralinkdrag.cpp new file mode 120000 index 0000000..4997e26 --- /dev/null +++ b/sidebar/baghiralinkdrag.cpp @@ -0,0 +1 @@ +../starter/baghiralinkdrag.cpp
\ No newline at end of file diff --git a/sidebar/baghiralinkdrag.h b/sidebar/baghiralinkdrag.h new file mode 120000 index 0000000..20f50f7 --- /dev/null +++ b/sidebar/baghiralinkdrag.h @@ -0,0 +1 @@ +../starter/baghiralinkdrag.h
\ No newline at end of file diff --git a/sidebar/baghirasidebar.cpp b/sidebar/baghirasidebar.cpp new file mode 100644 index 0000000..0969bad --- /dev/null +++ b/sidebar/baghirasidebar.cpp @@ -0,0 +1,68 @@ + +#include <kinstance.h> +#include <qsplitter.h> +#include <kiconloader.h> +#include <stdlib.h> +#include "dndlistbox.h" +#include "listboxlink.h" +#include "linkview.h" +#include "baghirasidebar.h" +#include "baghirasidebar.moc" + +baghiraSidebar::baghiraSidebar(KInstance *inst,QObject *parent,QWidget *widgetParent, QString &desktopName, const char* name): + KonqSidebarPlugin(inst,parent,widgetParent,desktopName,name) +{ + scrollView = new LinkView(widgetParent); + scrollView->setHScrollBarMode(QScrollView::AlwaysOff); + connect (scrollView->Hardware(), SIGNAL(clicked(QListBoxItem *)), this, SLOT(callURL(QListBoxItem *))); + connect (scrollView->Locations(), SIGNAL(clicked(QListBoxItem *)), this, SLOT(callURL(QListBoxItem *))); +} + +baghiraSidebar::~baghiraSidebar() +{ +} + +void baghiraSidebar::callURL(QListBoxItem *item) +{ + emit openURLRequest(KURL(((ListBoxLink*)(item))->URL()), KParts::URLArgs(true,0,0)); +} + +void baghiraSidebar::handleURL(const KURL &url) +{ + int item = scrollView->Hardware()->currentItem(); + if ( scrollView->Hardware()->isSelected(item) && + KURL(((ListBoxLink*)(scrollView->Hardware()->item(item)))->URL()).url() != url.url() ) + { + scrollView->Hardware()->setSelected(item, FALSE); + return; + } + item = scrollView->Locations()->KListBox::currentItem(); + if (scrollView->Locations()->isSelected(item) && + KURL(((ListBoxLink*)(scrollView->Locations()->item(item)))->URL()).url() != url.url() ) + { + scrollView->Locations()->setSelected(item, FALSE); + return; + } +} + +extern "C" { + KDE_EXPORT bool add_konqsidebar_baghirasidebar(QString* fn, QString* param, QMap<QString,QString> *map) { + Q_UNUSED(param); + + map->insert("Type", "Link"); + map->insert("Icon", "bab_brushed"); + map->insert("Name", "Baghira Sidebar"); + map->insert("Open", "true"); + map->insert("X-KDE-KonqSidebarModule","konqsidebar_baghirasidebar"); + fn->setLatin1("baghirasidebar%1.desktop"); + return true; + } +} + +extern "C" +{ + void* create_konqsidebar_baghirasidebar(KInstance *instance,QObject *par,QWidget *widp,QString &desktopname,const char *name) + { + return new baghiraSidebar(instance,par,widp,desktopname,name); + } +}; diff --git a/sidebar/baghirasidebar.desktop b/sidebar/baghirasidebar.desktop new file mode 100644 index 0000000..ba6b560 --- /dev/null +++ b/sidebar/baghirasidebar.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Link +URL= +Icon=bab_brushed +Comment=Baghira Sidebar +Name=baghirasidebar +Name[xx]=xxbaghirasidebarxx + +Open=false +X-KDE-KonqSidebarModule=konqsidebar_baghirasidebar + diff --git a/sidebar/baghirasidebar.h b/sidebar/baghirasidebar.h new file mode 100644 index 0000000..dae8fc5 --- /dev/null +++ b/sidebar/baghirasidebar.h @@ -0,0 +1,50 @@ + +#ifndef BAGHIRASIDEBAR_H +#define BAGHIRASIDEBAR_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <konqsidebarplugin.h> +#include <kconfig.h> + +class LinkView; +class KListBox; +class QListBoxItem; + +class baghiraSidebar : public KonqSidebarPlugin +{ + Q_OBJECT + +public: + /** + * Construct a @ref KonqSidebarPlugin. + * + * @param inst The sidebar's kinstance class. + * @param parent The sidebar internal button info class responsible for this plugin. + * @param widgetParent The container which will contain the plugins widget. + * @param desktopName The filename of the configuration file. + * @param name A Qt object name for your plugin. + **/ + baghiraSidebar(KInstance *inst,QObject *parent, QWidget *widgetParent, QString &desktopName, const char* name=0); + + /** destructor */ + ~baghiraSidebar(); + + virtual QWidget *getWidget(){return scrollView;} + virtual void *provides(const QString &) {return 0;} + +protected: + LinkView *scrollView; + virtual void handleURL(const KURL &url); + +private slots: + void callURL(QListBoxItem *); + +signals: + void openURLRequest(const KURL &url, const KParts::URLArgs &args); + +}; + +#endif diff --git a/sidebar/baghirasidebar_add.desktop b/sidebar/baghirasidebar_add.desktop new file mode 100644 index 0000000..634b658 --- /dev/null +++ b/sidebar/baghirasidebar_add.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Comment=Baghira Sidebar +Encoding=UTF-8 +Icon=filetypes +Name=Add Baghira Sidebar +Name[de]=Baghira Sideabr hinzufügen +Open=false +Type=Link +URL= +X-KDE-KonqSidebarAddModule=konqsidebar_baghirasidebar diff --git a/sidebar/baghirasidebariface.h b/sidebar/baghirasidebariface.h new file mode 100644 index 0000000..c5e160d --- /dev/null +++ b/sidebar/baghirasidebariface.h @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright (C) 2005 by Thomas Lübking * + * thomas.luebking@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _BAGHIRASIDEBARIFACE_H_ +#define _BAGHIRASIDEBARIFACE_H_ + +#include <dcopobject.h> + +class BaghiraSidebarIface : virtual public DCOPObject +{ + K_DCOP + k_dcop: + virtual void mediumAdded(const QString &name) = 0; + virtual void mediumRemoved(const QString &name) = 0; + virtual void mediumChanged(const QString &name) = 0; +}; + +#endif diff --git a/sidebar/configure.in.in b/sidebar/configure.in.in new file mode 100644 index 0000000..72f8843 --- /dev/null +++ b/sidebar/configure.in.in @@ -0,0 +1,2 @@ +AM_CONDITIONAL( HAVE_3_4, test $(kde-config --version | grep "KDE:" | cut -d" " -f2 | cut -d"." -f2) -gt 3 ) + diff --git a/sidebar/dndlistbox.cpp b/sidebar/dndlistbox.cpp new file mode 100644 index 0000000..8fe78cf --- /dev/null +++ b/sidebar/dndlistbox.cpp @@ -0,0 +1,685 @@ + +#include <dcopclient.h> +#include <qdragobject.h> +#include <kurl.h> +#include <qstrlist.h> +#include <qtimer.h> +#include <kapplication.h> +#include <klocale.h> +#include <kfileitem.h> +#include <kpopupmenu.h> +#include <kicondialog.h> +#include <kiconloader.h> +#include <klineedit.h> +#include <kprocess.h> +#include <kurlrequester.h> +#include <kstandarddirs.h> +#include <kwin.h> +#include <qclipboard.h> +#include "listboxlink.h" +#include "linkconfig.h" +#include "dndlistbox.h" +#include "baghiralinkdrag.h" +#include "dndlistbox.moc" + +#define ID 0 +#define NAME 1 +#define LABEL 2 +#define USER_LABEL 3 +#define MOUNTABLE 4 +#define DEVICE_NODE 5 +#define MOUNT_POINT 6 +#define FS_TYPE 7 +#define MOUNTED 8 +#define BASE_URL 9 +#define MIME_TYPE 10 +#define ICON_NAME 11 +#define MEDIA_PROPS 12 +#define MEDIALIST_PROPS 13 + +ResizingLinkBox::ResizingLinkBox( QWidget * parent, const char * name, WFlags f ) : KListBox( parent, name, f) +{ + KConfig config(QDir::homeDirPath() + "/.qt/baghirarc"); + config.setGroup("Sidebar"); + size_ = config.readNumEntry (QString(name) + "_IconSize", 48); + popupMenu = new KPopupMenu; + popupMenu->insertTitle (i18n("Icon Size"),122,122); + popupMenu->insertItem("16x16", this, SLOT(setIconSize(int)),0,16,123); + popupMenu->insertItem("22x22", this, SLOT(setIconSize(int)),0,22,124); + popupMenu->insertItem("32x32", this, SLOT(setIconSize(int)),0,32,125); + popupMenu->insertItem("48x48", this, SLOT(setIconSize(int)),0,48,126); + popupMenu->insertItem("64x64", this, SLOT(setIconSize(int)),0,64,127); + popupMenu->insertItem("128x128", this, SLOT(setIconSize(int)),0,128,128); +} + +void ResizingLinkBox::insertItem( const QListBoxItem *lbi, int index ) +{ + KListBox::insertItem( lbi, index ); + if (height() <= numRows()*itemHeight()) + emit itemNumberChanged(TRUE); +} + +void ResizingLinkBox::insertItem( const QListBoxItem *lbi, const QListBoxItem *after ) +{ + KListBox::insertItem( lbi, after ); + if (height() <= numRows()*itemHeight()) + emit itemNumberChanged(TRUE); +} + + +void ResizingLinkBox::insertItem( const QString & icon, const QString & title, const QString & url ) +{ + insertItem( new ListBoxLink(icon, size_, title, url ) ); +} + +void ResizingLinkBox::removeItem( int index ) +{ + blockSignals ( true ); + KListBox::removeItem(index); + blockSignals ( false ); + emit itemNumberChanged(FALSE); +} + +void ResizingLinkBox::setIconSize(int size) +{ + size_ = size; + KConfig *config = new KConfig(QDir::homeDirPath() + "/.qt/baghirarc"); + config->setGroup("Sidebar"); + config->writeEntry (QString(name()) + "_IconSize", size); + config->sync(); + ListBoxLink *runner; + ListBoxDevice *current; + blockSignals ( true ); + for (uint i = 0; i < count(); i++) + { + runner = (ListBoxLink*)item(i); + if (dynamic_cast<ListBoxDevice*>(runner)) + { + current = (ListBoxDevice*)runner; + insertItem( new ListBoxDevice(current->icon(), size, current->text(), current->URL(), current->name(), current->mountPoint(), current->mounted(), current->ejectable(), current->removable(), current->id()), i ); + } + else + { + insertItem( new ListBoxLink(runner->icon(), size, runner->text(), runner->URL()), i ); + } + KListBox::removeItem(i+1); + } + blockSignals ( false ); +} + +void ResizingLinkBox::mousePressEvent ( QMouseEvent *mpe ) +{ + KListBox::mousePressEvent( mpe ); +} + +void ResizingLinkBox::mouseReleaseEvent ( QMouseEvent *mpe ) +{ + if (mpe->button() == Qt::LeftButton) + { + ListBoxLink *link = (ListBoxLink*)itemAt(mpe->pos()); + if (isSelected(link)) emit clicked(link); + KListBox::mousePressEvent( mpe ); + return; + } + KListBox::mouseReleaseEvent( mpe ); +} + +void ResizingLinkBox::contentsWheelEvent ( QWheelEvent * we ) +{ + if (we->state() == Qt::ControlButton) + KListBox::contentsWheelEvent ( we ); + else + emit scrolled(0, -we->delta()); +} + +MediaListBox::MediaListBox( QWidget * parent, const char * name, WFlags f ) : ResizingLinkBox(parent, name, f), DCOPObject("BaghiraSidebarIface") +{ + KConfig config(QDir::homeDirPath() + "/.qt/baghirarc"); + config.setGroup("Sidebar"); + hiddenDevices = config.readListEntry("HiddenDevices"); + currentFloppy = 0L; + devicePopup = new KPopupMenu(this); + devicePopup->setCheckable ( true ); + popupMenu->insertItem(i18n("Device List"), devicePopup, 1, 0); + popupMenu->insertSeparator( 0 ); + +#if KDE_IS_VERSION(3,4,90) + insertItem(new ListBoxDevice("system", size_, i18n("My Computer"), "system:/", "", "", TRUE, FALSE, FALSE)); + insertItem(new ListBoxDevice("network", size_, i18n("Network"), "remote:/", "", "", TRUE, FALSE, FALSE)); +#else + insertItem(new ListBoxDevice("system", size_, i18n("My Computer"), "media:/", "", "", TRUE, FALSE, FALSE)); + insertItem(new ListBoxDevice("network", size_, i18n("Network"), "lan:/localhost", "", "", TRUE, FALSE, FALSE)); +#endif + insertItem(new ListBoxDevice("hdd_mount", size_, i18n("Startvolume"), QDir::rootDirPath(), "", "", TRUE, FALSE, FALSE)); + client = KApplication::dcopClient(); + client->connectDCOPSignal("kded", "mediamanager", "mediumAdded(QString)", "BaghiraSidebarIface", "mediumAdded(QString)", FALSE); + client->connectDCOPSignal("kded", "mediamanager", "mediumRemoved(QString)", "BaghiraSidebarIface", "mediumRemoved(const QString)", FALSE); + client->connectDCOPSignal("kded", "mediamanager", "mediumChanged(QString)", "BaghiraSidebarIface", "mediumChanged(QString)", FALSE); + /* Get the media info - huhhh ;) */ + QByteArray data, replyData; + QCString replyType; + QDataStream arg(data, IO_WriteOnly); + arg << ""; // ask for the full list + if (!client->call("kded", "mediamanager", "fullList()", data, replyType, replyData)) + qDebug("there was some error using DCOP."); + else + { + QDataStream reply(replyData, IO_ReadOnly); + if (replyType == "QStringList") + { + QStringList result; + reply >> result; + blockSignals ( true ); + for (uint i = 0; i < result.size()/MEDIALIST_PROPS; i++) + { + if (result[MEDIALIST_PROPS*i+MIME_TYPE] != "media/hdd_mounted" && + result[MEDIALIST_PROPS*i+MIME_TYPE] != "media/hdd_unmounted" && + result[MEDIALIST_PROPS*i+MIME_TYPE] != "media/nfs_mounted" && + result[MEDIALIST_PROPS*i+MIME_TYPE] != "media/nfs_unmounted" && + result[MEDIALIST_PROPS*i+MIME_TYPE] != "media/smb_mounted" && + result[MEDIALIST_PROPS*i+MIME_TYPE] != "media/smb_unmounted") + { + ListBoxDevice *dev = createListBoxDevice(result, i); + if (hiddenDevices.contains(dev->name())) + { + deviceList.append(dev); + devicePopup->setItemChecked(dev->id(),false); + } + else + { + insertItem(dev); + devicePopup->setItemChecked(dev->id(),true); + } + } + } + blockSignals ( false ); + } + else + qWarning("fullList() returned an unexpected type of reply!"); + } +// setCurrentItem( 0 ); +} + +MediaListBox::~MediaListBox() +{ + hiddenDevices.clear(); + ListBoxDevice *runner; + for ( runner = deviceList.first(); runner; runner = deviceList.next() ) + hiddenDevices.append(runner->name()); + KConfig config(QDir::homeDirPath() + "/.qt/baghirarc"); + config.setGroup("Sidebar"); + config.writeEntry("HiddenDevices", hiddenDevices); +} + +void MediaListBox::removeItem( int index ) +{ + devicePopup->removeItem(((ListBoxDevice*)item( index ))->id()); + ResizingLinkBox::removeItem(index); +} + +void MediaListBox::kfloppy() +{ + if (currentFloppy) + { + KProcess proc; + proc << "kfloppy" << currentFloppy->mountPoint(); + proc.start(KProcess::DontCare); + proc.detach(); + currentFloppy = 0L; + } + return; +} + +void MediaListBox::toggleDevice(int id) +{ + ListBoxDevice *runner; + if (devicePopup->isItemChecked(id)) // remove the device! + { + devicePopup->setItemChecked(id, false); + for (uint i = 0; i < count(); i++) + { + runner = (ListBoxDevice*)item(i); + if (runner->id() == id) + { + deviceList.append(runner); + blockSignals ( true ); + takeItem(runner); + blockSignals ( false ); + break; + } + } + } + else // add the device! + { + devicePopup->setItemChecked(id, true); + for ( runner = deviceList.first(); runner; runner = deviceList.next() ) + if (runner->id() == id) + { + insertItem(deviceList.take()); + break; + } + } +} + +ListBoxDevice *MediaListBox::createListBoxDevice(QStringList & deviceProperties, uint n) +{ + QString icon; + icon = deviceProperties[MEDIALIST_PROPS*n+ICON_NAME]; + if (icon.isNull()) + { + icon = deviceProperties[MEDIALIST_PROPS*n+MIME_TYPE]; + icon = icon.section( '/', -1 ); + icon.truncate( icon.length()-2 ); + if (icon.contains("floppy")) icon.prepend("3"); + } + QString label; + label = deviceProperties[MEDIALIST_PROPS*n+USER_LABEL]; + if (label.isNull()) + { + label = deviceProperties[MEDIALIST_PROPS*n+LABEL]; + label = i18n(label.section( " (", 0, 0 ).utf8()); + } +#if KDE_IS_VERSION(3,4,90) + return new ListBoxDevice( icon, size_, label, "system:/media/"+deviceProperties[MEDIALIST_PROPS*n+NAME], deviceProperties[MEDIALIST_PROPS*n+NAME], deviceProperties[MEDIALIST_PROPS*n+DEVICE_NODE], deviceProperties[MEDIALIST_PROPS*n+MOUNTED] == "true", icon.contains("dvd") || icon.contains("cdrom") || icon.contains("cdwriter"),icon.contains("floppy"), devicePopup->insertItem(deviceProperties[MEDIALIST_PROPS*n+NAME], this, SLOT(toggleDevice(int)))); +#else + return new ListBoxDevice( icon, size_, label, "media:/"+deviceProperties[MEDIALIST_PROPS*n+NAME], deviceProperties[MEDIALIST_PROPS*n+NAME], deviceProperties[MEDIALIST_PROPS*n+DEVICE_NODE], deviceProperties[MEDIALIST_PROPS*n+MOUNTED] == "true", icon.contains("dvd") || icon.contains("cdrom") || icon.contains("cdwriter"),icon.contains("floppy"),devicePopup->insertItem(deviceProperties[MEDIALIST_PROPS*n+NAME], this, SLOT(toggleDevice(int)))); +#endif +} + +int MediaListBox::index (const QString & name ) +{ + ListBoxDevice *device; + for (uint i = 0; i < count(); i++) + { + device = (ListBoxDevice*)item(i); + if (device && device->name() == name) return i; + } + return -1; +} + +void MediaListBox::mediumAdded(const QString &name) +{ + QByteArray data, replyData; + QCString replyType; + QDataStream arg(data, IO_WriteOnly); + arg << name; // ask for this item only + if (!client->call("kded", "mediamanager", "properties(QString)", data, replyType, replyData)) + qDebug("there was some error using DCOP."); + else + { + QDataStream reply(replyData, IO_ReadOnly); + if (replyType == "QStringList") + { + QStringList result; + reply >> result; + ListBoxDevice *dev = createListBoxDevice(result); + if (hiddenDevices.contains(dev->name())) + { + deviceList.append(dev); + devicePopup->setItemChecked(dev->id(),false); + } + else + { + insertItem(dev); + devicePopup->setItemChecked(dev->id(),true); + } + } + else + qWarning("properties() returned an unexpected type of reply!"); + } +} + +void MediaListBox::mediumRemoved(const QString &name) +{ + QByteArray data, replyData; + QCString replyType; + QDataStream arg(data, IO_WriteOnly); + arg << name; // ask for this item only + if (!client->call("kded", "mediamanager", "properties(QString)", data, replyType, replyData)) + qDebug("there was some error using DCOP."); + else + { + QDataStream reply(replyData, IO_ReadOnly); + if (replyType == "QStringList") + { + QStringList result; + reply >> result; + int i = index(name); + if (i<0) + return; + if (i == currentItem()) setCurrentItem(0); + removeItem(i); + } + else + qWarning("properties() returned an unexpected type of reply!"); + } +} + +void MediaListBox::mediumChanged(const QString &name) +{ + QByteArray data, replyData; + QCString replyType; + QDataStream arg(data, IO_WriteOnly); + arg << name; // ask for this item only + if (!client->call("kded", "mediamanager", "properties(QString)", data, replyType, replyData)) + qDebug("there was some error using DCOP."); + else + { + QDataStream reply(replyData, IO_ReadOnly); + if (replyType == "QStringList") + { + QStringList result; + reply >> result; + int i = index(name); + if (i<0) + return; + + ListBoxDevice *device = createListBoxDevice(result); + if (hiddenDevices.contains(device->name())) + { + deviceList.append(device); + devicePopup->setItemChecked(device->id(),false); + return; + } + devicePopup->setItemChecked(device->id(),true); + blockSignals(true); + if (i == currentItem()) // changing current item - take some care of updating stuff + { + if (((ListBoxDevice*)item(i))->mounted() && !device->mounted()) // unmounted the device - we certainly do not wanna select it anymore + { + setCurrentItem(0); + removeItem(i); + insertItem(device, i); + } + else // we're selected and wanna keep selection + { + removeItem(i); + insertItem(device, i); + setSelected( i, true ); + } + } + else // ordinary change + { + removeItem(i); + insertItem(device, i); + } + blockSignals(false); + } + else + qWarning("properties() returned an unexpected type of reply!"); + } +} + +#define _FLOPPYID_ 0 +#define _FLOPPYINDEX_ 0 + +void MediaListBox::mousePressEvent ( QMouseEvent *mpe ) +{ + if (mpe->button() == Qt::RightButton) + { + popupMenu->removeItem(_FLOPPYID_); + ListBoxDevice *device = (ListBoxDevice*)itemAt(mpe->pos()); + if (device && device->name().contains("fd")) + { + currentFloppy = device; + popupMenu->insertItem(i18n("Format disk..."), this, SLOT(kfloppy()),0,_FLOPPYID_,_FLOPPYINDEX_); + } + popupMenu->popup(mpe->globalPos()); + return; + } + if (mpe->button() == Qt::LeftButton && mpe->x() > width()-22) + { + ListBoxDevice *device = (ListBoxDevice*)itemAt(mpe->pos()); + int dy = itemRect(device).y(); + if ((device->removable() || device->ejectable()) && device->mounted() && mpe->y() > dy+11 && mpe->y() < dy+33) + { + KProcess proc; + device->ejectable()? + proc << "kdeeject" /*<< "-q"*/ << device->mountPoint(): + proc << "umount" << device->mountPoint(); // umount? + proc.start(KProcess::DontCare); + proc.detach(); + return; + } + } + ResizingLinkBox::mousePressEvent( mpe ); +} + +void MediaListBox::resizeEvent ( QResizeEvent * re) +{ + if (width() != re->oldSize().width()) + { + for (uint i = 0; i < count(); i++) + if (((ListBoxDevice*)item(i))->ejectable() && ((ListBoxDevice*)item(i))->mounted() && !isSelected(i)) updateItem(i); + } + ResizingLinkBox::resizeEvent(re); +} + +DnDListBox::DnDListBox( QWidget * parent, const char * name, WFlags f ): +ResizingLinkBox( parent, name, f), _poof(0), _poofIndex(0), _poofAnimPix(0), _poofPix(0) +{ + setAcceptDrops(true); + dialog = new LinkConfig(); + connect(dialog->buttonOk, SIGNAL(clicked()), this, SLOT(updateLink())); + setCursor(Qt::PointingHandCursor); +} + +DnDListBox::~DnDListBox() +{ +} + +void DnDListBox::poof(ListBoxLink *link) +{ + _poofIndex = 0; + _poofPix = new QPixmap(locateLocal("data", "baghira/poof.png"), "png"); + _poofAnimPix = new QPixmap(_poofPix->width(), _poofPix->width()); + if (!_poof) + _poof = new QWidget(0,0, Qt::WType_TopLevel | Qt::WStyle_NoBorder | Qt::WStyle_StaysOnTop | Qt::WX11BypassWM); + KWin::setShadowSize(_poof->winId(), 0); + _poof->setFixedSize(_poofPix->width(), _poofPix->width()); + int x = QCursor::pos().x() - _poof->width()/2; + int y = QCursor::pos().y() - _poof->height()/2; + QPixmap bgPix = QPixmap::grabWindow( qt_xrootwin(), x, y, _poofPix->width(), _poofPix->width()); + _poof->move(x,y); + _poof->show(); + _poof->setBackgroundOrigin(QWidget::WidgetOrigin); + _poof->setPaletteBackgroundPixmap( bgPix ); + runPoof(); + removeItem ( index(link) ); +} + +void DnDListBox::runPoof() +{ + if (_poofIndex > 4) + { + _poof->hide(); + delete _poofPix; + _poofPix = 0L; +// delete _poof; +// _poof = 0L; + delete _poofAnimPix; + _poofAnimPix = 0L; + _poofIndex = 0; + return; + } + _poof->erase(); + bitBlt(_poof, 0 ,0, _poofPix, 0, _poofIndex * _poofPix->width(), _poofPix->width(), _poofPix->width(), Qt::AndROP); + ++_poofIndex; + QTimer::singleShot ( 70, this, SLOT(runPoof()) ); // around 15 fps +} + +void DnDListBox::dragEnterEvent ( QDragEnterEvent *dee ) +{ +// dragging_ = true; + if (QUriDrag::canDecode(dee) || BaghiraLinkDrag::canDecode(dee) || QTextDrag::canDecode(dee)) + dee->accept(true); +} + +void DnDListBox::dropEvent ( QDropEvent *de ) +{ + QStrList list; + QString title; + QString command; + QString icon; + int oldIndex; + QCString subtype; + if (BaghiraLinkDrag::decode(de, &title, &command, &icon, &oldIndex)) // internal move + { + BaghiraLinkDrag::setAccepted(); + QListBoxItem *after = itemAt(de->pos()); + int newIndex = index(after); + if (!dragging_ || oldIndex < 0 || oldIndex > count()-2) + insertItem (new ListBoxLink(icon, size_, title, command), after?newIndex:count()); + else if (oldIndex != newIndex) + { + insertItem (new ListBoxLink(*((ListBoxLink*)item(oldIndex))), after?newIndex:count()); + removeItem ( (newIndex < 0 || oldIndex < newIndex) ? oldIndex : oldIndex + 1 ); + } + } + else if ( QUriDrag::decode(de, list) ) + { + char *uri; + KURL url; + QListBoxItem *after = itemAt(de->pos()); + for ( uri = list.first(); uri; uri = list.next() ) + { + url = KURL(uri); + if (url.protocol() == "http") + insertItem(new ListBoxLink("html", size_, url.host()+(url.path()=="/"?QString(""):url.path()), uri), after?index(after):count()); + else + { + KFileItem item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url, true); + insertItem(new ListBoxLink(item.iconName(), size_, url.fileName().isEmpty()?url.prettyURL():url.fileName(), uri), after?index(after):count()); + } + } + } + else if (QTextDrag::decode(de, command, subtype)) + { + KURL url(command); + if (url.isValid()) + { + QListBoxItem *after = itemAt(de->pos()); + if (url.protocol() == "http") + insertItem(new ListBoxLink("html", size_, url.host()+(url.path()=="/"?QString(""):url.path()), command), after?index(after):count()); + else + { + KFileItem item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url, true); + insertItem(new ListBoxLink(item.iconName(), size_, url.fileName().isEmpty()?url.prettyURL():url.fileName(), command), after?index(after):count()); + } + } + else if (command.contains('@')) + { + QListBoxItem *after = itemAt(de->pos()); + command.replace(" ",""); + insertItem(new ListBoxLink("kmail", size_, command, "mailto:"+command), after?index(after):count()); + } + else if (command.contains("'at'")) //last chance for anti-spam addy + { + QListBoxItem *after = itemAt(de->pos()); + command.replace(" ",""); + command.replace("'at'","@"); + insertItem(new ListBoxLink("kmail", size_, command, "mailto:"+command), after?index(after):count()); + } + } +} + +void DnDListBox::mousePressEvent ( QMouseEvent *mpe ) +{ + if (mpe->button() == Qt::RightButton) + { + currentItem = 0; + popupMenu->removeItem(0); + ListBoxDevice *device = (ListBoxDevice*)itemAt(mpe->pos()); + if (device) + { + currentItem = device; + popupMenu->insertItem("Edit link...", this, SLOT(configureLink()),0,0,0); + } + popupMenu->popup(mpe->globalPos()); + return; + } + if (mpe->button() == Qt::MidButton) + { + pasteURL(QClipboard::Selection, itemAt(mpe->pos())); + return; + } + ResizingLinkBox::mousePressEvent( mpe ); +} + +void DnDListBox::mouseReleaseEvent ( QMouseEvent *mre ) +{ + if (!dragging_) ResizingLinkBox::mouseReleaseEvent( mre ); +} + +void DnDListBox::mouseMoveEvent ( QMouseEvent * mme ) +{ + if (mme->state() & Qt::LeftButton) + { + if (!dragging_) + { + ListBoxLink *link = (ListBoxLink*)itemAt(mme->pos()); + if (link) + { + dragging_ = true; + BaghiraLinkDrag *d = new BaghiraLinkDrag( link->text(), link->URL(), link->icon(), index(link), this ); + d->setPixmap(*link->pixmap(),QPoint(22,22)); + d->drag(); + if (mme->state() & Qt::ControlButton || BaghiraLinkDrag::accepted()) + return; + poof(link); + // do NOT delete d. + } + } + } + else // ensure to release from drag + dragging_ = false; +} + +void DnDListBox::pasteURL(int mode, QListBoxItem *after) +{ + QString string = qApp->clipboard()->text( (QClipboard::Mode)mode ); + KURL url(string); + if (url.isValid()) + { + if (url.protocol() == "http") + insertItem(new ListBoxLink("html", size_, url.host()+(url.path()=="/"?QString(""):url.path()), string), after?index(after):count()); + else + { + KFileItem item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url, true); + insertItem(new ListBoxLink(item.iconName(),size_, url.fileName().isEmpty()?url.prettyURL():url.fileName(), string), after?index(after):count()); + } + } + else if (string.contains('@')) + { + string.replace(" ",""); + insertItem(new ListBoxLink("kmail", size_, string, "mailto:"+string), after?index(after):count()); + } + else if (string.contains("'at'")) //last chance for anti-spam addy + { + string.replace(" ",""); + string.replace("'at'","@"); + insertItem(new ListBoxLink("kmail", size_, string, "mailto:"+string), after?index(after):count()); + } +} + +void DnDListBox::configureLink() +{ + if (currentItem == 0L) + return; + dialog->title->setText(currentItem->text()); + dialog->url->setURL(currentItem->URL()); + dialog->icon->setIcon(currentItem->icon()); + dialog->show(); +} + +void DnDListBox::updateLink() +{ + if (currentItem) + { + int index_ = index(currentItem); + bool wasSelected = isSelected(index_); + insertItem( new ListBoxLink(dialog->icon->icon(), size_, dialog->title->text(),dialog->url->url()), index_ +1); + removeItem( index_ ); + setSelected(index_, wasSelected); + } +} diff --git a/sidebar/dndlistbox.h b/sidebar/dndlistbox.h new file mode 100644 index 0000000..b84dbcc --- /dev/null +++ b/sidebar/dndlistbox.h @@ -0,0 +1,126 @@ + +#ifndef DNDLISTBOX_H +#define DNDLISTBOX_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <klistbox.h> +#include <qptrlist.h> +#include <qstringlist.h> +#include "baghirasidebariface.h" + +class DCOPClient; +class QDragEnterEvent; +class QDragMoveEvent; +class QDragLeaveEvent; +class QDropEvent; +class QKeyEvent; +class QPoint; +class KPopupMenu; +class LinkConfig; +class ListBoxLink; +class ListBoxDevice; +class QResizeEvent; + +class ResizingLinkBox : public KListBox +{ + Q_OBJECT + +public: + ResizingLinkBox( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); + ~ResizingLinkBox(){}; + void insertItem( const QListBoxItem *, int index=-1 ); + void insertItem( const QListBoxItem *lbi, const QListBoxItem *after ); + void insertItem( const QString & icon, const QString & title, const QString & url ); + void insertItem( const QString &text, int index=-1 ) + { + insertItem( new QListBoxText(text), index ); + } + void insertItem( const QPixmap &pixmap, int index=-1 ) + { + insertItem( new QListBoxPixmap(pixmap), index ); + } + void insertItem( const QPixmap &pixmap, const QString &text, int index=-1 ){ + insertItem( new QListBoxPixmap(pixmap, text), index ); + } + + void removeItem( int index ); +protected: + void mousePressEvent ( QMouseEvent * ); + void mouseReleaseEvent ( QMouseEvent * ); + void contentsWheelEvent ( QWheelEvent * ); + KPopupMenu *popupMenu; + uint size_; +private slots: + void setIconSize(int); +signals: + void itemNumberChanged(bool); + void scrolled(int,int); +}; + +class MediaListBox : public ResizingLinkBox, virtual public BaghiraSidebarIface +{ + Q_OBJECT +public: + MediaListBox( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); + ~MediaListBox(); + ListBoxDevice *createListBoxDevice(QStringList & deviceProperties, uint n = 0); + void mediumAdded(const QString &name); + void mediumRemoved(const QString &name); + void mediumChanged(const QString &name); + int index (const QString & name ); + void removeItem( int index ); +protected: + void mousePressEvent ( QMouseEvent * ); + void resizeEvent ( QResizeEvent * ); +private: + KPopupMenu *devicePopup; + DCOPClient *client; + ListBoxDevice *currentFloppy; + typedef QPtrList<ListBoxDevice> DeviceList; + DeviceList deviceList; + QStringList hiddenDevices; +private slots: + void kfloppy(); + void toggleDevice(int id); +}; + +class DnDListBox : public ResizingLinkBox +{ + Q_OBJECT + +public: + DnDListBox( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); + + /** destructor */ + ~DnDListBox(); + void poof(ListBoxLink *link); + +protected: + void mousePressEvent ( QMouseEvent * ); + void mouseReleaseEvent ( QMouseEvent * ); + void mouseMoveEvent ( QMouseEvent * e ); + void dragEnterEvent ( QDragEnterEvent * ); +// void dragMoveEvent ( QDragMoveEvent * ); +// void dragLeaveEvent ( QDragLeaveEvent * ); + void dropEvent ( QDropEvent * ); + void startDrag(); +private: + ListBoxLink *currentItem; //TODO: unshadow int KListBox::currentItem() + LinkConfig *dialog; + bool dragging_; + void pasteURL(int mode, QListBoxItem *after = 0); + bool _draggedMe; + int _poofIndex; + QPixmap *_poofPix; + QPixmap *_poofAnimPix; + QWidget *_poof; +private slots: + void configureLink(); + void updateLink(); + void runPoof(); +}; + +#endif diff --git a/sidebar/eject.xbm b/sidebar/eject.xbm new file mode 100644 index 0000000..3230a26 --- /dev/null +++ b/sidebar/eject.xbm @@ -0,0 +1,9 @@ +#define eject_width 22 +#define eject_height 22 +static unsigned char eject_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x07, 0x00, + 0x80, 0x0f, 0x00, 0xc0, 0x1f, 0x00, 0xe0, 0x3f, 0x00, 0xf0, 0x7f, 0x00, + 0xf8, 0xff, 0x00, 0xfc, 0xff, 0x01, 0xfe, 0xff, 0x03, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0xff, 0xff, 0x07, + 0xff, 0xff, 0x07, 0xff, 0xff, 0x07, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/sidebar/linkconfig.ui b/sidebar/linkconfig.ui new file mode 100644 index 0000000..14ccf55 --- /dev/null +++ b/sidebar/linkconfig.ui @@ -0,0 +1,187 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>LinkConfig</class> +<widget class="QDialog"> + <property name="name"> + <cstring>LinkConfig</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>403</width> + <height>164</height> + </rect> + </property> + <property name="caption"> + <string>Configure Link</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout11</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string><b>Title</b></string> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>title</cstring> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string><b>URL</b></string> + </property> + </widget> + <widget class="KURLRequester"> + <property name="name"> + <cstring>url</cstring> + </property> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout10</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>206</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + <widget class="KIconButton" row="0" column="1"> + <property name="name"> + <cstring>icon</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>64</width> + <height>64</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>64</width> + <height>64</height> + </size> + </property> + <property name="text"> + <string></string> + </property> + <property name="iconSize"> + <number>48</number> + </property> + <property name="strictIconSize"> + <bool>false</bool> + </property> + </widget> + </grid> +</widget> +<customwidgets> +</customwidgets> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>LinkConfig</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>LinkConfig</receiver> + <slot>reject()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>kurlrequester.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kicondialog.h</includehint> +</includehints> +</UI> diff --git a/sidebar/linkview.cpp b/sidebar/linkview.cpp new file mode 100644 index 0000000..8becf29 --- /dev/null +++ b/sidebar/linkview.cpp @@ -0,0 +1,199 @@ + +#include <stdlib.h> +#include <qcursor.h> +#include <qsplitter.h> +#include <klocale.h> +#include <qdir.h> +#include <kconfig.h> +#include <qtimer.h> +#include "dndlistbox.h" +#include "listboxlink.h" +#include "linkview.h" +#include "linkview.moc" + +// internal class to eat invalid leave envents (i.e. leave that does not leave the rect but just enters the splitter, as styles (like baghira ;) may post install eventfilters that'd cause useless repaints and therefore flicker if the scroller appereance changes ;) +class EventKiller : public QObject +{ +protected: + virtual bool eventFilter( QObject *o, QEvent *e) + { + if (e->type() == QEvent::Leave) + return ((QScrollView*)o)->rect().contains(((QScrollView*)o)->mapFromGlobal (QCursor::pos())); + return false; + } +}; + +LinkView::LinkView(QWidget * parent, const char * name, WFlags f): + QScrollView(parent, name, f) +{ + setFrameShape( QFrame::StyledPanel ); + setFrameShadow( QFrame::Sunken ); + setBackgroundMode(Qt::PaletteBase); + _blocked = FALSE; + splitter = new QSplitter( Qt::Vertical, viewport() ); + addChild(splitter); + splitter->setMargin(5); + splitter->setBackgroundMode(Qt::PaletteBase); + splitter->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); + splitter->setFrameShape( QFrame::NoFrame ); + splitter->setChildrenCollapsible(TRUE); + splitter->setHandleWidth( 3 ); + splitter->setOpaqueResize(); + hardware = new MediaListBox(splitter, "hardware"); + splitter->setResizeMode( hardware, QSplitter::KeepSize ); + hardware->setFrameShape( QFrame::NoFrame ); + hardware->setHScrollBarMode(QScrollView::AlwaysOff); + hardware->setVScrollBarMode(QScrollView::AlwaysOff); + locations = new DnDListBox(splitter, "locations"); +// splitter->setResizeMode( locations, QSplitter::KeepSize ); + locations->setFrameShape( QFrame::NoFrame ); + locations->setHScrollBarMode(QScrollView::AlwaysOff); + locations->setVScrollBarMode(QScrollView::AlwaysOff); + // custom area, locations + loadLinks(); + locations->setCurrentItem(0); + locations->setSelected( locations->selectedItem(), false ); + hardware->installEventFilter(this); + connect (hardware, SIGNAL(highlighted( int )), this, SLOT(unselectLocations())); + connect (locations, SIGNAL(highlighted( int )), this, SLOT(unselectHardware())); + connect (hardware, SIGNAL(scrolled(int,int)), this, SLOT(scrollBy(int,int))); + connect (locations, SIGNAL(scrolled(int,int)), this, SLOT(scrollBy(int,int))); + connect (hardware, SIGNAL(itemNumberChanged(bool)), this, SLOT(adjustSplitter2Hardware(bool))); + connect (locations, SIGNAL(itemNumberChanged(bool)), this, SLOT(adjustSplitter2Locations())); + QTimer::singleShot(50, this, SLOT(adjustSplitter2Locations())); + QTimer::singleShot(60, this, SLOT(postInstallEventFilter())); +} + +static EventKiller *eventKiller = 0L; + +LinkView::~LinkView() +{ + + saveLinks(); + delete eventKiller; eventKiller = 0L; +} + +void LinkView::postInstallEventFilter() +{ + eventKiller = new EventKiller; + installEventFilter(eventKiller); +} + +bool LinkView::eventFilter(QObject *o, QEvent *e) +{ + if (o != hardware) + return QScrollView::eventFilter(o, e); + if (_blocked || e->type() != QEvent::Resize) + return FALSE; // not a resize - non of our business + QResizeEvent *rev = (QResizeEvent*)e; + if (rev->size().height() == rev->oldSize().height()) + return FALSE; // height didn't change + int tmpH = rev->size().height() + locations->numRows()*locations->itemHeight()+20; + if (tmpH < viewport()->height()) + tmpH = viewport()->height(); + if (tmpH != splitter->height()) + { + _blocked = TRUE; + splitter->resize ( splitter->width(), tmpH ); + _blocked = FALSE; + } + + return FALSE; +} + +void LinkView::adjustSplitter2Locations() +{ + int tmpH = hardware->height() + locations->numRows()*locations->itemHeight()+20; + if (tmpH < viewport()->height()) + tmpH = viewport()->height(); + if (tmpH != splitter->height()) + splitter->resize ( viewport()->width(), tmpH ); +} + +void LinkView::adjustSplitter2Hardware(bool added) +{ + if (added) + { + if (hardware->height() < hardware->numRows()*hardware->itemHeight()) + hardware->resize ( hardware->width(), hardware->numRows()*hardware->itemHeight() ); + } + else + if (hardware->height() > hardware->numRows()*hardware->itemHeight()) + hardware->resize ( hardware->width(), hardware->numRows()*hardware->itemHeight() ); +} + +void LinkView::viewportResizeEvent( QResizeEvent *rev ) +{ + int tmpH = hardware->height() + locations->numRows()*locations->itemHeight()+20; + if (tmpH < rev->size().height()) + tmpH = rev->size().height(); + splitter->resize(rev->size().width(), tmpH); +} + +void LinkView::unselectLocations() +{ + if (locations) locations->setSelected( locations->selectedItem(), FALSE ); +} + +void LinkView::unselectHardware() +{ + if (hardware) hardware->setSelected( hardware->selectedItem(), FALSE ); +} + +void LinkView::loadLinks() +{ + if (!locations) + return; + KConfig config(QDir::homeDirPath() + "/.qt/baghirarc"); + config.setGroup("Sidebar"); + splitter->setSizes(config.readIntListEntry ("Sizes")); + loadedLinks = (uint)config.readNumEntry("NumLinks", 0); + locations->blockSignals ( true ); + if (loadedLinks == 0) // no settings stored - load defaults + { + locations->insertItem("desktop", i18n("Desktop"), QDir::homeDirPath()+"/Desktop"); + locations->insertItem("folder_home", getenv("USER"), QDir::homeDirPath()); + locations->insertItem("kmenu", i18n("Programs"), "programs:/"); + } + QString num; + for (uint i = 0; i < loadedLinks; i++) + { + QString title; + QString icon; + QString url; + num.setNum(i); + title = config.readEntry("Link_"+num+"_Title", "???"); + icon = config.readEntry("Link_"+num+"_Icon", "empty"); + url = config.readEntry("Link_"+num+"_URL", QDir::homeDirPath()); + locations->insertItem(icon, title, url); + } + locations->blockSignals ( false ); +} + +void LinkView::saveLinks() +{ + if (!locations) + return; + KConfig *config = new KConfig(QDir::homeDirPath() + "/.qt/baghirarc"); + config->setGroup("Sidebar"); + config->writeEntry("Sizes", splitter->sizes()); + config->writeEntry("NumLinks", (int)locations->count()); + QString num; + for (uint i = 0; i < locations->count(); i++) + { + num.setNum(i); + ListBoxLink *current = (ListBoxLink*)locations->item(i); + config->writeEntry("Link_"+num+"_Title", current->text()); + config->writeEntry("Link_"+num+"_Icon", current->icon()); + config->writeEntry("Link_"+num+"_URL", current->URL()); + } + // reduced links, remove them from settings + for (uint i = locations->count(); i < loadedLinks; i++) + { + num.setNum(i); + config->deleteEntry("Link_"+num+"_Title"); + config->deleteEntry("Link_"+num+"_Icon"); + config->deleteEntry("Link_"+num+"_URL"); + } + delete config; +} diff --git a/sidebar/linkview.h b/sidebar/linkview.h new file mode 100644 index 0000000..ebe54ef --- /dev/null +++ b/sidebar/linkview.h @@ -0,0 +1,46 @@ + +#ifndef LINKVIEW_H +#define LINKVIEW_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qscrollview.h> + +class ListBoxLink; +class DnDListBox; +class MediaListBox; + +class LinkView : public QScrollView +{ + Q_OBJECT + +public: + LinkView(QWidget * parent = 0, const char * name = 0, WFlags f = 0); + + /** destructor */ + ~LinkView(); + MediaListBox *Hardware(){return hardware;} + DnDListBox *Locations(){return locations;} + void loadLinks(); + void saveLinks(); + +protected: + void viewportResizeEvent( QResizeEvent * ); + bool eventFilter(QObject *, QEvent *); +private: + MediaListBox *hardware; + DnDListBox *locations; + QSplitter *splitter; + bool _blocked; + uint loadedLinks; +private slots: + void postInstallEventFilter(); + void unselectLocations(); + void unselectHardware(); + void adjustSplitter2Locations(); + void adjustSplitter2Hardware(bool added); +}; + +#endif diff --git a/sidebar/listboxlink.cpp b/sidebar/listboxlink.cpp new file mode 100644 index 0000000..47adb88 --- /dev/null +++ b/sidebar/listboxlink.cpp @@ -0,0 +1,78 @@ + +#include <kiconloader.h> +#include "listboxlink.h" +#include <qpainter.h> +#include <qbitmap.h> +#include "eject.xbm" +#include "lock.xbm" + +static QBitmap eject = QBitmap( eject_width, eject_height, eject_bits, true ); +static QBitmap locked = QBitmap( lock_width, lock_height, lock_bits, true ); + +ListBoxLink::ListBoxLink( const QString & icon, uint size, const QString & title, const QString & url): QListBoxPixmap(KGlobal::iconLoader()->loadIcon(icon, KIcon::Desktop, size), title),url_(url),icon_(icon) +{ +} + +ListBoxLink::ListBoxLink( const QPixmap & pixmap, const QString & title, const QString & url) : QListBoxPixmap(pixmap, title), url_(url), icon_(0) +{ +} + +ListBoxLink::ListBoxLink(ListBoxLink & link) : QListBoxPixmap(*link.pixmap(), link.text()), url_(link.URL()), icon_(link.icon()) +{ +} + +ListBoxLink::~ListBoxLink() +{ +} + +void ListBoxLink::setURL(const QString & url) +{ + url_ = url; +} + +void ListBoxLink::setIcon(const QString & icon) +{ + icon_ = icon; +} + +int ListBoxLink::height ( const QListBox * lb ) const +{ + return (QListBoxPixmap::height ( lb ) + 4); +} + +ListBoxDevice::ListBoxDevice(const QString & icon, uint size, const QString & title, const QString & url, const QString & name, const QString & mountPoint, bool mounted, bool ejectable, bool removable, int id) : ListBoxLink(icon, size, title, url), name_(name), mountPoint_(mountPoint), mounted_(mounted), ejectable_(ejectable), removable_(removable),id_(id) +{ + if (!eject.mask()) + eject.setMask(eject); + if (!locked.mask()) + locked.setMask(locked); +} + +ListBoxDevice::ListBoxDevice(const QPixmap & pixmap, const QString & title, const QString & url, const QString & name, const QString & mountPoint, bool mounted, bool ejectable, bool removable, int id) : ListBoxLink(pixmap, title, url), name_(name), mountPoint_(mountPoint), mounted_(mounted), ejectable_(ejectable), removable_(removable),id_(id) +{ + if (!eject.mask()) + eject.setMask(eject); + if (!locked.mask()) + locked.setMask(locked); +} + +int ListBoxDevice::width ( const QListBox * lb ) const +{ + if (ejectable_ && mounted_ && lb) + return lb->width(); + return ListBoxLink::width(lb); +} + +void ListBoxDevice::paint( QPainter * p ) +{ + if ((ejectable_ || removable_) && mounted_) + { + p->save(); + ListBoxLink::paint(p); + p->setBrush(isSelected()?listBox()->colorGroup().highlightedText():listBox()->colorGroup().text()); + p->drawPixmap(listBox()->width()-22, 11, ejectable_?eject:locked); + p->restore(); + } + else + ListBoxLink::paint(p); +} diff --git a/sidebar/listboxlink.h b/sidebar/listboxlink.h new file mode 100644 index 0000000..6614920 --- /dev/null +++ b/sidebar/listboxlink.h @@ -0,0 +1,64 @@ + +#ifndef LISTBOXLINK_H +#define LISTBOXLINK_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qlistbox.h> + +class KListBox; +class QPainter; +class QPixmap; +class QStringList; +class KURL; + +class ListBoxLink : public QListBoxPixmap +{ +friend class DnDListBox; + +public: + ListBoxLink(const QString & icon, uint size, const QString & title, const QString & url); + ListBoxLink(const QPixmap & pixmap, const QString & title, const QString & url); + ListBoxLink(ListBoxLink & link); + ~ListBoxLink(); + QString & URL(){return url_;} + void setURL(const QString & url); + QString & icon(){return icon_;} + void setIcon(const QString & icon); + int height ( const QListBox * lb ) const; + +private: + QString url_; //TODO: make this KURL?! + QString icon_; +}; + +class ListBoxDevice : public ListBoxLink +{ + friend class MediaListBox; +public: + ListBoxDevice(const QString & icon, uint size, const QString & title, const QString & url, const QString & name, const QString & mountPoint, bool mounted, bool ejectable = FALSE, bool removable = FALSE, int id = 0); + ListBoxDevice(const QPixmap & pixmap, const QString & title, const QString & url, const QString & name, const QString & mountPoint, bool mounted, bool ejectable = FALSE, bool removable = FALSE, int id = 0); + ~ListBoxDevice(){}; + QString & name(){return name_;} + bool mounted(){return mounted_;} + bool ejectable(){return ejectable_;} + bool removable(){return removable_;} + QString & mountPoint(){return mountPoint_;} + int id(){return id_;} + int width ( const QListBox * lb ) const; + +protected: + void paint( QPainter * p ); + +private: + QString name_; + QString mountPoint_; + bool mounted_; + bool ejectable_; + bool removable_; + int id_; +}; + +#endif diff --git a/sidebar/lock.xbm b/sidebar/lock.xbm new file mode 100644 index 0000000..6f7caaf --- /dev/null +++ b/sidebar/lock.xbm @@ -0,0 +1,9 @@ +#define lock_width 22 +#define lock_height 22 +static unsigned char lock_bits[] = { + 0x00, 0x00, 0x00, 0xe0, 0x1f, 0x00, 0xf8, 0x7f, 0x00, 0x3c, 0xf0, 0x00, + 0x0e, 0xc0, 0x01, 0x06, 0x80, 0x01, 0x06, 0x80, 0x01, 0x06, 0x80, 0x01, + 0x06, 0x80, 0x01, 0x06, 0x80, 0x01, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, + 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0x03, 0x00, 0x03, 0xff, 0xff, 0x03, + 0x03, 0x00, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, + 0xff, 0xff, 0x03, 0x00, 0x00, 0x00 }; |