33 #include <config-kleopatra.h>
37 #ifndef QT_NO_SYSTEMTRAYICON
55 #include <KLocalizedString>
56 #include <KAboutApplicationDialog>
58 #include <KActionMenu>
63 #include <QApplication>
68 #include <boost/shared_ptr.hpp>
69 #include <boost/bind.hpp>
74 using namespace boost;
76 using namespace Kleo::Commands;
77 using namespace Kleo::SmartCard;
79 class SysTrayIcon::Private {
80 friend class ::SysTrayIcon;
89 aboutDialog =
new KAboutApplicationDialog( KGlobal::mainComponent().aboutData() );
90 aboutDialog->setAttribute( Qt::WA_DeleteOnClose );
93 if ( aboutDialog->isVisible() )
99 void enableDisableActions() {
103 openCertificateManagerAction.setEnabled( !
q->mainWindow() || !
q->mainWindow()->isVisible() );
104 setInitialPinAction.setEnabled( anyCardHasNullPin );
105 learnCertificatesAction.setEnabled( anyCardCanLearnKeys );
107 q->setAttentionWanted( ( anyCardHasNullPin || anyCardCanLearnKeys ) && !
q->attentionWindow() );
110 void slotSetInitialPin() {
112 q->setAttentionWindow( cmd->
dialog() );
116 void slotLearnCertificates() {
118 q->setAttentionWindow( cmd->
dialog() );
121 void startCommand(
Command * cmd ) {
128 bool anyCardHasNullPin;
129 bool anyCardCanLearnKeys;
132 QAction openCertificateManagerAction;
140 QAction updateCardStatusAction;
142 QAction learnCertificatesAction;
149 anyCardHasNullPin( false ),
150 anyCardCanLearnKeys( false ),
152 openCertificateManagerAction( i18n(
"&Open Certificate Manager..."),
q ),
153 configureAction( i18n(
"&Configure %1...", KGlobal::mainComponent().aboutData()->programName() ),
q ),
154 aboutAction( i18n(
"&About %1...", KGlobal::mainComponent().aboutData()->programName() ),
q ),
155 quitAction( i18n(
"&Shutdown Kleopatra"),
q ),
157 cardMenu( i18n(
"SmartCard") ),
158 updateCardStatusAction( i18n(
"Update Card Status"),
q ),
159 setInitialPinAction( i18n(
"Set NetKey v3 Initial PIN..."),
q ),
160 learnCertificatesAction( i18n(
"Learn NetKey v3 Card Certificates"),
q ),
176 connect( &openCertificateManagerAction, SIGNAL(triggered()), qApp, SLOT(openOrRaiseMainWindow()) );
177 connect( &configureAction, SIGNAL(triggered()), qApp, SLOT(openOrRaiseConfigDialog()) );
178 connect( &aboutAction, SIGNAL(triggered()),
q, SLOT(slotAbout()) );
180 connect( &updateCardStatusAction, SIGNAL(triggered()), ReaderStatus::instance(), SLOT(updateStatus()) );
181 connect( &setInitialPinAction, SIGNAL(triggered()),
q, SLOT(slotSetInitialPin()) );
182 connect( &learnCertificatesAction, SIGNAL(triggered()),
q, SLOT(slotLearnCertificates()) );
187 menu.addAction( &openCertificateManagerAction );
188 menu.addAction( &configureAction );
189 menu.addAction( &aboutAction );
191 menu.addMenu( clipboardMenu.clipboardMenu()->menu() );
193 menu.addMenu( &cardMenu );
194 cardMenu.addAction( &updateCardStatusAction );
195 cardMenu.addAction( &setInitialPinAction );
196 cardMenu.addAction( &learnCertificatesAction );
198 menu.addAction( &quitAction );
200 q->setContextMenu( &menu );
201 clipboardMenu.setMainWindow(
q->mainWindow());
204 SysTrayIcon::Private::~Private() {}
210 slotEnableDisableActions();
218 return static_cast<MainWindow*
>( SystemTrayIcon::mainWindow() );
222 return static_cast<QDialog*
>( SystemTrayIcon::attentionWindow() );
225 void SysTrayIcon::doActivated() {
227 if ( aw->isVisible() )
229 if ( d->anyCardHasNullPin )
230 d->slotSetInitialPin();
231 else if ( d->anyCardCanLearnKeys )
232 d->slotLearnCertificates();
240 if ( d->anyCardHasNullPin == on )
242 d->anyCardHasNullPin = on;
243 slotEnableDisableActions();
247 if ( d->anyCardCanLearnKeys == on )
249 d->anyCardCanLearnKeys = on;
250 slotEnableDisableActions();
253 void SysTrayIcon::slotEnableDisableActions() {
254 d->enableDisableActions();
257 #include "moc_systrayicon.cpp"
259 #endif // QT_NO_SYSTEMTRAYICON
virtual void slotEnableDisableActions()=0
MainWindow * mainWindow() const
void setAnyCardHasNullPin(bool)
static KleopatraApplication * instance()
QCoreApplication * instance()
void setAnyCardCanLearnKeys(bool)
void setParent(QObject *parent)
SysTrayIcon(QObject *parent=0)
Exception-safe and convenient wrapper around QObject::blockSignals()
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void toggleMainWindowVisibility()
QDialog * attentionWindow() const