diff options
Diffstat (limited to 'src/panels')
| -rw-r--r-- | src/panels/information/filemetadataconfigurationdialog.cpp | 102 | ||||
| -rw-r--r-- | src/panels/information/filemetadataconfigurationdialog.h | 76 | ||||
| -rw-r--r-- | src/panels/information/informationpanel.cpp | 24 | ||||
| -rw-r--r-- | src/panels/information/informationpanel.h | 1 | ||||
| -rw-r--r-- | src/panels/information/informationpanelcontent.cpp | 68 | ||||
| -rw-r--r-- | src/panels/information/informationpanelcontent.h | 17 |
6 files changed, 66 insertions, 222 deletions
diff --git a/src/panels/information/filemetadataconfigurationdialog.cpp b/src/panels/information/filemetadataconfigurationdialog.cpp deleted file mode 100644 index f3ca819b7..000000000 --- a/src/panels/information/filemetadataconfigurationdialog.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Peter Penz <[email protected]> * - * * - * 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 "filemetadataconfigurationdialog.h" - -#include <Baloo/FileMetaDataConfigWidget> -#include <KConfigGroup> -#include <KLocalizedString> -#include <KSharedConfig> -#include <KWindowConfig> - -#include <QDialogButtonBox> -#include <QLabel> -#include <QPushButton> -#include <QVBoxLayout> - -FileMetaDataConfigurationDialog::FileMetaDataConfigurationDialog(QWidget* parent) : - QDialog(parent), - m_descriptionLabel(nullptr), - m_configWidget(nullptr) - -{ - setWindowTitle(i18nc("@title:window", "Configure Shown Data")); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); - QVBoxLayout *mainLayout = new QVBoxLayout; - setLayout(mainLayout); - QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); - okButton->setDefault(true); - okButton->setShortcut(Qt::CTRL + Qt::Key_Return); - connect(buttonBox, &QDialogButtonBox::accepted, this, &FileMetaDataConfigurationDialog::slotAccepted); - connect(buttonBox, &QDialogButtonBox::rejected, this, &FileMetaDataConfigurationDialog::reject); - buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); - - m_descriptionLabel = new QLabel(i18nc("@label::textbox", - "Select which data should " - "be shown:"), this); - m_descriptionLabel->setWordWrap(true); - - m_configWidget = new Baloo::FileMetaDataConfigWidget(this); - - QWidget* mainWidget = new QWidget(this); - QVBoxLayout* topLayout = new QVBoxLayout(mainWidget); - topLayout->addWidget(m_descriptionLabel); - topLayout->addWidget(m_configWidget); - mainLayout->addWidget(mainWidget); - mainLayout->addWidget(buttonBox); - - - const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), - "FileMetaDataConfigurationDialog"); - KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig); -} - -FileMetaDataConfigurationDialog::~FileMetaDataConfigurationDialog() -{ - KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), - "FileMetaDataConfigurationDialog"); - KWindowConfig::saveWindowSize(windowHandle(), dialogConfig); -} - -void FileMetaDataConfigurationDialog::setItems(const KFileItemList& items) -{ - m_configWidget->setItems(items); -} - -KFileItemList FileMetaDataConfigurationDialog::items() const -{ - return m_configWidget->items(); -} - -void FileMetaDataConfigurationDialog::slotAccepted() -{ - m_configWidget->save(); - accept(); -} - -void FileMetaDataConfigurationDialog::setDescription(const QString& description) -{ - m_descriptionLabel->setText(description); -} - -QString FileMetaDataConfigurationDialog::description() const -{ - return m_descriptionLabel->text(); -} - diff --git a/src/panels/information/filemetadataconfigurationdialog.h b/src/panels/information/filemetadataconfigurationdialog.h deleted file mode 100644 index 04357783c..000000000 --- a/src/panels/information/filemetadataconfigurationdialog.h +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Peter Penz <[email protected]> * - * * - * 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 FILEMETADATACONFIGURATIONDIALOG_H -#define FILEMETADATACONFIGURATIONDIALOG_H - -#include <QDialog> - -#include <KFileItem> -#include <config-baloo.h> -#ifndef HAVE_BALOO -class KFileMetaDataConfigurationWidget; -#else -namespace Baloo { - class FileMetaDataConfigWidget; -} -#endif - -class QLabel; - -/** - * @brief Dialog which allows to configure which meta data should be shown - * in the KFileMetaDataWidget. - */ -class FileMetaDataConfigurationDialog : public QDialog -{ - Q_OBJECT - -public: - explicit FileMetaDataConfigurationDialog(QWidget* parent = nullptr); - ~FileMetaDataConfigurationDialog() override; - - /** - * Sets the items, for which the visibility of the meta data should - * be configured. Note that the visibility of the meta data is not - * bound to the items itself, the items are only used to determine - * which meta data should be configurable. For example when a JPEG image - * is set as item, it will be configurable which EXIF data should be - * shown. If an audio file is set as item, it will be configurable - * whether the artist, album name, ... should be shown. - */ - void setItems(const KFileItemList& items); - KFileItemList items() const; - - /** - * Sets the description that is shown above the list - * of meta data. Per default the translated text for - * "Select which data should be shown." is set. - */ - void setDescription(const QString& description); - QString description() const; - -protected slots: - void slotAccepted(); -private: - QLabel* m_descriptionLabel; - Baloo::FileMetaDataConfigWidget* m_configWidget; -}; - -#endif diff --git a/src/panels/information/informationpanel.cpp b/src/panels/information/informationpanel.cpp index cd8b6b38d..9a0358df0 100644 --- a/src/panels/information/informationpanel.cpp +++ b/src/panels/information/informationpanel.cpp @@ -36,7 +36,6 @@ #include <QMenu> #include "dolphin_informationpanelsettings.h" -#include "filemetadataconfigurationdialog.h" InformationPanel::InformationPanel(QWidget* parent) : Panel(parent), @@ -168,7 +167,8 @@ void InformationPanel::contextMenuEvent(QContextMenuEvent* event) Panel::contextMenuEvent(event); } -void InformationPanel::showContextMenu(const QPoint &pos) { +void InformationPanel::showContextMenu(const QPoint &pos) +{ QMenu popup(this); QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview")); @@ -178,6 +178,9 @@ void InformationPanel::showContextMenu(const QPoint &pos) { QAction* configureAction = popup.addAction(i18nc("@action:inmenu", "Configure...")); configureAction->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); + if (m_inConfigurationMode) { + configureAction->setEnabled(false); + } QAction* dateformatAction = popup.addAction(i18nc("@action:inmenu", "Condensed Date")); dateformatAction->setIcon(QIcon::fromTheme(QStringLiteral("change-date-symbolic"))); @@ -185,7 +188,8 @@ void InformationPanel::showContextMenu(const QPoint &pos) { dateformatAction->setChecked(InformationPanelSettings::dateFormat() == static_cast<int>(Baloo::DateFormats::ShortFormat)); popup.addSeparator(); - foreach (QAction* action, customContextMenuActions()) { + const auto actions = customContextMenuActions(); + for (QAction *action : actions) { popup.addAction(action); } @@ -201,13 +205,8 @@ void InformationPanel::showContextMenu(const QPoint &pos) { InformationPanelSettings::setPreviewsShown(isChecked); m_content->refreshPreview(); } else if (action == configureAction) { - FileMetaDataConfigurationDialog* dialog = new FileMetaDataConfigurationDialog(this); - dialog->setDescription(i18nc("@label::textbox", - "Select which data should be shown in the information panel:")); - dialog->setItems(m_content->items()); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); - connect(dialog, &FileMetaDataConfigurationDialog::destroyed, m_content, &InformationPanelContent::refreshMetaData); + m_inConfigurationMode = true; + m_content->configureShownProperties(); } if (action == dateformatAction) { int dateFormat = static_cast<int>(isChecked ? Baloo::DateFormats::ShortFormat : Baloo::DateFormats::LongFormat); @@ -311,7 +310,7 @@ void InformationPanel::slotFilesAdded(const QString& directory) void InformationPanel::slotFilesChanged(const QStringList& files) { - foreach (const QString& fileName, files) { + for (const QString& fileName : files) { if (m_shownUrl == QUrl::fromLocalFile(fileName)) { showItemInfo(); break; @@ -321,7 +320,7 @@ void InformationPanel::slotFilesChanged(const QStringList& files) void InformationPanel::slotFilesRemoved(const QStringList& files) { - foreach (const QString& fileName, files) { + for (const QString& fileName : files) { if (m_shownUrl == QUrl::fromLocalFile(fileName)) { // the currently shown item has been removed, show // the parent directory as fallback @@ -410,6 +409,7 @@ void InformationPanel::init() m_content = new InformationPanelContent(this); connect(m_content, &InformationPanelContent::urlActivated, this, &InformationPanel::urlActivated); + connect(m_content, &InformationPanelContent::configurationFinished, this, [this]() { m_inConfigurationMode = false; }); QVBoxLayout* layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); diff --git a/src/panels/information/informationpanel.h b/src/panels/information/informationpanel.h index f63af1e53..321827c5b 100644 --- a/src/panels/information/informationpanel.h +++ b/src/panels/information/informationpanel.h @@ -161,6 +161,7 @@ private: KIO::Job* m_folderStatJob; InformationPanelContent* m_content; + bool m_inConfigurationMode = false; }; #endif // INFORMATIONPANEL_H diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index 0eaa125f1..5b7dbbfe9 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -40,6 +40,7 @@ #include <Phonon/MediaObject> #include <QLabel> +#include <QDialogButtonBox> #include <QScrollArea> #include <QTextLayout> #include <QTimer> @@ -107,18 +108,31 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) : m_metaDataWidget->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); - // Encapsulate the MetaDataWidget inside a container that has a dummy widget - // at the bottom. This prevents that the meta data widget gets vertically stretched - // in the case where the height of m_metaDataArea > m_metaDataWidget. - QWidget* metaDataWidgetContainer = new QWidget(parent); - QVBoxLayout* containerLayout = new QVBoxLayout(metaDataWidgetContainer); - containerLayout->setContentsMargins(0, 0, 0, 0); - containerLayout->setSpacing(0); - containerLayout->addWidget(m_metaDataWidget); - containerLayout->addStretch(); + // Configuration + m_configureLabel = new QLabel(i18nc("@label::textbox", + "Select which data should be shown:"), this); + m_configureLabel->setWordWrap(true); + m_configureLabel->setVisible(false); + + m_configureButtons = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel); + m_configureButtons->setVisible(false); + connect(m_configureButtons, &QDialogButtonBox::accepted, this, [this]() { + m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::Accept); + m_configureButtons->setVisible(false); + m_configureLabel->setVisible(false); + emit configurationFinished(); + } + ); + connect(m_configureButtons, &QDialogButtonBox::rejected, this, [this]() { + m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::Cancel); + m_configureButtons->setVisible(false); + m_configureLabel->setVisible(false); + emit configurationFinished(); + } + ); m_metaDataArea = new QScrollArea(parent); - m_metaDataArea->setWidget(metaDataWidgetContainer); + m_metaDataArea->setWidget(m_metaDataWidget); m_metaDataArea->setWidgetResizable(true); m_metaDataArea->setFrameShape(QFrame::NoFrame); @@ -129,7 +143,9 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) : layout->addWidget(m_phononWidget); layout->addWidget(m_nameLabel); layout->addWidget(new KSeparator()); + layout->addWidget(m_configureLabel); layout->addWidget(m_metaDataArea); + layout->addWidget(m_configureButtons); m_placesItemModel = new PlacesItemModel(this); } @@ -147,7 +163,8 @@ void InformationPanelContent::showItem(const KFileItem& item) refreshMetaData(); } -void InformationPanelContent::refreshPreview() { +void InformationPanelContent::refreshPreview() +{ // If there is a preview job, kill it to prevent that we have jobs for // multiple items running, and thus a race condition (bug 250787). if (m_previewJob) { @@ -209,12 +226,18 @@ void InformationPanelContent::refreshPreview() { } } -void InformationPanelContent::refreshMetaData() { - if (m_metaDataWidget) { - m_metaDataWidget->setDateFormat(static_cast<Baloo::DateFormats>(InformationPanelSettings::dateFormat())); - m_metaDataWidget->show(); - m_metaDataWidget->setItems(KFileItemList() << m_item); - } +void InformationPanelContent::configureShownProperties() +{ + m_configureLabel->setVisible(true); + m_configureButtons->setVisible(true); + m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::ReStart); +} + +void InformationPanelContent::refreshMetaData() +{ + m_metaDataWidget->setDateFormat(static_cast<Baloo::DateFormats>(InformationPanelSettings::dateFormat())); + m_metaDataWidget->show(); + m_metaDataWidget->setItems(KFileItemList() << m_item); } void InformationPanelContent::showItems(const KFileItemList& items) @@ -230,9 +253,7 @@ void InformationPanelContent::showItems(const KFileItemList& items) ); setNameLabelText(i18ncp("@label", "%1 item selected", "%1 items selected", items.count())); - if (m_metaDataWidget) { - m_metaDataWidget->setItems(items); - } + m_metaDataWidget->setItems(items); m_phononWidget->hide(); @@ -297,7 +318,8 @@ void InformationPanelContent::markOutdatedPreview() m_preview->setPixmap(disabledPixmap); } -KFileItemList InformationPanelContent::items() { +KFileItemList InformationPanelContent::items() +{ return m_metaDataWidget->items(); } @@ -349,9 +371,7 @@ void InformationPanelContent::adjustWidgetSizes(int width) // The metadata widget also contains a text widget which may return // a large preferred width. - if (m_metaDataWidget) { - m_metaDataWidget->setMaximumWidth(maxWidth); - } + m_metaDataWidget->setMaximumWidth(maxWidth); // try to increase the preview as large as possible m_preview->setSizeHint(QSize(maxWidth, maxWidth)); diff --git a/src/panels/information/informationpanelcontent.h b/src/panels/information/informationpanelcontent.h index 83fb3d80b..43410ddfa 100644 --- a/src/panels/information/informationpanelcontent.h +++ b/src/panels/information/informationpanelcontent.h @@ -32,6 +32,7 @@ class PhononWidget; class PixmapViewer; class PlacesItemModel; class QPixmap; +class QDialogButtonBox; class QString; class QLabel; class QScrollArea; @@ -40,13 +41,9 @@ namespace KIO { class PreviewJob; } -#ifndef HAVE_BALOO -class KFileMetaDataWidget; -#else namespace Baloo { class FileMetaDataWidget; } -#endif /** * @brief Manages the widgets that display the meta information @@ -79,8 +76,14 @@ public: */ void refreshPreview(); + /** + * Switch the metadatawidget into configuration mode + */ + void configureShownProperties(); + signals: void urlActivated( const QUrl& url ); + void configurationFinished(); public slots: /** @@ -138,12 +141,10 @@ private: PixmapViewer* m_preview; PhononWidget* m_phononWidget; QLabel* m_nameLabel; -#ifndef HAVE_BALOO - KFileMetaDataWidget* m_metaDataWidget; -#else Baloo::FileMetaDataWidget* m_metaDataWidget; -#endif QScrollArea* m_metaDataArea; + QLabel* m_configureLabel; + QDialogButtonBox* m_configureButtons; PlacesItemModel* m_placesItemModel; }; |
