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

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • dialog
kmknotify.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015 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 <QVBoxLayout>
33 #include <QHBoxLayout>
34 #include <KComboBox>
35 #include <KNotifyConfigWidget>
36 #include <KLocalizedString>
37 #include <KConfig>
38 #include <KStandardDirs>
39 #include <KSeparator>
40 
41 using namespace KMail;
42 
43 KMKnotify::KMKnotify( QWidget * parent )
44  :KDialog( parent ), m_changed( false )
45 {
46  setCaption( i18n("Notification") );
47  setButtons( Ok|Cancel );
48 
49  QWidget *page = new QWidget( this );
50  setMainWidget( page );
51 
52  QVBoxLayout *layout = new QVBoxLayout( page );
53  layout->setMargin( 0 );
54  m_comboNotify = new KComboBox( false );
55  m_comboNotify->setSizeAdjustPolicy( QComboBox::AdjustToContents );
56 
57  QHBoxLayout *hbox = new QHBoxLayout();
58  layout->addLayout( hbox );
59  hbox->addWidget( m_comboNotify, 10 );
60 
61  m_notifyWidget = new KNotifyConfigWidget( page );
62  layout->addWidget( m_notifyWidget );
63  m_comboNotify->setFocus();
64 
65  layout->addWidget(new KSeparator);
66 
67  connect( m_comboNotify, SIGNAL(activated(int)),
68  SLOT(slotComboChanged(int)) );
69  connect( this, SIGNAL(okClicked()), SLOT(slotOk()) );
70  connect( m_notifyWidget ,SIGNAL(changed(bool)) , this , SLOT(slotConfigChanged(bool)));
71  initCombobox();
72  readConfig();
73 }
74 
75 KMKnotify::~KMKnotify()
76 {
77  writeConfig();
78 }
79 
80 void KMKnotify::slotConfigChanged( bool changed )
81 {
82  m_changed = changed;
83 }
84 
85 void KMKnotify::slotComboChanged( int index )
86 {
87  QString text( m_comboNotify->itemData(index).toString() );
88  if ( m_changed ) {
89  m_notifyWidget->save();
90  m_changed = false;
91  }
92 
93  m_notifyWidget->setApplication( text );
94 }
95 
96 void KMKnotify::setCurrentNotification(const QString &name)
97 {
98  const int index = m_comboNotify->findData(name);
99  if (index>-1) {
100  m_comboNotify->setCurrentIndex(index);
101  slotComboChanged(index);
102  }
103 }
104 
105 void KMKnotify::initCombobox()
106 {
107 
108  QStringList lstNotify;
109  lstNotify<< QLatin1String( "kmail2/kmail2.notifyrc" );
110  lstNotify<< QLatin1String( "akonadi_maildispatcher_agent/akonadi_maildispatcher_agent.notifyrc" );
111  lstNotify<< QLatin1String( "akonadi_mailfilter_agent/akonadi_mailfilter_agent.notifyrc" );
112  lstNotify<< QLatin1String( "akonadi_archivemail_agent/akonadi_archivemail_agent.notifyrc" );
113  lstNotify<< QLatin1String( "akonadi_sendlater_agent/akonadi_sendlater_agent.notifyrc" );
114  lstNotify<< QLatin1String( "akonadi_newmailnotifier_agent/akonadi_newmailnotifier_agent.notifyrc" );
115  lstNotify<< QLatin1String( "akonadi_followupreminder_agent/akonadi_followupreminder_agent.notifyrc" );
116  lstNotify<< QLatin1String( "messageviewer/messageviewer.notifyrc" );
117  //TODO add other notifyrc here if necessary
118 
119  Q_FOREACH ( const QString& notify, lstNotify ) {
120  const QString fullPath = KStandardDirs::locate( "data", notify );
121 
122  if ( !fullPath.isEmpty() ) {
123  const int slash = fullPath.lastIndexOf( QLatin1Char('/') ) - 1;
124  const int slash2 = fullPath.lastIndexOf( QLatin1Char('/'), slash );
125  const QString appname= ( slash2 < 0 ) ? QString() : fullPath.mid( slash2+1 , slash-slash2 );
126  if ( !appname.isEmpty() ) {
127  KConfig config(fullPath, KConfig::NoGlobals, "data" );
128  KConfigGroup globalConfig( &config, QString::fromLatin1("Global") );
129  const QString icon = globalConfig.readEntry(QString::fromLatin1("IconName"), QString::fromLatin1("misc"));
130  const QString description = globalConfig.readEntry( QString::fromLatin1("Comment"), appname );
131  m_comboNotify->addItem( SmallIcon( icon ), description, appname );
132  }
133  }
134  }
135 
136  m_comboNotify->model()->sort(0);
137  if ( m_comboNotify->count() > 0 ) {
138  m_comboNotify->setCurrentIndex(0);
139  m_notifyWidget->setApplication( m_comboNotify->itemData( 0 ).toString() );
140  }
141 }
142 
143 void KMKnotify::slotOk()
144 {
145  if ( m_changed )
146  m_notifyWidget->save();
147 }
148 
149 void KMKnotify::readConfig()
150 {
151  KConfigGroup notifyDialog( KMKernel::self()->config(), "KMKnotifyDialog" );
152  const QSize size = notifyDialog.readEntry( "Size", QSize(600, 400) );
153  if ( size.isValid() ) {
154  resize( size );
155  }
156 }
157 
158 void KMKnotify::writeConfig()
159 {
160  KConfigGroup notifyDialog( KMKernel::self()->config(), "KMKnotifyDialog" );
161  notifyDialog.writeEntry( "Size", size() );
162  notifyDialog.sync();
163 }
164 
165 
QWidget
QSize::isValid
bool isValid() const
KMail::KMKnotify::KMKnotify
KMKnotify(QWidget *parent)
Definition: kmknotify.cpp:43
text
virtual QByteArray text(quint32 serialNumber) const =0
QHBoxLayout
kmknotify.h
KDialog
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1471
QString::lastIndexOf
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KMail::KMKnotify::setCurrentNotification
void setCurrentNotification(const QString &name)
Definition: kmknotify.cpp:96
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
KMail::KMKnotify::~KMKnotify
~KMKnotify()
Definition: kmknotify.cpp:75
QString::isEmpty
bool isEmpty() const
QVBoxLayout
QString
QLayout::setMargin
void setMargin(int margin)
QStringList
QSize
QLatin1Char
kmkernel.h
QString::mid
QString mid(int position, int n) const
QLatin1String
KComboBox
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 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
  • pimprint

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