• 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
  • kerfuffle
adddialog.cpp
Go to the documentation of this file.
1 /*
2  * ark -- archiver for the KDE project
3  *
4  * Copyright (C) 2008 Harald Hvaal <haraldhv@stud.ntnu.no>
5  * Copyright (C) 2009,2011 Raphael Kubo da Costa <rakuco@FreeBSD.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "adddialog.h"
30 #include "ui_adddialog.h"
31 #include "kerfuffle/archive.h"
32 
33 #include <KConfigGroup>
34 #include <KFilePlacesModel>
35 #include <KGlobal>
36 
37 #include <QFileInfo>
38 #include <QStandardItemModel>
39 
40 namespace Kerfuffle
41 {
42 class AddDialogUI: public QWidget, public Ui::AddDialog
43 {
44 public:
45  AddDialogUI(QWidget *parent = 0)
46  : QWidget(parent) {
47  setupUi(this);
48  }
49 };
50 
51 AddDialog::AddDialog(const QStringList& itemsToAdd,
52  const KUrl & startDir,
53  const QString & filter,
54  QWidget * parent,
55  QWidget * widget
56  )
57  : KFileDialog(startDir, filter, parent, widget)
58 {
59  setOperationMode(KFileDialog::Saving);
60  setMode(KFile::File | KFile::LocalOnly);
61  setConfirmOverwrite(true);
62  setCaption(i18n("Compress to Archive"));
63 
64  loadConfiguration();
65 
66  connect(this, SIGNAL(okClicked()), SLOT(updateDefaultMimeType()));
67 
68  m_ui = new AddDialogUI(this);
69  mainWidget()->layout()->addWidget(m_ui);
70 
71  setupIconList(itemsToAdd);
72 
73  // Set up a default name if there's only one file to compress
74  if (itemsToAdd.size() == 1) {
75  const QFileInfo fileInfo(itemsToAdd.first());
76  const QString fileName =
77  fileInfo.isDir() ? fileInfo.dir().dirName() : fileInfo.baseName();
78 
79  // #272914: Add an extension when it is present, otherwise KFileDialog
80  // will not automatically add it as baseFileName is a file which
81  // already exists.
82  setSelection(fileName + currentFilterMimeType()->mainExtension());
83  }
84 
85  //These extra options will be implemented in a 4.2+ version of
86  //ark
87  m_ui->groupExtraOptions->hide();
88 }
89 
90 void AddDialog::loadConfiguration()
91 {
92  m_config = KConfigGroup(KGlobal::config()->group("AddDialog"));
93 
94  const QString defaultMimeType = QLatin1String( "application/x-compressed-tar" );
95  const QStringList writeMimeTypes = Kerfuffle::supportedWriteMimeTypes();
96  const QString lastMimeType = m_config.readEntry("LastMimeType", defaultMimeType);
97 
98  if (writeMimeTypes.contains(lastMimeType)) {
99  setMimeFilter(writeMimeTypes, lastMimeType);
100  } else {
101  setMimeFilter(writeMimeTypes, defaultMimeType);
102  }
103 }
104 
105 void AddDialog::setupIconList(const QStringList& itemsToAdd)
106 {
107  QStandardItemModel* listModel = new QStandardItemModel(this);
108  QStringList sortedList(itemsToAdd);
109 
110  sortedList.sort();
111 
112  Q_FOREACH(const QString& urlString, sortedList) {
113  KUrl url(urlString);
114 
115  QStandardItem* item = new QStandardItem;
116  item->setText(url.fileName());
117 
118  QString iconName = KMimeType::iconNameForUrl(url);
119  item->setIcon(KIcon(iconName));
120 
121  item->setData(QVariant(url), KFilePlacesModel::UrlRole);
122 
123  listModel->appendRow(item);
124  }
125 
126  m_ui->compressList->setModel(listModel);
127 }
128 
129 void AddDialog::updateDefaultMimeType()
130 {
131  m_config.writeEntry("LastMimeType", currentMimeFilter());
132 }
133 }
134 
135 #include "adddialog.moc"
QStandardItemModel
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
QStandardItem::setIcon
void setIcon(const QIcon &icon)
adddialog.h
Kerfuffle::supportedWriteMimeTypes
QStringList supportedWriteMimeTypes()
Definition: archive.cpp:306
Kerfuffle::AddDialog::AddDialog
AddDialog(const QStringList &itemsToAdd, const KUrl &startDir, const QString &filter, QWidget *parent, QWidget *widget=0)
Definition: adddialog.cpp:51
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
archive.h
QList::size
int size() const
QStandardItem::setData
virtual void setData(const QVariant &value, int role)
KFileDialog
QList::first
T & first()
QString
QStringList
QFileInfo
QStandardItem::setText
void setText(const QString &text)
QLatin1String
QStandardItem
QObject::parent
QObject * parent() const
QStandardItemModel::appendRow
void appendRow(const QList< QStandardItem * > &items)
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:36 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