33 #include <config-kleopatra.h>
40 #include "libkleo/kleo/cryptobackendfactory.h"
41 #include "libkleo/kleo/cryptoconfig.h"
46 #include <kmessagebox.h>
48 #include <kapplication.h>
50 #include <kactioncollection.h>
51 #include <kstandardaction.h>
54 #include <kedittoolbar.h>
55 #include <kshortcutsdialog.h>
64 #include <QTextStream>
66 #include <QFileDialog>
77 setCentralWidget( mCentralWidget );
79 mWatcher =
new KProcess;
80 connect( mWatcher, SIGNAL(finished(
int,QProcess::ExitStatus)),
81 this, SLOT(slotWatcherExited(
int,QProcess::ExitStatus)) );
83 connect( mWatcher, SIGNAL(readyReadStandardOutput()),
84 this, SLOT(slotReadStdout()) );
89 connect( mSysTray, SIGNAL(quitSelected()),
90 this, SLOT(slotQuit()) );
92 setAutoSaveSettings();
100 void KWatchGnuPGMainWindow::slotClear()
102 mCentralWidget->
clear();
103 mCentralWidget->
message( i18n(
"[%1] Log cleared", QDateTime::currentDateTime().toString(Qt::ISODate) ) );
106 void KWatchGnuPGMainWindow::createActions()
108 KAction *action = actionCollection()->addAction( QLatin1String(
"clear_log") );
109 action->setIcon( KIcon(QLatin1String(
"edit-clear-history")) );
110 action->setText( i18n(
"C&lear History") );
111 connect(action, SIGNAL(triggered()), SLOT(slotClear()));
112 action->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_L));
113 (void)KStandardAction::saveAs(
this, SLOT(slotSaveAs()), actionCollection() );
114 (void)KStandardAction::close(
this, SLOT(close()), actionCollection() );
115 (void)KStandardAction::quit(
this, SLOT(slotQuit()), actionCollection() );
116 (void)KStandardAction::preferences(
this, SLOT(slotConfigure()), actionCollection() );
117 ( void )KStandardAction::keyBindings(
this, SLOT(configureShortcuts()), actionCollection());
118 ( void )KStandardAction::configureToolbars(
this, SLOT(slotConfigureToolbars()), actionCollection());
121 void KWatchGnuPGMainWindow::configureShortcuts()
123 KShortcutsDialog::configure( actionCollection(), KShortcutsEditor::LetterShortcutsAllowed,
this );
126 void KWatchGnuPGMainWindow::slotConfigureToolbars()
128 KEditToolBar dlg( factory() );
132 void KWatchGnuPGMainWindow::startWatcher()
134 disconnect( mWatcher, SIGNAL(finished(
int,QProcess::ExitStatus)),
135 this, SLOT(slotWatcherExited(
int,QProcess::ExitStatus)) );
136 if( mWatcher->state()== QProcess::Running ) {
138 while( mWatcher->state()== QProcess::Running ) {
139 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
141 mCentralWidget->
message(i18n(
"[%1] Log stopped", QDateTime::currentDateTime().toString(Qt::ISODate)));
143 mWatcher->clearProgram();
146 const KConfigGroup config(KGlobal::config(),
"WatchGnuPG");
148 *mWatcher << QLatin1String(
"--force");
152 mWatcher->setOutputChannelMode( KProcess::OnlyStdoutChannel );
154 const bool ok = mWatcher->waitForStarted();
156 KMessageBox::sorry(
this, i18n(
"The watchgnupg logging process could not be started.\nPlease install watchgnupg somewhere in your $PATH.\nThis log window is unable to display any useful information." ) );
158 mCentralWidget->
message( i18n(
"[%1] Log started",QDateTime::currentDateTime().toString(Qt::ISODate) ) );
160 connect( mWatcher, SIGNAL(finished(
int,QProcess::ExitStatus)),
161 this, SLOT(slotWatcherExited(
int,QProcess::ExitStatus)) );
164 void KWatchGnuPGMainWindow::setGnuPGConfig()
166 QStringList logclients;
168 Kleo::CryptoConfig* cconfig = Kleo::CryptoBackendFactory::instance()->config();
172 KConfigGroup config(KGlobal::config(),
"WatchGnuPG");
173 const QStringList comps = cconfig->componentList();
174 for( QStringList::const_iterator it = comps.constBegin(); it != comps.constEnd(); ++it ) {
175 Kleo::CryptoConfigComponent* comp = cconfig->component( *it );
178 Kleo::CryptoConfigGroup* group = comp->group(QLatin1String(
"Debug"));
180 Kleo::CryptoConfigEntry* entry = group->entry(QLatin1String(
"log-file"));
182 entry->setStringValue( QString::fromLatin1(
"socket://")+ config.readEntry(
"Socket",
WATCHGNUPGSOCKET ));
183 logclients << QString::fromLatin1(
"%1 (%2)").arg(*it).arg(comp->description());
185 entry = group->entry(QLatin1String(
"debug-level"));
187 entry->setStringValue( config.readEntry(
"LogLevel",
"basic") );
192 if( logclients.isEmpty() ) {
193 KMessageBox::sorry( 0, i18n(
"There are no components available that support logging." ) );
197 void KWatchGnuPGMainWindow::slotWatcherExited(
int, QProcess::ExitStatus)
199 if( KMessageBox::questionYesNo(
this, i18n(
"The watchgnupg logging process died.\nDo you want to try to restart it?"), QString(), KGuiItem(i18n(
"Try Restart")), KGuiItem(i18n(
"Do Not Try")) ) == KMessageBox::Yes ) {
200 mCentralWidget->
message( i18n(
"====== Restarting logging process =====") );
203 KMessageBox::sorry(
this, i18n(
"The watchgnupg logging process is not running.\nThis log window is unable to display any useful information." ) );
207 void KWatchGnuPGMainWindow::slotReadStdout()
211 while(mWatcher->canReadLine()){
212 QString str = QString::fromUtf8( mWatcher->readLine() );
213 if ( str.endsWith( QLatin1Char(
'\n') ) )
215 if ( str.endsWith( QLatin1Char(
'\r') ) )
232 void KWatchGnuPGMainWindow::slotSaveAs()
235 if( filename.isEmpty() )
return;
236 QFile file(filename);
237 if( file.exists() ) {
238 if( KMessageBox::Yes !=
239 KMessageBox::warningYesNo(
this, i18n(
"The file named \"%1\" already "
240 "exists. Are you sure you want "
241 "to overwrite it?", filename),
242 i18n(
"Overwrite File"), KStandardGuiItem::overwrite(), KStandardGuiItem::cancel() ) ) {
246 if( file.open( QIODevice::WriteOnly ) )
247 QTextStream( &file ) << mCentralWidget->
text();
249 KMessageBox::information(
this, i18n(
"Could not save file %1: %2",
250 filename, file.errorString() ) );
253 void KWatchGnuPGMainWindow::slotQuit()
255 disconnect( mWatcher, SIGNAL(finished(
int,QProcess::ExitStatus)),
256 this, SLOT(slotWatcherExited(
int,QProcess::ExitStatus)) );
261 void KWatchGnuPGMainWindow::slotConfigure()
265 mConfig->setObjectName( QLatin1String(
"config dialog") );
266 connect( mConfig, SIGNAL(reconfigure()),
267 this, SLOT(slotReadConfig()) );
273 void KWatchGnuPGMainWindow::slotReadConfig()
275 const KConfigGroup config(KGlobal::config(),
"LogWindow");
276 const int maxLogLen = config.readEntry(
"MaxLogLen", 10000 );
284 if ( !kapp->sessionSaving() ) {
288 return KMainWindow::queryClose();
291 #include "kwatchgnupgmainwin.moc"
A high-speed text display widget.
void setAttention(bool att)
QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
void setHistorySize(unsigned int size)
void message(const QString &msg, const QColor &color)
KWatchGnuPGMainWindow(QWidget *parent=0)