[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-bugs-dist
Subject: [Bug 1015] kmail should have templates
From: Don Sanders <don () sanders ! org>
Date: 2004-12-31 6:12:07
Message-ID: 20041231061207.13279.qmail () ktown ! kde ! org
[Download RAW message or body]
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
http://bugs.kde.org/show_bug.cgi?id=1015
------- Additional Comments From don sanders org 2004-12-31 07:12 -------
CVS commit by sanders:
Add an Insert Recent File action to the composer Message menu, as discussed with \
Ingo.
This can act as a thrifty man's template system; put your often used phrases in \
descriptively named files and then quic kly insert them again using the Insert Recent \
File popup menu.
Later on files with a specific suffix, say, .template could be passed for, say, '%' \
quoted commands like %DATE etc.
Hopefully the implementation is ok. There's a bit of code to make sure the encoding \
used when inserting a recent file i s the same as when the file was inserted using \
the modified file dialog that includes an encoding combobox. Also some l ogic is \
required to stop the config file from growing without bound.
CCMAIL:1015 bugs kde org
M +2 -1 kmcomposerui.rc 1.37
M +52 -2 kmcomposewin.cpp 1.901
M +3 -0 kmcomposewin.h 1.268
--- kdepim/kmail/kmcomposerui.rc #1.36:1.37
@ -1,3 +1,3 @
-<!DOCTYPE kpartgui ><kpartgui version="23" name="kmcomposer" >
+<!DOCTYPE kpartgui ><kpartgui version="24" name="kmcomposer" >
<MenuBar>
<Menu noMerge="1" name="file" >
@ -11,4 +11,5 @
<Separator/>
<Action name="insert_file" />
+ <Action name="insert_file_recent" />
<Action name="file_print" />
<Separator/>
--- kdepim/kmail/kmcomposewin.h #1.267:1.268
@ -65,4 +65,5 @ class KToggleAction;
class KSelectColorAction;
class KURL;
+class KRecentFilesAction;
class SpellingFilter;
class MessageComposer;
@ -406,4 +407,5 @ public slots:
void slotPrint();
void slotAttachFile();
+ void slotInsertRecentFile(const KURL&);
void slotSendNow();
void slotSendLater();
@ -824,4 +826,5 @ protected:
KAction *mAttachPK, *mAttachMPK,
*mAttachRemoveAction, *mAttachSaveAction, *mAttachPropertiesAction;
+ KRecentFilesAction *mRecentAction;
KToggleAction *mSignAction, *mEncryptAction, *mRequestMDNAction;
--- kdepim/kmail/kmcomposewin.cpp #1.900:1.901
@ -91,4 +91,5 @ using KRecentAddress::RecentAddresses;
#include <kstatusbar.h>
#include <kaction.h>
+#include <kstdaction.h>
#include <kdirwatch.h>
#include <kstdguiitem.h>
@ -934,4 +935,11 @ void KMComposeWin::setupActions(void)
this, SLOT(slotInsertFile()),
actionCollection(), "insert_file");
+ mRecentAction = new KRecentFilesAction (i18n("&Insert File Recent"),
+ "fileopen", 0,
+ this, SLOT(slotInsertRecentFile(const KURL&)),
+ actionCollection(), "insert_file_recent");
+
+ mRecentAction->loadEntries( KMKernel::config() );
+
(void) new KAction (i18n("&Address Book"), "contents",0,
this, SLOT(slotAddrBook()),
@ -2366,5 +2374,37 @ void KMComposeWin::slotInsertFile()
KURL u = fdlg.selectedURL();
+ mRecentAction->addURL(u);
+ // Prevent race condition updating list when multiple composers are open
+ {
+ KConfig *config = KMKernel::config();
+ KConfigGroupSaver saver( config, "Composer" );
+ QString encoding = \
KGlobal::charsets()->encodingForName(combo->currentText()).latin1(); + QStringList \
urls = config->readListEntry( "recent-urls" ); + QStringList encodings = \
config->readListEntry( "recent-encodings" ); + // Prevent config file from growing \
without bound + // Would be nicer to get this constant from KRecentFilesAction
+ uint mMaxRecentFiles = 30;
+ while (urls.count() > mMaxRecentFiles)
+ urls.erase( urls.fromLast() );
+ while (encodings.count() > mMaxRecentFiles)
+ urls.erase( encodings.fromLast() );
+ // sanity check
+ if (urls.count() != encodings.count()) {
+ urls.clear();
+ encodings.clear();
+ }
+ urls.prepend( u.prettyURL() );
+ encodings.prepend( encoding );
+ config->writeEntry( "recent-urls", urls );
+ config->writeEntry( "recent-encodings", encodings );
+ mRecentAction->saveEntries( config );
+ }
+ slotInsertRecentFile(u);
+}
+
+//-----------------------------------------------------------------------------
+void KMComposeWin::slotInsertRecentFile(const KURL& u)
+{
if (u.fileName().isEmpty()) return;
@ -2374,6 +2414,16 @ void KMComposeWin::slotInsertFile()
ld.data = QByteArray();
ld.insert = true;
- ld.encoding = KGlobal::charsets()->encodingForName(
- combo->currentText()).latin1();
+ // Get the encoding previously used when inserting this file
+ {
+ KConfig *config = KMKernel::config();
+ KConfigGroupSaver saver( config, "Composer" );
+ QStringList urls = config->readListEntry( "recent-urls" );
+ QStringList encodings = config->readListEntry( "recent-encodings" );
+ int index = urls.findIndex( u.prettyURL() );
+ if (index != -1) {
+ QString encoding = encodings[ index ];
+ ld.encoding = encoding.latin1();
+ }
+ }
mMapAtmLoadData.insert(job, ld);
connect(job, SIGNAL(result(KIO::Job *)),
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic