diff options
Diffstat (limited to 'certmanager/lib/ui')
-rw-r--r-- | certmanager/lib/ui/cryptoconfigdialog.cpp | 6 | ||||
-rw-r--r-- | certmanager/lib/ui/cryptoconfigmodule.cpp | 30 | ||||
-rw-r--r-- | certmanager/lib/ui/cryptoconfigmodule.h | 2 | ||||
-rw-r--r-- | certmanager/lib/ui/keyselectiondialog.cpp | 57 | ||||
-rw-r--r-- | certmanager/lib/ui/keyselectiondialog.h | 15 | ||||
-rw-r--r-- | certmanager/lib/ui/messagebox.cpp | 69 | ||||
-rw-r--r-- | certmanager/lib/ui/messagebox.h | 3 |
7 files changed, 170 insertions, 12 deletions
diff --git a/certmanager/lib/ui/cryptoconfigdialog.cpp b/certmanager/lib/ui/cryptoconfigdialog.cpp index 472429942..0d383083b 100644 --- a/certmanager/lib/ui/cryptoconfigdialog.cpp +++ b/certmanager/lib/ui/cryptoconfigdialog.cpp @@ -46,6 +46,12 @@ Kleo::CryptoConfigDialog::CryptoConfigDialog( Kleo::CryptoConfig* config, TQWidg setMainWidget( mMainWidget ); connect( mMainWidget, TQT_SIGNAL( changed() ), TQT_SLOT( slotChanged() ) ); enableButton( Apply, false ); + if ( mMainWidget->hasError() ) { + showButton( Default, false ); + showButton( User1, false ); + showButton( Apply, false ); + showButton( Ok, false ); + } // Automatically assign accelerators KAcceleratorManager::manage( this ); diff --git a/certmanager/lib/ui/cryptoconfigmodule.cpp b/certmanager/lib/ui/cryptoconfigmodule.cpp index 33e7129c4..5b14d7c41 100644 --- a/certmanager/lib/ui/cryptoconfigmodule.cpp +++ b/certmanager/lib/ui/cryptoconfigmodule.cpp @@ -62,8 +62,20 @@ static inline TQPixmap loadIcon( TQString s ) { ->loadIcon( s.replace( TQRegExp( "[^a-zA-Z0-9_]" ), "_" ), KIcon::NoGroup, KIcon::SizeMedium ); } +static unsigned int num_components_with_options( const Kleo::CryptoConfig * config ) { + if ( !config ) + return 0; + const TQStringList components = config->componentList(); + unsigned int result = 0; + for ( TQStringList::const_iterator it = components.begin() ; it != components.end() ; ++it ) + if ( const Kleo::CryptoConfigComponent * const comp = config->component( *it ) ) + if ( !comp->groupList().empty() ) + ++result; + return result; +} + static const KJanusWidget::Face determineJanusFace( const Kleo::CryptoConfig * config ) { - return config && config->componentList().size() < 2 + return num_components_with_options( config ) < 2 ? KJanusWidget::Plain : KJanusWidget::IconList ; } @@ -115,6 +127,22 @@ Kleo::CryptoConfigModule::CryptoConfigModule( Kleo::CryptoConfig* config, TQWidg + scrollView->style().pixelMetric(TQStyle::PM_ScrollBarExtent), QMIN( compGUI->sizeHint().height(), dialogHeight ) ); } + if ( mComponentGUIs.empty() ) { + Q_ASSERT( face() == Plain ); + const TQString msg = i18n("The gpgconf tool used to provide the information " + "for this dialog does not seem to be installed " + "properly. It did not return any components. " + "Try running \"%1\" on the command line for more " + "information.") + .arg( components.empty() ? "gpgconf --list-components" : "gpgconf --list-options gpg" ); + TQLabel * label = new TQLabel( msg, vbox ); + label->setAlignment( TQt::WordBreak ); + label->setMinimumHeight( fontMetrics().lineSpacing() * 5 ); + } +} + +bool Kleo::CryptoConfigModule::hasError() const { + return mComponentGUIs.empty(); } void Kleo::CryptoConfigModule::save() diff --git a/certmanager/lib/ui/cryptoconfigmodule.h b/certmanager/lib/ui/cryptoconfigmodule.h index 70c4a2691..167c3ac84 100644 --- a/certmanager/lib/ui/cryptoconfigmodule.h +++ b/certmanager/lib/ui/cryptoconfigmodule.h @@ -50,6 +50,8 @@ namespace Kleo { public: CryptoConfigModule( Kleo::CryptoConfig* config, TQWidget * parent=0, const char * name=0 ); + bool hasError() const; + void save(); void reset(); // i.e. reload current settings, discarding user input void defaults(); diff --git a/certmanager/lib/ui/keyselectiondialog.cpp b/certmanager/lib/ui/keyselectiondialog.cpp index fcb257514..fc590d49b 100644 --- a/certmanager/lib/ui/keyselectiondialog.cpp +++ b/certmanager/lib/ui/keyselectiondialog.cpp @@ -61,6 +61,8 @@ #include <kconfig.h> #include <kmessagebox.h> #include <kprocess.h> +#include <kactivelabel.h> +#include <kurl.h> // Qt #include <tqcheckbox.h> @@ -85,7 +87,12 @@ static bool checkKeyUsage( const GpgME::Key & key, unsigned int keyUsage ) { if ( keyUsage & Kleo::KeySelectionDialog::ValidKeys ) { if ( key.isInvalid() ) - kdDebug() << "key is invalid - ignoring" << endl; + if ( key.keyListMode() & GpgME::Context::Validate ) { + kdDebug() << "key is invalid" << endl; + return false; + } else { + kdDebug() << "key is invalid - ignoring" << endl; + } if ( key.isExpired() ) { kdDebug() << "key is expired" << endl; return false; @@ -309,6 +316,28 @@ Kleo::KeySelectionDialog::KeySelectionDialog( const TQString & title, Kleo::KeySelectionDialog::KeySelectionDialog( const TQString & title, const TQString & text, + const TQString & initialQuery, + const std::vector<GpgME::Key> & selectedKeys, + unsigned int keyUsage, + bool extendedSelection, + bool rememberChoice, + TQWidget * parent, const char * name, + bool modal ) + : KDialogBase( parent, name, modal, title, Default|Ok|Cancel|Help, Ok ), + mOpenPGPBackend( 0 ), + mSMIMEBackend( 0 ), + mRememberCB( 0 ), + mSelectedKeys( selectedKeys ), + mKeyUsage( keyUsage ), + mSearchText( initialQuery ), + mInitialQuery( initialQuery ), + mCurrentContextMenuItem( 0 ) +{ + init( rememberChoice, extendedSelection, text, initialQuery ); +} + +Kleo::KeySelectionDialog::KeySelectionDialog( const TQString & title, + const TQString & text, const TQString & initialQuery, unsigned int keyUsage, bool extendedSelection, @@ -321,6 +350,7 @@ Kleo::KeySelectionDialog::KeySelectionDialog( const TQString & title, mRememberCB( 0 ), mKeyUsage( keyUsage ), mSearchText( initialQuery ), + mInitialQuery( initialQuery ), mCurrentContextMenuItem( 0 ) { init( rememberChoice, extendedSelection, text, initialQuery ); @@ -340,11 +370,26 @@ void Kleo::KeySelectionDialog::init( bool rememberChoice, bool extendedSelection mTopLayout = new TQVBoxLayout( page, 0, spacingHint() ); if ( !text.isEmpty() ) { - TQLabel* textLabel = new TQLabel( text, page ); - textLabel->setAlignment( textLabel->alignment() | Qt::WordBreak ); - mTopLayout->addWidget( textLabel ); + if ( text.startsWith( "<qt>" ) ) { + KActiveLabel *textLabel = new KActiveLabel( text, page ); + disconnect( textLabel, TQT_SIGNAL(linkClicked(const TQString&)), textLabel, TQT_SLOT(openLink(const TQString&)) ); + connect( textLabel, TQT_SIGNAL(linkClicked(const TQString&)), TQT_SLOT(slotStartCertificateManager(const TQString&)) ); + textLabel->setAlignment( textLabel->alignment() | TQt::WordBreak ); + mTopLayout->addWidget( textLabel ); + } else { + KActiveLabel *textLabel = new KActiveLabel( text, page ); + textLabel->setAlignment( textLabel->alignment() | TQt::WordBreak ); + mTopLayout->addWidget( textLabel ); + } } + TQPushButton * const searchExternalPB + = new TQPushButton( i18n("Search for &External Certificates"), page ); + mTopLayout->addWidget( searchExternalPB, 0, TQt::AlignLeft ); + connect( searchExternalPB, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotStartSearchForExternalCertificates()) ); + if ( initialQuery.isEmpty() ) + searchExternalPB->hide(); + TQHBoxLayout * hlay = new TQHBoxLayout( mTopLayout ); // inherits spacing TQLineEdit * le = new TQLineEdit( page ); le->setText( initialQuery ); @@ -500,10 +545,12 @@ void Kleo::KeySelectionDialog::slotHelp() emit helpClicked(); } -void Kleo::KeySelectionDialog::slotStartCertificateManager() +void Kleo::KeySelectionDialog::slotStartCertificateManager( const TQString &query ) { KProcess certManagerProc; certManagerProc << "kleopatra"; + if ( !query.isEmpty() ) + certManagerProc << "--external" << "--query" << KURL::decode_string( query ); if( !certManagerProc.start( KProcess::DontCare ) ) KMessageBox::error( this, i18n( "Could not start certificate manager; " diff --git a/certmanager/lib/ui/keyselectiondialog.h b/certmanager/lib/ui/keyselectiondialog.h index fd8f67394..ab8dc756d 100644 --- a/certmanager/lib/ui/keyselectiondialog.h +++ b/certmanager/lib/ui/keyselectiondialog.h @@ -93,6 +93,15 @@ namespace Kleo { bool modal=true ); KeySelectionDialog( const TQString & title, const TQString & text, + const TQString & initialPattern, + const std::vector<GpgME::Key> & selectedKeys, + unsigned int keyUsage=AllKeys, + bool extendedSelection=false, + bool rememberChoice=false, + TQWidget * parent=0, const char * name=0, + bool modal=true ); + KeySelectionDialog( const TQString & title, + const TQString & text, const TQString & initialPattern, unsigned int keyUsage=AllKeys, bool extendedSelection=false, @@ -129,7 +138,10 @@ namespace Kleo { private slots: void slotRereadKeys(); - void slotStartCertificateManager(); + void slotStartCertificateManager( const TQString &query = TQString() ); + void slotStartSearchForExternalCertificates() { + slotStartCertificateManager( mInitialQuery ); + } void slotKeyListResult( const GpgME::KeyListResult & ); void slotSelectionChanged(); void slotCheckSelection() { slotCheckSelection( 0 ); } @@ -170,6 +182,7 @@ namespace Kleo { TQTimer * mStartSearchTimer; // cross-eventloop temporaries: TQString mSearchText; + const TQString mInitialQuery; Kleo::KeyListViewItem * mCurrentContextMenuItem; int mTruncated, mListJobCount, mSavedOffsetY; }; diff --git a/certmanager/lib/ui/messagebox.cpp b/certmanager/lib/ui/messagebox.cpp index ddce8f04d..e05a21b9a 100644 --- a/certmanager/lib/ui/messagebox.cpp +++ b/certmanager/lib/ui/messagebox.cpp @@ -46,10 +46,15 @@ #include <klocale.h> #include <ksavefile.h> #include <kguiitem.h> +#include <kdebug.h> #include <tqtextedit.h> #include <tqtextstream.h> #include <tqvbox.h> +#include <tqapplication.h> +#include <tqstylesheet.h> + +#include <gpg-error.h> using namespace Kleo; using namespace GpgME; @@ -74,6 +79,7 @@ public: explicit AuditLogViewer( const TQString & log, TQWidget * parent=0, const char * name=0, WFlags f=0 ) : KDialogBase( parent, name, false, i18n("View GnuPG Audit Log"), Close|User1|User2, Close, false, KGuiItem_save(), KGuiItem_copy() ), + m_log( /* sic */ ), m_textEdit( new TQTextEdit( this, "m_textEdit" ) ) { setWFlags( f ); @@ -85,7 +91,18 @@ public: ~AuditLogViewer() {} void setAuditLog( const TQString & log ) { - m_textEdit->setText( log ); + if ( log == m_log ) + return; + m_log = log; + m_textEdit->setText( "<qt>" + log + "</qt>" ); + const TQRect rect = m_textEdit->paragraphRect( 0 ); + kdDebug() << "setAuditLog: rect = " << rect << endl; + if ( !rect.isValid() ) + return; + TQSize maxSize = qApp->desktop()->screenGeometry( this ).size() * 2 / 3 ; + if ( !maxSize.isValid() ) + maxSize = TQSize( 640, 480 ); + m_textEdit->setMinimumSize( rect.size().boundedTo( maxSize ) ); } private: @@ -98,7 +115,12 @@ private: KSaveFile file( fileName ); if ( TQTextStream * const s = file.textStream() ) { - *s << m_textEdit->text() << endl; + *s << "<html><head>"; + if ( !caption().isEmpty() ) + *s << "\n<title>" << /*TQt*/TQStyleSheet::escape( caption() ) << "</title>\n"; + *s << "</head><body>\n" + << m_log + << "\n</body></html>" << endl; file.close(); } @@ -114,6 +136,7 @@ private: } private: + TQString m_log; TQTextEdit * m_textEdit; }; @@ -125,13 +148,23 @@ void MessageBox::auditLog( TQWidget * parent, const Job * job, const TQString & if ( !job ) return; - if ( !GpgME::hasFeature( AuditLogFeature ) ) { + if ( !GpgME::hasFeature( AuditLogFeature ) || !job->isAuditLogSupported() ) { KMessageBox::information( parent, i18n("Your system does not have support for GnuPG Audit Logs"), i18n("System Error") ); return; } + const GpgME::Error err = job->auditLogError(); + + if ( err.code() != GPG_ERR_NO_DATA ) { + KMessageBox::information( parent, i18n("An error occurred while trying to retrieve the GnuPG Audit Log:\n%1") + .arg( TQString::fromLocal8Bit( err.asString() ) ), + i18n("GnuPG Audit Log Error") ); + return; + } + const TQString log = job->auditLogAsHtml(); + if ( log.isEmpty() ) { KMessageBox::information( parent, i18n("No GnuPG Audit Log available for this operation."), i18n("No GnuPG Audit Log") ); @@ -143,7 +176,7 @@ void MessageBox::auditLog( TQWidget * parent, const Job * job, const TQString & // static void MessageBox::auditLog( TQWidget * parent, const TQString & log, const TQString & caption ) { - AuditLogViewer * const alv = new AuditLogViewer( "<qt>" + log + "</qt>", parent, "alv", Qt::WDestructiveClose ); + AuditLogViewer * const alv = new AuditLogViewer( log, parent, "alv", Qt::WDestructiveClose ); alv->setCaption( caption ); alv->show(); } @@ -247,8 +280,34 @@ void MessageBox::error( TQWidget * parent, const SigningResult & sresult, const } // static +bool MessageBox::showAuditLogButton( const Kleo::Job * job ) { + if ( !job ) { + kdDebug() << "not showing audit log button (no job instance)" << endl; + return false; + } + if ( !GpgME::hasFeature( GpgME::AuditLogFeature ) ) { + kdDebug() << "not showing audit log button (gpgme too old)" << endl; + return false; + } + if ( !job->isAuditLogSupported() ) { + kdDebug() << "not showing audit log button (not supported)" << endl; + return false; + } + if ( job->auditLogError().code() == GPG_ERR_NO_DATA ) { + kdDebug() << "not showing audit log button (GPG_ERR_NO_DATA)" << endl; + return false; + } + if ( !job->auditLogError() && job->auditLogAsHtml().isEmpty() ) { + kdDebug() << "not showing audit log button (success, but result empty)" << endl; + return false; + } + return true; +} + + +// static void MessageBox::make( TQWidget * parent, TQMessageBox::Icon icon, const TQString & text, const Job * job, const TQString & caption, int options ) { - KDialogBase * dialog = GpgME::hasFeature( GpgME::AuditLogFeature ) + KDialogBase * dialog = showAuditLogButton( job ) ? new KDialogBase( caption, KDialogBase::Yes | KDialogBase::No, KDialogBase::Yes, KDialogBase::Yes, parent, "error", true, true, diff --git a/certmanager/lib/ui/messagebox.h b/certmanager/lib/ui/messagebox.h index 5ed2edaf4..ee72e43c3 100644 --- a/certmanager/lib/ui/messagebox.h +++ b/certmanager/lib/ui/messagebox.h @@ -40,6 +40,7 @@ namespace GpgME { class EncryptionResult; class DecryptionResult; class VerificationResult; + class Error; } namespace Kleo { @@ -73,6 +74,8 @@ namespace Kleo { static void auditLog( TQWidget * parent, const TQString & log, const TQString & caption ); static void auditLog( TQWidget * parent, const TQString & log ); + static bool showAuditLogButton( const Kleo::Job * job ); + private: static void make( TQWidget * parent, TQMessageBox::Icon icon, const TQString & text, const Kleo::Job * job, const TQString & caption, int options ); }; |