summaryrefslogtreecommitdiffstats
path: root/src/tdesvn_part.cpp
blob: bf3b6853da3e31b464d3de2b171daece3589bafa (plain)
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
/***************************************************************************
 *   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 "tdesvn_part.h"
#include "tdesvnsettings.h"
#include "displaysettings_impl.h"
#include "dispcolorsettings_impl.h"
#include "revisiontreesettingsdlg_impl.h"
#include "diffmergesettings_impl.h"
#include "subversionsettings_impl.h"
#include "cmdexecsettings_impl.h"
#include "tdesvnview.h"
#include "commandline_part.h"
#include "version_check.hpp"
#include "url.hpp"
#include "helpers/ktranslateurl.h"
#include "helpers/sshagent.h"

#include <kinstance.h>
#include <tdeaction.h>
#include <kstdaction.h>
#include <tdefiledialog.h>
#include <kdebug.h>
#include <kbugreport.h>
#include <kxmlguifactory.h>
#include <tdeaboutapplication.h>
#include <kapp.h>
#include <tdeconfigdialog.h>
#include <tdeaboutdata.h>
#include <tdelocale.h>

#include <tqcursor.h>
#include <tqpopupmenu.h>

//K_EXPORT_COMPONENT_FACTORY( tdesvnpart, tdesvnPartFactory )

extern "C" { KDESVN_EXPORT void *init_tdesvnpart() { return new tdesvnPartFactory; } }

static const char version[] = VERSION;
TQString tdesvnPart::m_Extratext = "";

static const char description[] =
    I18N_NOOP("A Subversion Client for TDE (dynamic Part component)");

tdesvnPart::tdesvnPart( TQWidget *parentWidget, const char *widgetName,
                                  TQObject *parent, const char *name , const TQStringList&)
    : KParts::ReadOnlyPart(parent, name)
{
    init(parentWidget,widgetName,false);
}

tdesvnPart::tdesvnPart(TQWidget *parentWidget, const char *widgetName,
               TQObject *parent, const char *name,bool ownapp, const TQStringList&)
    : KParts::ReadOnlyPart(parent, name)
{
    init(parentWidget,widgetName,ownapp);
}

void tdesvnPart::init( TQWidget *parentWidget, const char *widgetName,bool full)
{
    m_aboutDlg = 0;
    TDEGlobal::locale()->insertCatalogue("tdesvn");
    // we need an instance
    setInstance( tdesvnPartFactory::instance() );
    m_browserExt = new KdesvnBrowserExtension( this );

    // this should be your custom internal widget
    m_view = new tdesvnView(actionCollection(),parentWidget,widgetName,full);

    // notify the part that this is our internal widget
    setWidget(m_view);

    // create our actions
    setupActions();
    // set our XML-UI resource file
#ifdef TESTING_PARTRC
    setXMLFile(TESTING_PARTRC);
    kdDebug()<<"Using test rc file in " << TESTING_PARTRC << endl;
#else
    setXMLFile("tdesvn_part.rc");
#endif
    connect(m_view,TQT_SIGNAL(sigShowPopup(const TQString&,TQWidget**)),this,TQT_SLOT(slotDispPopup(const TQString&,TQWidget**)));
    connect(m_view,TQT_SIGNAL(sigSwitchUrl(const KURL&)),this,TQT_SLOT(openURL(const KURL&)));
    connect(this,TQT_SIGNAL(refreshTree()),m_view,TQT_SLOT(refreshCurrentTree()));
    connect(m_view,TQT_SIGNAL(setWindowCaption(const TQString&)),this,TQT_SIGNAL(setWindowCaption(const TQString&)));
    connect(m_view,TQT_SIGNAL(sigUrlChanged( const TQString&)),this,TQT_SLOT(slotUrlChanged(const TQString&)));
    connect(this,TQT_SIGNAL(settingsChanged()),widget(),TQT_SLOT(slotSettingsChanged()));

    m_browserExt->setPropertiesActionEnabled(false);
}

tdesvnPart::~tdesvnPart()
{
    tdesvnPartFactory::instance()->config()->sync();
}

void tdesvnPart::slotUrlChanged(const TQString&url)
{
    m_url = url;
}

bool tdesvnPart::openFile()
{
    m_view->openURL(m_url);
    // just for fun, set the status bar
    emit setStatusBarText( m_url.prettyURL() );

    return true;
}

bool tdesvnPart::openURL(const KURL&url)
{

    KURL _url = helpers::KTranslateUrl::translateSystemUrl(url);

    _url.setProtocol(svn::Url::transformProtokoll(_url.protocol()));

    if (!_url.isValid()||!closeURL()) {
        return false;
    }
    m_url = _url;
    emit started(0);
    bool ret = m_view->openURL(m_url);
    if (ret) {
        emit completed();
        emit setWindowCaption(url.prettyURL());
    }
    return ret;
}

void tdesvnPart::slotFileProperties()
{
}

void tdesvnPart::slotDispPopup(const TQString&name,TQWidget**target)
{
    *target = hostContainer(name);
}

TDEAboutData* tdesvnPart::createAboutData()
{
    m_Extratext = TQString(I18N_NOOP("Built with Subversion library: %1\n")).arg(svn::Version::linked_version());
    m_Extratext+=TQString(I18N_NOOP("Running Subversion library: %1")).arg(svn::Version::running_version());

    TDEAboutData*about = new TDEAboutData("tdesvnpart", I18N_NOOP("tdesvn Part"), version, description,
                     TDEAboutData::License_GPL, "(C) 2005-2007 Rajko Albrecht",0,
                         0, "ral@alwins-world.de");
    about->addAuthor( "Rajko Albrecht", 0, "ral@alwins-world.de" );
    about->setOtherText(m_Extratext.ascii());
    about->setHomepage("http://tdesvn.alwins-world.de/");
    about->setBugAddress("tdesvn-bugs@alwins-world.de");
    about->setTranslator(I18N_NOOP("tdesvn: NAME OF TRANSLATORS\\nYour names"),
        I18N_NOOP("tdesvn: EMAIL OF TRANSLATORS\\nYour emails"));
    return about;
}


/*!
    \fn tdesvnPart::setupActions()
 */
void tdesvnPart::setupActions()
{
    TDEToggleAction *toggletemp;

    toggletemp = new TDEToggleAction(i18n("Logs follow node changes"),TDEShortcut(),
            actionCollection(),"toggle_log_follows");
    toggletemp->setChecked(Kdesvnsettings::log_follows_nodes());
    connect(toggletemp,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotLogFollowNodes(bool)));

    toggletemp = new TDEToggleAction(i18n("Display ignored files"),TDEShortcut(),
            actionCollection(),"toggle_ignored_files");
    toggletemp->setChecked(Kdesvnsettings::display_ignored_files());
    connect(toggletemp,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotDisplayIgnored(bool)));


    toggletemp = new TDEToggleAction(i18n("Display unknown files"),TDEShortcut(),
            actionCollection(),"toggle_unknown_files");
    toggletemp->setChecked(Kdesvnsettings::display_unknown_files());
    connect(toggletemp,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotDisplayUnkown(bool)));

    toggletemp = new TDEToggleAction(i18n("Hide unchanged files"),TDEShortcut(),
                                   actionCollection(),"toggle_hide_unchanged_files");
    toggletemp->setChecked(Kdesvnsettings::hide_unchanged_files());
    connect(toggletemp,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotHideUnchanged(bool)));

    toggletemp = new TDEToggleAction(i18n("Work online"),TDEShortcut(),
                                   actionCollection(),"toggle_network");
    toggletemp->setChecked(Kdesvnsettings::network_on());
    connect(toggletemp,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableNetwork(bool)));

    kdDebug()<<"Appname = " << (TQString)kapp->instanceName() << endl;

    TDEAction * t = KStdAction::preferences(this, TQT_SLOT(slotShowSettings()), actionCollection(),"tdesvnpart_pref");
    t->setText(i18n("&Configure %1...").arg("Kdesvn"));
    if (TQString(kapp->instanceName())!=TQString("tdesvn")) {
        (void)new TDEAction(i18n("&About tdesvn part"), "tdesvn", 0, this, TQT_SLOT(showAboutApplication()), actionCollection(), "help_about_tdesvnpart");
        (void)new TDEAction(i18n("Kdesvn &Handbook"), "help", 0, this, TQT_SLOT(appHelpActivated()), actionCollection(), "help_tdesvn");
        (void)new TDEAction(i18n("Send Bugreport for tdesvn"), 0, 0, this, TQT_SLOT(reportBug()), actionCollection(), "report_bug");
    }
    actionCollection()->setHighlightingEnabled(true);
}

void tdesvnPart::slotSshAdd()
{
    SshAgent ag;
    ag.addSshIdentities(true);
}

/*!
    \fn tdesvnPart::slotLogFollowNodes(bool)
 */
void tdesvnPart::slotLogFollowNodes(bool how)
{
    Kdesvnsettings::setLog_follows_nodes(how);
    Kdesvnsettings::writeConfig();
}


/*!
    \fn tdesvnPart::slotDiplayIgnored(bool)
 */
void tdesvnPart::slotDisplayIgnored(bool how)
{
    Kdesvnsettings::setDisplay_ignored_files(how);
    Kdesvnsettings::writeConfig();
    emit refreshTree();
}


/*!
    \fn tdesvnPart::slotDisplayUnknown(bool)
 */
void tdesvnPart::slotDisplayUnkown(bool how)
{
    Kdesvnsettings::setDisplay_unknown_files(how);
    Kdesvnsettings::writeConfig();
    emit refreshTree();
}

/*!
    \fn tdesvnPart::slotHideUnchanged(bool)
 */
void tdesvnPart::slotHideUnchanged(bool how)
{
    Kdesvnsettings::setHide_unchanged_files(how);
    Kdesvnsettings::writeConfig();
    emit refreshTree();
}

void tdesvnPart::slotEnableNetwork(bool how)
{
    Kdesvnsettings::setNetwork_on(how);
    Kdesvnsettings::writeConfig();
    emit settingsChanged();
}

/*!
    \fn tdesvnPart::closeURL()
 */
bool tdesvnPart::closeURL()
{
    m_url=KURL();
    m_view->closeMe();
    emit setWindowCaption("");
    return true;
}

KdesvnBrowserExtension::KdesvnBrowserExtension( tdesvnPart *p )
    : KParts::BrowserExtension( p, "KdesvnBrowserExtension" )
{
    TDEGlobal::locale()->insertCatalogue("tdesvn");
}

KdesvnBrowserExtension::~KdesvnBrowserExtension()
{

}


void KdesvnBrowserExtension::setPropertiesActionEnabled(bool enabled)
{
    emit enableAction("properties", enabled);
}


void KdesvnBrowserExtension::properties()
{
    static_cast<tdesvnPart*>(parent())->slotFileProperties();
}


/*!
    \fn tdesvnPart::reportBug()
 */
void tdesvnPart::reportBug()
{
  KBugReport dlg(m_view, true, createAboutData());
  dlg.exec();
}

/*!
    \fn tdesvnPart::showAboutApplication()
 */
void tdesvnPart::showAboutApplication()
{
    if (!m_aboutDlg) m_aboutDlg = new TDEAboutApplication(createAboutData(), (TQWidget *)0, (const char *)0, false);
    if(m_aboutDlg == 0)
        return;
    if(!m_aboutDlg->isVisible())
        m_aboutDlg->show();
    else
        m_aboutDlg->raise();
}


/*!
    \fn tdesvnPart::appHelpActivated()
 */
void tdesvnPart::appHelpActivated()
{
    kapp->invokeHelp(TQString(), "tdesvn");
}


/*!
    \fn tdesvnPart::slotShowSettings()
 */
void tdesvnPart::slotShowSettings()
{
    if (TDEConfigDialog::showDialog("tdesvnpart_settings")) {
        return;
    }
    TDEConfigDialog *dialog = new TDEConfigDialog(widget(),
         "tdesvnpart_settings",
         Kdesvnsettings::self(),
         KDialogBase::IconList);
    dialog->setHelp("setup","tdesvn");
    dialog->addPage(new DisplaySettings_impl(0,"general_items"),
        i18n("General"),"configure",i18n("General"),true);
    dialog->addPage(new SubversionSettings_impl(0,"subversion_items"),
        i18n("Subversion"),"tdesvn",i18n("Subversion Settings"),true);
    dialog->addPage(new DiffMergeSettings_impl(0,"diffmerge_items"),
        i18n("Diff & Merge"),"tdesvnmerge",i18n("Settings for diff and merge"),true);
    dialog->addPage(new DispColorSettings_impl(0,"color_items"),
        i18n("Colors"),"colorize",i18n("Color Settings"),true);
    dialog->addPage(new RevisiontreeSettingsDlg_impl(0,"revisiontree_items"),
        i18n("Revision tree"),"configure",i18n("Revision tree Settings"),true);
    dialog->addPage(new CmdExecSettings_impl(0,"cmdexec_items"),
        "TDEIO/"+i18n("Commandline"),"terminal",i18n("Settings for commandline and TDEIO execution"),true);

    connect(dialog,TQT_SIGNAL(settingsChanged()),this,TQT_SLOT(slotSettingsChanged()));
    dialog->show();
}


/*!
    \fn tdesvnPart::slotSettingsChanged()
 */
void tdesvnPart::slotSettingsChanged()
{
    TDEAction * temp;
    temp = actionCollection()->action("toggle_log_follows");
    if (temp) {
        ((TDEToggleAction*)temp)->setChecked(Kdesvnsettings::log_follows_nodes());
    }
    temp = actionCollection()->action("toggle_ignored_files");
    if (temp) {
        ((TDEToggleAction*)temp)->setChecked(Kdesvnsettings::display_ignored_files());
    }
#if 0
    /// not needed this momenta
    temp = actionCollection()->action("toggle_unknown_files");
    if (temp) {
        ((TDEToggleAction*)temp)->setChecked(tdesvnPart_Prefs::self()->mdisp_unknown_files);
    }
#endif
    emit settingsChanged();
}

/*
 * we may not use generic factory 'cause we make some specials */
TDEInstance*  cFactory::s_instance = 0L;
TDEAboutData* cFactory::s_about = 0L;
commandline_part* cFactory::s_cline = 0L;

KParts::Part* cFactory::createPartObject( TQWidget *parentWidget, const char *widgetName,
                                                        TQObject *parent, const char *name,
                                                        const char *classname, const TQStringList &args )
{
    Q_UNUSED(classname);
    // Create an instance of our Part
    return new tdesvnPart( parentWidget, widgetName, parent, name, args );
}

KParts::Part* cFactory::createAppPart( TQWidget *parentWidget, const char *widgetName,
                                          TQObject *parent, const char *name,
                                          const char *classname, const TQStringList &args )
{
    Q_UNUSED(classname);
    // Create an instance of our Part
    tdesvnPart* obj = new tdesvnPart( parentWidget, widgetName, parent, name, false, args);
    emit objectCreated( obj );
    return obj;
}

cFactory::~cFactory()
{
    delete s_instance;
    delete s_about;
    delete s_cline;

    s_instance = 0L;
    s_cline = 0L;
}

TDEInstance* cFactory::instance()
{
    if( !s_instance ) {
        s_about = tdesvnPart::createAboutData();
        s_instance = new TDEInstance(s_about);
    }
    return s_instance;
}

commandline_part*cFactory::createCommandIf(TQObject*parent,const char*name, TDECmdLineArgs *args)
{
    if (!s_cline) {
        // no emit of creation - we will delete this object in destructor
        s_cline = new commandline_part(parent,name,args);
    }
    return s_cline;
}

#include "tdesvn_part.moc"