summaryrefslogtreecommitdiffstats
path: root/kmailcvt/filters.cxx
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kmailcvt/filters.cxx
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmailcvt/filters.cxx')
-rw-r--r--kmailcvt/filters.cxx213
1 files changed, 213 insertions, 0 deletions
diff --git a/kmailcvt/filters.cxx b/kmailcvt/filters.cxx
new file mode 100644
index 00000000..02f86985
--- /dev/null
+++ b/kmailcvt/filters.cxx
@@ -0,0 +1,213 @@
+/***************************************************************************
+ filters.cxx - description
+ -------------------
+ begin : Fri Jun 30 2000
+ copyright : (C) 2000 by Hans Dijkema
+ email : kmailcvt@hum.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <dcopclient.h>
+#include <dcopref.h>
+#include <kurl.h>
+#include <kdebug.h>
+
+#include "filters.hxx"
+#include "kmailcvt.h"
+
+
+//////////////////////////////////////////////////////////////////////////////////
+//
+// The API to the kmailcvt dialog --> Gives the import filter access to
+// put information on the dialog.
+//
+//////////////////////////////////////////////////////////////////////////////////
+
+bool FilterInfo::s_terminateASAP = false;
+
+FilterInfo::FilterInfo( KImportPageDlg* dlg, QWidget* parent , bool _removeDupMsg)
+ : m_dlg( dlg ),
+ m_parent( parent )
+{
+ removeDupMsg = _removeDupMsg;
+ s_terminateASAP = false;
+}
+
+FilterInfo::~FilterInfo()
+{
+}
+
+void FilterInfo::setStatusMsg( const QString& status )
+{
+ m_dlg->_textStatus->setText( status );
+}
+
+void FilterInfo::setFrom( const QString& from )
+{
+ m_dlg->_from->setText( from );
+}
+
+void FilterInfo::setTo( const QString& to )
+{
+ m_dlg->_to->setText( to );
+}
+
+void FilterInfo::setCurrent( const QString& current )
+{
+ m_dlg->_current->setText( current );
+ kapp->processEvents();
+}
+
+void FilterInfo::setCurrent( int percent )
+{
+ m_dlg->_done_current->setProgress( percent );
+ kapp->processEvents(); // Be careful - back & finish buttons disabled, so only user event that can happen is cancel/close button
+}
+
+void FilterInfo::setOverall( int percent )
+{
+ m_dlg->_done_overall->setProgress( percent );
+}
+
+void FilterInfo::addLog( const QString& log )
+{
+ m_dlg->_log->insertItem( log );
+ m_dlg->_log->setCurrentItem( m_dlg->_log->count() - 1 );
+ m_dlg->_log->centerCurrentItem();
+ kapp->processEvents();
+}
+
+void FilterInfo::clear()
+{
+ m_dlg->_log->clear();
+ setCurrent();
+ setOverall();
+ setCurrent( QString::null );
+ setFrom( QString::null );
+ setTo( QString::null );
+}
+
+void FilterInfo::alert( const QString& message )
+{
+ KMessageBox::information( m_parent, message );
+}
+
+void FilterInfo::terminateASAP()
+{
+ s_terminateASAP = true;
+}
+
+bool FilterInfo::shouldTerminate()
+{
+ return s_terminateASAP;
+}
+
+//////////////////////////////////////////////////////////////////////////////////
+//
+// The generic filter class
+//
+//////////////////////////////////////////////////////////////////////////////////
+
+
+Filter::Filter( const QString& name, const QString& author,
+ const QString& info )
+ : m_name( name ),
+ m_author( author ),
+ m_info( info )
+{
+ //public
+ count_duplicates = 0;
+}
+
+bool Filter::addMessage( FilterInfo* info, const QString& folderName,
+ const QString& msgPath, const QString & msgStatusFlags)
+{
+ KURL msgURL;
+ msgURL.setPath( msgPath );
+
+ if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) )
+ KApplication::startServiceByDesktopName( "kmail", QString::null ); // Will wait until kmail is started
+
+ DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "dcopAddMessage", folderName, msgURL, msgStatusFlags );
+
+ if ( !reply.isValid() )
+ {
+ info->alert( i18n( "<b>Fatal:</b> Unable to start KMail for DCOP communication. "
+ "Make sure <i>kmail</i> is installed." ) );
+ return false;
+ }
+
+ switch ( int( reply ) )
+ {
+ case -1:
+ info->alert( i18n( "Cannot make folder %1 in KMail" ).arg( folderName ) );
+ return false;
+ case -2:
+ info->alert( i18n( "Cannot add message to folder %1 in KMail" ).arg( folderName ) );
+ return false;
+ case -4:
+ count_duplicates++;
+ return false;
+ case 0:
+ info->alert( i18n( "Error while adding message to folder %1 in KMail" ).arg( folderName ) );
+ return false;
+ }
+ return true;
+}
+
+bool Filter::addMessage_fastImport( FilterInfo* info, const QString& folderName,
+ const QString& msgPath, const QString& msgStatusFlags )
+{
+ KURL msgURL;
+ msgURL.setPath( msgPath );
+
+ if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) )
+ KApplication::startServiceByDesktopName( "kmail", QString::null ); // Will wait until kmail is started
+
+ DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "dcopAddMessage_fastImport", folderName, msgURL, msgStatusFlags );
+ if ( !reply.isValid() )
+ {
+ info->alert( i18n( "<b>Fatal:</b> Unable to start KMail for DCOP communication. "
+ "Make sure <i>kmail</i> is installed." ) );
+ return false;
+ }
+
+ switch ( int( reply ) )
+ {
+ case -1:
+ info->alert( i18n( "Cannot make folder %1 in KMail" ).arg( folderName ) );
+ return false;
+ case -2:
+ info->alert( i18n( "Cannot add message to folder %1 in KMail" ).arg( folderName ) );
+ return false;
+ case 0:
+ info->alert( i18n( "Error while adding message to folder %1 in KMail" ).arg( folderName ) );
+ return false;
+ }
+ return true;
+}
+
+bool Filter::endImport()
+{
+ if ( !kapp->dcopClient()->isApplicationRegistered( "kmail" ) )
+ KApplication::startServiceByDesktopName( "kmail", QString::null ); // Will wait until kmail is started
+
+ DCOPReply reply = DCOPRef( "kmail", "KMailIface" ).call( "dcopAddMessage", QString::null, QString::null);
+ if ( !reply.isValid() ) return false;
+
+ reply = DCOPRef( "kmail", "KMailIface" ).call( "dcopResetAddMessage" );
+ if ( !reply.isValid() ) return false;
+
+ return true;
+}
+// vim: ts=2 sw=2 et