• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

ark

  • sources
  • kde-4.12
  • kdeutils
  • ark
  • app
mainwindow.cpp
Go to the documentation of this file.
1 /*
2  * ark -- archiver for the KDE project
3  *
4  * Copyright (C) 2002-2003: Georg Robbers <Georg.Robbers@urz.uni-hd.de>
5  * Copyright (C) 2003: Helio Chissini de Castro <helio@conectiva.com>
6  * Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
7  * Copyright (C) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  */
24 #include "mainwindow.h"
25 #include "kerfuffle/archive.h"
26 #include "part/interface.h"
27 
28 #include <KPluginLoader>
29 #include <KPluginFactory>
30 #include <KMessageBox>
31 #include <KApplication>
32 #include <KLocale>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KRecentFilesAction>
37 #include <KGlobal>
38 #include <KDebug>
39 #include <KEditToolBar>
40 #include <KShortcutsDialog>
41 
42 #include <QDragEnterEvent>
43 #include <QDragMoveEvent>
44 #include <QWeakPointer>
45 
46 static bool isValidArchiveDrag(const QMimeData *data)
47 {
48  return ((data->hasUrls()) && (data->urls().count() == 1));
49 }
50 
51 MainWindow::MainWindow(QWidget *)
52  : KParts::MainWindow()
53 {
54  setXMLFile(QLatin1String( "arkui.rc" ));
55 
56  setupActions();
57  statusBar();
58 
59  if (!initialGeometrySet()) {
60  resize(640, 480);
61  }
62  setAutoSaveSettings(QLatin1String( "MainWindow" ));
63 
64  setAcceptDrops(true);
65 }
66 
67 MainWindow::~MainWindow()
68 {
69  if (m_recentFilesAction) {
70  m_recentFilesAction->saveEntries(KGlobal::config()->group("Recent Files"));
71  }
72  delete m_part;
73  m_part = 0;
74 }
75 
76 void MainWindow::dragEnterEvent(QDragEnterEvent * event)
77 {
78  kDebug() << event;
79 
80  Interface *iface = qobject_cast<Interface*>(m_part);
81  if (iface->isBusy()) {
82  return;
83  }
84 
85  if ((event->source() == NULL) &&
86  (isValidArchiveDrag(event->mimeData()))) {
87  event->acceptProposedAction();
88  }
89  return;
90 }
91 
92 void MainWindow::dropEvent(QDropEvent * event)
93 {
94  kDebug() << event;
95 
96  Interface *iface = qobject_cast<Interface*>(m_part);
97  if (iface->isBusy()) {
98  return;
99  }
100 
101  if ((event->source() == NULL) &&
102  (isValidArchiveDrag(event->mimeData()))) {
103  event->acceptProposedAction();
104  }
105 
106  //TODO: if this call provokes a message box the drag will still be going
107  //while the box is onscreen. looks buggy, do something about it
108  openUrl(event->mimeData()->urls().at(0));
109 }
110 
111 void MainWindow::dragMoveEvent(QDragMoveEvent * event)
112 {
113  kDebug() << event;
114 
115  Interface *iface = qobject_cast<Interface*>(m_part);
116  if (iface->isBusy()) {
117  return;
118  }
119 
120  if ((event->source() == NULL) &&
121  (isValidArchiveDrag(event->mimeData()))) {
122  event->acceptProposedAction();
123  }
124 }
125 
126 bool MainWindow::loadPart()
127 {
128  KPluginFactory *factory = KPluginLoader(QLatin1String( "arkpart" )).factory();
129  if (factory) {
130  m_part = static_cast<KParts::ReadWritePart*>(factory->create<KParts::ReadWritePart>(this));
131  }
132  if (!factory || !m_part) {
133  KMessageBox::error(this, i18n("Unable to find Ark's KPart component, please check your installation."));
134  return false;
135  }
136 
137  m_part->setObjectName( QLatin1String("ArkPart" ));
138  setCentralWidget(m_part->widget());
139  createGUI(m_part);
140 
141  connect(m_part, SIGNAL(busy()), this, SLOT(updateActions()));
142  connect(m_part, SIGNAL(ready()), this, SLOT(updateActions()));
143  connect(m_part, SIGNAL(quit()), this, SLOT(quit()));
144 
145  return true;
146 }
147 
148 void MainWindow::setupActions()
149 {
150  m_newAction = KStandardAction::openNew(this, SLOT(newArchive()), actionCollection());
151  m_openAction = KStandardAction::open(this, SLOT(openArchive()), actionCollection());
152  KStandardAction::quit(this, SLOT(quit()), actionCollection());
153 
154  m_recentFilesAction = KStandardAction::openRecent(this, SLOT(openUrl(KUrl)), actionCollection());
155  m_recentFilesAction->setToolBarMode(KRecentFilesAction::MenuMode);
156  m_recentFilesAction->setToolButtonPopupMode(QToolButton::DelayedPopup);
157  m_recentFilesAction->setIconText(i18nc("action, to open an archive", "Open"));
158  m_recentFilesAction->setStatusTip(i18n("Click to open an archive, click and hold to open a recently-opened archive"));
159  m_recentFilesAction->setToolTip(i18n("Open an archive"));
160  m_recentFilesAction->loadEntries(KGlobal::config()->group("Recent Files"));
161  connect(m_recentFilesAction, SIGNAL(triggered()),
162  this, SLOT(openArchive()));
163 
164  createStandardStatusBarAction();
165 
166  KStandardAction::configureToolbars(this, SLOT(editToolbars()), actionCollection());
167  KStandardAction::keyBindings(this, SLOT(editKeyBindings()), actionCollection());
168 }
169 
170 void MainWindow::updateActions()
171 {
172  Interface *iface = qobject_cast<Interface*>(m_part);
173  m_newAction->setEnabled(!iface->isBusy());
174  m_openAction->setEnabled(!iface->isBusy());
175  m_recentFilesAction->setEnabled(!iface->isBusy());
176 }
177 
178 void MainWindow::editKeyBindings()
179 {
180  KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
181  dlg.addCollection(actionCollection());
182  dlg.addCollection(m_part->actionCollection());
183 
184  dlg.configure();
185 }
186 
187 void MainWindow::editToolbars()
188 {
189  saveMainWindowSettings(KGlobal::config()->group(QLatin1String("MainWindow")));
190 
191  QWeakPointer<KEditToolBar> dlg = new KEditToolBar(factory(), this);
192  dlg.data()->exec();
193 
194  createGUI(m_part);
195 
196  applyMainWindowSettings(KGlobal::config()->group(QLatin1String("MainWindow")));
197 
198  delete dlg.data();
199 }
200 
201 void MainWindow::openArchive()
202 {
203  Interface *iface = qobject_cast<Interface*>(m_part);
204  Q_ASSERT(iface);
205  const KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///ArkOpenDir"),
206  Kerfuffle::supportedMimeTypes().join( QLatin1String( " " )),
207  this);
208  openUrl(url);
209 }
210 
211 void MainWindow::openUrl(const KUrl& url)
212 {
213  if (!url.isEmpty()) {
214  m_part->setArguments(m_openArgs);
215 
216  if (m_part->openUrl(url)) {
217  m_recentFilesAction->addUrl(url);
218  } else {
219  m_recentFilesAction->removeUrl(url);
220  }
221  }
222 }
223 
224 void MainWindow::setShowExtractDialog(bool option)
225 {
226  if (option) {
227  m_openArgs.metaData()[QLatin1String( "showExtractDialog" )] = QLatin1String( "true" );
228  } else {
229  m_openArgs.metaData().remove(QLatin1String( "showExtractDialog" ));
230  }
231 }
232 
233 void MainWindow::quit()
234 {
235  close();
236 }
237 
238 void MainWindow::newArchive()
239 {
240  Interface *iface = qobject_cast<Interface*>(m_part);
241  Q_ASSERT(iface);
242 
243  const QStringList mimeTypes = Kerfuffle::supportedWriteMimeTypes();
244 
245  kDebug() << "Supported mimetypes are" << mimeTypes.join( QLatin1String( " " ));
246 
247  const KUrl saveFileUrl =
248  KFileDialog::getSaveUrl(KUrl("kfiledialog:///ArkNewDir"),
249  mimeTypes.join(QLatin1String(" ")));
250 
251  m_openArgs.metaData()[QLatin1String( "createNewArchive" )] = QLatin1String( "true" );
252 
253  openUrl(saveFileUrl);
254 
255  m_openArgs.metaData().remove(QLatin1String( "showExtractDialog" ));
256  m_openArgs.metaData().remove(QLatin1String( "createNewArchive" ));
257 }
MainWindow::dragEnterEvent
void dragEnterEvent(class QDragEnterEvent *event)
Definition: mainwindow.cpp:76
MainWindow::loadPart
bool loadPart()
Definition: mainwindow.cpp:126
Kerfuffle::supportedWriteMimeTypes
QStringList supportedWriteMimeTypes()
Definition: archive.cpp:306
archive.h
isValidArchiveDrag
static bool isValidArchiveDrag(const QMimeData *data)
Definition: mainwindow.cpp:46
Kerfuffle::supportedMimeTypes
QStringList supportedMimeTypes()
Definition: archive.cpp:279
interface.h
mainwindow.h
MainWindow::MainWindow
MainWindow(QWidget *parent=0)
Definition: mainwindow.cpp:51
Interface
Definition: interface.h:27
Interface::isBusy
virtual bool isBusy() const =0
MainWindow::setShowExtractDialog
void setShowExtractDialog(bool)
Definition: mainwindow.cpp:224
MainWindow::dragMoveEvent
void dragMoveEvent(class QDragMoveEvent *event)
Definition: mainwindow.cpp:111
MainWindow::openUrl
void openUrl(const KUrl &url)
Definition: mainwindow.cpp:211
MainWindow::~MainWindow
~MainWindow()
Definition: mainwindow.cpp:67
MainWindow
Definition: mainwindow.h:31
MainWindow::dropEvent
void dropEvent(class QDropEvent *event)
Definition: mainwindow.cpp:92
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:08:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ark

Skip menu "ark"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal