summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media/libmediacommon
diff options
context:
space:
mode:
Diffstat (limited to 'tdeioslave/media/libmediacommon')
-rw-r--r--tdeioslave/media/libmediacommon/CMakeLists.txt41
-rw-r--r--tdeioslave/media/libmediacommon/Makefile.am11
-rw-r--r--tdeioslave/media/libmediacommon/actionlistboxitem.cpp47
-rw-r--r--tdeioslave/media/libmediacommon/actionlistboxitem.h40
-rw-r--r--tdeioslave/media/libmediacommon/mediamanagersettings.kcfg28
-rw-r--r--tdeioslave/media/libmediacommon/mediamanagersettings.kcfgc4
-rw-r--r--tdeioslave/media/libmediacommon/medium.cpp268
-rw-r--r--tdeioslave/media/libmediacommon/medium.h127
-rw-r--r--tdeioslave/media/libmediacommon/notifieraction.cpp97
-rw-r--r--tdeioslave/media/libmediacommon/notifieraction.h60
-rw-r--r--tdeioslave/media/libmediacommon/notifiernothingaction.cpp39
-rw-r--r--tdeioslave/media/libmediacommon/notifiernothingaction.h34
-rw-r--r--tdeioslave/media/libmediacommon/notifieropenaction.cpp45
-rw-r--r--tdeioslave/media/libmediacommon/notifieropenaction.h34
-rw-r--r--tdeioslave/media/libmediacommon/notifierserviceaction.cpp166
-rw-r--r--tdeioslave/media/libmediacommon/notifierserviceaction.h61
-rw-r--r--tdeioslave/media/libmediacommon/notifiersettings.cpp391
-rw-r--r--tdeioslave/media/libmediacommon/notifiersettings.h63
18 files changed, 1556 insertions, 0 deletions
diff --git a/tdeioslave/media/libmediacommon/CMakeLists.txt b/tdeioslave/media/libmediacommon/CMakeLists.txt
new file mode 100644
index 000000000..2059e35a8
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/CMakeLists.txt
@@ -0,0 +1,41 @@
+#################################################
+#
+# (C) 2010-2011 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+
+##### other data ################################
+
+install( FILES mediamanagersettings.kcfg DESTINATION ${KCFG_INSTALL_DIR} )
+
+
+##### mediacommon (static) ######################
+
+set( target mediacommon )
+
+set( ${target}_SRCS
+ medium.cpp actionlistboxitem.cpp notifieraction.cpp
+ notifierserviceaction.cpp notifiernothingaction.cpp
+ notifieropenaction.cpp notifiersettings.cpp
+ mediamanagersettings.kcfgc
+)
+
+tde_add_library( ${target} STATIC_PIC AUTOMOC
+ SOURCES ${${target}_SRCS}
+)
diff --git a/tdeioslave/media/libmediacommon/Makefile.am b/tdeioslave/media/libmediacommon/Makefile.am
new file mode 100644
index 000000000..dd27d265a
--- /dev/null
+++ b/tdeioslave/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/tdeioslave/media/libmediacommon/actionlistboxitem.cpp b/tdeioslave/media/libmediacommon/actionlistboxitem.cpp
new file mode 100644
index 000000000..271d2e487
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/actionlistboxitem.cpp
@@ -0,0 +1,47 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 <tqpixmap.h>
+
+ActionListBoxItem::ActionListBoxItem(NotifierAction *action, TQString mimetype, TQListBox *parent)
+ : TQListBoxPixmap(parent, action->pixmap()),
+ m_action(action)
+{
+ TQString 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/tdeioslave/media/libmediacommon/actionlistboxitem.h b/tdeioslave/media/libmediacommon/actionlistboxitem.h
new file mode 100644
index 000000000..254f065de
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/actionlistboxitem.h
@@ -0,0 +1,40 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 <tqlistbox.h>
+#include <tqstring.h>
+
+#include "notifieraction.h"
+
+class ActionListBoxItem : public TQListBoxPixmap
+{
+public:
+ ActionListBoxItem(NotifierAction *action, TQString mimetype, TQListBox *parent);
+ ~ActionListBoxItem();
+
+ NotifierAction *action() const;
+
+private:
+ NotifierAction *m_action;
+};
+
+#endif
diff --git a/tdeioslave/media/libmediacommon/mediamanagersettings.kcfg b/tdeioslave/media/libmediacommon/mediamanagersettings.kcfg
new file mode 100644
index 000000000..2994680cd
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/mediamanagersettings.kcfg
@@ -0,0 +1,28 @@
+<?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, TDE will use it to gather information on the storage media available in your system.</whatsthis>
+ <default>true</default>
+ </entry>
+ <entry name="TdeHardwareBackendEnabled" type="Bool">
+ <label>Enable TDE hardware library backend</label>
+ <whatsthis>When TDE hardware library support is enabled, TDE 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 TDE 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 TDE 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/tdeioslave/media/libmediacommon/mediamanagersettings.kcfgc b/tdeioslave/media/libmediacommon/mediamanagersettings.kcfgc
new file mode 100644
index 000000000..bbc58d92e
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/mediamanagersettings.kcfgc
@@ -0,0 +1,4 @@
+File=mediamanagersettings.kcfg
+ClassName=MediaManagerSettings
+Singleton=true
+Mutators=true
diff --git a/tdeioslave/media/libmediacommon/medium.cpp b/tdeioslave/media/libmediacommon/medium.cpp
new file mode 100644
index 000000000..7b97fb1a0
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/medium.cpp
@@ -0,0 +1,268 @@
+/* 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 <tdeconfig.h>
+#include <klocale.h>
+
+const TQString Medium::SEPARATOR = "---";
+
+Medium::Medium(const TQString id, TQString uuid, const TQString name)
+{
+ m_properties+= id; /* ID */
+ m_properties+= uuid; /* UUID */
+ m_properties+= name; /* NAME */
+ m_properties+= name; /* LABEL */
+ m_properties+= TQString::null; /* USER_LABEL */
+
+ m_properties+= "false"; /* MOUNTABLE */
+ m_properties+= TQString::null; /* DEVICE_NODE */
+ m_properties+= TQString::null; /* MOUNT_POINT */
+ m_properties+= TQString::null; /* FS_TYPE */
+ m_properties+= "false"; /* MOUNTED */
+ m_properties+= TQString::null; /* BASE_URL */
+ m_properties+= TQString::null; /* MIME_TYPE */
+ m_properties+= TQString::null; /* ICON_NAME */
+ m_properties+= "false"; /* ENCRYPTED */
+ m_properties+= TQString::null; /* CLEAR_DEVICE_UDI */
+ m_properties+= "false"; /* HIDDEN */
+
+ loadUserLabel();
+
+ m_halmounted = false;
+}
+
+Medium::Medium()
+{
+ m_properties+= TQString::null; /* ID */
+ m_properties+= TQString::null; /* UUID */
+ m_properties+= TQString::null; /* NAME */
+ m_properties+= TQString::null; /* LABEL */
+ m_properties+= TQString::null; /* USER_LABEL */
+
+ m_properties+= TQString::null; /* MOUNTABLE */
+ m_properties+= TQString::null; /* DEVICE_NODE */
+ m_properties+= TQString::null; /* MOUNT_POINT */
+ m_properties+= TQString::null; /* FS_TYPE */
+ m_properties+= TQString::null; /* MOUNTED */
+ m_properties+= TQString::null; /* BASE_URL */
+ m_properties+= TQString::null; /* MIME_TYPE */
+ m_properties+= TQString::null; /* ICON_NAME */
+ m_properties+= TQString::null; /* ENCRYPTED */
+ m_properties+= TQString::null; /* CLEAR_DEVICE_UDI */
+ m_properties+= "false"; /* HIDDEN */
+
+ m_halmounted = false;
+}
+
+const Medium Medium::create(const TQStringList &properties)
+{
+ Medium m;
+
+ if ( properties.size() >= PROPERTIES_COUNT )
+ {
+ m.m_properties[ID] = properties[ID];
+ m.m_properties[UUID] = properties[UUID];
+ 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];
+ m.m_properties[ENCRYPTED] = properties[ENCRYPTED];
+ m.m_properties[CLEAR_DEVICE_UDI] = properties[CLEAR_DEVICE_UDI];
+ m.m_properties[HIDDEN] = properties[HIDDEN];
+ }
+
+ return m;
+}
+
+Medium::MList Medium::createList(const TQStringList &properties)
+{
+ MList l;
+
+ if ( properties.size() % (PROPERTIES_COUNT+1) == 0)
+ {
+ int media_count = properties.size()/(PROPERTIES_COUNT+1);
+
+ TQStringList props = properties;
+
+ for(int i=0; i<media_count; i++)
+ {
+ const Medium m = create(props);
+ l.append(m);
+
+ TQStringList::iterator first = props.begin();
+ TQStringList::iterator last = props.find(SEPARATOR);
+ ++last;
+ props.erase(first, last);
+ }
+ }
+
+ return l;
+}
+
+
+void Medium::setName(const TQString &name)
+{
+ m_properties[NAME] = name;
+}
+
+void Medium::setLabel(const TQString &label)
+{
+ m_properties[LABEL] = label;
+}
+
+void Medium::setEncrypted(bool state)
+{
+ m_properties[ENCRYPTED] = ( state ? "true" : "false" );
+}
+
+void Medium::setHidden(bool state)
+{
+ m_properties[HIDDEN] = ( state ? "true" : "false" );
+}
+
+void Medium::setUserLabel(const TQString &label)
+{
+ TDEConfig cfg("mediamanagerrc");
+ cfg.setGroup("UserLabels");
+
+ TQString entry_name = m_properties[UUID];
+
+ if ( label.isNull() )
+ {
+ cfg.deleteEntry(entry_name);
+ }
+ else
+ {
+ cfg.writeEntry(entry_name, label);
+ }
+
+ m_properties[USER_LABEL] = label;
+}
+
+void Medium::loadUserLabel()
+{
+ TDEConfig cfg("mediamanagerrc");
+ cfg.setGroup("UserLabels");
+
+ TQString entry_name = m_properties[UUID];
+
+ if ( cfg.hasKey(entry_name) )
+ {
+ m_properties[USER_LABEL] = cfg.readEntry(entry_name);
+ }
+ else
+ {
+ m_properties[USER_LABEL] = TQString::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 TQString &deviceNode,
+ const TQString &mountPoint,
+ const TQString &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::mountableState(const TQString &deviceNode,
+ const TQString &clearDeviceUdi,
+ const TQString &mountPoint,
+ const TQString &fsType, bool mounted)
+{
+ m_properties[MOUNTABLE] = "true";
+ m_properties[DEVICE_NODE] = deviceNode;
+ m_properties[CLEAR_DEVICE_UDI] = clearDeviceUdi;
+ m_properties[MOUNT_POINT] = mountPoint;
+ m_properties[FS_TYPE] = fsType;
+ m_properties[MOUNTED] = ( mounted ? "true" : "false" );
+}
+
+void Medium::unmountableState(const TQString &baseURL)
+{
+ m_properties[MOUNTABLE] = "false";
+ m_properties[BASE_URL] = baseURL;
+}
+
+void Medium::setMimeType(const TQString &mimeType)
+{
+ m_properties[MIME_TYPE] = mimeType;
+}
+
+void Medium::setIconName(const TQString &iconName)
+{
+ m_properties[ICON_NAME] = iconName;
+}
+
+bool Medium::needMounting() const
+{
+ return isMountable() && !isMounted();
+}
+
+bool Medium::needDecryption() const
+{
+ return isEncrypted() && clearDeviceUdi().isEmpty();
+}
+
+KURL Medium::prettyBaseURL() const
+{
+ if ( !baseURL().isEmpty() )
+ return baseURL();
+
+ return KURL( mountPoint() );
+}
+
+TQString Medium::prettyLabel() const
+{
+ if ( !userLabel().isEmpty() )
+ {
+ return userLabel();
+ }
+ else
+ {
+ return label();
+ }
+}
+
diff --git a/tdeioslave/media/libmediacommon/medium.h b/tdeioslave/media/libmediacommon/medium.h
new file mode 100644
index 000000000..e45dccbfd
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/medium.h
@@ -0,0 +1,127 @@
+/* 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 <tqstring.h>
+#include <tqstringlist.h>
+#include <kurl.h>
+#include <tqmap.h>
+
+class Medium
+{
+public:
+ typedef TQValueList<Medium> MList;
+
+ static const uint ID = 0;
+ static const uint UUID = 1;
+ static const uint NAME = 2;
+ static const uint LABEL = 3;
+ static const uint USER_LABEL = 4;
+ static const uint MOUNTABLE = 5;
+ static const uint DEVICE_NODE = 6;
+ static const uint MOUNT_POINT = 7;
+ static const uint FS_TYPE = 8;
+ static const uint MOUNTED = 9;
+ static const uint BASE_URL = 10;
+ static const uint MIME_TYPE = 11;
+ static const uint ICON_NAME = 12;
+ static const uint ENCRYPTED = 13;
+ static const uint CLEAR_DEVICE_UDI = 14;
+ static const uint HIDDEN = 15;
+ static const uint PROPERTIES_COUNT = 16;
+ static const TQString SEPARATOR;
+
+ Medium(const TQString id, TQString uuid, const TQString name);
+ static const Medium create(const TQStringList &properties);
+ static MList createList(const TQStringList &properties);
+
+ const TQStringList &properties() const { return m_properties; }
+
+ TQString id() const { return m_properties[ID]; }
+ TQString uuid() const { return m_properties[UUID]; }
+ TQString name() const { return m_properties[NAME]; }
+ TQString label() const { return m_properties[LABEL]; }
+ TQString userLabel() const { return m_properties[USER_LABEL]; }
+ bool isMountable() const { return m_properties[MOUNTABLE]=="true"; }
+ TQString deviceNode() const { return m_properties[DEVICE_NODE]; }
+ TQString mountPoint() const { return m_properties[MOUNT_POINT]; }
+ TQString fsType() const { return m_properties[FS_TYPE]; }
+ bool isMounted() const { return m_properties[MOUNTED]=="true"; }
+ TQString baseURL() const { return m_properties[BASE_URL]; }
+ TQString mimeType() const { return m_properties[MIME_TYPE]; }
+ TQString iconName() const { return m_properties[ICON_NAME]; }
+ bool isEncrypted() const { return m_properties[ENCRYPTED]=="true"; };
+ TQString clearDeviceUdi() const { return m_properties[CLEAR_DEVICE_UDI]; };
+ bool hidden() const { return m_properties[HIDDEN]=="true"; };
+
+ bool needMounting() const;
+ bool needDecryption() const;
+ KURL prettyBaseURL() const;
+ TQString prettyLabel() const;
+
+ void setName(const TQString &name);
+ void setLabel(const TQString &label);
+ void setUserLabel(const TQString &label);
+ void setEncrypted(bool state);
+ void setHidden(bool state);
+
+ bool mountableState(bool mounted);
+ void mountableState(const TQString &deviceNode,
+ const TQString &mountPoint,
+ const TQString &fsType, bool mounted);
+ void mountableState(const TQString &deviceNode,
+ const TQString &clearDeviceUdi,
+ const TQString &mountPoint,
+ const TQString &fsType, bool mounted);
+ void unmountableState(const TQString &baseURL = TQString::null);
+
+ void setMimeType(const TQString &mimeType);
+ void setIconName(const TQString &iconName);
+ void setHalMounted(bool flag) const { m_halmounted = flag; }
+ bool halMounted() const { return m_halmounted; }
+
+//private:
+ Medium();
+
+private:
+ void loadUserLabel();
+
+ TQStringList m_properties;
+ mutable bool m_halmounted;
+
+friend class TQValueListNode<const Medium>;
+};
+
+namespace MediaManagerUtils {
+ static inline TQMap<TQString,TQString> splitOptions(const TQStringList & options)
+ {
+ TQMap<TQString,TQString> valids;
+
+ for (TQStringList::ConstIterator it = options.begin(); it != options.end(); ++it)
+ {
+ TQString key = (*it).left((*it).find('='));
+ TQString value = (*it).mid((*it).find('=') + 1);
+ valids[key] = value;
+ }
+ return valids;
+ }
+}
+
+#endif
diff --git a/tdeioslave/media/libmediacommon/notifieraction.cpp b/tdeioslave/media/libmediacommon/notifieraction.cpp
new file mode 100644
index 000000000..0dfc4110e
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifieraction.cpp
@@ -0,0 +1,97 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 <tqfile.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <kicontheme.h>
+
+NotifierAction::NotifierAction()
+{
+}
+
+NotifierAction::~NotifierAction()
+{
+}
+
+void NotifierAction::setIconName(const TQString &iconName)
+{
+ m_iconName = iconName;
+}
+
+void NotifierAction::setLabel(const TQString &label)
+{
+ m_label = label;
+}
+
+TQString NotifierAction::iconName() const
+{
+ return m_iconName;
+}
+
+TQPixmap NotifierAction::pixmap() const
+{
+ TQFile f( m_iconName );
+
+ if ( f.exists() )
+ {
+ return TQPixmap( m_iconName );
+ }
+ else
+ {
+ TQString path = TDEGlobal::iconLoader()->iconPath( m_iconName, -32 );
+ return TQPixmap( path );
+ }
+}
+
+TQString NotifierAction::label() const
+{
+ return m_label;
+}
+
+void NotifierAction::addAutoMimetype( const TQString &mimetype )
+{
+ if ( !m_autoMimetypes.contains( mimetype ) )
+ {
+ m_autoMimetypes.append( mimetype );
+ }
+}
+
+void NotifierAction::removeAutoMimetype( const TQString &mimetype )
+{
+ m_autoMimetypes.remove( mimetype );
+}
+
+TQStringList NotifierAction::autoMimetypes()
+{
+ return m_autoMimetypes;
+}
+
+bool NotifierAction::isWritable() const
+{
+ return false;
+}
+
+bool NotifierAction::supportsMimetype(const TQString &/*mimetype*/) const
+{
+ return true;
+}
+
diff --git a/tdeioslave/media/libmediacommon/notifieraction.h b/tdeioslave/media/libmediacommon/notifieraction.h
new file mode 100644
index 000000000..0b8a87cac
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifieraction.h
@@ -0,0 +1,60 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 <tdefileitem.h>
+#include <tqstring.h>
+#include <tqpixmap.h>
+
+class NotifierSettings;
+
+class NotifierAction
+{
+public:
+ NotifierAction();
+ virtual ~NotifierAction();
+
+ virtual TQString label() const;
+ virtual TQString iconName() const;
+ virtual void setLabel( const TQString &label );
+ virtual void setIconName( const TQString &icon );
+
+ TQPixmap pixmap() const;
+
+ TQStringList autoMimetypes();
+
+ virtual TQString id() const = 0;
+ virtual bool isWritable() const;
+ virtual bool supportsMimetype( const TQString &mimetype ) const;
+ virtual void execute( KFileItem &medium ) = 0;
+
+private:
+ void addAutoMimetype( const TQString &mimetype );
+ void removeAutoMimetype( const TQString &mimetype );
+
+ TQString m_label;
+ TQString m_iconName;
+ TQStringList m_autoMimetypes;
+
+ friend class NotifierSettings;
+};
+
+#endif
diff --git a/tdeioslave/media/libmediacommon/notifiernothingaction.cpp b/tdeioslave/media/libmediacommon/notifiernothingaction.cpp
new file mode 100644
index 000000000..6a86ad92f
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifiernothingaction.cpp
@@ -0,0 +1,39 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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"));
+}
+
+TQString NotifierNothingAction::id() const
+{
+ return "#NothinAction";
+}
+
+void NotifierNothingAction::execute(KFileItem &/*medium*/)
+{
+}
+
diff --git a/tdeioslave/media/libmediacommon/notifiernothingaction.h b/tdeioslave/media/libmediacommon/notifiernothingaction.h
new file mode 100644
index 000000000..2c0d22cfb
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifiernothingaction.h
@@ -0,0 +1,34 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 TQString id() const;
+ virtual void execute(KFileItem &medium);
+};
+
+#endif
+
diff --git a/tdeioslave/media/libmediacommon/notifieropenaction.cpp b/tdeioslave/media/libmediacommon/notifieropenaction.cpp
new file mode 100644
index 000000000..4d6d8025c
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifieropenaction.cpp
@@ -0,0 +1,45 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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"));
+}
+
+TQString NotifierOpenAction::id() const
+{
+ return "#OpenAction";
+}
+
+void NotifierOpenAction::execute(KFileItem &medium)
+{
+ medium.run();
+}
+
+bool NotifierOpenAction::supportsMimetype( const TQString &mimetype ) const
+{
+ return !mimetype.contains( "blank" ) && !mimetype.contains( "encrypted" );
+}
+
diff --git a/tdeioslave/media/libmediacommon/notifieropenaction.h b/tdeioslave/media/libmediacommon/notifieropenaction.h
new file mode 100644
index 000000000..4fe8a614e
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifieropenaction.h
@@ -0,0 +1,34 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 TQString id() const;
+ virtual void execute(KFileItem &medium);
+ bool supportsMimetype( const TQString &mimetype ) const;
+};
+
+#endif
diff --git a/tdeioslave/media/libmediacommon/notifierserviceaction.cpp b/tdeioslave/media/libmediacommon/notifierserviceaction.cpp
new file mode 100644
index 000000000..c7bece4f8
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifierserviceaction.cpp
@@ -0,0 +1,166 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 <tqdir.h>
+#include <tqfile.h>
+#include <tqfileinfo.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";
+}
+
+TQString NotifierServiceAction::id() const
+{
+ if (m_filePath.isEmpty() || m_service.m_strName.isEmpty())
+ {
+ return TQString();
+ }
+ else
+ {
+ return "#Service:"+m_filePath;
+ }
+}
+
+void NotifierServiceAction::setIconName( const TQString &icon )
+{
+ m_service.m_strIcon = icon;
+ NotifierAction::setIconName( icon );
+}
+
+void NotifierServiceAction::setLabel( const TQString &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 TQString &filePath)
+{
+ m_filePath = filePath;
+}
+
+TQString NotifierServiceAction::filePath() const
+{
+ return m_filePath;
+}
+
+void NotifierServiceAction::updateFilePath()
+{
+ if ( !m_filePath.isEmpty() ) return;
+
+ TQString action_name = m_service.m_strName;
+ action_name.replace( " ", "_" );
+
+ TQDir actions_dir( locateLocal( "data", "konqueror/servicemenus/", true ) );
+
+ TQString filename = actions_dir.absFilePath( action_name + ".desktop" );
+
+ int counter = 1;
+ while ( TQFile::exists( filename ) )
+ {
+ filename = actions_dir.absFilePath( action_name
+ + TQString::number( counter )
+ + ".desktop" );
+ counter++;
+ }
+
+ m_filePath = filename;
+}
+
+void NotifierServiceAction::setMimetypes(const TQStringList &mimetypes)
+{
+ m_mimetypes = mimetypes;
+}
+
+TQStringList NotifierServiceAction::mimetypes()
+{
+ return m_mimetypes;
+}
+
+bool NotifierServiceAction::isWritable() const
+{
+ TQFileInfo info( m_filePath );
+
+ if ( info.exists() )
+ {
+ return info.isWritable();
+ }
+ else
+ {
+ info = TQFileInfo( info.dirPath() );
+ return info.isWritable();
+ }
+}
+
+bool NotifierServiceAction::supportsMimetype(const TQString &mimetype) const
+{
+ return m_mimetypes.contains(mimetype);
+}
+
+void NotifierServiceAction::save() const
+{
+ TQFile::remove( m_filePath );
+ KDesktopFile desktopFile(m_filePath);
+
+ desktopFile.setGroup(TQString("Desktop Action ") + m_service.m_strName);
+ desktopFile.writeEntry(TQString("Icon"), m_service.m_strIcon);
+ desktopFile.writeEntry(TQString("Name"), m_service.m_strName);
+ desktopFile.writeEntry(TQString("Exec"), m_service.m_strExec);
+
+ desktopFile.setDesktopGroup();
+
+ desktopFile.writeEntry(TQString("ServiceTypes"), m_mimetypes, ",");
+ desktopFile.writeEntry(TQString("Actions"),
+ TQStringList(m_service.m_strName),";");
+}
+
diff --git a/tdeioslave/media/libmediacommon/notifierserviceaction.h b/tdeioslave/media/libmediacommon/notifierserviceaction.h
new file mode 100644
index 000000000..829193fba
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifierserviceaction.h
@@ -0,0 +1,61 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 <tqstring.h>
+
+#include "notifieraction.h"
+
+class NotifierServiceAction : public NotifierAction
+{
+public:
+ NotifierServiceAction();
+ virtual TQString id() const;
+ virtual void execute(KFileItem &item);
+
+ virtual void setIconName( const TQString &icon );
+ virtual void setLabel( const TQString &label );
+
+ void setService(KDEDesktopMimeType::Service service);
+ KDEDesktopMimeType::Service service() const;
+
+ void setFilePath(const TQString &filePath);
+ TQString filePath() const;
+
+ void setMimetypes(const TQStringList &mimetypes);
+ TQStringList mimetypes();
+
+ virtual bool isWritable() const;
+ virtual bool supportsMimetype(const TQString &mimetype) const;
+
+ void save() const;
+
+private:
+ void updateFilePath();
+
+ KDEDesktopMimeType::Service m_service;
+ TQString m_filePath;
+ TQStringList m_mimetypes;
+};
+
+#endif
+
diff --git a/tdeioslave/media/libmediacommon/notifiersettings.cpp b/tdeioslave/media/libmediacommon/notifiersettings.cpp
new file mode 100644
index 000000000..254e591cb
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifiersettings.cpp
@@ -0,0 +1,391 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 <tqdir.h>
+#include <tqfile.h>
+
+#include "notifieropenaction.h"
+#include "notifiernothingaction.h"
+
+
+NotifierSettings::NotifierSettings()
+{
+ m_supportedMimetypes.append( "media/removable_unmounted" );
+ m_supportedMimetypes.append( "media/removable_unmounted_encrypted" );
+ m_supportedMimetypes.append( "media/removable_unmounted_decrypted" );
+ m_supportedMimetypes.append( "media/removable_mounted" );
+ m_supportedMimetypes.append( "media/removable_mounted_decrypted" );
+ 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_unmounted_encrypted" );
+ m_supportedMimetypes.append( "media/cdrom_unmounted_decrypted" );
+ m_supportedMimetypes.append( "media/cdrom_mounted" );
+ m_supportedMimetypes.append( "media/cdrom_mounted_decrypted" );
+ m_supportedMimetypes.append( "media/dvd_unmounted" );
+ m_supportedMimetypes.append( "media/dvd_unmounted_encrypted" );
+ m_supportedMimetypes.append( "media/dvd_unmounted_decrypted" );
+ m_supportedMimetypes.append( "media/dvd_mounted" );
+ m_supportedMimetypes.append( "media/dvd_mounted_decrypted" );
+ m_supportedMimetypes.append( "media/cdwriter_unmounted" );
+ m_supportedMimetypes.append( "media/cdwriter_unmounted_encrypted" );
+ m_supportedMimetypes.append( "media/cdwriter_unmounted_decrypted" );
+ m_supportedMimetypes.append( "media/cdwriter_mounted" );
+ m_supportedMimetypes.append( "media/cdwriter_mounted_decrypted" );
+ 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;
+ }
+}
+
+TQValueList<NotifierAction*> NotifierSettings::actions()
+{
+ return m_actions;
+}
+
+const TQStringList &NotifierSettings::supportedMimetypes()
+{
+ return m_supportedMimetypes;
+}
+
+TQValueList<NotifierAction*> NotifierSettings::actionsForMimetype( const TQString &mimetype )
+{
+ TQValueList<NotifierAction*> result;
+
+ TQValueList<NotifierAction*>::iterator it = m_actions.begin();
+ TQValueList<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 );
+
+ TQStringList auto_mimetypes = action->autoMimetypes();
+ TQStringList::iterator it = auto_mimetypes.begin();
+ TQStringList::iterator end = auto_mimetypes.end();
+
+ for ( ; it!=end; ++it )
+ {
+ action->removeAutoMimetype( *it );
+ m_autoMimetypesMap.remove( *it );
+ }
+
+ return true;
+ }
+ return false;
+}
+
+void NotifierSettings::setAutoAction( const TQString &mimetype, NotifierAction *action )
+{
+ resetAutoAction( mimetype );
+ m_autoMimetypesMap[mimetype] = action;
+ action->addAutoMimetype( mimetype );
+}
+
+
+void NotifierSettings::resetAutoAction( const TQString &mimetype )
+{
+ if ( m_autoMimetypesMap.contains( mimetype ) )
+ {
+ NotifierAction *action = m_autoMimetypesMap[mimetype];
+ action->removeAutoMimetype( mimetype );
+ m_autoMimetypesMap.remove(mimetype);
+ }
+}
+
+void NotifierSettings::clearAutoActions()
+{
+ TQMap<TQString,NotifierAction*>::iterator it = m_autoMimetypesMap.begin();
+ TQMap<TQString,NotifierAction*>::iterator end = m_autoMimetypesMap.end();
+
+ for ( ; it!=end; ++it )
+ {
+ NotifierAction *action = it.data();
+ TQString mimetype = it.key();
+
+ if ( action )
+ action->removeAutoMimetype( mimetype );
+ m_autoMimetypesMap[mimetype] = 0L;
+ }
+}
+
+NotifierAction *NotifierSettings::autoActionForMimetype( const TQString &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;
+
+ TQValueList<NotifierServiceAction*> services = listServices();
+
+ TQValueList<NotifierServiceAction*>::iterator serv_it = services.begin();
+ TQValueList<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;
+
+ TDEConfig config( "medianotifierrc", true );
+ TQMap<TQString,TQString> auto_actions_map = config.entryMap( "Auto Actions" );
+
+ TQMap<TQString,TQString>::iterator auto_it = auto_actions_map.begin();
+ TQMap<TQString,TQString>::iterator auto_end = auto_actions_map.end();
+
+ for ( ; auto_it!=auto_end; ++auto_it )
+ {
+ TQString mime = auto_it.key();
+ TQString action_id = auto_it.data();
+
+ if ( m_idMap.contains( action_id ) )
+ {
+ setAutoAction( mime, m_idMap[action_id] );
+ }
+ else
+ {
+ config.deleteEntry( mime );
+ }
+ }
+}
+void NotifierSettings::save()
+{
+ TQValueList<NotifierAction*>::iterator act_it = m_actions.begin();
+ TQValueList<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 );
+ TQFile::remove( a->filePath() );
+ delete a;
+ }
+
+ KSimpleConfig config( "medianotifierrc" );
+ config.setGroup( "Auto Actions" );
+
+ TQMap<TQString,NotifierAction*>::iterator auto_it = m_autoMimetypesMap.begin();
+ TQMap<TQString,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() );
+ }
+ }
+}
+
+TQValueList<NotifierServiceAction*> NotifierSettings::loadActions( KDesktopFile &desktop ) const
+{
+ desktop.setDesktopGroup();
+
+ TQValueList<NotifierServiceAction*> services;
+
+ const TQString filename = desktop.fileName();
+ const TQStringList mimetypes = desktop.readListEntry( "ServiceTypes" );
+
+ TQValueList<KDEDesktopMimeType::Service> type_services
+ = KDEDesktopMimeType::userDefinedServices(filename, true);
+
+ TQValueList<KDEDesktopMimeType::Service>::iterator service_it = type_services.begin();
+ TQValueList<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 TQString &mimetype ) const
+{
+ desktop.setDesktopGroup();
+
+ if ( desktop.hasKey( "Actions" )
+ && desktop.hasKey( "ServiceTypes" )
+ && !desktop.readBoolEntry( "X-TDE-MediaNotifierHide", false ) )
+ {
+ const TQStringList actions = desktop.readListEntry( "Actions" );
+
+ if ( actions.size()!=1 )
+ {
+ return false;
+ }
+
+ const TQStringList types = desktop.readListEntry( "ServiceTypes" );
+
+ if ( mimetype.isEmpty() )
+ {
+ TQStringList::ConstIterator type_it = types.begin();
+ TQStringList::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;
+}
+
+TQValueList<NotifierServiceAction*> NotifierSettings::listServices( const TQString &mimetype ) const
+{
+ TQValueList<NotifierServiceAction*> services;
+ TQStringList dirs = TDEGlobal::dirs()->findDirs("data", "konqueror/servicemenus/");
+
+ TQStringList::ConstIterator dir_it = dirs.begin();
+ TQStringList::ConstIterator dir_end = dirs.end();
+ for (; dir_it != dir_end; ++dir_it)
+ {
+ TQDir dir( *dir_it );
+
+ TQStringList entries = dir.entryList( "*.desktop", TQDir::Files );
+
+ TQStringList::ConstIterator entry_it = entries.begin();
+ TQStringList::ConstIterator entry_end = entries.end();
+
+ for (; entry_it != entry_end; ++entry_it )
+ {
+ TQString filename = *dir_it + *entry_it;
+
+ KDesktopFile desktop( filename, true );
+
+ if ( shouldLoadActions(desktop, mimetype) )
+ {
+ services+=loadActions(desktop);
+ }
+ }
+ }
+
+ return services;
+}
diff --git a/tdeioslave/media/libmediacommon/notifiersettings.h b/tdeioslave/media/libmediacommon/notifiersettings.h
new file mode 100644
index 000000000..dee5c440b
--- /dev/null
+++ b/tdeioslave/media/libmediacommon/notifiersettings.h
@@ -0,0 +1,63 @@
+/* This file is part of the KDE Project
+ Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
+ 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 <tqvaluelist.h>
+#include <tqmap.h>
+
+#include "notifieraction.h"
+#include "notifierserviceaction.h"
+
+
+class NotifierSettings
+{
+public:
+ NotifierSettings();
+ ~NotifierSettings();
+
+ TQValueList<NotifierAction*> actions();
+ TQValueList<NotifierAction*> actionsForMimetype( const TQString &mimetype );
+
+ bool addAction( NotifierServiceAction *action );
+ bool deleteAction( NotifierServiceAction *action );
+
+ void setAutoAction( const TQString &mimetype, NotifierAction *action );
+ void resetAutoAction( const TQString &mimetype );
+ void clearAutoActions();
+ NotifierAction *autoActionForMimetype( const TQString &mimetype );
+
+ const TQStringList &supportedMimetypes();
+
+ void reload();
+ void save();
+
+private:
+ TQValueList<NotifierServiceAction*> listServices( const TQString &mimetype = TQString() ) const;
+ bool shouldLoadActions( KDesktopFile &desktop, const TQString &mimetype ) const;
+ TQValueList<NotifierServiceAction*> loadActions( KDesktopFile &desktop ) const;
+
+ TQStringList m_supportedMimetypes;
+ TQValueList<NotifierAction*> m_actions;
+ TQValueList<NotifierServiceAction*> m_deletedActions;
+ TQMap<TQString,NotifierAction*> m_idMap;
+ TQMap<TQString,NotifierAction*> m_autoMimetypesMap;
+};
+#endif