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

kleopatra

  • sources
  • kde-4.14
  • 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 <KLocalizedString>
70 #include <KStandardAction>
71 #include <KAction>
72 #include <KAboutData>
73 #include <KMessageBox>
74 #include <KStandardGuiItem>
75 #include <KLineEdit>
76 #if 0
77 #include <KShortcutsDialog>
78 #endif
79 #include <KAboutApplicationDialog>
80 #include <kdebug.h>
81 
82 #include <QTreeView>
83 #include <QApplication>
84 #include <QCloseEvent>
85 #include <QTimer>
86 #include <QProcess>
87 #include <QPointer>
88 #include <QVariant>
89 #include <QHeaderView>
90 
91 #include <kleo/stl_util.h>
92 #include <kleo/cryptobackendfactory.h>
93 #include <ui/cryptoconfigdialog.h>
94 #include <kleo/cryptoconfig.h>
95 
96 #ifndef Q_MOC_RUN
97 #include <boost/bind.hpp>
98 #include <boost/shared_ptr.hpp>
99 #endif
100 
101 #include <vector>
102 
103 #ifdef Q_OS_WIN32
104 static const bool OS_WIN = true;
105 #else
106 static const bool OS_WIN = false;
107 #endif
108 
109 using namespace Kleo;
110 using namespace Kleo::Commands;
111 using namespace boost;
112 using namespace GpgME;
113 
114 namespace {
115 
116  static const KAboutData * aboutGpg4WinData() {
117  static const AboutGpg4WinData data;
118  return &data;
119  }
120 
121 }
122 
123 class MainWindow::KeyTreeViewItem : public DeclarativeWidgetBase<KeyTreeView,MainWindow,&MainWindow::registerKeyTreeView> {
124  Q_OBJECT
125 public:
126  explicit KeyTreeViewItem( QGraphicsItem * parent=0 )
127  : DeclarativeWidgetBase<KeyTreeView,MainWindow,&MainWindow::registerKeyTreeView>( parent ) {}
128  ~KeyTreeViewItem() {}
129 };
130 
131 class MainWindow::SearchBarItem : public DeclarativeWidgetBase<SearchBar,MainWindow,&MainWindow::registerSearchBar> {
132  Q_OBJECT
133 public:
134  explicit SearchBarItem( QGraphicsItem * parent=0 )
135  : DeclarativeWidgetBase<SearchBar,MainWindow,&MainWindow::registerSearchBar>( parent ) {}
136  ~SearchBarItem() {}
137 };
138 
139 static KGuiItem KStandardGuiItem_quit() {
140  static const QString app = KGlobal::mainComponent().aboutData()->programName();
141  KGuiItem item = KStandardGuiItem::quit();
142  item.setText( i18nc( "Quit [ApplicationName]", "&Quit %1", app ) );
143  return item;
144 }
145 
146 static KGuiItem KStandardGuiItem_close() {
147  KGuiItem item = KStandardGuiItem::close();
148  item.setText( i18n("Only &Close Window" ) );
149  return item;
150 }
151 
152 class MainWindow::Private {
153  friend class ::MainWindow;
154  MainWindow * const q;
155 
156 public:
157  explicit Private( MainWindow * qq );
158  ~Private();
159 
160  void start( Command * c ) {
161  c->setParentWidget( q );
162  c->start();
163  }
164 
165  template <typename T>
166  void createAndStart() {
167  this->start( new T( this->currentView(), &this->controller ) );
168  }
169  template <typename T>
170  void createAndStart( QAbstractItemView * view ) {
171  start( new T( view, &this->controller ) );
172  }
173  template <typename T>
174  void createAndStart( const QStringList & a ) {
175  start( new T( a, this->currentView(), &this->controller ) );
176  }
177  template <typename T>
178  void createAndStart( const QStringList & a, QAbstractItemView * view ) {
179  start( new T( a, view, &this->controller ) );
180  }
181 
182  void closeAndQuit() {
183  qApp->quit();
184  }
185 
186  void selfTest() {
187  createAndStart<SelfTestCommand>();
188  }
189  void configureBackend();
190  void showHandbook();
191 
192  void gnupgLogViewer() {
193  if( !QProcess::startDetached( QLatin1String( "kwatchgnupg" ) ) )
194  KMessageBox::error( q, i18n( "Could not start the GnuPG Log Viewer (kwatchgnupg). "
195  "Please check your installation." ),
196  i18n( "Error Starting KWatchGnuPG" ) );
197  }
198 
199  void gnupgAdministrativeConsole() {
200  if( !QProcess::startDetached( QLatin1String( "kgpgconf" ) ) )
201  KMessageBox::error( q, i18n( "Could not start the GnuPG Administrative Console (kgpgconf). "
202  "Please check your installation." ),
203  i18n( "Error Starting KGpgConf" ) );
204  }
205 
206  void slotConfigCommitted();
207  void slotSearchBarTextChanged( const QString & );
208 
209  void aboutGpg4Win() {
210  ( new KAboutApplicationDialog( aboutGpg4WinData(), KAboutApplicationDialog::HideKdeVersion|KAboutApplicationDialog::HideTranslators, q ) )->show();
211  }
212 
213 private:
214  void setupActions();
215  void tryToConnectSearchBarToKeyTreeView() {
216  if ( searchBar && keyTreeView )
217  keyTreeView->connectSearchBar( searchBar );
218  }
219 
220  QAbstractItemView * currentView() const {
221  return controller.currentView();
222  }
223 
224 private:
225  QPointer<SearchBar> searchBar;
226  QPointer<KeyTreeView> keyTreeView;
227  Kleo::KeyListController controller;
228  bool firstShow : 1;
229 };
230 
231 MainWindow::Private::Private( MainWindow * qq )
232  : q( qq ),
233  searchBar(),
234  keyTreeView(),
235  controller( q ),
236  firstShow( true )
237 {
238  KDAB_SET_OBJECT_NAME( controller );
239 
240  AbstractKeyListModel * flatModel = AbstractKeyListModel::createFlatKeyListModel( q );
241  AbstractKeyListModel * hierarchicalModel = AbstractKeyListModel::createHierarchicalKeyListModel( q );
242 
243  KDAB_SET_OBJECT_NAME( flatModel );
244  KDAB_SET_OBJECT_NAME( hierarchicalModel );
245 
246 
247  controller.setFlatModel( flatModel );
248  controller.setHierarchicalModel( hierarchicalModel );
249  controller.setParentWidget( q );
250 
251 }
252 
253 MainWindow::Private::~Private() {}
254 
255 MainWindow::MainWindow( QWidget * parent )
256  : KDeclarativeFullScreenView( QLatin1String("kleopatra-mobile"), parent ), d( new Private( this ) )
257 {
258 }
259 
260 MainWindow::~MainWindow() {}
261 
262 
263 void MainWindow::Private::setupActions() {
264 
265  KActionCollection * const coll = q->actionCollection();
266 
267  const action_data action_data[] = {
268  // Settings menu
269  { "settings_self_test", i18n("Perform Self-Test"), QString(),
270  0, q, SLOT(selfTest()), QString(), false, true },
271  };
272 
273  make_actions_from_data( action_data, coll );
274 
275  KStandardAction::close( q, SLOT(close()), coll );
276  KStandardAction::quit( q, SLOT(closeAndQuit()), coll );
277  KStandardAction::preferences( qApp, SLOT(openOrRaiseConfigDialog()), coll );
278 
279  controller.createActions( coll );
280 }
281 
282 void MainWindow::doDelayedInit() {
283  qmlRegisterType<KeyTreeViewItem>( "org.kde.kleopatra", 2, 1, "KeyTreeView" );
284  qmlRegisterType<SearchBarItem> ( "org.kde.kleopatra", 2, 1, "SearchBar" );
285  d->setupActions();
286  engine()->rootContext()->setContextProperty( QLatin1String( "application" ), QVariant::fromValue( static_cast<QObject*>( this ) ) );
287 }
288 
289 void MainWindow::registerKeyTreeView( KeyTreeView * view ) {
290  if ( !view )
291  return;
292  view->setFlatModel( d->controller.flatModel() );
293  view->setHierarchicalModel( d->controller.hierarchicalModel() );
294  QTreeView * const v = view->view();
295  v->setItemsExpandable( false );
296  v->header()->setResizeMode( QHeaderView::Stretch );
297  v->header()->hide();
298  d->controller.addView( v );
299  d->controller.setCurrentView( v );
300  d->keyTreeView = view;
301  d->tryToConnectSearchBarToKeyTreeView();
302 
303  connect( v->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
304  SIGNAL(certificatesAvailabilityChanged()) );
305  connect( v->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
306  SIGNAL(certificatesAvailabilityChanged()) );
307  connect( v->model(), SIGNAL(modelReset()),
308  SIGNAL(certificatesAvailabilityChanged()) );
309 
310  emit certificatesAvailabilityChanged();
311 }
312 
313 void MainWindow::registerSearchBar( SearchBar * bar ) {
314  if ( !bar )
315  return;
316  d->searchBar = bar;
317  bar->setFixedHeight( 0 );
318  connect( bar, SIGNAL(stringFilterChanged(QString)),
319  this, SLOT(slotSearchBarTextChanged(QString)) );
320  d->tryToConnectSearchBarToKeyTreeView();
321 }
322 
323 void MainWindow::Private::slotConfigCommitted() {
324  controller.updateConfig();
325 }
326 
327 void MainWindow::closeEvent( QCloseEvent * e ) {
328 
329  d->closeAndQuit();
330 
331  // KMainWindow::closeEvent() insists on quitting the application,
332  // so do not let it touch the event...
333  kDebug();
334  if ( d->controller.hasRunningCommands() ) {
335  if ( d->controller.shutdownWarningRequired() ) {
336  const int ret = KMessageBox::warningContinueCancel( this, i18n("There are still some background operations ongoing. "
337  "These will be terminated when closing the window. "
338  "Proceed?"),
339  i18n("Ongoing Background Tasks") );
340  if ( ret != KMessageBox::Continue ) {
341  e->ignore();
342  return;
343  }
344  }
345  d->controller.cancelCommands();
346  if ( d->controller.hasRunningCommands() ) {
347  // wait for them to be finished:
348  setEnabled( false );
349  QEventLoop ev;
350  QTimer::singleShot( 100, &ev, SLOT(quit()) );
351  connect( &d->controller, SIGNAL(commandsExecuting(bool)), &ev, SLOT(quit()) );
352  ev.exec();
353  kWarning( d->controller.hasRunningCommands() )
354  << "controller still has commands running, this may crash now...";
355  setEnabled( true );
356  }
357  }
358  e->accept();
359 }
360 
361 void MainWindow::keyPressEvent( QKeyEvent * e ) {
362  static bool isSendingEvent = false;
363 
364  if ( !isSendingEvent && d->searchBar && !e->text().isEmpty() ) {
365  const struct guard { guard() { isSendingEvent = true; } ~guard() { isSendingEvent = false; } } guard;
366  QCoreApplication::sendEvent( d->searchBar->lineEdit(), e );
367  } else {
368  KDeclarativeFullScreenView::keyPressEvent( e );
369  }
370 }
371 
372 void MainWindow::importCertificatesFromFile( const QStringList & files ) {
373  if ( !files.empty() )
374  d->createAndStart<ImportCertificateFromFileCommand>( files );
375 }
376 
377 void MainWindow::Private::slotSearchBarTextChanged( const QString & text ) {
378  if ( text.isEmpty() && searchBar && searchBar->isVisible() ) {
379  searchBar->setFixedHeight( 0 );
380  searchBar->hide();
381  } else if ( !text.isEmpty() && searchBar && !searchBar->isVisible() ) {
382  searchBar->setFixedHeight( searchBar->minimumSizeHint().height() );
383  searchBar->show();
384  searchBar->setFocus();
385  }
386 }
387 
388 bool MainWindow::certificatesAvailable() const {
389  return (d->keyTreeView && d->keyTreeView->view()->model()->rowCount());
390 }
391 
392 #include "moc_mainwindow_mobile.cpp"
393 #include "mainwindow_mobile.moc"
QModelIndex
keytreeview.h
decryptverifyfilescommand.h
QWidget
keylistcontroller.h
MainWindow::certificatesAvailabilityChanged
void certificatesAvailabilityChanged()
QEventLoop
QAbstractItemView
Kleo::KeyTreeView
Definition: keytreeview.h:56
mainwindow_mobile.h
OS_WIN
static const bool OS_WIN
Definition: mainwindow_mobile.cpp:106
Kleo::KeyListController
Definition: keylistcontroller.h:55
QProcess::startDetached
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
QPointer< SearchBar >
classify.h
Kleo::SearchBar
Definition: searchbar.h:50
Kleo::ImportCertificateFromFileCommand
Definition: importcertificatefromfilecommand.h:42
Kleo::Command::start
void start()
Definition: commands/command.cpp:182
QGraphicsItem
AboutGpg4WinData
Definition: aboutdata.h:43
MainWindow::keyPressEvent
void keyPressEvent(QKeyEvent *)
Definition: mainwindow_mobile.cpp:361
MainWindow::importCertificatesFromFile
void importCertificatesFromFile(const QStringList &files)
Definition: mainwindow_desktop.cpp:464
QCloseEvent
KDeclarativeFullScreenView
QWidget::setEnabled
void setEnabled(bool)
d
#define d
Definition: adduseridcommand.cpp:89
tabwidget.h
Kleo::KeyTreeView::setFlatModel
void setFlatModel(AbstractKeyListModel *model)
Definition: keytreeview.cpp:205
QEvent::ignore
void ignore()
QList::empty
bool empty() const
action_data.h
QEventLoop::exec
int exec(QFlags< QEventLoop::ProcessEventsFlag > flags)
QString::isEmpty
bool isEmpty() const
QCoreApplication::sendEvent
bool sendEvent(QObject *receiver, QEvent *event)
keylistsortfilterproxymodel.h
aboutdata.h
QKeyEvent::text
QString text() const
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
MainWindow::closeEvent
void closeEvent(QCloseEvent *e)
Definition: mainwindow_desktop.cpp:406
KAboutData
importcrlcommand.h
QString
QWidget::hide
void hide()
selftestcommand.h
Kleo::KeyTreeView::setHierarchicalModel
void setHierarchicalModel(AbstractKeyListModel *model)
Definition: keytreeview.cpp:214
QStringList
gnupg-helper.h
Kleo::action_data
Definition: action_data.h:44
Kleo::AbstractKeyListModel
Definition: keylistmodel.h:49
QEvent::accept
void accept()
QVariant::fromValue
QVariant fromValue(const T &value)
keylistmodel.h
QKeyEvent
KStandardGuiItem_quit
static KGuiItem KStandardGuiItem_quit()
Definition: mainwindow_mobile.cpp:139
signencryptfilescommand.h
QLatin1String
QTreeView
KStandardGuiItem_close
static KGuiItem KStandardGuiItem_close()
Definition: mainwindow_mobile.cpp:146
QWidget::setFixedHeight
void setFixedHeight(int h)
MainWindow::doDelayedInit
void doDelayedInit()
Definition: mainwindow_mobile.cpp:282
searchbar.h
QHeaderView::setResizeMode
void setResizeMode(ResizeMode mode)
q
#define q
Definition: adduseridcommand.cpp:90
detail_p.h
QTreeView::header
QHeaderView * header() const
MainWindow::~MainWindow
~MainWindow()
Definition: mainwindow.cpp:100
Kleo::KeyTreeView::view
QTreeView * view() const
Definition: keytreeview.h:64
Kleo::make_actions_from_data
void make_actions_from_data(const action_data *data, unsigned int numData, KActionCollection *collection)
Definition: action_data.cpp:66
QAbstractItemView::model
QAbstractItemModel * model() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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
QTreeView::setItemsExpandable
void setItemsExpandable(bool enable)
MainWindow
Definition: kgpgconf/mainwindow.h:47
importcertificatefromfilecommand.h
MainWindow::certificatesAvailable
bool certificatesAvailable() const
QTimer::singleShot
singleShot
filedialog.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 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
  • 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