kmail

templatesinsertcommand.cpp
1 /*
2  * kmail: KDE mail client
3  * This file: Copyright (C) 2006 Dmitry Morozhnikov <dmiceman@mail.ru>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #include <config.h>
22 
23 #include <tqpushbutton.h>
24 #include <tdeaction.h>
25 #include <tdeactionclasses.h>
26 #include <tdepopupmenu.h>
27 #include <tdelocale.h>
28 #include <tqsignalmapper.h>
29 #include <kdebug.h>
30 
31 #include "templatesinsertcommand.h"
32 
33 TemplatesInsertCommand::TemplatesInsertCommand( TQWidget *parent,
34  const char *name )
35  : TQPushButton( parent, name )
36 {
37  setText( i18n( "&Insert Command..." ) );
38  connect( this, TQ_SIGNAL( clicked() ),
39  this, TQ_SLOT( slotClicked() ) );
40 
41  TDEAction *action;
42  TDEActionMenu *menu;
43 
44  TQSignalMapper *mapper = new TQSignalMapper( this );
45  connect( mapper, TQ_SIGNAL( mapped(int) ),
46  this, TQ_SLOT( slotMapped(int) ) );
47 
48  mMenu = new TDEActionMenu( i18n( "Insert Command..." ), this );
49 
50  // ******************************************************
51  menu = new TDEActionMenu( i18n( "Original Message" ), mMenu );
52  mMenu->insert( menu );
53 
54  action = new TDEAction( i18n("Quoted Message"),
55  0, mapper, TQ_SLOT( map() ), menu );
56  mapper->setMapping( action, CQuote );
57  menu->insert( action );
58  action = new TDEAction( i18n("Message Text as Is"),
59  0, mapper, TQ_SLOT( map() ), menu );
60  mapper->setMapping( action, CText );
61  menu->insert( action );
62  action = new TDEAction( i18n("Message Id"),
63  0, mapper, TQ_SLOT( map() ), menu );
64  mapper->setMapping( action, COMsgId );
65  menu->insert( action );
66  action = new TDEAction( i18n("Date"),
67  0, mapper, TQ_SLOT( map() ), menu );
68  mapper->setMapping( action, CODate );
69  menu->insert( action );
70  action = new TDEAction( i18n("Date in Short Format"),
71  0, mapper, TQ_SLOT( map() ), menu );
72  mapper->setMapping( action, CODateShort );
73  menu->insert( action );
74  action = new TDEAction( i18n("Date in C Locale"),
75  0, mapper, TQ_SLOT( map() ), menu );
76  mapper->setMapping( action, CODateEn );
77  menu->insert( action );
78  action = new TDEAction( i18n("Day of Week"),
79  0, mapper, TQ_SLOT( map() ), menu );
80  mapper->setMapping( action, CODow );
81  menu->insert( action );
82  action = new TDEAction( i18n("Time"),
83  0, mapper, TQ_SLOT( map() ), menu );
84  mapper->setMapping( action, COTime );
85  menu->insert( action );
86  action = new TDEAction( i18n("Time in Long Format"),
87  0, mapper, TQ_SLOT( map() ), menu );
88  mapper->setMapping( action, COTimeLong );
89  menu->insert( action );
90  action = new TDEAction( i18n("Time in C Locale"),
91  0, mapper, TQ_SLOT( map() ), menu );
92  mapper->setMapping( action, COTimeLongEn );
93  menu->insert( action );
94  action = new TDEAction( i18n("To Field Address"),
95  0, mapper, TQ_SLOT( map() ), menu );
96  mapper->setMapping( action, COToAddr );
97  menu->insert( action );
98  action = new TDEAction( i18n("To Field Name"),
99  0, mapper, TQ_SLOT( map() ), menu );
100  mapper->setMapping( action, COToName );
101  menu->insert( action );
102  action = new TDEAction( i18n("To Field First Name"),
103  0, mapper, TQ_SLOT( map() ), menu );
104  mapper->setMapping( action, COToFName );
105  menu->insert( action );
106  action = new TDEAction( i18n("To Field Last Name"),
107  0, mapper, TQ_SLOT( map() ), menu );
108  mapper->setMapping( action, COToLName );
109  menu->insert( action );
110  action = new TDEAction( i18n( "CC Field Address" ),
111  0, mapper, TQ_SLOT( map() ), menu );
112  mapper->setMapping( action, COCCAddr );
113  menu->insert( action );
114  action = new TDEAction( i18n( "CC Field Name" ),
115  0, mapper, TQ_SLOT( map() ), menu );
116  mapper->setMapping( action, COCCName );
117  menu->insert( action );
118  action = new TDEAction( i18n( "CC Field First Name" ),
119  0, mapper, TQ_SLOT( map() ), menu );
120  mapper->setMapping( action, COCCFName );
121  menu->insert( action );
122  action = new TDEAction( i18n( "CC Field Last Name" ),
123  0, mapper, TQ_SLOT( map() ), menu );
124  mapper->setMapping( action, COCCLName );
125  menu->insert( action );
126  action = new TDEAction( i18n( "From Field Address" ),
127  0, mapper, TQ_SLOT( map() ), menu );
128  mapper->setMapping( action, COFromAddr );
129  menu->insert( action );
130  action = new TDEAction( i18n( "From Field Name" ),
131  0, mapper, TQ_SLOT( map() ), menu );
132  mapper->setMapping( action, COFromName );
133  menu->insert( action );
134  action = new TDEAction( i18n( "From Field First Name" ),
135  0, mapper, TQ_SLOT( map() ), menu );
136  mapper->setMapping( action, COFromFName );
137  menu->insert( action );
138  action = new TDEAction( i18n( "From Field Last Name" ),
139  0, mapper, TQ_SLOT( map() ), menu );
140  mapper->setMapping( action, COFromLName );
141  menu->insert( action );
142  action = new TDEAction( i18n( "Addresses of all original recipients" ),
143  0, mapper, TQ_SLOT( map() ), menu );
144  mapper->setMapping( action, COAddresseesAddr );
145  action = new TDEAction( i18n( "Subject" ),
146  0, mapper, TQ_SLOT( map() ), menu );
147  mapper->setMapping( action, COFullSubject );
148  menu->insert( action );
149  action = new TDEAction( i18n( "Quoted Headers" ),
150  0, mapper, TQ_SLOT( map() ), menu );
151  mapper->setMapping( action, CTQHeaders );
152  menu->insert( action );
153  action = new TDEAction( i18n( "Headers as Is" ),
154  0, mapper, TQ_SLOT( map() ), menu );
155  mapper->setMapping( action, CHeaders );
156  menu->insert( action );
157  action = new TDEAction( i18n( "Header Content" ),
158  0, mapper, TQ_SLOT( map() ), menu );
159  mapper->setMapping( action, COHeader );
160  menu->insert( action );
161 
162  // ******************************************************
163  menu = new TDEActionMenu( i18n( "Current Message" ), mMenu );
164  mMenu->insert( menu );
165 
166  action = new TDEAction( i18n( "Message Id" ),
167  0, mapper, TQ_SLOT( map() ), menu );
168  mapper->setMapping( action, CMsgId );
169  menu->insert( action );
170  action = new TDEAction( i18n( "Date" ),
171  0, mapper, TQ_SLOT( map() ), menu );
172  mapper->setMapping( action, CDate );
173  menu->insert( action );
174  action = new TDEAction( i18n( "Date in Short Format" ),
175  0, mapper, TQ_SLOT( map() ), menu );
176  mapper->setMapping( action, CDateShort );
177  menu->insert( action );
178  action = new TDEAction( i18n( "Date in C Locale" ),
179  0, mapper, TQ_SLOT( map() ), menu );
180  mapper->setMapping( action, CDateEn );
181  menu->insert( action );
182  action = new TDEAction( i18n( "Day of Week" ),
183  0, mapper, TQ_SLOT( map() ), menu );
184  mapper->setMapping( action, CDow );
185  menu->insert( action );
186  action = new TDEAction( i18n( "Time" ),
187  0, mapper, TQ_SLOT( map() ), menu );
188  mapper->setMapping( action, CTime );
189  menu->insert( action );
190  action = new TDEAction( i18n( "Time in Long Format" ),
191  0, mapper, TQ_SLOT( map() ), menu );
192  mapper->setMapping( action, CTimeLong );
193  menu->insert( action );
194  action = new TDEAction( i18n( "Time in C Locale" ),
195  0, mapper, TQ_SLOT( map() ), menu );
196  mapper->setMapping( action, CTimeLongEn );
197  menu->insert( action );
198  action = new TDEAction( i18n( "To Field Address" ),
199  0, mapper, TQ_SLOT( map() ), menu );
200  mapper->setMapping( action, CToAddr );
201  menu->insert( action );
202  action = new TDEAction( i18n( "To Field Name" ),
203  0, mapper, TQ_SLOT( map() ), menu );
204  mapper->setMapping( action, CToName );
205  menu->insert( action );
206  action = new TDEAction( i18n( "To Field First Name" ),
207  0, mapper, TQ_SLOT( map() ), menu );
208  mapper->setMapping( action, CToFName );
209  menu->insert( action );
210  action = new TDEAction( i18n( "To Field Last Name" ),
211  0, mapper, TQ_SLOT( map() ), menu );
212  mapper->setMapping( action, CToLName );
213  menu->insert( action );
214  action = new TDEAction( i18n( "CC Field Address" ),
215  0, mapper, TQ_SLOT( map() ), menu );
216  mapper->setMapping( action, CCCAddr );
217  menu->insert( action );
218  action = new TDEAction( i18n( "CC Field Name" ),
219  0, mapper, TQ_SLOT( map() ), menu );
220  mapper->setMapping( action, CCCName );
221  menu->insert( action );
222  action = new TDEAction( i18n( "CC Field First Name" ),
223  0, mapper, TQ_SLOT( map() ), menu );
224  mapper->setMapping( action, CCCFName );
225  menu->insert( action );
226  action = new TDEAction( i18n( "CC Field Last Name" ),
227  0, mapper, TQ_SLOT( map() ), menu );
228  mapper->setMapping( action, CCCLName );
229  menu->insert( action );
230  action = new TDEAction( i18n( "From Field Address" ),
231  0, mapper, TQ_SLOT( map() ), menu );
232  mapper->setMapping( action, CFromAddr );
233  menu->insert( action );
234  action = new TDEAction( i18n( "From Field Name" ),
235  0, mapper, TQ_SLOT( map() ), menu );
236  mapper->setMapping( action, CFromName );
237  menu->insert( action );
238  action = new TDEAction( i18n( "From Field First Name" ),
239  0, mapper, TQ_SLOT( map() ), menu );
240  mapper->setMapping( action, CFromFName );
241  menu->insert( action );
242  action = new TDEAction( i18n( "From Field Last Name" ),
243  0, mapper, TQ_SLOT( map() ), menu );
244  mapper->setMapping( action, CFromLName );
245  menu->insert( action );
246  action = new TDEAction( i18n( "Subject" ),
247  0, mapper, TQ_SLOT( map() ), menu );
248  mapper->setMapping( action, CFullSubject );
249  menu->insert( action );
250  action = new TDEAction( i18n( "Header Content" ),
251  0, mapper, TQ_SLOT( map() ), menu );
252  mapper->setMapping( action, CHeader );
253  menu->insert( action );
254 
255  // ******************************************************
256  menu = new TDEActionMenu( i18n( "Process With External Programs" ), mMenu );
257  mMenu->insert( menu );
258 
259  action = new TDEAction( i18n( "Insert Result of Command" ),
260  0, mapper, TQ_SLOT( map() ), menu );
261  mapper->setMapping( action, CSystem );
262  menu->insert( action );
263  action = new TDEAction( i18n( "Pipe Original Message Body and Insert Result as Quoted Text" ),
264  0, mapper, TQ_SLOT( map() ), menu );
265  mapper->setMapping( action, CQuotePipe );
266  menu->insert( action );
267  action = new TDEAction( i18n( "Pipe Original Message Body and Insert Result as Is" ),
268  0, mapper, TQ_SLOT( map() ), menu );
269  mapper->setMapping( action, CTextPipe );
270  menu->insert( action );
271  action = new TDEAction( i18n( "Pipe Original Message with Headers and Insert Result as Is" ),
272  0, mapper, TQ_SLOT( map() ), menu );
273  mapper->setMapping( action, CMsgPipe );
274  menu->insert( action );
275  action = new TDEAction( i18n( "Pipe Current Message Body and Insert Result as Is" ),
276  0, mapper, TQ_SLOT( map() ), menu );
277  mapper->setMapping( action, CBodyPipe );
278  menu->insert( action );
279  action = new TDEAction( i18n( "Pipe Current Message Body and Replace with Result" ),
280  0, mapper, TQ_SLOT( map() ), menu );
281  mapper->setMapping( action, CClearPipe );
282  menu->insert( action );
283 
284  // ******************************************************
285  menu = new TDEActionMenu( i18n( "Miscellaneous" ), mMenu );
286  mMenu->insert( menu );
287 
288  action = new TDEAction( i18n( "Set Cursor Position" ),
289  0, mapper, TQ_SLOT( map() ), menu );
290  mapper->setMapping( action, CCursor );
291  menu->insert( action );
292  action = new TDEAction( i18n( "Insert File Content" ),
293  0, mapper, TQ_SLOT( map() ), menu );
294  mapper->setMapping( action, CInsert );
295  menu->insert( action );
296  action = new TDEAction( i18n( "DNL" ),
297  0, mapper, TQ_SLOT( map() ), menu );
298  mapper->setMapping( action, CDnl );
299  menu->insert( action );
300  action = new TDEAction( i18n( "Template Comment" ),
301  0, mapper, TQ_SLOT( map() ), menu );
302  mapper->setMapping( action, CRem );
303  menu->insert( action );
304  action = new TDEAction( i18n( "No Operation" ),
305  0, mapper, TQ_SLOT( map() ), menu );
306  mapper->setMapping( action, CNop );
307  menu->insert( action );
308  action = new TDEAction( i18n( "Clear Generated Message" ),
309  0, mapper, TQ_SLOT( map() ), menu );
310  mapper->setMapping( action, CClear );
311  menu->insert( action );
312  action = new TDEAction( i18n( "Turn Debug On" ),
313  0, mapper, TQ_SLOT( map() ), menu );
314  mapper->setMapping( action, CDebug );
315  menu->insert( action );
316  action = new TDEAction( i18n( "Turn Debug Off" ),
317  0, mapper, TQ_SLOT( map() ), menu );
318  mapper->setMapping( action, CDebugOff );
319  menu->insert( action );
320 }
321 
322 TemplatesInsertCommand::~TemplatesInsertCommand()
323 {
324 }
325 
326 void TemplatesInsertCommand::slotClicked()
327 {
328  TQSize ps = mMenu->popupMenu()->sizeHint();
329  mMenu->popup( mapToGlobal( TQPoint( 0, -(ps.height()) ) ) );
330 }
331 
332 void TemplatesInsertCommand::slotMapped( int cmd )
333 {
334  emit insertCommand( static_cast<Command>( cmd ) );
335 
336  switch( cmd ) {
337  case TemplatesInsertCommand::CQuote: emit insertCommand("%QUOTE"); break;
338  case TemplatesInsertCommand::CText: emit insertCommand("%TEXT"); break;
339  case TemplatesInsertCommand::COMsgId: emit insertCommand("%OMSGID"); break;
340  case TemplatesInsertCommand::CODate: emit insertCommand("%ODATE"); break;
341  case TemplatesInsertCommand::CODateShort: emit insertCommand("%ODATESHORT"); break;
342  case TemplatesInsertCommand::CODateEn: emit insertCommand("%ODATEEN"); break;
343  case TemplatesInsertCommand::CODow: emit insertCommand("%ODOW"); break;
344  case TemplatesInsertCommand::COTime: emit insertCommand("%OTIME"); break;
345  case TemplatesInsertCommand::COTimeLong: emit insertCommand("%OTIMELONG"); break;
346  case TemplatesInsertCommand::COTimeLongEn: emit insertCommand("%OTIMELONGEN"); break;
347  case TemplatesInsertCommand::COToAddr: emit insertCommand("%OTOADDR"); break;
348  case TemplatesInsertCommand::COToName: emit insertCommand("%OTONAME"); break;
349  case TemplatesInsertCommand::COToFName: emit insertCommand("%OTOFNAME"); break;
350  case TemplatesInsertCommand::COToLName: emit insertCommand("%OTOLNAME"); break;
351  case TemplatesInsertCommand::COCCAddr: emit insertCommand("%OCCADDR"); break;
352  case TemplatesInsertCommand::COCCName: emit insertCommand("%OCCNAME"); break;
353  case TemplatesInsertCommand::COCCFName: emit insertCommand("%OCCFNAME"); break;
354  case TemplatesInsertCommand::COCCLName: emit insertCommand("%OCCLNAME"); break;
355  case TemplatesInsertCommand::COFromAddr: emit insertCommand("%OFROMADDR"); break;
356  case TemplatesInsertCommand::COFromName: emit insertCommand("%OFROMNAME"); break;
357  case TemplatesInsertCommand::COFromFName: emit insertCommand("%OFROMFNAME"); break;
358  case TemplatesInsertCommand::COFromLName: emit insertCommand("%OFROMLNAME"); break;
359  case TemplatesInsertCommand::COFullSubject: emit insertCommand("%OFULLSUBJECT"); break;
360  case TemplatesInsertCommand::CTQHeaders: emit insertCommand("%TQHEADERS"); break;
361  case TemplatesInsertCommand::CHeaders: emit insertCommand("%HEADERS"); break;
362  case TemplatesInsertCommand::COHeader: emit insertCommand("%OHEADER=\"\"", -1); break;
363  case TemplatesInsertCommand::CMsgId: emit insertCommand("%MSGID"); break;
364  case TemplatesInsertCommand::CDate: emit insertCommand("%DATE"); break;
365  case TemplatesInsertCommand::CDateShort: emit insertCommand("%DATESHORT"); break;
366  case TemplatesInsertCommand::CDateEn: emit insertCommand("%DATEEN"); break;
367  case TemplatesInsertCommand::CDow: emit insertCommand("%DOW"); break;
368  case TemplatesInsertCommand::CTime: emit insertCommand("%TIME"); break;
369  case TemplatesInsertCommand::CTimeLong: emit insertCommand("%TIMELONG"); break;
370  case TemplatesInsertCommand::CTimeLongEn: emit insertCommand("%TIMELONGEN"); break;
371  case TemplatesInsertCommand::COAddresseesAddr: emit insertCommand("%OADDRESSEESADDR"); break;
372  case TemplatesInsertCommand::CToAddr: emit insertCommand("%TOADDR"); break;
373  case TemplatesInsertCommand::CToName: emit insertCommand("%TONAME"); break;
374  case TemplatesInsertCommand::CToFName: emit insertCommand("%TOFNAME"); break;
375  case TemplatesInsertCommand::CToLName: emit insertCommand("%TOLNAME"); break;
376  case TemplatesInsertCommand::CCCAddr: emit insertCommand("%CCADDR"); break;
377  case TemplatesInsertCommand::CCCName: emit insertCommand("%CCNAME"); break;
378  case TemplatesInsertCommand::CCCFName: emit insertCommand("%CCFNAME"); break;
379  case TemplatesInsertCommand::CCCLName: emit insertCommand("%CCLNAME"); break;
380  case TemplatesInsertCommand::CFromAddr: emit insertCommand("%FROMADDR"); break;
381  case TemplatesInsertCommand::CFromName: emit insertCommand("%FROMNAME"); break;
382  case TemplatesInsertCommand::CFromFName: emit insertCommand("%FROMFNAME"); break;
383  case TemplatesInsertCommand::CFromLName: emit insertCommand("%FROMLNAME"); break;
384  case TemplatesInsertCommand::CFullSubject: emit insertCommand("%FULLSUBJECT"); break;
385  case TemplatesInsertCommand::CHeader: emit insertCommand("%HEADER=\"\"", -1); break;
386  case TemplatesInsertCommand::CSystem: emit insertCommand("%SYSTEM=\"\"", -1); break;
387  case TemplatesInsertCommand::CQuotePipe: emit insertCommand("%QUOTEPIPE=\"\"", -1); break;
388  case TemplatesInsertCommand::CTextPipe: emit insertCommand("%TEXTPIPE=\"\"", -1); break;
389  case TemplatesInsertCommand::CMsgPipe: emit insertCommand("%MSGPIPE=\"\"", -1); break;
390  case TemplatesInsertCommand::CBodyPipe: emit insertCommand("%BODYPIPE=\"\"", -1); break;
391  case TemplatesInsertCommand::CClearPipe: emit insertCommand("%CLEARPIPE=\"\"", -1); break;
392  case TemplatesInsertCommand::CCursor: emit insertCommand("%CURSOR"); break;
393  case TemplatesInsertCommand::CInsert: emit insertCommand("%INSERT=\"\"", -1); break;
394  case TemplatesInsertCommand::CDnl: emit insertCommand("%-"); break;
395  case TemplatesInsertCommand::CRem: emit insertCommand("%REM=\"\"", -1); break;
396  case TemplatesInsertCommand::CNop: emit insertCommand("%NOP"); break;
397  case TemplatesInsertCommand::CClear: emit insertCommand("%CLEAR"); break;
398  case TemplatesInsertCommand::CDebug: emit insertCommand("%DEBUG"); break;
399  case TemplatesInsertCommand::CDebugOff: emit insertCommand("%DEBUGOFF"); break;
400  default:
401  kdDebug() << "Unknown template command index: " << cmd << endl;
402  break;
403  }
404 }
405 
406 #include "templatesinsertcommand.moc"