From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kicker/menuext/prefmenu/Makefile.am | 17 ++ kicker/menuext/prefmenu/prefmenu.cpp | 394 +++++++++++++++++++++++++++++++ kicker/menuext/prefmenu/prefmenu.desktop | 135 +++++++++++ kicker/menuext/prefmenu/prefmenu.h | 74 ++++++ 4 files changed, 620 insertions(+) create mode 100644 kicker/menuext/prefmenu/Makefile.am create mode 100644 kicker/menuext/prefmenu/prefmenu.cpp create mode 100644 kicker/menuext/prefmenu/prefmenu.desktop create mode 100644 kicker/menuext/prefmenu/prefmenu.h (limited to 'kicker/menuext/prefmenu') diff --git a/kicker/menuext/prefmenu/Makefile.am b/kicker/menuext/prefmenu/Makefile.am new file mode 100644 index 000000000..2ccbb4ba2 --- /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_KDEUI) $(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..dd157d2cb --- /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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "global.h" +#include "kickerSettings.h" +#include "prefmenu.h" + +K_EXPORT_KICKER_MENUEXT(prefmenu, PrefMenu) + +const int idStart = 4242; + +PrefMenu::PrefMenu(QWidget *parent, + const char *name, + const QStringList &/*args*/) + : KPanelMenu(i18n("Settings"), parent, name), + m_clearOnClose(false) +{ +} + +PrefMenu::PrefMenu(const QString& label, + const QString& root, + QWidget *parent) + : KPanelMenu(label, parent), + m_clearOnClose(false), + m_root(root) +{ + m_subMenus.setAutoDelete(true); + + connect(KSycoca::self(), SIGNAL(databaseChanged()), + this, SLOT(clearOnClose())); + + connect(this, SIGNAL(aboutToHide()), + this, SLOT(aboutToClose())); +} + +PrefMenu::~PrefMenu() +{ +} + +void PrefMenu::insertMenuItem(KService::Ptr& s, + int nId, + int nIndex, + const QStringList *suppressGenericNames) +{ + QString serviceName = s->name(); + // add comment + QString comment = s->genericName(); + if (!comment.isEmpty()) + { + if (KickerSettings::menuEntryFormat() == KickerSettings::NameAndDescription) + { + if (!suppressGenericNames || + !suppressGenericNames->contains(s->untranslatedGenericName())) + { + serviceName = QString("%1 (%2)").arg(serviceName).arg(comment); + } + } + else if (KickerSettings::menuEntryFormat() == KickerSettings::DescriptionAndName) + { + serviceName = QString("%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(s)); +} + +void PrefMenu::mousePressEvent(QMouseEvent * ev) +{ + m_dragStartPos = ev->pos(); + KPanelMenu::mousePressEvent(ev); +} + +void PrefMenu::mouseMoveEvent(QMouseEvent * ev) +{ + KPanelMenu::mouseMoveEvent(ev); + + if ((ev->state() & LeftButton) != LeftButton) + { + return; + } + + QPoint p = ev->pos() - m_dragStartPos; + if (p.manhattanLength() <= QApplication::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]; + + QPixmap icon; + KURL url; + + switch (e->sycocaType()) + { + case KST_KService: + { + icon = static_cast(e)->pixmap(KIcon::Small); + QString filePath = static_cast(e)->desktopEntryPath(); + if (filePath[0] != '/') + { + filePath = locate("apps", filePath); + } + url.setPath(filePath); + break; + } + + case KST_KServiceGroup: + { + icon = KGlobal::iconLoader()->loadIcon(static_cast(e)->icon(), + KIcon::Small); + url = "programs:/" + static_cast(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, SIGNAL(destroyed()), this, 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 = QPoint(-1,-1); +} + +void PrefMenu::dragEnterEvent(QDragEnterEvent *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(QDragLeaveEvent */*event*/) +{ + // see PrefMenu::dragEnterEvent why this is nescessary + if (!frameGeometry().contains(QCursor::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 = QPoint(-1,-1); + + if (m_root.isEmpty()) + { + insertItem(KickerLib::menuIconSet("kcontrol"), + i18n("Control Center"), + this, 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; + + QStringList 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(e)); + QString 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(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(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(e); + KApplication::startServiceByDesktopPath(service->desktopEntryPath(), + QStringList(), 0, 0, 0, "", true); + m_dragStartPos = QPoint(-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 + QTimer::singleShot( 100, this, SLOT( slotClear())); + return; + } + + m_entryMap.clear(); + KPanelMenu::slotClear(); + m_subMenus.clear(); +} + +void PrefMenu::aboutToClose() +{ + if (m_clearOnClose) + { + m_clearOnClose = false; + slotClear(); + } +} + +void PrefMenu::launchControlCenter() +{ + KApplication::startServiceByDesktopName("kcontrol", QStringList(), + 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..f3206d4e3 --- /dev/null +++ b/kicker/menuext/prefmenu/prefmenu.desktop @@ -0,0 +1,135 @@ +[Desktop Entry] +Name=Settings +Name[af]=Instellings +Name[ar]=التعيينات +Name[az]=Qurğular +Name[be]=Настаўленні +Name[bg]=Настройки +Name[bn]=সেটিংস +Name[br]=Dibarzhoù +Name[bs]=Postavke +Name[ca]=Preferències +Name[cs]=Nastavení +Name[csb]=Ùstôw +Name[cy]=Gosodiadau +Name[da]=Opsætning +Name[de]=Einstellungen +Name[el]=Ρυθμίσεις +Name[eo]=Agordo +Name[es]=Preferencias +Name[et]=Seadistused +Name[eu]=Ezarpenak +Name[fa]=تنظیمات +Name[fi]=Asetukset +Name[fr]=Configuration +Name[fy]=Ynstellings +Name[ga]=Socruithe +Name[gl]=Opcións +Name[he]=הגדרות +Name[hi]=विन्यास +Name[hr]=Postavke +Name[hsb]=Nastajenja +Name[hu]=Beállítások +Name[is]=Stillingar +Name[it]=Impostazioni +Name[ja]=設定 +Name[ka]=პარამეტრები +Name[kk]=Параметрлері +Name[km]=ការ​កំណត់ +Name[ko]=설정 +Name[lt]=Parinktys +Name[lv]=Parametri +Name[mk]=Поставувања +Name[mn]=Тохируулга +Name[ms]=Tempatan +Name[nb]=Innstillinger +Name[nds]=Instellen +Name[ne]=सेटिङ +Name[nl]=Instellingen +Name[nn]=Innstillingar +Name[pa]=ਸੈਟਿੰਗ +Name[pl]=Ustawienia +Name[pt]=Configuração +Name[pt_BR]=Configurações +Name[ro]=Setări +Name[ru]=Настройка +Name[rw]=Amagenamiterere +Name[se]=Heivehusat +Name[sk]=Nastavenia +Name[sl]=Nastavitve +Name[sr]=Поставке +Name[sr@Latn]=Postavke +Name[sv]=Inställningar +Name[ta]=அமைப்புகள் +Name[te]=అమరికలు +Name[tg]=Танзимот +Name[th]=ตั้งค่าต่างๆ +Name[tr]=Ayarlar +Name[tt]=Caylaw +Name[uk]=Параметри +Name[uz]=Moslamalar +Name[uz@cyrillic]=Мосламалар +Name[vi]=Thiết lập +Name[wa]=Apontiaedjes +Name[zh_CN]=设置 +Name[zh_TW]=設定 +Comment=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 +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 +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=package_settings + +X-KDE-Library=kickermenu_prefmenu diff --git a/kicker/menuext/prefmenu/prefmenu.h b/kicker/menuext/prefmenu/prefmenu.h new file mode 100644 index 000000000..99c3772fc --- /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 + +#include +#include + +typedef QMap EntryMap; +typedef QPtrList PopupMenuList; + +class PrefMenu : public KPanelMenu +{ + Q_OBJECT + + public: + PrefMenu(QWidget *parent, + const char *name, + const QStringList & /*args*/); + PrefMenu(const QString& label, + const QString& root, + QWidget *parent); + ~PrefMenu(); + + protected: + void insertMenuItem(KService::Ptr & s, + int nId, + int nIndex= -1, + const QStringList *suppressGenericNames = 0); + virtual void mousePressEvent(QMouseEvent *); + virtual void mouseMoveEvent(QMouseEvent *); + virtual void dragEnterEvent(QDragEnterEvent *); + virtual void dragLeaveEvent(QDragLeaveEvent *); + + bool m_clearOnClose; + QString m_root; + QPoint 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 -- cgit v1.2.1