33 #include <config-kleopatra.h>
59 #include "progresswidget/statusbarprogresswidget.h"
60 #include "progresswidget/progressdialog.h"
63 #include <KXMLGUIFactory>
64 #include <KApplication>
65 #include <KActionCollection>
66 #include <KLocalizedString>
67 #include <KStandardAction>
70 #include <KMessageBox>
71 #include <KStandardGuiItem>
72 #include <KShortcutsDialog>
73 #include <KEditToolBar>
74 #include <KAboutApplicationDialog>
77 #include <KActionMenu>
79 #include <QAbstractItemView>
80 #include <QApplication>
81 #include <QCloseEvent>
85 #include <QVBoxLayout>
87 #include <kleo/cryptobackendfactory.h>
88 #include <ui/cryptoconfigdialog.h>
89 #include <kleo/cryptoconfig.h>
90 #include <kleo/stl_util.h>
93 #include <boost/bind.hpp>
94 #include <boost/shared_ptr.hpp>
100 static const bool OS_WIN =
true;
105 using namespace Kleo;
106 using namespace Kleo::Commands;
107 using namespace boost;
108 using namespace GpgME;
112 static const KAboutData * aboutGpg4WinData() {
120 static const QString app = KGlobal::mainComponent().aboutData()->programName();
121 KGuiItem item = KStandardGuiItem::quit();
122 item.setText( i18nc(
"Quit [ApplicationName]",
"&Quit %1", app ) );
127 KGuiItem item = KStandardGuiItem::close();
128 item.setText( i18n(
"Only &Close Window" ) );
134 class MainWindow::Private {
135 friend class ::MainWindow;
142 template <
typename T>
143 void createAndStart() {
144 (
new T( this->currentView(), &this->controller ) )->start();
146 template <
typename T>
148 (
new T( view, &this->controller ) )->start();
150 template <
typename T>
152 (
new T( a, this->currentView(), &this->controller ) )->start();
154 template <
typename T>
156 (
new T( a, view, &this->controller ) )->start();
159 void closeAndQuit() {
160 const QString app = KGlobal::mainComponent().aboutData()->programName();
161 const int rc = KMessageBox::questionYesNoCancel(
q,
162 i18n(
"%1 may be used by other applications as a service.\n"
163 "You may instead want to close this window without exiting %1.", app ),
166 if ( rc == KMessageBox::Cancel )
172 if ( rc == KMessageBox::No )
175 void configureToolbars() {
176 KEditToolBar dlg(
q->factory() );
179 void editKeybindings() {
180 KShortcutsDialog::configure(
q->actionCollection(), KShortcutsEditor::LetterShortcutsAllowed );
181 updateSearchBarClickMessage();
184 void updateSearchBarClickMessage() {
185 const QString shortcutStr = focusToClickSearchAction->shortcut().toString();
186 ui.searchBar->updateClickMessage(shortcutStr);
190 createAndStart<SelfTestCommand>();
192 void configureBackend();
196 void gnupgLogViewer() {
198 KMessageBox::error(
q, i18n(
"Could not start the GnuPG Log Viewer (kwatchgnupg). "
199 "Please check your installation." ),
200 i18n(
"Error Starting KWatchGnuPG" ) );
203 void gnupgAdministrativeConsole() {
205 KMessageBox::error(
q, i18n(
"Could not start the GnuPG Administrative Console (kgpgconf). "
206 "Please check your installation." ),
207 i18n(
"Error Starting KGpgConf" ) );
210 void slotConfigCommitted();
212 if (
QMenu *
const menu = qobject_cast<QMenu*>(
q->factory()->container(
QLatin1String(
"listview_popup"),
q ) ) )
215 kDebug() <<
"no \"listview_popup\" <Menu> in kleopatra's ui.rc file";
218 void aboutGpg4Win() {
219 (
new KAboutApplicationDialog( aboutGpg4WinData(), KAboutApplicationDialog::HideKdeVersion|KAboutApplicationDialog::HideTranslators,
q ) )->show();
221 void slotFocusQuickSearch() {
222 ui.searchBar->lineEdit()->setFocus();
229 return ui.tabWidget.currentView();
241 KAction *focusToClickSearchAction;
256 tabWidget.connectSearchBar( searchBar );
260 KPIM::ProgressDialog * progressDialog =
new KPIM::ProgressDialog( q->
statusBar(),
q );
262 progressDialog->hide();
263 KPIM::StatusbarProgressWidget * statusBarProgressWidget
264 =
new KPIM::StatusbarProgressWidget( progressDialog, q->
statusBar() );
267 statusBarProgressWidget->show();
271 MainWindow::Private::Private(
MainWindow * qq )
280 AbstractKeyListModel * hierarchicalModel = AbstractKeyListModel::createHierarchicalKeyListModel( q );
286 controller.setFlatModel( flatModel );
287 controller.setHierarchicalModel( hierarchicalModel );
288 controller.setTabWidget( &ui.tabWidget );
290 ui.tabWidget.setFlatModel( flatModel );
291 ui.tabWidget.setHierarchicalModel( hierarchicalModel );
303 q->setAutoSaveSettings();
304 updateSearchBarClickMessage();
307 MainWindow::Private::~Private() {}
317 void MainWindow::Private::setupActions() {
319 KActionCollection *
const coll = q->actionCollection();
325 {
"tools_start_kwatchgnupg", i18n(
"GnuPG Log Viewer"),
QString(),
326 "kwatchgnupg",
q, SLOT(gnupgLogViewer()),
QString(),
false,
true },
329 {
"tools_start_kgpgconf", i18n(
"GnuPG Administrative Console"),
QString(),
330 "kgpgconf",
q, SLOT(gnupgLogViewer()),
QString(),
false,
true },
334 {
"configure_backend", i18n(
"Configure GnuPG Backend..."),
QString(),
335 0,
q, SLOT(configureBackend()),
QString(),
false,
true },
338 {
"settings_self_test", i18n(
"Perform Self-Test"),
QString(),
339 0,
q, SLOT(selfTest()),
QString(),
false,
true },
342 {
"help_about_gpg4win", i18n(
"About Gpg4win"),
QString(),
343 "gpg4win-compact",
q, SLOT(aboutGpg4Win()),
QString(),
false,
true },
351 action->setMenuRole( QAction::NoRole );
353 KStandardAction::close( q, SLOT(close()), coll );
354 KStandardAction::quit( q, SLOT(closeAndQuit()), coll );
355 KStandardAction::configureToolbars( q, SLOT(configureToolbars()), coll );
356 KStandardAction::keyBindings( q, SLOT(editKeybindings()), coll );
357 KStandardAction::preferences( qApp, SLOT(openOrRaiseConfigDialog()), coll );
359 focusToClickSearchAction =
new KAction(i18n(
"Set Focus to Quick Search"), q);
360 focusToClickSearchAction->setShortcut(
QKeySequence( Qt::ALT + Qt::Key_Q ) );
361 coll->addAction(
QLatin1String(
"focus_to_quickseach"), focusToClickSearchAction );
362 connect( focusToClickSearchAction, SIGNAL(triggered(
bool)), q, SLOT(slotFocusQuickSearch()) );
364 clipboadMenu->setMainWindow(q);
365 clipboadMenu->clipboardMenu()->setIcon(KIcon(
QLatin1String(
"edit-paste")));
366 clipboadMenu->clipboardMenu()->setDelayed(
false);
367 coll->addAction(
QLatin1String(
"clipboard_menu"), clipboadMenu->clipboardMenu());
369 q->createStandardStatusBarAction();
370 q->setStandardToolBarMenuEnabled(
true );
372 controller.createActions( coll );
374 ui.tabWidget.createActions( coll );
377 void MainWindow::Private::configureBackend() {
378 Kleo::CryptoConfig *
const config = Kleo::CryptoBackendFactory::instance()->config();
380 KMessageBox::error( q, i18n(
"Could not configure the cryptography backend (gpgconf tool not found)" ), i18n(
"Configuration Error" ) );
384 Kleo::CryptoConfigDialog dlg( config );
386 const int result = dlg.exec();
392 if ( result == QDialog::Accepted ) {
402 void MainWindow::Private::slotConfigCommitted() {
403 controller.updateConfig();
410 if ( d->controller.hasRunningCommands() ) {
411 if ( d->controller.shutdownWarningRequired() ) {
412 const int ret = KMessageBox::warningContinueCancel(
this, i18n(
"There are still some background operations ongoing. "
413 "These will be terminated when closing the window. "
415 i18n(
"Ongoing Background Tasks") );
416 if ( ret != KMessageBox::Continue ) {
421 d->controller.cancelCommands();
422 if ( d->controller.hasRunningCommands() ) {
427 connect( &d->controller, SIGNAL(commandsExecuting(
bool)), &ev, SLOT(quit()) );
429 kWarning( d->controller.hasRunningCommands() )
430 <<
"controller still has commands running, this may crash now...";
435 d->ui.tabWidget.saveViews( KGlobal::config().data() );
436 saveMainWindowSettings( KConfigGroup( KGlobal::config(), autoSaveGroup() ) );
445 KXmlGuiWindow::showEvent( e );
446 if ( d->firstShow ) {
447 d->ui.tabWidget.loadViews( KGlobal::config().data() );
448 d->firstShow =
false;
460 KXmlGuiWindow::hideEvent( e );
465 if ( !files.
empty() )
478 std::transform( urls.
begin(), end,
479 std::back_inserter( result ),
509 const unsigned int classification =
classify( files );
514 QAction *
const decryptVerify = mayBeAnyMessageType( classification ) ? menu.
addAction( i18n(
"Decrypt/Verify...") ) : 0 ;
515 if ( signEncrypt || decryptVerify )
518 QAction *
const importCerts = mayBeAnyCertStoreType( classification ) ? menu.
addAction( i18n(
"Import Certificates") ) : 0 ;
519 QAction *
const importCRLs = mayBeCertificateRevocationList( classification ) ? menu.
addAction( i18n(
"Import CRLs") ) : 0 ;
520 if ( importCerts || importCRLs )
523 if ( !signEncrypt && !decryptVerify && !importCerts && !importCRLs )
533 if ( chosen == signEncrypt )
535 else if ( chosen == decryptVerify )
537 else if ( chosen == importCerts )
539 else if ( chosen == importCRLs )
548 KXmlGuiWindow::readProperties(cg);
554 if (! cg.readEntry<
bool>(
"hidden",
false))
561 KXmlGuiWindow::saveProperties( cg );
562 cg.writeEntry(
"hidden",
isHidden() );
570 #include "moc_mainwindow_desktop.cpp"
static const char * flags[]
void showEvent(QShowEvent *e)
void dropEvent(QDropEvent *)
static KGuiItem KStandardGuiItem_quit()
const QMimeData * mimeData() const
static QStringList extract_local_files(const QMimeData *data)
QStatusBar * statusBar() const
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
void hideEvent(QHideEvent *e)
const QPoint & pos() const
iterator erase(iterator pos)
void dragEnterEvent(QDragEnterEvent *)
QDBusConnection sessionBus()
void acceptProposedAction()
void importCertificatesFromFile(const QStringList &files)
void readProperties(const KConfigGroup &cg)
int exec(QFlags< QEventLoop::ProcessEventsFlag > flags)
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
bool send(const QDBusMessage &message) const
void closeEvent(QCloseEvent *e)
void setDropAction(Qt::DropAction action)
void setCentralWidget(QWidget *widget)
void saveProperties(KConfigGroup &cg)
QString toLocalFile() const
unsigned int classify(const QString &filename)
QList< QUrl > urls() const
static bool can_decode_local_files(const QMimeData *data)
static KGuiItem KStandardGuiItem_close()
void make_actions_from_data(const action_data *data, unsigned int numData, KActionCollection *collection)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
MainWindow(QWidget *parent=0, Qt::WindowFlags flags=0)
void setSpacing(int spacing)