summaryrefslogtreecommitdiffstats
path: root/kioslave/media/libmediacommon
diff options
context:
space:
mode:
Diffstat (limited to 'kioslave/media/libmediacommon')
-rw-r--r--kioslave/media/libmediacommon/Makefile.am11
-rw-r--r--kioslave/media/libmediacommon/actionlistboxitem.cpp47
-rw-r--r--kioslave/media/libmediacommon/actionlistboxitem.h40
-rw-r--r--kioslave/media/libmediacommon/mediamanagersettings.kcfg23
-rw-r--r--kioslave/media/libmediacommon/mediamanagersettings.kcfgc4
-rw-r--r--kioslave/media/libmediacommon/medium.cpp228
-rw-r--r--kioslave/media/libmediacommon/medium.h110
-rw-r--r--kioslave/media/libmediacommon/notifieraction.cpp97
-rw-r--r--kioslave/media/libmediacommon/notifieraction.h60
-rw-r--r--kioslave/media/libmediacommon/notifiernothingaction.cpp39
-rw-r--r--kioslave/media/libmediacommon/notifiernothingaction.h34
-rw-r--r--kioslave/media/libmediacommon/notifieropenaction.cpp45
-rw-r--r--kioslave/media/libmediacommon/notifieropenaction.h34
-rw-r--r--kioslave/media/libmediacommon/notifierserviceaction.cpp166
-rw-r--r--kioslave/media/libmediacommon/notifierserviceaction.h61
-rw-r--r--kioslave/media/libmediacommon/notifiersettings.cpp379
-rw-r--r--kioslave/media/libmediacommon/notifiersettings.h63
17 files changed, 1441 insertions, 0 deletions
diff --git a/kioslave/media/libmediacommon/Makefile.am b/kioslave/media/libmediacommon/Makefile.am
new file mode 100644
index 000000000..dd27d265a
--- /dev/null
+++ b/kioslave/media/libmediacommon/Makefile.am
@@ -0,0 +1,11 @@
+INCLUDES = $(all_includes)
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libmediacommon.la
+libmediacommon_la_SOURCES = medium.cpp actionlistboxitem.cpp \
+ notifieraction.cpp notifierserviceaction.cpp \
+ notifiernothingaction.cpp notifieropenaction.cpp \
+ notifiersettings.cpp mediamanagersettings.kcfgc
+
+kde_kcfg_DATA = mediamanagersettings.kcfg
+
diff --git a/kioslave/media/libmediacommon/actionlistboxitem.cpp b/kioslave/media/libmediacommon/actionlistboxitem.cpp
new file mode 100644
index 000000000..3551857c1
--- /dev/null
+++ b/kioslave/media/libmediacommon/actionlistboxitem.cpp
@@ -0,0 +1,47 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 Kévin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 "actionlistboxitem.h"
+
+#include <klocale.h>
+
+#include <qpixmap.h>
+
+ActionListBoxItem::ActionListBoxItem(NotifierAction *action, QString mimetype, QListBox *parent)
+ : QListBoxPixmap(parent, action->pixmap()),
+ m_action(action)
+{
+ QString text = m_action->label();
+
+ if ( m_action->autoMimetypes().contains( mimetype ) )
+ {
+ text += " (" + i18n( "Auto Action" ) + ")";
+ }
+
+ setText( text );
+}
+
+ActionListBoxItem::~ActionListBoxItem()
+{
+}
+
+NotifierAction *ActionListBoxItem::action() const
+{
+ return m_action;
+}
diff --git a/kioslave/media/libmediacommon/actionlistboxitem.h b/kioslave/media/libmediacommon/actionlistboxitem.h
new file mode 100644
index 000000000..cdd8a3ff1
--- /dev/null
+++ b/kioslave/media/libmediacommon/actionlistboxitem.h
@@ -0,0 +1,40 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 K�vin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 _ACTIONLISTBOXITEM_H_
+#define _ACTIONLISTBOXITEM_H_
+
+#include <qlistbox.h>
+#include <qstring.h>
+
+#include "notifieraction.h"
+
+class ActionListBoxItem : public QListBoxPixmap
+{
+public:
+ ActionListBoxItem(NotifierAction *action, QString mimetype, QListBox *parent);
+ ~ActionListBoxItem();
+
+ NotifierAction *action() const;
+
+private:
+ NotifierAction *m_action;
+};
+
+#endif
diff --git a/kioslave/media/libmediacommon/mediamanagersettings.kcfg b/kioslave/media/libmediacommon/mediamanagersettings.kcfg
new file mode 100644
index 000000000..4c9615ade
--- /dev/null
+++ b/kioslave/media/libmediacommon/mediamanagersettings.kcfg
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd">
+
+<kcfg>
+ <kcfgfile name="mediamanagerrc"/>
+ <group name="Global">
+ <entry name="HalBackendEnabled" type="Bool">
+ <label>Enable HAL backend</label>
+ <whatsthis>When HAL (Hardware Abstraction Layer) support is enabled, KDE will use it to gather information on the storage media available in your system.</whatsthis>
+ <default>true</default>
+ </entry>
+ <entry name="CdPollingEnabled" type="Bool">
+ <label>Enable CD polling</label>
+ <whatsthis>Allows KDE to poll CD-Rom or DVD-Rom drives itself in order to detect medium insert.</whatsthis>
+ <default>true</default>
+ </entry>
+ <entry name="AutostartEnabled" type="Bool">
+ <label>Enable medium application autostart after mount</label>
+ <whatsthis>Allows KDE to autostart application after a medium mount if it contains an Autostart or an Autoopen file.</whatsthis>
+ <default>true</default>
+ </entry>
+ </group>
+</kcfg>
diff --git a/kioslave/media/libmediacommon/mediamanagersettings.kcfgc b/kioslave/media/libmediacommon/mediamanagersettings.kcfgc
new file mode 100644
index 000000000..bbc58d92e
--- /dev/null
+++ b/kioslave/media/libmediacommon/mediamanagersettings.kcfgc
@@ -0,0 +1,4 @@
+File=mediamanagersettings.kcfg
+ClassName=MediaManagerSettings
+Singleton=true
+Mutators=true
diff --git a/kioslave/media/libmediacommon/medium.cpp b/kioslave/media/libmediacommon/medium.cpp
new file mode 100644
index 000000000..5767a6c9a
--- /dev/null
+++ b/kioslave/media/libmediacommon/medium.cpp
@@ -0,0 +1,228 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 "medium.h"
+
+#include <kconfig.h>
+#include <klocale.h>
+
+const QString Medium::SEPARATOR = "---";
+
+Medium::Medium(const QString &id, const QString &name)
+{
+ m_properties+= id; /* ID */
+ m_properties+= name; /* NAME */
+ m_properties+= name; /* LABEL */
+ m_properties+= QString::null; /* USER_LABEL */
+
+ m_properties+= "false"; /* MOUNTABLE */
+ m_properties+= QString::null; /* DEVICE_NODE */
+ m_properties+= QString::null; /* MOUNT_POINT */
+ m_properties+= QString::null; /* FS_TYPE */
+ m_properties+= "false"; /* MOUNTED */
+ m_properties+= QString::null; /* BASE_URL */
+ m_properties+= QString::null; /* MIME_TYPE */
+ m_properties+= QString::null; /* ICON_NAME */
+
+ loadUserLabel();
+
+ m_halmounted = false;
+}
+
+Medium::Medium()
+{
+ m_properties+= QString::null; /* ID */
+ m_properties+= QString::null; /* NAME */
+ m_properties+= QString::null; /* LABEL */
+ m_properties+= QString::null; /* USER_LABEL */
+
+ m_properties+= QString::null; /* MOUNTABLE */
+ m_properties+= QString::null; /* DEVICE_NODE */
+ m_properties+= QString::null; /* MOUNT_POINT */
+ m_properties+= QString::null; /* FS_TYPE */
+ m_properties+= QString::null; /* MOUNTED */
+ m_properties+= QString::null; /* BASE_URL */
+ m_properties+= QString::null; /* MIME_TYPE */
+ m_properties+= QString::null; /* ICON_NAME */
+
+ m_halmounted = false;
+}
+
+const Medium Medium::create(const QStringList &properties)
+{
+ Medium m;
+
+ if ( properties.size() >= PROPERTIES_COUNT )
+ {
+ m.m_properties[ID] = properties[ID];
+ m.m_properties[NAME] = properties[NAME];
+ m.m_properties[LABEL] = properties[LABEL];
+ m.m_properties[USER_LABEL] = properties[USER_LABEL];
+
+ m.m_properties[MOUNTABLE] = properties[MOUNTABLE];
+ m.m_properties[DEVICE_NODE] = properties[DEVICE_NODE];
+ m.m_properties[MOUNT_POINT] = properties[MOUNT_POINT];
+ m.m_properties[FS_TYPE] = properties[FS_TYPE];
+ m.m_properties[MOUNTED] = properties[MOUNTED];
+ m.m_properties[BASE_URL] = properties[BASE_URL];
+ m.m_properties[MIME_TYPE] = properties[MIME_TYPE];
+ m.m_properties[ICON_NAME] = properties[ICON_NAME];
+ }
+
+ return m;
+}
+
+Medium::List Medium::createList(const QStringList &properties)
+{
+ List l;
+
+ if ( properties.size() % (PROPERTIES_COUNT+1) == 0)
+ {
+ int media_count = properties.size()/(PROPERTIES_COUNT+1);
+
+ QStringList props = properties;
+
+ for(int i=0; i<media_count; i++)
+ {
+ const Medium m = create(props);
+ l.append(m);
+
+ QStringList::iterator first = props.begin();
+ QStringList::iterator last = props.find(SEPARATOR);
+ ++last;
+ props.erase(first, last);
+ }
+ }
+
+ return l;
+}
+
+
+void Medium::setName(const QString &name)
+{
+ m_properties[NAME] = name;
+}
+
+void Medium::setLabel(const QString &label)
+{
+ m_properties[LABEL] = label;
+}
+
+void Medium::setUserLabel(const QString &label)
+{
+ KConfig cfg("mediamanagerrc");
+ cfg.setGroup("UserLabels");
+
+ QString entry_name = m_properties[ID];
+
+ if ( label.isNull() )
+ {
+ cfg.deleteEntry(entry_name);
+ }
+ else
+ {
+ cfg.writeEntry(entry_name, label);
+ }
+
+ m_properties[USER_LABEL] = label;
+}
+
+void Medium::loadUserLabel()
+{
+ KConfig cfg("mediamanagerrc");
+ cfg.setGroup("UserLabels");
+
+ QString entry_name = m_properties[ID];
+
+ if ( cfg.hasKey(entry_name) )
+ {
+ m_properties[USER_LABEL] = cfg.readEntry(entry_name);
+ }
+ else
+ {
+ m_properties[USER_LABEL] = QString::null;
+ }
+}
+
+
+bool Medium::mountableState(bool mounted)
+{
+ if ( m_properties[DEVICE_NODE].isEmpty()
+ || ( mounted && m_properties[MOUNT_POINT].isEmpty() ) )
+ {
+ return false;
+ }
+
+ m_properties[MOUNTABLE] = "true";
+ m_properties[MOUNTED] = ( mounted ? "true" : "false" );
+
+ return true;
+}
+
+void Medium::mountableState(const QString &deviceNode,
+ const QString &mountPoint,
+ const QString &fsType, bool mounted)
+{
+ m_properties[MOUNTABLE] = "true";
+ m_properties[DEVICE_NODE] = deviceNode;
+ m_properties[MOUNT_POINT] = mountPoint;
+ m_properties[FS_TYPE] = fsType;
+ m_properties[MOUNTED] = ( mounted ? "true" : "false" );
+}
+
+void Medium::unmountableState(const QString &baseURL)
+{
+ m_properties[MOUNTABLE] = "false";
+ m_properties[BASE_URL] = baseURL;
+}
+
+void Medium::setMimeType(const QString &mimeType)
+{
+ m_properties[MIME_TYPE] = mimeType;
+}
+
+void Medium::setIconName(const QString &iconName)
+{
+ m_properties[ICON_NAME] = iconName;
+}
+
+bool Medium::needMounting() const
+{
+ return isMountable() && !isMounted();
+}
+
+KURL Medium::prettyBaseURL() const
+{
+ if ( !baseURL().isEmpty() )
+ return baseURL();
+
+ return KURL( mountPoint() );
+}
+
+QString Medium::prettyLabel() const
+{
+ if ( !userLabel().isEmpty() )
+ {
+ return userLabel();
+ }
+ else
+ {
+ return label();
+ }
+}
+
diff --git a/kioslave/media/libmediacommon/medium.h b/kioslave/media/libmediacommon/medium.h
new file mode 100644
index 000000000..f94545e8e
--- /dev/null
+++ b/kioslave/media/libmediacommon/medium.h
@@ -0,0 +1,110 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2004 K�vin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 _MEDIUM_H_
+#define _MEDIUM_H_
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <kurl.h>
+#include <qmap.h>
+
+class Medium
+{
+public:
+ typedef QValueList<const Medium> List;
+
+ static const uint ID = 0;
+ static const uint NAME = 1;
+ static const uint LABEL = 2;
+ static const uint USER_LABEL = 3;
+ static const uint MOUNTABLE = 4;
+ static const uint DEVICE_NODE = 5;
+ static const uint MOUNT_POINT = 6;
+ static const uint FS_TYPE = 7;
+ static const uint MOUNTED = 8;
+ static const uint BASE_URL = 9;
+ static const uint MIME_TYPE = 10;
+ static const uint ICON_NAME = 11;
+ static const uint PROPERTIES_COUNT = 12;
+ static const QString SEPARATOR;
+
+ Medium(const QString &id, const QString &name);
+ static const Medium create(const QStringList &properties);
+ static List createList(const QStringList &properties);
+
+ const QStringList &properties() const { return m_properties; }
+
+ QString id() const { return m_properties[ID]; }
+ QString name() const { return m_properties[NAME]; }
+ QString label() const { return m_properties[LABEL]; }
+ QString userLabel() const { return m_properties[USER_LABEL]; }
+ bool isMountable() const { return m_properties[MOUNTABLE]=="true"; }
+ QString deviceNode() const { return m_properties[DEVICE_NODE]; }
+ QString mountPoint() const { return m_properties[MOUNT_POINT]; }
+ QString fsType() const { return m_properties[FS_TYPE]; }
+ bool isMounted() const { return m_properties[MOUNTED]=="true"; }
+ QString baseURL() const { return m_properties[BASE_URL]; }
+ QString mimeType() const { return m_properties[MIME_TYPE]; }
+ QString iconName() const { return m_properties[ICON_NAME]; }
+
+ bool needMounting() const;
+ KURL prettyBaseURL() const;
+ QString prettyLabel() const;
+
+ void setName(const QString &name);
+ void setLabel(const QString &label);
+ void setUserLabel(const QString &label);
+
+ bool mountableState(bool mounted);
+ void mountableState(const QString &deviceNode,
+ const QString &mountPoint,
+ const QString &fsType, bool mounted);
+ void unmountableState(const QString &baseURL = QString::null);
+
+ void setMimeType(const QString &mimeType);
+ void setIconName(const QString &iconName);
+ void setHalMounted(bool flag) const { m_halmounted = flag; }
+ bool halMounted() const { return m_halmounted; }
+
+private:
+ Medium();
+ void loadUserLabel();
+
+ QStringList m_properties;
+ mutable bool m_halmounted;
+
+friend class QValueListNode<const Medium>;
+};
+
+namespace MediaManagerUtils {
+ static inline QMap<QString,QString> splitOptions(const QStringList & options)
+ {
+ QMap<QString,QString> valids;
+
+ for (QStringList::ConstIterator it = options.begin(); it != options.end(); ++it)
+ {
+ QString key = (*it).left((*it).find('='));
+ QString value = (*it).mid((*it).find('=') + 1);
+ valids[key] = value;
+ }
+ return valids;
+ }
+}
+
+#endif
diff --git a/kioslave/media/libmediacommon/notifieraction.cpp b/kioslave/media/libmediacommon/notifieraction.cpp
new file mode 100644
index 000000000..3eea682d4
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifieraction.cpp
@@ -0,0 +1,97 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 Kévin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 "notifieraction.h"
+
+#include <qfile.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <kicontheme.h>
+
+NotifierAction::NotifierAction()
+{
+}
+
+NotifierAction::~NotifierAction()
+{
+}
+
+void NotifierAction::setIconName(const QString &iconName)
+{
+ m_iconName = iconName;
+}
+
+void NotifierAction::setLabel(const QString &label)
+{
+ m_label = label;
+}
+
+QString NotifierAction::iconName() const
+{
+ return m_iconName;
+}
+
+QPixmap NotifierAction::pixmap() const
+{
+ QFile f( m_iconName );
+
+ if ( f.exists() )
+ {
+ return QPixmap( m_iconName );
+ }
+ else
+ {
+ QString path = KGlobal::iconLoader()->iconPath( m_iconName, -32 );
+ return QPixmap( path );
+ }
+}
+
+QString NotifierAction::label() const
+{
+ return m_label;
+}
+
+void NotifierAction::addAutoMimetype( const QString &mimetype )
+{
+ if ( !m_autoMimetypes.contains( mimetype ) )
+ {
+ m_autoMimetypes.append( mimetype );
+ }
+}
+
+void NotifierAction::removeAutoMimetype( const QString &mimetype )
+{
+ m_autoMimetypes.remove( mimetype );
+}
+
+QStringList NotifierAction::autoMimetypes()
+{
+ return m_autoMimetypes;
+}
+
+bool NotifierAction::isWritable() const
+{
+ return false;
+}
+
+bool NotifierAction::supportsMimetype(const QString &/*mimetype*/) const
+{
+ return true;
+}
+
diff --git a/kioslave/media/libmediacommon/notifieraction.h b/kioslave/media/libmediacommon/notifieraction.h
new file mode 100644
index 000000000..028ce7433
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifieraction.h
@@ -0,0 +1,60 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 K�vin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 _NOTIFIERACTION_H_
+#define _NOTIFIERACTION_H_
+
+#include <kfileitem.h>
+#include <qstring.h>
+#include <qpixmap.h>
+
+class NotifierSettings;
+
+class NotifierAction
+{
+public:
+ NotifierAction();
+ virtual ~NotifierAction();
+
+ virtual QString label() const;
+ virtual QString iconName() const;
+ virtual void setLabel( const QString &label );
+ virtual void setIconName( const QString &icon );
+
+ QPixmap pixmap() const;
+
+ QStringList autoMimetypes();
+
+ virtual QString id() const = 0;
+ virtual bool isWritable() const;
+ virtual bool supportsMimetype( const QString &mimetype ) const;
+ virtual void execute( KFileItem &medium ) = 0;
+
+private:
+ void addAutoMimetype( const QString &mimetype );
+ void removeAutoMimetype( const QString &mimetype );
+
+ QString m_label;
+ QString m_iconName;
+ QStringList m_autoMimetypes;
+
+ friend class NotifierSettings;
+};
+
+#endif
diff --git a/kioslave/media/libmediacommon/notifiernothingaction.cpp b/kioslave/media/libmediacommon/notifiernothingaction.cpp
new file mode 100644
index 000000000..adf7fcf04
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifiernothingaction.cpp
@@ -0,0 +1,39 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 Kévin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 "notifiernothingaction.h"
+
+#include <klocale.h>
+
+NotifierNothingAction::NotifierNothingAction()
+ : NotifierAction()
+{
+ setIconName("button_cancel");
+ setLabel(i18n("Do Nothing"));
+}
+
+QString NotifierNothingAction::id() const
+{
+ return "#NothinAction";
+}
+
+void NotifierNothingAction::execute(KFileItem &/*medium*/)
+{
+}
+
diff --git a/kioslave/media/libmediacommon/notifiernothingaction.h b/kioslave/media/libmediacommon/notifiernothingaction.h
new file mode 100644
index 000000000..6fd564f61
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifiernothingaction.h
@@ -0,0 +1,34 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 K�vin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 _NOTIFIERNOTHINGACTION_H_
+#define _NOTIFIERNOTHINGACTION_H_
+
+#include "notifieraction.h"
+
+class NotifierNothingAction : public NotifierAction
+{
+public:
+ NotifierNothingAction();
+ virtual QString id() const;
+ virtual void execute(KFileItem &medium);
+};
+
+#endif
+
diff --git a/kioslave/media/libmediacommon/notifieropenaction.cpp b/kioslave/media/libmediacommon/notifieropenaction.cpp
new file mode 100644
index 000000000..82db14b97
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifieropenaction.cpp
@@ -0,0 +1,45 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 Kévin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 "notifieropenaction.h"
+
+#include <klocale.h>
+
+NotifierOpenAction::NotifierOpenAction()
+ : NotifierAction()
+{
+ setIconName("window_new");
+ setLabel(i18n("Open in New Window"));
+}
+
+QString NotifierOpenAction::id() const
+{
+ return "#OpenAction";
+}
+
+void NotifierOpenAction::execute(KFileItem &medium)
+{
+ medium.run();
+}
+
+bool NotifierOpenAction::supportsMimetype( const QString &mimetype ) const
+{
+ return !mimetype.contains( "blank" );
+}
+
diff --git a/kioslave/media/libmediacommon/notifieropenaction.h b/kioslave/media/libmediacommon/notifieropenaction.h
new file mode 100644
index 000000000..3239e5ca2
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifieropenaction.h
@@ -0,0 +1,34 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 K�vin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 _NOTIFIEROPENACTION_H_
+#define _NOTIFIEROPENACTION_H_
+
+#include "notifieraction.h"
+
+class NotifierOpenAction : public NotifierAction
+{
+public:
+ NotifierOpenAction();
+ virtual QString id() const;
+ virtual void execute(KFileItem &medium);
+ bool supportsMimetype( const QString &mimetype ) const;
+};
+
+#endif
diff --git a/kioslave/media/libmediacommon/notifierserviceaction.cpp b/kioslave/media/libmediacommon/notifierserviceaction.cpp
new file mode 100644
index 000000000..ee2401945
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifierserviceaction.cpp
@@ -0,0 +1,166 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 Kévin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 "notifierserviceaction.h"
+
+#include <qdir.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <kstddirs.h>
+#include <kdesktopfile.h>
+#include <klocale.h>
+
+NotifierServiceAction::NotifierServiceAction()
+ : NotifierAction()
+{
+ NotifierAction::setIconName("button_cancel");
+ NotifierAction::setLabel(i18n("Unknown"));
+
+ m_service.m_strName = "New Service";
+ m_service.m_strIcon = "button_cancel";
+ m_service.m_strExec = "konqueror %u";
+}
+
+QString NotifierServiceAction::id() const
+{
+ if (m_filePath.isEmpty() || m_service.m_strName.isEmpty())
+ {
+ return QString();
+ }
+ else
+ {
+ return "#Service:"+m_filePath;
+ }
+}
+
+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();
+}
+
+void NotifierServiceAction::execute(KFileItem &medium)
+{
+ KURL::List urls = KURL::List( medium.url() );
+ KDEDesktopMimeType::executeService( urls, m_service );
+}
+
+void NotifierServiceAction::setService(KDEDesktopMimeType::Service service)
+{
+ NotifierAction::setIconName( service.m_strIcon );
+ NotifierAction::setLabel( service.m_strName );
+
+ m_service = service;
+
+ updateFilePath();
+}
+
+KDEDesktopMimeType::Service NotifierServiceAction::service() const
+{
+ return m_service;
+}
+
+void NotifierServiceAction::setFilePath(const QString &filePath)
+{
+ m_filePath = filePath;
+}
+
+QString NotifierServiceAction::filePath() const
+{
+ return m_filePath;
+}
+
+void NotifierServiceAction::updateFilePath()
+{
+ if ( !m_filePath.isEmpty() ) return;
+
+ QString action_name = m_service.m_strName;
+ action_name.replace( " ", "_" );
+
+ QDir actions_dir( locateLocal( "data", "konqueror/servicemenus/", true ) );
+
+ QString filename = actions_dir.absFilePath( action_name + ".desktop" );
+
+ int counter = 1;
+ while ( QFile::exists( filename ) )
+ {
+ filename = actions_dir.absFilePath( action_name
+ + QString::number( counter )
+ + ".desktop" );
+ counter++;
+ }
+
+ m_filePath = filename;
+}
+
+void NotifierServiceAction::setMimetypes(const QStringList &mimetypes)
+{
+ m_mimetypes = mimetypes;
+}
+
+QStringList NotifierServiceAction::mimetypes()
+{
+ return m_mimetypes;
+}
+
+bool NotifierServiceAction::isWritable() const
+{
+ QFileInfo info( m_filePath );
+
+ if ( info.exists() )
+ {
+ return info.isWritable();
+ }
+ else
+ {
+ info = QFileInfo( info.dirPath() );
+ return info.isWritable();
+ }
+}
+
+bool NotifierServiceAction::supportsMimetype(const QString &mimetype) const
+{
+ return m_mimetypes.contains(mimetype);
+}
+
+void NotifierServiceAction::save() const
+{
+ QFile::remove( m_filePath );
+ KDesktopFile desktopFile(m_filePath);
+
+ desktopFile.setGroup(QString("Desktop Action ") + m_service.m_strName);
+ desktopFile.writeEntry(QString("Icon"), m_service.m_strIcon);
+ desktopFile.writeEntry(QString("Name"), m_service.m_strName);
+ desktopFile.writeEntry(QString("Exec"), m_service.m_strExec);
+
+ desktopFile.setDesktopGroup();
+
+ desktopFile.writeEntry(QString("ServiceTypes"), m_mimetypes, ",");
+ desktopFile.writeEntry(QString("Actions"),
+ QStringList(m_service.m_strName),";");
+}
+
diff --git a/kioslave/media/libmediacommon/notifierserviceaction.h b/kioslave/media/libmediacommon/notifierserviceaction.h
new file mode 100644
index 000000000..4d61a6b74
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifierserviceaction.h
@@ -0,0 +1,61 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 K�vin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 _NOTIFIERSERVICEACTION_H_
+#define _NOTIFIERSERVICEACTION_H_
+
+#include <kmimetype.h>
+#include <qstring.h>
+
+#include "notifieraction.h"
+
+class NotifierServiceAction : public NotifierAction
+{
+public:
+ NotifierServiceAction();
+ virtual QString id() const;
+ virtual void execute(KFileItem &item);
+
+ virtual void setIconName( const QString &icon );
+ virtual void setLabel( const QString &label );
+
+ void setService(KDEDesktopMimeType::Service service);
+ KDEDesktopMimeType::Service service() const;
+
+ void setFilePath(const QString &filePath);
+ QString filePath() const;
+
+ void setMimetypes(const QStringList &mimetypes);
+ QStringList mimetypes();
+
+ virtual bool isWritable() const;
+ virtual bool supportsMimetype(const QString &mimetype) const;
+
+ void save() const;
+
+private:
+ void updateFilePath();
+
+ KDEDesktopMimeType::Service m_service;
+ QString m_filePath;
+ QStringList m_mimetypes;
+};
+
+#endif
+
diff --git a/kioslave/media/libmediacommon/notifiersettings.cpp b/kioslave/media/libmediacommon/notifiersettings.cpp
new file mode 100644
index 000000000..c7ad616a5
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifiersettings.cpp
@@ -0,0 +1,379 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 Kévin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 "notifiersettings.h"
+
+#include <kglobal.h>
+#include <kdesktopfile.h>
+#include <kstandarddirs.h>
+#include <qdir.h>
+#include <qfile.h>
+
+#include "notifieropenaction.h"
+#include "notifiernothingaction.h"
+
+
+NotifierSettings::NotifierSettings()
+{
+ m_supportedMimetypes.append( "media/removable_unmounted" );
+ m_supportedMimetypes.append( "media/removable_mounted" );
+ m_supportedMimetypes.append( "media/camera_unmounted" );
+ m_supportedMimetypes.append( "media/camera_mounted" );
+ m_supportedMimetypes.append( "media/gphoto2camera" );
+ m_supportedMimetypes.append( "media/cdrom_unmounted" );
+ m_supportedMimetypes.append( "media/cdrom_mounted" );
+ m_supportedMimetypes.append( "media/dvd_unmounted" );
+ m_supportedMimetypes.append( "media/dvd_mounted" );
+ m_supportedMimetypes.append( "media/cdwriter_unmounted" );
+ m_supportedMimetypes.append( "media/cdwriter_mounted" );
+ m_supportedMimetypes.append( "media/blankcd" );
+ m_supportedMimetypes.append( "media/blankdvd" );
+ m_supportedMimetypes.append( "media/audiocd" );
+ m_supportedMimetypes.append( "media/dvdvideo" );
+ m_supportedMimetypes.append( "media/vcd" );
+ m_supportedMimetypes.append( "media/svcd" );
+
+ reload();
+}
+
+NotifierSettings::~NotifierSettings()
+{
+ while ( !m_actions.isEmpty() )
+ {
+ NotifierAction *a = m_actions.first();
+ m_actions.remove( a );
+ delete a;
+ }
+
+ while ( !m_deletedActions.isEmpty() )
+ {
+ NotifierServiceAction *a = m_deletedActions.first();
+ m_deletedActions.remove( a );
+ delete a;
+ }
+}
+
+QValueList<NotifierAction*> NotifierSettings::actions()
+{
+ return m_actions;
+}
+
+const QStringList &NotifierSettings::supportedMimetypes()
+{
+ return m_supportedMimetypes;
+}
+
+QValueList<NotifierAction*> NotifierSettings::actionsForMimetype( const QString &mimetype )
+{
+ QValueList<NotifierAction*> result;
+
+ QValueList<NotifierAction*>::iterator it = m_actions.begin();
+ QValueList<NotifierAction*>::iterator end = m_actions.end();
+
+ for ( ; it!=end; ++it )
+ {
+ if ( (*it)->supportsMimetype( mimetype ) )
+ {
+ result.append( *it );
+ }
+ }
+
+ return result;
+}
+
+bool NotifierSettings::addAction( NotifierServiceAction *action )
+{
+ if ( !m_idMap.contains( action->id() ) )
+ {
+ m_actions.insert( --m_actions.end(), action );
+ m_idMap[ action->id() ] = action;
+ return true;
+ }
+ return false;
+}
+
+bool NotifierSettings::deleteAction( NotifierServiceAction *action )
+{
+ if ( action->isWritable() )
+ {
+ m_actions.remove( action );
+ m_idMap.remove( action->id() );
+ m_deletedActions.append( action );
+
+ QStringList auto_mimetypes = action->autoMimetypes();
+ QStringList::iterator it = auto_mimetypes.begin();
+ QStringList::iterator end = auto_mimetypes.end();
+
+ for ( ; it!=end; ++it )
+ {
+ action->removeAutoMimetype( *it );
+ m_autoMimetypesMap.remove( *it );
+ }
+
+ return true;
+ }
+ return false;
+}
+
+void NotifierSettings::setAutoAction( const QString &mimetype, NotifierAction *action )
+{
+ resetAutoAction( mimetype );
+ m_autoMimetypesMap[mimetype] = action;
+ action->addAutoMimetype( mimetype );
+}
+
+
+void NotifierSettings::resetAutoAction( const QString &mimetype )
+{
+ if ( m_autoMimetypesMap.contains( mimetype ) )
+ {
+ NotifierAction *action = m_autoMimetypesMap[mimetype];
+ action->removeAutoMimetype( mimetype );
+ m_autoMimetypesMap.remove(mimetype);
+ }
+}
+
+void NotifierSettings::clearAutoActions()
+{
+ QMap<QString,NotifierAction*>::iterator it = m_autoMimetypesMap.begin();
+ QMap<QString,NotifierAction*>::iterator end = m_autoMimetypesMap.end();
+
+ for ( ; it!=end; ++it )
+ {
+ NotifierAction *action = it.data();
+ QString mimetype = it.key();
+
+ if ( action )
+ action->removeAutoMimetype( mimetype );
+ m_autoMimetypesMap[mimetype] = 0L;
+ }
+}
+
+NotifierAction *NotifierSettings::autoActionForMimetype( const QString &mimetype )
+{
+ if ( m_autoMimetypesMap.contains( mimetype ) )
+ {
+ return m_autoMimetypesMap[mimetype];
+ }
+ else
+ {
+ return 0L;
+ }
+}
+
+void NotifierSettings::reload()
+{
+ while ( !m_actions.isEmpty() )
+ {
+ NotifierAction *a = m_actions.first();
+ m_actions.remove( a );
+ delete a;
+ }
+
+ while ( !m_deletedActions.isEmpty() )
+ {
+ NotifierServiceAction *a = m_deletedActions.first();
+ m_deletedActions.remove( a );
+ delete a;
+ }
+
+ m_idMap.clear();
+ m_autoMimetypesMap.clear();
+
+ NotifierOpenAction *open = new NotifierOpenAction();
+ m_actions.append( open );
+ m_idMap[ open->id() ] = open;
+
+ QValueList<NotifierServiceAction*> services = listServices();
+
+ QValueList<NotifierServiceAction*>::iterator serv_it = services.begin();
+ QValueList<NotifierServiceAction*>::iterator serv_end = services.end();
+
+ for ( ; serv_it!=serv_end; ++serv_it )
+ {
+ m_actions.append( *serv_it );
+ m_idMap[ (*serv_it)->id() ] = *serv_it;
+ }
+
+ NotifierNothingAction *nothing = new NotifierNothingAction();
+ m_actions.append( nothing );
+ m_idMap[ nothing->id() ] = nothing;
+
+ KConfig config( "medianotifierrc", true );
+ QMap<QString,QString> auto_actions_map = config.entryMap( "Auto Actions" );
+
+ QMap<QString,QString>::iterator auto_it = auto_actions_map.begin();
+ QMap<QString,QString>::iterator auto_end = auto_actions_map.end();
+
+ for ( ; auto_it!=auto_end; ++auto_it )
+ {
+ QString mime = auto_it.key();
+ QString action_id = auto_it.data();
+
+ if ( m_idMap.contains( action_id ) )
+ {
+ setAutoAction( mime, m_idMap[action_id] );
+ }
+ else
+ {
+ config.deleteEntry( mime );
+ }
+ }
+}
+void NotifierSettings::save()
+{
+ QValueList<NotifierAction*>::iterator act_it = m_actions.begin();
+ QValueList<NotifierAction*>::iterator act_end = m_actions.end();
+
+ for ( ; act_it!=act_end; ++act_it )
+ {
+ NotifierServiceAction *service;
+ if ( ( service=dynamic_cast<NotifierServiceAction*>( *act_it ) )
+ && service->isWritable() )
+ {
+ service->save();
+ }
+ }
+
+ while ( !m_deletedActions.isEmpty() )
+ {
+ NotifierServiceAction *a = m_deletedActions.first();
+ m_deletedActions.remove( a );
+ QFile::remove( a->filePath() );
+ delete a;
+ }
+
+ KSimpleConfig config( "medianotifierrc" );
+ config.setGroup( "Auto Actions" );
+
+ QMap<QString,NotifierAction*>::iterator auto_it = m_autoMimetypesMap.begin();
+ QMap<QString,NotifierAction*>::iterator auto_end = m_autoMimetypesMap.end();
+
+ for ( ; auto_it!=auto_end; ++auto_it )
+ {
+ if ( auto_it.data()!=0L )
+ {
+ config.writeEntry( auto_it.key(), auto_it.data()->id() );
+ }
+ else
+ {
+ config.deleteEntry( auto_it.key() );
+ }
+ }
+}
+
+QValueList<NotifierServiceAction*> NotifierSettings::loadActions( KDesktopFile &desktop ) const
+{
+ desktop.setDesktopGroup();
+
+ QValueList<NotifierServiceAction*> services;
+
+ const QString filename = desktop.fileName();
+ const QStringList mimetypes = desktop.readListEntry( "ServiceTypes" );
+
+ QValueList<KDEDesktopMimeType::Service> type_services
+ = KDEDesktopMimeType::userDefinedServices(filename, true);
+
+ QValueList<KDEDesktopMimeType::Service>::iterator service_it = type_services.begin();
+ QValueList<KDEDesktopMimeType::Service>::iterator service_end = type_services.end();
+ for (; service_it!=service_end; ++service_it)
+ {
+ NotifierServiceAction *service_action
+ = new NotifierServiceAction();
+
+ service_action->setService( *service_it );
+ service_action->setFilePath( filename );
+ service_action->setMimetypes( mimetypes );
+
+ services += service_action;
+ }
+
+ return services;
+}
+
+
+bool NotifierSettings::shouldLoadActions( KDesktopFile &desktop, const QString &mimetype ) const
+{
+ desktop.setDesktopGroup();
+
+ if ( desktop.hasKey( "Actions" )
+ && desktop.hasKey( "ServiceTypes" )
+ && !desktop.readBoolEntry( "X-KDE-MediaNotifierHide", false ) )
+ {
+ const QStringList actions = desktop.readListEntry( "Actions" );
+
+ if ( actions.size()!=1 )
+ {
+ return false;
+ }
+
+ const QStringList types = desktop.readListEntry( "ServiceTypes" );
+
+ if ( mimetype.isEmpty() )
+ {
+ QStringList::ConstIterator type_it = types.begin();
+ QStringList::ConstIterator type_end = types.end();
+ for (; type_it != type_end; ++type_it)
+ {
+ if ( (*type_it).startsWith( "media/" ) )
+ {
+ return true;
+ }
+ }
+ }
+ else if ( types.contains(mimetype) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+QValueList<NotifierServiceAction*> NotifierSettings::listServices( const QString &mimetype ) const
+{
+ QValueList<NotifierServiceAction*> services;
+ QStringList dirs = KGlobal::dirs()->findDirs("data", "konqueror/servicemenus/");
+
+ QStringList::ConstIterator dir_it = dirs.begin();
+ QStringList::ConstIterator dir_end = dirs.end();
+ for (; dir_it != dir_end; ++dir_it)
+ {
+ QDir dir( *dir_it );
+
+ QStringList entries = dir.entryList( "*.desktop", QDir::Files );
+
+ QStringList::ConstIterator entry_it = entries.begin();
+ QStringList::ConstIterator entry_end = entries.end();
+
+ for (; entry_it != entry_end; ++entry_it )
+ {
+ QString filename = *dir_it + *entry_it;
+
+ KDesktopFile desktop( filename, true );
+
+ if ( shouldLoadActions(desktop, mimetype) )
+ {
+ services+=loadActions(desktop);
+ }
+ }
+ }
+
+ return services;
+}
diff --git a/kioslave/media/libmediacommon/notifiersettings.h b/kioslave/media/libmediacommon/notifiersettings.h
new file mode 100644
index 000000000..6ddee318b
--- /dev/null
+++ b/kioslave/media/libmediacommon/notifiersettings.h
@@ -0,0 +1,63 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <[email protected]>
+ Copyright (c) 2005 K�vin Ottens <ervin ipsquad net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License 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 _NOTIFIERSETTINGS_H_
+#define _NOTIFIERSETTINGS_H_
+
+#include <qvaluelist.h>
+#include <qmap.h>
+
+#include "notifieraction.h"
+#include "notifierserviceaction.h"
+
+
+class NotifierSettings
+{
+public:
+ NotifierSettings();
+ ~NotifierSettings();
+
+ QValueList<NotifierAction*> actions();
+ QValueList<NotifierAction*> actionsForMimetype( const QString &mimetype );
+
+ bool addAction( NotifierServiceAction *action );
+ bool deleteAction( NotifierServiceAction *action );
+
+ void setAutoAction( const QString &mimetype, NotifierAction *action );
+ void resetAutoAction( const QString &mimetype );
+ void clearAutoActions();
+ NotifierAction *autoActionForMimetype( const QString &mimetype );
+
+ const QStringList &supportedMimetypes();
+
+ void reload();
+ void save();
+
+private:
+ QValueList<NotifierServiceAction*> listServices( const QString &mimetype = QString() ) const;
+ bool shouldLoadActions( KDesktopFile &desktop, const QString &mimetype ) const;
+ QValueList<NotifierServiceAction*> loadActions( KDesktopFile &desktop ) const;
+
+ QStringList m_supportedMimetypes;
+ QValueList<NotifierAction*> m_actions;
+ QValueList<NotifierServiceAction*> m_deletedActions;
+ QMap<QString,NotifierAction*> m_idMap;
+ QMap<QString,NotifierAction*> m_autoMimetypesMap;
+};
+#endif