33 #include <config-kleopatra.h>
62 #include "progresswidget/statusbarprogresswidget.h"
63 #include "progresswidget/progressdialog.h"
66 #include "declarativewidgetbase.h"
68 #include <KActionCollection>
72 #include <KStandardAction>
75 #include <KMessageBox>
76 #include <KStandardGuiItem>
77 #include <KStandardDirs>
80 #include <KShortcutsDialog>
81 #include <KEditToolBar>
83 #include <KAboutApplicationDialog>
89 #include <QWidgetAction>
90 #include <QApplication>
91 #include <QCloseEvent>
96 #include <QDeclarativeItem>
97 #include <QDeclarativeEngine>
98 #include <QDeclarativeContext>
100 #include <QHeaderView>
102 #include <kleo/stl_util.h>
103 #include <kleo/cryptobackendfactory.h>
104 #include <ui/cryptoconfigdialog.h>
105 #include <kleo/cryptoconfig.h>
107 #include <boost/bind.hpp>
108 #include <boost/shared_ptr.hpp>
113 static const bool OS_WIN =
true;
118 using namespace Kleo;
119 using namespace Kleo::Commands;
120 using namespace boost;
121 using namespace GpgME;
125 static const KAboutData * aboutGpg4WinData() {
132 class MainWindow::KeyTreeViewItem :
public DeclarativeWidgetBase<KeyTreeView,MainWindow,&MainWindow::registerKeyTreeView> {
135 explicit KeyTreeViewItem( QGraphicsItem * parent=0 )
137 ~KeyTreeViewItem() {}
140 class MainWindow::SearchBarItem :
public DeclarativeWidgetBase<SearchBar,MainWindow,&MainWindow::registerSearchBar> {
143 explicit SearchBarItem( QGraphicsItem * parent=0 )
149 static const QString app = KGlobal::mainComponent().aboutData()->programName();
150 KGuiItem item = KStandardGuiItem::quit();
151 item.setText( i18nc(
"Quit [ApplicationName]",
"&Quit %1", app ) );
156 KGuiItem item = KStandardGuiItem::close();
157 item.setText( i18n(
"Only &Close Window" ) );
161 class MainWindow::Private {
162 friend class ::MainWindow;
174 template <
typename T>
175 void createAndStart() {
176 this->start(
new T( this->currentView(), &this->controller ) );
178 template <
typename T>
179 void createAndStart( QAbstractItemView * view ) {
180 start(
new T( view, &this->controller ) );
182 template <
typename T>
183 void createAndStart(
const QStringList & a ) {
184 start(
new T( a, this->currentView(), &this->controller ) );
186 template <
typename T>
187 void createAndStart(
const QStringList & a, QAbstractItemView * view ) {
188 start(
new T( a, view, &this->controller ) );
191 void closeAndQuit() {
196 createAndStart<SelfTestCommand>();
198 void configureBackend();
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" ) );
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" ) );
215 void slotConfigCommitted();
216 void slotSearchBarTextChanged(
const QString & );
218 void aboutGpg4Win() {
219 (
new KAboutApplicationDialog( aboutGpg4WinData(), KAboutApplicationDialog::HideKdeVersion|KAboutApplicationDialog::HideTranslators,
q ) )->show();
224 void tryToConnectSearchBarToKeyTreeView() {
225 if ( searchBar && keyTreeView )
226 keyTreeView->connectSearchBar( searchBar );
229 QAbstractItemView * currentView()
const {
230 return controller.currentView();
234 QPointer<SearchBar> searchBar;
235 QPointer<KeyTreeView> keyTreeView;
240 MainWindow::Private::Private(
MainWindow * qq )
250 AbstractKeyListModel * hierarchicalModel = AbstractKeyListModel::createHierarchicalKeyListModel(
q );
256 controller.setFlatModel( flatModel );
257 controller.setHierarchicalModel( hierarchicalModel );
258 controller.setParentWidget(
q );
262 MainWindow::Private::~Private() {}
272 void MainWindow::Private::setupActions() {
274 KActionCollection *
const coll =
q->actionCollection();
278 {
"settings_self_test", i18n(
"Perform Self-Test"), QString(),
279 0,
q, SLOT(selfTest()), QString(),
false,
true },
284 KStandardAction::close(
q, SLOT(close()), coll );
285 KStandardAction::quit(
q, SLOT(closeAndQuit()), coll );
286 KStandardAction::preferences( qApp, SLOT(openOrRaiseConfigDialog()), coll );
288 controller.createActions( coll );
292 qmlRegisterType<KeyTreeViewItem>(
"org.kde.kleopatra", 2, 1,
"KeyTreeView" );
293 qmlRegisterType<SearchBarItem> (
"org.kde.kleopatra", 2, 1,
"SearchBar" );
295 engine()->rootContext()->setContextProperty( QLatin1String(
"application" ), QVariant::fromValue( static_cast<QObject*>(
this ) ) );
298 void MainWindow::registerKeyTreeView(
KeyTreeView * view ) {
303 QTreeView *
const v = view->
view();
304 v->setItemsExpandable(
false );
305 v->header()->setResizeMode( QHeaderView::Stretch );
307 d->controller.addView( v );
308 d->controller.setCurrentView( v );
309 d->keyTreeView = view;
310 d->tryToConnectSearchBarToKeyTreeView();
312 connect( v->model(), SIGNAL(rowsInserted(QModelIndex,
int,
int)),
314 connect( v->model(), SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
316 connect( v->model(), SIGNAL(modelReset()),
322 void MainWindow::registerSearchBar(
SearchBar * bar ) {
326 bar->setFixedHeight( 0 );
327 connect( bar, SIGNAL(stringFilterChanged(QString)),
328 this, SLOT(slotSearchBarTextChanged(QString)) );
329 d->tryToConnectSearchBarToKeyTreeView();
332 void MainWindow::Private::slotConfigCommitted() {
333 controller.updateConfig();
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. "
348 i18n(
"Ongoing Background Tasks") );
349 if ( ret != KMessageBox::Continue ) {
354 d->controller.cancelCommands();
355 if ( d->controller.hasRunningCommands() ) {
359 QTimer::singleShot( 100, &ev, SLOT(quit()) );
360 connect( &d->controller, SIGNAL(commandsExecuting(
bool)), &ev, SLOT(quit()) );
362 kWarning( d->controller.hasRunningCommands() )
363 <<
"controller still has commands running, this may crash now...";
371 static bool isSendingEvent =
false;
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 );
377 KDeclarativeFullScreenView::keyPressEvent( e );
382 if ( !files.empty() )
386 void MainWindow::Private::slotSearchBarTextChanged(
const QString & text ) {
387 if ( text.isEmpty() && searchBar && searchBar->isVisible() ) {
388 searchBar->setFixedHeight( 0 );
390 }
else if ( !text.isEmpty() && searchBar && !searchBar->isVisible() ) {
391 searchBar->setFixedHeight( searchBar->minimumSizeHint().height() );
393 searchBar->setFocus();
398 return (d->keyTreeView && d->keyTreeView->view()->model()->rowCount());
401 #include "moc_mainwindow_mobile.cpp"
402 #include "mainwindow_mobile.moc"
void certificatesAvailabilityChanged()
void keyPressEvent(QKeyEvent *)
void importCertificatesFromFile(const QStringList &files)
void setFlatModel(AbstractKeyListModel *model)
void closeEvent(QCloseEvent *e)
void setHierarchicalModel(AbstractKeyListModel *model)
static KGuiItem KStandardGuiItem_quit()
static KGuiItem KStandardGuiItem_close()
void make_actions_from_data(const action_data *data, unsigned int numData, KActionCollection *collection)
void setParentWidget(QWidget *widget)
MainWindow(QWidget *parent=0, Qt::WindowFlags flags=0)
bool certificatesAvailable() const