From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kioslave/media/libmediacommon/Makefile.am | 11 + .../media/libmediacommon/actionlistboxitem.cpp | 47 +++ kioslave/media/libmediacommon/actionlistboxitem.h | 40 +++ .../media/libmediacommon/mediamanagersettings.kcfg | 23 ++ .../libmediacommon/mediamanagersettings.kcfgc | 4 + kioslave/media/libmediacommon/medium.cpp | 228 +++++++++++++ kioslave/media/libmediacommon/medium.h | 110 ++++++ kioslave/media/libmediacommon/notifieraction.cpp | 97 ++++++ kioslave/media/libmediacommon/notifieraction.h | 60 ++++ .../media/libmediacommon/notifiernothingaction.cpp | 39 +++ .../media/libmediacommon/notifiernothingaction.h | 34 ++ .../media/libmediacommon/notifieropenaction.cpp | 45 +++ kioslave/media/libmediacommon/notifieropenaction.h | 34 ++ .../media/libmediacommon/notifierserviceaction.cpp | 166 +++++++++ .../media/libmediacommon/notifierserviceaction.h | 61 ++++ kioslave/media/libmediacommon/notifiersettings.cpp | 379 +++++++++++++++++++++ kioslave/media/libmediacommon/notifiersettings.h | 63 ++++ 17 files changed, 1441 insertions(+) create mode 100644 kioslave/media/libmediacommon/Makefile.am create mode 100644 kioslave/media/libmediacommon/actionlistboxitem.cpp create mode 100644 kioslave/media/libmediacommon/actionlistboxitem.h create mode 100644 kioslave/media/libmediacommon/mediamanagersettings.kcfg create mode 100644 kioslave/media/libmediacommon/mediamanagersettings.kcfgc create mode 100644 kioslave/media/libmediacommon/medium.cpp create mode 100644 kioslave/media/libmediacommon/medium.h create mode 100644 kioslave/media/libmediacommon/notifieraction.cpp create mode 100644 kioslave/media/libmediacommon/notifieraction.h create mode 100644 kioslave/media/libmediacommon/notifiernothingaction.cpp create mode 100644 kioslave/media/libmediacommon/notifiernothingaction.h create mode 100644 kioslave/media/libmediacommon/notifieropenaction.cpp create mode 100644 kioslave/media/libmediacommon/notifieropenaction.h create mode 100644 kioslave/media/libmediacommon/notifierserviceaction.cpp create mode 100644 kioslave/media/libmediacommon/notifierserviceaction.h create mode 100644 kioslave/media/libmediacommon/notifiersettings.cpp create mode 100644 kioslave/media/libmediacommon/notifiersettings.h (limited to 'kioslave/media/libmediacommon') 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 + Copyright (c) 2005 Kévin Ottens + + 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 + +#include + +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 + Copyright (c) 2005 Kévin Ottens + + 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 +#include + +#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 @@ + + + + + + + + + When HAL (Hardware Abstraction Layer) support is enabled, KDE will use it to gather information on the storage media available in your system. + true + + + + Allows KDE to poll CD-Rom or DVD-Rom drives itself in order to detect medium insert. + true + + + + Allows KDE to autostart application after a medium mount if it contains an Autostart or an Autoopen file. + true + + + 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 + + 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 +#include + +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 + + 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 +#include +#include +#include + +class Medium +{ +public: + typedef QValueList 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; +}; + +namespace MediaManagerUtils { + static inline QMap splitOptions(const QStringList & options) + { + QMap 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 + Copyright (c) 2005 Kévin Ottens + + 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 +#include +#include +#include + +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 + Copyright (c) 2005 Kévin Ottens + + 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 +#include +#include + +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 + Copyright (c) 2005 Kévin Ottens + + 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 + +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 + Copyright (c) 2005 Kévin Ottens + + 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 + Copyright (c) 2005 Kévin Ottens + + 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 + +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 + Copyright (c) 2005 Kévin Ottens + + 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 + Copyright (c) 2005 Kévin Ottens + + 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 +#include +#include +#include +#include +#include + +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 + Copyright (c) 2005 Kévin Ottens + + 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 +#include + +#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 + Copyright (c) 2005 Kévin Ottens + + 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 +#include +#include +#include +#include + +#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 NotifierSettings::actions() +{ + return m_actions; +} + +const QStringList &NotifierSettings::supportedMimetypes() +{ + return m_supportedMimetypes; +} + +QValueList NotifierSettings::actionsForMimetype( const QString &mimetype ) +{ + QValueList result; + + QValueList::iterator it = m_actions.begin(); + QValueList::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::iterator it = m_autoMimetypesMap.begin(); + QMap::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 services = listServices(); + + QValueList::iterator serv_it = services.begin(); + QValueList::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 auto_actions_map = config.entryMap( "Auto Actions" ); + + QMap::iterator auto_it = auto_actions_map.begin(); + QMap::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::iterator act_it = m_actions.begin(); + QValueList::iterator act_end = m_actions.end(); + + for ( ; act_it!=act_end; ++act_it ) + { + NotifierServiceAction *service; + if ( ( service=dynamic_cast( *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::iterator auto_it = m_autoMimetypesMap.begin(); + QMap::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 NotifierSettings::loadActions( KDesktopFile &desktop ) const +{ + desktop.setDesktopGroup(); + + QValueList services; + + const QString filename = desktop.fileName(); + const QStringList mimetypes = desktop.readListEntry( "ServiceTypes" ); + + QValueList type_services + = KDEDesktopMimeType::userDefinedServices(filename, true); + + QValueList::iterator service_it = type_services.begin(); + QValueList::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 NotifierSettings::listServices( const QString &mimetype ) const +{ + QValueList 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 + Copyright (c) 2005 Kévin Ottens + + 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 +#include + +#include "notifieraction.h" +#include "notifierserviceaction.h" + + +class NotifierSettings +{ +public: + NotifierSettings(); + ~NotifierSettings(); + + QValueList actions(); + QValueList 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 listServices( const QString &mimetype = QString() ) const; + bool shouldLoadActions( KDesktopFile &desktop, const QString &mimetype ) const; + QValueList loadActions( KDesktopFile &desktop ) const; + + QStringList m_supportedMimetypes; + QValueList m_actions; + QValueList m_deletedActions; + QMap m_idMap; + QMap m_autoMimetypesMap; +}; +#endif -- cgit v1.2.3