• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • dialog
kmknotify.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 2012, 2013 Montel Laurent <montel@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License
7  *
8  * This program 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
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of this program with any edition of
19  * the Qt library by Trolltech AS, Norway (or with modified versions
20  * of Qt that use the same license as Qt), and distribute linked
21  * combinations including the two. You must obey the GNU General
22  * Public License in all respects for all of the code used other than
23  * Qt. If you modify this file, you may extend this exception to
24  * your version of the file, but you are not obligated to do so. If
25  * you do not wish to do so, delete this exception statement from
26  * your version.
27  */
28 
29 #include "kmknotify.h"
30 #include "kmkernel.h"
31 
32 #include <QLabel>
33 #include <QVBoxLayout>
34 #include <QHBoxLayout>
35 #include <KComboBox>
36 #include <KNotifyConfigWidget>
37 #include <KLocale>
38 #include <KConfig>
39 #include <KStandardDirs>
40 #include <KSeparator>
41 
42 using namespace KMail;
43 
44 KMKnotify::KMKnotify( QWidget * parent )
45  :KDialog( parent ), m_changed( false )
46 {
47  setCaption( i18n("Notification") );
48  setButtons( Ok|Cancel );
49 
50  QWidget *page = new QWidget( this );
51  setMainWidget( page );
52 
53  QVBoxLayout *layout = new QVBoxLayout( page );
54  layout->setMargin( 0 );
55  m_comboNotify = new KComboBox( false );
56  m_comboNotify->setSizeAdjustPolicy( QComboBox::AdjustToContents );
57 
58  QHBoxLayout *hbox = new QHBoxLayout();
59  layout->addLayout( hbox );
60  hbox->addWidget( m_comboNotify, 10 );
61 
62  m_notifyWidget = new KNotifyConfigWidget( page );
63  layout->addWidget( m_notifyWidget );
64  m_comboNotify->setFocus();
65 
66  layout->addWidget(new KSeparator);
67 
68  connect( m_comboNotify, SIGNAL(activated(int)),
69  SLOT(slotComboChanged(int)) );
70  connect( this, SIGNAL(okClicked()), SLOT(slotOk()) );
71  connect( m_notifyWidget ,SIGNAL(changed(bool)) , this , SLOT(slotConfigChanged(bool)));
72  initCombobox();
73  readConfig();
74 }
75 
76 KMKnotify::~KMKnotify()
77 {
78  writeConfig();
79 }
80 
81 void KMKnotify::slotConfigChanged( bool changed )
82 {
83  m_changed = changed;
84 }
85 
86 void KMKnotify::slotComboChanged( int index )
87 {
88  QString text( m_comboNotify->itemData(index).toString() );
89  if ( m_changed ) {
90  m_notifyWidget->save();
91  m_changed = false;
92  }
93 
94  m_notifyWidget->setApplication( text );
95 }
96 
97 void KMKnotify::setCurrentNotification(const QString &name)
98 {
99  const int index = m_comboNotify->findData(name);
100  if (index>-1) {
101  m_comboNotify->setCurrentIndex(index);
102  slotComboChanged(index);
103  }
104 }
105 
106 void KMKnotify::initCombobox()
107 {
108 
109  QStringList lstNotify;
110  lstNotify<< QLatin1String( "kmail2/kmail2.notifyrc" );
111  lstNotify<< QLatin1String( "akonadi_maildispatcher_agent/akonadi_maildispatcher_agent.notifyrc" );
112  lstNotify<< QLatin1String( "akonadi_mailfilter_agent/akonadi_mailfilter_agent.notifyrc" );
113  lstNotify<< QLatin1String( "akonadi_archivemail_agent/akonadi_archivemail_agent.notifyrc" );
114  lstNotify<< QLatin1String( "akonadi_sendlater_agent/akonadi_sendlater_agent.notifyrc" );
115  lstNotify<< QLatin1String( "akonadi_newmailnotifier_agent/akonadi_newmailnotifier_agent.notifyrc" );
116  lstNotify<< QLatin1String( "akonadi_folderarchive_agent/akonadi_folderarchive_agent.notifyrc" );
117  lstNotify<< QLatin1String( "messageviewer/messageviewer.notifyrc" );
118  //TODO add other notifyrc here if necessary
119 
120  Q_FOREACH ( const QString& notify, lstNotify ) {
121  const QString fullPath = KStandardDirs::locate( "data", notify );
122 
123  if ( !fullPath.isEmpty() ) {
124  const int slash = fullPath.lastIndexOf( QLatin1Char('/') ) - 1;
125  const int slash2 = fullPath.lastIndexOf( QLatin1Char('/'), slash );
126  const QString appname= ( slash2 < 0 ) ? QString() : fullPath.mid( slash2+1 , slash-slash2 );
127  if ( !appname.isEmpty() ) {
128  KConfig config(fullPath, KConfig::NoGlobals, "data" );
129  KConfigGroup globalConfig( &config, QString::fromLatin1("Global") );
130  const QString icon = globalConfig.readEntry(QString::fromLatin1("IconName"), QString::fromLatin1("misc"));
131  const QString description = globalConfig.readEntry( QString::fromLatin1("Comment"), appname );
132  m_comboNotify->addItem( SmallIcon( icon ), description, appname );
133  }
134  }
135  }
136 
137  m_comboNotify->model()->sort(0);
138  if ( m_comboNotify->count() > 0 ) {
139  m_comboNotify->setCurrentIndex(0);
140  m_notifyWidget->setApplication( m_comboNotify->itemData( 0 ).toString() );
141  }
142 }
143 
144 void KMKnotify::slotOk()
145 {
146  if ( m_changed )
147  m_notifyWidget->save();
148 }
149 
150 void KMKnotify::readConfig()
151 {
152  KConfigGroup notifyDialog( KMKernel::self()->config(), "KMKnotifyDialog" );
153  const QSize size = notifyDialog.readEntry( "Size", QSize(600, 400) );
154  if ( size.isValid() ) {
155  resize( size );
156  }
157 }
158 
159 void KMKnotify::writeConfig()
160 {
161  KConfigGroup notifyDialog( KMKernel::self()->config(), "KMKnotifyDialog" );
162  notifyDialog.writeEntry( "Size", size() );
163  notifyDialog.sync();
164 }
165 
166 
167 #include "kmknotify.moc"
KMail::KMKnotify::KMKnotify
KMKnotify(QWidget *parent)
Definition: kmknotify.cpp:44
text
virtual QByteArray text(quint32 serialNumber) const =0
QWidget
kmknotify.h
KDialog
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1451
KMail::KMKnotify::setCurrentNotification
void setCurrentNotification(const QString &name)
Definition: kmknotify.cpp:97
KMail::KMKnotify::~KMKnotify
~KMKnotify()
Definition: kmknotify.cpp:76
kmkernel.h
KComboBox
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal