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@80
|
22 #include "kdiff3_part.h"
|
joachim99@8
|
23
|
joachim99@80
|
24 #include <kshortcutsdialog.h>
|
joachim99@8
|
25 #include <kfiledialog.h>
|
joachim99@8
|
26 #include <kconfig.h>
|
joachim99@8
|
27 #include <kurl.h>
|
joachim99@8
|
28
|
joachim99@8
|
29 #include <kedittoolbar.h>
|
joachim99@8
|
30
|
joachim99@8
|
31 #include <kaction.h>
|
joachim99@80
|
32 #include <kstandardaction.h>
|
joachim99@8
|
33
|
joachim99@8
|
34 #include <klibloader.h>
|
joachim99@8
|
35 #include <kmessagebox.h>
|
joachim99@8
|
36 #include <kstatusbar.h>
|
joachim99@8
|
37 #include <klocale.h>
|
joachim99@8
|
38
|
joachim99@8
|
39 #include <iostream>
|
joachim99@75
|
40
|
joachim99@75
|
41 #include <QStatusBar>
|
joachim99@70
|
42 #include <QCloseEvent>
|
joachim99@80
|
43 #include <ktoolbar.h>
|
joachim99@8
|
44
|
joachim99@75
|
45
|
joachim99@80
|
46 KDiff3Shell::KDiff3Shell( bool bCompleteInit )
|
joachim99@80
|
47 : KParts::MainWindow( )
|
joachim99@8
|
48 {
|
joachim99@8
|
49 m_bUnderConstruction = true;
|
joachim99@8
|
50 // set the shell's ui resource file
|
joachim99@8
|
51 setXMLFile("kdiff3_shell.rc");
|
joachim99@8
|
52
|
joachim99@8
|
53 // and a status bar
|
joachim99@8
|
54 statusBar()->show();
|
joachim99@8
|
55
|
joachim99@80
|
56 // m_part = static_cast<KParts::ReadWritePart*>(factory->create(this, "KDiff3Part", QStringList("KParts::ReadWritePart")));
|
joachim99@80
|
57 m_part = new KDiff3Part( this, "KDiff3Part", this );
|
joachim99@8
|
58
|
joachim99@80
|
59 if (m_part)
|
joachim99@80
|
60 {
|
joachim99@80
|
61 // and integrate the part's GUI with the shell's
|
joachim99@80
|
62 createGUI(m_part);
|
joachim99@80
|
63 //toolBar()->setToolButtonStyle( Qt::ToolButtonIconOnly );
|
joachim99@8
|
64
|
joachim99@80
|
65 // tell the KParts::MainWindow that this is indeed the main widget
|
joachim99@80
|
66 setCentralWidget(m_part->widget());
|
joachim99@8
|
67
|
joachim99@80
|
68 if (bCompleteInit)
|
joachim99@80
|
69 ((KDiff3App*)m_part->widget())->completeInit();
|
joachim99@80
|
70 connect(((KDiff3App*)m_part->widget()), SIGNAL(createNewInstance(const QString&, const QString&, const QString&)), this, SLOT(slotNewInstance(const QString&, const QString&, const QString&)));
|
joachim99@80
|
71 }
|
joachim99@8
|
72 else
|
joachim99@8
|
73 {
|
joachim99@8
|
74 // if we couldn't find our Part, we exit since the Shell by
|
joachim99@8
|
75 // itself can't do anything useful
|
joachim99@80
|
76 KMessageBox::error(this, i18n("Could not initialize our part!\n"
|
joachim99@8
|
77 "This usually happens due to an installation problem. "
|
joachim99@8
|
78 "Please read the README-file in the source package for details.")
|
joachim99@8
|
79 );
|
joachim99@66
|
80 //kapp->quit();
|
joachim99@80
|
81
|
joachim99@66
|
82 ::exit(-1); //kapp->quit() doesn't work here yet.
|
joachim99@66
|
83
|
joachim99@8
|
84 // we return here, cause kapp->quit() only means "exit the
|
joachim99@8
|
85 // next time we enter the event loop...
|
joachim99@80
|
86
|
joachim99@8
|
87 return;
|
joachim99@8
|
88 }
|
joachim99@8
|
89
|
joachim99@8
|
90 // apply the saved mainwindow settings, if any, and ask the mainwindow
|
joachim99@8
|
91 // to automatically save settings if changed: window size, toolbar
|
joachim99@8
|
92 // position, icon size, etc.
|
joachim99@8
|
93 setAutoSaveSettings();
|
joachim99@8
|
94 m_bUnderConstruction = false;
|
joachim99@8
|
95 }
|
joachim99@8
|
96
|
joachim99@8
|
97 KDiff3Shell::~KDiff3Shell()
|
joachim99@8
|
98 {
|
joachim99@8
|
99 }
|
joachim99@8
|
100
|
joachim99@8
|
101 bool KDiff3Shell::queryClose()
|
joachim99@8
|
102 {
|
joachim99@8
|
103 if (m_part)
|
joachim99@8
|
104 return ((KDiff3App*)m_part->widget())->queryClose();
|
joachim99@8
|
105 else
|
joachim99@8
|
106 return true;
|
joachim99@8
|
107 }
|
joachim99@8
|
108
|
joachim99@8
|
109 bool KDiff3Shell::queryExit()
|
joachim99@8
|
110 {
|
joachim99@8
|
111 return true;
|
joachim99@8
|
112 }
|
joachim99@8
|
113
|
joachim99@69
|
114 void KDiff3Shell::closeEvent(QCloseEvent*e)
|
joachim99@69
|
115 {
|
joachim99@69
|
116 if ( queryClose() )
|
joachim99@69
|
117 {
|
joachim99@69
|
118 e->accept();
|
joachim99@69
|
119 bool bFileSaved = ((KDiff3App*)m_part->widget())->isFileSaved();
|
joachim99@80
|
120 bool bDirCompare = ((KDiff3App*)m_part->widget())->isDirComparison();
|
joachim99@80
|
121 KApplication::exit( bFileSaved || bDirCompare ? 0 : 1 );
|
joachim99@69
|
122 }
|
joachim99@69
|
123 else
|
joachim99@69
|
124 e->ignore();
|
joachim99@69
|
125 }
|
joachim99@8
|
126
|
joachim99@8
|
127 void KDiff3Shell::optionsShowToolbar()
|
joachim99@8
|
128 {
|
joachim99@8
|
129 // this is all very cut and paste code for showing/hiding the
|
joachim99@8
|
130 // toolbar
|
joachim99@8
|
131 if (m_toolbarAction->isChecked())
|
joachim99@8
|
132 toolBar()->show();
|
joachim99@8
|
133 else
|
joachim99@8
|
134 toolBar()->hide();
|
joachim99@8
|
135 }
|
joachim99@8
|
136
|
joachim99@8
|
137 void KDiff3Shell::optionsShowStatusbar()
|
joachim99@8
|
138 {
|
joachim99@8
|
139 // this is all very cut and paste code for showing/hiding the
|
joachim99@8
|
140 // statusbar
|
joachim99@8
|
141 if (m_statusbarAction->isChecked())
|
joachim99@8
|
142 statusBar()->show();
|
joachim99@8
|
143 else
|
joachim99@8
|
144 statusBar()->hide();
|
joachim99@8
|
145 }
|
joachim99@8
|
146
|
joachim99@8
|
147 void KDiff3Shell::optionsConfigureKeys()
|
joachim99@8
|
148 {
|
joachim99@80
|
149 KShortcutsDialog::configure(actionCollection() /*, "kdiff3_shell.rc" */ );
|
joachim99@8
|
150 }
|
joachim99@8
|
151
|
joachim99@8
|
152 void KDiff3Shell::optionsConfigureToolbars()
|
joachim99@8
|
153 {
|
joachim99@80
|
154 KConfigGroup mainWindowGroup( KGlobal::config(), "MainWindow" );
|
joachim99@80
|
155 saveMainWindowSettings( mainWindowGroup );
|
joachim99@8
|
156
|
joachim99@8
|
157 // use the standard toolbar editor
|
joachim99@80
|
158 KEditToolBar dlg(factory());
|
joachim99@8
|
159 connect(&dlg, SIGNAL(newToolbarConfig()),
|
joachim99@8
|
160 this, SLOT(applyNewToolbarConfig()));
|
joachim99@8
|
161 dlg.exec();
|
joachim99@8
|
162 }
|
joachim99@8
|
163
|
joachim99@8
|
164 void KDiff3Shell::applyNewToolbarConfig()
|
joachim99@8
|
165 {
|
joachim99@80
|
166 KConfigGroup mainWindowGroup( KGlobal::config(), "MainWindow" );
|
joachim99@80
|
167 applyMainWindowSettings( mainWindowGroup );
|
joachim99@8
|
168 }
|
joachim99@8
|
169
|
joachim99@69
|
170 void KDiff3Shell::slotNewInstance( const QString& fn1, const QString& fn2, const QString& fn3 )
|
joachim99@69
|
171 {
|
joachim99@69
|
172 KDiff3Shell* pKDiff3Shell = new KDiff3Shell(false);
|
joachim99@69
|
173 ((KDiff3App*)pKDiff3Shell->m_part->widget())->completeInit(fn1,fn2,fn3);
|
joachim99@69
|
174 }
|
joachim99@69
|
175
|
joachim99@70
|
176 //#include "kdiff3_shell.moc"
|