[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Re: [Patch] Wallet support for KMail
From:       Volker Krause <volker.krause () rwth-aachen ! de>
Date:       2004-08-27 14:52:13
Message-ID: 200408271652.14318.volker.krause () rwth-aachen ! de
[Download RAW message or body]

On Friday 27 August 2004 15:53, Bo Thorsen wrote:
> On Friday 27 August 2004 15:34, Volker Krause wrote:
> > On Friday 27 August 2004 14:27, David Faure wrote:
> > > If yes, then the method can also be made const.
> >
> > No, since passwd() loads the password from the wallet on first use.
>
> Nitpicking: Declare mWallet mutable, and then you can make passwd() const.
> It's The Right Way (TM).

new version of the patch attached.

regards
Volker

["kmail-wallet4.diff" (text/x-diff)]

? .kateconfig
? kmail-wallet.diff
? kmail-wallet2.diff
? kmail-wallet3.diff
? kmail-wallet4.diff
? kmail.kdevelop
? kmail.kdevelop.pcs
? kmail.kdevses
Index: kmacctmgr.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmacctmgr.cpp,v
retrieving revision 1.122
diff -u -p -r1.122 kmacctmgr.cpp
--- kmacctmgr.cpp	26 Aug 2004 21:13:41 -0000	1.122
+++ kmacctmgr.cpp	27 Aug 2004 14:45:28 -0000
@@ -458,4 +458,14 @@ QString KMAcctMgr::hostForAccount( const
   return net_acct ? net_acct->host() : QString::null;
 }
 
+//-----------------------------------------------------------------------------
+void KMAcctMgr::readPasswords()
+{
+  for (QPtrListIterator<KMAccount> it(mAcctList); it.current(); ++it) {
+    NetworkAccount *acct = dynamic_cast<NetworkAccount*>( it.current() );
+    if( acct )
+      acct->readPassword();
+  }
+}
+
 #include "kmacctmgr.moc"
Index: kmacctmgr.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmacctmgr.h,v
retrieving revision 1.48
diff -u -p -r1.48 kmacctmgr.h
--- kmacctmgr.h	26 Aug 2004 03:02:44 -0000	1.48
+++ kmacctmgr.h	27 Aug 2004 14:45:28 -0000
@@ -70,6 +70,9 @@ public:
   /// Called on exit (KMMainWin::queryExit)
   void cancelMailCheck();
 
+  /** Read passwords of all accounts from the wallet */
+  void readPasswords();
+
 public slots:
   virtual void singleCheckMail(KMAccount *, bool _interactive = true);
   virtual void singleInvalidateIMAPFolders(KMAccount *);
Index: kmkernel.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmkernel.cpp,v
retrieving revision 1.302
diff -u -p -r1.302 kmkernel.cpp
--- kmkernel.cpp	20 Aug 2004 23:57:21 -0000	1.302
+++ kmkernel.cpp	27 Aug 2004 14:45:28 -0000
@@ -60,6 +60,8 @@ using KMail::FolderIface;
 #include <ksystemtray.h>
 #include <kpgp.h>
 #include <kdebug.h>
+#include <kwallet.h>
+using KWallet::Wallet;
 
 #include <qutf7codec.h>
 #include <qvbox.h>
@@ -88,7 +90,7 @@ KMKernel *KMKernel::mySelf = 0;
 KMKernel::KMKernel (QObject *parent, const char *name) :
   DCOPObject("KMailIface"), QObject(parent, name),
   mIdentityManager(0), mConfigureDialog(0),
-  mContextMenuShown( false )
+  mContextMenuShown( false ), mWallet(0)
 {
   kdDebug(5006) << "KMKernel::KMKernel" << endl;
   mySelf = this;
@@ -180,6 +182,8 @@ KMKernel::~KMKernel ()
   mMailService = 0;
 
   GlobalSettings::writeConfig();
+  delete mWallet;
+  mWallet = 0;
   mySelf = 0;
   kdDebug(5006) << "KMKernel::~KMKernel" << endl;
 }
@@ -1785,4 +1789,27 @@ int KMKernel::timeOfLastMessageCountChan
   return mTimeOfLastMessageCountChange;
 }
 
+Wallet *KMKernel::wallet() {
+  if ( mWallet && mWallet->isOpen() )
+    return mWallet;
+
+  if ( !Wallet::isEnabled() )
+    return 0;
+
+  delete mWallet;
+  mWallet = Wallet::openWallet(Wallet::NetworkWallet(),
+        getKMMainWidget() ? getKMMainWidget()->topLevelWidget()->winId() : 0);
+
+  if ( !mWallet ) {
+    KMessageBox::error(getKMMainWidget(), i18n("The wallet could not be opened. "
+        "This error is most probably caused by providing a wrong password."));
+    return 0;
+  }
+
+  if (!mWallet->hasFolder("kmail"))
+    mWallet->createFolder("kmail");
+  mWallet->setFolder("kmail");
+  return mWallet;
+}
+
 #include "kmkernel.moc"
Index: kmkernel.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmkernel.h,v
retrieving revision 1.118
diff -u -p -r1.118 kmkernel.h
--- kmkernel.h	20 Aug 2004 23:57:21 -0000	1.118
+++ kmkernel.h	27 Aug 2004 14:45:28 -0000
@@ -20,6 +20,9 @@
 namespace KIO {
   class Job;
 }
+namespace KWallet {
+  class Wallet;
+}
 namespace KMail {
   class MailServiceImpl;
   class UndoStack;
@@ -271,6 +274,9 @@ public:
    */
   void messageCountChanged();
 
+  /** Open KDE wallet and set it to kmail folder */
+  KWallet::Wallet *wallet();
+
 public slots:
 
   /// Save contents of all open composer widnows to ~/dead.letter
@@ -374,6 +380,8 @@ private:
   /* Weaver */
   KPIM::ThreadWeaver::Weaver *the_weaver;
   KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;
+
+  KWallet::Wallet *mWallet;
 };
 
 #endif
Index: kmsender.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsender.cpp,v
retrieving revision 1.220
diff -u -p -r1.220 kmsender.cpp
--- kmsender.cpp	28 Jul 2004 09:33:56 -0000	1.220
+++ kmsender.cpp	27 Aug 2004 14:45:29 -0000
@@ -1045,13 +1045,14 @@ bool KMSendSMTP::send(KMMessage *aMsg)
 
   if (ti->auth)
   {
-    if(ti->user.isEmpty() || ti->pass.isEmpty())
+    if(ti->user.isEmpty() || ti->passwd().isEmpty())
     {
       bool b = FALSE;
       int result;
 
       KCursorSaver idle(KBusyPtr::idle());
-      result = KIO::PasswordDialog::getNameAndPassword(ti->user, ti->pass,
+      QString passwd = ti->passwd();
+      result = KIO::PasswordDialog::getNameAndPassword(ti->user, passwd,
 	&b, i18n("You need to supply a username and a password to use this "
 	     "SMTP server."), FALSE, QString::null, ti->name, QString::null);
 
@@ -1060,11 +1061,13 @@ bool KMSendSMTP::send(KMMessage *aMsg)
         abort();
         return FALSE;
       }
-      if (int id = KMTransportInfo::findTransport(ti->name))
+      if (int id = KMTransportInfo::findTransport(ti->name)) {
+        ti->setPasswd( passwd );
         ti->writeConfig(id);
+      }
     }
     destination.setUser(ti->user);
-    destination.setPass(ti->pass);
+    destination.setPass(ti->passwd());
   }
 
   if (!mSlave || !mInProcess)
Index: kmtransport.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmtransport.cpp,v
retrieving revision 1.39
diff -u -p -r1.39 kmtransport.cpp
--- kmtransport.cpp	13 Jul 2004 22:10:31 -0000	1.39
+++ kmtransport.cpp	27 Aug 2004 14:45:29 -0000
@@ -38,18 +38,22 @@
 #include <kmessagebox.h>
 #include <kseparator.h>
 #include <kdebug.h>
+#include <kwallet.h>
+using KWallet::Wallet;
 
 #include "kmservertest.h"
 #include "kmaccount.h"
 #include "kmkernel.h"
 #include "protocols.h"
+#include "transportmanager.h"
+using namespace KMail;
 
-KMTransportInfo::KMTransportInfo()
+KMTransportInfo::KMTransportInfo() : mPasswdDirty( false ),
+  mStorePasswd( false ), mId( 0 )
 {
   name = i18n("Unnamed");
   port = "25";
   auth = FALSE;
-  storePass = FALSE;
   specifyHostname = false;
 }
 
@@ -63,19 +67,33 @@ void KMTransportInfo::readConfig(int id)
 {
   KConfig *config = KMKernel::config();
   KConfigGroupSaver saver(config, "Transport " + QString::number(id));
+  mId = config->readUnsignedNumEntry( "id", 0 );
   type = config->readEntry("type", "smtp");
   name = config->readEntry("name", i18n("Unnamed"));
   host = config->readEntry("host", "localhost");
   port = config->readEntry("port", "25");
   user = config->readEntry("user");
-  pass = KMAccount::decryptStr(config->readEntry("pass"));
+  mPasswd = KMAccount::decryptStr(config->readEntry("pass"));
   precommand = config->readPathEntry("precommand");
   encryption = config->readEntry("encryption");
   authType = config->readEntry("authtype");
   auth = config->readBoolEntry("auth");
-  storePass = config->readBoolEntry("storepass");
+  mStorePasswd = config->readBoolEntry("storepass");
   specifyHostname = config->readBoolEntry("specifyHostname", false);
   localHostname = config->readEntry("localHostname");
+
+  if (!storePasswd())
+    return;
+
+  if (!mPasswd.isEmpty()) {
+    // migration to kwallet
+    config->deleteEntry( "pass" );
+    mPasswdDirty = true;
+  } else {
+    // read password if wallet is open, defer otherwise
+    if (Wallet::isOpen(Wallet::NetworkWallet()))
+      readPassword();
+  }
 }
 
 
@@ -83,20 +101,40 @@ void KMTransportInfo::writeConfig(int id
 {
   KConfig *config = KMKernel::config();
   KConfigGroupSaver saver(config, "Transport " + QString::number(id));
+  if (!mId)
+    mId = TransportManager::createId();
+  config->writeEntry("id", mId);
   config->writeEntry("type", type);
   config->writeEntry("name", name);
   config->writeEntry("host", host);
   config->writeEntry("port", port);
   config->writeEntry("user", user);
-  config->writeEntry("pass", (storePass) ? KMAccount::encryptStr(pass) :
-                                           QString("") );
   config->writePathEntry("precommand", precommand);
   config->writeEntry("encryption", encryption);
   config->writeEntry("authtype", authType);
   config->writeEntry("auth", auth);
-  config->writeEntry("storepass", storePass);
+  config->writeEntry("storepass", storePasswd());
   config->writeEntry("specifyHostname", specifyHostname);
   config->writeEntry("localHostname", localHostname);
+
+  // write password to the wallet if necessary
+  if (storePasswd() && auth && mPasswdDirty) {
+    Wallet *wallet = kmkernel->wallet();
+    if (!wallet || wallet->writePassword("transport-" + QString::number(mId), passwd()) ) {
+      KMessageBox::information(0, i18n("KWallet is not running. It is strongly recommend to use "
+          "KWallet for managing your password"),
+          i18n("KWallet is Not Running."), "KWalletWarning" );
+      config->writeEntry( "pass", KMAccount::encryptStr(passwd()) );
+    }
+  }
+
+  // delete already stored password from the wallet if password storage is disabled
+  if (!storePasswd() && !Wallet::keyDoesNotExist(
+       Wallet::NetworkWallet(), "kmail", "transport-" + QString::number(mId))) {
+    Wallet *wallet = kmkernel->wallet();
+    if (wallet)
+      wallet->removeEntry( "transport-" + QString::number(mId) );
+  }
 }
 
 
@@ -129,6 +167,45 @@ QStringList KMTransportInfo::availableTr
 }
 
 
+QString KMTransportInfo::passwd() const
+{
+  if (auth && storePasswd() && mPasswd.isEmpty())
+    readPassword();
+  return mPasswd;
+}
+
+
+void KMTransportInfo::setPasswd( const QString &passwd )
+{
+  if ( passwd != mPasswd ) {
+    mPasswd = passwd;
+    mPasswdDirty = true;
+  }
+}
+
+
+void KMTransportInfo::setStorePasswd( bool store )
+{
+  if (mStorePasswd != store && store)
+    mPasswdDirty = true;
+  mStorePasswd = store;
+}
+
+
+void KMTransportInfo::readPassword() const
+{
+  if (!storePasswd() || !auth)
+    return;
+
+  if ( Wallet::folderDoesNotExist(Wallet::NetworkWallet(), "kmail") ||
+       Wallet::keyDoesNotExist(Wallet::NetworkWallet(), "kmail", "transport-" + QString::number(mId)) )
+    return;
+
+  if ( kmkernel->wallet() )
+    kmkernel->wallet()->readPassword( "transport-" + QString::number(mId), mPasswd );
+}
+
+
 KMTransportSelDlg::KMTransportSelDlg( QWidget *parent, const char *name,
   bool modal )
   : KDialogBase( parent, name, modal, i18n("Add Transport"), Ok|Cancel, Ok )
@@ -429,8 +506,8 @@ void KMTransportDialog::setupSettings()
     mSmtp.portEdit->setText(mTransportInfo->port);
     mSmtp.authCheck->setChecked(mTransportInfo->auth);
     mSmtp.loginEdit->setText(mTransportInfo->user);
-    mSmtp.passwordEdit->setText(mTransportInfo->pass);
-    mSmtp.storePasswordCheck->setChecked(mTransportInfo->storePass);
+    mSmtp.passwordEdit->setText(mTransportInfo->passwd());
+    mSmtp.storePasswordCheck->setChecked(mTransportInfo->storePasswd());
     mSmtp.precommand->setText(mTransportInfo->precommand);
     mSmtp.specifyHostnameCheck->setChecked(mTransportInfo->specifyHostname);
     mSmtp.localHostnameEdit->setText(mTransportInfo->localHostname);
@@ -468,8 +545,8 @@ void KMTransportDialog::saveSettings()
     mTransportInfo->port = mSmtp.portEdit->text().stripWhiteSpace();
     mTransportInfo->auth = mSmtp.authCheck->isChecked();
     mTransportInfo->user = mSmtp.loginEdit->text().stripWhiteSpace();
-    mTransportInfo->pass = mSmtp.passwordEdit->text();
-    mTransportInfo->storePass = mSmtp.storePasswordCheck->isChecked();
+    mTransportInfo->setPasswd( mSmtp.passwordEdit->text() );
+    mTransportInfo->setStorePasswd( mSmtp.storePasswordCheck->isChecked() );
     mTransportInfo->precommand = mSmtp.precommand->text().stripWhiteSpace();
     mTransportInfo->specifyHostname = mSmtp.specifyHostnameCheck->isChecked();
     mTransportInfo->localHostname = mSmtp.localHostnameEdit->text().stripWhiteSpace();
Index: kmtransport.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmtransport.h,v
retrieving revision 1.10
diff -u -p -r1.10 kmtransport.h
--- kmtransport.h	10 Apr 2004 09:21:44 -0000	1.10
+++ kmtransport.h	27 Aug 2004 14:45:29 -0000
@@ -19,7 +19,7 @@
 
 #ifndef _KMTRANSPORT_H_
 #define _KMTRANSPORT_H_
- 
+
 #include <kdialogbase.h>
 
 class QCheckBox;
@@ -38,22 +38,40 @@ public:
   void writeConfig(int id);
   static int findTransport(const QString &name);
   static QStringList availableTransports();
-  QString type, name, host, port, user, pass, precommand, encryption, authType;
+  uint id() const { return mId; }
+
+  /** Get/set password for this account */
+  QString passwd() const;
+  void setPasswd( const QString& passwd );
+
+  /** Get/set password storage flag */
+  bool storePasswd() const { return mStorePasswd; }
+  void setStorePasswd( bool store );
+
+  /** Read password from wallet */
+  void readPassword() const;
+
+  QString type, name, host, port, user, precommand, encryption, authType;
   QString localHostname;
-  bool auth, storePass, specifyHostname;
+  bool auth, specifyHostname;
+
+  private:
+    mutable QString mPasswd;
+    bool mPasswdDirty, mStorePasswd;
+    uint mId;
 };
 
 class KMTransportSelDlg : public KDialogBase
 {
   Q_OBJECT
- 
+
 public:
   KMTransportSelDlg( QWidget *parent=0, const char *name=0, bool modal=TRUE );
   int selected() const;
- 
+
 private slots:
   void buttonClicked( int id );
- 
+
 private:
   int mSelectedButton;
 };
@@ -73,8 +91,8 @@ private slots:
   void slotRequiresAuthClicked();
   void slotSmtpEncryptionChanged(int);
   void slotCheckSmtpCapabilities();
-  void slotSmtpCapabilities( const QStringList &, const QStringList &, 
-                             const QString &, const QString &, 
+  void slotSmtpCapabilities( const QStringList &, const QStringList &,
+                             const QString &, const QString &,
                              const QString & );
   void slotSendmailEditPath(const QString &);
 private:
Index: networkaccount.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/networkaccount.cpp,v
retrieving revision 1.9
diff -u -p -r1.9 networkaccount.cpp
--- networkaccount.cpp	10 Mar 2004 18:41:27 -0000	1.9
+++ networkaccount.cpp	27 Aug 2004 14:45:29 -0000
@@ -28,10 +28,16 @@
 #endif
 
 #include "networkaccount.h"
+#include "kmacctmgr.h"
+#include "kmkernel.h"
 
 #include <kconfig.h>
 #include <kio/global.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kwallet.h>
 using KIO::MetaData;
+using KWallet::Wallet;
 
 #include <climits>
 
@@ -45,7 +51,8 @@ namespace KMail {
       mStorePasswd( false ),
       mUseSSL( false ),
       mUseTLS( false ),
-      mAskAgain( false )
+      mAskAgain( false ),
+      mPasswdDirty( false )
   {
 
   }
@@ -80,11 +87,16 @@ namespace KMail {
   }
 
   QString NetworkAccount::passwd() const {
+    if (storePasswd() && mPasswd.isEmpty())
+      mOwner->readPasswords();
     return decryptStr( mPasswd );
   }
 
   void NetworkAccount::setPasswd( const QString & passwd, bool storeInConfig ) {
-    mPasswd = encryptStr( passwd );
+    if (mPasswd != encryptStr( passwd )) {
+      mPasswd = encryptStr( passwd );
+      mPasswdDirty = true;
+    }
     setStorePasswd( storeInConfig );
   }
 
@@ -97,6 +109,8 @@ namespace KMail {
   }
 
   void NetworkAccount::setStorePasswd( bool store ) {
+    if( mStorePasswd != store && store )
+      mPasswdDirty = true;
     mStorePasswd = store;
   }
 
@@ -132,25 +146,39 @@ namespace KMail {
     setLogin( config.readEntry( "login" ) );
 
     if ( config.readNumEntry( "store-passwd", false ) ) { // ### s/Num/Bool/
+      mStorePasswd = true;
       QString encpasswd = config.readEntry( "pass" );
       if ( encpasswd.isEmpty() ) {
-	encpasswd = config.readEntry( "passwd" );
-	if ( !encpasswd.isEmpty() ) encpasswd = importPassword( encpasswd );
+        encpasswd = config.readEntry( "passwd" );
+        if ( !encpasswd.isEmpty() ) encpasswd = importPassword( encpasswd );
       }
-      setPasswd( decryptStr( encpasswd ), true );
-    } else
+
+      if ( !encpasswd.isEmpty() ) {
+        // migration to KWallet
+        setPasswd( decryptStr( encpasswd ), true );
+        config.deleteEntry( "pass" );
+        config.deleteEntry( "passwd" );
+        mPasswdDirty = true;
+      } else {
+        // read password if wallet is already open, otherwise defer to on-demand loading
+        if (Wallet::isOpen(Wallet::NetworkWallet()))
+          readPassword();
+      }
+
+    } else {
       setPasswd( "", false );
-    
+    }
+
     setHost( config.readEntry( "host" ) );
 
     unsigned int port = config.readUnsignedNumEntry( "port", defaultPort() );
     if ( port > USHRT_MAX ) port = defaultPort();
     setPort( port );
-    
+
     setAuth( config.readEntry( "auth", "*" ) );
     setUseSSL( config.readBoolEntry( "use-ssl", false ) );
     setUseTLS( config.readBoolEntry( "use-tls", false ) );
-    
+
     mSieveConfig.readConfig( config );
   }
 
@@ -159,8 +187,25 @@ namespace KMail {
 
     config.writeEntry( "login", login() );
     config.writeEntry( "store-passwd", storePasswd() );
-    if ( storePasswd() ) config.writeEntry( "pass", mPasswd ); // NOT passwd()
-    else config.writeEntry( "passwd", "" ); // ### ???? why two different keys?
+
+    // write password to the wallet if necessary
+    if ( storePasswd() && mPasswdDirty ) {
+      Wallet *wallet = kmkernel->wallet();
+      if (!wallet || wallet->writePassword("account-" + QString::number(mId), passwd()) ) {
+        KMessageBox::information(0, i18n("KWallet is not running. It is strongly recommend to use "
+            "KWallet for managing your password"),
+            i18n("KWallet is Not Running."), "KWalletWarning" );
+        config.writeEntry( "pass", encryptStr(passwd()) );
+      }
+    }
+
+    // delete password from the wallet if password storage is disabled
+    if (!storePasswd() && !Wallet::keyDoesNotExist(
+        Wallet::NetworkWallet(), "kmail", "account-" + QString::number(mId))) {
+      Wallet *wallet = kmkernel->wallet();
+      if (wallet)
+        wallet->removeEntry( "account-" + QString::number(mId) );
+    }
 
     config.writeEntry( "host", host() );
     config.writeEntry( "port", static_cast<unsigned int>( port() ) );
@@ -209,6 +254,22 @@ namespace KMail {
     setSieveConfig( n->sieveConfig() );
   }
 
+  void NetworkAccount::readPassword() {
+    if (!storePasswd())
+      return;
+
+    if ( Wallet::folderDoesNotExist(Wallet::NetworkWallet(), "kmail") ||
+          Wallet::keyDoesNotExist(Wallet::NetworkWallet(), "kmail", "account-" + QString::number(mId)) )
+      return;
+
+    if ( kmkernel->wallet() ) {
+      QString passwd;
+      kmkernel->wallet()->readPassword( "account-" + QString::number(mId), passwd );
+      setPasswd( passwd, true );
+      mPasswdDirty = false;
+    }
+  }
+
 } // namespace KMail
 
 #include "networkaccount.moc"
Index: networkaccount.h
===================================================================
RCS file: /home/kde/kdepim/kmail/networkaccount.h,v
retrieving revision 1.6
diff -u -p -r1.6 networkaccount.h
--- networkaccount.h	10 Mar 2004 18:41:27 -0000	1.6
+++ networkaccount.h	27 Aug 2004 14:45:29 -0000
@@ -110,6 +110,9 @@ namespace KMail {
     /** Kill all jobs that are currently in progress */
     virtual void killAllJobs( bool disconnectSlave = false ) = 0;
 
+    /** Read password from wallet, used for on-demand wallet opening */
+    void readPassword();
+
   protected:
     virtual QString protocol() const = 0;
     virtual unsigned short int defaultPort() const = 0;
@@ -123,6 +126,7 @@ namespace KMail {
     bool mUseSSL : 1;
     bool mUseTLS : 1;
     bool mAskAgain : 1;
+    bool mPasswdDirty;
 
   };
 
Index: transportmanager.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/transportmanager.cpp,v
retrieving revision 1.12
diff -u -p -r1.12 transportmanager.cpp
--- transportmanager.cpp	11 Jan 2004 21:57:08 -0000	1.12
+++ transportmanager.cpp	27 Aug 2004 14:45:29 -0000
@@ -20,6 +20,7 @@
 
 #include "kmtransport.h"
 #include "kmkernel.h"
+#include <kapplication.h>
 #include <kconfig.h>
 
 namespace KMail {
@@ -40,4 +41,28 @@ namespace KMail {
     return transportNames;
   }
 
+  // more or less copied from KMAcctMgr
+  uint TransportManager::createId()
+  {
+    QValueList<unsigned int> usedIds;
+
+    KConfigGroup general( KMKernel::config(), "General");
+    int numTransports = general.readNumEntry("transports", 0);
+
+    for ( int i = 1 ; i <= numTransports ; i++ ) {
+      KMTransportInfo ti;
+      ti.readConfig(i);
+      usedIds << ti.id();
+    }
+
+    usedIds << 0; // 0 is default for unknown
+    int newId;
+    do
+    {
+      newId = kapp->random();
+    } while ( usedIds.find(newId) != usedIds.end() );
+
+    return newId;
+  }
+
 } // namespace KMail
Index: transportmanager.h
===================================================================
RCS file: /home/kde/kdepim/kmail/transportmanager.h,v
retrieving revision 1.3
diff -u -p -r1.3 transportmanager.h
--- transportmanager.h	26 Jul 2003 14:51:50 -0000	1.3
+++ transportmanager.h	27 Aug 2004 14:45:29 -0000
@@ -25,13 +25,16 @@ namespace KMail {
    * @author Ingo Kloecker <kloecker@kde.org>
    **/
   class TransportManager {
-    
+
   public:
     TransportManager() {};
     virtual ~TransportManager() {};
-    
+
     /** Returns the list for transport names */
     static QStringList transportNames();
+
+    /** Create a unique id for a transport info item */
+    static unsigned int createId();
   };
 
 } // namespace KMail


_______________________________________________
KMail developers mailing list
KMail-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmail-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic