• 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
  • part
infopanel.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  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  */
21 #include "infopanel.h"
22 #include "kerfuffle/archive.h"
23 
24 #include <QLabel>
25 #include <QVBoxLayout>
26 #include <QFileInfo>
27 
28 #include <KLocale>
29 #include <KMimeType>
30 #include <KIconLoader>
31 #include <KIO/NetAccess>
32 
33 using namespace Kerfuffle;
34 
35 static QPixmap getMimeIcon(const QString& mimeName)
36 {
37  return KIconLoader::global()->loadMimeTypeIcon(mimeName, KIconLoader::Desktop, KIconLoader::SizeHuge);
38 }
39 
40 InfoPanel::InfoPanel(ArchiveModel *model, QWidget *parent)
41  : QFrame(parent), m_model(model)
42 {
43  setupUi(this);
44 
45  // Make the file name font bigger than the rest
46  QFont fnt = fileName->font();
47  if (fnt.pointSize() > -1) {
48  fnt.setPointSize(fnt.pointSize() + 1);
49  } else {
50  fnt.setPixelSize(fnt.pixelSize() + 3);
51  }
52  fileName->setFont(fnt);
53 
54  updateWithDefaults();
55 }
56 
57 InfoPanel::~InfoPanel()
58 {
59 }
60 
61 void InfoPanel::updateWithDefaults()
62 {
63  iconLabel->setPixmap(KIconLoader::global()->loadIcon(QLatin1String( "utilities-file-archiver" ), KIconLoader::Desktop, KIconLoader::SizeHuge));
64 
65  const QString currentFileName = prettyFileName();
66 
67  if (currentFileName.isEmpty()) {
68  fileName->setText(i18n("No archive loaded"));
69  } else {
70  fileName->setText(currentFileName);
71  }
72 
73  additionalInfo->setText(QString());
74  hideMetaData();
75  hideActions();
76 }
77 
78 QString InfoPanel::prettyFileName() const
79 {
80  if (m_prettyFileName.isEmpty()) {
81  if (m_model->archive()) {
82  QFileInfo fileInfo(m_model->archive()->fileName());
83  return fileInfo.fileName();
84  }
85  }
86 
87  return m_prettyFileName;
88 }
89 
90 void InfoPanel::setPrettyFileName(const QString& fileName)
91 {
92  m_prettyFileName = fileName;
93 }
94 
95 void InfoPanel::setIndex(const QModelIndex& index)
96 {
97  if (!index.isValid()) {
98  updateWithDefaults();
99  } else {
100  const ArchiveEntry& entry = m_model->entryForIndex(index);
101 
102  KMimeType::Ptr mimeType;
103 
104  if (entry[ IsDirectory ].toBool()) {
105  mimeType = KMimeType::mimeType(QLatin1String( "inode/directory" ));
106  } else {
107  mimeType = KMimeType::findByPath(entry[ FileName ].toString(), 0, true);
108  }
109 
110  iconLabel->setPixmap(getMimeIcon(mimeType->iconName()));
111  if (entry[ IsDirectory ].toBool()) {
112  int dirs;
113  int files;
114  const int children = m_model->childCount(index, dirs, files);
115  additionalInfo->setText(KIO::itemsSummaryString(children, files, dirs, 0, false));
116  } else if (entry.contains(Link)) {
117  additionalInfo->setText(i18n("Symbolic Link"));
118  } else {
119  if (entry.contains(Size)) {
120  additionalInfo->setText(KIO::convertSize(entry[ Size ].toULongLong()));
121  } else {
122  additionalInfo->setText(i18n("Unknown size"));
123 
124  }
125  }
126 
127  const QStringList nameParts = entry[ FileName ].toString().split(QLatin1Char( '/' ), QString::SkipEmptyParts);
128  const QString name = (nameParts.count() > 0) ? nameParts.last() : entry[ FileName ].toString();
129  fileName->setText(name);
130 
131  metadataLabel->setText(metadataTextFor(index));
132  showMetaData();
133  }
134 }
135 
136 void InfoPanel::setIndexes(const QModelIndexList &list)
137 {
138  if (list.size() == 0) {
139  setIndex(QModelIndex());
140  } else if (list.size() == 1) {
141  setIndex(list[ 0 ]);
142  } else {
143  iconLabel->setPixmap(KIconLoader::global()->loadIcon(QLatin1String( "utilities-file-archiver" ), KIconLoader::Desktop, KIconLoader::SizeHuge));
144  fileName->setText(i18np("One file selected", "%1 files selected", list.size()));
145  quint64 totalSize = 0;
146  foreach(const QModelIndex& index, list) {
147  const ArchiveEntry& entry = m_model->entryForIndex(index);
148  totalSize += entry[ Size ].toULongLong();
149  }
150  additionalInfo->setText(KIO::convertSize(totalSize));
151  hideMetaData();
152  }
153 }
154 
155 void InfoPanel::showMetaData()
156 {
157  firstSeparator->show();
158  metadataLabel->show();
159 }
160 
161 void InfoPanel::hideMetaData()
162 {
163  firstSeparator->hide();
164  metadataLabel->hide();
165 }
166 
167 void InfoPanel::showActions()
168 {
169  secondSeparator->show();
170  actionsLabel->show();
171 }
172 
173 void InfoPanel::hideActions()
174 {
175  secondSeparator->hide();
176  actionsLabel->hide();
177 }
178 
179 QString InfoPanel::metadataTextFor(const QModelIndex &index)
180 {
181  const ArchiveEntry& entry = m_model->entryForIndex(index);
182  QString text;
183 
184  KMimeType::Ptr mimeType;
185 
186  if (entry[ IsDirectory ].toBool()) {
187  mimeType = KMimeType::mimeType(QLatin1String( "inode/directory" ));
188  } else {
189  mimeType = KMimeType::findByPath(entry[ FileName ].toString(), 0, true);
190  }
191 
192  text += i18n("<b>Type:</b> %1<br/>", mimeType->comment());
193 
194  if (entry.contains(Owner)) {
195  text += i18n("<b>Owner:</b> %1<br/>", entry[ Owner ].toString());
196  }
197 
198  if (entry.contains(Group)) {
199  text += i18n("<b>Group:</b> %1<br/>", entry[ Group ].toString());
200  }
201 
202  if (entry.contains(Link)) {
203  text += i18n("<b>Target:</b> %1<br/>", entry[ Link ].toString());
204  }
205 
206  if (entry.contains(IsPasswordProtected) && entry[ IsPasswordProtected ].toBool()) {
207  text += i18n("<b>Password protected:</b> Yes<br/>");
208  }
209 
210  return text;
211 }
212 
213 #include "infopanel.moc"
Kerfuffle::Owner
The user the entry belongs to.
Definition: archive.h:62
QModelIndex
QWidget
QFont::setPointSize
void setPointSize(int pointSize)
QWidget::setupUi
void setupUi(QWidget *widget)
Kerfuffle::IsPasswordProtected
The entry is password-protected.
Definition: archive.h:74
QFont::pixelSize
int pixelSize() const
Kerfuffle::IsDirectory
The entry is a directory.
Definition: archive.h:72
QFont
InfoPanel::setPrettyFileName
void setPrettyFileName(const QString &fileName)
Sets a different file name for the current open archive.
Definition: infopanel.cpp:90
QObject::children
const QObjectList & children() const
InfoPanel::setIndex
void setIndex(const QModelIndex &)
Definition: infopanel.cpp:95
archive.h
Kerfuffle::Link
The entry is a symbolic link.
Definition: archive.h:66
ArchiveModel
Definition: archivemodel.h:41
QFont::setPixelSize
void setPixelSize(int pixelSize)
QObject::name
const char * name() const
QModelIndex::isValid
bool isValid() const
QList::count
int count(const T &value) const
Kerfuffle::ArchiveEntry
QHash< int, QVariant > ArchiveEntry
Definition: archive.h:78
InfoPanel::updateWithDefaults
void updateWithDefaults()
Definition: infopanel.cpp:61
getMimeIcon
static QPixmap getMimeIcon(const QString &mimeName)
Definition: infopanel.cpp:35
InfoPanel::InfoPanel
InfoPanel(ArchiveModel *model, QWidget *parent=0)
Definition: infopanel.cpp:40
QFileInfo::fileName
QString fileName() const
QString::isEmpty
bool isEmpty() const
QString
ArchiveModel::childCount
int childCount(const QModelIndex &index, int &dirs, int &files) const
Definition: archivemodel.cpp:463
ArchiveModel::archive
Kerfuffle::Archive * archive() const
Definition: archivemodel.cpp:858
QStringList
Kerfuffle::Archive::fileName
QString fileName() const
Definition: archive.cpp:194
Kerfuffle::FileName
The entry's file name.
Definition: archive.h:59
QPixmap
QFileInfo
QLatin1Char
QFrame
QTest::toString
char * toString(const T &value)
QLatin1String
Kerfuffle::Size
The entry's original size.
Definition: archive.h:64
QList::last
T & last()
QStringList::split
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
InfoPanel::setIndexes
void setIndexes(const QModelIndexList &list)
Definition: infopanel.cpp:136
Kerfuffle::Group
The user group the entry belongs to.
Definition: archive.h:63
InfoPanel::~InfoPanel
virtual ~InfoPanel()
Definition: infopanel.cpp:57
infopanel.h
QFont::pointSize
int pointSize() const
InfoPanel::prettyFileName
QString prettyFileName() const
Returns the file name that is displayed on the info panel.
Definition: infopanel.cpp:78
ArchiveModel::entryForIndex
Kerfuffle::ArchiveEntry entryForIndex(const QModelIndex &index)
Definition: archivemodel.cpp:453
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