Hey guys, My name is Christopher and I have been working on Okular for a few months. I want to get everyones opinion on a patch that gives a user the ability to manage their meta data. This allows users to delete all history of a particular file on their system, clear all history of all meta data, or just not save it in the first place.
If you apply this patch check out this "Configure Okular" Dialog in "Settings" to check out this feature and let me know what you think. I am especially concerned about the English writing facing the user and the way it sounds. Thank you all for your time and patience, -Christopher
Index: conf/dlgmetadata.cpp =================================================================== --- conf/dlgmetadata.cpp (revision 0) +++ conf/dlgmetadata.cpp (revision 0) @@ -0,0 +1,179 @@ +/*************************************************************************** + * 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 <QFileSystemModel> +#include <QSortFilterProxyModel> +#include <QHeaderView> + +//kde +#include <KStandardDirs> +#include <KMessageBox> +#include <KGuiItem> +#include <KDebug> + +#include <config-okular.h> + +#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().localkdedir().append("share/apps/okular/docdata"); + + // 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, 350); + + //m_dlg->MetaFileList->header()->setResizeMode( QHeaderView::Interactive ); + //m_dlg->MetaFileList->header()->resize(10,20); + } + + connect( m_dlg->DelMetaButton, SIGNAL( clicked() ), + this, SLOT( delMetaFile() )); +} + +DlgMetaData::~DlgMetaData() +{ + delete m_dlg; +} + +void DlgMetaData::delMetaFile() +{ + KGuiItem yesButton( i18n( "Yes" ), QString(), + i18n( "This is a tooltip" ), + i18n( "This is a WhatsThis help text." ) ); + if ( KMessageBox::questionYesNo( 0, i18n( "Are you sure you want to do this?\n\n" + "Warning: deleting meta data will result\n" + "in the loss of bookmarks and annotations." ), + i18n( "Warning " ), + KStandardGuiItem::yes(), + KStandardGuiItem::no(), + i18n( "Do ask me again" )) == KMessageBox::Yes ) + { + m_model->remove( m_customModel->mapToSource( m_dlg->MetaFileList->currentIndex() )); + } +} + +void DlgMetaData::clearAllMetaData() +{ + if ( KMessageBox::questionYesNo( 0, i18n( "Are you sure you want to do this?\n\n" + "Warning: deleting meta data will result\n" + "in the loss of bookmarks and annotations." ), + i18n( "Warning " ), + KStandardGuiItem::yes(), + KStandardGuiItem::no(), + i18n( "Do ask me again" )) == KMessageBox::Yes ) + { + QDirIterator it(m_docdataDir, QDir::Files | QDir::NoDotAndDotDot ); + QDir dir(m_docdataDir); + while ( it.hasNext() ) + { + dir.remove( it.next() ); + } + } +} + + +// Custom Proxy for Meta Data File Lis +MetaFileProxyModel::MetaFileProxyModel( QObject *parent ) + : QSortFilterProxyModel( parent ) +{ +} + +QVariant MetaFileProxyModel::data( const QModelIndex & index, int role ) const +{ + if ( !index.isValid() ) + return QVariant(); + + if ( role == Qt::DisplayRole ) + { + QVariant modifiedData; + modifiedData = sourceModel()->data(mapToSource(index), role); + QRegExp rx("*.xml"); + rx.setPatternSyntax(QRegExp::Wildcard); + + if ( rx.exactMatch( modifiedData.toString() )) + { + // remove the prepensions and extensions from meta data filename to + // beautify its display to the users + modifiedData = modifiedData.toString().remove(QRegExp(".xml$")); + modifiedData = modifiedData.toString().remove(QRegExp("^[0-9]+\.")); + return modifiedData; + + } + else + { + return sourceModel()->data(mapToSource(index), role); + } + } + + return QVariant(); +} + +QVariant MetaFileProxyModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + // we need to properly size the headers and make them look better + if (role == Qt::SizeHintRole) { + if ( orientation == Qt::Horizontal ) + { + switch (section) + { + // 0 == File Name; 3 == Modified + // --this sizes the actual Header size so it looks proper + case 0: case 3: + //return QSize(20,20); + default: + return QVariant(); + } + } + } + else if ( role == Qt::DisplayRole ) { + if ( orientation == Qt::Horizontal ) + { + switch (section) + { + case 0: + return i18n("File Name"); + case 3: + return i18n("Modified"); + default: + return QVariant(); + } + } + } + + return QVariant(); +} + +#include "dlgmetadata.moc" Index: conf/dlgmetadata.h =================================================================== --- conf/dlgmetadata.h (revision 0) +++ conf/dlgmetadata.h (revision 0) @@ -0,0 +1,58 @@ +/*************************************************************************** + * 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 _DLGMETADATA_H +#define _DLGMETADATA_H + +#include <QWidget> +#include <QSortFilterProxyModel> + +class QHeaderView; +class QFileSystemModel; +class KMessageBox; +class Ui_DlgMetaDataBase; +class MetaFileProxyModel; + +class DlgMetaData : public QWidget +{ + Q_OBJECT + + public: + DlgMetaData( QWidget * parent = 0 ); + virtual ~DlgMetaData(); + + protected: + void MetaDataExp(bool); + Ui_DlgMetaDataBase *m_dlg; + + private slots: + void delMetaFile(); + void clearAllMetaData(); + + private: + QFileSystemModel *m_model; + QString m_docdataDir; + KMessageBox *warningDlg; + MetaFileProxyModel *m_customModel; + QHeaderView *m_header; + +}; + + +class MetaFileProxyModel : public QSortFilterProxyModel +{ + public: + MetaFileProxyModel( QObject *parent); + QVariant data(const QModelIndex &, int) const; + QVariant headerData(int section, Qt::Orientation, int role) const; + + private: +}; + +#endif // _DLGMETADATA_H Index: conf/preferencesdialog.cpp =================================================================== --- conf/preferencesdialog.cpp (revision 1230563) +++ conf/preferencesdialog.cpp (working copy) @@ -20,6 +20,7 @@ #include "dlgidentity.h" #include "dlgeditor.h" #include "dlgdebug.h" +#include "dlgmetadata.h" PreferencesDialog::PreferencesDialog( QWidget * parent, KConfigSkeleton * skeleton ) : KConfigDialog( parent, "preferences", skeleton ) @@ -30,6 +31,7 @@ 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 @@ 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 Index: conf/okular.kcfg =================================================================== --- conf/okular.kcfg (revision 1230563) +++ conf/okular.kcfg (working copy) @@ -294,4 +294,9 @@ <default>false</default> </entry> </group> + <group name="Dlg MetaData"> + <entry key="SaveMetaData" type="Bool"> + <default>true</default> + </entry> + </group> </kcfg> Index: conf/preferencesdialog.h =================================================================== --- conf/preferencesdialog.h (revision 1230563) +++ conf/preferencesdialog.h (working copy) @@ -23,6 +23,7 @@ class DlgIdentity; class DlgEditor; class DlgDebug; +class DlgMetaData; class PreferencesDialog : public KConfigDialog { @@ -44,6 +45,7 @@ DlgPresentation * m_presentation; DlgIdentity * m_identity; DlgEditor * m_editor; + DlgMetaData * m_metadata; DlgDebug * m_debug; }; Index: conf/dlgmetadatabase.ui =================================================================== --- conf/dlgmetadatabase.ui (revision 0) +++ conf/dlgmetadatabase.ui (revision 0) @@ -0,0 +1,290 @@ +<?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>499</width> + <height>403</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_3"> + <item row="0" column="0"> + <widget class="QGroupBox" name="groupBox"> + <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="title"> + <string>Meta Data</string> + </property> + <layout class="QGridLayout" name="gridLayout_2" rowstretch="0"> + <item row="0" column="0"> + <widget class="QWidget" name="widget" native="true"> + <property name="enabled"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QCheckBox" name="kcfg_SaveMetaData"> + <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="text"> + <string>Save all meta data</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>328</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <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_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>18</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <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>98</width> + <height>20</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> + <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>true</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> + </layout> + </widget> + </item> + <item row="1" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>10</width> + <height>10</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> Index: core/document.cpp =================================================================== --- core/document.cpp (revision 1230563) +++ core/document.cpp (working copy) @@ -1027,6 +1027,16 @@ int pageToKick = m_allocatedTextPagesFifo.takeFirst(); m_pagesVector.at(pageToKick)->setTextPage( 0 ); // deletes the textpage } + + if ( Okular::Settings::saveMetaData() ) + { + if ( m_saveBookmarksTimer ) + { + m_saveBookmarksTimer->start( 5 * 60 * 1000 ); + } + } + else if ( m_saveBookmarksTimer && !Okular::Settings::saveMetaData() ) + 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,8 +1697,12 @@ 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 +1795,9 @@ // 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(); } Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (revision 1230563) +++ CMakeLists.txt (working copy) @@ -123,6 +123,7 @@ conf/dlgidentity.cpp conf/dlgperformance.cpp conf/dlgpresentation.cpp + conf/dlgmetadata.cpp ui/embeddedfilesdialog.cpp ui/annotwindow.cpp ui/annotationmodel.cpp @@ -166,6 +167,7 @@ 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)
_______________________________________________ Okular-devel mailing list Okular-devel@kde.org https://mail.kde.org/mailman/listinfo/okular-devel