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

List:       kde-devel
Subject:    [KMail] Forgotten atachment detector
From:       Alexey Arzamasov <AArzamasov () kkb ! kz>
Date:       2003-08-19 8:33:41
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi ppl.
I getting 'round the KMail code, and saw this wish/feature-request on 
bugzilla:  http://bugs.kde.org/show_bug.cgi?id=62651
I made the patch which implements this functionality and want you to comment, 
fix the mistakes, if there are any, and then, maybe someone will commit it?

- -- 
  Arzamasov Alexey  ICQ 58961246
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/QkECYnQYd4hpr/wRAsmpAJ9qze/xbr6+1Nu9QE4b86HGUDla3gCbBP4T
P//k5EgvJWG3cl9vUQrDYks=
=y52w
-----END PGP SIGNATURE-----

["kmail-attach-detector.patch" (text/x-diff)]

diff -u3 -p -b -B ./old/configuredialog.cpp ./new/configuredialog.cpp
--- ./old/configuredialog.cpp	Sun Jul 13 19:30:03 2003
+++ ./new/configuredialog.cpp	Mon Aug 18 17:47:13 2003
@@ -2324,6 +2324,12 @@ ComposerPage::ComposerPage( QWidget * pa
   //
   mHeadersTab = new HeadersTab();
   addTab( mHeadersTab, mHeadersTab->title() );
+
+  //
+  // "Misc" tab:
+  //
+  mMiscTab = new MiscTab();
+  addTab( mMiscTab, mMiscTab->title() );
 }
 
 
@@ -3075,6 +3081,75 @@ void ComposerPage::HeadersTab::apply() {
   general.writeEntry( "mime-header-count", numValidEntries );
 }
 
+QString ComposerPage::MiscTab::title() {
+    return i18n("Misc");
+}
+
+QString ComposerPage::MiscTab::helpAnchor() const {
+    return QString::fromLatin1("configure-composer-misc");
+}
+
+ComposerPageMiscTab::ComposerPageMiscTab( QWidget * parent, const char * name )
+        : ConfigurationPage( parent, name ) {
+    // tmp. vars:
+    QVBoxLayout *vlay;
+    QGroupBox   *group;
+    QLabel      *label;
+
+    vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
+
+    group = new QVGroupBox( i18n("Forgotten &attachment detector"), this );
+    group->layout()->setSpacing( KDialog::spacingHint() );
+
+    // row 0: help text:
+    label = new QLabel( i18n("Recognize any of the following strings as intention to \
attach a file\n" +                             "(entries are case-insensitive \
alternatives):"), group ); +    label->setAlignment( AlignLeft|WordBreak );
+
+    // row 1, string list editor:
+    SimpleStringListEditor::ButtonCode buttonCode =
+        static_cast<SimpleStringListEditor::ButtonCode>( \
SimpleStringListEditor::Add|SimpleStringListEditor::Remove ); +    \
mAttachWordsListEditor = +        new SimpleStringListEditor( group, 0, buttonCode,
+                                    i18n("A&dd..."), i18n("Re&move"),
+                                    QString::null,
+                                    i18n("Enter new \"attachment\" synonym:") );
+
+    mUseRegexpCheck =
+        new QCheckBox( i18n("&Use additional regular expresion"), group );
+
+    mRegexpEdit =  new QLineEdit(group);
+    mRegexpEdit->setReadOnly(true);
+    connect (mUseRegexpCheck, SIGNAL(toggled(bool)), this, \
SLOT(regexpCheckToggled(bool))); +
+
+    vlay->addWidget( group );
+
+}
+
+void ComposerPage::MiscTab::regexpCheckToggled(bool on) {
+    mRegexpEdit->setReadOnly ( !on );
+}
+
+void ComposerPage::MiscTab::apply() {
+    KConfigGroup composer( kapp->config(), "Composer" );
+    composer.writeEntry("attachment-synonyms", \
mAttachWordsListEditor->stringList()); +    \
composer.writeEntry("attachment-detect-use-regexp", mUseRegexpCheck->isChecked()); +  \
composer.writeEntry("attachment-detect-regexp", mRegexpEdit->text()); +}
+
+void ComposerPage::MiscTab::setup() {
+    KConfigGroup composer( kapp->config(), "Composer" );
+
+    QStringList attachWordsList = composer.readListEntry( "attachment-synonyms", ',' \
); +    if ( attachWordsList.isEmpty() )
+        // default value
+        attachWordsList << i18n("attachment");
+    mAttachWordsListEditor->setStringList( attachWordsList );
+
+    mUseRegexpCheck->setChecked( \
composer.readBoolEntry("attachment-detect-use-regexp", false ) ); +    \
mRegexpEdit->setText(composer.readEntry("attachment-detect-regexp", "")); +}
 
 // *************************************************************
 // *                                                           *
diff -u3 -p -b -B ./old/configuredialog_p.h ./new/configuredialog_p.h
--- ./old/configuredialog_p.h	Sun Jul 13 19:30:03 2003
+++ ./new/configuredialog_p.h	Mon Aug 18 17:55:23 2003
@@ -682,6 +682,34 @@ protected:
   QLabel      *mTagValueLabel;
 };
 
+class ComposerPageMiscTab : public ConfigurationPage {
+    Q_OBJECT
+public:
+    ComposerPageMiscTab( QWidget * parent=0, const char * name=0 );
+
+    // no icon
+    static QString iconLabel() {
+        return QString::null;
+    }
+    static const char * iconName() {
+        return 0;
+    }
+
+    static QString title();
+    QString helpAnchor() const;
+
+    void setup();
+    void apply();
+
+protected:
+    SimpleStringListEditor *mAttachWordsListEditor;
+    QCheckBox              *mUseRegexpCheck;
+    QLineEdit                 *mRegexpEdit;
+
+protected slots:
+    void regexpCheckToggled(bool on);
+};
+
 class ComposerPage : public TabbedConfigurationPage {
   Q_OBJECT
 public:
@@ -698,6 +726,7 @@ public:
   typedef ComposerPageSubjectTab SubjectTab;
   typedef ComposerPageCharsetTab CharsetTab;
   typedef ComposerPageHeadersTab HeadersTab;
+  typedef ComposerPageMiscTab MiscTab;
 
 protected:
   GeneralTab  *mGeneralTab;
@@ -705,6 +734,7 @@ protected:
   SubjectTab  *mSubjectTab;
   CharsetTab  *mCharsetTab;
   HeadersTab  *mHeadersTab;
+  MiscTab  *mMiscTab;
 };
 
 //
diff -u3 -p -b -B ./old/kmcomposewin.cpp ./new/kmcomposewin.cpp
--- ./old/kmcomposewin.cpp	Sun Jul 13 19:30:04 2003
+++ ./new/kmcomposewin.cpp	Mon Aug 18 17:49:04 2003
@@ -1382,6 +1382,43 @@ bool KMComposeWin::applyChanges(void)
     return FALSE;
   }
 
+  if (mAtmList.count() == 0) {
+      KConfigGroup composer( kapp->config(), "Composer" );
+
+      QStringList attachWordsList = composer.readListEntry( "attachment-synonyms", \
',' ); +      QRegExp customRx;
+      bool useCustomRx;
+
+      if ( attachWordsList.isEmpty() )
+          // default value
+          attachWordsList << i18n("attachment");
+
+      useCustomRx = composer.readBoolEntry("attachment-detect-use-regexp", false );
+      if ( useCustomRx )
+          customRx = composer.readEntry("attachment-detect-regexp", "");
+
+      QString body = mEditor->text();
+      QRegExp rx (attachWordsList.join("|"));
+      rx.setCaseSensitive(false);
+      if ( (rx.search(body) >= 0) ||
+           (useCustomRx && (customRx.search(body) >=0))
+         ) {
+             int rc = KMessageBox::warningYesNoCancel(this,
+                     i18n("It's seems that the message you have composed need to \
have an attachment, but actually don't have it.\nDo you want to add an attachment?"), \
+                     i18n("No Attachment"), +                     i18n("&Attach \
file..."), +                     i18n("&Send as is"));
+             if (rc == KMessageBox::Cancel)
+                 return false;
+             else if (rc == KMessageBox::Yes) {
+                slotAttachFile();
+
+              //preceed with editing
+              return false;
+          }
+      }
+  }
+
   bccMsgList.clear();
 
   if (bAutoCharset) {



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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