Pino, Thank you for the time you took to review the code. I think I may have sent an outdated patch as Albert addressed a few of these issues with me as well. However, every other point you bring up is valid.
> > + m_model = new QFileSystemModel( this ); > > please use a KDirModel > I just want to know why? Maybe KDirModel may be a better KDE api option but its not necessarily easy to set up. This would require me to reimplement quite a few things in the dialog( which is not a problem I just want to know that its justified). If a KDirModel is necessary then I will definitely need more time. > > > + // Hide file size and type > > + m_dlg->MetaFileList->hideColumn( 1 ); > > + m_dlg->MetaFileList->hideColumn( 2 ); > > you have a proxy model, so make that proxy do the column hiding job (not > sure it is needed that way with KDirModel) > Because the proxy model would have to implement catching these which would have taken a few more lines of code. That's not a big deal but I will wait until the KDirModel. > > > + m_dlg->MetaFileList->setColumnWidth( 0, 350); > > why this hardcoded value? > This has been bugging me for a while. I cant get the view to resize the table to contents efficiently. The resizeColumnsToContents() is a slot I havent quite figured out yet. Any suggestions? >> + i18n( "Warning " ), > + trailing space in i18n() string text, and a bit too generic Hmmm, any suggestions? > > + modifiedData = > > modifiedData.toString().remove(QRegExp(".xml$")); > > + modifiedData = > > modifiedData.toString().remove(QRegExp("^[0-9]+\.")); > > pretty inefficient; you're getting the string out of the variant, do a > removal of some text using two regexps (which are not needed), and then > converting to qvariant again; just get the string out once, do the > replacements and reassign back to the variant > I have refactored this process a bit. While I agree that a regular expression may be heavy duty it does guarantees a match and delete of a file size of varying digit lengths as well as a .xml that __has__ to be at the end. > - i'm not sure having both configuration and "handling" in the very same > ui is ideal... maybe one could rename the "personal identity" > configuration page to "personal data", and put just the metadata > checkbox there, while leaving the actual handling reachable from > somewhere else (settings -> handle (personal) meta data?) > I understand what you mean and this is why I have held off a little on fixing some of the issues that will take a longer time. Does anybody else have any thoughts on this?
From 297025dd337306fd9b0b6b89543e55a5fdf464ef Mon Sep 17 00:00:00 2001 From: Christopher Reichert <creicher...@gmail.com> Date: Sat, 4 Jun 2011 12:39:01 -0500 Subject: [PATCH] Added feature that allows the management of okular meta data. This feature is appended to the config dialog and allows users the option to save meta data. Also, allows for the user to delete meta data if they wish. --- CMakeLists.txt | 3 + conf/dlgmetadata.cpp | 130 +++++++++++++++++++++ conf/dlgmetadata.h | 51 +++++++++ conf/dlgmetadatabase.ui | 267 ++++++++++++++++++++++++++++++++++++++++++++ conf/okular.kcfg | 5 + conf/preferencesdialog.cpp | 3 + conf/preferencesdialog.h | 2 + core/document.cpp | 15 ++- 8 files changed, 474 insertions(+), 2 deletions(-) create mode 100644 conf/dlgmetadata.cpp create mode 100644 conf/dlgmetadata.h create mode 100644 conf/dlgmetadatabase.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 6465564..c1c5c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,7 @@ set(okularpart_SRCS conf/dlgidentity.cpp conf/dlgperformance.cpp conf/dlgpresentation.cpp + conf/dlgmetadata.cpp ui/embeddedfilesdialog.cpp ui/annotwindow.cpp ui/annotationmodel.cpp @@ -180,6 +181,8 @@ kde4_add_ui_files(okularpart_SRCS conf/dlgidentitybase.ui conf/dlgperformancebase.ui conf/dlgpresentationbase.ui + conf/dlgmetadatabase.ui + ) qt4_add_dbus_interfaces(okularpart_SRCS ${KDE4_DBUS_INTERFACES_DIR}/org.kde.KSpeech.xml) diff --git a/conf/dlgmetadata.cpp b/conf/dlgmetadata.cpp new file mode 100644 index 0000000..ef5e747 --- /dev/null +++ b/conf/dlgmetadata.cpp @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (C) 2011 by Christopher Reichert <creicher...@gmail.com> * + * * + * 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. * + ***************************************************************************/ + +//local +#include "dlgmetadata.h" + +//qt +#include <QWidget> +#include <QDirIterator> +#include <QVariant> +#include <QHeaderView> +#include <QSortFilterProxyModel> +#include <QFileSystemModel> + +//kde +#include <KStandardDirs> +#include <KMessageBox> +#include <KGuiItem> + +#include "ui_dlgmetadatabase.h" + + +DlgMetaData::DlgMetaData( QWidget * parent ) + : QWidget( parent ) +{ + m_dlg = new Ui_DlgMetaDataBase(); + m_dlg->setupUi( this ); + + m_model = new QFileSystemModel( this ); + m_customModel = new MetaFileProxyModel( this ); + m_docdataDir = KStandardDirs().saveLocation( "data", "okular/docdata", false ); + + // set up models + // --> m_cusomModel wraps m_model + if ( QDir(m_docdataDir).exists() ) + { + m_model->setRootPath( QDir::root().path() ); + m_customModel->setSourceModel( m_model ); + m_dlg->MetaFileList->setModel( m_customModel ); + m_dlg->MetaFileList->setRootIndex( m_customModel->mapFromSource( m_model->index( m_docdataDir ))); + + // Hide file size and type + m_dlg->MetaFileList->hideColumn( 1 ); + m_dlg->MetaFileList->hideColumn( 2 ); + + m_dlg->MetaFileList->setColumnWidth( 0, 340 ); + } + + connect( m_dlg->DelMetaButton, SIGNAL( clicked() ), + this, SLOT( deleteMetaFile() )); +} + +DlgMetaData::~DlgMetaData() +{ + delete m_dlg; +} + +void DlgMetaData::deleteMetaFile() +{ + if ( KMessageBox::questionYesNo( this, i18n( "Are you sure you want to do this?\n\n" + "Warning: deleting meta data will result\n" + "in the loss of annotations." ), + i18n( "Warning" ), + KStandardGuiItem::del(), + KStandardGuiItem::no(), 0, + KMessageBox::Dangerous ) == KMessageBox::Yes ) + { + m_model->remove( m_customModel->mapToSource( m_dlg->MetaFileList->currentIndex() )); + } +} + +void DlgMetaData::clearAllMetaData() +{ + if ( KMessageBox::questionYesNo( this, i18n( "Are you sure you want to do this?\n\n" + "Warning: deleting meta data will result\n" + "in the loss of annotations." ), + i18n( "Warning" ), + KStandardGuiItem::del(), + KStandardGuiItem::no(), 0, + KMessageBox::Dangerous ) == KMessageBox::Yes ) + { + QDirIterator it(m_docdataDir, QDir::Files | QDir::NoDotAndDotDot ); + QDir dir(m_docdataDir); + while ( it.hasNext() ) + { + QString fileName = it.next(); + if ( fileName.endsWith( ".xml" ) ) + dir.remove( fileName ); + } + } +} + +// Custom Proxy for Meta Data File List +MetaFileProxyModel::MetaFileProxyModel( QObject *parent ) + : QSortFilterProxyModel( parent ) +{ +} + +QVariant MetaFileProxyModel::data( const QModelIndex & index, int role ) const +{ + if ( !index.isValid() ) + return QVariant(); + + switch ( role ) + { + case Qt::DisplayRole: + QVariant modifiedData; + modifiedData = sourceModel()->data( mapToSource(index), role ); + QString fileName = modifiedData.toString(); + + if ( fileName.endsWith( ".xml" ) ) + { + // remove the prepensions and extensions from meta data filename to + // beautify its display to the user + fileName.remove( QRegExp(".xml$") ); + fileName.remove( QRegExp("^[0-9]+\\.") ); + return fileName; + } + } + + return sourceModel()->data( mapToSource( index ), role ); +} + +#include "dlgmetadata.moc" diff --git a/conf/dlgmetadata.h b/conf/dlgmetadata.h new file mode 100644 index 0000000..909ad56 --- /dev/null +++ b/conf/dlgmetadata.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2011 by Christopher Reichert <creicher...@gmail.com> * + * * + * 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. * + ***************************************************************************/ + +#ifndef OKULAR_CONF_DLGMETADATA_H +#define OKULAR_CONF_DLGMETADATA_H + +#include <QWidget> +#include <QSortFilterProxyModel> + +class QFileSystemModel; +class MetaFileProxyModel; +class Ui_DlgMetaDataBase; +class KDirModel; + +class DlgMetaData : public QWidget +{ + Q_OBJECT + + public: + DlgMetaData( QWidget * parent = 0 ); + virtual ~DlgMetaData(); + + protected: + void MetaDataExp(bool); + + private slots: + void deleteMetaFile(); + void clearAllMetaData(); + + private: + Ui_DlgMetaDataBase *m_dlg; + QFileSystemModel *m_model; + QString m_docdataDir; + MetaFileProxyModel *m_customModel; +}; + + +class MetaFileProxyModel : public QSortFilterProxyModel +{ + public: + MetaFileProxyModel( QObject *parent); + QVariant data(const QModelIndex &, int) const; +}; + +#endif // OKULAR_CONF_DLGMETADATA_H diff --git a/conf/dlgmetadatabase.ui b/conf/dlgmetadatabase.ui new file mode 100644 index 0000000..c2fbcf2 --- /dev/null +++ b/conf/dlgmetadatabase.ui @@ -0,0 +1,267 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>DlgMetaDataBase</class> + <widget class="QWidget" name="DlgMetaDataBase"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>576</width> + <height>445</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <weight>50</weight> + <bold>false</bold> + </font> + </property> + <property name="windowTitle"> + <string/> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <widget class="QGroupBox" name="groupBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>16777215</height> + </size> + </property> + <property name="title"> + <string>Meta Data</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QCheckBox" name="kcfg_SaveMetaData"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Save all meta data</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_3"> + <property name="font"> + <font> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Warning:</string> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="indent"> + <number>-1</number> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Deleting meta data will result in the loss of Bookmarks and Annotations.</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="2" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>All Meta Data Files:</string> + </property> + <property name="margin"> + <number>1</number> + </property> + <property name="indent"> + <number>-1</number> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>48</width> + <height>21</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="DelMetaButton"> + <property name="text"> + <string>Delete</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="ClearMetaData"> + <property name="text"> + <string>Clear all</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="3" column="0"> + <widget class="QTreeView" name="MetaFileList"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>16777215</height> + </size> + </property> + <property name="whatsThis"> + <string>dialog to hold meta data files</string> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAsNeeded</enum> + </property> + <property name="horizontalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="rootIsDecorated"> + <bool>false</bool> + </property> + <property name="uniformRowHeights"> + <bool>true</bool> + </property> + <property name="itemsExpandable"> + <bool>false</bool> + </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + <property name="allColumnsShowFocus"> + <bool>true</bool> + </property> + <property name="headerHidden"> + <bool>false</bool> + </property> + <property name="expandsOnDoubleClick"> + <bool>false</bool> + </property> + <attribute name="headerVisible"> + <bool>true</bool> + </attribute> + <attribute name="headerCascadingSectionResizes"> + <bool>false</bool> + </attribute> + <attribute name="headerDefaultSectionSize"> + <number>25</number> + </attribute> + <attribute name="headerHighlightSections"> + <bool>false</bool> + </attribute> + <attribute name="headerMinimumSectionSize"> + <number>23</number> + </attribute> + <attribute name="headerShowSortIndicator" stdset="0"> + <bool>true</bool> + </attribute> + <attribute name="headerStretchLastSection"> + <bool>true</bool> + </attribute> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Minimum</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>124</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>ClearMetaData</sender> + <signal>clicked()</signal> + <receiver>DlgMetaDataBase</receiver> + <slot>clearAllMetaData()</slot> + <hints> + <hint type="sourcelabel"> + <x>409</x> + <y>118</y> + </hint> + <hint type="destinationlabel"> + <x>330</x> + <y>0</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>clearAllMetaData()</slot> + <slot>delMetaFile()</slot> + </slots> +</ui> diff --git a/conf/okular.kcfg b/conf/okular.kcfg index 168056c..6af2920 100644 --- a/conf/okular.kcfg +++ b/conf/okular.kcfg @@ -294,4 +294,9 @@ <default>false</default> </entry> </group> + <group name="Dlg MetaData"> + <entry key="SaveMetaData" type="Bool"> + <default>true</default> + </entry> + </group> </kcfg> diff --git a/conf/preferencesdialog.cpp b/conf/preferencesdialog.cpp index 5ea6269..a9fcfbf 100644 --- a/conf/preferencesdialog.cpp +++ b/conf/preferencesdialog.cpp @@ -19,6 +19,7 @@ #include "dlgpresentation.h" #include "dlgidentity.h" #include "dlgeditor.h" +#include "dlgmetadata.h" #include "dlgdebug.h" PreferencesDialog::PreferencesDialog( QWidget * parent, KConfigSkeleton * skeleton ) @@ -30,6 +31,7 @@ PreferencesDialog::PreferencesDialog( QWidget * parent, KConfigSkeleton * skelet m_presentation = new DlgPresentation( this ); m_identity = new DlgIdentity( this ); m_editor = new DlgEditor( this ); + m_metadata = new DlgMetaData( this ); #ifdef OKULAR_DEBUG_CONFIGPAGE m_debug = new DlgDebug( this ); #endif @@ -42,6 +44,7 @@ PreferencesDialog::PreferencesDialog( QWidget * parent, KConfigSkeleton * skelet addPage( m_identity, i18n("Identity"), "preferences-desktop-personal", i18n("Identity Settings") ); addPage( m_editor, i18n("Editor"), "accessories-text-editor", i18n("Editor Options") ); + addPage( m_metadata, i18n("Meta Data"), "system-file-manager", i18n("Meta Data Options") ); #ifdef OKULAR_DEBUG_CONFIGPAGE addPage( m_debug, "Debug", "system-run", "Debug options" ); #endif diff --git a/conf/preferencesdialog.h b/conf/preferencesdialog.h index 72a7072..fbdd662 100644 --- a/conf/preferencesdialog.h +++ b/conf/preferencesdialog.h @@ -23,6 +23,7 @@ class DlgPresentation; class DlgIdentity; class DlgEditor; class DlgDebug; +class DlgMetaData; class PreferencesDialog : public KConfigDialog { @@ -44,6 +45,7 @@ class PreferencesDialog : public KConfigDialog DlgPresentation * m_presentation; DlgIdentity * m_identity; DlgEditor * m_editor; + DlgMetaData * m_metadata; DlgDebug * m_debug; }; diff --git a/core/document.cpp b/core/document.cpp index 8af1840..b01ec7c 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1027,6 +1027,11 @@ void DocumentPrivate::_o_configChanged() int pageToKick = m_allocatedTextPagesFifo.takeFirst(); m_pagesVector.at(pageToKick)->setTextPage( 0 ); // deletes the textpage } + + if ( Okular::Settings::saveMetaData() && m_saveBookmarksTimer ) + m_saveBookmarksTimer->start( 5 * 60 * 1000 ); + else if ( !Okular::Settings::saveMetaData() && m_saveBookmarksTimer ) + m_saveBookmarksTimer->stop(); } void DocumentPrivate::doContinueNextMatchSearch(void *pagesToNotifySet, void * theMatch, int currentPage, int searchID, const QString & text, int theCaseSensitivity, bool moveViewport, const QColor & color, bool noDialogs, int donePages) @@ -1687,7 +1692,11 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi d->m_saveBookmarksTimer = new QTimer( this ); connect( d->m_saveBookmarksTimer, SIGNAL( timeout() ), this, SLOT( saveDocumentInfo() ) ); } - d->m_saveBookmarksTimer->start( 5 * 60 * 1000 ); + + if ( Okular::Settings::saveMetaData() ) + { + d->m_saveBookmarksTimer->start( 5 * 60 * 1000 ); + } // start memory check timer if ( !d->m_memCheckTimer ) @@ -1781,7 +1790,9 @@ void Document::closeDocument() // close the current document and save document info if a document is still opened if ( d->m_generator && d->m_pagesVector.size() > 0 ) { - d->saveDocumentInfo(); + // only save data if specified in preferences + if ( Okular::Settings::saveMetaData() ) + d->saveDocumentInfo(); d->m_generator->closeDocument(); } -- 1.7.4.1
_______________________________________________ Okular-devel mailing list Okular-devel@kde.org https://mail.kde.org/mailman/listinfo/okular-devel