diff options
Diffstat (limited to 'kicker/menuext/prefmenu')
-rw-r--r-- | kicker/menuext/prefmenu/CMakeLists.txt | 35 | ||||
-rw-r--r-- | kicker/menuext/prefmenu/Makefile.am | 17 | ||||
-rw-r--r-- | kicker/menuext/prefmenu/prefmenu.cpp | 394 | ||||
-rw-r--r-- | kicker/menuext/prefmenu/prefmenu.desktop | 143 | ||||
-rw-r--r-- | kicker/menuext/prefmenu/prefmenu.h | 74 |
5 files changed, 663 insertions, 0 deletions
diff --git a/kicker/menuext/prefmenu/CMakeLists.txt b/kicker/menuext/prefmenu/CMakeLists.txt new file mode 100644 index 000000000..448e03d74 --- /dev/null +++ b/kicker/menuext/prefmenu/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR}/kicker/libkicker + ${CMAKE_SOURCE_DIR}/kicker/libkicker + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +##### other data ################################ + +install( FILES prefmenu.desktop DESTINATION ${DATA_INSTALL_DIR}/kicker/menuext ) + + +##### kickermenu_prefmenu (module) ############## + +tde_add_kpart( kickermenu_prefmenu AUTOMOC + SOURCES prefmenu.cpp + LINK kickermain-shared tdeui-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/kicker/menuext/prefmenu/Makefile.am b/kicker/menuext/prefmenu/Makefile.am new file mode 100644 index 000000000..e11ad0cdd --- /dev/null +++ b/kicker/menuext/prefmenu/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES = -I../../libkicker -I$(top_srcdir)/kicker/libkicker $(all_includes) + +kde_module_LTLIBRARIES = kickermenu_prefmenu.la + +kickermenu_prefmenu_la_SOURCES = prefmenu.cpp +kickermenu_prefmenu_la_LDFLAGS = $(all_libraries) -module -avoid-version +kickermenu_prefmenu_la_LIBADD = $(LIB_TDEUI) $(top_builddir)/kicker/libkicker/libkickermain.la + +kickermenu_prefmenu_la_METASOURCES = AUTO + +desktopmenu_DATA = prefmenu.desktop +desktopmenudir = $(kde_datadir)/kicker/menuext + +messages: + $(XGETTEXT) *.cpp -o $(podir)/libkickermenu_prefmenu.pot + +prefmenu.lo: ../../libkicker/kickerSettings.h diff --git a/kicker/menuext/prefmenu/prefmenu.cpp b/kicker/menuext/prefmenu/prefmenu.cpp new file mode 100644 index 000000000..534387394 --- /dev/null +++ b/kicker/menuext/prefmenu/prefmenu.cpp @@ -0,0 +1,394 @@ +/***************************************************************** + +Copyright (c) 1996-2002 the kicker authors. See file AUTHORS. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************/ + +#include <tqcursor.h> +#include <tqtimer.h> + +#include <tdeapplication.h> +#include <tdeglobal.h> +#include <kiconloader.h> +#include <tdelocale.h> +#include <kservice.h> +#include <kservicegroup.h> +#include <kstandarddirs.h> +#include <tdesycoca.h> +#include <kurl.h> +#include <kurldrag.h> + +#include "global.h" +#include "kickerSettings.h" +#include "prefmenu.h" + +K_EXPORT_KICKER_MENUEXT(prefmenu, PrefMenu) + +const int idStart = 4242; + +PrefMenu::PrefMenu(TQWidget *parent, + const char *name, + const TQStringList &/*args*/) + : KPanelMenu(i18n("Settings"), parent, name), + m_clearOnClose(false) +{ +} + +PrefMenu::PrefMenu(const TQString& label, + const TQString& root, + TQWidget *parent) + : KPanelMenu(label, parent), + m_clearOnClose(false), + m_root(root) +{ + m_subMenus.setAutoDelete(true); + + connect(KSycoca::self(), TQT_SIGNAL(databaseChanged()), + this, TQT_SLOT(clearOnClose())); + + connect(this, TQT_SIGNAL(aboutToHide()), + this, TQT_SLOT(aboutToClose())); +} + +PrefMenu::~PrefMenu() +{ +} + +void PrefMenu::insertMenuItem(KService::Ptr& s, + int nId, + int nIndex, + const TQStringList *suppressGenericNames) +{ + TQString serviceName = s->name(); + // add comment + TQString comment = s->genericName(); + if (!comment.isEmpty()) + { + if (KickerSettings::menuEntryFormat() == KickerSettings::NameAndDescription) + { + if (!suppressGenericNames || + !suppressGenericNames->contains(s->untranslatedGenericName())) + { + serviceName = TQString("%1 (%2)").arg(serviceName).arg(comment); + } + } + else if (KickerSettings::menuEntryFormat() == KickerSettings::DescriptionAndName) + { + serviceName = TQString("%1 (%2)").arg(comment).arg(serviceName); + } + else if (KickerSettings::menuEntryFormat() == KickerSettings::DescriptionOnly) + { + serviceName = comment; + } + } + + // restrict menu entries to a sane length + if (serviceName.length() > 60) + { + serviceName.truncate(57); + serviceName += "..."; + } + + // check for NoDisplay + if (s->noDisplay()) + { + return; + } + + // ignore dotfiles. + if ((serviceName.at(0) == '.')) + { + return; + } + + // item names may contain ampersands. To avoid them being converted + // to accelerators, replace them with two ampersands. + serviceName.replace("&", "&&"); + + int newId = insertItem(KickerLib::menuIconSet(s->icon()), serviceName, nId, nIndex); + m_entryMap.insert(newId, static_cast<KSycocaEntry*>(s)); +} + +void PrefMenu::mousePressEvent(TQMouseEvent * ev) +{ + m_dragStartPos = ev->pos(); + KPanelMenu::mousePressEvent(ev); +} + +void PrefMenu::mouseMoveEvent(TQMouseEvent * ev) +{ + KPanelMenu::mouseMoveEvent(ev); + + if ((ev->state() & Qt::LeftButton) != Qt::LeftButton) + { + return; + } + + TQPoint p = ev->pos() - m_dragStartPos; + if (p.manhattanLength() <= TQApplication::startDragDistance()) + { + return; + } + + int id = idAt(m_dragStartPos); + + // Don't drag items we didn't create. + if (id < idStart) + { + return; + } + + if (!m_entryMap.contains(id)) + { + kdDebug(1210) << "Cannot find service with menu id " << id << endl; + return; + } + + KSycocaEntry * e = m_entryMap[id]; + + TQPixmap icon; + KURL url; + + switch (e->sycocaType()) + { + case KST_KService: + { + icon = static_cast<KService *>(e)->pixmap(TDEIcon::Small); + TQString filePath = static_cast<KService *>(e)->desktopEntryPath(); + if (filePath[0] != '/') + { + filePath = locate("apps", filePath); + } + url.setPath(filePath); + break; + } + + case KST_KServiceGroup: + { + icon = TDEGlobal::iconLoader()->loadIcon(static_cast<KServiceGroup*>(e)->icon(), + TDEIcon::Small); + url = "programs:/" + static_cast<KServiceGroup*>(e)->relPath(); + break; + } + + default: + { + return; + break; + } + } + + // If the path to the desktop file is relative, try to get the full + // path from KStdDirs. + KURLDrag *d = new KURLDrag(KURL::List(url), this); + connect(d, TQT_SIGNAL(destroyed()), this, TQT_SLOT(dragObjectDestroyed())); + d->setPixmap(icon); + d->dragCopy(); + + // Set the startposition outside the panel, so there is no drag initiated + // when we use drag and click to select items. A drag is only initiated when + // you click to open the menu, and then press and drag an item. + m_dragStartPos = TQPoint(-1,-1); +} + +void PrefMenu::dragEnterEvent(TQDragEnterEvent *event) +{ + // Set the DragObject's target to this widget. This is needed because the + // widget doesn't accept drops, but we want to determine if the drag object + // is dropped on it. This avoids closing on accidental drags. If this + // widget accepts drops in the future, these lines can be removed. + if (event->source() == this) + { + KURLDrag::setTarget(this); + } + event->ignore(); +} + +void PrefMenu::dragLeaveEvent(TQDragLeaveEvent */*event*/) +{ + // see PrefMenu::dragEnterEvent why this is nescessary + if (!TQT_TQRECT_OBJECT(frameGeometry()).contains(TQCursor::pos())) + { + KURLDrag::setTarget(0); + } +} + +void PrefMenu::initialize() +{ + if (initialized()) + { + return; + } + + // Set the startposition outside the panel, so there is no drag initiated + // when we use drag and click to select items. A drag is only initiated when + // you click to open the menu, and then press and drag an item. + m_dragStartPos = TQPoint(-1,-1); + + if (m_root.isEmpty()) + { + insertItem(KickerLib::menuIconSet("kcontrol"), + i18n("Trinity Control Center"), + this, TQT_SLOT(launchControlCenter())); + insertSeparator(); + } + + // We ask KSycoca to give us all services under Settings/ + KServiceGroup::Ptr root = KServiceGroup::group(m_root.isEmpty() ? "Settings/" : m_root); + + if (!root || !root->isValid()) + { + return; + } + + KServiceGroup::List list = root->entries(true, true, true, + KickerSettings::menuEntryFormat() == KickerSettings:: NameAndDescription); + + if (list.isEmpty()) + { + setItemEnabled(insertItem(i18n("No Entries")), false); + return; + } + + int id = idStart; + + TQStringList suppressGenericNames = root->suppressGenericNames(); + + KServiceGroup::List::ConstIterator it = list.begin(); + for (; it != list.end(); ++it) + { + KSycocaEntry* e = *it; + + if (e->isType(KST_KServiceGroup)) + { + + KServiceGroup::Ptr g(static_cast<KServiceGroup *>(e)); + TQString groupCaption = g->caption(); + + // Avoid adding empty groups. + KServiceGroup::Ptr subMenuRoot = KServiceGroup::group(g->relPath()); + if (subMenuRoot->childCount() == 0) + { + continue; + } + + // Ignore dotfiles. + if ((g->name().at(0) == '.')) + { + continue; + } + + // Item names may contain ampersands. To avoid them being converted + // to accelerators, replace each ampersand with two ampersands. + groupCaption.replace("&", "&&"); + + PrefMenu* m = new PrefMenu(g->name(), g->relPath(), this); + m->setCaption(groupCaption); + + int newId = insertItem(KickerLib::menuIconSet(g->icon()), groupCaption, m, id++); + m_entryMap.insert(newId, static_cast<KSycocaEntry*>(g)); + // We have to delete the sub menu our selves! (See Qt docs.) + m_subMenus.append(m); + } + else if (e->isType(KST_KService)) + { + KService::Ptr s(static_cast<KService *>(e)); + insertMenuItem(s, id++, -1, &suppressGenericNames); + } + else if (e->isType(KST_KServiceSeparator)) + { + insertSeparator(); + } + } + + setInitialized(true); +} + +void PrefMenu::slotExec(int id) +{ + if (!m_entryMap.contains(id)) + { + return; + } + + kapp->propagateSessionManager(); + KSycocaEntry *e = m_entryMap[id]; + KService::Ptr service = static_cast<KService *>(e); + TDEApplication::startServiceByDesktopPath(service->desktopEntryPath(), + TQStringList(), 0, 0, 0, "", true); + m_dragStartPos = TQPoint(-1,-1); +} + +void PrefMenu::clearOnClose() +{ + if (!initialized()) + { + return; + } + + m_clearOnClose = isVisible(); + if (!m_clearOnClose) + { + // we aren't visible right now so clear immediately + slotClear(); + } +} + +void PrefMenu::slotClear() +{ + if( isVisible()) + { + // QPopupMenu's aboutToHide() is emitted before the popup is really hidden, + // and also before a click in the menu is handled, so do the clearing + // only after that has been handled + TQTimer::singleShot( 100, this, TQT_SLOT( slotClear())); + return; + } + + m_entryMap.clear(); + KPanelMenu::slotClear(); + m_subMenus.clear(); +} + +void PrefMenu::aboutToClose() +{ + if (m_clearOnClose) + { + m_clearOnClose = false; + slotClear(); + } +} + +void PrefMenu::launchControlCenter() +{ + TDEApplication::startServiceByDesktopName("kcontrol", TQStringList(), + 0, 0, 0, "", true); +} + + +void PrefMenu::dragObjectDestroyed() +{ + if (KURLDrag::target() != this) + { + close(); + } +} + +#include "prefmenu.moc" diff --git a/kicker/menuext/prefmenu/prefmenu.desktop b/kicker/menuext/prefmenu/prefmenu.desktop new file mode 100644 index 000000000..88b0438f6 --- /dev/null +++ b/kicker/menuext/prefmenu/prefmenu.desktop @@ -0,0 +1,143 @@ +[Desktop Entry] +Name=Trinity Control Center +Name[af]=Beheer Sentrum +Name[ar]=مركز التحكم +Name[az]=İdarə Mərkəzi +Name[be]=Цэнтр кіравання +Name[bg]=Контролен център +Name[bn]=নিয়ন্ত্রণ কেন্দ্র +Name[br]=Kreizenn ren +Name[bs]=Kontrolni centar +Name[ca]=Centre de control +Name[cs]=Ovládací centrum +Name[csb]=Centróm kòntrolë +Name[cy]=Canolfan Rheoli +Name[da]=Kontrolcenter +Name[de]=Trinity-Kontrollzentrum +Name[el]=Κέντρο ελέγχου +Name[en_GB]=Control Centre +Name[eo]=Stircentro +Name[es]=Centro de control +Name[et]=Juhtimiskeskus +Name[eu]=Kontrol gunea +Name[fa]=مرکز کنترل +Name[fi]=Ohjauskeskus +Name[fr]=Centre de configuration de Trinity +Name[fy]=Konfiguraasjesintrum +Name[ga]=Lárionad Rialaithe +Name[gl]=Centro de Control +Name[he]=מרכז הבקרה +Name[hi]=नियंत्रण केंद्र +Name[hr]=Upravljačko središte +Name[hu]=Vezérlőpult +Name[id]=Pusat Kontrol +Name[is]=Stjórnborð +Name[it]=Centro di controllo di Trinity +Name[ja]=コントロールセンター +Name[ka]=საკონტროლო ცენტრი +Name[kk]=Басқару орталығы +Name[km]=មជ្ឈមណ្ឌលបញ្ជា +Name[ko]=제어판 모듈 +Name[lo]=ສູນຄວບຄຸມ +Name[lt]=Valdymo centras +Name[lv]=Vadības Centrs +Name[mk]=Контролен центар +Name[mn]=Удирдах төв +Name[ms]=Pusat Kawalan +Name[mt]=Ċentru tal-Kontroll +Name[nb]=Kontrollpanel +Name[nds]=Kuntrullzentrum +Name[ne]=नियन्त्रण केन्द्र +Name[nl]=Configuratiecentrum +Name[nn]=Kontrollsenter +Name[nso]=Bogare bja Taolo +Name[oc]=Centre de control +Name[pa]=ਕੰਟਰੋਲ ਕੇਂਦਰ +Name[pl]=Centrum sterowania +Name[pt]=Centro de Controlo +Name[pt_BR]=Centro de Controle +Name[ro]=Centrul de control +Name[ru]=Центр управления +Name[rw]=Kugenzura Hagati +Name[se]=Stivrenguovddáš +Name[sk]=Ovládacie Centrum +Name[sl]=Nadzorno središče +Name[sr]=Контролни центар +Name[sr@Latn]=Kontrolni centar +Name[ss]=Sikhungo sekulawula +Name[sv]=Inställningscentralen +Name[ta]=கட்டுப்பாட்டு மையம் +Name[te]=అధికార కేంద్రం +Name[tg]=Маркази контрол +Name[th]=ศูนย์ควบคุม +Name[tr]=Kontrol Merkezi +Name[tt]=İdärä Üzäge +Name[uk]=Центр керування +Name[uz]=Boshqaruv markazi +Name[uz@cyrillic]=Бошқарув маркази +Name[ven]=Senthara ya vhulanguli +Name[vi]=Trung tâm Điều khiển +Name[wa]=Cinte di contrôle +Name[xh]=Umbindi Wolawulo +Name[zh_CN]=控制中心 +Name[zh_TW]=控制中心 +Name[zu]=Indawo Yokulawula +Comment=Trinity Control Center modules menu +Comment[af]=Beheer Sentrum Modules kieslys +Comment[ar]=قائمة وحدات مركز التحكّم +Comment[be]=Меню модуляў Цэнтра кіравання +Comment[bg]=Меню на модулите в контролния център +Comment[bn]=বিভিন্ন নিয়ন্ত্রণ কেন্দ্র মডিউল সম্বলিত মেনু +Comment[ca]=Menú dels mòduls del centre de control +Comment[cs]=Nabídka modulů Ovládacího centra +Comment[csb]=Menu mòdułów Centróm kòntrolë +Comment[da]=Menu med moduler i kontrolcentret +Comment[de]=Das Menü für Kontrollzentrum-Module +Comment[el]=Μενού αρθρωμάτων κέντρου ελέγχου +Comment[en_GB]=Control Centre modules menu +Comment[eo]=Menuo de Stircentraj Moduloj +Comment[es]=Menú de los módulos del Centro de control +Comment[et]=Juhtimiskeskuse moodulite menüü +Comment[eu]=Kontrol gunearen moduluen menua +Comment[fa]=گزینگان پیمانههای مرکز کنترل +Comment[fi]=Ohjauskeskuksen moduulivalikko +Comment[fr]=Menu des modules du Centre de configuration de Trinity +Comment[fy]=Menu mei Konfiguraasjemodules +Comment[gl]=Menu dos Módulos do Centro de Control +Comment[he]=תפריט מודולי מרכז בקרה +Comment[hr]=Izbornik modula upravljačkog središta +Comment[hu]=Menü a Vezérlőpult moduljaival +Comment[is]=Valmynd stjórnborðseininga +Comment[it]=Menu dei moduli del centro di controllo di Trinity +Comment[ja]=コントロールセンターモジュールメニュー +Comment[kk]=Басқару орталықтың модульдер мәзірі +Comment[km]=ម៉ឺនុយម៉ូឌុលមជ្ឈមណ្ឌលបញ្ជា +Comment[ko]=제어판 모듈 +Comment[lt]=Valdymo centro modulių meniu +Comment[mk]=Мени со модулите од Контролниот центар +Comment[nb]=Meny for kontrollpanelmoduler +Comment[nds]=Kuntrullzentrum-Modulen +Comment[ne]=नियन्त्रण केन्द्र मोड्युल मेनु +Comment[nl]=Menu met Configuratiemodules +Comment[nn]=Meny for kontrollsentermodular +Comment[pa]=ਕੰਟਰੋਲ ਕੇਂਦਰ ਮੈਡੀਊਲ ਮੇਨੂ +Comment[pl]=Menu modułów Centrum sterowania +Comment[pt]=Menu de módulos do Centro de Controlo +Comment[pt_BR]=Menu dos módulos do Centro de Controle +Comment[ru]=Модули Центра управления +Comment[sk]=Menu pre moduly Ovládacieho centra +Comment[sl]=Meni z moduli Nadzornega središča +Comment[sr]=Мени модула Контролног центра +Comment[sr@Latn]=Meni modula Kontrolnog centra +Comment[sv]=Meny med moduler i Inställningscentralen +Comment[th]=เมนูของโมดูลของศูนย์ควบคุม +Comment[tr]=Kontrol Merkezi modülleri menüsü +Comment[uk]=Меню модулів в Центрі керування +Comment[uz]=Boshqaruv markazining modullari +Comment[uz@cyrillic]=Бошқарув марказининг модуллари +Comment[vi]=Trung tâm điều khiển mô đun thực đơn +Comment[wa]=Dressêye des modules do cinte di contrôle +Comment[zh_CN]=控制中心模块菜单 +Comment[zh_TW]=控制中心模組選單 +Icon=kcontrol +X-TDE-Library=kickermenu_prefmenu diff --git a/kicker/menuext/prefmenu/prefmenu.h b/kicker/menuext/prefmenu/prefmenu.h new file mode 100644 index 000000000..10befe6b2 --- /dev/null +++ b/kicker/menuext/prefmenu/prefmenu.h @@ -0,0 +1,74 @@ +/***************************************************************** + +Copyright (c) 1996-2002 the kicker authors. See file AUTHORS. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************/ + +#ifndef _prefmenu_h_ +#define _prefmenu_h_ + +#include <tqmap.h> + +#include <kpanelmenu.h> +#include <tdesycocaentry.h> + +typedef TQMap<int, KSycocaEntry::Ptr> EntryMap; +typedef TQPtrList<TQPopupMenu> PopupMenuList; + +class PrefMenu : public KPanelMenu +{ + Q_OBJECT + + public: + PrefMenu(TQWidget *parent, + const char *name, + const TQStringList & /*args*/); + PrefMenu(const TQString& label, + const TQString& root, + TQWidget *parent); + ~PrefMenu(); + + protected: + void insertMenuItem(KService::Ptr & s, + int nId, + int nIndex= -1, + const TQStringList *suppressGenericNames = 0); + virtual void mousePressEvent(TQMouseEvent *); + virtual void mouseMoveEvent(TQMouseEvent *); + virtual void dragEnterEvent(TQDragEnterEvent *); + virtual void dragLeaveEvent(TQDragLeaveEvent *); + + bool m_clearOnClose; + TQString m_root; + TQPoint m_dragStartPos; + EntryMap m_entryMap; + PopupMenuList m_subMenus; + + protected slots: + void initialize(); + void slotExec(int id); // from KPanelMenu + void slotClear(); // from KPanelMenu + void clearOnClose(); + void aboutToClose(); + void launchControlCenter(); + void dragObjectDestroyed(); +}; + +#endif |