joachim99@69
|
1 /***************************************************************************
|
joachim99@77
|
2 * Copyright (C) 2003-2007 Joachim Eibl <joachim.eibl at gmx.de> *
|
joachim99@69
|
3 * *
|
joachim99@69
|
4 * This program is free software; you can redistribute it and/or modify *
|
joachim99@69
|
5 * it under the terms of the GNU General Public License as published by *
|
joachim99@69
|
6 * the Free Software Foundation; either version 2 of the License, or *
|
joachim99@69
|
7 * (at your option) any later version. *
|
joachim99@69
|
8 * *
|
joachim99@69
|
9 * This program is distributed in the hope that it will be useful, *
|
joachim99@69
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
joachim99@69
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
joachim99@69
|
12 * GNU General Public License for more details. *
|
joachim99@69
|
13 * *
|
joachim99@69
|
14 * You should have received a copy of the GNU General Public License *
|
joachim99@69
|
15 * along with this program; if not, write to the *
|
joachim99@69
|
16 * Free Software Foundation, Inc., *
|
joachim99@69
|
17 * 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
|
joachim99@69
|
18 ***************************************************************************/
|
joachim99@8
|
19
|
joachim99@8
|
20 #include "kdiff3_shell.h"
|
joachim99@8
|
21 #include "kdiff3.h"
|
joachim99@8
|
22
|
joachim99@8
|
23 #include <kkeydialog.h>
|
joachim99@8
|
24 #include <kfiledialog.h>
|
joachim99@8
|
25 #include <kconfig.h>
|
joachim99@8
|
26 #include <kurl.h>
|
joachim99@8
|
27
|
joachim99@8
|
28 #include <kedittoolbar.h>
|
joachim99@8
|
29
|
joachim99@8
|
30 #include <kaction.h>
|
joachim99@8
|
31 #include <kstdaction.h>
|
joachim99@8
|
32
|
joachim99@8
|
33 #include <klibloader.h>
|
joachim99@8
|
34 #include <kmessagebox.h>
|
joachim99@8
|
35 #include <kstatusbar.h>
|
joachim99@8
|
36 #include <klocale.h>
|
joachim99@8
|
37
|
joachim99@8
|
38 #include <iostream>
|
joachim99@75
|
39
|
joachim99@75
|
40 #include <QStatusBar>
|
joachim99@70
|
41 #include <QCloseEvent>
|
joachim99@8
|
42
|
joachim99@75
|
43
|
joachim99@69
|
44 KDiff3Shell::KDiff3Shell(bool bCompleteInit)
|
joachim99@8
|
45 : KParts::MainWindow( 0L, "kdiff3" )
|
joachim99@8
|
46 {
|
joachim99@8
|
47 m_bUnderConstruction = true;
|
joachim99@8
|
48 // set the shell's ui resource file
|
joachim99@8
|
49 setXMLFile("kdiff3_shell.rc");
|
joachim99@8
|
50
|
joachim99@8
|
51 // and a status bar
|
joachim99@8
|
52 statusBar()->show();
|
joachim99@8
|
53
|
joachim99@8
|
54 // this routine will find and load our Part. it finds the Part by
|
joachim99@8
|
55 // name which is a bad idea usually.. but it's alright in this
|
joachim99@8
|
56 // case since our Part is made for this Shell
|
joachim99@8
|
57 KLibFactory *factory = KLibLoader::self()->factory("libkdiff3part");
|
joachim99@8
|
58 if (factory)
|
joachim99@8
|
59 {
|
joachim99@8
|
60 // now that the Part is loaded, we cast it to a Part to get
|
joachim99@8
|
61 // our hands on it
|
joachim99@8
|
62 m_part = static_cast<KParts::ReadWritePart *>(factory->create(this,
|
joachim99@8
|
63 "kdiff3_part", "KParts::ReadWritePart" ));
|
joachim99@8
|
64
|
joachim99@8
|
65 if (m_part)
|
joachim99@8
|
66 {
|
joachim99@8
|
67 // and integrate the part's GUI with the shell's
|
joachim99@8
|
68 createGUI(m_part);
|
joachim99@8
|
69
|
joachim99@8
|
70 // tell the KParts::MainWindow that this is indeed the main widget
|
joachim99@8
|
71 setCentralWidget(m_part->widget());
|
joachim99@8
|
72
|
joachim99@69
|
73 if (bCompleteInit)
|
joachim99@69
|
74 ((KDiff3App*)m_part->widget())->completeInit();
|
joachim99@69
|
75 connect(((KDiff3App*)m_part->widget()), SIGNAL(createNewInstance(const QString&, const QString&, const QString&)), this, SLOT(slotNewInstance(const QString&, const QString&, const QString&)));
|
joachim99@8
|
76 }
|
joachim99@8
|
77 }
|
joachim99@8
|
78 else
|
joachim99@8
|
79 {
|
joachim99@8
|
80 // if we couldn't find our Part, we exit since the Shell by
|
joachim99@8
|
81 // itself can't do anything useful
|
joachim99@8
|
82 KMessageBox::error(this, i18n("Could not find our part!\n"
|
joachim99@8
|
83 "This usually happens due to an installation problem. "
|
joachim99@8
|
84 "Please read the README-file in the source package for details.")
|
joachim99@8
|
85 );
|
joachim99@66
|
86 //kapp->quit();
|
joachim99@66
|
87
|
joachim99@66
|
88 ::exit(-1); //kapp->quit() doesn't work here yet.
|
joachim99@66
|
89
|
joachim99@8
|
90 // we return here, cause kapp->quit() only means "exit the
|
joachim99@8
|
91 // next time we enter the event loop...
|
joachim99@66
|
92
|
joachim99@8
|
93 return;
|
joachim99@8
|
94 }
|
joachim99@8
|
95
|
joachim99@8
|
96 // apply the saved mainwindow settings, if any, and ask the mainwindow
|
joachim99@8
|
97 // to automatically save settings if changed: window size, toolbar
|
joachim99@8
|
98 // position, icon size, etc.
|
joachim99@8
|
99 setAutoSaveSettings();
|
joachim99@8
|
100 m_bUnderConstruction = false;
|
joachim99@8
|
101 }
|
joachim99@8
|
102
|
joachim99@8
|
103 KDiff3Shell::~KDiff3Shell()
|
joachim99@8
|
104 {
|
joachim99@8
|
105 }
|
joachim99@8
|
106
|
joachim99@8
|
107 bool KDiff3Shell::queryClose()
|
joachim99@8
|
108 {
|
joachim99@8
|
109 if (m_part)
|
joachim99@8
|
110 return ((KDiff3App*)m_part->widget())->queryClose();
|
joachim99@8
|
111 else
|
joachim99@8
|
112 return true;
|
joachim99@8
|
113 }
|
joachim99@8
|
114
|
joachim99@8
|
115 bool KDiff3Shell::queryExit()
|
joachim99@8
|
116 {
|
joachim99@8
|
117 return true;
|
joachim99@8
|
118 }
|
joachim99@8
|
119
|
joachim99@69
|
120 void KDiff3Shell::closeEvent(QCloseEvent*e)
|
joachim99@69
|
121 {
|
joachim99@69
|
122 if ( queryClose() )
|
joachim99@69
|
123 {
|
joachim99@69
|
124 e->accept();
|
joachim99@69
|
125 bool bFileSaved = ((KDiff3App*)m_part->widget())->isFileSaved();
|
joachim99@69
|
126 KApplication::exit( bFileSaved ? 0 : 1 );
|
joachim99@69
|
127 }
|
joachim99@69
|
128 else
|
joachim99@69
|
129 e->ignore();
|
joachim99@69
|
130 }
|
joachim99@8
|
131
|
joachim99@8
|
132 void KDiff3Shell::optionsShowToolbar()
|
joachim99@8
|
133 {
|
joachim99@8
|
134 // this is all very cut and paste code for showing/hiding the
|
joachim99@8
|
135 // toolbar
|
joachim99@8
|
136 if (m_toolbarAction->isChecked())
|
joachim99@8
|
137 toolBar()->show();
|
joachim99@8
|
138 else
|
joachim99@8
|
139 toolBar()->hide();
|
joachim99@8
|
140 }
|
joachim99@8
|
141
|
joachim99@8
|
142 void KDiff3Shell::optionsShowStatusbar()
|
joachim99@8
|
143 {
|
joachim99@8
|
144 // this is all very cut and paste code for showing/hiding the
|
joachim99@8
|
145 // statusbar
|
joachim99@8
|
146 if (m_statusbarAction->isChecked())
|
joachim99@8
|
147 statusBar()->show();
|
joachim99@8
|
148 else
|
joachim99@8
|
149 statusBar()->hide();
|
joachim99@8
|
150 }
|
joachim99@8
|
151
|
joachim99@8
|
152 void KDiff3Shell::optionsConfigureKeys()
|
joachim99@8
|
153 {
|
joachim99@8
|
154 KKeyDialog::configure(actionCollection(), "kdiff3_shell.rc");
|
joachim99@8
|
155 }
|
joachim99@8
|
156
|
joachim99@8
|
157 void KDiff3Shell::optionsConfigureToolbars()
|
joachim99@8
|
158 {
|
joachim99@8
|
159 #if defined(KDE_MAKE_VERSION)
|
joachim99@8
|
160 # if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
|
joachim99@8
|
161 saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
|
joachim99@8
|
162 # else
|
joachim99@8
|
163 saveMainWindowSettings(KGlobal::config() );
|
joachim99@8
|
164 # endif
|
joachim99@8
|
165 #else
|
joachim99@8
|
166 saveMainWindowSettings(KGlobal::config() );
|
joachim99@8
|
167 #endif
|
joachim99@8
|
168
|
joachim99@8
|
169 // use the standard toolbar editor
|
joachim99@8
|
170 KEditToolbar dlg(factory());
|
joachim99@8
|
171 connect(&dlg, SIGNAL(newToolbarConfig()),
|
joachim99@8
|
172 this, SLOT(applyNewToolbarConfig()));
|
joachim99@8
|
173 dlg.exec();
|
joachim99@8
|
174 }
|
joachim99@8
|
175
|
joachim99@8
|
176 void KDiff3Shell::applyNewToolbarConfig()
|
joachim99@8
|
177 {
|
joachim99@8
|
178 #if defined(KDE_MAKE_VERSION)
|
joachim99@8
|
179 # if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
|
joachim99@8
|
180 applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
|
joachim99@8
|
181 # else
|
joachim99@8
|
182 applyMainWindowSettings(KGlobal::config());
|
joachim99@8
|
183 # endif
|
joachim99@8
|
184 #else
|
joachim99@8
|
185 applyMainWindowSettings(KGlobal::config());
|
joachim99@8
|
186 #endif
|
joachim99@8
|
187 }
|
joachim99@8
|
188
|
joachim99@69
|
189 void KDiff3Shell::slotNewInstance( const QString& fn1, const QString& fn2, const QString& fn3 )
|
joachim99@69
|
190 {
|
joachim99@69
|
191 KDiff3Shell* pKDiff3Shell = new KDiff3Shell(false);
|
joachim99@69
|
192 ((KDiff3App*)pKDiff3Shell->m_part->widget())->completeInit(fn1,fn2,fn3);
|
joachim99@69
|
193 }
|
joachim99@69
|
194
|
joachim99@70
|
195 //#include "kdiff3_shell.moc"
|