diff --git a/part/infopanel.cpp b/part/infopanel.cpp index c452c75d..d93a0b36 100644 --- a/part/infopanel.cpp +++ b/part/infopanel.cpp @@ -1,201 +1,211 @@ /* * ark -- archiver for the KDE project * * Copyright (C) 2007 Henrique Pinto * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include "infopanel.h" #include "ark_debug.h" #include "kerfuffle/archive_kerfuffle.h" #include #include #include #include #include #include #include using namespace Kerfuffle; static QPixmap getDesktopIconForName(const QString& name) { return QIcon::fromTheme(name).pixmap(IconSize(KIconLoader::Desktop), IconSize(KIconLoader::Desktop)); } InfoPanel::InfoPanel(ArchiveModel *model, QWidget *parent) : QFrame(parent), m_model(model) { setupUi(this); // Make the file name font bigger than the rest QFont fnt = fileName->font(); if (fnt.pointSize() > -1) { fnt.setPointSize(fnt.pointSize() + 1); } else { fnt.setPixelSize(fnt.pixelSize() + 3); } fileName->setFont(fnt); updateWithDefaults(); } InfoPanel::~InfoPanel() { } void InfoPanel::updateWithDefaults() { iconLabel->setPixmap(getDesktopIconForName(QStringLiteral("utilities-file-archiver"))); const QString currentFileName = prettyFileName(); if (currentFileName.isEmpty()) { fileName->setText(i18n("No archive loaded")); } else { fileName->setText(currentFileName); } additionalInfo->setText(QString()); hideMetaData(); } QString InfoPanel::prettyFileName() const { if (m_prettyFileName.isEmpty()) { if (m_model->archive()) { QFileInfo fileInfo(m_model->archive()->fileName()); return fileInfo.fileName(); } } return m_prettyFileName; } void InfoPanel::setPrettyFileName(const QString& fileName) { m_prettyFileName = fileName; } void InfoPanel::setIndex(const QModelIndex& index) { if (!index.isValid()) { updateWithDefaults(); } else { const ArchiveEntry& entry = m_model->entryForIndex(index); QMimeDatabase db; QMimeType mimeType; if (entry[ IsDirectory ].toBool()) { mimeType = db.mimeTypeForName(QStringLiteral("inode/directory")); } else { mimeType = db.mimeTypeForFile(entry[ FileName ].toString(), QMimeDatabase::MatchExtension); } iconLabel->setPixmap(getDesktopIconForName(mimeType.iconName())); if (entry[ IsDirectory ].toBool()) { int dirs; int files; const int children = m_model->childCount(index, dirs, files); additionalInfo->setText(KIO::itemsSummaryString(children, files, dirs, 0, false)); } else if (entry.contains(Link)) { additionalInfo->setText(i18n("Symbolic Link")); } else { if (entry.contains(Size)) { additionalInfo->setText(KIO::convertSize(entry[ Size ].toULongLong())); } else { additionalInfo->setText(i18n("Unknown size")); } } const QStringList nameParts = entry[ FileName ].toString().split(QLatin1Char( '/' ), QString::SkipEmptyParts); const QString name = (nameParts.count() > 0) ? nameParts.last() : entry[ FileName ].toString(); fileName->setText(name); - metadataLabel->setText(metadataTextFor(index)); - showMetaData(); + showMetaDataFor(index); } } void InfoPanel::setIndexes(const QModelIndexList &list) { if (list.size() == 0) { setIndex(QModelIndex()); } else if (list.size() == 1) { setIndex(list[ 0 ]); } else { iconLabel->setPixmap(getDesktopIconForName(QStringLiteral("utilities-file-archiver"))); fileName->setText(i18np("One file selected", "%1 files selected", list.size())); quint64 totalSize = 0; foreach(const QModelIndex& index, list) { const ArchiveEntry& entry = m_model->entryForIndex(index); totalSize += entry[ Size ].toULongLong(); } additionalInfo->setText(KIO::convertSize(totalSize)); hideMetaData(); } } void InfoPanel::showMetaData() { m_separator->show(); - metadataLabel->show(); + m_metaDataWidget->show(); } void InfoPanel::hideMetaData() { m_separator->hide(); - metadataLabel->hide(); + m_metaDataWidget->hide(); } -QString InfoPanel::metadataTextFor(const QModelIndex &index) +void InfoPanel::showMetaDataFor(const QModelIndex &index) { + showMetaData(); + const ArchiveEntry& entry = m_model->entryForIndex(index); - QString text; QMimeDatabase db; QMimeType mimeType; if (entry[ IsDirectory ].toBool()) { mimeType = db.mimeTypeForName(QStringLiteral("inode/directory")); } else { mimeType = db.mimeTypeForFile(entry[FileName].toString(), QMimeDatabase::MatchExtension); } - text += i18n("Type: %1
", mimeType.comment()); + m_typeLabel->setText(i18n("Type: %1", mimeType.comment())); if (entry.contains(Owner)) { - text += i18n("Owner: %1
", entry[ Owner ].toString()); + m_ownerLabel->show(); + m_ownerLabel->setText(i18n("Owner: %1", entry[Owner].toString())); + } else { + m_ownerLabel->hide(); } if (entry.contains(Group)) { - text += i18n("Group: %1
", entry[ Group ].toString()); + m_groupLabel->show(); + m_groupLabel->setText(i18n("Group: %1", entry[Group].toString())); + } else { + m_groupLabel->hide(); } if (entry.contains(Link)) { - text += i18n("Target: %1
", entry[ Link ].toString()); + m_targetLabel->show(); + m_targetLabel->setText(i18n("Target: %1", entry[Link].toString())); + } else { + m_targetLabel->hide(); } if (entry.contains(IsPasswordProtected) && entry[ IsPasswordProtected ].toBool()) { - text += i18n("Password protected: Yes
"); + m_passwordLabel->show(); + m_passwordLabel->setText(i18n("Password protected: Yes")); + } else { + m_passwordLabel->hide(); } - - return text; } diff --git a/part/infopanel.h b/part/infopanel.h index bc2cdf7c..b0be79a8 100644 --- a/part/infopanel.h +++ b/part/infopanel.h @@ -1,73 +1,73 @@ /* * ark -- archiver for the KDE project * * Copyright (C) 2007 Henrique Pinto * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #ifndef INFOPANEL_H #define INFOPANEL_H #include "kerfuffle/archive_kerfuffle.h" #include "archivemodel.h" #include "ui_infopanel.h" #include class InfoPanel: public QFrame, Ui::InformationPanel { Q_OBJECT public: explicit InfoPanel(ArchiveModel *model, QWidget *parent = 0); virtual ~InfoPanel(); void setIndex(const QModelIndex &); void setIndexes(const QModelIndexList &list); /** * Returns the file name that is displayed on the info panel. * * @return The current file name. If no pretty name has been * set, it returns the name of the loaded archive. */ QString prettyFileName() const; /** * Sets a different file name for the current open archive. * * This is particularly useful when a temporary archive (from * a remote location) is loaded, and the window title shows the * remote file name and the info panel, by default, would show * the name of the temporary downloaded file. * * @param fileName The new file name. */ void setPrettyFileName(const QString& fileName); void updateWithDefaults(); private: void showMetaData(); void hideMetaData(); - QString metadataTextFor(const QModelIndex &); + void showMetaDataFor(const QModelIndex &index); ArchiveModel *m_model; QString m_prettyFileName; }; #endif // INFOPANEL_H diff --git a/part/infopanel.ui b/part/infopanel.ui index 1c8c477a..c9ac5eac 100644 --- a/part/infopanel.ui +++ b/part/infopanel.ui @@ -1,121 +1,146 @@ InformationPanel 0 0 140 300 0 0 Information Panel Qt::AlignCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse 75 true KSqueezedTextLabel Qt::AlignCenter true Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse Qt::ElideRight Unknown file type Qt::AlignCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse Qt::Horizontal - - - Metadata Label - - - 10 - - - 20 - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - + + + + + + Type + + + + + + + Owner + + + + + + + Group + + + + + + + Target + + + + + + + Password + + + + Qt::Vertical 20 40 KSqueezedTextLabel QLabel
ksqueezedtextlabel.h