1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
// $Id$
// (c) 2001, Cornelius Schumacher
#include <ktextedit.h>
#include <tqlayout.h>
#include <klocale.h>
#include <kdebug.h>
#include <tqcombobox.h>
#include <tqsplitter.h>
#include <tqlabel.h>
#include "messageeditor.h"
#include "kbbprefs.h"
#include "bugsystem.h"
#include "bugcommand.h"
#include "msginputdialog.h"
#include "msginputdialog.moc"
MsgInputDialog::MsgInputDialog(MsgInputDialog::MessageType type, const Bug &bug,
const Package &package, const TQString "edMsg,
TQWidget *parent)
: KDialogBase(Plain,TQString(),User1|User2|Ok|Cancel,Ok,parent,0,false,
true,KStdGuiItem::clear(),i18n( "&Edit Presets..." )),
mBug( bug ),
mPackage( package ),
mType( type )
{
switch ( mType ) {
case Close:
setCaption( i18n("Close Bug %1").arg( mBug.number() ) );
break;
case Reply:
setCaption( i18n("Reply to Bug") );
break;
case ReplyPrivate:
setCaption( i18n("Reply Privately to Bug") );
break;
default:
break;
}
TQFrame *topFrame = plainPage();
( new TQHBoxLayout( topFrame ) )->setAutoAdd( true );
mSplitter = new TQSplitter( Qt::Horizontal, topFrame );
TQWidget *w = new TQWidget( mSplitter );
( new TQVBoxLayout( w, spacingHint(), -1 ) )->setAutoAdd( true );
if ( mType == Reply ) {
TQWidget *r = new TQWidget( w );
TQHBoxLayout* rtqlayout = new TQHBoxLayout( r );
TQLabel *rlabel = new TQLabel( i18n("&Recipient:"),r );
TQFont f = r->font();
f.setBold( true );
r->setFont( f );
rtqlayout->add( rlabel );
mRecipient = new TQComboBox( r );
mRecipient->insertItem( i18n("Normal (bugs.kde.org & Maintainer & kde-bugs-dist)"), BugCommand::Normal );
mRecipient->insertItem( i18n("Maintonly (bugs.kde.org & Maintainer)"), BugCommand::Maintonly );
mRecipient->insertItem( i18n("Quiet (bugs.kde.org only)"), BugCommand::Quiet );
rlabel->setBuddy( mRecipient );
rtqlayout->add( mRecipient );
TQSpacerItem *rspacer= new TQSpacerItem( 1,1,TQSizePolicy::Expanding );
rtqlayout->addItem( rspacer );
// Reply currently only replies to the bug tracking system
r->hide();
}
TQLabel *l = new TQLabel( i18n( "&Message" ), w );
TQFont f = l->font();
f.setBold( true );
l->setFont( f );
mMessageEdit = new KTextEdit( w );
mMessageEdit->setMinimumWidth( mMessageEdit->fontMetrics().width('x') * 72 );
mMessageEdit->setWordWrap( TQTextEdit::FixedColumnWidth );
mMessageEdit->setWrapColumnOrWidth( 72 );
l->setBuddy( mMessageEdit );
w = new TQWidget( mSplitter );
( new TQVBoxLayout( w, spacingHint(), -1 ) )->setAutoAdd( true );
l = new TQLabel( i18n( "&Preset Messages" ), w );
l->setFont( f );
mPresets = new KListBox( w );
updatePresets();
l->setBuddy( mPresets );
connect( mPresets, TQT_SIGNAL( executed( TQListBoxItem* ) ),
TQT_SLOT( slotPresetSelected( TQListBoxItem * ) ) );
connect( this, TQT_SIGNAL( user2Clicked() ), TQT_SLOT( editPresets() ) );
connect( this, TQT_SIGNAL( user1Clicked() ), TQT_SLOT( clearMessage() ) );
mMessageEdit->setFocus();
if ( !quotedMsg.isEmpty() )
insertQuotedMessage( quotedMsg );
readConfig();
}
MsgInputDialog::~MsgInputDialog()
{
kdDebug() << "MsgInputDialog::~MsgInputDialog()" << endl;
writeConfig();
}
void MsgInputDialog::readConfig()
{
resize( KBBPrefs::instance()->mMsgDlgWidth,
KBBPrefs::instance()->mMsgDlgHeight );
TQValueList<int> sizes = KBBPrefs::instance()->mMsgDlgSplitter;
mSplitter->setSizes( sizes );
}
void MsgInputDialog::writeConfig()
{
KBBPrefs::instance()->mMsgDlgWidth = width();
KBBPrefs::instance()->mMsgDlgHeight = height();
KBBPrefs::instance()->mMsgDlgSplitter = mSplitter->sizes();
}
void MsgInputDialog::updatePresets()
{
mPresets->clear();
TQMap<TQString,TQString> messageButtons = KBBPrefs::instance()->mMessageButtons;
int id = 0;
TQMap<TQString,TQString>::ConstIterator it;
for( it = messageButtons.begin(); it != messageButtons.end(); ++it )
mPresets->insertItem( it.key(), id );
}
TQString MsgInputDialog::message() const
{
return mMessageEdit->text();
}
void MsgInputDialog::editPresets()
{
MessageEditor *dlg = new MessageEditor(this);
dlg->exec();
delete dlg;
updatePresets();
}
void MsgInputDialog::slotPresetSelected( TQListBoxItem *lbi )
{
mMessageEdit->setText( KBBPrefs::instance()->mMessageButtons[ lbi->text() ] );
}
void MsgInputDialog::clearMessage()
{
mMessageEdit->setText("");
}
void MsgInputDialog::queueCommand()
{
switch ( mType ) {
case Close:
BugSystem::self()->queueCommand(
new BugCommandClose( mBug, message(), mPackage ) );
break;
case Reply:
BugSystem::self()->queueCommand(
new BugCommandReply( mBug, message(), mRecipient->currentItem() ) );
break;
case ReplyPrivate:
BugSystem::self()->queueCommand(
new BugCommandReplyPrivate( mBug, mBug.submitter().email,
message() ) );
break;
default:
break;
}
}
void MsgInputDialog::slotOk()
{
queueCommand();
delete this;
}
void MsgInputDialog::slotCancel()
{
delete this;
}
void MsgInputDialog::insertQuotedMessage( const TQString &msg )
{
Q_ASSERT( mMessageEdit->wordWrap() == TQTextEdit::FixedColumnWidth );
const TQString quotationMarker = "> ";
const unsigned int wrapColumn = mMessageEdit->wrapColumnOrWidth();
// ### Needs something more sophisticated than simplifyWhiteSpace to
// handle quoting multiple paragraphs properly.
TQString line = msg.simplifyWhiteSpace();
TQString quotedMsg;
while ( line.length() + quotationMarker.length() + 1 > wrapColumn ) {
int pos = wrapColumn - quotationMarker.length() - 1;
while ( pos > 0 && !line[ pos ].isSpace() )
--pos;
if ( pos == 0 )
pos = wrapColumn;
quotedMsg += quotationMarker + line.left( pos ) + "\n";
line = line.mid( pos + 1 );
}
quotedMsg += quotationMarker + line + "\n\n";
mMessageEdit->setText( quotedMsg );
const int lastPara = mMessageEdit->paragraphs() - 1;
const int lastParaLen = mMessageEdit->paragraphLength( lastPara ) - 1;
mMessageEdit->setCursorPosition( lastPara, lastParaLen );
}
|