diff options
Diffstat (limited to 'kicker/applets/media')
-rw-r--r-- | kicker/applets/media/Makefile.am | 20 | ||||
-rw-r--r-- | kicker/applets/media/mediaapplet.cpp | 444 | ||||
-rw-r--r-- | kicker/applets/media/mediaapplet.desktop | 130 | ||||
-rw-r--r-- | kicker/applets/media/mediaapplet.h | 79 | ||||
-rw-r--r-- | kicker/applets/media/mediumbutton.cpp | 202 | ||||
-rw-r--r-- | kicker/applets/media/mediumbutton.h | 66 | ||||
-rw-r--r-- | kicker/applets/media/preferencesdialog.cpp | 167 | ||||
-rw-r--r-- | kicker/applets/media/preferencesdialog.h | 53 |
8 files changed, 1161 insertions, 0 deletions
diff --git a/kicker/applets/media/Makefile.am b/kicker/applets/media/Makefile.am new file mode 100644 index 000000000..0b971aef2 --- /dev/null +++ b/kicker/applets/media/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = -I$(top_srcdir)/libkonq -I$(top_srcdir)/kicker/libkicker $(all_includes) + +kde_module_LTLIBRARIES = media_panelapplet.la +media_panelapplet_la_SOURCES = preferencesdialog.cpp mediumbutton.cpp mediaapplet.cpp + +METASOURCES = AUTO + +noinst_HEADERS = mediaapplet.h mediumbutton.h preferencesdialog.h + +lnkdir = $(kde_datadir)/kicker/applets +lnk_DATA = mediaapplet.desktop + +EXTRA_DIST = $(lnk_DATA) + +media_panelapplet_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) +media_panelapplet_la_LIBADD = ../../../libkonq/libkonq.la ../../libkicker/libkickermain.la $(LIB_KDEUI) $(LIB_KIO) $(LIB_KUTILS) + +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/mediaapplet.pot + diff --git a/kicker/applets/media/mediaapplet.cpp b/kicker/applets/media/mediaapplet.cpp new file mode 100644 index 000000000..4ccd0eeef --- /dev/null +++ b/kicker/applets/media/mediaapplet.cpp @@ -0,0 +1,444 @@ +/* This file is part of the KDE project + Copyright (c) 2004 Kevin Ottens <ervin ipsquad net> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <kglobal.h> +#include <klocale.h> +#include <kconfig.h> +#include <kapplication.h> +#include <kaboutdata.h> +#include <kaboutapplication.h> +#include <kdebug.h> +#include <kpopupmenu.h> +#include <kiconloader.h> + +#include "mediaapplet.h" + +#include "preferencesdialog.h" + +extern "C" +{ + KDE_EXPORT KPanelApplet* init( QWidget *parent, const QString configFile) + { + KGlobal::locale()->insertCatalogue("mediaapplet"); + return new MediaApplet(configFile, KPanelApplet::Normal, + KPanelApplet::About | KPanelApplet::Preferences, + parent, "mediaapplet"); + } +} + +MediaApplet::MediaApplet(const QString& configFile, Type type, int actions, QWidget *parent, const char *name) + : KPanelApplet(configFile, type, actions, parent, name), + mButtonSizeSum(0) +{ + if (!parent) + setBackgroundMode(X11ParentRelative); + + setBackgroundOrigin(AncestorOrigin); + + setAcceptDrops(true); + + loadConfig(); + + mpDirLister = new KDirLister(); + + connect( mpDirLister, SIGNAL( clear() ), + this, SLOT( slotClear() ) ); + connect( mpDirLister, SIGNAL( started(const KURL&) ), + this, SLOT( slotStarted(const KURL&) ) ); + connect( mpDirLister, SIGNAL( completed() ), + this, SLOT( slotCompleted() ) ); + connect( mpDirLister, SIGNAL( newItems( const KFileItemList & ) ), + this, SLOT( slotNewItems( const KFileItemList & ) ) ); + connect( mpDirLister, SIGNAL( deleteItem( KFileItem * ) ), + this, SLOT( slotDeleteItem( KFileItem * ) ) ); + connect( mpDirLister, SIGNAL( refreshItems( const KFileItemList & ) ), + this, SLOT( slotRefreshItems( const KFileItemList & ) ) ); + + reloadList(); +} + +MediaApplet::~MediaApplet() +{ + delete mpDirLister; + + while (!mButtonList.isEmpty()) + { + MediumButton *b = mButtonList.first(); + mButtonList.remove(b); + delete b; + } + + KGlobal::locale()->removeCatalogue("mediaapplet"); +} + +void MediaApplet::about() +{ + KAboutData data("mediaapplet", + I18N_NOOP("Media Applet"), + "1.0", + I18N_NOOP("\"media:/\" ioslave frontend applet"), + KAboutData::License_GPL_V2, + "(c) 2004, Kevin Ottens"); + + data.addAuthor("Kevin \'ervin\' Ottens", + I18N_NOOP("Maintainer"), + "ervin ipsquad net", + "http://ervin.ipsquad.net"); + + data.addCredit("Joseph Wenninger", + I18N_NOOP("Good mentor, patient and helpful. Thanks for all!"), + "[email protected]"); + + KAboutApplication dialog(&data); + dialog.exec(); +} + +void MediaApplet::preferences() +{ + PreferencesDialog dialog(mMedia); + + dialog.setExcludedMediumTypes(mExcludedTypesList); + dialog.setExcludedMedia(mExcludedList); + + if(dialog.exec()) + { + mExcludedTypesList = dialog.excludedMediumTypes(); + mExcludedList = dialog.excludedMedia(); + saveConfig(); + reloadList(); + } +} + +int MediaApplet::widthForHeight( int /*height*/ ) const +{ + return mButtonSizeSum; +} + +int MediaApplet::heightForWidth( int /*width*/ ) const +{ + return mButtonSizeSum; +} + +void MediaApplet::resizeEvent( QResizeEvent *) +{ + arrangeButtons(); +} + +void MediaApplet::arrangeButtons() +{ + int button_size = 1; + int x_offset = 0; + int y_offset = 0; + + // Determine upper bound for the button size + MediumButtonList::iterator it; + MediumButtonList::iterator end = mButtonList.end(); + for ( it = mButtonList.begin(); it != end; ++it ) + { + MediumButton *button = *it; + + button_size = std::max(button_size, + orientation() == Vertical ? + button->heightForWidth(width()) : + button->widthForHeight(height()) ); + // button->widthForHeight(height()) : + // button->heightForWidth(width()) ); + } + + int kicker_size; + if (orientation() == Vertical) + { + kicker_size = width(); + } + else + { + kicker_size = height(); + } + + unsigned int max_packed_buttons = kicker_size / button_size; + // Center icons if we only have one column/row + if (mButtonList.count() < max_packed_buttons) + { + max_packed_buttons = QMAX(uint(1), mButtonList.count()); + } + max_packed_buttons = QMAX(uint(1), max_packed_buttons); + + int padded_button_size = kicker_size / max_packed_buttons; + mButtonSizeSum = 0; + unsigned int pack_count = 0; + + // Arrange the buttons. If kicker is more than twice as high/wide + // as the maximum preferred size of an icon, we put several icons + // in one column/row + for ( it = mButtonList.begin(); it != end; ++it ) + { + MediumButton *button = *it; + + button->move(x_offset, y_offset); + button->setPanelPosition(position()); + + if(pack_count == 0) + { + mButtonSizeSum += button_size; + } + + ++pack_count; + + if(orientation() == Vertical) + { + if (pack_count < max_packed_buttons) + { + x_offset += padded_button_size; + } + else + { + x_offset = 0; + y_offset += button_size; + pack_count = 0; + } + + button->resize(padded_button_size, button_size); + } + else + { + if (pack_count < max_packed_buttons) + { + y_offset += padded_button_size; + } + else + { + y_offset = 0; + x_offset += button_size; + pack_count = 0; + } + + button->resize(button_size, padded_button_size); + } + + button->unsetPalette(); + button->setBackgroundOrigin(AncestorOrigin); + } + + updateGeometry(); + emit updateLayout(); +} + +void MediaApplet::slotClear() +{ + kdDebug()<<"MediaApplet::slotClear"<<endl; + + while (!mButtonList.isEmpty()) + { + MediumButton *b = mButtonList.first(); + mButtonList.remove(b); + delete b; + } + + arrangeButtons(); +} + +void MediaApplet::slotStarted(const KURL &/*url*/) +{ +} + +void MediaApplet::slotCompleted() +{ + mMedia = mpDirLister->items(KDirLister::AllItems); +} + +void MediaApplet::slotNewItems(const KFileItemList &entries) +{ + kdDebug()<<"MediaApplet::slotNewItems"<<endl; + + for(KFileItemListIterator it(entries); it.current(); ++it) + { + kdDebug() << "item: " << it.current()->url() << endl; + + bool found = false; + MediumButtonList::iterator it2; + MediumButtonList::iterator end = mButtonList.end(); + for ( it2 = mButtonList.begin(); it2 != end; ++it2 ) + { + MediumButton *button = *it2; + + if(button->fileItem().url()==it.current()->url()) + { + found = true; + button->setFileItem(*it.current()); + break; + } + } + + if(!found && !mExcludedList.contains(it.current()->url().url()) ) + { + MediumButton *button = new MediumButton(this, *it.current()); + button->show(); + mButtonList.append(button); + } + } + + arrangeButtons(); +} + +void MediaApplet::slotDeleteItem(KFileItem *fileItem) +{ + kdDebug()<<"MediumApplet::slotDeleteItem:"<< fileItem->url() << endl; + + MediumButtonList::iterator it; + MediumButtonList::iterator end = mButtonList.end(); + for ( it = mButtonList.begin(); it != end; ++it ) + { + MediumButton *button = *it; + + if(button->fileItem().url()==fileItem->url()) + { + mButtonList.remove(button); + delete button; + break; + } + } + slotCompleted(); + arrangeButtons(); +} + +void MediaApplet::slotRefreshItems(const KFileItemList &entries) +{ + for(KFileItemListIterator it(entries); it.current(); ++it) + { + kdDebug()<<"MediaApplet::slotRefreshItems:"<<(*it.current()).url().url()<<endl; + + QString mimetype = (*it.current()).mimetype(); + bool found = false; + + kdDebug()<<"mimetype="<<mimetype<<endl; + + MediumButtonList::iterator it2; + MediumButtonList::iterator end = mButtonList.end(); + for ( it2 = mButtonList.begin(); it2 != end; ++it2 ) + { + MediumButton *button = *it2; + + if(button->fileItem().url()==(*it.current()).url()) + { + if(mExcludedTypesList.contains(mimetype)) + { + mButtonList.remove(button); + delete button; + } + else + { + button->setFileItem(*it.current()); + } + found = true; + break; + } + } + + if(!found && !mExcludedTypesList.contains(mimetype) && !mExcludedList.contains(it.current()->url().url()) ) + { + MediumButton *button = new MediumButton(this, *it.current()); + button->show(); + mButtonList.append(button); + } + } + + arrangeButtons(); +} + +void MediaApplet::positionChange(Position) +{ + arrangeButtons(); +} + +void MediaApplet::loadConfig() +{ + KConfig *c = config(); + c->setGroup("General"); + + if(c->hasKey("ExcludedTypes")) + { + mExcludedTypesList = c->readListEntry("ExcludedTypes",';'); + } + else + { + mExcludedTypesList.clear(); + mExcludedTypesList << "media/hdd_mounted"; + mExcludedTypesList << "media/hdd_unmounted"; + mExcludedTypesList << "media/nfs_mounted"; + mExcludedTypesList << "media/nfs_unmounted"; + mExcludedTypesList << "media/smb_mounted"; + mExcludedTypesList << "media/smb_unmounted"; + } + + if(c->hasKey("ExcludedMedia")) + { + mExcludedList = c->readListEntry("ExcludedMedia",';'); + } + else + { + mExcludedList.clear(); + } +} + +void MediaApplet::saveConfig() +{ + KConfig *c = config(); + c->setGroup("General"); + + c->writeEntry("ExcludedTypes", mExcludedTypesList, ';'); + c->writeEntry("ExcludedMedia", mExcludedList, ';'); + + c->sync(); +} + +void MediaApplet::reloadList() +{ + mpDirLister->stop(); + + while (!mButtonList.isEmpty()) + { + MediumButton *b = mButtonList.first(); + mButtonList.remove(b); + delete b; + } + + mpDirLister->clearMimeFilter(); + mpDirLister->setMimeExcludeFilter(mExcludedTypesList); + mpDirLister->openURL(KURL("media:/")); +} + +void MediaApplet::mousePressEvent(QMouseEvent *e) +{ + if(e->button()==RightButton) + { + KPopupMenu menu(this); + + menu.insertTitle(i18n("Media")); + menu.insertItem(SmallIcon("configure"), i18n("&Configure..."), 1); + + int choice = menu.exec(this->mapToGlobal(e->pos())); + + if(choice==1) + { + preferences(); + } + } +} + +#include "mediaapplet.moc" diff --git a/kicker/applets/media/mediaapplet.desktop b/kicker/applets/media/mediaapplet.desktop new file mode 100644 index 000000000..958ebb753 --- /dev/null +++ b/kicker/applets/media/mediaapplet.desktop @@ -0,0 +1,130 @@ +[Desktop Entry] +Type=Plugin +Comment=Directly access your storage media +Comment[af]=Kry direkte toegang tot jou stoor media +Comment[ar]=الوصول مباشرة إلى وسائطك للتخزين +Comment[be]=Наўпрост дае доступ да носьбітаў інфармацыі +Comment[bg]=Директен достъп до съхраняващите устройства +Comment[bn]=আপনার স্টোরেজ মিডিয়া সরাসরি খুলুন +Comment[bs]=Direktno pristupite vašim uređajima +Comment[ca]=Accedeix directament als suports d'emmagatzematge +Comment[cs]=Přímý přístup k úložným zařízením +Comment[csb]=Prosti przistãp do Twòjëch zôpisownëch mediów +Comment[da]=Direkte adgang til opbevaringsmedie +Comment[de]=Direkter Zugriff auf Ihre Speichermedien +Comment[el]=Απευθείας πρόσβαση στις συσκευές αποθήκευσής σας +Comment[eo]=Rekte atingi vian konservejon +Comment[es]= Acceso directo a sus dispositivos de almacenamiento +Comment[et]=Ligipääs andmekandjatele +Comment[eu]=Atzitu zure biltegiratze-euskarriak +Comment[fa]=دستیابی مستقیم رسانۀ ذخیرهگاه شما +Comment[fi]=Tallennuslaitteet näyttävä paneelisovelma +Comment[fr]=Accès direct aux périphériques de stockage +Comment[fy]=Direkte tagong ta jo opslachmedia +Comment[gl]=Unha applet que mostra os seus dispositivos +Comment[he]=גישה ישירה אל ההתקנים שלך +Comment[hr]=Izravni pristup medijima za pohranjivanje +Comment[hu]=A tárolóeszközök közvetlen elérése +Comment[is]=Beinn aðgangur að geymslumiðlum +Comment[it]=Accesso diretto ai dispositivi di archiviazione +Comment[ja]=記憶メディアに直接アクセス +Comment[ka]=თქვენი შენახვის მედიის პირდაპირი წვდომა +Comment[kk]=Жинақтаушыларыңызды тез ашу +Comment[km]=ចូលដំណើរការឧបករណ៍ផ្ទុករបស់អ្នកដោយផ្ទាល់ +Comment[lt]=Tiesiogiai pasiekite savo saugojimo įrenginius +Comment[mk]=Пристапете директно на вашите медиуми за податоци +Comment[nb]=Direkte tilgang til lagringsenheter +Comment[nds]=Direktemang op Dien Spiekermedien togriepen +Comment[ne]=भण्डारण मिडियामा तपाईँको प्रत्यक्ष पहुँच +Comment[nl]=Directe toegang tot uw opslagmedia +Comment[nn]=Direkte tilgang til lagringseiningar +Comment[pa]=ਜੋ ਕਿ ਤੁਹਾਡਾ ਸਟੋਰੇਜ਼ ਮਾਧਿਅਮ ਵੇਖਾਉਦਾ ਹੈ। +Comment[pl]=Bezpośredni dostęp do Twoich urządzeń przechowywania danych +Comment[pt]=Aceder directamente aos seus suportes de armazenamento +Comment[pt_BR]=Acesso direto às suas mídias de armazenamento +Comment[ro]=Accesează direct dispozitivele de stocare +Comment[ru]=Аплет панели, показывающий устройства хранения +Comment[se]=Njuolggoluotta vurkenmediaide +Comment[sk]=Priamy prístup na zálohovacie médiá +Comment[sl]=Neposreden dostop do nosilcev za shranjevanje +Comment[sr]=Директно приступите складишним медијима +Comment[sr@Latn]=Direktno pristupite skladišnim medijima +Comment[sv]=Direkt åtkomst av lagringsmedia +Comment[th]=เข้าใช้งานสื่อที่เก็บข้อมูลของคุณโดยตรง +Comment[tr]=Depolama aygıtlarına doğrudan erişim +Comment[uk]=Безпосередній доступ до пристроїв зберігання інформації +Comment[uz]=Saqlash usunalariga qisqa yoʻl +Comment[uz@cyrillic]=Сақлаш усуналарига қисқа йўл +Comment[vi]=Truy cập ngay vào các ổ chứa dữ liệu của bạn +Comment[wa]=Accès direk a vos sopoirts di wårdaedje +Comment[zh_CN]=直接访问您的存储介质 +Comment[zh_TW]=直接存取您的儲存媒體 +Name=Storage Media +Name[af]=Stoor Media +Name[ar]=وسائط التخزين +Name[be]=Носьбіты +Name[bg]=Съхраняващи устройства +Name[bn]=স্টোরেজ মিডিয়া +Name[bs]=Uređaji za smještaj podataka +Name[ca]=Suports d'emmagatzematge +Name[cs]=Úložná zařízení +Name[csb]=Zôpisowné media +Name[da]=Opbevaringsmedie +Name[de]=Speichermedien +Name[el]=Συσκευές αποθήκευσης +Name[eo]=Enmemoriga Medio +Name[es]=Dispositivos de almacenamiento +Name[et]=Andmekandjad +Name[eu]=Biltegiratze-euskarria +Name[fa]=رسانۀ ذخیرهگاه +Name[fi]=Tallennusmedia +Name[fr]=Support de stockage +Name[fy]=Opslachapparaten +Name[ga]=Meán Stórais +Name[gl]=Medios de armacenaxe +Name[he]=התקנים +Name[hi]=भंडार मीडिया +Name[hr]=Mediji za pohranjivanje +Name[hu]=Tárolóeszközök +Name[is]=Geymslumiðlar +Name[it]=Dispositivi di archiviazione +Name[ja]=記憶メディア +Name[ka]=მონაცემთა შენახვის მოწყობილობები +Name[kk]=Жинақтаушы құрылғылар +Name[km]=ឧបករណ៍ផ្ទុក +Name[lt]=Saugojimo įrenginiai +Name[lv]=Datu nesējs +Name[mk]=Медиуми за податоци +Name[ms]=Media Storan +Name[nb]=Lagringsenheter +Name[nds]=Spiekermedien +Name[ne]=भण्डारण मिडिया +Name[nl]=Opslagapparaten +Name[nn]=Lagringsmedium +Name[pa]=ਸਟੋਰੇਜ਼ ਮੀਡਿਆ +Name[pl]=Urządzenia przechowywania danych +Name[pt]=Dispositivos de Armazenamento +Name[pt_BR]=Mídia de Armazenamento +Name[ro]=Mediu de stocare +Name[ru]=Устройства хранения данных +Name[rw]=Uburyo bwo Kubika +Name[se]=Vurkenmedia +Name[sk]=Zálohovacie médiá +Name[sl]=Nosilci za shranjevanje +Name[sr]=Складишни медијуми +Name[sr@Latn]=Skladišni medijumi +Name[sv]=Lagringsmedia +Name[ta]=சேகரிப்பு ஊடகம் +Name[tg]=Захирагоҳи маълумот +Name[th]=สื่อเก็บข้อมูล +Name[tr]=Depolama Ortamı +Name[tt]=Saqlawlı Media +Name[uk]=Пристрої зберігання інформації +Name[uz]=Saqlash uskunalari +Name[uz@cyrillic]=Сақлаш ускуналари +Name[vi]=Ổ chứa Dữ liệu +Name[wa]=Sopoirts di wårdaedje +Name[zh_CN]=存储介质 +Name[zh_TW]=儲存媒體 +Icon=3floppy_unmount +X-KDE-Library=media_panelapplet diff --git a/kicker/applets/media/mediaapplet.h b/kicker/applets/media/mediaapplet.h new file mode 100644 index 000000000..5e2320be0 --- /dev/null +++ b/kicker/applets/media/mediaapplet.h @@ -0,0 +1,79 @@ +/* This file is part of the KDE project + Copyright (c) 2004 Kevin Ottens <ervin ipsquad net> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef MEDIAAPPLET_H +#define MEDIAAPPLET_H + +#ifdef HAVE_CONFIG_H + #include <config.h> +#endif + +#include <kpanelapplet.h> +#include <qstring.h> +#include <kconfig.h> +#include <kurl.h> +#include <kfileitem.h> +#include <kdirlister.h> + +#include <qptrlist.h> +#include "mediumbutton.h" +typedef QValueList<MediumButton*> MediumButtonList; + + +class MediaApplet : public KPanelApplet +{ +Q_OBJECT + +public: + MediaApplet(const QString& configFile, Type t = Normal, int actions = 0, + QWidget *parent = 0, const char *name = 0); + ~MediaApplet(); + + int widthForHeight(int height) const; + int heightForWidth(int width) const; + void about(); + void preferences(); + +protected: + void arrangeButtons(); + void resizeEvent(QResizeEvent *e); + void positionChange(Position p); + void reloadList(); + void loadConfig(); + void saveConfig(); + void mousePressEvent(QMouseEvent *e); + +protected slots: + void slotClear(); + void slotStarted(const KURL &url); + void slotCompleted(); + void slotNewItems(const KFileItemList &entries); + void slotDeleteItem(KFileItem *fileItem); + void slotRefreshItems(const KFileItemList &entries); + +private: + KDirLister *mpDirLister; + MediumButtonList mButtonList; + QStringList mExcludedTypesList; + QStringList mExcludedList; + KFileItemList mMedia; + int mButtonSizeSum; +}; + +#endif diff --git a/kicker/applets/media/mediumbutton.cpp b/kicker/applets/media/mediumbutton.cpp new file mode 100644 index 000000000..2c96601ea --- /dev/null +++ b/kicker/applets/media/mediumbutton.cpp @@ -0,0 +1,202 @@ +/* This file is part of the KDE project + Copyright (c) 2004 Kevin Ottens <ervin ipsquad net> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "mediumbutton.h" + +#include <qapplication.h> +#include <qclipboard.h> +#include <qpainter.h> +#include <qdrawutil.h> +#include <qpopupmenu.h> +#include <qstyle.h> +#include <qtooltip.h> + +#include <kmessagebox.h> +#include <kmimetype.h> +#include <klocale.h> +#include <kdesktopfile.h> +#include <krun.h> +#include <kglobalsettings.h> +#include <kcursor.h> +#include <kapplication.h> +#include <kipc.h> +#include <kiconloader.h> +#include <kurldrag.h> +#include <kpopupmenu.h> + +#include <konq_operations.h> +#include <konq_popupmenu.h> +#include <konq_drag.h> + +MediumButton::MediumButton(QWidget *parent, const KFileItem &fileItem) + : PanelPopupButton(parent), mActions(this, this), mFileItem(fileItem) +{ + KAction *a = KStdAction::paste(this, SLOT(slotPaste()), + &mActions, "pasteto"); + a->setShortcut(0); + a = KStdAction::copy(this, SLOT(slotCopy()), &mActions, "copy"); + a->setShortcut(0); + + setBackgroundOrigin(AncestorOrigin); + + resize(20, 20); + + setAcceptDrops(mFileItem.isWritable()); + + setTitle(mFileItem.text()); + + refreshType(); + + connect(&mOpenTimer, SIGNAL(timeout()), SLOT(slotDragOpen())); + + // Activate this code only if we find a way to have both an + // action and a popup menu for the same kicker button + //connect(this, SIGNAL(clicked()), this, SLOT(slotClicked())); + + setPopup(new QPopupMenu()); +} + +MediumButton::~MediumButton() +{ + QPopupMenu *menu = popup(); + setPopup(0); + delete menu; +} + +const KFileItem &MediumButton::fileItem() const +{ + return mFileItem; +} + +void MediumButton::setFileItem(const KFileItem &fileItem) +{ + mFileItem.assign(fileItem); + setAcceptDrops(mFileItem.isWritable()); + setTitle(mFileItem.text()); + refreshType(); +} + +void MediumButton::initPopup() +{ + QPopupMenu *old_popup = popup(); + + KFileItemList items; + items.append(&mFileItem); + + KonqPopupMenu::KonqPopupFlags kpf = + KonqPopupMenu::ShowProperties + | KonqPopupMenu::ShowNewWindow; + + KParts::BrowserExtension::PopupFlags bef = + KParts::BrowserExtension::DefaultPopupItems; + + KonqPopupMenu *new_popup = new KonqPopupMenu(0L, items, + KURL("media:/"), mActions, 0L, + this, kpf, bef); + KPopupTitle *title = new KPopupTitle(new_popup); + title->setTitle(mFileItem.text()); + + new_popup->insertItem(title, -1, 0); + + setPopup(new_popup); + + if (old_popup!=0L) delete old_popup; +} + +void MediumButton::refreshType() +{ + KMimeType::Ptr mime = mFileItem.determineMimeType(); + QToolTip::add(this, mime->comment()); + setIcon(mime->icon(QString::null, false)); +} + +// Activate this code only if we find a way to have both an +// action and a popup menu for the same kicker button +/* +void MediumButton::slotClicked() +{ + mFileItem.run(); +} +*/ + +void MediumButton::slotPaste() +{ + KonqOperations::doPaste(this, mFileItem.url()); +} + +void MediumButton::slotCopy() +{ + KonqDrag * obj = KonqDrag::newDrag(mFileItem.url(), false); + + QApplication::clipboard()->setData( obj ); +} + +void MediumButton::dragEnterEvent(QDragEnterEvent* e) +{ + if (mFileItem.isWritable()) + { + mOpenTimer.start(1000, true); + e->accept(true); + } +} + +void MediumButton::dragLeaveEvent(QDragLeaveEvent* e) +{ + mOpenTimer.stop(); + + PanelPopupButton::dragLeaveEvent( e ); +} + +void MediumButton::dropEvent(QDropEvent *e) +{ + mOpenTimer.stop(); + + KonqOperations::doDrop(&mFileItem, mFileItem.url(), e, this); +} + +void MediumButton::slotDragOpen() +{ + mFileItem.run(); +} + +QString MediumButton::tileName() +{ + return mFileItem.text(); +} + +void MediumButton::setPanelPosition(KPanelApplet::Position position) +{ + switch(position) + { + case KPanelApplet::pBottom: + setPopupDirection(KPanelApplet::Up); + break; + case KPanelApplet::pTop: + setPopupDirection(KPanelApplet::Down); + break; + case KPanelApplet::pRight: + setPopupDirection(KPanelApplet::Left); + break; + case KPanelApplet::pLeft: + setPopupDirection(KPanelApplet::Right); + break; + } +} + +#include "mediumbutton.moc" diff --git a/kicker/applets/media/mediumbutton.h b/kicker/applets/media/mediumbutton.h new file mode 100644 index 000000000..8d7970d89 --- /dev/null +++ b/kicker/applets/media/mediumbutton.h @@ -0,0 +1,66 @@ +/* This file is part of the KDE project + Copyright (c) 2004 Kevin Ottens <ervin ipsquad net> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef MEDIUMBUTTON_H +#define MEDIUMBUTTON_H + +#include <panelbutton.h> +#include <qpoint.h> +#include <qstring.h> +#include <qpixmap.h> +#include <qcursor.h> +#include <qtimer.h> +#include <kfileitem.h> +#include <kpanelapplet.h> +#include <kactioncollection.h> + +class MediumButton : public PanelPopupButton +{ +Q_OBJECT + +public: + MediumButton(QWidget *parent, const KFileItem &fileItem); + ~MediumButton(); + const KFileItem &fileItem() const; + void setFileItem(const KFileItem &fileItem); + void setPanelPosition(KPanelApplet::Position position); + +protected: + QString tileName(); + void refreshType(); + void initPopup(); + void dragEnterEvent( QDragEnterEvent* ); + void dragLeaveEvent( QDragLeaveEvent* ); + void dropEvent(QDropEvent *e); + +protected slots: + // Activate this code only if we find a way to have both an + // action and a popup menu for the same kicker button + //void slotClicked(); + void slotPaste(); + void slotCopy(); + void slotDragOpen(); + +private: + KActionCollection mActions; + KFileItem mFileItem; + QTimer mOpenTimer; +}; + +#endif diff --git a/kicker/applets/media/preferencesdialog.cpp b/kicker/applets/media/preferencesdialog.cpp new file mode 100644 index 000000000..179878e89 --- /dev/null +++ b/kicker/applets/media/preferencesdialog.cpp @@ -0,0 +1,167 @@ +/* This file is part of the KDE project + Copyright (c) 2004 Kevin Ottens <ervin ipsquad net> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "preferencesdialog.h" + +#include <klocale.h> +#include <kmimetype.h> +#include <qvbox.h> +#include <qwhatsthis.h> +#include <klistview.h> +#include <kfiledetailview.h> + +class MediumTypeItem : public QCheckListItem +{ +public: + MediumTypeItem(QListView *parent, const QString name, + const QString mimetype) + : QCheckListItem(parent, name, CheckBox), + mMimeType(mimetype) { } + + const QString &mimeType() const { return mMimeType; } + +private: + QString mMimeType; +}; + +class MediumItem : public QCheckListItem +{ +public: + MediumItem(QListView *parent, const QString name, + const KFileItem medium) + : QCheckListItem(parent, name, CheckBox), + mMedium(medium) { } + + const QString itemURL() const { return mMedium.url().url(); } + +private: + KFileItem mMedium; +}; + + + +PreferencesDialog::PreferencesDialog(KFileItemList media, QWidget *parent, + const char *name) + : KDialogBase(Tabbed, i18n("Media Applet Preferences"), Ok|Cancel|Default, + Ok, parent, name, true), + mMedia(media) +{ + QVBox *types_page = addVBoxPage( i18n("Medium Types") ); + mpMediumTypesListView = new KListView(types_page); + + //mpMediumTypesListView->setFullWidth(true); + mpMediumTypesListView->addColumn( i18n("Types to Display") ); + QWhatsThis::add(mpMediumTypesListView, i18n("Deselect the medium types which you do not want to see in the applet")); + + + + QVBox *media_page = addVBoxPage( i18n("Media") ); + mpMediaListView = new KListView(media_page); + + //mpMediaListView->setFullWidth(true); + mpMediaListView->addColumn( i18n("Media to Display") ); + QWhatsThis::add(mpMediaListView, i18n("Deselect the media which you do not want to see in the applet")); + + slotDefault(); +} + +PreferencesDialog::~PreferencesDialog() +{ +} + +void PreferencesDialog::slotDefault() +{ + QStringList defaultExclude; + + defaultExclude << "media/hdd_mounted"; + defaultExclude << "media/hdd_unmounted"; + defaultExclude << "media/nfs_mounted"; + defaultExclude << "media/nfs_unmounted"; + defaultExclude << "media/smb_mounted"; + defaultExclude << "media/smb_unmounted"; + + setExcludedMediumTypes(defaultExclude); + setExcludedMedia(QStringList()); +} + +QStringList PreferencesDialog::excludedMediumTypes() +{ + QStringList excludedTypes; + + for(MediumTypeItem *it=static_cast<MediumTypeItem *>(mpMediumTypesListView->firstChild()); + it; it=static_cast<MediumTypeItem *>(it->nextSibling())) + { + if(!it->isOn()) excludedTypes << it->mimeType(); + } + + return excludedTypes; +} + +void PreferencesDialog::setExcludedMediumTypes(QStringList excludedTypesList) +{ + mpMediumTypesListView->clear(); + mpMediumTypesListView->setRootIsDecorated(false); + KMimeType::List mimetypes = KMimeType::allMimeTypes(); + + QValueListIterator<KMimeType::Ptr> it(mimetypes.begin()); + + for(; it != mimetypes.end(); ++it) + { + if ((*it)->name().startsWith("media/")) + { + bool ok=excludedTypesList.contains((*it)->name())==0; + MediumTypeItem *item = new MediumTypeItem(mpMediumTypesListView, (*it)->comment(), (*it)->name()); + item->setOn(ok); + } + } +} + +QStringList PreferencesDialog::excludedMedia() +{ + QStringList excluded; + + for(MediumItem *it=static_cast<MediumItem *>(mpMediaListView->firstChild()); + it; it=static_cast<MediumItem *>(it->nextSibling())) + { + if(!it->isOn()) excluded << it->itemURL(); + } + + return excluded; +} + +void PreferencesDialog::setExcludedMedia(QStringList excludedList) +{ + mpMediaListView->clear(); + mpMediaListView->setRootIsDecorated(false); + + KFileItemListIterator it( mMedia ); + KFileItem *file; + while ( (file = it.current()) != 0 ) + { + ++it; + + bool ok = excludedList.contains(file->url().url())==0; + MediumItem *item = new MediumItem(mpMediaListView, + file->text(), *file); + item->setOn(ok); + } +} + + +#include "preferencesdialog.moc" diff --git a/kicker/applets/media/preferencesdialog.h b/kicker/applets/media/preferencesdialog.h new file mode 100644 index 000000000..bb400564b --- /dev/null +++ b/kicker/applets/media/preferencesdialog.h @@ -0,0 +1,53 @@ +/* This file is part of the KDE project + Copyright (c) 2004 Kevin Ottens <ervin ipsquad net> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef PREFERENCESDIALOG_H +#define PREFERENCESDIALOG_H + +#include <qwidget.h> +#include <kdialogbase.h> +#include <kfileitem.h> + +/** + *@author ervin + */ + +class PreferencesDialog : public KDialogBase +{ + Q_OBJECT +public: + PreferencesDialog(KFileItemList media, QWidget *parent=0, const char *name=0); + ~PreferencesDialog(); + + QStringList excludedMediumTypes(); + void setExcludedMediumTypes(QStringList excludedTypesList); + + QStringList excludedMedia(); + void setExcludedMedia(QStringList excludedList); + +protected slots: + void slotDefault(); + +private: + KListView *mpMediumTypesListView; + KListView *mpMediaListView; + KFileItemList mMedia; +}; + +#endif |