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
|
/***************************************************************************
* Copyright (C) 2005-2007 by Rajko Albrecht *
* ral@alwins-world.de *
* *
* 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 "kdesvn.h"
#include "urldlg.h"
#include "kdesvn_part.h"
#include <tqdragobject.h>
#include <kprinter.h>
#include <tqpainter.h>
#include <tqpaintdevicemetrics.h>
#include <tqcursor.h>
#include <kglobal.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kdeversion.h>
#include <kstatusbar.h>
#include <kaccel.h>
#include <kio/netaccess.h>
#include <kfiledialog.h>
#include <kconfig.h>
#include <kurl.h>
#include <kurldrag.h>
#include <kurlrequesterdlg.h>
#include <khelpmenu.h>
#include <kmenubar.h>
#include <kpopupmenu.h>
#include <kactionclasses.h>
#include <kmessagebox.h>
#include <kstdaccel.h>
#include <kaction.h>
#include <kstdaction.h>
#include <kstandarddirs.h>
#include <kbookmarkmanager.h>
#include <kbookmarkmenu.h>
#include <kdebug.h>
#include <klibloader.h>
#include <kedittoolbar.h>
#include <kkeydialog.h>
#include <kdirselectdialog.h>
#ifdef TESTING_RC
#include <kcrash.h>
#endif
kdesvn::kdesvn()
: KParts::MainWindow( 0, "kdesvn" ),
KBookmarkOwner()
{
m_part = 0;
#ifdef TESTING_RC
setXMLFile(TESTING_RC);
kdDebug()<<"Using test rc file in " << TESTING_RC << endl;
// I hate this crashhandler in development
KCrash::setCrashHandler(0);
#else
setXMLFile("kdesvnui.rc");
#endif
setStandardToolBarMenuEnabled(true);
// then, setup our actions
setupActions();
// and a status bar
statusBar()->show();
m_bookmarkFile = locateLocal("appdata",TQString::tqfromLatin1("bookmarks.xml"),true);
m_BookmarkManager = KBookmarkManager::managerForFile(m_bookmarkFile,false);
m_BookmarkManager->setShowNSBookmarks(false);
m_BookmarkManager->setEditorOptions(TQString::tqfromLatin1("KDE Svn"),false);
m_BookmarksActionmenu = new KActionMenu(i18n("&Bookmarks"),"bookmark",actionCollection(),"bookmarks");
m_BookmarksActionmenu->setDelayed(false);
m_BookmarksActionmenu->setEnabled(true);
m_Bookmarkactions = new KActionCollection( this );
m_Bookmarkactions->setHighlightingEnabled( true );
connectActionCollection( m_Bookmarkactions );
m_pBookmarkMenu = new KBookmarkMenu(m_BookmarkManager,this,m_BookmarksActionmenu->popupMenu(),m_Bookmarkactions,true);
// m_BookmarksActionmenu->plug(menuBar());
// this routine will find and load our Part. it finds the Part by
// name which is a bad idea usually.. but it's alright in this
// case since our Part is made for this Shell
KLibFactory *factory = KLibLoader::self()->factory("libtdesvnpart");
if (factory)
{
if (TQCString(factory->className())!="cFactory") {
kdDebug()<<"wrong factory"<<endl;
KMessageBox::error(this, i18n("Could not find our part"));
kapp->quit();
return;
}
cFactory*cfa = static_cast<cFactory*>(factory);
// now that the Part is loaded, we cast it to a Part to get
// our hands on it
m_part = static_cast<KParts::ReadOnlyPart *>(cfa->createAppPart(this,"kdesvn_part", TQT_TQOBJECT(this), "kdesvn_part", "KParts::ReadOnlyPart",TQStringList()));
if (m_part)
{
// tell the KParts::MainWindow that this is indeed the main widget
setCentralWidget(m_part->widget());
KAction*tmpAction;
tmpAction = new KAction(i18n("Create and open new repository"),"filenew",
KShortcut(),TQT_TQOBJECT(m_part->widget()),TQT_SLOT(slotCreateRepo()),actionCollection(),"subversion_create_repo");
tmpAction->setToolTip(i18n("Create and opens a new local subversion repository"));
tmpAction = new KAction(i18n("Dump repository to file"),"filenew",
KShortcut(),TQT_TQOBJECT(m_part->widget()),TQT_SLOT(slotDumpRepo()),actionCollection(),"subversion_dump_repo");
tmpAction->setToolTip(i18n("Dump a subversion repository to a file"));
tmpAction = new KAction(i18n("Hotcopy a repository"),"filenew",
KShortcut(),TQT_TQOBJECT(m_part->widget()),TQT_SLOT(slotHotcopy()),actionCollection(),"subversion_hotcopy_repo");
tmpAction->setToolTip(i18n("Hotcopy a subversion repository to a new folder"));
tmpAction = new KAction(i18n("Load dump into repository"),"filenew",
KShortcut(),TQT_TQOBJECT(m_part->widget()),TQT_SLOT(slotLoaddump()),actionCollection(),"subversion_load_repo");
tmpAction->setToolTip(i18n("Load a dump file into a repository."));
tmpAction = new KAction(i18n("Add ssh identities to ssh-agent"),"password",
KShortcut(),TQT_TQOBJECT(m_part),TQT_SLOT(slotSshAdd()),actionCollection(),"kdesvn_ssh_add");
tmpAction->setToolTip(i18n("Force add ssh-identities to ssh-agent for future use."));
tmpAction = new KAction(i18n("Info about kdesvn part"), "kdesvn",
KShortcut(), TQT_TQOBJECT(m_part), TQT_SLOT(showAboutApplication()), actionCollection(), "help_about_tdesvnpart");
tmpAction->setToolTip(i18n("Shows info about the kdesvn plugin not the standalone app."));
/* enable tooltips in statusbar for menu */
actionCollection()->setHighlightingEnabled(true);
connectActionCollection(actionCollection());
// and integrate the part's GUI with the shells
createGUI(m_part);
connectActionCollection(m_part->actionCollection());
} else {
KMessageBox::error(this, i18n("Could not load the part:\n")+KLibLoader::self()->lastErrorMessage());
kapp->quit();
return;
}
}
else
{
// if we couldn't find our Part, we exit since the Shell by
// itself can't do anything useful
KMessageBox::error(this, i18n("Could not find our part")+TQString(":\n")+KLibLoader::self()->lastErrorMessage());
kapp->quit();
// we return here, cause kapp->quit() only means "exit the
// next time we enter the event loop...
return;
}
setAutoSaveSettings();
}
void kdesvn::connectActionCollection( KActionCollection *coll )
{
if (!coll)return;
connect( coll, TQT_SIGNAL( actionStatusText( const TQString & ) ),
this, TQT_SLOT( changeStatusbar( const TQString & ) ) );
connect( coll, TQT_SIGNAL( clearStatusText() ),
this, TQT_SLOT( resetStatusBar() ) );
}
void kdesvn::disconnectActionCollection( KActionCollection *coll )
{
if (!coll)return;
}
kdesvn::~kdesvn()
{
}
void kdesvn::loadRescent(const KURL& url)
{
load(url,true);
}
void kdesvn::load(const KURL& url,bool addRescent)
{
if (m_part) {
bool ret = m_part->openURL(url);
KRecentFilesAction*rac = 0;
if (addRescent) {
KAction * ac = actionCollection()->action("file_open_recent");
if (ac) {
rac = (KRecentFilesAction*)ac;
}
}
if (!ret) {
changeStatusbar(i18n("Could not open url %1").tqarg(url.prettyURL()));
if (rac) {
rac->removeURL(url);
}
} else {
resetStatusBar();
if (rac) {
rac->addURL(url);
}
}
if (rac) {
rac->saveEntries(KGlobal::config(),"recent_files");
}
}
}
void kdesvn::setupActions()
{
KAction*ac;
KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(fileOpen()), actionCollection());
KStdAction::openNew(TQT_TQOBJECT(this),TQT_SLOT(fileNew()),actionCollection());
ac = KStdAction::close(TQT_TQOBJECT(this),TQT_SLOT(fileClose()),actionCollection());
ac->setEnabled(getMemberList()->count()>1);
KStdAction::quit(TQT_TQOBJECT(kapp), TQT_SLOT(quit()), actionCollection());
KRecentFilesAction*rac = KStdAction::openRecent(TQT_TQOBJECT(this),TQT_SLOT(loadRescent(const KURL&)),actionCollection());
if (rac)
{
rac->setMaxItems(8);
rac->loadEntries(KGlobal::config(),"recent_files");
rac->setText(i18n("Recent opened URLs"));
}
KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureKeys()), actionCollection());
KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureToolbars()), actionCollection());
m_statusbarAction = KStdAction::showStatusbar(TQT_TQOBJECT(this), TQT_SLOT(optionsShowStatusbar()), actionCollection());
KToggleAction *toggletemp;
toggletemp = new KToggleAction(i18n("Load last opened URL on start"),KShortcut(),
actionCollection(),"toggle_load_last_url");
toggletemp->setToolTip(i18n("Reload last opened url if no one is given on commandline"));
KConfigGroup cs(KGlobal::config(),"startup");
toggletemp->setChecked(cs.readBoolEntry("load_last_on_start",false));
connect(toggletemp,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotLoadLast(bool)));
}
void kdesvn::optionsShowStatusbar()
{
// this is all very cut and paste code for showing/hiding the
// statusbar
if (m_statusbarAction->isChecked())
statusBar()->show();
else
statusBar()->hide();
}
void kdesvn::fileClose()
{
if (m_part) m_part->closeURL();
if (getMemberList()->count()>1) {
close();
} else {
enableClose(false);
}
}
void kdesvn::saveProperties(KConfig *config)
{
// the 'config' object points to the session managed
// config file. anything you write here will be available
// later when this app is restored
if (!m_part) return;
if (!m_part->url().isEmpty()) {
#if KDE_IS_VERSION(3,1,3)
config->writePathEntry("lastURL", m_part->url().prettyURL());
#else
config->writeEntry("lastURL", m_part->url().prettyURL());
#endif
}
}
void kdesvn::readProperties(KConfig *config)
{
// the 'config' object points to the session managed
// config file. this function is automatically called whenever
// the app is being restored. read in here whatever you wrote
// in 'saveProperties'
TQString url = config->readPathEntry("lastURL");
if (!url.isEmpty() && m_part)
m_part->openURL(KURL(url));
}
void kdesvn::fileNew()
{
// this slot is called whenever the File->New menu is selected,
// the New shortcut is pressed (usually CTRL+N) or the New toolbar
// button is clicked
// create a new window
(new kdesvn)->show();
enableClose(true);
}
void kdesvn::fileOpen()
{
KURL url = UrlDlg::getURL(this);
if (!url.isEmpty())
load(url,true);
}
void kdesvn::changeStatusbar(const TQString& text)
{
// display the text on the statusbar
statusBar()->message(text);
}
void kdesvn::resetStatusBar()
{
statusBar()->message(i18n("Ready"));
}
void kdesvn::openBookmarkURL (const TQString &_url)
{
if (!_url.isEmpty() && m_part)
load(_url,false);
}
TQString kdesvn::currentURL () const
{
if (!m_part) return "";
return m_part->url().prettyURL();
}
void kdesvn::enableClose(bool how)
{
KAction * ac;
if ( (ac=actionCollection()->action("file_close"))) {
ac->setEnabled(how);
}
}
/*!
\fn kdesvn::slotUrlOpened(bool)
*/
void kdesvn::slotUrlOpened(bool how)
{
enableClose(how);
}
/*!
\fn kdesvn::optionsConfigureToolbars()
*/
void kdesvn::optionsConfigureToolbars()
{
#if defined(KDE_MAKE_VERSION)
# if TDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
# else
saveMainWindowSettings(KGlobal::config() );
# endif
#else
saveMainWindowSettings(KGlobal::config() );
#endif
// use the standard toolbar editor
KEditToolbar dlg(factory());
connect(&dlg, TQT_SIGNAL(newToolbarConfig()),
this, TQT_SLOT(applyNewToolbarConfig()));
dlg.exec();
}
/*!
\fn kdesvn::applyNewToolbarConfig()
*/
void kdesvn::applyNewToolbarConfig()
{
#if defined(KDE_MAKE_VERSION)
# if TDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
# else
applyMainWindowSettings(kdesvnPart::config());
# endif
#else
applyMainWindowSettings(kdesvnPart::config());
#endif
}
void kdesvn::optionsConfigureKeys()
{
KKeyDialog kdlg(true,m_part->widget());
kdlg.insert(actionCollection());
kdlg.insert(m_part->actionCollection());
bool b = kdlg.configure(true);
if (b) {
kdlg.commitChanges();
}
}
/*!
\fn kdesvn::queryExit()
*/
bool kdesvn::queryExit()
{
if (m_part) {
KConfigGroup cs(KGlobal::config(),"startup");
#if KDE_IS_VERSION(3,1,3)
cs.writePathEntry("lastURL", m_part->url().prettyURL());
#else
cs.writeEntry("lastURL", m_part->url().prettyURL());
#endif
}
return KParts::MainWindow::queryExit();
}
/*!
\fn kdesvn::checkReload()
*/
void kdesvn::checkReload()
{
KConfigGroup cs(KGlobal::config(),"startup");
if (!cs.readBoolEntry("load_last_on_start",false))
return;
TQString url = cs.readPathEntry("lastURL");
if (!url.isEmpty() && m_part)
load(KURL(url),false);
}
/*!
\fn kdesvn::slotLoadLast(bool)
*/
void kdesvn::slotLoadLast(bool how)
{
KConfigGroup cs(KGlobal::config(),"startup");
cs.writeEntry("load_last_on_start",how);
}
#include "kdesvn.moc"
|