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

ark

  • sources
  • kde-4.14
  • kdeutils
  • ark
  • app
main.cpp
Go to the documentation of this file.
1 /*
2  * ark -- archiver for the KDE project
3  *
4  * Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
5  * Copyright (C) 2008-2009 Harald Hvaal <haraldhv@stud.ntnu.no>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "mainwindow.h"
24 #include "batchextract.h"
25 #include "kerfuffle/addtoarchive.h"
26 
27 #include <KAboutData>
28 #include <KApplication>
29 #include <KCmdLineArgs>
30 #include <KDebug>
31 #include <KLocale>
32 
33 #include <QByteArray>
34 #include <QFileInfo>
35 
36 using Kerfuffle::AddToArchive;
37 
38 int main(int argc, char **argv)
39 {
40  KAboutData aboutData("ark", 0, ki18n("Ark"),
41  "2.19", ki18n("KDE Archiving tool"),
42  KAboutData::License_GPL,
43  ki18n("(c) 1997-2011, The Various Ark Developers"),
44  KLocalizedString(),
45  "http://utils.kde.org/projects/ark"
46  );
47 
48  aboutData.addAuthor(ki18n("Raphael Kubo da Costa"),
49  ki18n("Maintainer"),
50  "rakuco@FreeBSD.org");
51  aboutData.addAuthor(ki18n("Harald Hvaal"),
52  ki18n("Former Maintainer"),
53  "haraldhv@stud.ntnu.no");
54  aboutData.addAuthor(ki18n("Henrique Pinto"),
55  ki18n("Former Maintainer"),
56  "henrique.pinto@kdemail.net");
57  aboutData.addAuthor(ki18n("Helio Chissini de Castro"),
58  ki18n("Former maintainer"),
59  "helio@kde.org");
60  aboutData.addAuthor(ki18n("Georg Robbers"),
61  KLocalizedString(),
62  "Georg.Robbers@urz.uni-hd.de");
63  aboutData.addAuthor(ki18n("Roberto Selbach Teixeira"),
64  KLocalizedString(),
65  "maragato@kde.org");
66  aboutData.addAuthor(ki18n("Francois-Xavier Duranceau"),
67  KLocalizedString(),
68  "duranceau@kde.org");
69  aboutData.addAuthor(ki18n("Emily Ezust (Corel Corporation)"),
70  KLocalizedString(),
71  "emilye@corel.com");
72  aboutData.addAuthor(ki18n("Michael Jarrett (Corel Corporation)"),
73  KLocalizedString(),
74  "michaelj@corel.com");
75  aboutData.addAuthor(ki18n("Robert Palmbos"),
76  KLocalizedString(),
77  "palm9744@kettering.edu");
78 
79  aboutData.addCredit(ki18n("Bryce Corkins"),
80  ki18n("Icons"),
81  "dbryce@attglobal.net");
82  aboutData.addCredit(ki18n("Liam Smit"),
83  ki18n("Ideas, help with the icons"),
84  "smitty@absamail.co.za");
85  aboutData.addCredit(ki18n("Andrew Smith"),
86  ki18n("bkisofs code"),
87  QByteArray(),
88  "http://littlesvr.ca/misc/contactandrew.php");
89  aboutData.setProgramIconName(QLatin1String("ark"));
90 
91  KCmdLineArgs::init(argc, argv, &aboutData);
92  KCmdLineOptions option;
93  option.add("+[url]", ki18n("URL of an archive to be opened"));
94  option.add("d").add("dialog", ki18n("Show a dialog for specifying the options for the operation (extract/add)"));
95  option.add("o").add("destination <directory>", ki18n("Destination folder to extract to. Defaults to current path if not specified."));
96  option.add(":", ki18n("Options for adding files"));
97  option.add("c").add("add", ki18n("Query the user for an archive filename and add specified files to it. Quit when finished."));
98  option.add("t").add("add-to <filename>", ki18n("Add the specified files to 'filename'. Create archive if it does not exist. Quit when finished."));
99  option.add("p").add("changetofirstpath", ki18n("Change the current dir to the first entry and add all other entries relative to this one."));
100  option.add("f").add("autofilename <suffix>", ki18n("Automatically choose a filename, with the selected suffix (for example rar, tar.gz, zip or any other supported types)"));
101  option.add(":", ki18n("Options for batch extraction:"));
102  option.add("b").add("batch", ki18n("Use the batch interface instead of the usual dialog. This option is implied if more than one url is specified."));
103  option.add("e").add("autodestination", ki18n("The destination argument will be set to the path of the first file supplied."));
104  option.add("a").add("autosubfolder", ki18n("Archive contents will be read, and if detected to not be a single folder archive, a subfolder with the name of the archive will be created."));
105  KCmdLineArgs::addCmdLineOptions(option);
106  KCmdLineArgs::addTempFileOption();
107 
108  KApplication application;
109  application.setQuitOnLastWindowClosed(false);
110 
111  //session restoring
112  if (application.isSessionRestored()) {
113  MainWindow* window = NULL;
114 
115  if (KMainWindow::canBeRestored(1)) {
116  window = new MainWindow;
117  window->restore(1);
118  if (!window->loadPart()) {
119  delete window;
120  window = NULL;
121  }
122  }
123 
124  if (window == NULL) {
125  return -1;
126  }
127  } else { //new ark window (no restored session)
128  // open any given URLs
129  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
130 
131  if (args->isSet("add") || args->isSet("add-to")) {
132  AddToArchive *addToArchiveJob = new AddToArchive;
133  application.connect(addToArchiveJob, SIGNAL(result(KJob*)), SLOT(quit()), Qt::QueuedConnection);
134 
135  if (args->isSet("changetofirstpath")) {
136  addToArchiveJob->setChangeToFirstPath(true);
137  }
138 
139  if (args->isSet("add-to")) {
140  addToArchiveJob->setFilename(args->getOption("add-to"));
141  }
142 
143  if (args->isSet("autofilename")) {
144  addToArchiveJob->setAutoFilenameSuffix(args->getOption("autofilename"));
145  }
146 
147  for (int i = 0; i < args->count(); ++i) {
148  //TODO: use the returned value here?
149  addToArchiveJob->addInput(args->url(i));
150  }
151 
152  if (args->isSet("dialog")) {
153  if (!addToArchiveJob->showAddDialog()) {
154  return 0;
155  }
156  }
157 
158  addToArchiveJob->start();
159  } else if (args->isSet("batch")) {
160  BatchExtract *batchJob = new BatchExtract;
161  application.connect(batchJob, SIGNAL(result(KJob*)), SLOT(quit()), Qt::QueuedConnection);
162 
163  for (int i = 0; i < args->count(); ++i) {
164  batchJob->addInput(args->url(i));
165  }
166 
167  if (args->isSet("autosubfolder")) {
168  kDebug() << "Setting autosubfolder";
169  batchJob->setAutoSubfolder(true);
170  }
171 
172  if (args->isSet("autodestination")) {
173  QString autopath = QFileInfo(args->url(0).path()).path();
174  kDebug() << "By autodestination, setting path to " << autopath;
175  batchJob->setDestinationFolder(autopath);
176  }
177 
178  if (args->isSet("destination")) {
179  kDebug() << "Setting destination to " << args->getOption("destination");
180  batchJob->setDestinationFolder(args->getOption("destination"));
181  }
182 
183  if (args->isSet("dialog")) {
184  if (!batchJob->showExtractDialog()) {
185  return 0;
186  }
187  }
188 
189  batchJob->start();
190  } else {
191  MainWindow *window = new MainWindow;
192  if (!window->loadPart()) { // if loading the part fails
193  return -1;
194  }
195 
196  if (args->count()) {
197  kDebug() << "trying to open" << args->url(0);
198 
199  if (args->isSet("dialog")) {
200  window->setShowExtractDialog(true);
201  }
202  window->openUrl(args->url(0));
203  }
204  window->show();
205  }
206  }
207 
208  kDebug() << "Entering application loop";
209  return application.exec();
210 }
Kerfuffle::AddToArchive::setAutoFilenameSuffix
void setAutoFilenameSuffix(const QString &suffix)
Definition: addtoarchive.cpp:57
addtoarchive.h
MainWindow::loadPart
bool loadPart()
Definition: mainwindow.cpp:129
QByteArray
main
int main(int argc, char **argv)
Definition: main.cpp:38
Kerfuffle::AddToArchive::setFilename
void setFilename(const KUrl &path)
Definition: addtoarchive.cpp:67
BatchExtract::addInput
bool addInput(const KUrl &url)
Adds a file to the list of files that will be extracted.
Definition: batchextract.cpp:207
Kerfuffle::AddToArchive::start
void start()
Definition: addtoarchive.cpp:116
BatchExtract::setAutoSubfolder
void setAutoSubfolder(bool value)
Set whether a folder should be created when necessary so the archive is extracted to it...
Definition: batchextract.cpp:111
mainwindow.h
QString
QFileInfo
batchextract.h
Kerfuffle::AddToArchive::showAddDialog
bool showAddDialog()
Definition: addtoarchive.cpp:77
Kerfuffle::AddToArchive
Definition: addtoarchive.h:50
Kerfuffle::AddToArchive::setChangeToFirstPath
void setChangeToFirstPath(bool value)
Definition: addtoarchive.cpp:62
QLatin1String
MainWindow::setShowExtractDialog
void setShowExtractDialog(bool)
Definition: mainwindow.cpp:229
BatchExtract::start
void start()
A wrapper that calls slotStartJob() when the event loop has started.
Definition: batchextract.cpp:116
BatchExtract::setDestinationFolder
void setDestinationFolder(const QString &folder)
Sets the directory the archives will be extracted to.
Definition: batchextract.cpp:240
Kerfuffle::AddToArchive::addInput
bool addInput(const KUrl &url)
Definition: addtoarchive.cpp:100
MainWindow::openUrl
void openUrl(const KUrl &url)
Definition: mainwindow.cpp:216
BatchExtract::showExtractDialog
bool showExtractDialog()
Shows the extract options dialog before extracting the files.
Definition: batchextract.cpp:257
BatchExtract
This class schedules the extraction of all given compressed archives.
Definition: batchextract.h:54
KJob
MainWindow
Definition: mainwindow.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:37 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
  • ktimer
  • kwallet
  • 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