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

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
mainwindow_mobile.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  mainwindow_mobile.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2010 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "mainwindow_mobile.h"
36 
37 #include "aboutdata.h"
38 
39 #include "models/keylistmodel.h"
40 #include "models/keylistsortfilterproxymodel.h"
41 
42 #include "view/searchbar.h"
43 #if 0
44 #include "view/tabwidget.h"
45 #endif
46 #include "view/keytreeview.h"
47 #include "view/keylistcontroller.h"
48 
49 #include "commands/selftestcommand.h"
50 #include "commands/importcrlcommand.h"
51 #include "commands/importcertificatefromfilecommand.h"
52 #include "commands/decryptverifyfilescommand.h"
53 #include "commands/signencryptfilescommand.h"
54 
55 #include "utils/detail_p.h"
56 #include "utils/gnupg-helper.h"
57 #include "utils/action_data.h"
58 #include "utils/classify.h"
59 #include "utils/filedialog.h"
60 
61 // from libkdepim
62 #include "progresswidget/statusbarprogresswidget.h"
63 #include "progresswidget/progressdialog.h"
64 
65 // from mobileui
66 #include "declarativewidgetbase.h"
67 
68 #include <KActionCollection>
69 #include <KLocale>
70 #include <KTabWidget>
71 #include <KStatusBar>
72 #include <KStandardAction>
73 #include <KAction>
74 #include <KAboutData>
75 #include <KMessageBox>
76 #include <KStandardGuiItem>
77 #include <KStandardDirs>
78 #include <KLineEdit>
79 #if 0
80 #include <KShortcutsDialog>
81 #include <KEditToolBar>
82 #endif
83 #include <KAboutApplicationDialog>
84 #include <kdebug.h>
85 
86 #include <QTreeView>
87 #include <QFile>
88 #include <QToolBar>
89 #include <QWidgetAction>
90 #include <QApplication>
91 #include <QCloseEvent>
92 #include <QMenu>
93 #include <QTimer>
94 #include <QProcess>
95 #include <QPointer>
96 #include <QDeclarativeItem>
97 #include <QDeclarativeEngine>
98 #include <QDeclarativeContext>
99 #include <QVariant>
100 #include <QHeaderView>
101 
102 #include <kleo/stl_util.h>
103 #include <kleo/cryptobackendfactory.h>
104 #include <ui/cryptoconfigdialog.h>
105 #include <kleo/cryptoconfig.h>
106 
107 #include <boost/bind.hpp>
108 #include <boost/shared_ptr.hpp>
109 
110 #include <vector>
111 
112 #ifdef Q_OS_WIN32
113 static const bool OS_WIN = true;
114 #else
115 static const bool OS_WIN = false;
116 #endif
117 
118 using namespace Kleo;
119 using namespace Kleo::Commands;
120 using namespace boost;
121 using namespace GpgME;
122 
123 namespace {
124 
125  static const KAboutData * aboutGpg4WinData() {
126  static const AboutGpg4WinData data;
127  return &data;
128  }
129 
130 }
131 
132 class MainWindow::KeyTreeViewItem : public DeclarativeWidgetBase<KeyTreeView,MainWindow,&MainWindow::registerKeyTreeView> {
133  Q_OBJECT
134 public:
135  explicit KeyTreeViewItem( QGraphicsItem * parent=0 )
136  : DeclarativeWidgetBase<KeyTreeView,MainWindow,&MainWindow::registerKeyTreeView>( parent ) {}
137  ~KeyTreeViewItem() {}
138 };
139 
140 class MainWindow::SearchBarItem : public DeclarativeWidgetBase<SearchBar,MainWindow,&MainWindow::registerSearchBar> {
141  Q_OBJECT
142 public:
143  explicit SearchBarItem( QGraphicsItem * parent=0 )
144  : DeclarativeWidgetBase<SearchBar,MainWindow,&MainWindow::registerSearchBar>( parent ) {}
145  ~SearchBarItem() {}
146 };
147 
148 static KGuiItem KStandardGuiItem_quit() {
149  static const QString app = KGlobal::mainComponent().aboutData()->programName();
150  KGuiItem item = KStandardGuiItem::quit();
151  item.setText( i18nc( "Quit [ApplicationName]", "&Quit %1", app ) );
152  return item;
153 }
154 
155 static KGuiItem KStandardGuiItem_close() {
156  KGuiItem item = KStandardGuiItem::close();
157  item.setText( i18n("Only &Close Window" ) );
158  return item;
159 }
160 
161 class MainWindow::Private {
162  friend class ::MainWindow;
163  MainWindow * const q;
164 
165 public:
166  explicit Private( MainWindow * qq );
167  ~Private();
168 
169  void start( Command * c ) {
170  c->setParentWidget( q );
171  c->start();
172  }
173 
174  template <typename T>
175  void createAndStart() {
176  this->start( new T( this->currentView(), &this->controller ) );
177  }
178  template <typename T>
179  void createAndStart( QAbstractItemView * view ) {
180  start( new T( view, &this->controller ) );
181  }
182  template <typename T>
183  void createAndStart( const QStringList & a ) {
184  start( new T( a, this->currentView(), &this->controller ) );
185  }
186  template <typename T>
187  void createAndStart( const QStringList & a, QAbstractItemView * view ) {
188  start( new T( a, view, &this->controller ) );
189  }
190 
191  void closeAndQuit() {
192  qApp->quit();
193  }
194 
195  void selfTest() {
196  createAndStart<SelfTestCommand>();
197  }
198  void configureBackend();
199  void showHandbook();
200 
201  void gnupgLogViewer() {
202  if( !QProcess::startDetached( QLatin1String( "kwatchgnupg" ) ) )
203  KMessageBox::error( q, i18n( "Could not start the GnuPG Log Viewer (kwatchgnupg). "
204  "Please check your installation." ),
205  i18n( "Error Starting KWatchGnuPG" ) );
206  }
207 
208  void gnupgAdministrativeConsole() {
209  if( !QProcess::startDetached( QLatin1String( "kgpgconf" ) ) )
210  KMessageBox::error( q, i18n( "Could not start the GnuPG Administrative Console (kgpgconf). "
211  "Please check your installation." ),
212  i18n( "Error Starting KGpgConf" ) );
213  }
214 
215  void slotConfigCommitted();
216  void slotSearchBarTextChanged( const QString & );
217 
218  void aboutGpg4Win() {
219  ( new KAboutApplicationDialog( aboutGpg4WinData(), KAboutApplicationDialog::HideKdeVersion|KAboutApplicationDialog::HideTranslators, q ) )->show();
220  }
221 
222 private:
223  void setupActions();
224  void tryToConnectSearchBarToKeyTreeView() {
225  if ( searchBar && keyTreeView )
226  keyTreeView->connectSearchBar( searchBar );
227  }
228 
229  QAbstractItemView * currentView() const {
230  return controller.currentView();
231  }
232 
233 private:
234  QPointer<SearchBar> searchBar;
235  QPointer<KeyTreeView> keyTreeView;
236  Kleo::KeyListController controller;
237  bool firstShow : 1;
238 };
239 
240 MainWindow::Private::Private( MainWindow * qq )
241  : q( qq ),
242  searchBar(),
243  keyTreeView(),
244  controller( q ),
245  firstShow( true )
246 {
247  KDAB_SET_OBJECT_NAME( controller );
248 
249  AbstractKeyListModel * flatModel = AbstractKeyListModel::createFlatKeyListModel( q );
250  AbstractKeyListModel * hierarchicalModel = AbstractKeyListModel::createHierarchicalKeyListModel( q );
251 
252  KDAB_SET_OBJECT_NAME( flatModel );
253  KDAB_SET_OBJECT_NAME( hierarchicalModel );
254 
255 
256  controller.setFlatModel( flatModel );
257  controller.setHierarchicalModel( hierarchicalModel );
258  controller.setParentWidget( q );
259 
260 }
261 
262 MainWindow::Private::~Private() {}
263 
264 MainWindow::MainWindow( QWidget * parent )
265  : KDeclarativeFullScreenView( QLatin1String("kleopatra-mobile"), parent ), d( new Private( this ) )
266 {
267 }
268 
269 MainWindow::~MainWindow() {}
270 
271 
272 void MainWindow::Private::setupActions() {
273 
274  KActionCollection * const coll = q->actionCollection();
275 
276  const action_data action_data[] = {
277  // Settings menu
278  { "settings_self_test", i18n("Perform Self-Test"), QString(),
279  0, q, SLOT(selfTest()), QString(), false, true },
280  };
281 
282  make_actions_from_data( action_data, coll );
283 
284  KStandardAction::close( q, SLOT(close()), coll );
285  KStandardAction::quit( q, SLOT(closeAndQuit()), coll );
286  KStandardAction::preferences( qApp, SLOT(openOrRaiseConfigDialog()), coll );
287 
288  controller.createActions( coll );
289 }
290 
291 void MainWindow::doDelayedInit() {
292  qmlRegisterType<KeyTreeViewItem>( "org.kde.kleopatra", 2, 1, "KeyTreeView" );
293  qmlRegisterType<SearchBarItem> ( "org.kde.kleopatra", 2, 1, "SearchBar" );
294  d->setupActions();
295  engine()->rootContext()->setContextProperty( QLatin1String( "application" ), QVariant::fromValue( static_cast<QObject*>( this ) ) );
296 }
297 
298 void MainWindow::registerKeyTreeView( KeyTreeView * view ) {
299  if ( !view )
300  return;
301  view->setFlatModel( d->controller.flatModel() );
302  view->setHierarchicalModel( d->controller.hierarchicalModel() );
303  QTreeView * const v = view->view();
304  v->setItemsExpandable( false );
305  v->header()->setResizeMode( QHeaderView::Stretch );
306  v->header()->hide();
307  d->controller.addView( v );
308  d->controller.setCurrentView( v );
309  d->keyTreeView = view;
310  d->tryToConnectSearchBarToKeyTreeView();
311 
312  connect( v->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
313  SIGNAL(certificatesAvailabilityChanged()) );
314  connect( v->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
315  SIGNAL(certificatesAvailabilityChanged()) );
316  connect( v->model(), SIGNAL(modelReset()),
317  SIGNAL(certificatesAvailabilityChanged()) );
318 
319  emit certificatesAvailabilityChanged();
320 }
321 
322 void MainWindow::registerSearchBar( SearchBar * bar ) {
323  if ( !bar )
324  return;
325  d->searchBar = bar;
326  bar->setFixedHeight( 0 );
327  connect( bar, SIGNAL(stringFilterChanged(QString)),
328  this, SLOT(slotSearchBarTextChanged(QString)) );
329  d->tryToConnectSearchBarToKeyTreeView();
330 }
331 
332 void MainWindow::Private::slotConfigCommitted() {
333  controller.updateConfig();
334 }
335 
336 void MainWindow::closeEvent( QCloseEvent * e ) {
337 
338  d->closeAndQuit();
339 
340  // KMainWindow::closeEvent() insists on quitting the application,
341  // so do not let it touch the event...
342  kDebug();
343  if ( d->controller.hasRunningCommands() ) {
344  if ( d->controller.shutdownWarningRequired() ) {
345  const int ret = KMessageBox::warningContinueCancel( this, i18n("There are still some background operations ongoing. "
346  "These will be terminated when closing the window. "
347  "Proceed?"),
348  i18n("Ongoing Background Tasks") );
349  if ( ret != KMessageBox::Continue ) {
350  e->ignore();
351  return;
352  }
353  }
354  d->controller.cancelCommands();
355  if ( d->controller.hasRunningCommands() ) {
356  // wait for them to be finished:
357  setEnabled( false );
358  QEventLoop ev;
359  QTimer::singleShot( 100, &ev, SLOT(quit()) );
360  connect( &d->controller, SIGNAL(commandsExecuting(bool)), &ev, SLOT(quit()) );
361  ev.exec();
362  kWarning( d->controller.hasRunningCommands() )
363  << "controller still has commands running, this may crash now...";
364  setEnabled( true );
365  }
366  }
367  e->accept();
368 }
369 
370 void MainWindow::keyPressEvent( QKeyEvent * e ) {
371  static bool isSendingEvent = false;
372 
373  if ( !isSendingEvent && d->searchBar && !e->text().isEmpty() ) {
374  const struct guard { guard() { isSendingEvent = true; } ~guard() { isSendingEvent = false; } } guard;
375  QCoreApplication::sendEvent( d->searchBar->lineEdit(), e );
376  } else {
377  KDeclarativeFullScreenView::keyPressEvent( e );
378  }
379 }
380 
381 void MainWindow::importCertificatesFromFile( const QStringList & files ) {
382  if ( !files.empty() )
383  d->createAndStart<ImportCertificateFromFileCommand>( files );
384 }
385 
386 void MainWindow::Private::slotSearchBarTextChanged( const QString & text ) {
387  if ( text.isEmpty() && searchBar && searchBar->isVisible() ) {
388  searchBar->setFixedHeight( 0 );
389  searchBar->hide();
390  } else if ( !text.isEmpty() && searchBar && !searchBar->isVisible() ) {
391  searchBar->setFixedHeight( searchBar->minimumSizeHint().height() );
392  searchBar->show();
393  searchBar->setFocus();
394  }
395 }
396 
397 bool MainWindow::certificatesAvailable() const {
398  return (d->keyTreeView && d->keyTreeView->view()->model()->rowCount());
399 }
400 
401 #include "moc_mainwindow_mobile.cpp"
402 #include "mainwindow_mobile.moc"
keytreeview.h
decryptverifyfilescommand.h
keylistcontroller.h
MainWindow::certificatesAvailabilityChanged
void certificatesAvailabilityChanged()
Kleo::KeyTreeView
Definition: keytreeview.h:54
mainwindow_mobile.h
OS_WIN
static const bool OS_WIN
Definition: mainwindow_mobile.cpp:115
Kleo::KeyListController
Definition: keylistcontroller.h:55
QWidget
classify.h
Kleo::SearchBar
Definition: searchbar.h:48
Kleo::ImportCertificateFromFileCommand
Definition: importcertificatefromfilecommand.h:42
Kleo::Command::start
void start()
Definition: commands/command.cpp:182
AboutGpg4WinData
Definition: aboutdata.h:43
MainWindow::keyPressEvent
void keyPressEvent(QKeyEvent *)
Definition: mainwindow_mobile.cpp:370
MainWindow::importCertificatesFromFile
void importCertificatesFromFile(const QStringList &files)
Definition: mainwindow_desktop.cpp:438
KDeclarativeFullScreenView
d
#define d
Definition: adduseridcommand.cpp:90
tabwidget.h
Kleo::KeyTreeView::setFlatModel
void setFlatModel(AbstractKeyListModel *model)
Definition: keytreeview.cpp:205
action_data.h
keylistsortfilterproxymodel.h
aboutdata.h
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
MainWindow::closeEvent
void closeEvent(QCloseEvent *e)
Definition: mainwindow_desktop.cpp:380
KAboutData
importcrlcommand.h
selftestcommand.h
Kleo::KeyTreeView::setHierarchicalModel
void setHierarchicalModel(AbstractKeyListModel *model)
Definition: keytreeview.cpp:214
gnupg-helper.h
Kleo::action_data
Definition: action_data.h:44
Kleo::AbstractKeyListModel
Definition: keylistmodel.h:49
keylistmodel.h
KStandardGuiItem_quit
static KGuiItem KStandardGuiItem_quit()
Definition: mainwindow_mobile.cpp:148
signencryptfilescommand.h
KStandardGuiItem_close
static KGuiItem KStandardGuiItem_close()
Definition: mainwindow_mobile.cpp:155
MainWindow::doDelayedInit
void doDelayedInit()
Definition: mainwindow_mobile.cpp:291
searchbar.h
q
#define q
Definition: adduseridcommand.cpp:91
detail_p.h
MainWindow::~MainWindow
~MainWindow()
Definition: mainwindow.cpp:100
Kleo::KeyTreeView::view
QTreeView * view() const
Definition: keytreeview.h:62
Kleo::make_actions_from_data
void make_actions_from_data(const action_data *data, unsigned int numData, KActionCollection *collection)
Definition: action_data.cpp:66
Kleo::Command::setParentWidget
void setParentWidget(QWidget *widget)
Definition: commands/command.cpp:136
MainWindow::MainWindow
MainWindow(QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: mainwindow.cpp:52
Kleo::Command
Definition: commands/command.h:58
MainWindow
Definition: kgpgconf/mainwindow.h:47
importcertificatefromfilecommand.h
MainWindow::certificatesAvailable
bool certificatesAvailable() const
filedialog.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • 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