diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-01-27 01:02:02 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-01-27 01:02:02 -0600 |
commit | de7e5867a65e0a46f1388e3e50bc7eeddd1aecbf (patch) | |
tree | dbb3152c372f8620f9290137d461f3d9f9eba1cb /tdeioslave/media/libmediacommon/notifierserviceaction.cpp | |
parent | 936d3cec490c13f2c5f7dd14f5e364fddaa6da71 (diff) | |
download | tdebase-de7e5867a65e0a46f1388e3e50bc7eeddd1aecbf.tar.gz tdebase-de7e5867a65e0a46f1388e3e50bc7eeddd1aecbf.zip |
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'tdeioslave/media/libmediacommon/notifierserviceaction.cpp')
-rw-r--r-- | tdeioslave/media/libmediacommon/notifierserviceaction.cpp | 166 |
1 files changed, 166 insertions, 0 deletions
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),";"); +} + |