2 ** Copyright (C) 2007 Toivo Pedaste <toivo@ucs.uwa.edu.au>
4 // Author: Toivo Pedaste
6 // See kpackage.h for more information.
10 ** This program is free software; you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation; either version 2 of the License, or
13 ** (at your option) any later version.
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** GNU General Public License for more details.
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program in a file called COPYING; if not, write to
22 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 ** MA 02110-1301, USA.
27 ** Bug reports and questions can be sent to kde-devel@kde.org
30 #include <kactioncollection.h>
31 #include <kapplication.h>
32 #include <QtCore/QDir>
33 #include <QtGui/QLabel>
34 #include <QtGui/QFrame>
36 #include <QtGui/QDragEnterEvent>
37 #include <QtGui/QResizeEvent>
38 #include <QtGui/QDropEvent>
39 #include <QtGui/QCloseEvent>
42 #include <kxmlguifactory.h>
43 #include <kfiledialog.h>
44 #include <QtGui/QProgressBar>
46 #include <krecentfilesaction.h>
49 #include <kinputdialog.h>
51 #include <kiconloader.h>
52 #include <kstandardaction.h>
53 #include <kedittoolbar.h>
54 #include <kstandardshortcut.h>
55 #include <kio/netaccess.h>
56 #include <kmessagebox.h>
60 #include "managementWidget.h"
61 #include "pkgOptions.h"
64 #include "kpSettings.h"
67 //////////////////////////////////////////////////////////////////////////////
68 //////////////////////////////////////////////////////////////////////////////
70 KPKG::KPKG(const KSharedConfigPtr
&_config
)
72 config(KGlobal::config())
74 kpackage
= new KPACKAGE(_config
, this);
75 setCentralWidget(kpackage
);
77 kpackage
->management
->readPSeparator();
79 // Get a nice default size
87 setAutoSaveSettings();
92 void KPKG::setupMenu()
95 pack_open
= KStandardAction::open(kpackage
, SLOT(fileOpen()),
98 recent
= KStandardAction::openRecent(this, SLOT(openRecent(const KUrl
&)),
100 fgroup
= new KConfigGroup(config
, "RecentFiles");
101 recent
->loadEntries( *fgroup
);
104 pack_hopen
= actionCollection()->addAction( "pack_hopen");
105 pack_hopen
->setText(i18n("remote &Host..."));
106 pack_hopen
->setIcon(KIcon("remote-host"));
107 connect(pack_hopen
, SIGNAL(triggered()), this, SLOT(openHost()));
109 recentHosts
= actionCollection()->add
<KRecentFilesAction
>("remote_host");
110 recentHosts
->setText(i18n("Recent Remote Hosts"));
111 recentHosts
->setIcon(KIcon("remote-host"));
112 connect(recentHosts
, SIGNAL(urlSelected(const KUrl
&)),SLOT(openRecentHost(const KUrl
&)));
114 // recentHosts = new KRecentFilesAction(KIcon("remote-host"), i18n("Recent remote Hosts"), actionCollection());
116 // connect(recentHosts, SIGNAL(urlSelected(const KUrl&)),this, SLOT(openRecentHost(const KUrl&)));
118 hgroup
= new KConfigGroup(config
, "RecentHosts");
119 recentHosts
->loadEntries( *hgroup
);
122 pack_find
= actionCollection()->addAction( "pack_find");
123 pack_find
->setText(i18n("Find &Package..."));
124 pack_find
->setIcon(KIcon("edit-find"));
125 qobject_cast
<KAction
*>( pack_find
)->setShortcut(KStandardShortcut::shortcut(KStandardShortcut::Find
));
126 connect(pack_find
, SIGNAL(triggered()), kpackage
, SLOT(find()));
128 pack_findf
= actionCollection()->addAction( "pack_findf");
129 pack_findf
->setText(i18n("Find &File..."));
130 pack_findf
->setIcon(KIcon("file-find"));
131 connect(pack_findf
, SIGNAL(triggered()), kpackage
, SLOT(findf()));
133 kpack_reload
= actionCollection()->addAction( "kpack_reload" );
134 kpack_reload
->setText(i18n("&Reload"));
135 kpack_reload
->setIcon(KIcon("view-refresh"));
136 qobject_cast
<KAction
*>( kpack_reload
)->setShortcut(KStandardShortcut::shortcut(KStandardShortcut::Reload
));
137 connect(kpack_reload
, SIGNAL(triggered()), kpackage
, SLOT(reload()));
139 (void) KStandardAction::quit(kpackage
, SLOT(fileQuit()),
142 pack_prev
= KStandardAction::back(kpackage
->management
->treeList
, SLOT(previous()),
144 actionCollection()->addAction( "pack_prev", pack_prev
);
146 pack_next
= KStandardAction::forward(kpackage
->management
->treeList
, SLOT(next()),
149 actionCollection()->addAction( "pack_next", pack_next
);
150 QAction
*a
= actionCollection()->addAction( "kpack_expand");
152 a
->setText(i18n("&Expand Tree"));
153 a
->setIcon(KIcon("ftout"));
154 connect(a
, SIGNAL(triggered()), kpackage
, SLOT(expandTree()));
156 a
= actionCollection()->addAction("kpack_collapse");
158 a
->setText(i18n("&Collapse Tree"));
159 a
->setIcon(KIcon("ftin"));
160 connect(a
, SIGNAL(triggered()), kpackage
, SLOT(collapseTree()));
162 a
= actionCollection()->addAction("kpack_clear");
163 a
->setText(i18n("Clear &Marked"));
164 connect(a
, SIGNAL(triggered()), kpackage
, SLOT(clearMarked()));
166 a
= actionCollection()->addAction( "kpack_markall");
167 a
->setText(i18n("Mark &All"));
168 connect(a
, SIGNAL(triggered()), kpackage
, SLOT(markAll()));
170 pack_install
= actionCollection()->addAction("install_single" );
171 pack_install
->setText(i18n("&Install"));
172 connect(pack_install
, SIGNAL(triggered()), kpackage
->management
, SLOT(installSingleClicked()));
174 pack_install
->setEnabled(false);
175 kpackage
->management
->setInstallAction(pack_install
);
178 pack_uninstall
= actionCollection()->addAction( "uninstall_single");
179 pack_uninstall
->setText(i18n("&Uninstall"));
180 connect(pack_uninstall
, SIGNAL(triggered()), kpackage
->management
, SLOT(uninstallSingleClicked()));
182 pack_uninstall
->setEnabled(false);
183 kpackage
->management
->setUninstallAction(pack_uninstall
);
186 a
= actionCollection()->addAction( "install_marked");
187 a
->setText(i18n("&Install Marked"));
188 connect(a
, SIGNAL(triggered()), kpackage
->management
, SLOT(installMultClicked()));
190 a
= actionCollection()->addAction( "unstall_marked");
192 a
->setText(i18n("&Uninstall Marked"));
193 connect(a
, SIGNAL(triggered()), kpackage
->management
, SLOT(uninstallMultClicked()));
195 setStandardToolBarMenuEnabled(true);
197 KStandardAction::configureToolbars( this, SLOT(configureToolBars()),
200 KStandardAction::saveOptions( this, SLOT(saveSettings()), actionCollection());
202 KStandardAction::keyBindings( guiFactory(), SLOT(configureShortcuts()), actionCollection());
204 a
= actionCollection()->addAction( "kpack_options");
206 a
->setText(i18n("Configure &KPackage..."));
207 a
->setIcon(KIcon("configure"));
208 connect(a
, SIGNAL(triggered()), this, SLOT(setOptions()));
210 kDebug() << "kpinterface[DEBt]->makeMenu\n";
211 kpinterface
[DEBt
]->makeMenu(actionCollection());
213 // urlList.setAutoDelete(TRUE);
219 void KPKG::createSettings()
221 conf
= new kpSettings();
222 conf
->readSettings();
223 kconf
= new kpConfig(conf
, this);
224 connect( kconf
, SIGNAL(settingsChanged(const QString
&)),
225 this, SLOT(updateConfiguration()) );
229 void KPKG::updateConfiguration()
231 conf
->readSettings();
232 kDebug() << "kpConfig::updateConfiguration()\n";
235 void KPKG::disableMenu()
237 pack_open
->setEnabled(false);
238 pack_find
->setEnabled(false);
239 pack_findf
->setEnabled(false);
240 kpack_reload
->setEnabled(false);
241 recent
->setEnabled(false);
244 void KPKG::enableMenu()
246 pack_open
->setEnabled(true);
247 pack_find
->setEnabled(true);
248 pack_findf
->setEnabled(true);
249 kpack_reload
->setEnabled(true);
250 recent
->setEnabled(true);
253 void KPKG::disableNext() {
254 pack_next
->setEnabled(false);
257 void KPKG::enableNext() {
258 pack_next
->setEnabled(true);
261 void KPKG::disablePrevious() {
262 pack_prev
->setEnabled(false);
265 void KPKG::enablePrevious() {
266 pack_prev
->setEnabled(true);
268 void KPKG::openRecent(const KUrl
& url
){
270 kpackage
->openNetFile( url
);
273 void KPKG::openHost() {
274 kDebug("KPKG::openHost\n");
276 QString host
= KInputDialog::getText( QString::null
,
277 i18n("Name of Remote Host:") );
279 if (!host
.isEmpty()) {
280 QString url
= "ssh:" + host
;
281 add_recent_host(url
);
284 s
<< "--remote" << host
;
285 int n
= KProcess::startDetached("kpackage",s
);
286 kDebug() << " startDetached " << n
<< "\n";
290 void KPKG::openRecentHost(const KUrl
& url
){
291 kDebug() << " KPKG::openRecentHost " << url
<< "\n";
293 QString host
= url
.url().remove("ssh://");
294 host
= host
.remove("ssh:");
297 s
<< "--remote" << host
;
298 int n
= KProcess::startDetached("kpackage",s
);
299 kDebug() << " startDetached " << n
<< "\n";
302 void KPKG::add_recent_file(const QString
&newfile
){
304 KUrl url
= KUrl(newfile
);
306 recent
->addUrl( url
);
307 recent
->saveEntries(*fgroup
);
310 void KPKG::add_recent_host(const QString
&newhost
){
314 recentHosts
->addUrl( url
);
315 recentHosts
->saveEntries(*hgroup
);
318 void KPKG::configureToolBars() {
319 KEditToolBar
dlg(actionCollection());
320 connect(&dlg
,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
324 void KPKG::slotNewToolbarConfig() {
328 void KPKG::writeSettings(){
330 kpackage
->management
->writePSeparator();
332 KConfigGroup
group(config
, "Kpackage");
333 recent
->saveEntries( group
);
335 kpackage
->management
->treeList
->writeTreePos();
340 void KPKG::setOptions(){
344 void KPKG::saveSettings(){
348 void KPKG::saveProperties(KConfigGroup
& config
)
350 config
.writePathEntry("Name", kpackage
->save_url
.url());
354 void KPKG::readProperties(const KConfigGroup
&config
)
356 QString entry
= config
.readPathEntry("Name", QString()); // no default
361 kpackage
->openNetFiles(lst
);
366 void KPKG::closeEvent ( QCloseEvent
*) {
367 kpackage
->fileQuit();