From b7658a0d5eca24a9d37c6e04f88298ef02389db0 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 25 Jan 2013 16:27:34 -0600 Subject: Fix FTBFS resulting from KCModule rename --- kcmshell/main.cpp | 6 +- kdewidgets/pics/CMakeLists.txt | 2 +- kdewidgets/pics/Makefile.am | 2 +- kdewidgets/pics/kcmodule.png | Bin 1340 -> 0 bytes kdewidgets/pics/tdecmodule.png | Bin 0 -> 1340 bytes kio/CMakeLists.txt | 2 +- kio/Makefile.am | 2 +- kio/kcmodule.desktop | 109 ------ kio/tdecmodule.desktop | 109 ++++++ krandr/randr.h | 2 +- kresources/kcmkresources.h | 2 +- kutils/CMakeLists.txt | 12 +- kutils/Makefile.am | 16 +- kutils/groups.dox | 2 +- kutils/kcmodulecontainer.cpp | 258 -------------- kutils/kcmodulecontainer.h | 207 ------------ kutils/kcmoduleinfo.cpp | 242 -------------- kutils/kcmoduleinfo.h | 296 ---------------- kutils/kcmoduleloader.cpp | 302 ----------------- kutils/kcmoduleloader.h | 220 ------------ kutils/kcmoduleproxy.cpp | 650 ------------------------------------ kutils/kcmoduleproxy.h | 358 -------------------- kutils/kcmoduleproxyIface.h | 121 ------- kutils/kcmoduleproxyIfaceImpl.cpp | 129 ------- kutils/kcmoduleproxyIfaceImpl.h | 97 ------ kutils/kcmultidialog.cpp | 4 +- kutils/kcmultidialog.h | 2 +- kutils/kpluginselector.cpp | 10 +- kutils/ksettings/dialog.cpp | 2 +- kutils/ksettings/pluginpage.h | 2 +- kutils/tdecmodulecontainer.cpp | 258 ++++++++++++++ kutils/tdecmodulecontainer.h | 207 ++++++++++++ kutils/tdecmoduleinfo.cpp | 242 ++++++++++++++ kutils/tdecmoduleinfo.h | 296 ++++++++++++++++ kutils/tdecmoduleloader.cpp | 302 +++++++++++++++++ kutils/tdecmoduleloader.h | 220 ++++++++++++ kutils/tdecmoduleproxy.cpp | 650 ++++++++++++++++++++++++++++++++++++ kutils/tdecmoduleproxy.h | 358 ++++++++++++++++++++ kutils/tdecmoduleproxyIface.h | 121 +++++++ kutils/tdecmoduleproxyIfaceImpl.cpp | 129 +++++++ kutils/tdecmoduleproxyIfaceImpl.h | 97 ++++++ tdecore/kdebug.areas | 2 +- tdeui/CMakeLists.txt | 4 +- tdeui/MAINTAINERS | 2 +- tdeui/Makefile.am | 4 +- tdeui/kcmodule.cpp | 220 ------------ tdeui/kcmodule.h | 361 -------------------- tdeui/tdecmodule.cpp | 220 ++++++++++++ tdeui/tdecmodule.h | 361 ++++++++++++++++++++ win/pro_files/tdeui/tdeui.pro | 2 +- 50 files changed, 3611 insertions(+), 3611 deletions(-) delete mode 100644 kdewidgets/pics/kcmodule.png create mode 100644 kdewidgets/pics/tdecmodule.png delete mode 100644 kio/kcmodule.desktop create mode 100644 kio/tdecmodule.desktop delete mode 100644 kutils/kcmodulecontainer.cpp delete mode 100644 kutils/kcmodulecontainer.h delete mode 100644 kutils/kcmoduleinfo.cpp delete mode 100644 kutils/kcmoduleinfo.h delete mode 100644 kutils/kcmoduleloader.cpp delete mode 100644 kutils/kcmoduleloader.h delete mode 100644 kutils/kcmoduleproxy.cpp delete mode 100644 kutils/kcmoduleproxy.h delete mode 100644 kutils/kcmoduleproxyIface.h delete mode 100644 kutils/kcmoduleproxyIfaceImpl.cpp delete mode 100644 kutils/kcmoduleproxyIfaceImpl.h create mode 100644 kutils/tdecmodulecontainer.cpp create mode 100644 kutils/tdecmodulecontainer.h create mode 100644 kutils/tdecmoduleinfo.cpp create mode 100644 kutils/tdecmoduleinfo.h create mode 100644 kutils/tdecmoduleloader.cpp create mode 100644 kutils/tdecmoduleloader.h create mode 100644 kutils/tdecmoduleproxy.cpp create mode 100644 kutils/tdecmoduleproxy.h create mode 100644 kutils/tdecmoduleproxyIface.h create mode 100644 kutils/tdecmoduleproxyIfaceImpl.cpp create mode 100644 kutils/tdecmoduleproxyIfaceImpl.h delete mode 100644 tdeui/kcmodule.cpp delete mode 100644 tdeui/kcmodule.h create mode 100644 tdeui/tdecmodule.cpp create mode 100644 tdeui/tdecmodule.h diff --git a/kcmshell/main.cpp b/kcmshell/main.cpp index 5d71fbaa7..29aba0501 100644 --- a/kcmshell/main.cpp +++ b/kcmshell/main.cpp @@ -30,9 +30,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/kdewidgets/pics/CMakeLists.txt b/kdewidgets/pics/CMakeLists.txt index 8e7ff6b13..b122c8b28 100644 --- a/kdewidgets/pics/CMakeLists.txt +++ b/kdewidgets/pics/CMakeLists.txt @@ -15,7 +15,7 @@ install( FILES klineedit.png ktextbrowser.png kpasswordedit.png kdatewidget.png kfontrequester.png kurlrequester.png kcombobox.png kiconview.png kintspinbox.png kled.png ksqueezedtextlabel.png kprogress.png - kurllabel.png kruler.png kcmodule.png kdoublespinbox.png + kurllabel.png kruler.png tdecmodule.png kdoublespinbox.png kdoublenuminput.png klistbox.png klistview.png kactivelabel.png kiconbutton.png kcolorcombo.png khsselector.png kcolorbutton.png kgradientselector.png kdualcolorbutton.png ktimewidget.png diff --git a/kdewidgets/pics/Makefile.am b/kdewidgets/pics/Makefile.am index 83e8aa357..aeda8e4cb 100644 --- a/kdewidgets/pics/Makefile.am +++ b/kdewidgets/pics/Makefile.am @@ -1,7 +1,7 @@ kdewidgetsdata_DATA = klineedit.png ktextbrowser.png kpasswordedit.png kdatewidget.png \ kfontrequester.png kurlrequester.png kcombobox.png kiconview.png kintspinbox.png \ kled.png ksqueezedtextlabel.png kprogress.png kurllabel.png \ - kruler.png kcmodule.png kdoublespinbox.png kdoublenuminput.png \ + kruler.png tdecmodule.png kdoublespinbox.png kdoublenuminput.png \ klistbox.png klistview.png kactivelabel.png kiconbutton.png \ kcolorcombo.png khsselector.png kcolorbutton.png \ kgradientselector.png kdualcolorbutton.png ktimewidget.png \ diff --git a/kdewidgets/pics/kcmodule.png b/kdewidgets/pics/kcmodule.png deleted file mode 100644 index 1a6a9dc17..000000000 Binary files a/kdewidgets/pics/kcmodule.png and /dev/null differ diff --git a/kdewidgets/pics/tdecmodule.png b/kdewidgets/pics/tdecmodule.png new file mode 100644 index 000000000..1a6a9dc17 Binary files /dev/null and b/kdewidgets/pics/tdecmodule.png differ diff --git a/kio/CMakeLists.txt b/kio/CMakeLists.txt index c89f33e99..3bd4ba8b7 100644 --- a/kio/CMakeLists.txt +++ b/kio/CMakeLists.txt @@ -41,7 +41,7 @@ install( FILES magic DESTINATION ${MIME_INSTALL_DIR} ) install( FILES application.desktop kurifilterplugin.desktop kcomprfilter.desktop kscan.desktop kdatatool.desktop - kfileplugin.desktop kcmodule.desktop + kfileplugin.desktop tdecmodule.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) install( FILES kioslave.upd DESTINATION ${KCONF_UPDATE_INSTALL_DIR} ) diff --git a/kio/Makefile.am b/kio/Makefile.am index 4a28986ef..b639d43df 100644 --- a/kio/Makefile.am +++ b/kio/Makefile.am @@ -37,7 +37,7 @@ libkio_la_LIBADD = kssl/libkssl.la kio/libkiocore.la \ kde_mime_DATA = magic kde_servicetypes_DATA = application.desktop kurifilterplugin.desktop \ kcomprfilter.desktop kscan.desktop kdatatool.desktop \ - kfileplugin.desktop kcmodule.desktop + kfileplugin.desktop tdecmodule.desktop EXTRA_DIST = $(kde_mime_DATA) diff --git a/kio/kcmodule.desktop b/kio/kcmodule.desktop deleted file mode 100644 index 5cbe9b786..000000000 --- a/kio/kcmodule.desktop +++ /dev/null @@ -1,109 +0,0 @@ -[Desktop Entry] -Type=ServiceType -X-TDE-ServiceType=TDECModule -Name=TDE Control Module -Name[af]=TDE Beheer Module -Name[ar]=وحدة تحكم كيدي -Name[az]=TDE İdarə Modulu -Name[be]=Модуль кіравання TDE -Name[bg]=Контролен модул на TDE -Name[bn]=কে.ডি.ই. নিয়ন্ত্রণ মডিউল -Name[br]=Mollad kreizenn ren TDE -Name[bs]=TDE kontrolni modul -Name[ca]=Mòdul de control del TDE -Name[cs]=Ovládací modul TDE -Name[csb]=Kòntrolny mòduł pùltu TDE -Name[cy]=Modiwl Rheolaeth TDE -Name[da]=TDE-kontrolmodul -Name[de]=TDE-Kontrollmodul -Name[el]=Άρθρωμα ελέγχου του TDE -Name[eo]=TDE Agordmodulo -Name[es]=Módulo de control de TDE -Name[et]=TDE juhtimismoodul -Name[eu]=TDEren kontrol-modulua -Name[fa]=پیمانۀ کنترل TDE -Name[fi]=TDE:n ohjausmoduuli -Name[fr]=Module de configuration de TDE -Name[fy]=TDE konfiguraasjemodule -Name[ga]=Modúl Rialaithe TDE -Name[gl]=Módulo de Controlo de TDE -Name[he]=מודול תצורה של TDE -Name[hi]=केडीई नियंत्रण घटक -Name[hr]=TDE kontrolni modul -Name[hu]=TDE beállítómodul -Name[id]=Modul Kontrol TDE -Name[is]=TDE stjórneining -Name[it]=Modulo di controllo TDE -Name[ja]=TDE コントロールモジュール -Name[ka]=TDE-ს კონტროლის პულტი -Name[kk]=TDE басқару модулі -Name[km]=ម៉ូឌុល​ត្រួត​ពិនិត្យ​របស់ TDE -Name[ko]=TDE 제어 모듈 -Name[lb]=TDE-Kontrollmodul -Name[lt]=TDE valdymo modulis -Name[lv]=TDE kontroles modulis -Name[mk]=TDE Контролен Модул -Name[mn]=TDED-Хяналтын Модул -Name[ms]=Modul Kawalan TDE -Name[nb]=TDE kontrollpanel-modul -Name[nds]=TDE-Kuntrullmoduul -Name[ne]=TDE नियन्त्रण मोड्युल -Name[nl]=TDE Configuratiemodule -Name[nn]=TDE-kontrollmodul -Name[nso]=Seripa sa Taolo ya TDE -Name[pa]=TDE ਕੰਟਰੋਲ ਮੈਡੀਊਲ -Name[pl]=Moduł centrum sterowania TDE -Name[pt]=Módulo de Controlo do TDE -Name[pt_BR]=Módulo de Controle do TDE -Name[ro]=Modul de control TDE -Name[ru]=Модуль управления TDE -Name[rw]=Igice cy'Igenzura TDE -Name[se]=TDE stivrrenmoduvla -Name[sk]=Ovládací modul TDE -Name[sl]=Nadzorni modul TDE -Name[sq]=Modula Kontrolues - TDE -Name[sr]=TDE-ов контролни модул -Name[sr@Latn]=TDE-ov kontrolni modul -Name[ss]=Sahluko sekulawula se TDE -Name[sv]=TDE-inställningsmodul -Name[ta]=கேடிஇ கட்டுப்பாட்டு கூறு -Name[te]=కెడిఈ నియంత్రణ మాడ్యూల్ -Name[tg]=Модулӣ TDE Control -Name[th]=โมดูลควบคุมของ TDE -Name[tr]=TDE Kontrol Modülü -Name[tt]=TDE İdärä Modulı -Name[uk]=Модуль центра керування TDE -Name[uz]=TDE boshqaruv moduli -Name[uz@cyrillic]=TDE бошқарув модули -Name[ven]=Phanele ndangula ya phirinthara -Name[vi]=Mô-đun điều khiển TDE -Name[wa]=Module di contrôle TDE -Name[xh]=Ulawulo Lwesicatshulwa we TDE -Name[zh_CN]=TDE 控制模块 -Name[zh_HK]=TDE 控制模組 -Name[zh_TW]=TDE 控制模組 -Name[zu]=Ingxenye ye-TDE Control - -[PropertyDef::X-TDE-FactoryName] -Type=TQString - -[PropertyDef::X-TDE-RootOnly] -Type=bool - -# a list of all components this KCM belongs to -[PropertyDef::X-TDE-ParentComponents] -Type=TQStringList - -# the id of the parent in the TreeList -[PropertyDef::X-TDE-CfgDlgHierarchy] -Type=TQString - -# sets the order of the modules in the TreeList/IconList -[PropertyDef::X-TDE-Weight] -Type=int - -[PropertyDef::X-TDE-RootOnly] -Type=bool - -[PropertyDef::X-TDE-IsHiddenByDefault] -Type=bool diff --git a/kio/tdecmodule.desktop b/kio/tdecmodule.desktop new file mode 100644 index 000000000..5cbe9b786 --- /dev/null +++ b/kio/tdecmodule.desktop @@ -0,0 +1,109 @@ +[Desktop Entry] +Type=ServiceType +X-TDE-ServiceType=TDECModule +Name=TDE Control Module +Name[af]=TDE Beheer Module +Name[ar]=وحدة تحكم كيدي +Name[az]=TDE İdarə Modulu +Name[be]=Модуль кіравання TDE +Name[bg]=Контролен модул на TDE +Name[bn]=কে.ডি.ই. নিয়ন্ত্রণ মডিউল +Name[br]=Mollad kreizenn ren TDE +Name[bs]=TDE kontrolni modul +Name[ca]=Mòdul de control del TDE +Name[cs]=Ovládací modul TDE +Name[csb]=Kòntrolny mòduł pùltu TDE +Name[cy]=Modiwl Rheolaeth TDE +Name[da]=TDE-kontrolmodul +Name[de]=TDE-Kontrollmodul +Name[el]=Άρθρωμα ελέγχου του TDE +Name[eo]=TDE Agordmodulo +Name[es]=Módulo de control de TDE +Name[et]=TDE juhtimismoodul +Name[eu]=TDEren kontrol-modulua +Name[fa]=پیمانۀ کنترل TDE +Name[fi]=TDE:n ohjausmoduuli +Name[fr]=Module de configuration de TDE +Name[fy]=TDE konfiguraasjemodule +Name[ga]=Modúl Rialaithe TDE +Name[gl]=Módulo de Controlo de TDE +Name[he]=מודול תצורה של TDE +Name[hi]=केडीई नियंत्रण घटक +Name[hr]=TDE kontrolni modul +Name[hu]=TDE beállítómodul +Name[id]=Modul Kontrol TDE +Name[is]=TDE stjórneining +Name[it]=Modulo di controllo TDE +Name[ja]=TDE コントロールモジュール +Name[ka]=TDE-ს კონტროლის პულტი +Name[kk]=TDE басқару модулі +Name[km]=ម៉ូឌុល​ត្រួត​ពិនិត្យ​របស់ TDE +Name[ko]=TDE 제어 모듈 +Name[lb]=TDE-Kontrollmodul +Name[lt]=TDE valdymo modulis +Name[lv]=TDE kontroles modulis +Name[mk]=TDE Контролен Модул +Name[mn]=TDED-Хяналтын Модул +Name[ms]=Modul Kawalan TDE +Name[nb]=TDE kontrollpanel-modul +Name[nds]=TDE-Kuntrullmoduul +Name[ne]=TDE नियन्त्रण मोड्युल +Name[nl]=TDE Configuratiemodule +Name[nn]=TDE-kontrollmodul +Name[nso]=Seripa sa Taolo ya TDE +Name[pa]=TDE ਕੰਟਰੋਲ ਮੈਡੀਊਲ +Name[pl]=Moduł centrum sterowania TDE +Name[pt]=Módulo de Controlo do TDE +Name[pt_BR]=Módulo de Controle do TDE +Name[ro]=Modul de control TDE +Name[ru]=Модуль управления TDE +Name[rw]=Igice cy'Igenzura TDE +Name[se]=TDE stivrrenmoduvla +Name[sk]=Ovládací modul TDE +Name[sl]=Nadzorni modul TDE +Name[sq]=Modula Kontrolues - TDE +Name[sr]=TDE-ов контролни модул +Name[sr@Latn]=TDE-ov kontrolni modul +Name[ss]=Sahluko sekulawula se TDE +Name[sv]=TDE-inställningsmodul +Name[ta]=கேடிஇ கட்டுப்பாட்டு கூறு +Name[te]=కెడిఈ నియంత్రణ మాడ్యూల్ +Name[tg]=Модулӣ TDE Control +Name[th]=โมดูลควบคุมของ TDE +Name[tr]=TDE Kontrol Modülü +Name[tt]=TDE İdärä Modulı +Name[uk]=Модуль центра керування TDE +Name[uz]=TDE boshqaruv moduli +Name[uz@cyrillic]=TDE бошқарув модули +Name[ven]=Phanele ndangula ya phirinthara +Name[vi]=Mô-đun điều khiển TDE +Name[wa]=Module di contrôle TDE +Name[xh]=Ulawulo Lwesicatshulwa we TDE +Name[zh_CN]=TDE 控制模块 +Name[zh_HK]=TDE 控制模組 +Name[zh_TW]=TDE 控制模組 +Name[zu]=Ingxenye ye-TDE Control + +[PropertyDef::X-TDE-FactoryName] +Type=TQString + +[PropertyDef::X-TDE-RootOnly] +Type=bool + +# a list of all components this KCM belongs to +[PropertyDef::X-TDE-ParentComponents] +Type=TQStringList + +# the id of the parent in the TreeList +[PropertyDef::X-TDE-CfgDlgHierarchy] +Type=TQString + +# sets the order of the modules in the TreeList/IconList +[PropertyDef::X-TDE-Weight] +Type=int + +[PropertyDef::X-TDE-RootOnly] +Type=bool + +[PropertyDef::X-TDE-IsHiddenByDefault] +Type=bool diff --git a/krandr/randr.h b/krandr/randr.h index bec5f1b61..af3712e71 100644 --- a/krandr/randr.h +++ b/krandr/randr.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include class KTimerDialog; diff --git a/kresources/kcmkresources.h b/kresources/kcmkresources.h index 38279d29a..29adc6583 100644 --- a/kresources/kcmkresources.h +++ b/kresources/kcmkresources.h @@ -22,7 +22,7 @@ #ifndef KRESOURCES_KCMKRESOURCES_H #define KRESOURCES_KCMKRESOURCES_H -#include +#include class KRESOURCES_EXPORT KCMKResources : public TDECModule { diff --git a/kutils/CMakeLists.txt b/kutils/CMakeLists.txt index a033088cd..073ffe3a0 100644 --- a/kutils/CMakeLists.txt +++ b/kutils/CMakeLists.txt @@ -33,9 +33,9 @@ link_directories( install( FILES kfind.h kfinddialog.h kreplace.h kreplacedialog.h - kcmoduleinfo.h kcmoduleloader.h kcmultidialog.h - kmultitabbar.h kplugininfo.h kcmoduleproxy.h - kpluginselector.h kcmodulecontainer.h + tdecmoduleinfo.h tdecmoduleloader.h kcmultidialog.h + kmultitabbar.h kplugininfo.h tdecmoduleproxy.h + kpluginselector.h tdecmodulecontainer.h DESTINATION ${INCLUDE_INSTALL_DIR} ) @@ -50,10 +50,10 @@ set( target kutils ) set( ${target}_SRCS kfind.cpp kfinddialog.cpp kreplace.cpp - kreplacedialog.cpp kcmoduleinfo.cpp kcmoduleloader.cpp + kreplacedialog.cpp tdecmoduleinfo.cpp tdecmoduleloader.cpp kcmultidialog.cpp kmultitabbar.cpp kplugininfo.cpp - kcmoduleproxy.cpp kpluginselector.cpp kcmodulecontainer.cpp - kcmoduleproxyIface.skel kcmoduleproxyIfaceImpl.cpp + tdecmoduleproxy.cpp kpluginselector.cpp tdecmodulecontainer.cpp + tdecmoduleproxyIface.skel tdecmoduleproxyIfaceImpl.cpp ) tde_add_library( ${target} SHARED AUTOMOC diff --git a/kutils/Makefile.am b/kutils/Makefile.am index d8ebcf156..5ff9bd041 100644 --- a/kutils/Makefile.am +++ b/kutils/Makefile.am @@ -7,19 +7,19 @@ libkutils_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 3:0:2 libkutils_la_LIBADD = ../kio/libkio.la ksettings/libksettings.la $(LIB_QT) $(top_builddir)/dcop/libDCOP.la $(LIB_TDEUI) $(LIB_TDECORE) $(LIB_X11) libkutils_la_SOURCES = kfind.cpp kfinddialog.cpp kreplace.cpp \ - kreplacedialog.cpp kcmoduleinfo.cpp kcmoduleloader.cpp \ + kreplacedialog.cpp tdecmoduleinfo.cpp tdecmoduleloader.cpp \ kcmultidialog.cpp kmultitabbar.cpp kplugininfo.cpp \ - kcmoduleproxy.cpp kpluginselector.cpp \ - kcmodulecontainer.cpp kcmoduleproxyIface.skel \ - kcmoduleproxyIfaceImpl.cpp + tdecmoduleproxy.cpp kpluginselector.cpp \ + tdecmodulecontainer.cpp tdecmoduleproxyIface.skel \ + tdecmoduleproxyIfaceImpl.cpp include_HEADERS = kfind.h kfinddialog.h kreplace.h kreplacedialog.h \ - kcmoduleinfo.h kcmoduleloader.h kcmultidialog.h \ - kmultitabbar.h kplugininfo.h kcmoduleproxy.h \ - kpluginselector.h kcmodulecontainer.h + tdecmoduleinfo.h tdecmoduleloader.h kcmultidialog.h \ + kmultitabbar.h kplugininfo.h tdecmoduleproxy.h \ + kpluginselector.h tdecmodulecontainer.h noinst_HEADERS = kmultitabbar_p.h kpluginselector_p.h \ - kcmoduleproxyIface.h kcmoduleproxyIfaceImpl.h + tdecmoduleproxyIface.h tdecmoduleproxyIfaceImpl.h kde_servicetypes_DATA = kplugininfo.desktop diff --git a/kutils/groups.dox b/kutils/groups.dox index 95d926d73..a4e0a633f 100644 --- a/kutils/groups.dox +++ b/kutils/groups.dox @@ -27,7 +27,7 @@ namespace description for an overview. */ /** -@defgroup kcmodule KControl module classes +@defgroup tdecmodule KControl module classes Thwse classes provide the KControl module API. */ diff --git a/kutils/kcmodulecontainer.cpp b/kutils/kcmodulecontainer.cpp deleted file mode 100644 index b91ffb641..000000000 --- a/kutils/kcmodulecontainer.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2004 Frans Englich - - 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 -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kcmodulecontainer.h" -#include "kcmodulecontainer.moc" - -/***********************************************************************/ -class TDECModuleContainer::TDECModuleContainerPrivate -{ - public: - TDECModuleContainerPrivate( const TQStringList& mods ) - : modules( mods ) - , tabWidget( 0 ) - , buttons( 0 ) - , hasRootKCM( false ) - , btnRootMode( 0 ) - , btnLayout( 0 ) - , topLayout( 0 ) - {} - - TQStringList modules; - TQTabWidget *tabWidget; - int buttons; - bool hasRootKCM: 1; - KPushButton *btnRootMode; - TQHBoxLayout *btnLayout; - TQVBoxLayout *topLayout; - - -}; -/***********************************************************************/ - - - - - -/***********************************************************************/ -TDECModuleContainer::TDECModuleContainer( TQWidget* parent, const char* name, - const TQString& mods ) - : TDECModule( parent, name ) -{ - d = new TDECModuleContainerPrivate( TQStringList::split( ",", TQString(mods).remove( " " )) ); - init(); -} - -TDECModuleContainer::TDECModuleContainer( TQWidget* parent, const char* name, - const TQStringList& mods ) - : TDECModule( parent, name ), d( new TDECModuleContainerPrivate( mods ) ) -{ - init(); -} - -void TDECModuleContainer::init() -{ - d->topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint(), "topLayout" ); - d->tabWidget = new TQTabWidget(this, "tabWidget"); - d->tabWidget->setMargin(KDialog::marginHint()); - connect( d->tabWidget, TQT_SIGNAL( currentChanged( TQWidget* ) ), TQT_SLOT( tabSwitched( TQWidget* ) )); - d->topLayout->addWidget( d->tabWidget ); - - if ( !d->modules.isEmpty() ) - { - /* Add our modules */ - for ( TQStringList::Iterator it = d->modules.begin(); it != d->modules.end(); ++it ) - addModule( (*it) ); - - finalize(); - } - -} - -void TDECModuleContainer::finalize() -{ - setButtons( d->buttons ); - if ( d->hasRootKCM ) /* Add a root mode button */ - { - if(!d->btnLayout) /* It could already be added */ - { - d->btnLayout = new TQHBoxLayout(this, 0, 0, "btnLayout"); - d->btnRootMode = new KPushButton(KStdGuiItem::adminMode(), this, "btnRootMode"); - - d->btnLayout->addWidget( d->btnRootMode ); - d->btnLayout->addStretch(); - d->topLayout->addLayout( d->btnLayout ); - } - } -} - -void TDECModuleContainer::addModule( const TQString& module ) -{ - /* In case it doesn't exist we just silently drop it. - * This allows people to easily extend containers. - * For example, KCM monitor gamma can be in tdegraphics. - */ - if ( !KService::serviceByDesktopName( module ) ) - { - kdDebug(713) << "TDECModuleContainer: module '" << - module << "' was not found and thus not loaded" << endl; - return; - } - - if( !TDECModuleLoader::testModule( module )) - return; - - TDECModuleProxy* proxy = new TDECModuleProxy( module, false, d->tabWidget, module.latin1()); - allModules.append( proxy ); - - d->tabWidget->addTab( proxy, TQIconSet(TDEGlobal::iconLoader()->loadIcon( - proxy->moduleInfo().icon(), KIcon::Desktop)), - /* QT eats ampersands for dinner. But not this time. */ - proxy->moduleInfo().moduleName().replace( "&", "&&" )); - - d->tabWidget->setTabToolTip( proxy, proxy->moduleInfo().comment() ); - - connect( proxy, TQT_SIGNAL(changed(TDECModuleProxy *)), TQT_SLOT(moduleChanged(TDECModuleProxy *))); - - /* Collect our buttons - we go for the common deliminator */ - d->buttons = d->buttons | proxy->realModule()->buttons(); - - /* If we should add an Administrator Mode button */ - if ( proxy->moduleInfo().needsRootPrivileges() ) - d->hasRootKCM=true; - - -} - -void TDECModuleContainer::tabSwitched( TQWidget * module ) -{ - if ( !d->hasRootKCM ) - return; - - /* Not like this. Not like this. */ - disconnect( d->btnRootMode, 0, 0, 0 ); - /* Welcome to the real world huh baby? */ - - TDECModuleProxy* mod = (TDECModuleProxy *) module; - - if ( mod->moduleInfo().needsRootPrivileges() && !mod->rootMode() ) - { - d->btnRootMode->setEnabled( true ); - connect( d->btnRootMode, TQT_SIGNAL( clicked() ), - TQT_SLOT( runAsRoot() )); - connect( mod, TQT_SIGNAL( childClosed() ), - TQT_SLOT ( rootExited() )); - } - else - d->btnRootMode->setEnabled( false ); - - setQuickHelp( mod->quickHelp() ); - setAboutData( const_cast(mod->aboutData()) ); - -} - -void TDECModuleContainer::runAsRoot() -{ - if ( d->tabWidget->currentPage() ) - ( (TDECModuleProxy *) d->tabWidget->currentPage() )->runAsRoot(); - d->btnRootMode->setEnabled( false ); -} - -void TDECModuleContainer::rootExited() -{ - connect( d->btnRootMode, TQT_SIGNAL( clicked() ), TQT_SLOT( runAsRoot() )); - d->btnRootMode->setEnabled( true ); -} - -void TDECModuleContainer::save() -{ - ModuleList list = changedModules; - ModuleList::iterator it; - for ( it = list.begin() ; it !=list.end() ; ++it ) - { - (*it)->save(); - } - - emit changed( false ); - -} - -void TDECModuleContainer::load() -{ - ModuleList list = allModules; - ModuleList::iterator it; - for ( it = list.begin() ; it !=list.end() ; ++it ) - { - (*it)->load(); - } - - emit changed( false ); -} - -void TDECModuleContainer::defaults() -{ - ModuleList list = allModules; - ModuleList::iterator it; - for ( it = list.begin() ; it !=list.end() ; ++it ) - { - (*it)->defaults(); - } - - emit changed( true ); -} - - -void TDECModuleContainer::moduleChanged(TDECModuleProxy * proxy) -{ - changedModules.append( proxy ); - if( changedModules.isEmpty() ) - return; - - emit changed(true); -} - -TDECModuleContainer::~TDECModuleContainer() -{ - delete d; -} - -/***********************************************************************/ - - - - diff --git a/kutils/kcmodulecontainer.h b/kutils/kcmodulecontainer.h deleted file mode 100644 index 956b23efd..000000000 --- a/kutils/kcmodulecontainer.h +++ /dev/null @@ -1,207 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2004 Frans Englich - - 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 KCMODULECONTAINER_H -#define KCMODULECONTAINER_H - -#include -#include -#include - -#include -#include - -class TQTabWidget; -class TQWidget; -class TQVBoxLayout; - -class TDECModuleProxy; - -/** - * @ingroup kcmodule - * @brief TDECModuleContainer is a convenience class encapsulating several TDECModules. - * - * The TDECModuleContainer class is a convenience class for organizing a multiple set - * of TDECModule. TDECModuleContainer is a sub class of TDECModule and builds an interface mainly - * consisting of a tab widget where each tab contains one of the modules specified via one of the - * constructors. TDECModuleContainer can handle modules which requires root permissions. What you - * most likely want is the KCMODULECONTAINER macro. \n - * Sometimes it is of interest to detect in runtime whether a module should be loaded or not. This - * can be achieved by sub classing TDECModuleContainer, doing the probing/testing checks and then manually - * call addModule for each module which should be displayed. When all calls to addModule is done, call - * finalize() which performs some necessary final steps. - * - * @author Frans Englich - * @since 3.4 - */ -class KUTILS_EXPORT TDECModuleContainer : public TDECModule -{ - Q_OBJECT - public: - /** - * Creates a TDECModuleContainer with tabs, each one containing one of the - * specified modules in @p mods. - * - * @param parent the parent TQWidget. - * @param name the module's name. - * @param mods The list of TDECModules to be loaded. The name of each - * TDECModule is its service name, that is the name of the desktop file without - * the ".desktop" part - * - */ - TDECModuleContainer( TQWidget* parent, const char* name, const TQStringList& mods ); - - /** - * This is a convenience function, instead of building a TQStringList you - * can specify the modules in a comma separated TQString. For example; - * \code - * TDECModuleContainer* cont = TDECModuleContainer( this, "kcm_misc", TQString("kcm_energy, kcm_keyboard ,kcm_useraccount, kcm_mouse") ); - * \endcode - * The other constructor takes its modules in a QStringlist which also can be constructed from a - * string and thus you will have to be explicit on the data type. - * - * What you probably want is the KCMODULECONTAINER macro which builds an TDECModule - * for you, taking the modules you want as argument. - * - * @param parent The parent widget - * @param name The service name - * @param mods The modules to load - * @return The TDECModule containing the requested modules. - */ - TDECModuleContainer( TQWidget *parent, const char* name, const TQString& mods = TQString() ); - - /** - * Adds the specified module to the tab widget. Setting the tab icon, text, - * tool tip, connecting the signals is what it does. - * - * @param module the name of the module to add. The name is the desktop file's name - * without the ".desktop" part. - */ - void addModule( const TQString& module ); - - /** - * Default destructor. - */ - virtual ~TDECModuleContainer(); - - /** - * Reimplemented for internal purposes. - * @internal - */ - void save(); - - /** - * Reimplemented for internal purposes. - * @internal - */ - void load(); - - /** - * Reimplemented for internal purposes. - * @internal - */ - void defaults(); - - protected: - - /** - * Sets this KCM's buttons and adds a AdminMode button - * if necessary. If TDECModuleContainer is subclassed finalize() - * should be called in the constructor after all calls to addModule - * have been done. Call it once. - */ - void finalize(); - - typedef TQValueList ModuleList; - - /** - * A list containing TDECModuleProxy objects which - * have changed and must be saved. - */ - ModuleList changedModules; - - /** - * A list of all modules which are encapsulated. - */ - ModuleList allModules; // KDE 4 put in the Private class and abstract with getter - - private slots: - - /** - * Enables/disables the Admin Mode button, as appropriate. - */ - void tabSwitched( TQWidget * module ); - - void moduleChanged(TDECModuleProxy *proxy); - - /** - * Called when the user clicks our custom root button. - */ - void runAsRoot(); - - /** - * Enables the admin mode button - */ - void rootExited(); - - private: - - void init(); - - class TDECModuleContainerPrivate; - TDECModuleContainerPrivate *d; - -}; - -/** - * @ingroup kcmodule - * This macro creates an factory declaration which when run creates an TDECModule with specified - * modules. For example: - * \code - * KCMODULECONTAINER( "kcm_fonts, kcm_keyboard,kcm_fonts", misc_modules) - * \endcode - * would create a TDECModule with three tabs, each containing one of the specified KCMs. Each - * use of the macro must be accompanied by a desktop file where the factory name equals - * the second argument in the macro(in this example, misc_modules). \n - * The module container takes care of testing the contained modules when being shown, as well - * as when the module itself is asked whether it should be shown. - * - * @param modules the modules to put in the container - * @param factoryName what factory name the module should have - */ -#define KCMODULECONTAINER( modules, factoryName ) \ -extern "C" \ -{ \ - TDECModule *create_## factoryName(TQWidget *parent, const char *name) \ - { \ - return new TDECModuleContainer( parent, name, TQString( modules ) ); \ - } \ - \ - bool test_## factoryName() \ - { \ - TQStringList modList = TQStringList::split( ",", TQString(modules).remove( " " )); \ - for ( TQStringList::Iterator it = modList.begin(); it != modList.end(); ++it ) \ - if ( TDECModuleLoader::testModule( *it ) ) \ - return true; \ - return false; \ - } \ -} - -#endif // KCMODULECONTAINER_H - diff --git a/kutils/kcmoduleinfo.cpp b/kutils/kcmoduleinfo.cpp deleted file mode 100644 index c1892df36..000000000 --- a/kutils/kcmoduleinfo.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* - Copyright (c) 1999 Matthias Hoelzer-Kluepfel - Copyright (c) 2000 Matthias Elter - Copyright (c) 2003 Daniel Molkentin - Copyright (c) 2003 Matthias Kretz - - This file is part of the KDE project - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - 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 - -#include -#include -#include -#include -#include - -#include "kcmoduleinfo.h" - -class TDECModuleInfo::TDECModuleInfoPrivate -{ - public: - TDECModuleInfoPrivate() : - testModule( false ) - {} - ~TDECModuleInfoPrivate() - { } - - TQString factoryName; - bool testModule; - -}; - -TDECModuleInfo::TDECModuleInfo() -{ - _allLoaded = false; - d = new TDECModuleInfoPrivate; -} - -TDECModuleInfo::TDECModuleInfo(const TQString& desktopFile) -{ - KService::Ptr service = KService::serviceByStorageId(desktopFile); - if(!service) setName(desktopFile); - init(service); -} - -TDECModuleInfo::TDECModuleInfo( KService::Ptr moduleInfo ) -{ - init(moduleInfo); -} - -TDECModuleInfo::TDECModuleInfo( const TDECModuleInfo &rhs ) -{ - d = new TDECModuleInfoPrivate; - ( *this ) = rhs; -} - -// this re-implementation exists to ensure that other code always calls -// our re-implementation, so in case we add data to the d pointer in the future -// we can be sure that we get called when we are copied. -TDECModuleInfo &TDECModuleInfo::operator=( const TDECModuleInfo &rhs ) -{ - _keywords = rhs._keywords; - _name = rhs._name; - _icon = rhs._icon; - _lib = rhs._lib; - _handle = rhs._handle; - _fileName = rhs._fileName; - _doc = rhs._doc; - _comment = rhs._comment; - _needsRootPrivileges = rhs._needsRootPrivileges; - _isHiddenByDefault = rhs._isHiddenByDefault; - _allLoaded = rhs._allLoaded; - _service = rhs._service; - - *d = *(rhs.d); - - return *this; -} - -TQString TDECModuleInfo::factoryName() const -{ - if( d->factoryName.isEmpty() ) - { - d->factoryName = _service->property("X-TDE-FactoryName", TQVariant::String).toString(); - if ( d->factoryName.isEmpty() ) - d->factoryName = library(); - } - - return d->factoryName; -} - -bool TDECModuleInfo::operator==( const TDECModuleInfo & rhs ) const -{ - return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) ); -} - -bool TDECModuleInfo::operator!=( const TDECModuleInfo & rhs ) const -{ - return ! operator==( rhs ); -} - -TDECModuleInfo::~TDECModuleInfo() -{ - delete d; -} - -void TDECModuleInfo::init(KService::Ptr s) -{ - _allLoaded = false; - d = new TDECModuleInfoPrivate; - - if ( s ) - _service = s; - else - { - kdDebug(712) << "Could not find the service." << endl; - return; - } - - // set the modules simple attributes - setName(_service->name()); - setComment(_service->comment()); - setIcon(_service->icon()); - - _fileName = ( _service->desktopEntryPath() ); - - // library and factory - setLibrary(_service->library()); - - // get the keyword list - setKeywords(_service->keywords()); -} - -void -TDECModuleInfo::loadAll() -{ - if( !_service ) /* We have a bogus service. All get functions will return empty/zero values */ - return; - - _allLoaded = true; - - // library and factory - setHandle(_service->property("X-TDE-FactoryName", TQVariant::String).toString()); - - TQVariant tmp; - - // read weight - tmp = _service->property( "X-TDE-Weight", TQVariant::Int ); - setWeight( tmp.isValid() ? tmp.toInt() : 100 ); - - // does the module need super user privileges? - tmp = _service->property( "X-TDE-RootOnly", TQVariant::Bool ); - setNeedsRootPrivileges( tmp.isValid() ? tmp.toBool() : false ); - - // does the module need to be shown to root only? - // Deprecated ! KDE 4 - tmp = _service->property( "X-TDE-IsHiddenByDefault", TQVariant::Bool ); - setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false ); - - // get the documentation path - setDocPath( _service->property( "DocPath", TQVariant::String ).toString() ); - - tmp = _service->property( "X-TDE-Test-Module", TQVariant::Bool ); - setNeedsTest( tmp.isValid() ? tmp.asBool() : false ); -} - -TQString -TDECModuleInfo::docPath() const -{ - if (!_allLoaded) - const_cast(this)->loadAll(); - - return _doc; -} - -TQString -TDECModuleInfo::handle() const -{ - if (!_allLoaded) - const_cast(this)->loadAll(); - - if (_handle.isEmpty()) - return _lib; - - return _handle; -} - -int -TDECModuleInfo::weight() const -{ - if (!_allLoaded) - const_cast(this)->loadAll(); - - return _weight; -} - -bool -TDECModuleInfo::needsRootPrivileges() const -{ - if (!_allLoaded) - const_cast(this)->loadAll(); - - return _needsRootPrivileges; -} - -bool -TDECModuleInfo::isHiddenByDefault() const -{ - if (!_allLoaded) - const_cast(this)->loadAll(); - - return _isHiddenByDefault; -} - -bool TDECModuleInfo::needsTest() const -{ - return d->testModule; -} - -void TDECModuleInfo::setNeedsTest( bool val ) -{ - d->testModule = val; -} - - - -// vim: ts=2 sw=2 et diff --git a/kutils/kcmoduleinfo.h b/kutils/kcmoduleinfo.h deleted file mode 100644 index a17f6af7a..000000000 --- a/kutils/kcmoduleinfo.h +++ /dev/null @@ -1,296 +0,0 @@ -/* - Copyright (c) 1999 Matthias Hoelzer-Kluepfel - Copyright (c) 2000 Matthias Elter - Copyright (c) 2003 Daniel Molkentin - Copyright (c) 2003 Matthias Kretz - - This file is part of the KDE project - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - 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 KCMODULEINFO_H -#define KCMODULEINFO_H - -#include - -class TQPixmap; -class TQString; -class TQStringList; - -/** - * @ingroup kcmodule - * A class that provides information about a TDECModule - * - * TDECModuleInfo provides various technical information, such as icon, library - * etc. about a TDECModule.n - * @note Any values set with the set* functions is not - * written back with TDECModuleInfo it only reads value from the desktop file. - * - * @internal - * @author Matthias Hoelzer-Kluepfel - * @author Matthias Elter - * @author Daniel Molkentin - * @since 3.2 - * - */ -class KUTILS_EXPORT TDECModuleInfo -{ - -public: - - /** - * Constructs a TDECModuleInfo. - * @note a TDECModuleInfo object will have to be manually deleted, it is not - * done automatically for you. - * @param desktopFile the desktop file representing the module, or - * the name of the module. - */ - TDECModuleInfo(const TQString& desktopFile); - - /** - * Same as above but takes a KService::Ptr as argument. - * - * @note @p moduleInfo must be a valid pointer. - * - * @param moduleInfo specifies the module - */ - TDECModuleInfo( KService::Ptr moduleInfo ); - - - /** - * Same as above but takes a TDECModuleInfo as argument. - * - * @param rhs specifies the module - */ - TDECModuleInfo( const TDECModuleInfo &rhs ); - - /** - * Same as above but creates an empty TDECModuleInfo. - * You should not normally call this. - * @since 3.4 - */ - TDECModuleInfo(); - - /** - * Assignment operator - */ - TDECModuleInfo &operator=( const TDECModuleInfo &rhs ); - - /** - * Equal operator - * - * @return true if @p rhs equals itself - */ - - bool operator==( const TDECModuleInfo &rhs ) const; - - /** - * @return true if @p rhs is not equal itself - */ - bool operator!=( const TDECModuleInfo &rhs ) const; - - /** - * Default destructor. - */ - ~TDECModuleInfo(); - - /** - * @return the filename of the .desktop file that describes the KCM - */ - TQString fileName() const { return _fileName; } - - /** - * @return the keywords associated with this KCM. - */ - const TQStringList &keywords() const { return _keywords; } - - /** - * Returns the module's factory name, if it's set. If not, the library - * name is returned. - * @returns the module's factory name - * @since 3.4 - */ - TQString factoryName() const; - - /** - * @return the module\'s (translated) name - */ - TQString moduleName() const { return _name; } - // changed from name() to avoid ambiguity with TQObject::name() on multiple inheritance - - /** - * @return a KSharedPtr to KService created from the modules .desktop file - */ - KService::Ptr service() const { return _service; } - - /** - * @return the module's (translated) comment field - */ - TQString comment() const { return _comment; } - - /** - * @return the module's icon name - */ - TQString icon() const { return _icon; } - - /** - * @return the path of the module's documentation - */ - TQString docPath() const; - - /** - * @return the library name - */ - TQString library() const { return _lib; } - - /** - * @return a handle (usually the contents of the FactoryName field) - */ - TQString handle() const; - - /** - * @return the weight of the module which determines the order of the pages in - * the KCMultiDialog. It's set by the X-TDE-Weight field. - */ - int weight() const; - - /** - * @return whether the module might require root permissions - */ - bool needsRootPrivileges() const; - - /** - * @deprecated - * @return the isHiddenByDefault attribute. - */ - bool isHiddenByDefault() const KDE_DEPRECATED; - - - /** - * @returns true if the module should be conditionally - * loaded. - * @since 3.4 - */ - bool needsTest() const; - - -protected: - - /** - * Sets the object's keywords. - * @param keyword the new keywords - */ - void setKeywords(const TQStringList &keyword) { _keywords = keyword; } - - /** - * Sets the object's name. - * @param name the new name - */ - void setName(const TQString &name) { _name = name; } - - /** - * Sets the object's name. - * @param comment the new comment - */ - void setComment(const TQString &comment) { _comment = comment; } - - /** - * Sets the object's icon. - * @param icon the name of the new icon - */ - void setIcon(const TQString &icon) { _icon = icon; } - - /** - * Set the object's library - * @param lib the name of the new library without any extensions or prefixs. - */ - void setLibrary(const TQString &lib) { _lib = lib; } - - /** - * Sets the factory name - * @param handle The new factory name - */ - void setHandle(const TQString &handle) { _handle = handle; } - - /** - * Sets the object's weight property which determines in what - * order modules will be displayed. Default is 100. - * - * @param weight the new weight - */ - void setWeight(int weight) { _weight = weight; } - - - /** - * Sets if the module should be tested for loading. - * @param val the value to set - * @since 3.4 - */ - void setNeedsTest( bool val ); - - /** - * Toggles whether the represented module needs root privileges. - * Use with caution. - * @param needsRootPrivileges if module needs root privilges - */ - void setNeedsRootPrivileges(bool needsRootPrivileges) - { _needsRootPrivileges = needsRootPrivileges; } - - /** - * @deprecated - */ - void setIsHiddenByDefault(bool isHiddenByDefault) - { _isHiddenByDefault = isHiddenByDefault; } - - /** - * Sets the object's documentation path - * @param p the new documentation path - */ - void setDocPath(const TQString &p) { _doc = p; } - - /** - * Reads the service entries specific for TDECModule from the desktop file. - * The usual desktop entries are read in init. - */ - void loadAll(); - -private: - - /** - * Reads the service entries. Called by the constructors. - */ - void init(KService::Ptr s); - -private: - - // KDE4 These needs to be moved to TDECModuleInfoPrivate - TQStringList _keywords; - TQString _name, _icon, _lib, _handle, _fileName, _doc, _comment; - bool _needsRootPrivileges : 1; - bool _isHiddenByDefault : 1; - bool _allLoaded : 1; - int _weight; - - KService::Ptr _service; - - class TDECModuleInfoPrivate; - TDECModuleInfoPrivate *d; - -}; - -#endif // KCMODULEINFO_H - -// vim: ts=2 sw=2 et diff --git a/kutils/kcmoduleloader.cpp b/kutils/kcmoduleloader.cpp deleted file mode 100644 index da31a72c2..000000000 --- a/kutils/kcmoduleloader.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/* - Copyright (c) 1999 Matthias Hoelzer-Kluepfel - Copyright (c) 2000 Matthias Elter - Copyright (c) 2003,2004 Matthias Kretz - Copyright (c) 2004 Frans Englich - - This file is part of the KDE project - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - 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 -#include -#include - -#include -#include -#include -#include -#include - -#include "kcmoduleloader.h" - - -/***************************************************************/ -/** - * When something goes wrong in loading the module, this one - * jumps in as a "dummy" module. - */ -class KCMError : public TDECModule -{ - public: - KCMError( const TQString& msg, const TQString& details, TQWidget* parent ) - : TDECModule( parent, "KCMError" ) - { - TQVBoxLayout* topLayout = new TQVBoxLayout( this ); - topLayout->addWidget( new TQLabel( msg, this ) ); - topLayout->addWidget( new TQLabel( details, this ) ); - } -}; -/***************************************************************/ - - - - -TDECModule* TDECModuleLoader::load(const TDECModuleInfo &mod, const TQString &libname, - KLibLoader *loader, ErrorReporting report, TQWidget * parent, - const char * name, const TQStringList & args ) -{ - // attempt to load modules with ComponentFactory, only if the symbol init_ exists - // (this is because some modules, e.g. kcmkio with multiple modules in the library, - // cannot be ported to KGenericFactory) - KLibrary *lib = loader->library(TQFile::encodeName(libname.arg(mod.library()))); - if (lib) { - TQString initSym("init_"); - initSym += libname.arg(mod.library()); - - if ( lib->hasSymbol(TQFile::encodeName(initSym)) ) - { - KLibFactory *factory = lib->factory(); - if ( factory ) - { - TDECModule *module = KParts::ComponentFactory::createInstanceFromFactory( factory, TQT_TQOBJECT(parent), name ? name : mod.handle().latin1(), args ); - if (module) - return module; - } - // else do a fallback - kdDebug(1208) << "Unable to load module using ComponentFactory. Falling back to old loader." << endl; - } - - // get the create_ function - TQString factory("create_%1"); - void *create = lib->symbol(TQFile::encodeName(factory.arg(mod.handle()))); - - if (create) - { - // create the module - TDECModule* (*func)(TQWidget *, const char *); - func = (TDECModule* (*)(TQWidget *, const char *)) create; - return func( parent, name ? name : mod.handle().latin1() ); - } - else - { - TQString libFileName = lib->fileName(); - lib->unload(); - return reportError( report, i18n("There was an error when loading the module '%1'.

" - "The desktop file (%2) as well as the library (%3) was found but " - "yet the module could not be loaded properly. Most likely " - "the factory declaration was wrong, or the " - "create_* function was missing.
") - .arg( mod.moduleName() ) - .arg( mod.fileName() ) - .arg( libFileName ), - TQString::null, parent ); - } - - lib->unload(); - } - return reportError( report, i18n("The specified library %1 could not be found.") - .arg( mod.library() ), TQString::null, parent ); - return 0; -} - -TDECModule* TDECModuleLoader::loadModule(const TDECModuleInfo &mod, bool withfallback, TQWidget * parent, const char * name, const TQStringList & args ) -{ - return loadModule( mod, None, withfallback, parent, name, args ); -} - -TDECModule* TDECModuleLoader::loadModule(const TDECModuleInfo &mod, ErrorReporting report, bool withfallback, TQWidget * parent, const char * name, const TQStringList & args ) -{ - /* - * Simple libraries as modules are the easiest case: - * We just have to load the library and get the module - * from the factory. - */ - - if ( !mod.service() ) - { - if ( mod.moduleName() == "kcmlisa" || mod.moduleName() == "kcmkiolan" ) - { - return reportError( report, - i18n("The module %1 could not be found.") - .arg( mod.moduleName() ), - i18n("

The Lisa and lan:/ ioslave modules " - "are not installed by default in Kubuntu, because they are obsolete " - "and replaced by zeroconf.
If you still wish to use them, you " - "should install the lisa package from the Universe repository.

"), - parent ); - } else { - return reportError( report, - i18n("The module %1 could not be found.") - .arg( mod.moduleName() ), - i18n("

The diagnostics is:
The desktop file %1 could not be found.

").arg(mod.fileName()), - parent ); - } - } - - if (!mod.library().isEmpty()) - { - // get the library loader instance - - KLibLoader *loader = KLibLoader::self(); - - TDECModule *module = load(mod, "kcm_%1", loader, report, parent, name, args ); - /* - * Only try to load libkcm_* if it exists, otherwise KLibLoader::lastErrorMessage would say - * "libkcm_foo not found" instead of the real problem with loading kcm_foo. - */ - if (!KLibLoader::findLibrary( TQCString( "libkcm_" ) + TQFile::encodeName( mod.library() ) ).isEmpty() ) - module = load(mod, "libkcm_%1", loader, report, parent, name, args ); - if (module) - return module; - return reportError( report, - i18n("The module %1 could not be loaded.") - .arg( mod.moduleName() ), TQString::null, parent ); - } - - /* - * Ok, we could not load the library. - * Try to run it as an executable. - * This must not be done when calling from kcmshell, or you'll - * have infinite recursion - * (startService calls kcmshell which calls modloader which calls startService...) - * - */ - if(withfallback) - { - TDEApplication::startServiceByDesktopPath(mod.fileName(), TQString::null); - } - else - { - return reportError( report, - i18n("The module %1 is not a valid configuration module.") - .arg( mod.moduleName() ), i18n("

The diagnostics is:
The desktop file %1 does not specify a library.").arg(mod.fileName()), parent ); - } - - return 0; -} - -TDECModule* TDECModuleLoader::loadModule(const TQString &module, TQWidget *parent, - const char *name, const TQStringList & args) -{ - return loadModule(TDECModuleInfo(module), None, false, parent, name, args); -} - -TDECModule* TDECModuleLoader::loadModule(const TQString &module, ErrorReporting - report, TQWidget *parent, const char *name, const TQStringList & args) -{ - return loadModule(TDECModuleInfo(module), report, false, parent, name, args); -} - -void TDECModuleLoader::unloadModule(const TDECModuleInfo &mod) -{ - // get the library loader instance - KLibLoader *loader = KLibLoader::self(); - - // try to unload the library - TQString libname("libkcm_%1"); - loader->unloadLibrary(TQFile::encodeName(libname.arg(mod.library()))); - - libname = "kcm_%1"; - loader->unloadLibrary(TQFile::encodeName(libname.arg(mod.library()))); -} - -void TDECModuleLoader::showLastLoaderError(TQWidget *parent) -{ - KMessageBox::detailedError(parent, - i18n("There was an error loading the module."),i18n("

The diagnostics is:
%1" - "

Possible reasons:

  • An error occurred during your last " - "TDE upgrade leaving an orphaned control module
  • You have old third party " - "modules lying around.

Check these points carefully and try to remove " - "the module mentioned in the error message. If this fails, consider contacting " - "your distributor or packager.

") - .arg(KLibLoader::self()->lastErrorMessage())); - -} - -bool TDECModuleLoader::testModule( const TQString& module ) -{ - return testModule( TDECModuleInfo( module ) ); -} - -bool TDECModuleLoader::testModule( const TDECModuleInfo& module ) -{ - if (!module.service()) - { - kdDebug(1208) << "Module '" << module.fileName() << "' not found." << endl; - return true; - } - - bool doLoad = module.service()->property( "X-TDE-Test-Module", TQVariant::Bool ).toBool(); - if( !doLoad ) - { - return true; - } - else - { - /** - * If something fails we return true - we can't risk functionality becoming - * unavailable because of a buggy test. Furthermore, the error needs to - * show so it is discovered. TDECModuleProxy will detect the error and load - * a corresponding KCMError. - * */ - KLibLoader* loader = KLibLoader::self(); - KLibrary* library = loader->library( TQFile::encodeName((TQString("kcm_%1").arg(module.library()))) ); - if( library ) - { - void *test_func = library->symbol( TQString(TQString("test_%1").arg(module.factoryName())).utf8() ); - if( test_func ) - { - bool (*func)() = (bool(*)())test_func; - if( func() ) - { - return true; - } - else - { - return false; - } - } - else - { - kdDebug(1208) << "The test function for module '" << module.fileName() << "' could not be found." << endl; - return true; - } - } - kdDebug(1208) << "The library '" << module.library() << "' could not be found." << endl; - return true; - } -} - -TDECModule* TDECModuleLoader::reportError( ErrorReporting report, const TQString & text, - TQString details, TQWidget * parent ) -{ - if( details.isNull() ) - details = i18n("

The diagnostics is:
%1" - "

Possible reasons:

  • An error occurred during your last " - "TDE upgrade leaving an orphaned control module
  • You have old third party " - "modules lying around.

Check these points carefully and try to remove " - "the module mentioned in the error message. If this fails, consider contacting " - "your distributor or packager.

").arg(KLibLoader::self()->lastErrorMessage()); - if( report & Dialog ) - KMessageBox::detailedError( parent, text, details ); - if( report & Inline ) - return new KCMError( text, details, parent ); - return 0; -} - -// vim: ts=2 sw=2 et - diff --git a/kutils/kcmoduleloader.h b/kutils/kcmoduleloader.h deleted file mode 100644 index b4b57e21a..000000000 --- a/kutils/kcmoduleloader.h +++ /dev/null @@ -1,220 +0,0 @@ -/* - Copyright (c) 1999 Matthias Hoelzer-Kluepfel - Copyright (c) 2002-2003 Daniel Molkentin - - This file is part of the KDE project - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - 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 MODLOADER_H -#define MODLOADER_H - -#include -#include - -class TQWidget; -class KLibLoader; - -/** - * @ingroup kcmodule - * @brief Loads a KControl Module. - * - * TDECModuleLoader tries in several ways - * to locate and load a TDECModule. If loading fails a - * zero pointer is returned. \n - * It is very unlikely TDECModuleLoader is what you want - * and @ref TDECModuleProxy suits your needs. - * - * @author Matthias Hoelzer-Kluepfel - * @author Frans Englich - * @since 3.2 - * @internal -**/ -class KUTILS_EXPORT TDECModuleLoader -{ - public: - - /** - * Loads a @ref TDECModule. If loading fails a zero pointer is returned. - * @param module what module to load - * @param withFallback if true and loading failed a separate window - * with the module may appear and a zero pointer is a returned - * @param parent The parent widget - * @param name The widget's name - * @param args A list of arguments for the module to load - * - * @return a pointer to the loaded @ref TDECModule - * - * @deprecated use the function which explicitly states the error reporting - * method - */ - static TDECModule *loadModule(const TDECModuleInfo &module, bool withFallback=true, - TQWidget * parent = 0, const char * name = 0, - const TQStringList & args = TQStringList() ) KDE_DEPRECATED; - - /** - * Loads a @ref TDECModule. If loading fails a zero pointer is returned. - * @param module what module to load - * with the module may appear and a zero pointer is a returned - * @param parent The parent widget - * @param name The widget's name - * @param args A list of arguments for the module to load - * - * @deprecated use the function which explicitly states the error reporting - * method - */ - static TDECModule *loadModule(const TQString &module, TQWidget *parent = 0, - const char *name = 0, const TQStringList & args = TQStringList()) KDE_DEPRECATED; - - /** - * Determines the way errors are reported - */ - enum ErrorReporting { - /** - * no error reporting is done - * */ - None = 0, - /** - * the error report is shown instead of the - * TDECModule that should have * been loaded - */ - Inline = 1, - /** - * shows a dialog with the error report - */ - Dialog = 2, - /** - * does both Inline and Dialog - */ - Both = 3 - }; - - /** - * Loads a @ref TDECModule. If loading fails a zero pointer is returned. - * @param module what module to load - * @param report see ErrorReporting - * @param withFallback if true and loading failed a separate window - * with the module may appear and a zero pointer is a returned - * @param parent The parent widget - * @param name The widget's name - * @param args A list of arguments for the module to load - * - * @return a pointer to the loaded @ref TDECModule - * @since 3.4 - */ - static TDECModule *loadModule(const TDECModuleInfo &module, ErrorReporting - report, bool withFallback=true, TQWidget * parent = 0, - const char * name = 0, const TQStringList & args = TQStringList() ); - - /** - * Loads a @ref TDECModule. If loading fails a zero pointer is returned. - * @param module what module to load - * @param report see ErrorReporting - * with the module may appear and a zero pointer is a returned - * @param parent The parent widget - * @param name The widget's name - * @param args A list of arguments for the module to load - * - * @return a pointer to the loaded @ref TDECModule - * @since 3.4 - */ - static TDECModule *loadModule(const TQString &module, ErrorReporting - report, TQWidget *parent = 0, const char *name = 0, - const TQStringList & args = TQStringList()); - - /** - * Unloads the module's library - * @param mod What module to unload for - */ - static void unloadModule(const TDECModuleInfo &mod); - - /** - * Display a message box explaining an error occured and possible - * reasons to why. - * - * @deprecated Use a constructor with ErrorReporting set to Dialog to show a - * message box like this function did. - */ - static void showLastLoaderError(TQWidget *parent) KDE_DEPRECATED; - - - /** - * Checks whether an TDECModule should be shown by running its - * test function. If it is unsure whether a module should be shown, it should - * be made available, leaving the decision to the user. - * If false is returned, the module should not be loaded in any interface. - * - * A module declares it needs to be tested by having "X-TDE-Test-Module=true" in - * its desktop file. When that line exists, the following code must be available - * in the module's library: - * - * \code - * extern "C" - * { - * bool test_moduleName() - * { - * // Code testing for hardware/software presence. - * return true; // and the modue will be loaded. - * } - * - * } - * \endcode - * - * where moduleName is the library name for the module. - * - * @param module the module to check - * @returns true if the module should be loaded - * @since 3.4 - */ - static bool testModule( const TQString& module ); - - /** - * Convenience function, essentially the same as above. - * - * @param module the module to check - * @returns true if the module should be loaded - * @since 3.4 - */ - static bool testModule( const TDECModuleInfo& module ); - - /** - * Returns a TDECModule containing the messages @p report and @p text. - * - * @param report the type of error reporting, see ErrorReporting - * @param text the main message - * @param details any additional details - * @param parent The parent widget - * - * @since 3.4 - * @internal - */ - static TDECModule* reportError( ErrorReporting report, const TQString & text, - TQString details, TQWidget * parent ); - - private: - - /** - * Internal loader called by the public loaders. - * @internal - */ - static TDECModule* load(const TDECModuleInfo &mod, const TQString &libname, - KLibLoader *loader, ErrorReporting report, TQWidget * parent = 0, - const char * name = 0, const TQStringList & args = TQStringList() ); - -}; - -// vim: ts=2 sw=2 et -#endif // MODLOADER_H - diff --git a/kutils/kcmoduleproxy.cpp b/kutils/kcmoduleproxy.cpp deleted file mode 100644 index df6b2bb98..000000000 --- a/kutils/kcmoduleproxy.cpp +++ /dev/null @@ -1,650 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2004 Frans Englich - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "kcmoduleproxy.h" -#include "kcmoduleproxyIface.h" -#include "kcmoduleproxyIfaceImpl.h" - -/***************************************************************/ -class TDECModuleProxy::TDECModuleProxyPrivate -{ - public: - TDECModuleProxyPrivate( const TDECModuleInfo & info ) - : args( 0 ) - , kcm( 0 ) - //, view( 0 ) - , embedWidget( 0 ) - , rootProcess ( 0 ) - , embedFrame ( 0 ) - , dcopObject( 0 ) - , dcopClient( 0 ) - , topLayout( 0 ) - , rootCommunicator( 0 ) - , rootInfo( 0 ) - , modInfo( info ) - , withFallback( false ) - , changed( false ) - , rootMode( false ) - , bogusOccupier( false ) - , isInitialized( false ) - {} - - ~TDECModuleProxyPrivate() - { - delete rootInfo; // Delete before embedWidget! - delete embedWidget; // Delete before embedFrame! - delete embedFrame; - delete dcopClient; - delete dcopObject; - delete rootCommunicator; - delete rootProcess; - delete kcm; - } - - TQStringList args; - TDECModule *kcm; - QXEmbed *embedWidget; - TDEProcess *rootProcess; - TQVBox *embedFrame; - TDECModuleProxyIfaceImpl *dcopObject; - DCOPClient *dcopClient; - TQVBoxLayout *topLayout; /* Contains TQScrollView view, and root stuff */ - TDECModuleProxyRootCommunicatorImpl *rootCommunicator; - TQLabel *rootInfo; - TQCString dcopName; - TDECModuleInfo modInfo; - bool withFallback; - bool changed; - bool rootMode; - bool bogusOccupier; - bool isInitialized; -}; -/***************************************************************/ - - - -/* - TODO: - - - How TDECModuleProxy behaves wrt memory leaks and behavior, when exiting - from root mode is not tested, because no code make use of it. It needs - work, if it should be used. - - - Should write a document which outlines test cases, to avoid - regressions. This class is a hazard. - - - Two Layout problems in runAsRoot: - * lblBusy doesn't show - * d->kcm/d->rootInfo doesn't get it right when the user - presses cancel in the tdesu dialog - - - Resizing horizontally is contrained; minimum size is set somewhere. - It appears to be somehow derived from the module's size. - - - Prettify: set icon in KCMultiDialog. - - - Perhaps it's possible to link against tdesu such that - the dialog is in process? - - */ -/***************************************************************/ -TDECModule * TDECModuleProxy::realModule() const -{ - - /* - * Note, don't call any function that calls realModule() since - * that leads to an infinite loop. - */ - - kdDebug(711) << k_funcinfo << endl; - - /* Already loaded */ - if( d->kcm ) - return d->kcm; - - /* /We/ have no kcm, but kcmshell running with root prevs does.. */ - if( d->rootMode ) - return 0; - - TQApplication::setOverrideCursor( Qt::WaitCursor ); - - TDECModuleProxy * that = const_cast( this ); - - if( !d->isInitialized ) - { - d->dcopName = TQString(moduleInfo().handle().prepend("TDECModuleProxy-")).utf8(); - d->topLayout = new TQVBoxLayout( that, 0, 0, "topLayout" ); - - d->isInitialized = true; - } - - if( !d->dcopClient ) - d->dcopClient = new DCOPClient(); - - if( !d->dcopClient->isRegistered() ) - d->dcopClient->registerAs( d->dcopName, false ); - - d->dcopClient->setAcceptCalls( true ); - - if( d->dcopClient->appId() == d->dcopName || d->bogusOccupier ) - { /* We got the name we requested, because no one was before us, - * or, it was an random application which had picked that name */ - kdDebug(711) << "Module not already loaded, loading module" << endl; - - d->dcopObject = new TDECModuleProxyIfaceImpl( d->dcopName, that ); - - d->kcm = TDECModuleLoader::loadModule( moduleInfo(), TDECModuleLoader::Inline, d->withFallback, - that, name(), d->args ); - - connect( d->kcm, TQT_SIGNAL( changed( bool ) ), - TQT_SLOT(moduleChanged(bool)) ); - connect( d->kcm, TQT_SIGNAL( destroyed() ), - TQT_SLOT( moduleDestroyed() ) ); - connect( d->kcm, TQT_SIGNAL(quickHelpChanged()), - TQT_SIGNAL(quickHelpChanged())); - TQWhatsThis::add( that, d->kcm->quickHelp() ); - - d->topLayout->addWidget( d->kcm ); - - if ( !d->rootInfo && /* If the message was not yet created */ - d->kcm->useRootOnlyMsg() /* and the module requests the message */ && - moduleInfo().needsRootPrivileges() /* and the module wants root access */ && - !KUser().isSuperUser() ) /* and we are not currently root */ - { - - d->rootInfo = new TQLabel( that, "rootInfo" ); - d->topLayout->insertWidget( 0, d->rootInfo ); - - d->rootInfo->setFrameShape(TQFrame::Box); - d->rootInfo->setFrameShadow(TQFrame::Raised); - - const TQString msg = d->kcm->rootOnlyMsg(); - if( msg.isEmpty() ) - d->rootInfo->setText(i18n( - "Changes in this section requires root access.
" - "Click the \"Administrator Mode\" button to " - "allow modifications.")); - else - d->rootInfo->setText(msg); - - TQWhatsThis::add( d->rootInfo, i18n( - "This section requires special permissions, probably " - "for system-wide changes; therefore, it is " - "required that you provide the root password to be " - "able to change the module's properties. If " - "you do not provide the password, the module will be " - "disabled.")); - } - } - else - { - kdDebug(711) << "Module already loaded, loading KCMError" << endl; - - d->dcopClient->detach(); - /* Re-register as anonymous */ - d->dcopClient->attach(); - - d->dcopClient->setNotifications( true ); - connect( d->dcopClient, TQT_SIGNAL( applicationRemoved( const TQCString& )), - TQT_SLOT( applicationRemoved( const TQCString& ))); - - /* Figure out the name of where the module is already loaded */ - TQByteArray replyData, data; - TQCString replyType; - TQString result; - TQDataStream arg, stream( replyData, IO_ReadOnly ); - - if( d->dcopClient->call( d->dcopName, d->dcopName, "applicationName()", - data, replyType, replyData )) - { - stream >> result; - - d->kcm = TDECModuleLoader::reportError( TDECModuleLoader::Inline, - i18n( "Argument is application name", "This configuration section is " - "already opened in %1" ).arg( result ), " ", that ); - - d->topLayout->addWidget( d->kcm ); - } - else - { - kdDebug(711) << "Calling TDECModuleProxy's DCOP interface for fetching the name failed." << endl; - d->bogusOccupier = true; - TQApplication::restoreOverrideCursor(); - return realModule(); - } - } - - TQApplication::restoreOverrideCursor(); - - return d->kcm; -} - -void TDECModuleProxy::applicationRemoved( const TQCString& app ) -{ - if( app == d->dcopName ) - { - /* Violence: Get rid of KCMError & CO, so that - * realModule() attempts to reload the module */ - delete d->kcm; - d->kcm = 0; - d->dcopClient->setNotifications( false ); - realModule(); - d->kcm->show(); - } -} - -void TDECModuleProxy::showEvent( TQShowEvent * ev ) -{ - - kdDebug(711) << k_funcinfo << endl; - ( void )realModule(); - - /* We have no kcm, if we're in root mode */ - if( d->kcm ) - d->kcm->show(); - - TQWidget::showEvent( ev ); - -} - -void TDECModuleProxy::runAsRoot() -{ - if ( !moduleInfo().needsRootPrivileges() ) - return; - - TQApplication::setOverrideCursor( Qt::WaitCursor ); - - delete d->rootProcess; - delete d->embedWidget; - delete d->embedFrame; - - d->embedFrame = new TQVBox( this, "embedFrame" ); - d->embedFrame->setFrameStyle( TQFrame::Box | TQFrame::Raised ); - - TQPalette pal( red ); - pal.setColor( TQColorGroup::Background, - colorGroup().background() ); - d->embedFrame->setPalette( pal ); - d->embedFrame->setLineWidth( 2 ); - d->embedFrame->setMidLineWidth( 2 ); - d->topLayout->addWidget(d->embedFrame,1); - - d->embedWidget = new QXEmbed( d->embedFrame, "embedWidget" ); - - d->embedFrame->show(); - - TQLabel *lblBusy = new TQLabel(i18n("Loading..."), d->embedWidget, "lblBusy" ); - lblBusy->setTextFormat(RichText); - lblBusy->setAlignment(AlignCenter); - lblBusy->setGeometry(0,0, d->kcm->width(), d->kcm->height()); - lblBusy->show(); - - deleteClient(); - /* The DCOP registration is now gone, and it will occur again when kcmshell soon - * registers. Here's a race condition in other words, but how likely is that? - * - * - It's a user initiated action, which means the user have to do weird stuff, very - * quick. - * - If the user _do_ manage to fsck up, the code will recover gracefully, see realModule(). - * - * So no worry. At the end of this function, communication with - * the DCOP object is established. - */ - - /* Prepare the process to run the kcmshell */ - TQString cmd = moduleInfo().service()->exec().stripWhiteSpace(); - if (cmd.left(5) == "tdesu") - { - cmd = TQString(cmd.remove(0,5)).stripWhiteSpace(); - - /* Remove all tdesu switches */ - while( cmd.length() > 1 && cmd[ 0 ] == '-' ) - cmd = TQString(cmd.remove( 0, cmd.find( ' ' ) )).stripWhiteSpace(); - } - - if (cmd.left(8) == "kcmshell") - cmd = TQString(cmd.remove(0,8)).stripWhiteSpace(); - - /* Run the process */ - TQString tdesu = KStandardDirs::findExe("tdesu"); - if (!tdesu.isEmpty()) - { - - d->rootProcess = new TDEProcess; - - *d->rootProcess << tdesu; - *d->rootProcess << "--nonewdcop" << "-n" << "-d" << TQString( "-i%1" ).arg(moduleInfo().icon()); - - *d->rootProcess << TQString("%1 %2 --embed-proxy %3 --lang %4").arg(locate("exe", "kcmshell")) - .arg(cmd).arg(d->embedWidget->winId()).arg(TDEGlobal::locale()->language()); - - connect(d->rootProcess, TQT_SIGNAL(processExited(TDEProcess*)), TQT_SLOT(rootExited())); - - if ( !d->rootProcess->start( TDEProcess::NotifyOnExit )) - { - d->rootMode = false; - rootExited(); - } - else - { - d->rootMode = true; - kapp->dcopClient(); - d->rootCommunicator = new TDECModuleProxyRootCommunicatorImpl( d->dcopName + "-RootCommunicator", this ); - } - - delete lblBusy; - TQApplication::restoreOverrideCursor(); - return; - } - - /* Clean up in case of failure */ - delete d->embedWidget; - d->embedWidget = 0; - delete d->embedFrame; - d->embedFrame = 0; - - TQApplication::restoreOverrideCursor(); -} - -void TDECModuleProxy::rootExited() -{ - kdDebug(711) << k_funcinfo << endl; - - if ( d->embedWidget->embeddedWinId() ) - XDestroyWindow(tqt_xdisplay(), d->embedWidget->embeddedWinId()); - - delete d->embedWidget; - d->embedWidget = 0; - - delete d->rootProcess; - d->rootProcess = 0; - - delete d->embedFrame; - d->embedFrame=0; - - delete d->rootCommunicator; - d->rootCommunicator = 0; - - /* Such that the "ordinary" module loads again */ - d->rootMode = false; - - d->topLayout->invalidate(); - - TQShowEvent ev; - showEvent( &ev ); - - moduleChanged( false ); - emit childClosed(); -} - -TDECModuleProxy::~TDECModuleProxy() -{ - deleteClient(); - TDECModuleLoader::unloadModule(moduleInfo()); - - delete d; -} - -void TDECModuleProxy::deleteClient() -{ - if( d->embedWidget ) - XKillClient(tqt_xdisplay(), d->embedWidget->embeddedWinId()); - - - delete d->kcm; - d->kcm = 0; - - delete d->dcopObject; - d->dcopObject = 0; - - if( d->dcopClient && !d->dcopClient->detach() ) - kdDebug(711) << "Unregistering from DCOP failed." << endl; - - delete d->dcopClient; - d->dcopClient = 0; - - kapp->syncX(); - -} - -void TDECModuleProxy::moduleChanged( bool c ) -{ - if( d->changed == c ) - return; - - d->changed = c; - emit changed( c ); - emit changed( this ); -} - -void TDECModuleProxy::moduleDestroyed() -{ - d->kcm = 0; -} - -TDECModuleProxy::TDECModuleProxy( const KService::Ptr & service, bool withFallback, - TQWidget * parent, const char * name, const TQStringList & args) - : TQWidget( parent, name ) -{ - init( TDECModuleInfo( service )); - d->args = args; - d->withFallback = withFallback; -} - -TDECModuleProxy::TDECModuleProxy( const TDECModuleInfo & info, bool withFallback, - TQWidget * parent, const char * name, const TQStringList & args ) - : TQWidget( parent, name ) -{ - init( info ); - d->args = args; - d->withFallback = withFallback; -} - -TDECModuleProxy::TDECModuleProxy( const TQString& serviceName, bool withFallback, - TQWidget * parent, const char * name, - const TQStringList & args) - : TQWidget( parent, name ) -{ - init( TDECModuleInfo( serviceName )); - d->args = args; - d->withFallback = withFallback; -} - -void TDECModuleProxy::init( const TDECModuleInfo& info ) -{ - kdDebug(711) << k_funcinfo << endl; - - d = new TDECModuleProxyPrivate( info ); - - /* This is all we do for now; all the heavy work is - * done in realModule(). It's called when the module - * _actually_ is needed, in for example showEvent(). - * The module is loaded "on demand" -- lazy loading. - */ - -} - -void TDECModuleProxy::load() -{ - - if( d->rootMode ) - callRootModule( "load()" ); - else if( realModule() ) - { - d->kcm->load(); - moduleChanged( false ); - } -} - -void TDECModuleProxy::save() -{ - if( d->rootMode ) - callRootModule( "save()" ); - else if( d->changed && realModule() ) - { - d->kcm->save(); - moduleChanged( false ); - } -} - -void TDECModuleProxy::callRootModule( const TQCString& function ) -{ - TQByteArray sendData, replyData; - TQCString replyType; - - /* Note, we don't use d->dcopClient here, because it's used for - * the loaded module(and it's not "us" when this function is called) */ - if( !kapp->dcopClient()->call( d->dcopName, d->dcopName, function, sendData, - replyType, replyData, true, -1 )) - kdDebug(711) << "Calling function '" << function << "' failed." << endl; - -} - -void TDECModuleProxy::defaults() -{ - if( d->rootMode ) - callRootModule( "defaults()" ); - if( realModule() ) - d->kcm->defaults(); -} - -TQString TDECModuleProxy::quickHelp() const -{ - - if( !d->rootMode ) - return realModule() ? realModule()->quickHelp() : TQString::null; - else - { - TQByteArray data, replyData; - TQCString replyType; - - if (kapp->dcopClient()->call(d->dcopName, d->dcopName, "quickHelp()", - data, replyType, replyData)) - kdDebug(711) << "Calling DCOP function bool changed() failed." << endl; - else - { - TQDataStream reply(replyData, IO_ReadOnly); - if (replyType == "TQString") - { - TQString result; - reply >> result; - return result; - } - else - kdDebug(711) << "DCOP function changed() returned mumbo jumbo." << endl; - } - return TQString::null; - } -} - -const TDEAboutData * TDECModuleProxy::aboutData() const -{ - if( !d->rootMode ) - return realModule() ? realModule()->aboutData() : 0; - else - /* This needs fixing, perhaps cache a TDEAboutData copy - * while in root mode? */ - return 0; - - -} - -int TDECModuleProxy::buttons() const -{ - return realModule() ? realModule()->buttons() : - TDECModule::Help | TDECModule::Default | TDECModule::Apply ; -} - -TQString TDECModuleProxy::rootOnlyMsg() const -{ - return realModule() ? realModule()->rootOnlyMsg() : TQString::null; -} - -bool TDECModuleProxy::useRootOnlyMsg() const -{ - return realModule() ? realModule()->useRootOnlyMsg() : true; -} - -TDEInstance * TDECModuleProxy::instance() const -{ - return realModule() ? realModule()->instance() : 0; -} - -bool TDECModuleProxy::changed() const -{ - return d->changed; -} - -const TDECModuleInfo& TDECModuleProxy::moduleInfo() const -{ - return d->modInfo; -} - -bool TDECModuleProxy::rootMode() const -{ - return d->rootMode; -} - -TQCString TDECModuleProxy::dcopName() const -{ - return d->dcopName; -} - -void TDECModuleProxy::emitQuickHelpChanged() -{ - emit quickHelpChanged(); -} - -/***************************************************************/ -#include "kcmoduleproxy.moc" - -// vim: sw=4 ts=4 noet diff --git a/kutils/kcmoduleproxy.h b/kutils/kcmoduleproxy.h deleted file mode 100644 index 2ffeabf56..000000000 --- a/kutils/kcmoduleproxy.h +++ /dev/null @@ -1,358 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - Copyright (C) 2004 Frans Englich - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - 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 KCMODULEPROXY_H -#define KCMODULEPROXY_H - -#include -#include - -#include -#include - -class TDEAboutData; -class TDECModule; -class TDECModuleInfo; -class TDEInstance; -class TDEProcess; - -/** - * @ingroup kcmodule - * - * @brief Encapsulates a TDECModule for embedding. - * - * TDECModuleProxy is a wrapper for TDECModule intended for cases where - * modules are to be displayed. It ensures layout is consistent, handles - * root/administrator modules and in general takes care of the details - * needed for making a module available in an interface. A TDECModuleProxy - * can be treated as a TQWidget, without worrying about the details specific - * for modules such as library loading. TDECModuleProxy is not a sub class of TDECModule - * but its API closely resembles TDECModule's.\n - * Usually, an instance is created by passing one of the constructors a KService::Ptr, - * TDECModuleInfo or simply the name of the module and then added to the layout as any - * other widget. \n - * When the user have changed the module, changed( bool ) as well as changed ( TDECModuleProxy * ) - * is emitted. TDECModuleProxy does not take care of prompting for saving - if the object is deleted while - * changes is not saved the changes will be lost. changed() returns true if changes are unsaved. \n - * \n - * TDECModuleProxy does not take care of authorization of TDECModules. \n - * TDECModuleProxy do lazy loading, meaning the library will not be loaded or - * any other initialization done before its show() function is called. This means - * modules will only be loaded when they are actually needed as well as it is possible to - * load many TDECModuleProxy without any speed penalty. - * - * TDECModuleProxy should be used in all cases where modules are embedded in order to - * promote code efficiency and usability consistency. - * - * @author Frans Englich - * @author Matthias Kretz - * - */ -class KUTILS_EXPORT TDECModuleProxy : public TQWidget -{ -Q_OBJECT - - - friend class TDECModuleProxyRootCommunicatorImpl; - -public: - - /** - * Constructs a TDECModuleProxy from a TDECModuleInfo class. - * - * @param info The TDECModuleInfo to construct the module from. - * @param withFallback If set to true and loading of the module fails, - * a alternative will be tried, resulting in the module appearing in its - * own window, if at all. - * The embedded module will be load()ed. - * @param parent the parent TQWidget. - * @param name the module's name. - * @param args This is used in the implementation and is internal. - * Use the default. - */ - TDECModuleProxy( const TDECModuleInfo & info, bool withFallback = true, - TQWidget * parent = 0, const char * name = 0, - const TQStringList & args = TQStringList() ); - - /** - * Constructs a TDECModuleProxy from a module's service name, which is - * equivalent to the desktop file for the kcm without the ".desktop" part. - * Otherwise equal to the one above. - * - * @param serviceName The module's service name to construct from. - * @param withFallback If set to true and loading of the module fails, - * a alternative will be tried, resulting in the module appearing in its - * own window, if at all. - * The embedded module will be load()ed. - * @param parent the parent TQWidget. - * @param name the module's name. - * @param args This is used in the implementation and is internal. - * Use the default. - */ - TDECModuleProxy( const TQString& serviceName, bool withFallback = true, - TQWidget * parent = 0, const char * name = 0, - const TQStringList & args = TQStringList() ); - - /** - * Constructs a TDECModuleProxy from KService. Otherwise equal to the one above. - * - * @param service The KService to construct from. - * @param withFallback If set to true and loading of the module fails, - * a alternative will be tried, resulting in the module appearing in its - * own window, if at all. - * The embedded module will be load()ed. - * @param parent the parent TQWidget. - * @param name the module's name. - * @param args This is used in the implementation and is internal. - * Use the default. - */ - TDECModuleProxy( const KService::Ptr& service, bool withFallback = true, - TQWidget * parent = 0, const char * name = 0, - const TQStringList & args = TQStringList() ); - - /** - * Default destructor - */ - ~TDECModuleProxy(); - - /** - * Calling it will cause the contained module to - * run its load() routine. - */ - void load(); - - /** - * Calling it will cause the contained module to - * run its save() routine. - * - * If the module was not modified, it will not be asked - * to save. - */ - void save(); - - /** - * @return the module's quickHelp(); - */ - TQString quickHelp() const; - - /** - * @return the module's aboutData() - */ - const TDEAboutData * aboutData() const; - - /** - * @return what buttons the module - * needs - */ - int buttons() const; - - /** - * @return The module's custom root - * message, if it has one - * @deprecated - */ - TQString rootOnlyMsg() const; - //KDE4 remove. There's a limit for convenience functions, - // this one's available via moduleInfo()-> and realModule()-> - - /** - * @return If the module is a root module. - * @deprecated - */ - bool useRootOnlyMsg() const; - //KDE4 remove. There's a limit for convenience functions, - // this one's available via moduleInfo()-> and realModule()-> - - /** - * Returns the embedded TDECModule's TDEInstance. - * @return The module's TDEInstance. - * @deprecated - */ - TDEInstance * instance() const; - //KDE4 remove. There's a limit for convenience functions, - // this one's available via realModule() - - /** - * @return true if the module is modified - * and needs to be saved. - */ - bool changed() const; - - /** - * Returns whether the module is running in root mode. A module is in root mode - * when runAsRoot() has been called. A session under root user will never reach - * root mode. - * - * @note realModule() will return null when the module is running in root mode. - * - * @return true if the module is running with root privileges - * @since 3.4 - */ - bool rootMode() const; - - /** - * Access to the actual module. However, if the module is - * running in root mode, see rootMode(), this function returns - * a NULL pointer, since the module is in another process. It may also - * return NULL if anything goes wrong. - * - * @return the encapsulated module. - */ - TDECModule* realModule() const; - - /** - * @return a TDECModuleInfo for the encapsulated - * module - */ - const TDECModuleInfo& moduleInfo() const; - - /** - * Returns the DCOP the module's DCOPClient - * and DCOPObject has(they are identical). - * - * @since 3.4 - */ - TQCString dcopName() const; - -public slots: - - /** - * Calling this will cause the module to be run in - * "administrator mode". - * - * @since 3.4 - */ - void runAsRoot(); - - /** - * Calling it will cause the contained module to - * load its default values. - */ - void defaults(); - - /** - * Calling this, results in deleting the contained - * module, and unregistering from DCOP. A similar result is achieved - * by deleting the TDECModuleProxy itself. - * - * @since 3.4 - */ - void deleteClient(); - -signals: - - /* - * This signal is emitted when the contained module is changed. - */ - void changed( bool state ); - - /** - * This is emitted in the same situations as in the one above. Practical - * when several TDECModuleProxys are loaded. - * - * @since 3.4 - */ - void changed( TDECModuleProxy* mod ); - - /** - * When a module running with root privileges and exits, returns to normal mode, the - * childClosed() signal is emitted. - * - * @since 3.4 - */ - void childClosed(); - - /* - * This signal is relayed from the encapsulated module, and - * is equivalent to the module's own quickHelpChanged() signal. - * - * @since 3.4 - */ - void quickHelpChanged(); - -protected: - - /** - * Reimplemented for internal purposes. Makes sure the encapsulated - * module is loaded before the show event is taken care of. - */ - void showEvent( TQShowEvent * ); - - /** - * Internal intialization function, called by the constructors. - * - * @internal - * @since 3.4 - */ - void init( const TDECModuleInfo& info ); - - - /** - * Emits the quickHelpChanged signal. - * @since 3.4 - */ - void emitQuickHelpChanged(); - -private slots: - - /** - * Calls the function @p function of the root module's TDECModuleProxy - * DCOP interface. - * - * @param function the function signature of the function to call. - * @since 3.4 - */ - void callRootModule( const TQCString& function ); - - /** - * This is called when the module exits from root mode. It zeroes - * pointers, deletes the embed window, and so forth. - * - * @since 3.4 - */ - void rootExited(); - - /** - * Makes sure the proper variables is set and signals are emitted. - */ - void moduleChanged( bool ); - - /** - * Zeroes d->kcm - */ - void moduleDestroyed(); - - /** - * Gets called by DCOP when an application closes. - * Is used to (try to) reload a KCM which previously - * was loaded. - * - * @since 3.4 - */ - void applicationRemoved( const TQCString& app ); - -private: - - class TDECModuleProxyPrivate; - TDECModuleProxyPrivate * d; -}; - -#endif // KCMODULEPROXY_H -// vim: sw=4 ts=4 noet diff --git a/kutils/kcmoduleproxyIface.h b/kutils/kcmoduleproxyIface.h deleted file mode 100644 index 5bf24ac91..000000000 --- a/kutils/kcmoduleproxyIface.h +++ /dev/null @@ -1,121 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2004 Frans Englich - - 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 __KCMODULEPROXYIFACE_H__ -#define __KCMODULEPROXYIFACE_H__ - -#include - -/** - * @ingroup kcmodule - * @brief DCOP Interface for TDECModule. - * - * A module (which is loaded via TDECModuleProxy) does always have - * this DCOP interface, whether it's in root mode or not. - * - * @since 3.4 - * @internal - * @author Frans Englich - */ -class TDECModuleProxyIface : virtual public DCOPObject -{ - K_DCOP - -k_dcop: - - /** - * Return the caption of the host application which the module - * is part in. This is the application name, or similar. - * - * @returns the host's name - */ - virtual TQString applicationName() = 0; - - /** - * Save settings. - */ - virtual void save() = 0; - - /** - * Load settings. - */ - virtual void load() = 0; - - /** - * Load defaults. - */ - virtual void defaults() = 0; - - /** - * Returns the module's quick help. - */ - virtual TQString quickHelp() = 0; - - /** - * @returns true if the module has unsaved - * data, typically. - */ - virtual bool changed() = 0; - -k_dcop_signals: - - /** - * Emitted when the state of the module changes. @p c - * is true when the content is changed, otherwise false. - * - * @param c true if the module is modified, false if its not. - * @param module a string identifying the module which was changed. This - * is typically "TDECModuleProx-X" where X is the module's name. - */ - virtual void changed( bool c ); - - virtual void quickHelpChanged(); - -}; - -/** - * @ingroup kcmodule - * @brief DCOP interface for communicating with the real module running in root mode. - * - * When a TDECModuleProxy tells kcmshell to load "itself" and embed into the - * TDECModuleProxy, this DCOP interface is used to communicate to the real TDECModuleProxy, since - * the TDECModuleProxy which told kcmshell to load itself, is nothing but a shell. - * - * Currently is only the changed signal routed, but it's possible to proxy - * the rest of the TDECModuleProxy API, if it turns out necessary. - * - * @since 3.4 - * @internal - * @author Frans Englich - */ -class TDECModuleProxyRootDispatcher : virtual public DCOPObject -{ - K_DCOP - -k_dcop: - - /** - * TDECModuleProxyIface::changed() gets connected to this. - */ - virtual void changed( bool c ) = 0; - - virtual void quickHelpChanged() = 0; -}; - -#endif // __KCMODULEPROXYIFACE_H__ diff --git a/kutils/kcmoduleproxyIfaceImpl.cpp b/kutils/kcmoduleproxyIfaceImpl.cpp deleted file mode 100644 index 5e1ca4986..000000000 --- a/kutils/kcmoduleproxyIfaceImpl.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2004 Frans Englich - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License version 2 as published by the Free Software Foundation. - * - * 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 -#include - -#include - -#include -#include -#include - -#include "kcmoduleproxyIfaceImpl.h" - - -#include - -TDECModuleProxyIfaceImpl::TDECModuleProxyIfaceImpl( const TQCString& name, - TDECModuleProxy* const client ) - : DCOPObject( name ), TQObject( 0, name ), - p( const_cast( client )) -{ - connect( p, TQT_SIGNAL( changed(bool)), - TQT_SLOT( changedRelay(bool))); - connect( p, TQT_SIGNAL( quickHelpChanged()), - TQT_SLOT( quickHelpRelay())); -} - -void TDECModuleProxyIfaceImpl::save() -{ - kdDebug(711) << k_funcinfo << endl; - p->save(); -} - -void TDECModuleProxyIfaceImpl::load() -{ - kdDebug(711) << k_funcinfo << endl; - p->load(); -} - -void TDECModuleProxyIfaceImpl::defaults() -{ - kdDebug(711) << k_funcinfo << endl; - p->defaults(); -} - -TQString TDECModuleProxyIfaceImpl::applicationName() -{ - return kapp->caption(); -} - -TQString TDECModuleProxyIfaceImpl::quickHelp() -{ - return p->quickHelp(); -} - -bool TDECModuleProxyIfaceImpl::changed() -{ - return p->changed(); -} - -void TDECModuleProxyIfaceImpl::changedRelay( bool c ) -{ - TQByteArray data; - TQDataStream stream(data, IO_WriteOnly); - stream << c; - emitDCOPSignal( "changed(bool)", data ); -} - -void TDECModuleProxyIfaceImpl::quickHelpRelay() -{ - TQByteArray data; - emitDCOPSignal( "quickHelpChanged()", data ); -} - -/***************************************************************/ - - - - -/***************************************************************/ -TDECModuleProxyRootCommunicatorImpl::TDECModuleProxyRootCommunicatorImpl - ( const TQCString& name, TDECModuleProxy* const client ) - : DCOPObject( name ), TQObject( 0, name ), - p( const_cast( client )) -{ - /* - * Connect kcmshell's TDECModuleProxy's change signal - * to us, such that we act as a proxy for - * TDECModuleProxy's API. - */ - - /* Note, we don't use TDECModuleProxy::d->dcopClient */ - kapp->dcopClient()->connectDCOPSignal( 0, p->dcopName(), - "changed(bool)", objId(), "changed(bool)", false ); - - kapp->dcopClient()->connectDCOPSignal( 0, p->dcopName(), - "quickHelpChanged()", objId(), "quickHelpChanged()", false ); -} - -/* Reimplementations of DCOP members */ -void TDECModuleProxyRootCommunicatorImpl::changed( bool c ) -{ - kdDebug(711) << k_funcinfo << endl; - p->moduleChanged( c ); -} - -void TDECModuleProxyRootCommunicatorImpl::quickHelpChanged() -{ - kdDebug(711) << k_funcinfo << endl; - p->emitQuickHelpChanged(); -} - -#include "kcmoduleproxyIfaceImpl.moc" diff --git a/kutils/kcmoduleproxyIfaceImpl.h b/kutils/kcmoduleproxyIfaceImpl.h deleted file mode 100644 index 9de3d58dd..000000000 --- a/kutils/kcmoduleproxyIfaceImpl.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2004 Frans Englich - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License version 2 as published by the Free Software Foundation. - * - * 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 __KCMODULEPROXYIFACEIMPL_H__ -#define __KCMODULEPROXYIFACEIMPL_H__ - -#include "kcmoduleproxyIface.h" - -class TDECModuleProxy; - -/***************************************************************/ -/** @internal - @ingroup internal */ -class TDECModuleProxyIfaceImpl: public TQObject, virtual public TDECModuleProxyIface -{ - /* KDE4 Merge TDECModuleProxyIfaceImpl with TDECModuleProxy(MI) - * if it doesn't break what DCOPClient it binds to. - * Update: This is probably not possible, since we don't want the DCOPObject when - * we're running in root mode. */ - - Q_OBJECT - -public: - - /* Reimplementations of DCOP members */ - TDECModuleProxyIfaceImpl( const TQCString& name, TDECModuleProxy* const client ); - - virtual void save(); - - virtual void load(); - - virtual void defaults(); - - virtual TQString applicationName(); - - virtual TQString quickHelp(); - - virtual bool changed(); -public slots: - - /** - * Emits the changed(bool) DCOP signal. - */ - void changedRelay( bool c ); - - /** - * Simply relays TDECModuleProxy's signal with the same name. - */ - void quickHelpRelay(); - - -private: - - TDECModuleProxy* p; -}; -/***************************************************************/ - - - - -/***************************************************************/ -/** @internal - @ingroup internal */ -class TDECModuleProxyRootCommunicatorImpl: public TQObject, - virtual public TDECModuleProxyRootDispatcher -{ - Q_OBJECT - -public: - TDECModuleProxyRootCommunicatorImpl( const TQCString& name, TDECModuleProxy* const client ); - - /* Reimplementations of DCOP members */ - virtual void changed( bool c ); - - virtual void quickHelpChanged(); - -TDECModuleProxy* p; -}; -/***************************************************************/ - -#endif // __KCMODULEPROXYIFACEIMPL_H__ - diff --git a/kutils/kcmultidialog.cpp b/kutils/kcmultidialog.cpp index 5fe862177..b09f25e88 100644 --- a/kutils/kcmultidialog.cpp +++ b/kutils/kcmultidialog.cpp @@ -38,8 +38,8 @@ #include #include -#include "kcmoduleloader.h" -#include "kcmoduleproxy.h" +#include "tdecmoduleloader.h" +#include "tdecmoduleproxy.h" #include "kcmultidialog.h" #include "kcmultidialog.moc" diff --git a/kutils/kcmultidialog.h b/kutils/kcmultidialog.h index 7c89621ca..46dde98fb 100644 --- a/kutils/kcmultidialog.h +++ b/kutils/kcmultidialog.h @@ -33,7 +33,7 @@ class TDECModuleProxy; class TDECModuleInfo; /** - * @ingroup kcmodule + * @ingroup tdecmodule * @short A method that offers a KDialogBase containing arbitrary * KControl Modules. * diff --git a/kutils/kpluginselector.cpp b/kutils/kpluginselector.cpp index 7f07b7ed2..fb1386106 100644 --- a/kutils/kpluginselector.cpp +++ b/kutils/kpluginselector.cpp @@ -43,22 +43,22 @@ #include #include #include -#include +#include #include #include #include #include #include -#include -#include "kcmoduleinfo.h" -#include "kcmoduleloader.h" +#include +#include "tdecmoduleinfo.h" +#include "tdecmoduleloader.h" #include #include #include "kplugininfo.h" #include #include #include -#include "kcmoduleproxy.h" +#include "tdecmoduleproxy.h" /* QCheckListViewItem that holds a pointer to the KPluginInfo object. diff --git a/kutils/ksettings/dialog.cpp b/kutils/ksettings/dialog.cpp index 727ca1072..e3bfa579f 100644 --- a/kutils/ksettings/dialog.cpp +++ b/kutils/ksettings/dialog.cpp @@ -33,7 +33,7 @@ #include #include #include -#include "kcmoduleinfo.h" +#include "tdecmoduleinfo.h" namespace KSettings { diff --git a/kutils/ksettings/pluginpage.h b/kutils/ksettings/pluginpage.h index 2ba4f2142..7f5c7e952 100644 --- a/kutils/ksettings/pluginpage.h +++ b/kutils/ksettings/pluginpage.h @@ -20,7 +20,7 @@ #ifndef KSETTINGS_PLUGINPAGE_H #define KSETTINGS_PLUGINPAGE_H -#include +#include #include class KPluginSelector; diff --git a/kutils/tdecmodulecontainer.cpp b/kutils/tdecmodulecontainer.cpp new file mode 100644 index 000000000..04cbf6751 --- /dev/null +++ b/kutils/tdecmodulecontainer.cpp @@ -0,0 +1,258 @@ +/* This file is part of the KDE libraries + Copyright (C) 2004 Frans Englich + + 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tdecmodulecontainer.h" +#include "tdecmodulecontainer.moc" + +/***********************************************************************/ +class TDECModuleContainer::TDECModuleContainerPrivate +{ + public: + TDECModuleContainerPrivate( const TQStringList& mods ) + : modules( mods ) + , tabWidget( 0 ) + , buttons( 0 ) + , hasRootKCM( false ) + , btnRootMode( 0 ) + , btnLayout( 0 ) + , topLayout( 0 ) + {} + + TQStringList modules; + TQTabWidget *tabWidget; + int buttons; + bool hasRootKCM: 1; + KPushButton *btnRootMode; + TQHBoxLayout *btnLayout; + TQVBoxLayout *topLayout; + + +}; +/***********************************************************************/ + + + + + +/***********************************************************************/ +TDECModuleContainer::TDECModuleContainer( TQWidget* parent, const char* name, + const TQString& mods ) + : TDECModule( parent, name ) +{ + d = new TDECModuleContainerPrivate( TQStringList::split( ",", TQString(mods).remove( " " )) ); + init(); +} + +TDECModuleContainer::TDECModuleContainer( TQWidget* parent, const char* name, + const TQStringList& mods ) + : TDECModule( parent, name ), d( new TDECModuleContainerPrivate( mods ) ) +{ + init(); +} + +void TDECModuleContainer::init() +{ + d->topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint(), "topLayout" ); + d->tabWidget = new TQTabWidget(this, "tabWidget"); + d->tabWidget->setMargin(KDialog::marginHint()); + connect( d->tabWidget, TQT_SIGNAL( currentChanged( TQWidget* ) ), TQT_SLOT( tabSwitched( TQWidget* ) )); + d->topLayout->addWidget( d->tabWidget ); + + if ( !d->modules.isEmpty() ) + { + /* Add our modules */ + for ( TQStringList::Iterator it = d->modules.begin(); it != d->modules.end(); ++it ) + addModule( (*it) ); + + finalize(); + } + +} + +void TDECModuleContainer::finalize() +{ + setButtons( d->buttons ); + if ( d->hasRootKCM ) /* Add a root mode button */ + { + if(!d->btnLayout) /* It could already be added */ + { + d->btnLayout = new TQHBoxLayout(this, 0, 0, "btnLayout"); + d->btnRootMode = new KPushButton(KStdGuiItem::adminMode(), this, "btnRootMode"); + + d->btnLayout->addWidget( d->btnRootMode ); + d->btnLayout->addStretch(); + d->topLayout->addLayout( d->btnLayout ); + } + } +} + +void TDECModuleContainer::addModule( const TQString& module ) +{ + /* In case it doesn't exist we just silently drop it. + * This allows people to easily extend containers. + * For example, KCM monitor gamma can be in tdegraphics. + */ + if ( !KService::serviceByDesktopName( module ) ) + { + kdDebug(713) << "TDECModuleContainer: module '" << + module << "' was not found and thus not loaded" << endl; + return; + } + + if( !TDECModuleLoader::testModule( module )) + return; + + TDECModuleProxy* proxy = new TDECModuleProxy( module, false, d->tabWidget, module.latin1()); + allModules.append( proxy ); + + d->tabWidget->addTab( proxy, TQIconSet(TDEGlobal::iconLoader()->loadIcon( + proxy->moduleInfo().icon(), KIcon::Desktop)), + /* QT eats ampersands for dinner. But not this time. */ + proxy->moduleInfo().moduleName().replace( "&", "&&" )); + + d->tabWidget->setTabToolTip( proxy, proxy->moduleInfo().comment() ); + + connect( proxy, TQT_SIGNAL(changed(TDECModuleProxy *)), TQT_SLOT(moduleChanged(TDECModuleProxy *))); + + /* Collect our buttons - we go for the common deliminator */ + d->buttons = d->buttons | proxy->realModule()->buttons(); + + /* If we should add an Administrator Mode button */ + if ( proxy->moduleInfo().needsRootPrivileges() ) + d->hasRootKCM=true; + + +} + +void TDECModuleContainer::tabSwitched( TQWidget * module ) +{ + if ( !d->hasRootKCM ) + return; + + /* Not like this. Not like this. */ + disconnect( d->btnRootMode, 0, 0, 0 ); + /* Welcome to the real world huh baby? */ + + TDECModuleProxy* mod = (TDECModuleProxy *) module; + + if ( mod->moduleInfo().needsRootPrivileges() && !mod->rootMode() ) + { + d->btnRootMode->setEnabled( true ); + connect( d->btnRootMode, TQT_SIGNAL( clicked() ), + TQT_SLOT( runAsRoot() )); + connect( mod, TQT_SIGNAL( childClosed() ), + TQT_SLOT ( rootExited() )); + } + else + d->btnRootMode->setEnabled( false ); + + setQuickHelp( mod->quickHelp() ); + setAboutData( const_cast(mod->aboutData()) ); + +} + +void TDECModuleContainer::runAsRoot() +{ + if ( d->tabWidget->currentPage() ) + ( (TDECModuleProxy *) d->tabWidget->currentPage() )->runAsRoot(); + d->btnRootMode->setEnabled( false ); +} + +void TDECModuleContainer::rootExited() +{ + connect( d->btnRootMode, TQT_SIGNAL( clicked() ), TQT_SLOT( runAsRoot() )); + d->btnRootMode->setEnabled( true ); +} + +void TDECModuleContainer::save() +{ + ModuleList list = changedModules; + ModuleList::iterator it; + for ( it = list.begin() ; it !=list.end() ; ++it ) + { + (*it)->save(); + } + + emit changed( false ); + +} + +void TDECModuleContainer::load() +{ + ModuleList list = allModules; + ModuleList::iterator it; + for ( it = list.begin() ; it !=list.end() ; ++it ) + { + (*it)->load(); + } + + emit changed( false ); +} + +void TDECModuleContainer::defaults() +{ + ModuleList list = allModules; + ModuleList::iterator it; + for ( it = list.begin() ; it !=list.end() ; ++it ) + { + (*it)->defaults(); + } + + emit changed( true ); +} + + +void TDECModuleContainer::moduleChanged(TDECModuleProxy * proxy) +{ + changedModules.append( proxy ); + if( changedModules.isEmpty() ) + return; + + emit changed(true); +} + +TDECModuleContainer::~TDECModuleContainer() +{ + delete d; +} + +/***********************************************************************/ + + + + diff --git a/kutils/tdecmodulecontainer.h b/kutils/tdecmodulecontainer.h new file mode 100644 index 000000000..5708f80cf --- /dev/null +++ b/kutils/tdecmodulecontainer.h @@ -0,0 +1,207 @@ +/* This file is part of the KDE libraries + Copyright (C) 2004 Frans Englich + + 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 KCMODULECONTAINER_H +#define KCMODULECONTAINER_H + +#include +#include +#include + +#include +#include + +class TQTabWidget; +class TQWidget; +class TQVBoxLayout; + +class TDECModuleProxy; + +/** + * @ingroup tdecmodule + * @brief TDECModuleContainer is a convenience class encapsulating several TDECModules. + * + * The TDECModuleContainer class is a convenience class for organizing a multiple set + * of TDECModule. TDECModuleContainer is a sub class of TDECModule and builds an interface mainly + * consisting of a tab widget where each tab contains one of the modules specified via one of the + * constructors. TDECModuleContainer can handle modules which requires root permissions. What you + * most likely want is the KCMODULECONTAINER macro. \n + * Sometimes it is of interest to detect in runtime whether a module should be loaded or not. This + * can be achieved by sub classing TDECModuleContainer, doing the probing/testing checks and then manually + * call addModule for each module which should be displayed. When all calls to addModule is done, call + * finalize() which performs some necessary final steps. + * + * @author Frans Englich + * @since 3.4 + */ +class KUTILS_EXPORT TDECModuleContainer : public TDECModule +{ + Q_OBJECT + public: + /** + * Creates a TDECModuleContainer with tabs, each one containing one of the + * specified modules in @p mods. + * + * @param parent the parent TQWidget. + * @param name the module's name. + * @param mods The list of TDECModules to be loaded. The name of each + * TDECModule is its service name, that is the name of the desktop file without + * the ".desktop" part + * + */ + TDECModuleContainer( TQWidget* parent, const char* name, const TQStringList& mods ); + + /** + * This is a convenience function, instead of building a TQStringList you + * can specify the modules in a comma separated TQString. For example; + * \code + * TDECModuleContainer* cont = TDECModuleContainer( this, "kcm_misc", TQString("kcm_energy, kcm_keyboard ,kcm_useraccount, kcm_mouse") ); + * \endcode + * The other constructor takes its modules in a QStringlist which also can be constructed from a + * string and thus you will have to be explicit on the data type. + * + * What you probably want is the KCMODULECONTAINER macro which builds an TDECModule + * for you, taking the modules you want as argument. + * + * @param parent The parent widget + * @param name The service name + * @param mods The modules to load + * @return The TDECModule containing the requested modules. + */ + TDECModuleContainer( TQWidget *parent, const char* name, const TQString& mods = TQString() ); + + /** + * Adds the specified module to the tab widget. Setting the tab icon, text, + * tool tip, connecting the signals is what it does. + * + * @param module the name of the module to add. The name is the desktop file's name + * without the ".desktop" part. + */ + void addModule( const TQString& module ); + + /** + * Default destructor. + */ + virtual ~TDECModuleContainer(); + + /** + * Reimplemented for internal purposes. + * @internal + */ + void save(); + + /** + * Reimplemented for internal purposes. + * @internal + */ + void load(); + + /** + * Reimplemented for internal purposes. + * @internal + */ + void defaults(); + + protected: + + /** + * Sets this KCM's buttons and adds a AdminMode button + * if necessary. If TDECModuleContainer is subclassed finalize() + * should be called in the constructor after all calls to addModule + * have been done. Call it once. + */ + void finalize(); + + typedef TQValueList ModuleList; + + /** + * A list containing TDECModuleProxy objects which + * have changed and must be saved. + */ + ModuleList changedModules; + + /** + * A list of all modules which are encapsulated. + */ + ModuleList allModules; // KDE 4 put in the Private class and abstract with getter + + private slots: + + /** + * Enables/disables the Admin Mode button, as appropriate. + */ + void tabSwitched( TQWidget * module ); + + void moduleChanged(TDECModuleProxy *proxy); + + /** + * Called when the user clicks our custom root button. + */ + void runAsRoot(); + + /** + * Enables the admin mode button + */ + void rootExited(); + + private: + + void init(); + + class TDECModuleContainerPrivate; + TDECModuleContainerPrivate *d; + +}; + +/** + * @ingroup tdecmodule + * This macro creates an factory declaration which when run creates an TDECModule with specified + * modules. For example: + * \code + * KCMODULECONTAINER( "kcm_fonts, kcm_keyboard,kcm_fonts", misc_modules) + * \endcode + * would create a TDECModule with three tabs, each containing one of the specified KCMs. Each + * use of the macro must be accompanied by a desktop file where the factory name equals + * the second argument in the macro(in this example, misc_modules). \n + * The module container takes care of testing the contained modules when being shown, as well + * as when the module itself is asked whether it should be shown. + * + * @param modules the modules to put in the container + * @param factoryName what factory name the module should have + */ +#define KCMODULECONTAINER( modules, factoryName ) \ +extern "C" \ +{ \ + TDECModule *create_## factoryName(TQWidget *parent, const char *name) \ + { \ + return new TDECModuleContainer( parent, name, TQString( modules ) ); \ + } \ + \ + bool test_## factoryName() \ + { \ + TQStringList modList = TQStringList::split( ",", TQString(modules).remove( " " )); \ + for ( TQStringList::Iterator it = modList.begin(); it != modList.end(); ++it ) \ + if ( TDECModuleLoader::testModule( *it ) ) \ + return true; \ + return false; \ + } \ +} + +#endif // KCMODULECONTAINER_H + diff --git a/kutils/tdecmoduleinfo.cpp b/kutils/tdecmoduleinfo.cpp new file mode 100644 index 000000000..3a7fdfd63 --- /dev/null +++ b/kutils/tdecmoduleinfo.cpp @@ -0,0 +1,242 @@ +/* + Copyright (c) 1999 Matthias Hoelzer-Kluepfel + Copyright (c) 2000 Matthias Elter + Copyright (c) 2003 Daniel Molkentin + Copyright (c) 2003 Matthias Kretz + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + 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 + +#include +#include +#include +#include +#include + +#include "tdecmoduleinfo.h" + +class TDECModuleInfo::TDECModuleInfoPrivate +{ + public: + TDECModuleInfoPrivate() : + testModule( false ) + {} + ~TDECModuleInfoPrivate() + { } + + TQString factoryName; + bool testModule; + +}; + +TDECModuleInfo::TDECModuleInfo() +{ + _allLoaded = false; + d = new TDECModuleInfoPrivate; +} + +TDECModuleInfo::TDECModuleInfo(const TQString& desktopFile) +{ + KService::Ptr service = KService::serviceByStorageId(desktopFile); + if(!service) setName(desktopFile); + init(service); +} + +TDECModuleInfo::TDECModuleInfo( KService::Ptr moduleInfo ) +{ + init(moduleInfo); +} + +TDECModuleInfo::TDECModuleInfo( const TDECModuleInfo &rhs ) +{ + d = new TDECModuleInfoPrivate; + ( *this ) = rhs; +} + +// this re-implementation exists to ensure that other code always calls +// our re-implementation, so in case we add data to the d pointer in the future +// we can be sure that we get called when we are copied. +TDECModuleInfo &TDECModuleInfo::operator=( const TDECModuleInfo &rhs ) +{ + _keywords = rhs._keywords; + _name = rhs._name; + _icon = rhs._icon; + _lib = rhs._lib; + _handle = rhs._handle; + _fileName = rhs._fileName; + _doc = rhs._doc; + _comment = rhs._comment; + _needsRootPrivileges = rhs._needsRootPrivileges; + _isHiddenByDefault = rhs._isHiddenByDefault; + _allLoaded = rhs._allLoaded; + _service = rhs._service; + + *d = *(rhs.d); + + return *this; +} + +TQString TDECModuleInfo::factoryName() const +{ + if( d->factoryName.isEmpty() ) + { + d->factoryName = _service->property("X-TDE-FactoryName", TQVariant::String).toString(); + if ( d->factoryName.isEmpty() ) + d->factoryName = library(); + } + + return d->factoryName; +} + +bool TDECModuleInfo::operator==( const TDECModuleInfo & rhs ) const +{ + return ( ( _name == rhs._name ) && ( _lib == rhs._lib ) && ( _fileName == rhs._fileName ) ); +} + +bool TDECModuleInfo::operator!=( const TDECModuleInfo & rhs ) const +{ + return ! operator==( rhs ); +} + +TDECModuleInfo::~TDECModuleInfo() +{ + delete d; +} + +void TDECModuleInfo::init(KService::Ptr s) +{ + _allLoaded = false; + d = new TDECModuleInfoPrivate; + + if ( s ) + _service = s; + else + { + kdDebug(712) << "Could not find the service." << endl; + return; + } + + // set the modules simple attributes + setName(_service->name()); + setComment(_service->comment()); + setIcon(_service->icon()); + + _fileName = ( _service->desktopEntryPath() ); + + // library and factory + setLibrary(_service->library()); + + // get the keyword list + setKeywords(_service->keywords()); +} + +void +TDECModuleInfo::loadAll() +{ + if( !_service ) /* We have a bogus service. All get functions will return empty/zero values */ + return; + + _allLoaded = true; + + // library and factory + setHandle(_service->property("X-TDE-FactoryName", TQVariant::String).toString()); + + TQVariant tmp; + + // read weight + tmp = _service->property( "X-TDE-Weight", TQVariant::Int ); + setWeight( tmp.isValid() ? tmp.toInt() : 100 ); + + // does the module need super user privileges? + tmp = _service->property( "X-TDE-RootOnly", TQVariant::Bool ); + setNeedsRootPrivileges( tmp.isValid() ? tmp.toBool() : false ); + + // does the module need to be shown to root only? + // Deprecated ! KDE 4 + tmp = _service->property( "X-TDE-IsHiddenByDefault", TQVariant::Bool ); + setIsHiddenByDefault( tmp.isValid() ? tmp.toBool() : false ); + + // get the documentation path + setDocPath( _service->property( "DocPath", TQVariant::String ).toString() ); + + tmp = _service->property( "X-TDE-Test-Module", TQVariant::Bool ); + setNeedsTest( tmp.isValid() ? tmp.asBool() : false ); +} + +TQString +TDECModuleInfo::docPath() const +{ + if (!_allLoaded) + const_cast(this)->loadAll(); + + return _doc; +} + +TQString +TDECModuleInfo::handle() const +{ + if (!_allLoaded) + const_cast(this)->loadAll(); + + if (_handle.isEmpty()) + return _lib; + + return _handle; +} + +int +TDECModuleInfo::weight() const +{ + if (!_allLoaded) + const_cast(this)->loadAll(); + + return _weight; +} + +bool +TDECModuleInfo::needsRootPrivileges() const +{ + if (!_allLoaded) + const_cast(this)->loadAll(); + + return _needsRootPrivileges; +} + +bool +TDECModuleInfo::isHiddenByDefault() const +{ + if (!_allLoaded) + const_cast(this)->loadAll(); + + return _isHiddenByDefault; +} + +bool TDECModuleInfo::needsTest() const +{ + return d->testModule; +} + +void TDECModuleInfo::setNeedsTest( bool val ) +{ + d->testModule = val; +} + + + +// vim: ts=2 sw=2 et diff --git a/kutils/tdecmoduleinfo.h b/kutils/tdecmoduleinfo.h new file mode 100644 index 000000000..0bd7c44e3 --- /dev/null +++ b/kutils/tdecmoduleinfo.h @@ -0,0 +1,296 @@ +/* + Copyright (c) 1999 Matthias Hoelzer-Kluepfel + Copyright (c) 2000 Matthias Elter + Copyright (c) 2003 Daniel Molkentin + Copyright (c) 2003 Matthias Kretz + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + 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 KCMODULEINFO_H +#define KCMODULEINFO_H + +#include + +class TQPixmap; +class TQString; +class TQStringList; + +/** + * @ingroup tdecmodule + * A class that provides information about a TDECModule + * + * TDECModuleInfo provides various technical information, such as icon, library + * etc. about a TDECModule.n + * @note Any values set with the set* functions is not + * written back with TDECModuleInfo it only reads value from the desktop file. + * + * @internal + * @author Matthias Hoelzer-Kluepfel + * @author Matthias Elter + * @author Daniel Molkentin + * @since 3.2 + * + */ +class KUTILS_EXPORT TDECModuleInfo +{ + +public: + + /** + * Constructs a TDECModuleInfo. + * @note a TDECModuleInfo object will have to be manually deleted, it is not + * done automatically for you. + * @param desktopFile the desktop file representing the module, or + * the name of the module. + */ + TDECModuleInfo(const TQString& desktopFile); + + /** + * Same as above but takes a KService::Ptr as argument. + * + * @note @p moduleInfo must be a valid pointer. + * + * @param moduleInfo specifies the module + */ + TDECModuleInfo( KService::Ptr moduleInfo ); + + + /** + * Same as above but takes a TDECModuleInfo as argument. + * + * @param rhs specifies the module + */ + TDECModuleInfo( const TDECModuleInfo &rhs ); + + /** + * Same as above but creates an empty TDECModuleInfo. + * You should not normally call this. + * @since 3.4 + */ + TDECModuleInfo(); + + /** + * Assignment operator + */ + TDECModuleInfo &operator=( const TDECModuleInfo &rhs ); + + /** + * Equal operator + * + * @return true if @p rhs equals itself + */ + + bool operator==( const TDECModuleInfo &rhs ) const; + + /** + * @return true if @p rhs is not equal itself + */ + bool operator!=( const TDECModuleInfo &rhs ) const; + + /** + * Default destructor. + */ + ~TDECModuleInfo(); + + /** + * @return the filename of the .desktop file that describes the KCM + */ + TQString fileName() const { return _fileName; } + + /** + * @return the keywords associated with this KCM. + */ + const TQStringList &keywords() const { return _keywords; } + + /** + * Returns the module's factory name, if it's set. If not, the library + * name is returned. + * @returns the module's factory name + * @since 3.4 + */ + TQString factoryName() const; + + /** + * @return the module\'s (translated) name + */ + TQString moduleName() const { return _name; } + // changed from name() to avoid ambiguity with TQObject::name() on multiple inheritance + + /** + * @return a KSharedPtr to KService created from the modules .desktop file + */ + KService::Ptr service() const { return _service; } + + /** + * @return the module's (translated) comment field + */ + TQString comment() const { return _comment; } + + /** + * @return the module's icon name + */ + TQString icon() const { return _icon; } + + /** + * @return the path of the module's documentation + */ + TQString docPath() const; + + /** + * @return the library name + */ + TQString library() const { return _lib; } + + /** + * @return a handle (usually the contents of the FactoryName field) + */ + TQString handle() const; + + /** + * @return the weight of the module which determines the order of the pages in + * the KCMultiDialog. It's set by the X-TDE-Weight field. + */ + int weight() const; + + /** + * @return whether the module might require root permissions + */ + bool needsRootPrivileges() const; + + /** + * @deprecated + * @return the isHiddenByDefault attribute. + */ + bool isHiddenByDefault() const KDE_DEPRECATED; + + + /** + * @returns true if the module should be conditionally + * loaded. + * @since 3.4 + */ + bool needsTest() const; + + +protected: + + /** + * Sets the object's keywords. + * @param keyword the new keywords + */ + void setKeywords(const TQStringList &keyword) { _keywords = keyword; } + + /** + * Sets the object's name. + * @param name the new name + */ + void setName(const TQString &name) { _name = name; } + + /** + * Sets the object's name. + * @param comment the new comment + */ + void setComment(const TQString &comment) { _comment = comment; } + + /** + * Sets the object's icon. + * @param icon the name of the new icon + */ + void setIcon(const TQString &icon) { _icon = icon; } + + /** + * Set the object's library + * @param lib the name of the new library without any extensions or prefixs. + */ + void setLibrary(const TQString &lib) { _lib = lib; } + + /** + * Sets the factory name + * @param handle The new factory name + */ + void setHandle(const TQString &handle) { _handle = handle; } + + /** + * Sets the object's weight property which determines in what + * order modules will be displayed. Default is 100. + * + * @param weight the new weight + */ + void setWeight(int weight) { _weight = weight; } + + + /** + * Sets if the module should be tested for loading. + * @param val the value to set + * @since 3.4 + */ + void setNeedsTest( bool val ); + + /** + * Toggles whether the represented module needs root privileges. + * Use with caution. + * @param needsRootPrivileges if module needs root privilges + */ + void setNeedsRootPrivileges(bool needsRootPrivileges) + { _needsRootPrivileges = needsRootPrivileges; } + + /** + * @deprecated + */ + void setIsHiddenByDefault(bool isHiddenByDefault) + { _isHiddenByDefault = isHiddenByDefault; } + + /** + * Sets the object's documentation path + * @param p the new documentation path + */ + void setDocPath(const TQString &p) { _doc = p; } + + /** + * Reads the service entries specific for TDECModule from the desktop file. + * The usual desktop entries are read in init. + */ + void loadAll(); + +private: + + /** + * Reads the service entries. Called by the constructors. + */ + void init(KService::Ptr s); + +private: + + // KDE4 These needs to be moved to TDECModuleInfoPrivate + TQStringList _keywords; + TQString _name, _icon, _lib, _handle, _fileName, _doc, _comment; + bool _needsRootPrivileges : 1; + bool _isHiddenByDefault : 1; + bool _allLoaded : 1; + int _weight; + + KService::Ptr _service; + + class TDECModuleInfoPrivate; + TDECModuleInfoPrivate *d; + +}; + +#endif // KCMODULEINFO_H + +// vim: ts=2 sw=2 et diff --git a/kutils/tdecmoduleloader.cpp b/kutils/tdecmoduleloader.cpp new file mode 100644 index 000000000..c661ac22f --- /dev/null +++ b/kutils/tdecmoduleloader.cpp @@ -0,0 +1,302 @@ +/* + Copyright (c) 1999 Matthias Hoelzer-Kluepfel + Copyright (c) 2000 Matthias Elter + Copyright (c) 2003,2004 Matthias Kretz + Copyright (c) 2004 Frans Englich + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + 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 +#include +#include + +#include +#include +#include +#include +#include + +#include "tdecmoduleloader.h" + + +/***************************************************************/ +/** + * When something goes wrong in loading the module, this one + * jumps in as a "dummy" module. + */ +class KCMError : public TDECModule +{ + public: + KCMError( const TQString& msg, const TQString& details, TQWidget* parent ) + : TDECModule( parent, "KCMError" ) + { + TQVBoxLayout* topLayout = new TQVBoxLayout( this ); + topLayout->addWidget( new TQLabel( msg, this ) ); + topLayout->addWidget( new TQLabel( details, this ) ); + } +}; +/***************************************************************/ + + + + +TDECModule* TDECModuleLoader::load(const TDECModuleInfo &mod, const TQString &libname, + KLibLoader *loader, ErrorReporting report, TQWidget * parent, + const char * name, const TQStringList & args ) +{ + // attempt to load modules with ComponentFactory, only if the symbol init_ exists + // (this is because some modules, e.g. kcmkio with multiple modules in the library, + // cannot be ported to KGenericFactory) + KLibrary *lib = loader->library(TQFile::encodeName(libname.arg(mod.library()))); + if (lib) { + TQString initSym("init_"); + initSym += libname.arg(mod.library()); + + if ( lib->hasSymbol(TQFile::encodeName(initSym)) ) + { + KLibFactory *factory = lib->factory(); + if ( factory ) + { + TDECModule *module = KParts::ComponentFactory::createInstanceFromFactory( factory, TQT_TQOBJECT(parent), name ? name : mod.handle().latin1(), args ); + if (module) + return module; + } + // else do a fallback + kdDebug(1208) << "Unable to load module using ComponentFactory. Falling back to old loader." << endl; + } + + // get the create_ function + TQString factory("create_%1"); + void *create = lib->symbol(TQFile::encodeName(factory.arg(mod.handle()))); + + if (create) + { + // create the module + TDECModule* (*func)(TQWidget *, const char *); + func = (TDECModule* (*)(TQWidget *, const char *)) create; + return func( parent, name ? name : mod.handle().latin1() ); + } + else + { + TQString libFileName = lib->fileName(); + lib->unload(); + return reportError( report, i18n("There was an error when loading the module '%1'.

" + "The desktop file (%2) as well as the library (%3) was found but " + "yet the module could not be loaded properly. Most likely " + "the factory declaration was wrong, or the " + "create_* function was missing.
") + .arg( mod.moduleName() ) + .arg( mod.fileName() ) + .arg( libFileName ), + TQString::null, parent ); + } + + lib->unload(); + } + return reportError( report, i18n("The specified library %1 could not be found.") + .arg( mod.library() ), TQString::null, parent ); + return 0; +} + +TDECModule* TDECModuleLoader::loadModule(const TDECModuleInfo &mod, bool withfallback, TQWidget * parent, const char * name, const TQStringList & args ) +{ + return loadModule( mod, None, withfallback, parent, name, args ); +} + +TDECModule* TDECModuleLoader::loadModule(const TDECModuleInfo &mod, ErrorReporting report, bool withfallback, TQWidget * parent, const char * name, const TQStringList & args ) +{ + /* + * Simple libraries as modules are the easiest case: + * We just have to load the library and get the module + * from the factory. + */ + + if ( !mod.service() ) + { + if ( mod.moduleName() == "kcmlisa" || mod.moduleName() == "kcmkiolan" ) + { + return reportError( report, + i18n("The module %1 could not be found.") + .arg( mod.moduleName() ), + i18n("

The Lisa and lan:/ ioslave modules " + "are not installed by default in Kubuntu, because they are obsolete " + "and replaced by zeroconf.
If you still wish to use them, you " + "should install the lisa package from the Universe repository.

"), + parent ); + } else { + return reportError( report, + i18n("The module %1 could not be found.") + .arg( mod.moduleName() ), + i18n("

The diagnostics is:
The desktop file %1 could not be found.

").arg(mod.fileName()), + parent ); + } + } + + if (!mod.library().isEmpty()) + { + // get the library loader instance + + KLibLoader *loader = KLibLoader::self(); + + TDECModule *module = load(mod, "kcm_%1", loader, report, parent, name, args ); + /* + * Only try to load libkcm_* if it exists, otherwise KLibLoader::lastErrorMessage would say + * "libkcm_foo not found" instead of the real problem with loading kcm_foo. + */ + if (!KLibLoader::findLibrary( TQCString( "libkcm_" ) + TQFile::encodeName( mod.library() ) ).isEmpty() ) + module = load(mod, "libkcm_%1", loader, report, parent, name, args ); + if (module) + return module; + return reportError( report, + i18n("The module %1 could not be loaded.") + .arg( mod.moduleName() ), TQString::null, parent ); + } + + /* + * Ok, we could not load the library. + * Try to run it as an executable. + * This must not be done when calling from kcmshell, or you'll + * have infinite recursion + * (startService calls kcmshell which calls modloader which calls startService...) + * + */ + if(withfallback) + { + TDEApplication::startServiceByDesktopPath(mod.fileName(), TQString::null); + } + else + { + return reportError( report, + i18n("The module %1 is not a valid configuration module.") + .arg( mod.moduleName() ), i18n("

The diagnostics is:
The desktop file %1 does not specify a library.").arg(mod.fileName()), parent ); + } + + return 0; +} + +TDECModule* TDECModuleLoader::loadModule(const TQString &module, TQWidget *parent, + const char *name, const TQStringList & args) +{ + return loadModule(TDECModuleInfo(module), None, false, parent, name, args); +} + +TDECModule* TDECModuleLoader::loadModule(const TQString &module, ErrorReporting + report, TQWidget *parent, const char *name, const TQStringList & args) +{ + return loadModule(TDECModuleInfo(module), report, false, parent, name, args); +} + +void TDECModuleLoader::unloadModule(const TDECModuleInfo &mod) +{ + // get the library loader instance + KLibLoader *loader = KLibLoader::self(); + + // try to unload the library + TQString libname("libkcm_%1"); + loader->unloadLibrary(TQFile::encodeName(libname.arg(mod.library()))); + + libname = "kcm_%1"; + loader->unloadLibrary(TQFile::encodeName(libname.arg(mod.library()))); +} + +void TDECModuleLoader::showLastLoaderError(TQWidget *parent) +{ + KMessageBox::detailedError(parent, + i18n("There was an error loading the module."),i18n("

The diagnostics is:
%1" + "

Possible reasons:

  • An error occurred during your last " + "TDE upgrade leaving an orphaned control module
  • You have old third party " + "modules lying around.

Check these points carefully and try to remove " + "the module mentioned in the error message. If this fails, consider contacting " + "your distributor or packager.

") + .arg(KLibLoader::self()->lastErrorMessage())); + +} + +bool TDECModuleLoader::testModule( const TQString& module ) +{ + return testModule( TDECModuleInfo( module ) ); +} + +bool TDECModuleLoader::testModule( const TDECModuleInfo& module ) +{ + if (!module.service()) + { + kdDebug(1208) << "Module '" << module.fileName() << "' not found." << endl; + return true; + } + + bool doLoad = module.service()->property( "X-TDE-Test-Module", TQVariant::Bool ).toBool(); + if( !doLoad ) + { + return true; + } + else + { + /** + * If something fails we return true - we can't risk functionality becoming + * unavailable because of a buggy test. Furthermore, the error needs to + * show so it is discovered. TDECModuleProxy will detect the error and load + * a corresponding KCMError. + * */ + KLibLoader* loader = KLibLoader::self(); + KLibrary* library = loader->library( TQFile::encodeName((TQString("kcm_%1").arg(module.library()))) ); + if( library ) + { + void *test_func = library->symbol( TQString(TQString("test_%1").arg(module.factoryName())).utf8() ); + if( test_func ) + { + bool (*func)() = (bool(*)())test_func; + if( func() ) + { + return true; + } + else + { + return false; + } + } + else + { + kdDebug(1208) << "The test function for module '" << module.fileName() << "' could not be found." << endl; + return true; + } + } + kdDebug(1208) << "The library '" << module.library() << "' could not be found." << endl; + return true; + } +} + +TDECModule* TDECModuleLoader::reportError( ErrorReporting report, const TQString & text, + TQString details, TQWidget * parent ) +{ + if( details.isNull() ) + details = i18n("

The diagnostics is:
%1" + "

Possible reasons:

  • An error occurred during your last " + "TDE upgrade leaving an orphaned control module
  • You have old third party " + "modules lying around.

Check these points carefully and try to remove " + "the module mentioned in the error message. If this fails, consider contacting " + "your distributor or packager.

").arg(KLibLoader::self()->lastErrorMessage()); + if( report & Dialog ) + KMessageBox::detailedError( parent, text, details ); + if( report & Inline ) + return new KCMError( text, details, parent ); + return 0; +} + +// vim: ts=2 sw=2 et + diff --git a/kutils/tdecmoduleloader.h b/kutils/tdecmoduleloader.h new file mode 100644 index 000000000..1ae9f6b9f --- /dev/null +++ b/kutils/tdecmoduleloader.h @@ -0,0 +1,220 @@ +/* + Copyright (c) 1999 Matthias Hoelzer-Kluepfel + Copyright (c) 2002-2003 Daniel Molkentin + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + 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 MODLOADER_H +#define MODLOADER_H + +#include +#include + +class TQWidget; +class KLibLoader; + +/** + * @ingroup tdecmodule + * @brief Loads a KControl Module. + * + * TDECModuleLoader tries in several ways + * to locate and load a TDECModule. If loading fails a + * zero pointer is returned. \n + * It is very unlikely TDECModuleLoader is what you want + * and @ref TDECModuleProxy suits your needs. + * + * @author Matthias Hoelzer-Kluepfel + * @author Frans Englich + * @since 3.2 + * @internal +**/ +class KUTILS_EXPORT TDECModuleLoader +{ + public: + + /** + * Loads a @ref TDECModule. If loading fails a zero pointer is returned. + * @param module what module to load + * @param withFallback if true and loading failed a separate window + * with the module may appear and a zero pointer is a returned + * @param parent The parent widget + * @param name The widget's name + * @param args A list of arguments for the module to load + * + * @return a pointer to the loaded @ref TDECModule + * + * @deprecated use the function which explicitly states the error reporting + * method + */ + static TDECModule *loadModule(const TDECModuleInfo &module, bool withFallback=true, + TQWidget * parent = 0, const char * name = 0, + const TQStringList & args = TQStringList() ) KDE_DEPRECATED; + + /** + * Loads a @ref TDECModule. If loading fails a zero pointer is returned. + * @param module what module to load + * with the module may appear and a zero pointer is a returned + * @param parent The parent widget + * @param name The widget's name + * @param args A list of arguments for the module to load + * + * @deprecated use the function which explicitly states the error reporting + * method + */ + static TDECModule *loadModule(const TQString &module, TQWidget *parent = 0, + const char *name = 0, const TQStringList & args = TQStringList()) KDE_DEPRECATED; + + /** + * Determines the way errors are reported + */ + enum ErrorReporting { + /** + * no error reporting is done + * */ + None = 0, + /** + * the error report is shown instead of the + * TDECModule that should have * been loaded + */ + Inline = 1, + /** + * shows a dialog with the error report + */ + Dialog = 2, + /** + * does both Inline and Dialog + */ + Both = 3 + }; + + /** + * Loads a @ref TDECModule. If loading fails a zero pointer is returned. + * @param module what module to load + * @param report see ErrorReporting + * @param withFallback if true and loading failed a separate window + * with the module may appear and a zero pointer is a returned + * @param parent The parent widget + * @param name The widget's name + * @param args A list of arguments for the module to load + * + * @return a pointer to the loaded @ref TDECModule + * @since 3.4 + */ + static TDECModule *loadModule(const TDECModuleInfo &module, ErrorReporting + report, bool withFallback=true, TQWidget * parent = 0, + const char * name = 0, const TQStringList & args = TQStringList() ); + + /** + * Loads a @ref TDECModule. If loading fails a zero pointer is returned. + * @param module what module to load + * @param report see ErrorReporting + * with the module may appear and a zero pointer is a returned + * @param parent The parent widget + * @param name The widget's name + * @param args A list of arguments for the module to load + * + * @return a pointer to the loaded @ref TDECModule + * @since 3.4 + */ + static TDECModule *loadModule(const TQString &module, ErrorReporting + report, TQWidget *parent = 0, const char *name = 0, + const TQStringList & args = TQStringList()); + + /** + * Unloads the module's library + * @param mod What module to unload for + */ + static void unloadModule(const TDECModuleInfo &mod); + + /** + * Display a message box explaining an error occured and possible + * reasons to why. + * + * @deprecated Use a constructor with ErrorReporting set to Dialog to show a + * message box like this function did. + */ + static void showLastLoaderError(TQWidget *parent) KDE_DEPRECATED; + + + /** + * Checks whether an TDECModule should be shown by running its + * test function. If it is unsure whether a module should be shown, it should + * be made available, leaving the decision to the user. + * If false is returned, the module should not be loaded in any interface. + * + * A module declares it needs to be tested by having "X-TDE-Test-Module=true" in + * its desktop file. When that line exists, the following code must be available + * in the module's library: + * + * \code + * extern "C" + * { + * bool test_moduleName() + * { + * // Code testing for hardware/software presence. + * return true; // and the modue will be loaded. + * } + * + * } + * \endcode + * + * where moduleName is the library name for the module. + * + * @param module the module to check + * @returns true if the module should be loaded + * @since 3.4 + */ + static bool testModule( const TQString& module ); + + /** + * Convenience function, essentially the same as above. + * + * @param module the module to check + * @returns true if the module should be loaded + * @since 3.4 + */ + static bool testModule( const TDECModuleInfo& module ); + + /** + * Returns a TDECModule containing the messages @p report and @p text. + * + * @param report the type of error reporting, see ErrorReporting + * @param text the main message + * @param details any additional details + * @param parent The parent widget + * + * @since 3.4 + * @internal + */ + static TDECModule* reportError( ErrorReporting report, const TQString & text, + TQString details, TQWidget * parent ); + + private: + + /** + * Internal loader called by the public loaders. + * @internal + */ + static TDECModule* load(const TDECModuleInfo &mod, const TQString &libname, + KLibLoader *loader, ErrorReporting report, TQWidget * parent = 0, + const char * name = 0, const TQStringList & args = TQStringList() ); + +}; + +// vim: ts=2 sw=2 et +#endif // MODLOADER_H + diff --git a/kutils/tdecmoduleproxy.cpp b/kutils/tdecmoduleproxy.cpp new file mode 100644 index 000000000..673074c16 --- /dev/null +++ b/kutils/tdecmoduleproxy.cpp @@ -0,0 +1,650 @@ +/* This file is part of the KDE project + Copyright (C) 2004 Frans Englich + Copyright (C) 2003 Matthias Kretz + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "tdecmoduleproxy.h" +#include "tdecmoduleproxyIface.h" +#include "tdecmoduleproxyIfaceImpl.h" + +/***************************************************************/ +class TDECModuleProxy::TDECModuleProxyPrivate +{ + public: + TDECModuleProxyPrivate( const TDECModuleInfo & info ) + : args( 0 ) + , kcm( 0 ) + //, view( 0 ) + , embedWidget( 0 ) + , rootProcess ( 0 ) + , embedFrame ( 0 ) + , dcopObject( 0 ) + , dcopClient( 0 ) + , topLayout( 0 ) + , rootCommunicator( 0 ) + , rootInfo( 0 ) + , modInfo( info ) + , withFallback( false ) + , changed( false ) + , rootMode( false ) + , bogusOccupier( false ) + , isInitialized( false ) + {} + + ~TDECModuleProxyPrivate() + { + delete rootInfo; // Delete before embedWidget! + delete embedWidget; // Delete before embedFrame! + delete embedFrame; + delete dcopClient; + delete dcopObject; + delete rootCommunicator; + delete rootProcess; + delete kcm; + } + + TQStringList args; + TDECModule *kcm; + QXEmbed *embedWidget; + TDEProcess *rootProcess; + TQVBox *embedFrame; + TDECModuleProxyIfaceImpl *dcopObject; + DCOPClient *dcopClient; + TQVBoxLayout *topLayout; /* Contains TQScrollView view, and root stuff */ + TDECModuleProxyRootCommunicatorImpl *rootCommunicator; + TQLabel *rootInfo; + TQCString dcopName; + TDECModuleInfo modInfo; + bool withFallback; + bool changed; + bool rootMode; + bool bogusOccupier; + bool isInitialized; +}; +/***************************************************************/ + + + +/* + TODO: + + - How TDECModuleProxy behaves wrt memory leaks and behavior, when exiting + from root mode is not tested, because no code make use of it. It needs + work, if it should be used. + + - Should write a document which outlines test cases, to avoid + regressions. This class is a hazard. + + - Two Layout problems in runAsRoot: + * lblBusy doesn't show + * d->kcm/d->rootInfo doesn't get it right when the user + presses cancel in the tdesu dialog + + - Resizing horizontally is contrained; minimum size is set somewhere. + It appears to be somehow derived from the module's size. + + - Prettify: set icon in KCMultiDialog. + + - Perhaps it's possible to link against tdesu such that + the dialog is in process? + + */ +/***************************************************************/ +TDECModule * TDECModuleProxy::realModule() const +{ + + /* + * Note, don't call any function that calls realModule() since + * that leads to an infinite loop. + */ + + kdDebug(711) << k_funcinfo << endl; + + /* Already loaded */ + if( d->kcm ) + return d->kcm; + + /* /We/ have no kcm, but kcmshell running with root prevs does.. */ + if( d->rootMode ) + return 0; + + TQApplication::setOverrideCursor( Qt::WaitCursor ); + + TDECModuleProxy * that = const_cast( this ); + + if( !d->isInitialized ) + { + d->dcopName = TQString(moduleInfo().handle().prepend("TDECModuleProxy-")).utf8(); + d->topLayout = new TQVBoxLayout( that, 0, 0, "topLayout" ); + + d->isInitialized = true; + } + + if( !d->dcopClient ) + d->dcopClient = new DCOPClient(); + + if( !d->dcopClient->isRegistered() ) + d->dcopClient->registerAs( d->dcopName, false ); + + d->dcopClient->setAcceptCalls( true ); + + if( d->dcopClient->appId() == d->dcopName || d->bogusOccupier ) + { /* We got the name we requested, because no one was before us, + * or, it was an random application which had picked that name */ + kdDebug(711) << "Module not already loaded, loading module" << endl; + + d->dcopObject = new TDECModuleProxyIfaceImpl( d->dcopName, that ); + + d->kcm = TDECModuleLoader::loadModule( moduleInfo(), TDECModuleLoader::Inline, d->withFallback, + that, name(), d->args ); + + connect( d->kcm, TQT_SIGNAL( changed( bool ) ), + TQT_SLOT(moduleChanged(bool)) ); + connect( d->kcm, TQT_SIGNAL( destroyed() ), + TQT_SLOT( moduleDestroyed() ) ); + connect( d->kcm, TQT_SIGNAL(quickHelpChanged()), + TQT_SIGNAL(quickHelpChanged())); + TQWhatsThis::add( that, d->kcm->quickHelp() ); + + d->topLayout->addWidget( d->kcm ); + + if ( !d->rootInfo && /* If the message was not yet created */ + d->kcm->useRootOnlyMsg() /* and the module requests the message */ && + moduleInfo().needsRootPrivileges() /* and the module wants root access */ && + !KUser().isSuperUser() ) /* and we are not currently root */ + { + + d->rootInfo = new TQLabel( that, "rootInfo" ); + d->topLayout->insertWidget( 0, d->rootInfo ); + + d->rootInfo->setFrameShape(TQFrame::Box); + d->rootInfo->setFrameShadow(TQFrame::Raised); + + const TQString msg = d->kcm->rootOnlyMsg(); + if( msg.isEmpty() ) + d->rootInfo->setText(i18n( + "Changes in this section requires root access.
" + "Click the \"Administrator Mode\" button to " + "allow modifications.")); + else + d->rootInfo->setText(msg); + + TQWhatsThis::add( d->rootInfo, i18n( + "This section requires special permissions, probably " + "for system-wide changes; therefore, it is " + "required that you provide the root password to be " + "able to change the module's properties. If " + "you do not provide the password, the module will be " + "disabled.")); + } + } + else + { + kdDebug(711) << "Module already loaded, loading KCMError" << endl; + + d->dcopClient->detach(); + /* Re-register as anonymous */ + d->dcopClient->attach(); + + d->dcopClient->setNotifications( true ); + connect( d->dcopClient, TQT_SIGNAL( applicationRemoved( const TQCString& )), + TQT_SLOT( applicationRemoved( const TQCString& ))); + + /* Figure out the name of where the module is already loaded */ + TQByteArray replyData, data; + TQCString replyType; + TQString result; + TQDataStream arg, stream( replyData, IO_ReadOnly ); + + if( d->dcopClient->call( d->dcopName, d->dcopName, "applicationName()", + data, replyType, replyData )) + { + stream >> result; + + d->kcm = TDECModuleLoader::reportError( TDECModuleLoader::Inline, + i18n( "Argument is application name", "This configuration section is " + "already opened in %1" ).arg( result ), " ", that ); + + d->topLayout->addWidget( d->kcm ); + } + else + { + kdDebug(711) << "Calling TDECModuleProxy's DCOP interface for fetching the name failed." << endl; + d->bogusOccupier = true; + TQApplication::restoreOverrideCursor(); + return realModule(); + } + } + + TQApplication::restoreOverrideCursor(); + + return d->kcm; +} + +void TDECModuleProxy::applicationRemoved( const TQCString& app ) +{ + if( app == d->dcopName ) + { + /* Violence: Get rid of KCMError & CO, so that + * realModule() attempts to reload the module */ + delete d->kcm; + d->kcm = 0; + d->dcopClient->setNotifications( false ); + realModule(); + d->kcm->show(); + } +} + +void TDECModuleProxy::showEvent( TQShowEvent * ev ) +{ + + kdDebug(711) << k_funcinfo << endl; + ( void )realModule(); + + /* We have no kcm, if we're in root mode */ + if( d->kcm ) + d->kcm->show(); + + TQWidget::showEvent( ev ); + +} + +void TDECModuleProxy::runAsRoot() +{ + if ( !moduleInfo().needsRootPrivileges() ) + return; + + TQApplication::setOverrideCursor( Qt::WaitCursor ); + + delete d->rootProcess; + delete d->embedWidget; + delete d->embedFrame; + + d->embedFrame = new TQVBox( this, "embedFrame" ); + d->embedFrame->setFrameStyle( TQFrame::Box | TQFrame::Raised ); + + TQPalette pal( red ); + pal.setColor( TQColorGroup::Background, + colorGroup().background() ); + d->embedFrame->setPalette( pal ); + d->embedFrame->setLineWidth( 2 ); + d->embedFrame->setMidLineWidth( 2 ); + d->topLayout->addWidget(d->embedFrame,1); + + d->embedWidget = new QXEmbed( d->embedFrame, "embedWidget" ); + + d->embedFrame->show(); + + TQLabel *lblBusy = new TQLabel(i18n("Loading..."), d->embedWidget, "lblBusy" ); + lblBusy->setTextFormat(RichText); + lblBusy->setAlignment(AlignCenter); + lblBusy->setGeometry(0,0, d->kcm->width(), d->kcm->height()); + lblBusy->show(); + + deleteClient(); + /* The DCOP registration is now gone, and it will occur again when kcmshell soon + * registers. Here's a race condition in other words, but how likely is that? + * + * - It's a user initiated action, which means the user have to do weird stuff, very + * quick. + * - If the user _do_ manage to fsck up, the code will recover gracefully, see realModule(). + * + * So no worry. At the end of this function, communication with + * the DCOP object is established. + */ + + /* Prepare the process to run the kcmshell */ + TQString cmd = moduleInfo().service()->exec().stripWhiteSpace(); + if (cmd.left(5) == "tdesu") + { + cmd = TQString(cmd.remove(0,5)).stripWhiteSpace(); + + /* Remove all tdesu switches */ + while( cmd.length() > 1 && cmd[ 0 ] == '-' ) + cmd = TQString(cmd.remove( 0, cmd.find( ' ' ) )).stripWhiteSpace(); + } + + if (cmd.left(8) == "kcmshell") + cmd = TQString(cmd.remove(0,8)).stripWhiteSpace(); + + /* Run the process */ + TQString tdesu = KStandardDirs::findExe("tdesu"); + if (!tdesu.isEmpty()) + { + + d->rootProcess = new TDEProcess; + + *d->rootProcess << tdesu; + *d->rootProcess << "--nonewdcop" << "-n" << "-d" << TQString( "-i%1" ).arg(moduleInfo().icon()); + + *d->rootProcess << TQString("%1 %2 --embed-proxy %3 --lang %4").arg(locate("exe", "kcmshell")) + .arg(cmd).arg(d->embedWidget->winId()).arg(TDEGlobal::locale()->language()); + + connect(d->rootProcess, TQT_SIGNAL(processExited(TDEProcess*)), TQT_SLOT(rootExited())); + + if ( !d->rootProcess->start( TDEProcess::NotifyOnExit )) + { + d->rootMode = false; + rootExited(); + } + else + { + d->rootMode = true; + kapp->dcopClient(); + d->rootCommunicator = new TDECModuleProxyRootCommunicatorImpl( d->dcopName + "-RootCommunicator", this ); + } + + delete lblBusy; + TQApplication::restoreOverrideCursor(); + return; + } + + /* Clean up in case of failure */ + delete d->embedWidget; + d->embedWidget = 0; + delete d->embedFrame; + d->embedFrame = 0; + + TQApplication::restoreOverrideCursor(); +} + +void TDECModuleProxy::rootExited() +{ + kdDebug(711) << k_funcinfo << endl; + + if ( d->embedWidget->embeddedWinId() ) + XDestroyWindow(tqt_xdisplay(), d->embedWidget->embeddedWinId()); + + delete d->embedWidget; + d->embedWidget = 0; + + delete d->rootProcess; + d->rootProcess = 0; + + delete d->embedFrame; + d->embedFrame=0; + + delete d->rootCommunicator; + d->rootCommunicator = 0; + + /* Such that the "ordinary" module loads again */ + d->rootMode = false; + + d->topLayout->invalidate(); + + TQShowEvent ev; + showEvent( &ev ); + + moduleChanged( false ); + emit childClosed(); +} + +TDECModuleProxy::~TDECModuleProxy() +{ + deleteClient(); + TDECModuleLoader::unloadModule(moduleInfo()); + + delete d; +} + +void TDECModuleProxy::deleteClient() +{ + if( d->embedWidget ) + XKillClient(tqt_xdisplay(), d->embedWidget->embeddedWinId()); + + + delete d->kcm; + d->kcm = 0; + + delete d->dcopObject; + d->dcopObject = 0; + + if( d->dcopClient && !d->dcopClient->detach() ) + kdDebug(711) << "Unregistering from DCOP failed." << endl; + + delete d->dcopClient; + d->dcopClient = 0; + + kapp->syncX(); + +} + +void TDECModuleProxy::moduleChanged( bool c ) +{ + if( d->changed == c ) + return; + + d->changed = c; + emit changed( c ); + emit changed( this ); +} + +void TDECModuleProxy::moduleDestroyed() +{ + d->kcm = 0; +} + +TDECModuleProxy::TDECModuleProxy( const KService::Ptr & service, bool withFallback, + TQWidget * parent, const char * name, const TQStringList & args) + : TQWidget( parent, name ) +{ + init( TDECModuleInfo( service )); + d->args = args; + d->withFallback = withFallback; +} + +TDECModuleProxy::TDECModuleProxy( const TDECModuleInfo & info, bool withFallback, + TQWidget * parent, const char * name, const TQStringList & args ) + : TQWidget( parent, name ) +{ + init( info ); + d->args = args; + d->withFallback = withFallback; +} + +TDECModuleProxy::TDECModuleProxy( const TQString& serviceName, bool withFallback, + TQWidget * parent, const char * name, + const TQStringList & args) + : TQWidget( parent, name ) +{ + init( TDECModuleInfo( serviceName )); + d->args = args; + d->withFallback = withFallback; +} + +void TDECModuleProxy::init( const TDECModuleInfo& info ) +{ + kdDebug(711) << k_funcinfo << endl; + + d = new TDECModuleProxyPrivate( info ); + + /* This is all we do for now; all the heavy work is + * done in realModule(). It's called when the module + * _actually_ is needed, in for example showEvent(). + * The module is loaded "on demand" -- lazy loading. + */ + +} + +void TDECModuleProxy::load() +{ + + if( d->rootMode ) + callRootModule( "load()" ); + else if( realModule() ) + { + d->kcm->load(); + moduleChanged( false ); + } +} + +void TDECModuleProxy::save() +{ + if( d->rootMode ) + callRootModule( "save()" ); + else if( d->changed && realModule() ) + { + d->kcm->save(); + moduleChanged( false ); + } +} + +void TDECModuleProxy::callRootModule( const TQCString& function ) +{ + TQByteArray sendData, replyData; + TQCString replyType; + + /* Note, we don't use d->dcopClient here, because it's used for + * the loaded module(and it's not "us" when this function is called) */ + if( !kapp->dcopClient()->call( d->dcopName, d->dcopName, function, sendData, + replyType, replyData, true, -1 )) + kdDebug(711) << "Calling function '" << function << "' failed." << endl; + +} + +void TDECModuleProxy::defaults() +{ + if( d->rootMode ) + callRootModule( "defaults()" ); + if( realModule() ) + d->kcm->defaults(); +} + +TQString TDECModuleProxy::quickHelp() const +{ + + if( !d->rootMode ) + return realModule() ? realModule()->quickHelp() : TQString::null; + else + { + TQByteArray data, replyData; + TQCString replyType; + + if (kapp->dcopClient()->call(d->dcopName, d->dcopName, "quickHelp()", + data, replyType, replyData)) + kdDebug(711) << "Calling DCOP function bool changed() failed." << endl; + else + { + TQDataStream reply(replyData, IO_ReadOnly); + if (replyType == "TQString") + { + TQString result; + reply >> result; + return result; + } + else + kdDebug(711) << "DCOP function changed() returned mumbo jumbo." << endl; + } + return TQString::null; + } +} + +const TDEAboutData * TDECModuleProxy::aboutData() const +{ + if( !d->rootMode ) + return realModule() ? realModule()->aboutData() : 0; + else + /* This needs fixing, perhaps cache a TDEAboutData copy + * while in root mode? */ + return 0; + + +} + +int TDECModuleProxy::buttons() const +{ + return realModule() ? realModule()->buttons() : + TDECModule::Help | TDECModule::Default | TDECModule::Apply ; +} + +TQString TDECModuleProxy::rootOnlyMsg() const +{ + return realModule() ? realModule()->rootOnlyMsg() : TQString::null; +} + +bool TDECModuleProxy::useRootOnlyMsg() const +{ + return realModule() ? realModule()->useRootOnlyMsg() : true; +} + +TDEInstance * TDECModuleProxy::instance() const +{ + return realModule() ? realModule()->instance() : 0; +} + +bool TDECModuleProxy::changed() const +{ + return d->changed; +} + +const TDECModuleInfo& TDECModuleProxy::moduleInfo() const +{ + return d->modInfo; +} + +bool TDECModuleProxy::rootMode() const +{ + return d->rootMode; +} + +TQCString TDECModuleProxy::dcopName() const +{ + return d->dcopName; +} + +void TDECModuleProxy::emitQuickHelpChanged() +{ + emit quickHelpChanged(); +} + +/***************************************************************/ +#include "tdecmoduleproxy.moc" + +// vim: sw=4 ts=4 noet diff --git a/kutils/tdecmoduleproxy.h b/kutils/tdecmoduleproxy.h new file mode 100644 index 000000000..9fc559d97 --- /dev/null +++ b/kutils/tdecmoduleproxy.h @@ -0,0 +1,358 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Matthias Kretz + Copyright (C) 2004 Frans Englich + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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 KCMODULEPROXY_H +#define KCMODULEPROXY_H + +#include +#include + +#include +#include + +class TDEAboutData; +class TDECModule; +class TDECModuleInfo; +class TDEInstance; +class TDEProcess; + +/** + * @ingroup tdecmodule + * + * @brief Encapsulates a TDECModule for embedding. + * + * TDECModuleProxy is a wrapper for TDECModule intended for cases where + * modules are to be displayed. It ensures layout is consistent, handles + * root/administrator modules and in general takes care of the details + * needed for making a module available in an interface. A TDECModuleProxy + * can be treated as a TQWidget, without worrying about the details specific + * for modules such as library loading. TDECModuleProxy is not a sub class of TDECModule + * but its API closely resembles TDECModule's.\n + * Usually, an instance is created by passing one of the constructors a KService::Ptr, + * TDECModuleInfo or simply the name of the module and then added to the layout as any + * other widget. \n + * When the user have changed the module, changed( bool ) as well as changed ( TDECModuleProxy * ) + * is emitted. TDECModuleProxy does not take care of prompting for saving - if the object is deleted while + * changes is not saved the changes will be lost. changed() returns true if changes are unsaved. \n + * \n + * TDECModuleProxy does not take care of authorization of TDECModules. \n + * TDECModuleProxy do lazy loading, meaning the library will not be loaded or + * any other initialization done before its show() function is called. This means + * modules will only be loaded when they are actually needed as well as it is possible to + * load many TDECModuleProxy without any speed penalty. + * + * TDECModuleProxy should be used in all cases where modules are embedded in order to + * promote code efficiency and usability consistency. + * + * @author Frans Englich + * @author Matthias Kretz + * + */ +class KUTILS_EXPORT TDECModuleProxy : public TQWidget +{ +Q_OBJECT + + + friend class TDECModuleProxyRootCommunicatorImpl; + +public: + + /** + * Constructs a TDECModuleProxy from a TDECModuleInfo class. + * + * @param info The TDECModuleInfo to construct the module from. + * @param withFallback If set to true and loading of the module fails, + * a alternative will be tried, resulting in the module appearing in its + * own window, if at all. + * The embedded module will be load()ed. + * @param parent the parent TQWidget. + * @param name the module's name. + * @param args This is used in the implementation and is internal. + * Use the default. + */ + TDECModuleProxy( const TDECModuleInfo & info, bool withFallback = true, + TQWidget * parent = 0, const char * name = 0, + const TQStringList & args = TQStringList() ); + + /** + * Constructs a TDECModuleProxy from a module's service name, which is + * equivalent to the desktop file for the kcm without the ".desktop" part. + * Otherwise equal to the one above. + * + * @param serviceName The module's service name to construct from. + * @param withFallback If set to true and loading of the module fails, + * a alternative will be tried, resulting in the module appearing in its + * own window, if at all. + * The embedded module will be load()ed. + * @param parent the parent TQWidget. + * @param name the module's name. + * @param args This is used in the implementation and is internal. + * Use the default. + */ + TDECModuleProxy( const TQString& serviceName, bool withFallback = true, + TQWidget * parent = 0, const char * name = 0, + const TQStringList & args = TQStringList() ); + + /** + * Constructs a TDECModuleProxy from KService. Otherwise equal to the one above. + * + * @param service The KService to construct from. + * @param withFallback If set to true and loading of the module fails, + * a alternative will be tried, resulting in the module appearing in its + * own window, if at all. + * The embedded module will be load()ed. + * @param parent the parent TQWidget. + * @param name the module's name. + * @param args This is used in the implementation and is internal. + * Use the default. + */ + TDECModuleProxy( const KService::Ptr& service, bool withFallback = true, + TQWidget * parent = 0, const char * name = 0, + const TQStringList & args = TQStringList() ); + + /** + * Default destructor + */ + ~TDECModuleProxy(); + + /** + * Calling it will cause the contained module to + * run its load() routine. + */ + void load(); + + /** + * Calling it will cause the contained module to + * run its save() routine. + * + * If the module was not modified, it will not be asked + * to save. + */ + void save(); + + /** + * @return the module's quickHelp(); + */ + TQString quickHelp() const; + + /** + * @return the module's aboutData() + */ + const TDEAboutData * aboutData() const; + + /** + * @return what buttons the module + * needs + */ + int buttons() const; + + /** + * @return The module's custom root + * message, if it has one + * @deprecated + */ + TQString rootOnlyMsg() const; + //KDE4 remove. There's a limit for convenience functions, + // this one's available via moduleInfo()-> and realModule()-> + + /** + * @return If the module is a root module. + * @deprecated + */ + bool useRootOnlyMsg() const; + //KDE4 remove. There's a limit for convenience functions, + // this one's available via moduleInfo()-> and realModule()-> + + /** + * Returns the embedded TDECModule's TDEInstance. + * @return The module's TDEInstance. + * @deprecated + */ + TDEInstance * instance() const; + //KDE4 remove. There's a limit for convenience functions, + // this one's available via realModule() + + /** + * @return true if the module is modified + * and needs to be saved. + */ + bool changed() const; + + /** + * Returns whether the module is running in root mode. A module is in root mode + * when runAsRoot() has been called. A session under root user will never reach + * root mode. + * + * @note realModule() will return null when the module is running in root mode. + * + * @return true if the module is running with root privileges + * @since 3.4 + */ + bool rootMode() const; + + /** + * Access to the actual module. However, if the module is + * running in root mode, see rootMode(), this function returns + * a NULL pointer, since the module is in another process. It may also + * return NULL if anything goes wrong. + * + * @return the encapsulated module. + */ + TDECModule* realModule() const; + + /** + * @return a TDECModuleInfo for the encapsulated + * module + */ + const TDECModuleInfo& moduleInfo() const; + + /** + * Returns the DCOP the module's DCOPClient + * and DCOPObject has(they are identical). + * + * @since 3.4 + */ + TQCString dcopName() const; + +public slots: + + /** + * Calling this will cause the module to be run in + * "administrator mode". + * + * @since 3.4 + */ + void runAsRoot(); + + /** + * Calling it will cause the contained module to + * load its default values. + */ + void defaults(); + + /** + * Calling this, results in deleting the contained + * module, and unregistering from DCOP. A similar result is achieved + * by deleting the TDECModuleProxy itself. + * + * @since 3.4 + */ + void deleteClient(); + +signals: + + /* + * This signal is emitted when the contained module is changed. + */ + void changed( bool state ); + + /** + * This is emitted in the same situations as in the one above. Practical + * when several TDECModuleProxys are loaded. + * + * @since 3.4 + */ + void changed( TDECModuleProxy* mod ); + + /** + * When a module running with root privileges and exits, returns to normal mode, the + * childClosed() signal is emitted. + * + * @since 3.4 + */ + void childClosed(); + + /* + * This signal is relayed from the encapsulated module, and + * is equivalent to the module's own quickHelpChanged() signal. + * + * @since 3.4 + */ + void quickHelpChanged(); + +protected: + + /** + * Reimplemented for internal purposes. Makes sure the encapsulated + * module is loaded before the show event is taken care of. + */ + void showEvent( TQShowEvent * ); + + /** + * Internal intialization function, called by the constructors. + * + * @internal + * @since 3.4 + */ + void init( const TDECModuleInfo& info ); + + + /** + * Emits the quickHelpChanged signal. + * @since 3.4 + */ + void emitQuickHelpChanged(); + +private slots: + + /** + * Calls the function @p function of the root module's TDECModuleProxy + * DCOP interface. + * + * @param function the function signature of the function to call. + * @since 3.4 + */ + void callRootModule( const TQCString& function ); + + /** + * This is called when the module exits from root mode. It zeroes + * pointers, deletes the embed window, and so forth. + * + * @since 3.4 + */ + void rootExited(); + + /** + * Makes sure the proper variables is set and signals are emitted. + */ + void moduleChanged( bool ); + + /** + * Zeroes d->kcm + */ + void moduleDestroyed(); + + /** + * Gets called by DCOP when an application closes. + * Is used to (try to) reload a KCM which previously + * was loaded. + * + * @since 3.4 + */ + void applicationRemoved( const TQCString& app ); + +private: + + class TDECModuleProxyPrivate; + TDECModuleProxyPrivate * d; +}; + +#endif // KCMODULEPROXY_H +// vim: sw=4 ts=4 noet diff --git a/kutils/tdecmoduleproxyIface.h b/kutils/tdecmoduleproxyIface.h new file mode 100644 index 000000000..22bfa8e52 --- /dev/null +++ b/kutils/tdecmoduleproxyIface.h @@ -0,0 +1,121 @@ +/* This file is part of the KDE libraries + Copyright (C) 2004 Frans Englich + + 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 __KCMODULEPROXYIFACE_H__ +#define __KCMODULEPROXYIFACE_H__ + +#include + +/** + * @ingroup tdecmodule + * @brief DCOP Interface for TDECModule. + * + * A module (which is loaded via TDECModuleProxy) does always have + * this DCOP interface, whether it's in root mode or not. + * + * @since 3.4 + * @internal + * @author Frans Englich + */ +class TDECModuleProxyIface : virtual public DCOPObject +{ + K_DCOP + +k_dcop: + + /** + * Return the caption of the host application which the module + * is part in. This is the application name, or similar. + * + * @returns the host's name + */ + virtual TQString applicationName() = 0; + + /** + * Save settings. + */ + virtual void save() = 0; + + /** + * Load settings. + */ + virtual void load() = 0; + + /** + * Load defaults. + */ + virtual void defaults() = 0; + + /** + * Returns the module's quick help. + */ + virtual TQString quickHelp() = 0; + + /** + * @returns true if the module has unsaved + * data, typically. + */ + virtual bool changed() = 0; + +k_dcop_signals: + + /** + * Emitted when the state of the module changes. @p c + * is true when the content is changed, otherwise false. + * + * @param c true if the module is modified, false if its not. + * @param module a string identifying the module which was changed. This + * is typically "TDECModuleProx-X" where X is the module's name. + */ + virtual void changed( bool c ); + + virtual void quickHelpChanged(); + +}; + +/** + * @ingroup tdecmodule + * @brief DCOP interface for communicating with the real module running in root mode. + * + * When a TDECModuleProxy tells kcmshell to load "itself" and embed into the + * TDECModuleProxy, this DCOP interface is used to communicate to the real TDECModuleProxy, since + * the TDECModuleProxy which told kcmshell to load itself, is nothing but a shell. + * + * Currently is only the changed signal routed, but it's possible to proxy + * the rest of the TDECModuleProxy API, if it turns out necessary. + * + * @since 3.4 + * @internal + * @author Frans Englich + */ +class TDECModuleProxyRootDispatcher : virtual public DCOPObject +{ + K_DCOP + +k_dcop: + + /** + * TDECModuleProxyIface::changed() gets connected to this. + */ + virtual void changed( bool c ) = 0; + + virtual void quickHelpChanged() = 0; +}; + +#endif // __KCMODULEPROXYIFACE_H__ diff --git a/kutils/tdecmoduleproxyIfaceImpl.cpp b/kutils/tdecmoduleproxyIfaceImpl.cpp new file mode 100644 index 000000000..53019f72f --- /dev/null +++ b/kutils/tdecmoduleproxyIfaceImpl.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2004 Frans Englich + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * 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 +#include + +#include + +#include +#include +#include + +#include "tdecmoduleproxyIfaceImpl.h" + + +#include + +TDECModuleProxyIfaceImpl::TDECModuleProxyIfaceImpl( const TQCString& name, + TDECModuleProxy* const client ) + : DCOPObject( name ), TQObject( 0, name ), + p( const_cast( client )) +{ + connect( p, TQT_SIGNAL( changed(bool)), + TQT_SLOT( changedRelay(bool))); + connect( p, TQT_SIGNAL( quickHelpChanged()), + TQT_SLOT( quickHelpRelay())); +} + +void TDECModuleProxyIfaceImpl::save() +{ + kdDebug(711) << k_funcinfo << endl; + p->save(); +} + +void TDECModuleProxyIfaceImpl::load() +{ + kdDebug(711) << k_funcinfo << endl; + p->load(); +} + +void TDECModuleProxyIfaceImpl::defaults() +{ + kdDebug(711) << k_funcinfo << endl; + p->defaults(); +} + +TQString TDECModuleProxyIfaceImpl::applicationName() +{ + return kapp->caption(); +} + +TQString TDECModuleProxyIfaceImpl::quickHelp() +{ + return p->quickHelp(); +} + +bool TDECModuleProxyIfaceImpl::changed() +{ + return p->changed(); +} + +void TDECModuleProxyIfaceImpl::changedRelay( bool c ) +{ + TQByteArray data; + TQDataStream stream(data, IO_WriteOnly); + stream << c; + emitDCOPSignal( "changed(bool)", data ); +} + +void TDECModuleProxyIfaceImpl::quickHelpRelay() +{ + TQByteArray data; + emitDCOPSignal( "quickHelpChanged()", data ); +} + +/***************************************************************/ + + + + +/***************************************************************/ +TDECModuleProxyRootCommunicatorImpl::TDECModuleProxyRootCommunicatorImpl + ( const TQCString& name, TDECModuleProxy* const client ) + : DCOPObject( name ), TQObject( 0, name ), + p( const_cast( client )) +{ + /* + * Connect kcmshell's TDECModuleProxy's change signal + * to us, such that we act as a proxy for + * TDECModuleProxy's API. + */ + + /* Note, we don't use TDECModuleProxy::d->dcopClient */ + kapp->dcopClient()->connectDCOPSignal( 0, p->dcopName(), + "changed(bool)", objId(), "changed(bool)", false ); + + kapp->dcopClient()->connectDCOPSignal( 0, p->dcopName(), + "quickHelpChanged()", objId(), "quickHelpChanged()", false ); +} + +/* Reimplementations of DCOP members */ +void TDECModuleProxyRootCommunicatorImpl::changed( bool c ) +{ + kdDebug(711) << k_funcinfo << endl; + p->moduleChanged( c ); +} + +void TDECModuleProxyRootCommunicatorImpl::quickHelpChanged() +{ + kdDebug(711) << k_funcinfo << endl; + p->emitQuickHelpChanged(); +} + +#include "tdecmoduleproxyIfaceImpl.moc" diff --git a/kutils/tdecmoduleproxyIfaceImpl.h b/kutils/tdecmoduleproxyIfaceImpl.h new file mode 100644 index 000000000..fec8c6e5c --- /dev/null +++ b/kutils/tdecmoduleproxyIfaceImpl.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2004 Frans Englich + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * 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 __KCMODULEPROXYIFACEIMPL_H__ +#define __KCMODULEPROXYIFACEIMPL_H__ + +#include "tdecmoduleproxyIface.h" + +class TDECModuleProxy; + +/***************************************************************/ +/** @internal + @ingroup internal */ +class TDECModuleProxyIfaceImpl: public TQObject, virtual public TDECModuleProxyIface +{ + /* KDE4 Merge TDECModuleProxyIfaceImpl with TDECModuleProxy(MI) + * if it doesn't break what DCOPClient it binds to. + * Update: This is probably not possible, since we don't want the DCOPObject when + * we're running in root mode. */ + + Q_OBJECT + +public: + + /* Reimplementations of DCOP members */ + TDECModuleProxyIfaceImpl( const TQCString& name, TDECModuleProxy* const client ); + + virtual void save(); + + virtual void load(); + + virtual void defaults(); + + virtual TQString applicationName(); + + virtual TQString quickHelp(); + + virtual bool changed(); +public slots: + + /** + * Emits the changed(bool) DCOP signal. + */ + void changedRelay( bool c ); + + /** + * Simply relays TDECModuleProxy's signal with the same name. + */ + void quickHelpRelay(); + + +private: + + TDECModuleProxy* p; +}; +/***************************************************************/ + + + + +/***************************************************************/ +/** @internal + @ingroup internal */ +class TDECModuleProxyRootCommunicatorImpl: public TQObject, + virtual public TDECModuleProxyRootDispatcher +{ + Q_OBJECT + +public: + TDECModuleProxyRootCommunicatorImpl( const TQCString& name, TDECModuleProxy* const client ); + + /* Reimplementations of DCOP members */ + virtual void changed( bool c ); + + virtual void quickHelpChanged(); + +TDECModuleProxy* p; +}; +/***************************************************************/ + +#endif // __KCMODULEPROXYIFACEIMPL_H__ + diff --git a/tdecore/kdebug.areas b/tdecore/kdebug.areas index ab08d0ed2..92e62aaee 100644 --- a/tdecore/kdebug.areas +++ b/tdecore/kdebug.areas @@ -95,7 +95,7 @@ 1402 khc_indexbuilder 1420 kikbd -1421 ki18b_keys (kcmodule) +1421 ki18b_keys (tdecmodule) 1430 nspluginviewer (Qt/Xt) 1431 nspluginviewer (plugin) diff --git a/tdeui/CMakeLists.txt b/tdeui/CMakeLists.txt index 9ff7efc91..f7c1027d7 100644 --- a/tdeui/CMakeLists.txt +++ b/tdeui/CMakeLists.txt @@ -58,7 +58,7 @@ install( FILES kdualcolorbtn.h kdualcolorbutton.h ktoolbarbutton.h ktoolbarradiogroup.h ktextbrowser.h kaction.h kactioncollection.h kactionclasses.h khelpmenu.h kswitchlanguagedialog.h - kcmodule.h kcmenumngr.h kpanelmenu.h kpanelappmenu.h + tdecmodule.h kcmenumngr.h kpanelmenu.h kpanelappmenu.h kactionshortcutlist.h kstdaction.h kcombobox.h kiconview.h klistview.h klistbox.h kbugreport.h kpassdlg.h kxmlguiclient.h kxmlgui.h kxmlguibuilder.h kxmlguifactory.h @@ -129,7 +129,7 @@ set( ${target}_SRCS kanimwidget.cpp krootpixmap.cpp kaboutkde.cpp kaboutapplication.cpp kpanelapplet.cpp kdcopactionproxy.cpp kcolorcombo.cpp kpushbutton.cpp kpanelextension.cpp - kcompletionbox.cpp ksqueezedtextlabel.cpp kcmodule.cpp + kcompletionbox.cpp ksqueezedtextlabel.cpp tdecmodule.cpp kcommand.cpp twindowlistmenu.cpp kfontcombo.cpp ktip.cpp kdatewidget.cpp karrowbutton.cpp kmainwindowiface.cpp kmainwindowiface.skel kguiitem.cpp kstdguiitem.cpp diff --git a/tdeui/MAINTAINERS b/tdeui/MAINTAINERS index f666536cb..a5c4465b6 100644 --- a/tdeui/MAINTAINERS +++ b/tdeui/MAINTAINERS @@ -16,7 +16,7 @@ kbugreport.cpp kbuttonbox.cpp kcharselect.cpp kcmenumngr.cpp -kcmodule.cpp +tdecmodule.cpp kcolorbutton.cpp kcolorcombo.cpp kcolordialog.cpp Waldo Bastian diff --git a/tdeui/Makefile.am b/tdeui/Makefile.am index 821e2e682..b28c38584 100644 --- a/tdeui/Makefile.am +++ b/tdeui/Makefile.am @@ -55,7 +55,7 @@ include_HEADERS = kprogressbox.h kprogress.h kcolordlg.h \ kdualcolorbtn.h kdualcolorbutton.h ktoolbarbutton.h \ ktoolbarradiogroup.h ktextbrowser.h \ kaction.h kactioncollection.h kactionclasses.h khelpmenu.h kswitchlanguagedialog.h \ - kcmodule.h kcmenumngr.h kpanelmenu.h kpanelappmenu.h \ + tdecmodule.h kcmenumngr.h kpanelmenu.h kpanelappmenu.h \ kactionshortcutlist.h kstdaction.h kcombobox.h \ kiconview.h klistview.h klistbox.h kbugreport.h kpassdlg.h \ kxmlguiclient.h kxmlgui.h kxmlguibuilder.h kxmlguifactory.h \ @@ -110,7 +110,7 @@ libtdeui_la_SOURCES = \ kanimwidget.cpp krootpixmap.cpp kaboutkde.cpp \ kaboutapplication.cpp kpanelapplet.cpp kdcopactionproxy.cpp \ kcolorcombo.cpp kpushbutton.cpp kpanelextension.cpp \ - kcompletionbox.cpp ksqueezedtextlabel.cpp kcmodule.cpp \ + kcompletionbox.cpp ksqueezedtextlabel.cpp tdecmodule.cpp \ kcommand.cpp twindowlistmenu.cpp kfontcombo.cpp ktip.cpp \ kdatewidget.cpp karrowbutton.cpp kmainwindowiface.cpp \ kmainwindowiface.skel kguiitem.cpp kstdguiitem.cpp \ diff --git a/tdeui/kcmodule.cpp b/tdeui/kcmodule.cpp deleted file mode 100644 index 904c1cdc4..000000000 --- a/tdeui/kcmodule.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/* - This file is part of the KDE libraries - -<< - Copyright (C) 2004 Frans Englich - - 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 - -#include -#include -#include -#include -#include -#include -#include - -#include "kcmodule.h" -#include "kcmodule.moc" - -class TDECModulePrivate -{ -public: - TDECModulePrivate(): - _about( 0 ), - _useRootOnlyMsg( false ), - _hasOwnInstance( true ), - _unmanagedWidgetChangeState( false ) - { } - - TDEInstance *_instance; - TDEAboutData *_about; - TQString _rootOnlyMsg; - bool _useRootOnlyMsg; - bool _hasOwnInstance; - TQPtrList managers; - TQString _quickHelp; - - // this member is used to record the state on non-automatically - // managed widgets, allowing for mixed TDEConfigXT-drive and manual - // widgets to coexist peacefully and do the correct thing with - // the changed(bool) signal - bool _unmanagedWidgetChangeState; -}; - -TDECModule::TDECModule(TQWidget *parent, const char *name, const TQStringList &) - : TQWidget(parent, name) -{ - init(); - if (name && strlen(name)) { - d->_instance = new TDEInstance(name); - TDEGlobal::locale()->insertCatalogue(name); - } else - d->_instance = new TDEInstance("kcmunnamed"); - TDEGlobal::setActiveInstance(this->instance()); - - d->managers.setAutoDelete( true ); - -} - -TDECModule::TDECModule(TDEInstance *instance, TQWidget *parent, const TQStringList & ) - : TQWidget(parent, instance ? instance->instanceName().data() : 0) -{ - init(); - d->_instance = instance; - - if (instance) - { - TDEGlobal::locale()->insertCatalogue(instance->instanceName()); - } - - d->_hasOwnInstance = false; - TDEGlobal::setActiveInstance(this->instance()); -} - -void TDECModule::init() -{ - d = new TDECModulePrivate; - _btn = Help|Default|Apply; -} - -TDEConfigDialogManager* TDECModule::addConfig( TDEConfigSkeleton *config, TQWidget* widget ) -{ - TDEConfigDialogManager* manager = new TDEConfigDialogManager( widget, config, name() ); - connect( manager, TQT_SIGNAL( widgetModified() ), TQT_SLOT( widgetChanged() )); - d->managers.append( manager ); - return manager; -} - -TDECModule::~TDECModule() -{ - if (d->_hasOwnInstance) - delete d->_instance; - delete d->_about; - delete d; -} - -void TDECModule::load() -{ - TDEConfigDialogManager* manager; - for( manager = d->managers.first(); manager; manager = d->managers.next() ) - manager->updateWidgets(); -} - -void TDECModule::save() -{ - TDEConfigDialogManager* manager; - for( manager = d->managers.first(); manager; manager = d->managers.next() ) - manager->updateSettings(); - emit( changed( false )); -} - -void TDECModule::defaults() -{ - TDEConfigDialogManager* manager; - for( manager = d->managers.first(); manager; manager = d->managers.next() ) - manager->updateWidgetsDefault(); -} - -void TDECModule::widgetChanged() -{ - emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState()); -} - -bool TDECModule::managedWidgetChangeState() const -{ - TDEConfigDialogManager* manager; - for( manager = d->managers.first(); manager; manager = d->managers.next() ) - { - if ( manager->hasChanged() ) - return true; - } - - return false; -} - -void TDECModule::unmanagedWidgetChangeState(bool changed) -{ - d->_unmanagedWidgetChangeState = changed; - widgetChanged(); -} - -const TDEAboutData *TDECModule::aboutData() const -{ - return d->_about; -} - -void TDECModule::setAboutData( TDEAboutData* about ) -{ - delete d->_about; - d->_about = about; -} - -void TDECModule::setRootOnlyMsg(const TQString& msg) -{ - d->_rootOnlyMsg = msg; -} - -TQString TDECModule::rootOnlyMsg() const -{ - return d->_rootOnlyMsg; -} - -void TDECModule::setUseRootOnlyMsg(bool on) -{ - d->_useRootOnlyMsg = on; -} - -bool TDECModule::useRootOnlyMsg() const -{ - return d->_useRootOnlyMsg; -} - -void TDECModule::changed() -{ - emit changed(true); -} - -TDEInstance *TDECModule::instance() const -{ - return d->_instance; -} - -void TDECModule::setQuickHelp( const TQString& help ) -{ - d->_quickHelp = help; - emit( quickHelpChanged() ); -} - -TQString TDECModule::quickHelp() const -{ - return d->_quickHelp; -} - - -const TQPtrList& TDECModule::configs() const -{ - return d->managers; -} - -void TDECModule::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -// vim: sw=4 et sts=4 diff --git a/tdeui/kcmodule.h b/tdeui/kcmodule.h deleted file mode 100644 index 41d8d095e..000000000 --- a/tdeui/kcmodule.h +++ /dev/null @@ -1,361 +0,0 @@ -/* - This file is part of the KDE libraries - - Copyright (c) 1999 Matthias Hoelzer-Kluepfel - - 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 KCMODULE_H -#define KCMODULE_H - -#include - -#include - -class TQStringList; - -class TDEAboutData; -class TDEConfigDialogManager; -class TDEConfigSkeleton; -class TDECModulePrivate; -class TDEInstance; - -/** - * The base class for control center modules. - * - * Starting from KDE 2.0, control center modules are realized as shared - * libraries that are loaded into the control center at runtime. - * - * The module in principle is a simple widget displaying the - * item to be changed. The module has a very small interface. - * - * All the necessary glue logic and the GUI bells and whistles - * are provided by the control center and must not concern - * the module author. - * - * To write a config module, you have to create a library - * that contains at one factory function like this: - * - * \code - * #include - * - * typedef KGenericFactory YourTDECModuleFactory; - * K_EXPORT_COMPONENT_FACTORY( yourLibName, YourTDECModuleFactory("name_of_the_po_file") ); - * \endcode - * - * The parameter "name_of_the_po_file" has to correspond with the messages target - * that you created in your Makefile.am. - * - * See http://developer.kde.org/documentation/other/kcm_howto.html - * for more detailed documentation. - * - * @author Matthias Hoelzer-Kluepfel - */ -class TDEUI_EXPORT TDECModule : public TQWidget -{ - Q_OBJECT - -public: - - /** - * An enumeration type for the buttons used by this module. - * You should only use Help, Default and Apply. The rest is obsolete. - * - * @see TDECModule::buttons @see TDECModule::setButtons - */ - enum Button {Help=1, Default=2, Apply=16, - Reset=4, /* obsolete, do not use! */ - Cancel=8, /* obsolete, do not use! */ - Ok=32, /* obsolete, do not use! */ - SysDefault=64 /* obsolete, do not use! */ }; - - /* - * Base class for all KControlModules. - * Make sure you have a TQStringList argument in your - * implementation. - */ - TDECModule(TQWidget *parent=0, const char *name=0, const TQStringList &args=TQStringList() ); - - TDECModule(TDEInstance *instance, TQWidget *parent=0, const TQStringList &args=TQStringList() ); - - /* - * Destroys the module. - */ - ~TDECModule(); - - /** - * Load the configuration data into the module. - * - * The load method sets the user interface elements of the - * module to reflect the current settings stored in the - * configuration files. - * - * This method is invoked whenever the module should read its configuration - * (most of the times from a config file) and update the user interface. - * This happens when the user clicks the "Reset" button in the control - * center, to undo all of his changes and restore the currently valid - * settings. - * - * If you use TDEConfigXT, loading is taken care of automatically and - * you do not need to do it manually. However, if you for some reason reimplement it and - * also are using TDEConfigXT, you must call this function otherwise the loading of TDEConfigXT - * options will not work. - * - */ - virtual void load(); - // ### KDE 4: Call load() automatically through a single-shot timer - // from the constructor // and change documentation - - /** - * Save the configuration data. - * - * The save method stores the config information as shown - * in the user interface in the config files. - * - * If necessary, this method also updates the running system, - * e.g. by restarting applications. This normally does not apply for - * KSettings::Dialog modules where the updating is taken care of by - * KSettings::Dispatcher. - * - * save is called when the user clicks "Apply" or "Ok". - * - * If you use TDEConfigXT, saving is taken care off automatically and - * you do not need to load manually. However, if you for some reason reimplement it and - * also are using TDEConfigXT, you must call this function, otherwise the saving of TDEConfigXT - * options will not work. Call it at the very end of your reimplementation, to avoid - * changed() signals getting emitted when you modify widgets. - */ - virtual void save(); - - /** - * Sets the configuration to sensible default values. - * - * This method is called when the user clicks the "Default" - * button. It should set the display to useful values. - * - * If you use TDEConfigXT, you do not have to reimplement this function since - * the fetching and settings of default values is done automatically. However, if you - * reimplement and also are using TDEConfigXT, remember to call the base function at the - * very end of your reimplementation. - */ - virtual void defaults(); - - /** - * Set the configuration to system default values. - * - * This method is called when the user clicks the "System-Default" - * button. It should set the display to the system default values. - * - * @note The default behavior is to call defaults(). - */ - virtual void sysdefaults() { defaults(); } - // KDE 4 deprecate - - /** - * Return a quick-help text. - * - * This method is called when the module is docked. - * The quick-help text should contain a short description of the module and - * links to the module's help files. You can use QML formatting tags in the text. - * - * @note make sure the quick help text gets translated (use i18n()). - */ - virtual TQString quickHelp() const; - - /** - * This is generally only called for the KBugReport. - * If you override you should have it return a pointer to a constant. - * - * - * @returns the TDEAboutData for this module - */ - virtual const TDEAboutData *aboutData() const; - - /** - * This sets the TDEAboutData returned by aboutData() - * @since 3.3 - */ - void setAboutData( TDEAboutData* about ); - - /** - * Indicate which buttons will be used. - * - * The return value is a value or'ed together from - * the Button enumeration type. - * - * @see TDECModule::setButtons - */ - int buttons() const { return _btn; } - - /** - * Get the RootOnly message for this module. - * - * When the module must be run as root, or acts differently - * for root and a normal user, it is sometimes useful to - * customize the message that appears at the top of the module - * when used as a normal user. This function returns this - * customized message. If none has been set, a default message - * will be used. - * - * @see TDECModule::setRootOnlyMsg - */ - TQString rootOnlyMsg() const; - - /** - * Tell if KControl should show a RootOnly message when run as - * a normal user. - * - * In some cases, the module don't want a RootOnly message to - * appear (for example if it has already one). This function - * tells KControl if a RootOnly message should be shown - * - * @see TDECModule::setUseRootOnlyMsg - */ - bool useRootOnlyMsg() const; - - TDEInstance *instance() const; - - /** - * @return a list of @ref TDEConfigDialogManager's in use, if any. - * @since 3.4 - */ - const TQPtrList& configs() const; - -protected: - /** - * Adds a TDEConfigskeleton @p config to watch the widget @p widget - * - * This function is useful if you need to handle multiple configuration files. - * - * @since 3.3 - * @return a pointer to the TDEConfigDialogManager in use - * @param config the TDEConfigSkeleton to use - * @param widget the widget to watch - */ - TDEConfigDialogManager* addConfig( TDEConfigSkeleton *config, TQWidget* widget ); - - /** - * Sets the quick help. - * - * @since 3.3 - */ - void setQuickHelp( const TQString& help ); - -signals: - - /** - * Indicate that the state of the modules contents has changed. - * - * This signal is emitted whenever the state of the configuration - * shown in the module changes. It allows the control center to - * keep track of unsaved changes. - */ - void changed(bool state); - - /** - * Indicate that the module's quickhelp has changed. - * - * Emit this signal whenever the module's quickhelp changes. - * Modules implemented as tabbed dialogs might want to implement - * per-tab quickhelp for example. - * - */ - void quickHelpChanged(); - -protected slots: - - /** - * Calling this slot is equivalent to emitting changed(true). - * @since 3.3 - */ - void changed(); - - /** - * A managed widget was changed, the widget settings and the current - * settings are compared and a corresponding changed() signal is emitted - * @since 3.4 - */ - void widgetChanged(); - -protected: - - /** - * Sets the buttons to display. - * - * Help: shows a "Help" button. - * Default: shows a "Use Defaults" button - * Apply: in kcontrol this will show an "Apply" and "Reset" button - * in kcmshell this will show an "Ok", "Apply" and "Cancel" button - * - * If Apply is not specified, kcmshell will show a "Close" button. - * - * @see TDECModule::buttons - */ - void setButtons(int btn) { _btn = btn; } - - /** - * Sets the RootOnly message. - * - * This message will be shown at the top of the module of the - * corresponding desktop file contains the line X-TDE-RootOnly=true. - * If no message is set, a default one will be used. - * - * @see TDECModule::rootOnlyMsg - */ - void setRootOnlyMsg(const TQString& msg); - - /** - * Change whether or not the RootOnly message should be shown. - * - * Following the value of @p on, the RootOnly message will be - * shown or not. - * - * @see TDECModule::useRootOnlyMsg - */ - void setUseRootOnlyMsg(bool on); - - /** - * Returns the changed state of automatically managed widgets in this dialog - * @since 3.5 - */ - bool managedWidgetChangeState() const; - - /** - * Call this method when your manually managed widgets change state between - * changed and not changed - * @since 3.5 - */ - void unmanagedWidgetChangeState(bool); - -private: - - int _btn; -protected: - virtual void virtual_hook( int id, void* data ); -private: - TDECModulePrivate *d; - - /** - * Internal function for initialization of the class. - */ - void init(); - -}; - -#endif //KCMODULE_H - diff --git a/tdeui/tdecmodule.cpp b/tdeui/tdecmodule.cpp new file mode 100644 index 000000000..0b1b4f5fb --- /dev/null +++ b/tdeui/tdecmodule.cpp @@ -0,0 +1,220 @@ +/* + This file is part of the KDE libraries + +<< + Copyright (C) 2004 Frans Englich + + 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 + +#include +#include +#include +#include +#include +#include +#include + +#include "tdecmodule.h" +#include "tdecmodule.moc" + +class TDECModulePrivate +{ +public: + TDECModulePrivate(): + _about( 0 ), + _useRootOnlyMsg( false ), + _hasOwnInstance( true ), + _unmanagedWidgetChangeState( false ) + { } + + TDEInstance *_instance; + TDEAboutData *_about; + TQString _rootOnlyMsg; + bool _useRootOnlyMsg; + bool _hasOwnInstance; + TQPtrList managers; + TQString _quickHelp; + + // this member is used to record the state on non-automatically + // managed widgets, allowing for mixed TDEConfigXT-drive and manual + // widgets to coexist peacefully and do the correct thing with + // the changed(bool) signal + bool _unmanagedWidgetChangeState; +}; + +TDECModule::TDECModule(TQWidget *parent, const char *name, const TQStringList &) + : TQWidget(parent, name) +{ + init(); + if (name && strlen(name)) { + d->_instance = new TDEInstance(name); + TDEGlobal::locale()->insertCatalogue(name); + } else + d->_instance = new TDEInstance("kcmunnamed"); + TDEGlobal::setActiveInstance(this->instance()); + + d->managers.setAutoDelete( true ); + +} + +TDECModule::TDECModule(TDEInstance *instance, TQWidget *parent, const TQStringList & ) + : TQWidget(parent, instance ? instance->instanceName().data() : 0) +{ + init(); + d->_instance = instance; + + if (instance) + { + TDEGlobal::locale()->insertCatalogue(instance->instanceName()); + } + + d->_hasOwnInstance = false; + TDEGlobal::setActiveInstance(this->instance()); +} + +void TDECModule::init() +{ + d = new TDECModulePrivate; + _btn = Help|Default|Apply; +} + +TDEConfigDialogManager* TDECModule::addConfig( TDEConfigSkeleton *config, TQWidget* widget ) +{ + TDEConfigDialogManager* manager = new TDEConfigDialogManager( widget, config, name() ); + connect( manager, TQT_SIGNAL( widgetModified() ), TQT_SLOT( widgetChanged() )); + d->managers.append( manager ); + return manager; +} + +TDECModule::~TDECModule() +{ + if (d->_hasOwnInstance) + delete d->_instance; + delete d->_about; + delete d; +} + +void TDECModule::load() +{ + TDEConfigDialogManager* manager; + for( manager = d->managers.first(); manager; manager = d->managers.next() ) + manager->updateWidgets(); +} + +void TDECModule::save() +{ + TDEConfigDialogManager* manager; + for( manager = d->managers.first(); manager; manager = d->managers.next() ) + manager->updateSettings(); + emit( changed( false )); +} + +void TDECModule::defaults() +{ + TDEConfigDialogManager* manager; + for( manager = d->managers.first(); manager; manager = d->managers.next() ) + manager->updateWidgetsDefault(); +} + +void TDECModule::widgetChanged() +{ + emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState()); +} + +bool TDECModule::managedWidgetChangeState() const +{ + TDEConfigDialogManager* manager; + for( manager = d->managers.first(); manager; manager = d->managers.next() ) + { + if ( manager->hasChanged() ) + return true; + } + + return false; +} + +void TDECModule::unmanagedWidgetChangeState(bool changed) +{ + d->_unmanagedWidgetChangeState = changed; + widgetChanged(); +} + +const TDEAboutData *TDECModule::aboutData() const +{ + return d->_about; +} + +void TDECModule::setAboutData( TDEAboutData* about ) +{ + delete d->_about; + d->_about = about; +} + +void TDECModule::setRootOnlyMsg(const TQString& msg) +{ + d->_rootOnlyMsg = msg; +} + +TQString TDECModule::rootOnlyMsg() const +{ + return d->_rootOnlyMsg; +} + +void TDECModule::setUseRootOnlyMsg(bool on) +{ + d->_useRootOnlyMsg = on; +} + +bool TDECModule::useRootOnlyMsg() const +{ + return d->_useRootOnlyMsg; +} + +void TDECModule::changed() +{ + emit changed(true); +} + +TDEInstance *TDECModule::instance() const +{ + return d->_instance; +} + +void TDECModule::setQuickHelp( const TQString& help ) +{ + d->_quickHelp = help; + emit( quickHelpChanged() ); +} + +TQString TDECModule::quickHelp() const +{ + return d->_quickHelp; +} + + +const TQPtrList& TDECModule::configs() const +{ + return d->managers; +} + +void TDECModule::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +// vim: sw=4 et sts=4 diff --git a/tdeui/tdecmodule.h b/tdeui/tdecmodule.h new file mode 100644 index 000000000..41d8d095e --- /dev/null +++ b/tdeui/tdecmodule.h @@ -0,0 +1,361 @@ +/* + This file is part of the KDE libraries + + Copyright (c) 1999 Matthias Hoelzer-Kluepfel + + 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 KCMODULE_H +#define KCMODULE_H + +#include + +#include + +class TQStringList; + +class TDEAboutData; +class TDEConfigDialogManager; +class TDEConfigSkeleton; +class TDECModulePrivate; +class TDEInstance; + +/** + * The base class for control center modules. + * + * Starting from KDE 2.0, control center modules are realized as shared + * libraries that are loaded into the control center at runtime. + * + * The module in principle is a simple widget displaying the + * item to be changed. The module has a very small interface. + * + * All the necessary glue logic and the GUI bells and whistles + * are provided by the control center and must not concern + * the module author. + * + * To write a config module, you have to create a library + * that contains at one factory function like this: + * + * \code + * #include + * + * typedef KGenericFactory YourTDECModuleFactory; + * K_EXPORT_COMPONENT_FACTORY( yourLibName, YourTDECModuleFactory("name_of_the_po_file") ); + * \endcode + * + * The parameter "name_of_the_po_file" has to correspond with the messages target + * that you created in your Makefile.am. + * + * See http://developer.kde.org/documentation/other/kcm_howto.html + * for more detailed documentation. + * + * @author Matthias Hoelzer-Kluepfel + */ +class TDEUI_EXPORT TDECModule : public TQWidget +{ + Q_OBJECT + +public: + + /** + * An enumeration type for the buttons used by this module. + * You should only use Help, Default and Apply. The rest is obsolete. + * + * @see TDECModule::buttons @see TDECModule::setButtons + */ + enum Button {Help=1, Default=2, Apply=16, + Reset=4, /* obsolete, do not use! */ + Cancel=8, /* obsolete, do not use! */ + Ok=32, /* obsolete, do not use! */ + SysDefault=64 /* obsolete, do not use! */ }; + + /* + * Base class for all KControlModules. + * Make sure you have a TQStringList argument in your + * implementation. + */ + TDECModule(TQWidget *parent=0, const char *name=0, const TQStringList &args=TQStringList() ); + + TDECModule(TDEInstance *instance, TQWidget *parent=0, const TQStringList &args=TQStringList() ); + + /* + * Destroys the module. + */ + ~TDECModule(); + + /** + * Load the configuration data into the module. + * + * The load method sets the user interface elements of the + * module to reflect the current settings stored in the + * configuration files. + * + * This method is invoked whenever the module should read its configuration + * (most of the times from a config file) and update the user interface. + * This happens when the user clicks the "Reset" button in the control + * center, to undo all of his changes and restore the currently valid + * settings. + * + * If you use TDEConfigXT, loading is taken care of automatically and + * you do not need to do it manually. However, if you for some reason reimplement it and + * also are using TDEConfigXT, you must call this function otherwise the loading of TDEConfigXT + * options will not work. + * + */ + virtual void load(); + // ### KDE 4: Call load() automatically through a single-shot timer + // from the constructor // and change documentation + + /** + * Save the configuration data. + * + * The save method stores the config information as shown + * in the user interface in the config files. + * + * If necessary, this method also updates the running system, + * e.g. by restarting applications. This normally does not apply for + * KSettings::Dialog modules where the updating is taken care of by + * KSettings::Dispatcher. + * + * save is called when the user clicks "Apply" or "Ok". + * + * If you use TDEConfigXT, saving is taken care off automatically and + * you do not need to load manually. However, if you for some reason reimplement it and + * also are using TDEConfigXT, you must call this function, otherwise the saving of TDEConfigXT + * options will not work. Call it at the very end of your reimplementation, to avoid + * changed() signals getting emitted when you modify widgets. + */ + virtual void save(); + + /** + * Sets the configuration to sensible default values. + * + * This method is called when the user clicks the "Default" + * button. It should set the display to useful values. + * + * If you use TDEConfigXT, you do not have to reimplement this function since + * the fetching and settings of default values is done automatically. However, if you + * reimplement and also are using TDEConfigXT, remember to call the base function at the + * very end of your reimplementation. + */ + virtual void defaults(); + + /** + * Set the configuration to system default values. + * + * This method is called when the user clicks the "System-Default" + * button. It should set the display to the system default values. + * + * @note The default behavior is to call defaults(). + */ + virtual void sysdefaults() { defaults(); } + // KDE 4 deprecate + + /** + * Return a quick-help text. + * + * This method is called when the module is docked. + * The quick-help text should contain a short description of the module and + * links to the module's help files. You can use QML formatting tags in the text. + * + * @note make sure the quick help text gets translated (use i18n()). + */ + virtual TQString quickHelp() const; + + /** + * This is generally only called for the KBugReport. + * If you override you should have it return a pointer to a constant. + * + * + * @returns the TDEAboutData for this module + */ + virtual const TDEAboutData *aboutData() const; + + /** + * This sets the TDEAboutData returned by aboutData() + * @since 3.3 + */ + void setAboutData( TDEAboutData* about ); + + /** + * Indicate which buttons will be used. + * + * The return value is a value or'ed together from + * the Button enumeration type. + * + * @see TDECModule::setButtons + */ + int buttons() const { return _btn; } + + /** + * Get the RootOnly message for this module. + * + * When the module must be run as root, or acts differently + * for root and a normal user, it is sometimes useful to + * customize the message that appears at the top of the module + * when used as a normal user. This function returns this + * customized message. If none has been set, a default message + * will be used. + * + * @see TDECModule::setRootOnlyMsg + */ + TQString rootOnlyMsg() const; + + /** + * Tell if KControl should show a RootOnly message when run as + * a normal user. + * + * In some cases, the module don't want a RootOnly message to + * appear (for example if it has already one). This function + * tells KControl if a RootOnly message should be shown + * + * @see TDECModule::setUseRootOnlyMsg + */ + bool useRootOnlyMsg() const; + + TDEInstance *instance() const; + + /** + * @return a list of @ref TDEConfigDialogManager's in use, if any. + * @since 3.4 + */ + const TQPtrList& configs() const; + +protected: + /** + * Adds a TDEConfigskeleton @p config to watch the widget @p widget + * + * This function is useful if you need to handle multiple configuration files. + * + * @since 3.3 + * @return a pointer to the TDEConfigDialogManager in use + * @param config the TDEConfigSkeleton to use + * @param widget the widget to watch + */ + TDEConfigDialogManager* addConfig( TDEConfigSkeleton *config, TQWidget* widget ); + + /** + * Sets the quick help. + * + * @since 3.3 + */ + void setQuickHelp( const TQString& help ); + +signals: + + /** + * Indicate that the state of the modules contents has changed. + * + * This signal is emitted whenever the state of the configuration + * shown in the module changes. It allows the control center to + * keep track of unsaved changes. + */ + void changed(bool state); + + /** + * Indicate that the module's quickhelp has changed. + * + * Emit this signal whenever the module's quickhelp changes. + * Modules implemented as tabbed dialogs might want to implement + * per-tab quickhelp for example. + * + */ + void quickHelpChanged(); + +protected slots: + + /** + * Calling this slot is equivalent to emitting changed(true). + * @since 3.3 + */ + void changed(); + + /** + * A managed widget was changed, the widget settings and the current + * settings are compared and a corresponding changed() signal is emitted + * @since 3.4 + */ + void widgetChanged(); + +protected: + + /** + * Sets the buttons to display. + * + * Help: shows a "Help" button. + * Default: shows a "Use Defaults" button + * Apply: in kcontrol this will show an "Apply" and "Reset" button + * in kcmshell this will show an "Ok", "Apply" and "Cancel" button + * + * If Apply is not specified, kcmshell will show a "Close" button. + * + * @see TDECModule::buttons + */ + void setButtons(int btn) { _btn = btn; } + + /** + * Sets the RootOnly message. + * + * This message will be shown at the top of the module of the + * corresponding desktop file contains the line X-TDE-RootOnly=true. + * If no message is set, a default one will be used. + * + * @see TDECModule::rootOnlyMsg + */ + void setRootOnlyMsg(const TQString& msg); + + /** + * Change whether or not the RootOnly message should be shown. + * + * Following the value of @p on, the RootOnly message will be + * shown or not. + * + * @see TDECModule::useRootOnlyMsg + */ + void setUseRootOnlyMsg(bool on); + + /** + * Returns the changed state of automatically managed widgets in this dialog + * @since 3.5 + */ + bool managedWidgetChangeState() const; + + /** + * Call this method when your manually managed widgets change state between + * changed and not changed + * @since 3.5 + */ + void unmanagedWidgetChangeState(bool); + +private: + + int _btn; +protected: + virtual void virtual_hook( int id, void* data ); +private: + TDECModulePrivate *d; + + /** + * Internal function for initialization of the class. + */ + void init(); + +}; + +#endif //KCMODULE_H + diff --git a/win/pro_files/tdeui/tdeui.pro b/win/pro_files/tdeui/tdeui.pro index 5c438b6cf..26813b1b7 100644 --- a/win/pro_files/tdeui/tdeui.pro +++ b/win/pro_files/tdeui/tdeui.pro @@ -30,7 +30,7 @@ kbugreport.cpp \ kbuttonbox.cpp \ kcharselect.cpp \ kcmenumngr.cpp \ -kcmodule.cpp \ +tdecmodule.cpp \ kcolorbutton.cpp \ kcolorcombo.cpp \ kcolordialog.cpp \ -- cgit v1.2.1