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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
/***************************************************************************
* Copyright (C) 2005-2007 by Rajko Albrecht *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "logmsg_impl.h"
#include "src/settings/kdesvnsettings.h"
#include "depthselector.h"
#include <ktextedit.h>
#include <kcombobox.h>
#include <kdialogbase.h>
#include <klocale.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kapp.h>
#include <kconfigbase.h>
#include <kconfig.h>
#include <kurlrequesterdlg.h>
#include <kio/netaccess.h>
#include <kmessagebox.h>
#include <kfile.h>
#include <kurlrequester.h>
#include <qvbox.h>
#include <qcheckbox.h>
#include <qlabel.h>
#include <qlistview.h>
#include <qlayout.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qfile.h>
#define MAX_MESSAGE_HISTORY 10
QValueList<QString> Logmsg_impl::sLogHistory = QValueList<QString>();
QString Logmsg_impl::sLastMessage=QString();
const QString Logmsg_impl::groupName("logmsg_dlg_size");
unsigned int Logmsg_impl::smax_message_history = 0xFFFF;
class SvnCheckListItem:public QCheckListItem
{
protected:
Logmsg_impl::logActionEntry m_Content;
public:
SvnCheckListItem(QListView*,const Logmsg_impl::logActionEntry&);
const Logmsg_impl::logActionEntry&data(){return m_Content;}
virtual int rtti()const{return 1000;}
virtual int compare( QListViewItem* item, int col, bool ascending ) const;
};
Logmsg_impl::Logmsg_impl(QWidget *parent, const char *name)
:LogmessageData(parent, name)
{
m_LogEdit->setFocus();
m_Reviewlabel->hide();
m_ReviewList->hide();
m_hidden=true;
hideButtons(true);
m_MainSplitter->moveToFirst(m_EditFrame);
delete m_ReviewFrame;
m_Reviewlabel=0;
m_ReviewList=0;
m_MarkUnversioned=0;
m_UnmarkUnversioned=0;
m_DiffItem=0;
}
Logmsg_impl::Logmsg_impl(const svn::CommitItemList&_items,QWidget *parent, const char *name)
:LogmessageData(parent, name)
{
m_LogEdit->setFocus();
m_ReviewList->setColumnText(1,i18n("Items to commit"));
m_ReviewList->setColumnText(0,i18n("Action"));
m_ReviewList->setSortColumn(1);
hideButtons(true);
if (_items.count()>0) {
for (unsigned i = 0;i<_items.count();++i) {
QListViewItem*item = new QListViewItem(m_ReviewList);
if (_items[i].path().isEmpty()) {
item->setText(1,_items[i].url());
} else {
item->setText(1,_items[i].path());
}
item->setText(0,QChar(_items[i].actionType()));
}
m_hidden=false;
} else {
m_Reviewlabel->hide();
m_ReviewList->hide();
m_hidden=true;
}
checkSplitterSize();
}
Logmsg_impl::Logmsg_impl(const QMap<QString,QString>&_items,QWidget *parent, const char *name)
:LogmessageData(parent, name)
{
m_LogEdit->setFocus();
m_ReviewList->setColumnText(1,i18n("Items to commit"));
m_ReviewList->setColumnText(0,i18n("Action"));
m_ReviewList->setSortColumn(1);
hideButtons(true);
if (_items.count()>0) {
QMap<QString,QString>::ConstIterator it = _items.begin();
for (;it!=_items.end();++it) {
QListViewItem*item = new QListViewItem(m_ReviewList);
item->setText(1,it.key());
item->setText(0,it.data());
}
m_hidden=false;
} else {
m_Reviewlabel->hide();
m_ReviewList->hide();
m_hidden=true;
}
checkSplitterSize();
}
Logmsg_impl::Logmsg_impl(const logActionEntries&_activatedList,
const logActionEntries&_notActivatedList,
QWidget *parent, const char *name)
:LogmessageData(parent, name)
{
m_LogEdit->setFocus();
m_hidden=false;
for (unsigned j = 0; j<_activatedList.count();++j) {
SvnCheckListItem * item = new SvnCheckListItem(m_ReviewList,_activatedList[j]);
item->setState(QCheckListItem::On);
}
for (unsigned j = 0; j<_notActivatedList.count();++j) {
SvnCheckListItem * item = new SvnCheckListItem(m_ReviewList,_notActivatedList[j]);
item->setState(QCheckListItem::Off);
}
m_HideNewItems->setOn(Kdesvnsettings::commit_hide_new());
checkSplitterSize();
}
Logmsg_impl::~Logmsg_impl()
{
QValueList<int> list = m_MainSplitter->sizes();
if (!m_hidden && list.count()==2) {
Kdesvnsettings::setCommit_splitter_height(list);
Kdesvnsettings::writeConfig();
}
for (unsigned int j=0; j<m_Hidden.size();++j) {
delete m_Hidden[j];
}
Kdesvnsettings::setCommit_hide_new(m_HideNewItems->state()==QButton::On);
}
void Logmsg_impl::checkSplitterSize()
{
QValueList<int> list = Kdesvnsettings::commit_splitter_height();
if (list.count()!=2) {
return;
}
if (m_hidden) {
list[1]=list[0]+list[1];
list[0]=0;
}
if (m_hidden || (list[0]>0||list[1]>0)) {
m_MainSplitter->setSizes(list);
}
}
void Logmsg_impl::slotHistoryActivated(int number)
{
if (number < 1||(unsigned)number>sLogHistory.size()) {
m_LogEdit->setText("");
} else {
m_LogEdit->setText(sLogHistory[number-1]);
}
}
/*!
\fn Logmsg_impl::getMessage()const
*/
QString Logmsg_impl::getMessage()const
{
return m_LogEdit->text();
}
/*!
\fn Logmsg_impl::isRecursive()const
*/
svn::Depth Logmsg_impl::getDepth()const
{
return m_DepthSelector->getDepth();
}
/*!
\fn Logmsg_impl::isRecursive()const
*/
bool Logmsg_impl::isKeeplocks()const
{
return m_keepLocksButton->isChecked();
}
/*!
\fn Logmsg_impl::initHistory()
*/
void Logmsg_impl::initHistory()
{
if (smax_message_history==0xFFFF) {
smax_message_history = Kdesvnsettings::max_log_messages();
KConfigGroup cs(Kdesvnsettings::self()->config(),"log_messages");
QString s = QString::null;
unsigned int current = 0;
QString key = QString("log_%0").arg(current);
s = cs.readEntry(key,QString::null);
while (s!=QString::null) {
if (current<smax_message_history) {
sLogHistory.push_back(s);
} else {
cs.deleteEntry(key);
}
++current;
key = QString("log_%0").arg(current);
s = cs.readEntry(key,QString::null);
}
}
QValueList<QString>::const_iterator it;
for (it=sLogHistory.begin();it!=sLogHistory.end();++it) {
if ((*it).length()<=40) {
m_LogHistory->insertItem((*it));
} else {
m_LogHistory->insertItem((*it).left(37)+"...");
}
}
if (sLastMessage.length()>0) {
m_LogEdit->setText(sLastMessage);
sLastMessage=QString();
}
}
/*!
\fn Logmsg_impl::saveHistory()
*/
void Logmsg_impl::saveHistory(bool canceld)
{
if (m_LogEdit->text().length()==0||m_LogEdit->text().length()>512) return;
/// @todo make static threadsafe
if (!canceld) {
QValueList<QString>::iterator it;
if ( (it=sLogHistory.find(m_LogEdit->text()))!=sLogHistory.end()) {
sLogHistory.erase(it);
}
sLogHistory.push_front(m_LogEdit->text());
if (sLogHistory.size()>smax_message_history) {
sLogHistory.erase(sLogHistory.fromLast());
}
KConfigGroup cs(Kdesvnsettings::self()->config(),"log_messages");
for (unsigned int i = 0; i < sLogHistory.size();++i) {
cs.writeEntry(QString("log_%0").arg(i),sLogHistory[i]);
}
cs.sync();
} else {
sLastMessage=m_LogEdit->text();
}
}
QString Logmsg_impl::getLogmessage(bool*ok,svn::Depth*rec,bool*keep_locks,QWidget*parent,const char*name)
{
bool _ok,_keep_locks;
svn::Depth _depth = svn::DepthUnknown;
QString msg("");
Logmsg_impl*ptr=0;
KDialogBase dlg(parent,name,true,i18n("Commit log"),
KDialogBase::Ok|KDialogBase::Cancel,
KDialogBase::Ok,true);
QWidget* Dialog1Layout = dlg.makeVBoxMainWidget();
ptr = new Logmsg_impl(Dialog1Layout);
if (!rec) {
ptr->m_DepthSelector->hide();
}
if (!keep_locks) {
ptr->m_keepLocksButton->hide();
}
ptr->initHistory();
dlg.resize(dlg.configDialogSize(*(Kdesvnsettings::self()->config()),groupName));
if (dlg.exec()!=QDialog::Accepted) {
_ok = false;
/* avoid compiler warnings */
_keep_locks = false;
} else {
_ok = true;
_depth = ptr->getDepth();
_keep_locks = ptr->isKeeplocks();
msg=ptr->getMessage();
}
ptr->saveHistory(!_ok);
dlg.saveDialogSize(*(Kdesvnsettings::self()->config()),groupName,false);
if (ok) *ok = _ok;
if (rec) *rec = _depth;
return msg;
}
QString Logmsg_impl::getLogmessage(const svn::CommitItemList&items,bool*ok,svn::Depth*rec,bool*keep_locks,QWidget*parent,const char*name)
{
bool _ok,_keep_locks;
svn::Depth _depth = svn::DepthUnknown;
QString msg("");
Logmsg_impl*ptr=0;
KDialogBase dlg(parent,name,true,i18n("Commit log"),
KDialogBase::Ok|KDialogBase::Cancel,
KDialogBase::Ok,true);
QWidget* Dialog1Layout = dlg.makeVBoxMainWidget();
ptr = new Logmsg_impl(items,Dialog1Layout);
if (!rec) {
ptr->m_DepthSelector->hide();
}
if (!keep_locks) {
ptr->m_keepLocksButton->hide();
}
ptr->initHistory();
dlg.resize(dlg.configDialogSize(*(Kdesvnsettings::self()->config()),groupName));
if (dlg.exec()!=QDialog::Accepted) {
_ok = false;
/* avoid compiler warnings */
_keep_locks = false;
} else {
_ok = true;
_depth = ptr->getDepth();
_keep_locks = ptr->isKeeplocks();
msg=ptr->getMessage();
}
ptr->saveHistory(!_ok);
dlg.saveDialogSize(*(Kdesvnsettings::self()->config()),groupName,false);
if (ok) *ok = _ok;
if (rec) *rec = _depth;
if (keep_locks) *keep_locks = _keep_locks;
return msg;
}
QString Logmsg_impl::getLogmessage(const QMap<QString,QString>&items,
bool*ok,svn::Depth*rec,bool*keep_locks,QWidget*parent,const char*name)
{
bool _ok,_rec,_keep_locks;
svn::Depth _depth = svn::DepthUnknown;
QString msg("");
Logmsg_impl*ptr=0;
KDialogBase dlg(parent,name,true,i18n("Commit log"),
KDialogBase::Ok|KDialogBase::Cancel,
KDialogBase::Ok,true);
QWidget* Dialog1Layout = dlg.makeVBoxMainWidget();
ptr = new Logmsg_impl(items,Dialog1Layout);
if (!rec) {
ptr->m_DepthSelector->hide();
}
if (!keep_locks) {
ptr->m_keepLocksButton->hide();
}
ptr->initHistory();
dlg.resize(dlg.configDialogSize(*(Kdesvnsettings::self()->config()),groupName));
if (dlg.exec()!=QDialog::Accepted) {
_ok = false;
/* avoid compiler warnings */
_rec = false;
_keep_locks=false;
} else {
_ok = true;
_depth = ptr->getDepth();
msg=ptr->getMessage();
_keep_locks = ptr->isKeeplocks();
}
ptr->saveHistory(!_ok);
dlg.saveDialogSize(*(Kdesvnsettings::self()->config()),groupName,false);
if (ok) *ok = _ok;
if (rec) *rec = _depth;
if (keep_locks) *keep_locks = _keep_locks;
return msg;
}
QString Logmsg_impl::getLogmessage(const logActionEntries&_on,
const logActionEntries&_off,
QObject*callback,
logActionEntries&_result,
bool*ok,bool*keep_locks,QWidget*parent,const char*name)
{
bool _ok,_keep_locks;
QString msg("");
Logmsg_impl*ptr=0;
KDialogBase dlg(parent,name,true,i18n("Commit log"),
KDialogBase::Ok|KDialogBase::Cancel,
KDialogBase::Ok,true);
QWidget* Dialog1Layout = dlg.makeVBoxMainWidget();
ptr = new Logmsg_impl(_on,_off,Dialog1Layout);
ptr->m_DepthSelector->hide();
if (!keep_locks) {
ptr->m_keepLocksButton->hide();
}
ptr->initHistory();
if (callback)
{
connect(ptr,SIGNAL(makeDiff(const QString&,const svn::Revision&,const QString&,const svn::Revision&,QWidget*)),
callback,SLOT(makeDiff(const QString&,const svn::Revision&,const QString&,const svn::Revision&,QWidget*)));
}
dlg.resize(dlg.configDialogSize(*(Kdesvnsettings::self()->config()),groupName));
if (dlg.exec()!=QDialog::Accepted) {
_ok = false;
/* avoid compiler warnings */
_keep_locks=false;
} else {
_ok = true;
msg=ptr->getMessage();
_keep_locks = ptr->isKeeplocks();
}
ptr->saveHistory(!_ok);
dlg.saveDialogSize(*(Kdesvnsettings::self()->config()),groupName,false);
if (ok) *ok = _ok;
_result = ptr->selectedEntries();
if (keep_locks) *keep_locks = _keep_locks;
return msg;
}
/*!
\fn Logmsg_impl::setRecCheckboxtext(const QString&what)
*/
void Logmsg_impl::addItemWidget(QWidget*aWidget)
{
m_DepthSelector->addItemWidget(aWidget);
/* aWidget->reparent(this,geometry().topLeft());
m_ItemsLayout->addWidget(aWidget);
kdDebug()<<"SizeHint: "<<aWidget->minimumSizeHint()<< endl;
aWidget->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
setMinimumHeight(minimumSizeHint().height());*/
}
Logmsg_impl::logActionEntries Logmsg_impl::selectedEntries()
{
logActionEntries _result;
if (m_ReviewList) {
QListViewItemIterator it( m_ReviewList );
while ( it.current() ) {
if (it.current()->rtti()==1000) {
SvnCheckListItem *item = static_cast<SvnCheckListItem*>(it.current());
if (item->isOn()) {
_result.append(item->data());
}
}
++it;
}
}
return _result;
}
Logmsg_impl::logActionEntry::logActionEntry(const QString&name,const QString&action,ACTION_TYPE kind)
: _name(name),_actionDesc(action),_kind(kind)
{
}
Logmsg_impl::logActionEntry::logActionEntry()
: _name(""),_actionDesc(""),_kind(COMMIT)
{
}
SvnCheckListItem::SvnCheckListItem(QListView*parent,const Logmsg_impl::logActionEntry&content)
:QCheckListItem(parent,content._name,QCheckListItem::CheckBox),m_Content(content)
{
setTristate(FALSE);
setText(1,m_Content._actionDesc);
if (content._name.isEmpty()) {
setText(0,"...");
}
}
int SvnCheckListItem::compare( QListViewItem* item, int col, bool ascending ) const
{
if (item->rtti()!=1000 || col>0) {
return QCheckListItem::compare(item,col,ascending);
}
SvnCheckListItem* k = static_cast<SvnCheckListItem*>( item );
if (Kdesvnsettings::case_sensitive_sort()) {
if (Kdesvnsettings::locale_is_casesensitive()) {
return m_Content._name.lower().localeAwareCompare(k->m_Content._name.lower());
}
return m_Content._name.compare(k->m_Content._name);
} else {
return m_Content._name.lower().localeAwareCompare(k->m_Content._name.lower());
}
}
void Logmsg_impl::slotUnmarkUnversioned()
{
markUnversioned(false);
}
void Logmsg_impl::slotMarkUnversioned()
{
markUnversioned(true);
}
void Logmsg_impl::slotDiffSelected()
{
QListViewItem * it=0;
if (!m_ReviewList || !(it=m_ReviewList->selectedItem()))
{
return;
}
if (it->rtti()==1000)
{
SvnCheckListItem *item = static_cast<SvnCheckListItem*>(it);
QString what = item->data()._name;
emit makeDiff(what,svn::Revision::BASE,what,svn::Revision::WORKING,parentWidget());
}
}
void Logmsg_impl::hideButtons(bool how)
{
if (!m_MarkUnversioned)return;
if (how)
{
m_MarkUnversioned->hide();
m_UnmarkUnversioned->hide();
m_DiffItem->hide();
m_HideNewItems->hide();
}
else
{
m_MarkUnversioned->show();
m_UnmarkUnversioned->show();
m_DiffItem->show();
m_HideNewItems->show();
}
}
/*!
\fn Logmsg_impl::markUnversioned(bool mark)
*/
void Logmsg_impl::markUnversioned(bool mark)
{
if (!m_ReviewList)return;
QListViewItemIterator it( m_ReviewList );
while ( it.current() ) {
if (it.current()->rtti()==1000) {
SvnCheckListItem *item = static_cast<SvnCheckListItem*>(it.current());
if (item->data()._kind==logActionEntry::ADD_COMMIT) {
item->setOn(mark);
}
}
++it;
}
}
void Logmsg_impl::hideNewItems(bool how)
{
if (!m_ReviewList)return;
if (how) {
QListViewItemIterator it( m_ReviewList );
while ( it.current() ) {
if (it.current()->rtti()==1000) {
SvnCheckListItem *item = static_cast<SvnCheckListItem*>(it.current());
if (item->data()._kind==logActionEntry::ADD_COMMIT) {
item->setOn(false);
m_Hidden.push_back(item);
}
}
++it;
}
for (unsigned j=0;j<m_Hidden.size();++j) {
m_ReviewList->takeItem(m_Hidden[j]);
}
} else {
for (unsigned j=0;j<m_Hidden.size();++j) {
m_ReviewList->insertItem(m_Hidden[j]);
}
m_Hidden.clear();
}
}
/*!
\fn Logmsg_impl::hideDepth(bool hide)
*/
void Logmsg_impl::hideDepth(bool ahide)
{
m_DepthSelector->hideDepth(ahide);
// if (hide) m_DepthSelector->hide();
// else m_DepthSelector->show();
}
void Logmsg_impl::insertFile(const QString&fname)
{
QFile ifs(fname);
if (ifs.open(IO_ReadOnly)) {
QTextStream ts(&ifs);
QString _content = ts.read();
int para,index;
m_LogEdit->getCursorPosition(¶,&index);
m_LogEdit->insertAt(_content,para,index);
}
}
void Logmsg_impl::insertFile()
{
QString head = i18n("Select textfile for insert");
KURLRequesterDlg dlg(QString::null,this,head);
dlg.setCaption(head);
KFile::Mode mode = static_cast<KFile::Mode>(KFile::File);
dlg.urlRequester()->setMode(mode);
dlg.urlRequester()->setCaption(head);
if (dlg.exec()!=QDialog::Accepted) {
return;
}
KURL _url = dlg.selectedURL();
if (_url.isEmpty() || !_url.isValid()) {
return;
}
if (_url.isLocalFile()) {
insertFile(_url.path());
} else {
QString tmpFile;
if( KIO::NetAccess::download(_url, tmpFile, this) ) {
insertFile( tmpFile );
KIO::NetAccess::removeTempFile( tmpFile );
} else {
KMessageBox::error(this, KIO::NetAccess::lastErrorString() );
}
}
}
#include "logmsg_impl.moc"
|