some more win32'fication to fix non-ascii filename handling
[kdelibs.git] / knotify / config / knotifyconfigwidget.cpp
blob60f3a51f963b429dc70c09f7729e7b0e41d35e74
1 /* This file is part of the KDE libraries
2 Copyright (C) 2005 Olivier Goffart <ogoffart at kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "knotifyconfigwidget.h"
20 #include "knotifyconfigactionswidget.h"
21 #include "knotifyeventlist.h"
22 #include "knotifyconfigelement.h"
24 #include <kapplication.h>
25 #include <kdialog.h>
26 #include <QVBoxLayout>
27 #include <QDBusInterface>
28 #include <QDBusConnectionInterface>
30 struct KNotifyConfigWidget::Private
32 KNotifyEventList *eventList;
33 KNotifyConfigActionsWidget *actionsconfig;
34 KNotifyConfigElement *currentElement;
38 KNotifyConfigWidget::KNotifyConfigWidget( QWidget * parent )
39 : QWidget(parent) , d(new Private)
41 d->currentElement=0l;
42 d->eventList=new KNotifyEventList( this );
43 d->eventList->setFocus();
44 d->actionsconfig=new KNotifyConfigActionsWidget(this);
45 d->actionsconfig->setEnabled(false);
46 connect(d->eventList , SIGNAL(eventSelected( KNotifyConfigElement* )) ,
47 this , SLOT(slotEventSelected( KNotifyConfigElement* )));
48 connect(d->actionsconfig,SIGNAL(changed()),this,SLOT(slotActionChanged()));
50 QVBoxLayout *layout = new QVBoxLayout(this);
51 layout->setMargin(0);
52 layout->addWidget(d->eventList,1);
53 layout->addWidget(d->actionsconfig);
57 KNotifyConfigWidget::~KNotifyConfigWidget()
59 delete d;
63 void KNotifyConfigWidget::setApplication (const QString & app, const QString & context_name, const QString & context_value )
65 d->currentElement=0l;
66 d->eventList->fill( app.isEmpty() ? KGlobal::mainComponent().componentName() : app , context_name , context_value );
70 void KNotifyConfigWidget::slotEventSelected( KNotifyConfigElement * e )
72 if(d->currentElement)
74 d->actionsconfig->save( d->currentElement );
76 d->currentElement=e;
77 if(e)
79 d->actionsconfig->setConfigElement( e);
80 d->actionsconfig->setEnabled(true);
82 else
83 d->actionsconfig->setEnabled(false);
87 void KNotifyConfigWidget::save( )
89 if(d->currentElement)
90 d->actionsconfig->save( d->currentElement );
93 d->eventList->save();
94 emit changed(false);
96 //ask the notify daemon to reload the config
97 if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.knotify"))
99 QDBusInterface( QLatin1String("org.kde.knotify"), QLatin1String("/Notify"),
100 QLatin1String("org.kde.KNotify")).call( "reconfigure" );
104 KNotifyConfigWidget * KNotifyConfigWidget::configure( QWidget * parent, const QString & appname )
106 KDialog *dialog=new KDialog(parent);
107 dialog->setCaption(i18n("Configure Notifications"));
108 KNotifyConfigWidget *w=new KNotifyConfigWidget(dialog);
109 dialog->setMainWidget(w);
111 connect(dialog,SIGNAL(applyClicked()),w,SLOT(save()));
112 connect(dialog,SIGNAL(okClicked()),w,SLOT(save()));
113 connect(w,SIGNAL(changed(bool)) , dialog , SLOT(enableButtonApply(bool)));
115 w->setApplication(appname);
116 dialog->show();
117 return w;
120 void KNotifyConfigWidget::slotActionChanged()
122 emit changed( true ); //TODO
123 if(d->currentElement)
125 d->actionsconfig->save( d->currentElement );
126 d->eventList->updateCurrentItem();
131 #include "knotifyconfigwidget.moc"