33 #include <config-kleopatra.h>
37 #ifndef QT_NO_SYSTEMTRAYICON
55 #include <KAboutApplicationDialog>
57 #include <KComponentData>
58 #include <KWindowSystem>
63 #include <QApplication>
67 #include <boost/shared_ptr.hpp>
68 #include <boost/bind.hpp>
72 using namespace boost;
74 using namespace Kleo::Commands;
75 using namespace Kleo::SmartCard;
77 class SysTrayIcon::Private {
78 friend class ::SysTrayIcon;
87 aboutDialog =
new KAboutApplicationDialog( KGlobal::mainComponent().aboutData() );
88 aboutDialog->setAttribute( Qt::WA_DeleteOnClose );
91 if ( aboutDialog->isVisible() )
97 void enableDisableActions() {
101 openCertificateManagerAction.setEnabled( !
q->mainWindow() || !
q->mainWindow()->isVisible() );
102 importClipboardAction.setEnabled( ImportCertificateFromClipboardCommand::canImportCurrentClipboard() );
103 encryptClipboardAction.setEnabled( EncryptClipboardCommand::canEncryptCurrentClipboard() );
104 openPGPSignClipboardAction.setEnabled( SignClipboardCommand::canSignCurrentClipboard() );
105 smimeSignClipboardAction.setEnabled( SignClipboardCommand::canSignCurrentClipboard() );
106 decryptVerifyClipboardAction.setEnabled( DecryptVerifyClipboardCommand::canDecryptVerifyCurrentClipboard() );
107 setInitialPinAction.setEnabled( anyCardHasNullPin );
108 learnCertificatesAction.setEnabled( anyCardCanLearnKeys );
110 q->setAttentionWanted( ( anyCardHasNullPin || anyCardCanLearnKeys ) && !
q->attentionWindow() );
113 void startCommand(
Command * cmd ) {
115 cmd->setParent(
q->mainWindow() );
119 void slotImportClipboard() {
123 void slotEncryptClipboard() {
127 void slotOpenPGPSignClipboard() {
131 void slotSMIMESignClipboard() {
135 void slotDecryptVerifyClipboard() {
139 void slotSetInitialPin() {
141 q->setAttentionWindow( cmd->
dialog() );
145 void slotLearnCertificates() {
147 q->setAttentionWindow( cmd->
dialog() );
152 bool anyCardHasNullPin;
153 bool anyCardCanLearnKeys;
156 QAction openCertificateManagerAction;
157 QAction configureAction;
161 QAction importClipboardAction;
162 QAction encryptClipboardAction;
163 QAction smimeSignClipboardAction;
164 QAction openPGPSignClipboardAction;
165 QAction decryptVerifyClipboardAction;
167 QAction updateCardStatusAction;
168 QAction setInitialPinAction;
169 QAction learnCertificatesAction;
171 QPointer<KAboutApplicationDialog> aboutDialog;
176 anyCardHasNullPin( false ),
177 anyCardCanLearnKeys( false ),
179 openCertificateManagerAction( i18n(
"&Open Certificate Manager..."),
q ),
180 configureAction( i18n(
"&Configure %1...", KGlobal::mainComponent().aboutData()->programName() ),
q ),
181 aboutAction( i18n(
"&About %1...", KGlobal::mainComponent().aboutData()->programName() ),
q ),
182 quitAction( i18n(
"&Shutdown Kleopatra"),
q ),
183 clipboardMenu( i18n(
"Clipboard" ) ),
184 importClipboardAction( i18n(
"Certificate Import"),
q ),
185 encryptClipboardAction( i18n(
"Encrypt..."),
q ),
186 smimeSignClipboardAction( i18n(
"S/MIME-Sign..."),
q ),
187 openPGPSignClipboardAction( i18n(
"OpenPGP-Sign..."),
q ),
188 decryptVerifyClipboardAction( i18n(
"Decrypt/Verify..."),
q ),
189 cardMenu( i18n(
"SmartCard") ),
190 updateCardStatusAction( i18n(
"Update Card Status"),
q ),
191 setInitialPinAction( i18n(
"Set NetKey v3 Initial PIN..."),
q ),
192 learnCertificatesAction( i18n(
"Learn NetKey v3 Card Certificates"),
q ),
195 q->setNormalIcon( KIcon( QLatin1String(
"kleopatra") ) );
196 q->setAttentionIcon( KIcon( QLatin1String(
"secure-card") ) );
213 connect( &openCertificateManagerAction, SIGNAL(triggered()), qApp, SLOT(openOrRaiseMainWindow()) );
214 connect( &configureAction, SIGNAL(triggered()), qApp, SLOT(openOrRaiseConfigDialog()) );
215 connect( &aboutAction, SIGNAL(triggered()),
q, SLOT(slotAbout()) );
216 connect( &quitAction, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()) );
217 connect( &importClipboardAction, SIGNAL(triggered()),
q, SLOT(slotImportClipboard()) );
218 connect( &encryptClipboardAction, SIGNAL(triggered()),
q, SLOT(slotEncryptClipboard()) );
219 connect( &smimeSignClipboardAction, SIGNAL(triggered()),
q, SLOT(slotSMIMESignClipboard()) );
220 connect( &openPGPSignClipboardAction, SIGNAL(triggered()),
q, SLOT(slotOpenPGPSignClipboard()) );
221 connect( &decryptVerifyClipboardAction, SIGNAL(triggered()),
q, SLOT(slotDecryptVerifyClipboard()) );
222 connect( &updateCardStatusAction, SIGNAL(triggered()), ReaderStatus::instance(), SLOT(updateStatus()) );
223 connect( &setInitialPinAction, SIGNAL(triggered()),
q, SLOT(slotSetInitialPin()) );
224 connect( &learnCertificatesAction, SIGNAL(triggered()),
q, SLOT(slotLearnCertificates()) );
226 connect( QApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)),
229 menu.addAction( &openCertificateManagerAction );
230 menu.addAction( &configureAction );
231 menu.addAction( &aboutAction );
233 menu.addMenu( &clipboardMenu );
234 clipboardMenu.addAction( &importClipboardAction );
235 clipboardMenu.addAction( &encryptClipboardAction );
236 clipboardMenu.addAction( &smimeSignClipboardAction );
237 clipboardMenu.addAction( &openPGPSignClipboardAction );
238 clipboardMenu.addAction( &decryptVerifyClipboardAction );
240 menu.addMenu( &cardMenu );
241 cardMenu.addAction( &updateCardStatusAction );
242 cardMenu.addAction( &setInitialPinAction );
243 cardMenu.addAction( &learnCertificatesAction );
245 menu.addAction( &quitAction );
247 q->setContextMenu( &menu );
250 SysTrayIcon::Private::~Private() {}
256 slotEnableDisableActions();
264 return static_cast<MainWindow*
>( SystemTrayIcon::mainWindow() );
268 return static_cast<QDialog*
>( SystemTrayIcon::attentionWindow() );
271 void SysTrayIcon::doActivated() {
273 if ( aw->isVisible() )
275 if ( d->anyCardHasNullPin )
276 d->slotSetInitialPin();
277 else if ( d->anyCardCanLearnKeys )
278 d->slotLearnCertificates();
286 if ( d->anyCardHasNullPin == on )
288 d->anyCardHasNullPin = on;
289 slotEnableDisableActions();
293 if ( d->anyCardCanLearnKeys == on )
295 d->anyCardCanLearnKeys = on;
296 slotEnableDisableActions();
299 void SysTrayIcon::slotEnableDisableActions() {
300 d->enableDisableActions();
303 #include "moc_systrayicon.cpp"
305 #endif // QT_NO_SYSTEMTRAYICON
virtual void slotEnableDisableActions()=0
MainWindow * mainWindow() const
void setAnyCardHasNullPin(bool)
static KleopatraApplication * instance()
void setAnyCardCanLearnKeys(bool)
SysTrayIcon(QObject *parent=0)
Exception-safe and convenient wrapper around QObject::blockSignals()
void toggleMainWindowVisibility()
QDialog * attentionWindow() const