diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 4aed2c8219774f5d797760606b8489a92ddc5163 (patch) | |
tree | 3f8c130f7d269626bf6a9447407ef6c35954426a /kioslave/media/medianotifier/notificationdialog.cpp | |
download | tdebase-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/medianotifier/notificationdialog.cpp')
-rw-r--r-- | kioslave/media/medianotifier/notificationdialog.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/kioslave/media/medianotifier/notificationdialog.cpp b/kioslave/media/medianotifier/notificationdialog.cpp new file mode 100644 index 000000000..a4dab0245 --- /dev/null +++ b/kioslave/media/medianotifier/notificationdialog.cpp @@ -0,0 +1,147 @@ +/* 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 "notificationdialog.h" +#include <qlayout.h> + +#include <krun.h> +#include <klocale.h> +#include <kstandarddirs.h> +#include <kio/global.h> +#include <klistbox.h> +#include <qlabel.h> +#include <qcheckbox.h> +#include <qpushbutton.h> + +#include "actionlistboxitem.h" +#include "notificationdialogview.h" + +NotificationDialog::NotificationDialog( KFileItem medium, NotifierSettings *settings, + QWidget* parent, const char* name ) + : KDialogBase( parent, name, false, i18n( "Medium Detected" ), Ok|Cancel|User1, Ok, true), + m_medium(medium), m_settings( settings ) +{ + setCaption( KIO::decodeFileName(m_medium.name()) ); + clearWState( WState_Polished ); + + QWidget *page = new QWidget( this ); + setMainWidget(page); + QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); + + m_view = new NotificationDialogView( page ); + + topLayout->addWidget(m_view); + m_view->iconLabel->setPixmap( m_medium.pixmap(64) ); + m_view->mimetypeLabel->setText( i18n( "<b>Medium type:</b>" ) + " " + + m_medium.mimeTypePtr()->comment() ); + + updateActionsListBox(); + + resize( QSize(400,400).expandedTo( minimumSizeHint() ) ); + + + m_actionWatcher = new KDirWatch(); + QString services_dir + = locateLocal( "data", "konqueror/servicemenus", true ); + m_actionWatcher->addDir( services_dir ); + + setButtonText( User1, i18n("Configure...") ); + + connect( m_actionWatcher, SIGNAL( dirty( const QString & ) ), + this, SLOT( slotActionsChanged( const QString & ) ) ); + connect( this , SIGNAL( okClicked() ), + this, SLOT( slotOk() ) ); + connect( this, SIGNAL( user1Clicked() ), + this, SLOT( slotConfigure() ) ); + connect( m_view->actionsList, SIGNAL( doubleClicked ( QListBoxItem*, const QPoint & ) ), + this, SLOT( slotOk() ) ); + + connect( this, SIGNAL( finished() ), + this, SLOT( delayedDestruct() ) ); + + m_actionWatcher->startScan(); + QPushButton * btn = actionButton( Ok ); + btn->setFocus(); +} + +NotificationDialog::~NotificationDialog() +{ + delete m_actionWatcher; + delete m_settings; +} + +void NotificationDialog::updateActionsListBox() +{ + m_view->actionsList->clear(); + + QValueList<NotifierAction*> actions + = m_settings->actionsForMimetype( m_medium.mimetype() ); + + QValueList<NotifierAction*>::iterator it = actions.begin(); + QValueList<NotifierAction*>::iterator end = actions.end(); + + for ( ; it!=end; ++it ) + { + new ActionListBoxItem( *it, m_medium.mimetype(), + m_view->actionsList ); + } + + m_view->actionsList->setSelected( 0, true ); +} + + +void NotificationDialog::slotActionsChanged(const QString &/*dir*/) +{ + m_settings->reload(); + updateActionsListBox(); +} + +void NotificationDialog::slotOk() +{ + QListBoxItem *item = m_view->actionsList->selectedItem(); + + if ( item != 0L ) + { + ActionListBoxItem *action_item + = static_cast<ActionListBoxItem*>( item ); + NotifierAction *action = action_item->action(); + + launchAction( action ); + } +} + +void NotificationDialog::launchAction( NotifierAction *action ) +{ + if ( m_view->autoActionCheck->isChecked() ) + { + m_settings->setAutoAction( m_medium.mimetype(), action ); + m_settings->save(); + } + + action->execute(m_medium); + + QDialog::accept(); +} + +void NotificationDialog::slotConfigure() +{ + KRun::runCommand("kcmshell media"); +} + +#include "notificationdialog.moc" |