[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: KService: support for storing Actions defined in .desktop files
From: David Faure <faure () kde ! org>
Date: 2007-10-15 14:06:18
Message-ID: 200710151606.19526.faure () kde ! org
[Download RAW message or body]
On Saturday 13 October 2007, David Faure wrote:
> Desktop files can defined Actions (as per the desktop entry standard). [...]
> This is simple to fix: letting KService save the information about those actions into ksycoca. [...]
>
> Also ported KDesktopFileActions to that; changes the API slightly, KDesktopFileActions::Service
> is to be ported to KServiceAction, which is good since Service had ugly public members. This part
> will wait until Monday obviously.
Here's the patch that ports kdebase to this API change.
Kevin used KDesktopFileActions::Service more than I expected :)
In the diff:
Index: runtime/kioslave/media/*
Index: runtime/soliduiserver/*
Index: apps/lib/konq/konq_menuactions_p.h
Index: apps/lib/konq/konq_menuactions.cpp
Index: workspace/kscreensaver/krandom_screensaver/random.cpp (Laurent, can you double-check this one?)
OK for committing this today?
> While writing the unit test for this, I noticed that the binary representation (like, in ksycoca)
> of a single KService was 3700 bytes. This is because KConfigGroup::entryMap returns all translated
> entries. After filtering those out, the KService is down to 755 bytes; and the whole ksycoca4 went
> from 9.0M to 1.5M!
> I still have to figure out how this worked in KDE3. From my tests, KConfig::entryMap(group) returned
> translated entries as well, and yet they are not seen by kservice nor end up in ksycoca3; confusing.
> Seems like KDesktopFile and KConfig behaved a bit differently on this; with KDesktopFile the entryMap
> doesn't have the translations... Anyone knows about this? (cf kconfigtest.cpp.kde3.diff)
Any input from KConfig people?
--
David Faure, faure@kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
["kdebase_kserviceaction.diff" (text/x-diff)]
Index: runtime/kioslave/media/libmediacommon/notifierserviceaction.cpp
===================================================================
--- runtime/kioslave/media/libmediacommon/notifierserviceaction.cpp (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifierserviceaction.cpp (working copy)
@@ -28,19 +28,21 @@
#include <kconfiggroup.h>
NotifierServiceAction::NotifierServiceAction()
- : NotifierAction()
+ : NotifierAction(),
+ m_service("newservice", i18n("New Service"), "dialog-cancel", "konqueror %u")
{
- NotifierAction::setIconName("dialog-cancel");
- NotifierAction::setLabel(i18n("Unknown"));
+ setService(m_service);
+}
- m_service.m_strName = "New Service";
- m_service.m_strIcon = "dialog-cancel";
- m_service.m_strExec = "konqueror %u";
+NotifierServiceAction::NotifierServiceAction(const KServiceAction& service)
+ : NotifierAction(), m_service(service)
+{
+ setService(service);
}
QString NotifierServiceAction::id() const
{
- if (m_filePath.isEmpty() || m_service.m_strName.isEmpty())
+ if (m_filePath.isEmpty() || m_service.isSeparator())
{
return QString();
}
@@ -50,37 +52,37 @@ QString NotifierServiceAction::id() cons
}
}
-void NotifierServiceAction::setIconName( const QString &icon )
-{
- m_service.m_strIcon = icon;
- NotifierAction::setIconName( icon );
-}
-
-void NotifierServiceAction::setLabel( const QString &label )
-{
- m_service.m_strName = label;
- NotifierAction::setLabel( label );
+// void NotifierServiceAction::setIconName( const QString &icon )
+// {
+// //m_service.m_strIcon = icon;
+// NotifierAction::setIconName( icon );
+// }
+
+// void NotifierServiceAction::setLabel( const QString &label )
+// {
+// //m_service.m_strName = label;
+// NotifierAction::setLabel( label );
- updateFilePath();
-}
+// updateFilePath();
+// }
-void NotifierServiceAction::execute(KFileItem &medium)
+void NotifierServiceAction::execute(const KFileItem &medium)
{
KUrl::List urls = KUrl::List( medium.url() );
KDesktopFileActions::executeService( urls, m_service );
}
-void NotifierServiceAction::setService(KDesktopFileActions::Service service)
+void NotifierServiceAction::setService(const KServiceAction& service)
{
- NotifierAction::setIconName( service.m_strIcon );
- NotifierAction::setLabel( service.m_strName );
+ NotifierAction::setIconName( service.icon() );
+ NotifierAction::setLabel( service.text() );
m_service = service;
updateFilePath();
}
-KDesktopFileActions::Service NotifierServiceAction::service() const
+KServiceAction NotifierServiceAction::service() const
{
return m_service;
}
@@ -99,7 +101,7 @@ void NotifierServiceAction::updateFilePa
{
if ( !m_filePath.isEmpty() ) return;
- QString action_name = m_service.m_strName;
+ QString action_name = m_service.text();
action_name.replace( " ", "_" );
QDir actions_dir( KStandardDirs::locateLocal( "data", "konqueror/servicemenus/", \
true ) ); @@ -152,14 +154,14 @@ void NotifierServiceAction::save() const
{
QFile::remove( m_filePath );
KDesktopFile desktopFile(m_filePath);
- KConfigGroup actionGroup(&desktopFile, QString("Desktop Action ") + \
m_service.m_strName);
- actionGroup.writeEntry(QString("Icon"), m_service.m_strIcon);
- actionGroup.writeEntry(QString("Name"), m_service.m_strName);
- actionGroup.writeEntry(QString("Exec"), m_service.m_strExec);
+ KConfigGroup actionGroup(&desktopFile, QString("Desktop Action ") + \
m_service.name()); + actionGroup.writeEntry(QString("Icon"), m_service.icon());
+ actionGroup.writeEntry(QString("Name"), m_service.text());
+ actionGroup.writeEntry(QString("Exec"), m_service.exec());
KConfigGroup desktopGroup = desktopFile.desktopGroup();
desktopGroup.writeEntry(QString("ServiceTypes"), m_mimetypes, ',');
desktopGroup.writeEntry(QString("Actions"),
- QStringList(m_service.m_strName),';');
+ QStringList(m_service.name()),';');
}
Index: runtime/kioslave/media/libmediacommon/notifieropenaction.cpp
===================================================================
--- runtime/kioslave/media/libmediacommon/notifieropenaction.cpp (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifieropenaction.cpp (working copy)
@@ -33,7 +33,7 @@ QString NotifierOpenAction::id() const
return "#OpenAction";
}
-void NotifierOpenAction::execute(KFileItem &medium)
+void NotifierOpenAction::execute(const KFileItem &medium)
{
medium.run();
}
Index: runtime/kioslave/media/libmediacommon/notifiersettings.cpp
===================================================================
--- runtime/kioslave/media/libmediacommon/notifiersettings.cpp (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifiersettings.cpp (working copy)
@@ -289,17 +289,16 @@ QList<NotifierServiceAction*> NotifierSe
const QString filename = desktop.fileName();
const QStringList mimetypes = group.readEntry( "ServiceTypes" , QStringList() );
- QList<KDesktopFileActions::Service> type_services
+ const QList<KServiceAction> type_services
= KDesktopFileActions::userDefinedServices(filename, true);
- QList<KDesktopFileActions::Service>::iterator service_it = type_services.begin();
- QList<KDesktopFileActions::Service>::iterator service_end = type_services.end();
+ QList<KServiceAction>::const_iterator service_it = type_services.begin();
+ const QList<KServiceAction>::const_iterator service_end = type_services.end();
for (; service_it!=service_end; ++service_it)
{
NotifierServiceAction *service_action
- = new NotifierServiceAction();
+ = new NotifierServiceAction(*service_it);
- service_action->setService( *service_it );
service_action->setFilePath( filename );
service_action->setMimetypes( mimetypes );
Index: runtime/kioslave/media/libmediacommon/notifierserviceaction.h
===================================================================
--- runtime/kioslave/media/libmediacommon/notifierserviceaction.h (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifierserviceaction.h (working copy)
@@ -30,14 +30,15 @@ class NotifierServiceAction : public Not
{
public:
NotifierServiceAction();
+ NotifierServiceAction(const KServiceAction& service);
virtual QString id() const;
- virtual void execute(KFileItem &item);
+ virtual void execute(const KFileItem &item);
- virtual void setIconName( const QString &icon );
- virtual void setLabel( const QString &label );
+ //virtual void setIconName( const QString &icon );
+ //virtual void setLabel( const QString &label );
- void setService(KDesktopFileActions::Service service);
- KDesktopFileActions::Service service() const;
+ void setService(const KServiceAction& service);
+ KServiceAction service() const;
void setFilePath(const QString &filePath);
QString filePath() const;
@@ -53,7 +54,7 @@ public:
private:
void updateFilePath();
- KDesktopFileActions::Service m_service;
+ KServiceAction m_service;
QString m_filePath;
QStringList m_mimetypes;
};
Index: runtime/kioslave/media/libmediacommon/notifiernothingaction.cpp
===================================================================
--- runtime/kioslave/media/libmediacommon/notifiernothingaction.cpp (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifiernothingaction.cpp (working copy)
@@ -33,7 +33,7 @@ QString NotifierNothingAction::id() cons
return "#NothinAction";
}
-void NotifierNothingAction::execute(KFileItem &/*medium*/)
+void NotifierNothingAction::execute(const KFileItem &/*medium*/)
{
}
Index: runtime/kioslave/media/libmediacommon/notifieropenaction.h
===================================================================
--- runtime/kioslave/media/libmediacommon/notifieropenaction.h (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifieropenaction.h (working copy)
@@ -27,7 +27,7 @@ class NotifierOpenAction : public Notifi
public:
NotifierOpenAction();
virtual QString id() const;
- virtual void execute(KFileItem &medium);
+ virtual void execute(const KFileItem &medium);
bool supportsMimetype( const QString &mimetype ) const;
};
Index: runtime/kioslave/media/libmediacommon/notifiernothingaction.h
===================================================================
--- runtime/kioslave/media/libmediacommon/notifiernothingaction.h (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifiernothingaction.h (working copy)
@@ -27,7 +27,7 @@ class NotifierNothingAction : public Not
public:
NotifierNothingAction();
virtual QString id() const;
- virtual void execute(KFileItem &medium);
+ virtual void execute(const KFileItem &medium);
};
#endif
Index: runtime/kioslave/media/libmediacommon/notifieraction.cpp
===================================================================
--- runtime/kioslave/media/libmediacommon/notifieraction.cpp (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifieraction.cpp (working copy)
@@ -100,6 +100,7 @@ bool NotifierAction::supportsMimetype(co
KIconLoader* NotifierAction::iconLoader()
{
+ /// ###### Why not use KIconLoader::global() ?
if (!s_iconLoader)
{
s_iconLoader = new KIconLoader(KGlobal::mainComponent().componentName(), \
KGlobal::mainComponent().dirs());
Index: runtime/kioslave/media/libmediacommon/notifieraction.h
===================================================================
--- runtime/kioslave/media/libmediacommon/notifieraction.h (revision 725386)
+++ runtime/kioslave/media/libmediacommon/notifieraction.h (working copy)
@@ -33,10 +33,8 @@ public:
NotifierAction();
virtual ~NotifierAction();
- virtual QString label() const;
- virtual QString iconName() const;
- virtual void setLabel( const QString &label );
- virtual void setIconName( const QString &icon );
+ QString label() const;
+ QString iconName() const;
QPixmap pixmap() const;
@@ -45,8 +43,11 @@ public:
virtual QString id() const = 0;
virtual bool isWritable() const;
virtual bool supportsMimetype( const QString &mimetype ) const;
- virtual void execute( KFileItem &medium ) = 0;
+ virtual void execute( const KFileItem &medium ) = 0;
+protected:
+ void setIconName( const QString &icon );
+ void setLabel( const QString &label );
private:
static KIconLoader* iconLoader();
void addAutoMimetype( const QString &mimetype );
Index: runtime/kioslave/media/kcmodule/serviceconfigdialog.cpp
===================================================================
--- runtime/kioslave/media/kcmodule/serviceconfigdialog.cpp (revision 725386)
+++ runtime/kioslave/media/kcmodule/serviceconfigdialog.cpp (working copy)
@@ -18,6 +18,7 @@
*/
#include "serviceconfigdialog.h"
+#include "mimetypelistboxitem.h"
#include <klocale.h>
#include <klineedit.h>
@@ -31,9 +32,6 @@
#include <QPixmap>
#include <QIcon>
-
-#include "mimetypelistboxitem.h"
-
ServiceConfigDialog::ServiceConfigDialog(NotifierServiceAction *action,
const QStringList &mimetypesList,
QWidget* parent)
@@ -50,7 +48,7 @@ ServiceConfigDialog::ServiceConfigDialog
m_view->iconButton->setIcon( m_action->iconName() );
m_view->labelEdit->setText( m_action->label() );
- m_view->commandEdit->setText( m_action->service().m_strExec );
+ m_view->commandEdit->setText( m_action->service().exec() );
m_view->commandButton->setIcon( KIcon("configure") );
const int pixmapSize = style()->pixelMetric(QStyle::PM_SmallIconSize);
@@ -90,24 +88,25 @@ ServiceConfigDialog::ServiceConfigDialog
connect( this, SIGNAL(okClicked()),this, SLOT(slotOk()));
}
-bool operator==( KDesktopFileActions::Service s1, KDesktopFileActions::Service s2 )
+bool operator==( const KServiceAction& s1, const KServiceAction& s2 )
{
- return ( s1.m_strName==s2.m_strName )
- && ( s1.m_strIcon==s2.m_strIcon )
- && ( s1.m_strExec==s2.m_strExec );
+ return ( s1.text()==s2.text() )
+ && ( s1.icon()==s2.icon() )
+ && ( s1.exec()==s2.exec() );
}
-bool operator!=( KDesktopFileActions::Service s1, KDesktopFileActions::Service s2 )
+bool operator!=( const KServiceAction& s1, const KServiceAction& s2 )
{
return !( s1==s2 );
}
void ServiceConfigDialog::slotOk()
{
- KDesktopFileActions::Service service;
- service.m_strName = m_view->labelEdit->text();
- service.m_strIcon = m_view->iconButton->icon();
- service.m_strExec = m_view->commandEdit->text();
+ static int serviceId = 0;
+ KServiceAction service(QString::number(++serviceId),
+ m_view->labelEdit->text(),
+ m_view->iconButton->icon(),
+ m_view->commandEdit->text()); // exec
QStringList mimetypes;
Index: runtime/kioslave/media/kcmodule/notifiermodule.cpp
===================================================================
--- runtime/kioslave/media/kcmodule/notifiermodule.cpp (revision 725386)
+++ runtime/kioslave/media/kcmodule/notifiermodule.cpp (working copy)
@@ -32,7 +32,6 @@
#include "notifiersettings.h"
#include "serviceconfigdialog.h"
#include "actionlistboxitem.h"
-#include "mimetypelistboxitem.h"
NotifierModule::NotifierModule(const KComponentData &componentData, QWidget *parent)
: KCModule(componentData, parent)
@@ -50,20 +49,16 @@ NotifierModule::NotifierModule(const KCo
m_view->mimetypesCombo->addItem( i18n("All Mime Types") );
- QStringList mimetypes = m_settings.supportedMimetypes();
+ const QStringList mimetypes = m_settings.supportedMimetypes();
- QStringList::iterator it = mimetypes.begin();
- QStringList::iterator end = mimetypes.end();
+ QStringList::const_iterator it = mimetypes.begin();
+ const QStringList::const_iterator end = mimetypes.end();
-#ifdef __GNUC__
-#warning "Needs porting. listBox() is no longer supplied in Qt4 QComboBox."
-#endif
-#if 0
for ( ; it!=end; ++it )
{
- new MimetypeListBoxItem( *it, m_view->mimetypesCombo->listBox() );
+ KMimeType::Ptr mime = KMimeType::mimeType(*it);
+ m_view->mimetypesCombo->addItem( mime->comment(), QVariant(*it) );
}
-#endif
updateListBox();
connect( m_view->mimetypesCombo, SIGNAL( activated(int) ),
@@ -150,15 +145,7 @@ void NotifierModule::slotMimeTypeChanged
}
else
{
-#ifdef __GNUC__
-#warning "Needs porting. listBox() is no longer supplied in Qt4 QComboBox."
-#endif
-#if 0
- QListWidgetItem *item = m_view->mimetypesCombo->listBox()->item( index );
- MimetypeListBoxItem *mime_item
- = static_cast<MimetypeListBoxItem*>( item );
- m_mimetype = mime_item->mimetype();
-#endif
+ m_mimetype = m_view->mimetypesCombo->itemData(index).toString();
}
updateListBox();
Index: runtime/kioslave/media/kcmodule/CMakeLists.txt
===================================================================
--- runtime/kioslave/media/kcmodule/CMakeLists.txt (revision 725386)
+++ runtime/kioslave/media/kcmodule/CMakeLists.txt (working copy)
@@ -4,7 +4,7 @@ include_directories( ../libmediacommon/
########### next target ###############
-set(kcm_media_PART_SRCS
+set(kcm_media_SRCS
notifiermodule.cpp
serviceconfigdialog.cpp
mimetypelistboxitem.cpp
@@ -12,15 +12,15 @@ set(kcm_media_PART_SRCS
main.cpp ${libmediacommon_SRCS})
-kde4_add_kcfg_files(kcm_media_PART_SRCS ../libmediacommon/mediamanagersettings.kcfgc \
) +kde4_add_kcfg_files(kcm_media_SRCS ../libmediacommon/mediamanagersettings.kcfgc )
-kde4_add_ui3_files(kcm_media_PART_SRCS notifiermoduleview.ui serviceview.ui \
managermoduleview.ui )
-
-kde4_add_plugin(kcm_media ${kcm_media_PART_SRCS})
+kde4_add_ui3_files(kcm_media_SRCS notifiermoduleview.ui serviceview.ui \
managermoduleview.ui )
+kde4_add_plugin(kcm_media ${kcm_media_SRCS})
+# the .ui file needs porting before we can move away from kde3support
target_link_libraries(kcm_media ${KDE4_KDE3SUPPORT_LIBS})
install(TARGETS kcm_media DESTINATION ${PLUGIN_INSTALL_DIR} )
Index: runtime/soliduiserver/deviceserviceaction.cpp
===================================================================
--- runtime/soliduiserver/deviceserviceaction.cpp (revision 725386)
+++ runtime/soliduiserver/deviceserviceaction.cpp (working copy)
@@ -19,10 +19,6 @@
#include "deviceserviceaction.h"
-#include <QDir>
-#include <QFile>
-#include <QFileInfo>
-#include <kstandarddirs.h>
#include <kdesktopfile.h>
#include <klocale.h>
#include <kmacroexpander.h>
@@ -55,47 +51,35 @@ DeviceServiceAction::DeviceServiceAction
QString DeviceServiceAction::id() const
{
- if (m_service.isEmpty()) {
+ if (m_service.name().isEmpty() && m_service.exec().isEmpty()) {
return QString();
} else {
- return "#Service:"+m_service.m_strName+m_service.m_strExec;
+ return "#Service:"+m_service.name()+m_service.exec();
}
}
-void DeviceServiceAction::setIconName(const QString &icon)
-{
- m_service.m_strIcon = icon;
- DeviceAction::setIconName(icon);
-}
-
-void DeviceServiceAction::setLabel(const QString &label)
-{
- m_service.m_strName = label;
- DeviceAction::setLabel(label);
-}
-
void DeviceServiceAction::execute(Solid::Device &device)
{
- QString exec = m_service.m_strExec;
+ QString exec = m_service.exec();
MacroExpander mx(device);
if (!mx.expandMacrosShellQuote(exec)) {
- kWarning() << ", Syntax error:" << m_service.m_strExec ;
+ kWarning() << ", Syntax error:" << m_service.exec();
return;
}
- KRun::runCommand(exec, QString(), m_service.m_strIcon, 0);
+ KRun::runCommand(exec, QString(), m_service.icon(), 0);
}
-void DeviceServiceAction::setService(KDesktopFileActions::Service service)
+void DeviceServiceAction::setService(const KServiceAction& service)
{
- DeviceAction::setIconName(service.m_strIcon);
- DeviceAction::setLabel(service.m_strName);
+ DeviceAction::setIconName(service.icon());
+ DeviceAction::setLabel(service.text());
m_service = service;
}
-KDesktopFileActions::Service DeviceServiceAction::service() const
+KServiceAction DeviceServiceAction::service() const
{
return m_service;
}
Index: runtime/soliduiserver/soliduiserver.cpp
===================================================================
--- runtime/soliduiserver/soliduiserver.cpp (revision 725386)
+++ runtime/soliduiserver/soliduiserver.cpp (working copy)
@@ -71,10 +71,10 @@ void SolidUiServer::showActionsDialog(co
foreach (QString desktop, desktopFiles) {
QString filePath = KStandardDirs::locate("data", "solid/actions/"+desktop);
- QList<KDesktopFileActions::Service> services
+ QList<KServiceAction> services
= KDesktopFileActions::userDefinedServices(filePath, true);
- foreach (KDesktopFileActions::Service service, services) {
+ foreach (KServiceAction service, services) {
DeviceServiceAction *action = new DeviceServiceAction();
action->setService(service);
actions << action;
Index: runtime/soliduiserver/deviceaction.h
===================================================================
--- runtime/soliduiserver/deviceaction.h (revision 725386)
+++ runtime/soliduiserver/deviceaction.h (working copy)
@@ -28,14 +28,16 @@ public:
DeviceAction();
virtual ~DeviceAction();
- virtual QString label() const;
- virtual QString iconName() const;
- virtual void setLabel(const QString &label);
- virtual void setIconName(const QString &icon);
+ QString label() const;
+ QString iconName() const;
virtual QString id() const = 0;
virtual void execute(Solid::Device &device) = 0;
+protected:
+ void setLabel(const QString &label);
+ void setIconName(const QString &icon);
+
private:
QString m_label;
QString m_iconName;
Index: runtime/soliduiserver/deviceserviceaction.h
===================================================================
--- runtime/soliduiserver/deviceserviceaction.h (revision 725386)
+++ runtime/soliduiserver/deviceserviceaction.h (working copy)
@@ -20,11 +20,11 @@
#ifndef DEVICESERVICEACTION_H
#define DEVICESERVICEACTION_H
-#include <kmimetype.h>
-#include <kdesktopfileactions.h>
+#include "deviceaction.h"
+
+#include <kserviceaction.h>
#include <solid/predicate.h>
-#include "deviceaction.h"
class DeviceServiceAction : public DeviceAction
{
@@ -33,14 +33,11 @@ public:
virtual QString id() const;
virtual void execute(Solid::Device &device);
- virtual void setIconName(const QString &icon);
- virtual void setLabel(const QString &label);
-
- void setService(KDesktopFileActions::Service service);
- KDesktopFileActions::Service service() const;
+ void setService(const KServiceAction& service);
+ KServiceAction service() const;
private:
- KDesktopFileActions::Service m_service;
+ KServiceAction m_service;
};
#endif
Index: runtime/soliduiserver/CMakeLists.txt
===================================================================
--- runtime/soliduiserver/CMakeLists.txt (revision 725386)
+++ runtime/soliduiserver/CMakeLists.txt (working copy)
@@ -1,6 +1,6 @@
########### next target ###############
-set(kded_soliduiserver_PART_SRCS
+set(kded_soliduiserver_SRCS
soliduiserver.cpp
deviceactionsdialog.cpp
deviceaction.cpp
@@ -8,9 +8,9 @@ set(kded_soliduiserver_PART_SRCS
deviceserviceaction.cpp
)
-kde4_add_ui_files(kded_soliduiserver_PART_SRCS deviceactionsdialogview.ui)
+kde4_add_ui_files(kded_soliduiserver_SRCS deviceactionsdialogview.ui)
-kde4_add_plugin(kded_soliduiserver ${kded_soliduiserver_PART_SRCS})
+kde4_add_plugin(kded_soliduiserver ${kded_soliduiserver_SRCS})
target_link_libraries(kded_soliduiserver ${KDE4_SOLID_LIBS} ${KDE4_KIO_LIBS})
Index: apps/lib/konq/konq_menuactions_p.h
===================================================================
--- apps/lib/konq/konq_menuactions_p.h (revision 725386)
+++ apps/lib/konq/konq_menuactions_p.h (working copy)
@@ -24,9 +24,9 @@
#include <kactioncollection.h>
#include <QActionGroup>
#include <QObject>
-#include <kdesktopfileactions.h>
+#include <kserviceaction.h>
-typedef QList<KDesktopFileActions::Service> ServiceList;
+typedef QList<KServiceAction> ServiceList;
class KonqMenuActionsPrivate : public QObject
{
@@ -50,7 +50,7 @@ public:
bool m_readOnly;
// TODO try action->setData(QVariant::fromValue(service))
- QMap<QAction *, KDesktopFileActions::Service> m_mapPopupServices;
+ QMap<QAction *, KServiceAction> m_mapPopupServices;
QActionGroup m_executeServiceActionGroup;
KActionCollection m_ownActions; // TODO connect to statusbar for help on actions
};
Index: apps/lib/konq/konq_menuactions.cpp
===================================================================
--- apps/lib/konq/konq_menuactions.cpp (revision 725386)
+++ apps/lib/konq/konq_menuactions.cpp (working copy)
@@ -19,6 +19,7 @@
#include "konq_menuactions.h"
#include "konq_menuactions_p.h"
+#include <kdesktopfileactions.h>
#include <kmenu.h>
#include <klocale.h>
#include <kauthorized.h>
@@ -118,7 +119,7 @@ int KonqMenuActionsPrivate::insertServic
int count = 0;
ServiceList::const_iterator it = list.begin();
for( ; it != list.end(); ++it ) {
- if ((*it).isEmpty()) {
+ if ((*it).isSeparator()) {
const QList<QAction*> actions = menu->actions();
if (!actions.isEmpty() && !actions.last()->isSeparator()) {
menu->addSeparator();
@@ -126,13 +127,13 @@ int KonqMenuActionsPrivate::insertServic
continue;
}
- if (isBuiltin || (*it).m_display == true) {
+ if (isBuiltin || !(*it).noDisplay()) {
QAction* act = new QAction(&m_ownActions);
- QString text = (*it).m_strName;
+ QString text = (*it).text();
text.replace('&',"&&");
act->setText( text );
- if ( !(*it).m_strIcon.isEmpty() ) {
- act->setIcon( KIcon((*it).m_strIcon) );
+ if ( !(*it).icon().isEmpty() ) {
+ act->setIcon( KIcon((*it).icon()) );
}
// act->setData(...);
m_executeServiceActionGroup.addAction(act);
@@ -149,7 +150,7 @@ int KonqMenuActionsPrivate::insertServic
void KonqMenuActionsPrivate::slotExecuteService(QAction* act)
{
- QMap<QAction *,KDesktopFileActions::Service>::Iterator it = \
m_mapPopupServices.find(act); + QMap<QAction *,KServiceAction>::Iterator it = \
m_mapPopupServices.find(act); Q_ASSERT(it != m_mapPopupServices.end());
if (it != m_mapPopupServices.end()) {
KDesktopFileActions::executeService(m_urlList, it.value());
Index: workspace/kscreensaver/libkscreensaver/main.cpp
===================================================================
--- workspace/kscreensaver/libkscreensaver/main.cpp (revision 725386)
+++ workspace/kscreensaver/libkscreensaver/main.cpp (working copy)
@@ -115,7 +115,7 @@ int kScreenSaverMain( int argc, char** a
args->clear();
dlg->exec();
delete dlg;
- exit(0);
+ return 0;
}
if (args->isSet("window-id"))
Index: workspace/kscreensaver/krandom_screensaver/random.cpp
===================================================================
--- workspace/kscreensaver/krandom_screensaver/random.cpp (revision 725386)
+++ workspace/kscreensaver/krandom_screensaver/random.cpp (working copy)
@@ -52,6 +52,15 @@ static const char description[] = I18N_N
static const char version[] = "2.0.0";
+static QString exeFromActionGroup(const QList<KServiceAction>& actions, const char* \
name) +{
+ foreach(const KServiceAction& action, actions) {
+ if (action.name() == name)
+ return action.exec();
+ }
+ return QString();
+}
+
//----------------------------------------------------------------------------
int main(int argc, char *argv[])
@@ -93,76 +102,54 @@ int main(int argc, char *argv[])
windowId = RootWindow(QX11Info::display(), info.screen());
}
args->clear();
- KService::List lst = KServiceTypeTrader::self()->query( "ScreenSaver");
- QStringList saverFileList;
+ const KService::List lst = KServiceTypeTrader::self()->query( "ScreenSaver");
+ KService::List availableSavers;
KConfig type("krandom.kssrc", KConfig::CascadeConfig);
const KConfigGroup configGroup = type.group("Settings");
- bool opengl = configGroup.readEntry("OpenGL", false);
- bool manipulatescreen = configGroup.readEntry("ManipulateScreen", false);
- bool fortune = !KStandardDirs::findExe("fortune").isEmpty();
- for( KService::List::const_iterator it = lst.begin();
- it != lst.end(); ++it)
- {
- QString file = KStandardDirs::locate("services", (*it)->entryPath());
- kDebug() << "Looking at " << file;
- KDesktopFile saver( file );
- kDebug() << "read X-KDE-Type";
- QString saverType = saver.desktopGroup().readEntry("X-KDE-Type");
- if (saverType.isEmpty()) // no X-KDE-Type defined so must be OK
- {
- saverFileList.append(file);
- }
- else
- {
- QStringList saverTypes = saverType.split( ";");
- for (QStringList::ConstIterator it = saverTypes.begin(); it != saverTypes.end(); \
++it )
- {
+ const bool opengl = configGroup.readEntry("OpenGL", false);
+ const bool manipulatescreen = configGroup.readEntry("ManipulateScreen", false);
+ // TODO replace this with TryExec=fortune in the desktop files
+ const bool fortune = !KStandardDirs::findExe("fortune").isEmpty();
+ foreach( const KService::Ptr& service, lst ) {
+ //QString file = KStandardDirs::locate("services", \
service->entryPath()); + //kDebug() << "Looking at " << file;
+ const QString saverType = service->property("X-KDE-Type").toString();
+ if (saverType.isEmpty()) { // no X-KDE-Type defined so must be OK
+ availableSavers.append(service);
+ } else {
+ const QStringList saverTypes = saverType.split( ";");
+ for (QStringList::ConstIterator it = saverTypes.begin(); it != \
saverTypes.end(); ++it ) { kDebug() << "saverTypes is "<< *it;
- if (*it == "ManipulateScreen")
- {
- if (manipulatescreen)
- {
- saverFileList.append(file);
- }
- }
- else
- if (*it == "OpenGL")
- {
- if (opengl)
- {
- saverFileList.append(file);
- }
- }
- if (*it == "Fortune")
- {
- if (fortune)
- {
- saverFileList.append(file);
+ if (*it == "ManipulateScreen") {
+ if (manipulatescreen) {
+ availableSavers.append(service);
+ }
+ } else if (*it == "OpenGL") {
+ if (opengl) {
+ availableSavers.append(service);
+ }
+ } else if (*it == "Fortune") {
+ if (fortune) {
+ availableSavers.append(service);
}
}
-
}
}
}
KRandomSequence rnd;
- int indx = rnd.getLong(saverFileList.count());
- QString filename = saverFileList.at(indx);
-
- KDesktopFile config( filename );
+ const int indx = rnd.getLong(availableSavers.count());
+ const KService::Ptr service = availableSavers.at(indx);
+ const QList<KServiceAction> actions = service->actions();
- KConfigGroup cg = config.desktopGroup();
QString cmd;
- if (windowId && config.hasActionGroup("InWindow"))
- {
- cg = config.actionGroup("InWindow");
- }
- else if ((windowId == 0) && config.hasActionGroup("Root"))
- {
- cg = config.actionGroup("Root");
- }
- cmd = cg.readPathEntry("Exec");
+ if (windowId)
+ cmd = exeFromActionGroup(actions, "InWindow");
+ if (cmd.isEmpty() && windowId == 0)
+ cmd = exeFromActionGroup(actions, "Root");
+ if (cmd.isEmpty())
+ cmd = service->exec();
QTextStream ts(&cmd, QIODevice::ReadOnly);
QString word;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic