summaryrefslogtreecommitdiffstats
path: root/kioslave/media/kcmodule/notifiermodule.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kioslave/media/kcmodule/notifiermodule.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
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
Diffstat (limited to 'kioslave/media/kcmodule/notifiermodule.cpp')
-rw-r--r--kioslave/media/kcmodule/notifiermodule.cpp230
1 files changed, 230 insertions, 0 deletions
diff --git a/kioslave/media/kcmodule/notifiermodule.cpp b/kioslave/media/kcmodule/notifiermodule.cpp
new file mode 100644
index 000000000..015d7396a
--- /dev/null
+++ b/kioslave/media/kcmodule/notifiermodule.cpp
@@ -0,0 +1,230 @@
+/* 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 "notifiermodule.h"
+
+#include <klocale.h>
+
+#include <qlayout.h>
+#include <kcombobox.h>
+#include <kpushbutton.h>
+#include <kstdguiitem.h>
+
+#include "notifiersettings.h"
+#include "serviceconfigdialog.h"
+#include "actionlistboxitem.h"
+#include "mimetypelistboxitem.h"
+
+NotifierModule::NotifierModule(QWidget *parent, const char *name)
+ : KCModule(parent, name)
+{
+ QBoxLayout *layout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
+
+ m_view = new NotifierModuleView( this );
+ layout->addWidget( m_view );
+
+ m_view->addButton->setGuiItem( KStdGuiItem::add() );
+ m_view->editButton->setGuiItem( KStdGuiItem::properties() );
+ m_view->deleteButton->setGuiItem( KStdGuiItem::del() );
+
+ m_view->mimetypesCombo->insertItem( i18n("All Mime Types") );
+
+ QStringList mimetypes = m_settings.supportedMimetypes();
+
+ QStringList::iterator it = mimetypes.begin();
+ QStringList::iterator end = mimetypes.end();
+
+ for ( ; it!=end; ++it )
+ {
+ new MimetypeListBoxItem( *it, m_view->mimetypesCombo->listBox() );
+ }
+
+ updateListBox();
+
+ connect( m_view->mimetypesCombo, SIGNAL( activated(int) ),
+ this, SLOT( slotMimeTypeChanged(int) ) );
+ connect( m_view->actionsList, SIGNAL( selectionChanged(QListBoxItem*) ),
+ this, SLOT( slotActionSelected(QListBoxItem*) ) );
+ connect( m_view->addButton, SIGNAL( clicked() ),
+ this, SLOT( slotAdd() ) );
+ connect( m_view->editButton, SIGNAL( clicked() ),
+ this, SLOT( slotEdit() ) );
+ connect( m_view->deleteButton, SIGNAL( clicked() ),
+ this, SLOT( slotDelete() ) );
+ connect( m_view->toggleAutoButton, SIGNAL( clicked() ),
+ this, SLOT( slotToggleAuto() ) );
+}
+
+NotifierModule::~NotifierModule()
+{
+}
+
+void NotifierModule::load()
+{
+ m_settings.reload();
+ slotMimeTypeChanged( m_view->mimetypesCombo->currentItem() );
+}
+
+void NotifierModule::save()
+{
+ m_settings.save();
+}
+
+void NotifierModule::defaults()
+{
+ m_settings.clearAutoActions();
+ slotMimeTypeChanged( m_view->mimetypesCombo->currentItem() );
+}
+
+void NotifierModule::updateListBox()
+{
+ m_view->actionsList->clear();
+ slotActionSelected( 0L );
+
+ QValueList<NotifierAction*> services;
+ if ( m_mimetype.isEmpty() )
+ {
+ services = m_settings.actions();
+ }
+ else
+ {
+ services = m_settings.actionsForMimetype( m_mimetype );
+ }
+
+ QValueList<NotifierAction*>::iterator it;
+
+ for ( it = services.begin(); it != services.end(); ++it )
+ {
+ new ActionListBoxItem( *it, m_mimetype, m_view->actionsList );
+ }
+}
+
+void NotifierModule::slotActionSelected(QListBoxItem *item)
+{
+ NotifierAction *action = 0L;
+
+ if ( item!=0L )
+ {
+ ActionListBoxItem *action_item
+ = static_cast<ActionListBoxItem*>(item);
+ action = action_item->action();
+ }
+
+ bool isWritable = action!=0L && action->isWritable();
+ m_view->deleteButton->setEnabled( isWritable );
+ m_view->editButton->setEnabled( isWritable );
+ m_view->addButton->setEnabled( TRUE );
+ m_view->toggleAutoButton->setEnabled( action!=0L && !m_mimetype.isEmpty() );
+}
+
+void NotifierModule::slotMimeTypeChanged(int index)
+{
+ if ( index == 0 )
+ {
+ m_mimetype = QString();
+ }
+ else
+ {
+ QListBoxItem *item = m_view->mimetypesCombo->listBox()->item( index );
+ MimetypeListBoxItem *mime_item
+ = static_cast<MimetypeListBoxItem*>( item );
+ m_mimetype = mime_item->mimetype();
+ }
+
+ updateListBox();
+}
+
+void NotifierModule::slotAdd()
+{
+ NotifierServiceAction *action = new NotifierServiceAction();
+ ServiceConfigDialog dialog(action, m_settings.supportedMimetypes(), this);
+
+ int value = dialog.exec();
+
+ if ( value == QDialog::Accepted )
+ {
+ m_settings.addAction( action );
+ updateListBox();
+ emit changed( true );
+ }
+ else
+ {
+ delete action;
+ }
+}
+
+void NotifierModule::slotEdit()
+{
+ ActionListBoxItem *action_item
+ = static_cast<ActionListBoxItem*>(m_view->actionsList->selectedItem());
+
+ NotifierServiceAction * action = dynamic_cast<NotifierServiceAction*>( action_item->action() );
+ if ( action )
+ {
+ ServiceConfigDialog dialog(action, m_settings.supportedMimetypes(), this);
+
+ int value = dialog.exec();
+
+ if ( value == QDialog::Accepted )
+ {
+ updateListBox();
+ emit changed( true );
+ }
+ }
+}
+
+void NotifierModule::slotDelete()
+{
+ ActionListBoxItem *action_item
+ = static_cast<ActionListBoxItem*>(m_view->actionsList->selectedItem());
+
+ NotifierServiceAction *action;
+ action = dynamic_cast<NotifierServiceAction*>( action_item->action() );
+ if ( action )
+ {
+ m_settings.deleteAction( action );
+ updateListBox();
+ emit changed( true );
+ }
+}
+
+void NotifierModule::slotToggleAuto()
+{
+ ActionListBoxItem *action_item
+ = static_cast<ActionListBoxItem*>( m_view->actionsList->selectedItem() );
+ NotifierAction *action = action_item->action();
+
+ int index = m_view->actionsList->index( action_item );
+
+ if ( action->autoMimetypes().contains( m_mimetype ) )
+ {
+ m_settings.resetAutoAction( m_mimetype );
+ }
+ else
+ {
+ m_settings.setAutoAction( m_mimetype, action );
+ }
+
+ updateListBox();
+ emit changed( true );
+
+ m_view->actionsList->setSelected( index, true );
+}
+
+#include "notifiermodule.moc"