Browse files

Merge commit 'refs/merge-requests/2216' of git://gitorious.org/basket…

…/basket
  • Loading branch information...
2 parents f3a8c61 + cd03c2e commit 58882a8169940e4d4bb2133ac7de7d66b84aaab9 @mattr- mattr- committed Apr 8, 2011
View
1 .gitignore
@@ -1,2 +1,3 @@
.*.swp
.kdev4
+qtcreator-build
View
12 CMakeLists.txt
@@ -1,10 +1,13 @@
-cmake_minimum_required(VERSION 2.4)
+cmake_minimum_required(VERSION 2.6)
find_package(X11 REQUIRED)
find_package(KDE4 REQUIRED)
find_package(QImageBlitz REQUIRED)
find_package(Gpgme)
find_package(Gpgmepp)
+find_package(Soprano)
+find_package(Nepomuk)
+find_package(SharedDesktopOntologies)
if (BUILD_KPARTS)
find_package(KdepimLibs REQUIRED)
@@ -24,6 +27,12 @@ ELSE(GPGME_FOUND)
MESSAGE("GPG not found, configuring without")
ENDIF(GPGME_FOUND)
+IF(SHAREDDESKTOPONTOLOGIES_FOUND AND SOPRANO_FOUND AND NEPOMUK_FOUND)
+ SET(HAVE_NEPOMUK 1)
+ELSE(SHAREDDESKTOPONTOLOGIES_FOUND AND SOPRANO_FOUND AND NEPOMUK_FOUND)
+ MESSAGE("Soprano and/or Nepomuk not found, configuring without")
+ENDIF(SHAREDDESKTOPONTOLOGIES_FOUND AND SOPRANO_FOUND AND NEPOMUK_FOUND)
+
#TODO: find meinproc
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
@@ -40,4 +49,3 @@ add_subdirectory(welcome)
add_subdirectory(backgrounds)
add_subdirectory(images)
add_subdirectory(file-integration)
-
View
4 config.h.cmake
@@ -1,7 +1,9 @@
-
/* Define if libgpgme is available */
#cmakedefine HAVE_LIBGPGME
+/* Define if Nepomuk is available */
+#cmakedefine HAVE_NEPOMUK
+
/* Version number of package */
#define VERSION "1.90"
View
10 file-integration/CMakeLists.txt
@@ -1,4 +1,3 @@
-
set(basketthumbcreator_PART_SRCS basketthumbcreator.cpp)
kde4_add_plugin(basketthumbcreator ${basketthumbcreator_PART_SRCS})
@@ -11,7 +10,12 @@ install(TARGETS basketthumbcreator DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install(FILES basketthumbcreator.desktop DESTINATION ${SERVICES_INSTALL_DIR})
-install(FILES basket.magic DESTINATION ${CONFIG_INSTALL_DIR}/magic)
-install(FILES x-basket-archive.desktop x-basket-template.desktop DESTINATION ${MIME_INSTALL_DIR}/application)
+install(CODE "
+find_program(XDG-MIME_EXECUTABLE xdg-mime)
+find_program(XDG-DESKTOP-MENU_EXECUTABLE xdg-desktop-menu)
+execute_process(COMMAND ${XDG-MIME_EXECUTABLE} install --novendor basket.xml)
+execute_process(COMMAND ${XDG-DESKTOP-MENU_EXECUTABLE} install --novendor basket.desktop)
+execute_process(COMMAND ${XDG-MIME_EXECUTABLE} default basket.desktop application/x-basket-item)
+")
kde4_install_icons(${ICON_INSTALL_DIR})
View
2 file-integration/basket.magic
@@ -1,2 +0,0 @@
-0 string BasKetNP:archive\n application/x-basket-archive
-0 string BasKetNP:template\n application/x-basket-template
View
55 file-integration/basket.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
+ <mime-type type="application/x-basket-archive">
+ <comment>Basket Archive</comment>
+ <comment xml:lang="af">verskille tussen lêers</comment>
+ <comment xml:lang="de">Korbarchiv</comment>
+ <comment xml:lang="es">Archivo de cestas</comment>
+ <comment xml:lang="fr">Archive de paniers</comment>
+ <comment xml:lang="it">Archivio di canestri</comment>
+ <comment xml:lang="ja">バスケットアーカイブ</comment>
+ <comment xml:lang="nb">Kurvarkiv</comment>
+ <comment xml:lang="nn">Korgarkiv</comment>
+ <comment xml:lang="pt">Ficheiro de cestos</comment>
+ <comment xml:lang="ru">Контейнер Basket</comment>
+ <comment xml:lang="tr">Basket Arşivi</comment>
+ <icon name="basket" />
+ <glob pattern="*.baskets" weight="50" />
+ <magic priority="90">
+ <match type="string" offset="0" value="BasKetNP:archive\n"/>
+ </magic>
+ </mime-type>
+
+ <mime-type type="application/x-basket-template">
+ <comment>Basket Template</comment>
+ <comment xml:lang="de">Korbvorlage</comment>
+ <comment xml:lang="es">Plantilla de cesta</comment>
+ <comment xml:lang="fr">Modèle de panier</comment>
+ <comment xml:lang="it">Modello di canestri</comment>
+ <comment xml:lang="ja">バスケットテンプレート</comment>
+ <comment xml:lang="nb">Kurvmal</comment>
+ <comment xml:lang="nn">Korgmal</comment>
+ <comment xml:lang="pt">Modelo de cesto</comment>
+ <comment xml:lang="ru">Шаблон корзины</comment>
+ <comment xml:lang="tr">Basket Şabolonu</comment>
+ <icon name="basket" />
+ <glob pattern="*.baskett" weight="50" />
+ <magic priority="90">
+ <match type="string" offset="0" value="BasKetNP:template\n"/>
+ </magic>
+ </mime-type>
+
+ <mime-type type="application/x-basket-item">
+ <sub-class-of type="text/xml"/>
+ <sub-class-of type="application/xml"/>
+ <comment>Basket Note Pads</comment>
+ <icon name="basket" />
+ <glob pattern=".basket" weight="60" />
+ <magic priority="90">
+ <match type="string" offset="2" value="xml">
+ <match type="string" offset="39" value="!DOCTYPE basket>"/>
+ </match>
+ </magic>
+ <root-XML localName="basket" />
+ </mime-type>
+</mime-info>
View
17 file-integration/x-basket-archive.desktop
@@ -1,17 +0,0 @@
-[Desktop Entry]
-Encoding=UTF-8
-MimeType=application/x-basket-archive
-Type=MimeType
-Comment=Basket Archive
-Comment[de]=Korbarchiv
-Comment[es]=Archivo de cestas
-Comment[fr]=Archive de paniers
-Comment[it]=Archivio di canestri
-Comment[ja]=バスケットアーカイブ
-Comment[nb]=Kurvarkiv
-Comment[nn]=Korgarkiv
-Comment[pt]=Ficheiro de cestos
-Comment[ru]=Контейнер Basket
-Comment[tr]=Basket Arşivi
-Icon=baskets
-Patterns=*.baskets
View
17 file-integration/x-basket-template.desktop
@@ -1,17 +0,0 @@
-[Desktop Entry]
-Encoding=UTF-8
-MimeType=application/x-basket-template
-Type=MimeType
-Comment=Basket Template
-Comment[de]=Korbvorlage
-Comment[es]=Plantilla de cesta
-Comment[fr]=Modèle de panier
-Comment[it]=Modello di canestri
-Comment[ja]=バスケットテンプレート
-Comment[nb]=Kurvmal
-Comment[nn]=Korgmal
-Comment[pt]=Modelo de cesto
-Comment[ru]=Шаблон корзины
-Comment[tr]=Basket Şabolonu
-Icon=baskett
-Patterns=*.baskett
View
5 installer
@@ -140,9 +140,8 @@ echo " ======================================================================
echo ""
echo ""
-if [ $1 -gt 0 ]; then
- threads=$1
-else
+threads=${1:-2}
+if [ $threads -le 0 ]; then
threads=2
fi
echo "make -j${threads}"
View
13 src/CMakeLists.txt
@@ -51,6 +51,15 @@ set(basketcommon_LIB_SRCS
xmlwork.cpp
)
+IF(HAVE_NEPOMUK)
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src" ${NEPOMUK_INCLUDES} ${SOPRANO_INCLUDE_DIR})
+ include(SopranoAddOntology)
+ soprano_add_ontology(basketcommon_LIB_SRCS ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nie.trig "NIE" "Soprano::Vocabulary" "trig")
+ soprano_add_ontology(basketcommon_LIB_SRCS ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nfo.trig "NFO" "Soprano::Vocabulary" "trig")
+ soprano_add_ontology(basketcommon_LIB_SRCS ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/pimo/pimo.trig "PIMO" "Soprano::Vocabulary" "trig")
+ list(INSERT basketcommon_LIB_SRCS 10 nepomukintegration.cpp)
+ENDIF(HAVE_NEPOMUK)
+
kde4_add_ui_files(basketcommon_LIB_SRCS passwordlayout.ui)
QT4_ADD_DBUS_ADAPTOR(basketcommon_LIB_SRCS org.basket.BNPView.xml bnpview.h BNPView)
@@ -74,6 +83,10 @@ if(Q_WS_X11)
target_link_libraries(basketcommon ${X11_X11_LIB})
endif(Q_WS_X11)
+IF(HAVE_NEPOMUK)
+ target_link_libraries(basketcommon ${NEPOMUK_LIBRARIES} ${SOPRANO_LIBRARIES})
+ENDIF(HAVE_NEPOMUK)
+
set_target_properties(basketcommon PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION})
install(TARGETS basketcommon DESTINATION ${LIB_INSTALL_DIR})
View
9 src/application.cpp
@@ -23,6 +23,7 @@
#include <QFile>
#include <QFileInfo>
#include <QTimer>
+#include <KDebug>
#include "application.h"
#include "global.h"
@@ -45,9 +46,15 @@ int Application::newInstance()
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args && args->count() >= 1) {
QString fileName = args->arg(args->count() - 1);
+
if (QFile::exists(fileName)) {
QFileInfo fileInfo(fileName);
- if (!fileInfo.isDir()) { // Do not mis-interpret data-folder param!
+ if (fileInfo.absoluteFilePath().contains(Global::basketsFolder())) {
+ QString folder = fileInfo.absolutePath().split("/").last();
+ folder.append("/");
+ BNPView::s_basketToOpen = folder;
+ QTimer::singleShot(100, Global::bnpView, SLOT(delayedOpenBasket()));
+ } else if (!fileInfo.isDir()) { // Do not mis-interpret data-folder param!
// Tags are not loaded until Global::bnpView::lateInit() is called.
// It is called 0ms after the application start.
BNPView::s_fileToOpen = fileName;
View
2 src/basket.desktop
@@ -2,7 +2,7 @@
Type=Application
Exec=basket %f
-MimeType=application/x-basket-archive;application/x-basket-template;
+MimeType=application/x-basket-archive;application/x-basket-template;application/x-basket-item;
Icon=basket
Categories=Qt;KDE;Office;
View
6 src/basket_part.rc
@@ -40,6 +40,8 @@
<Action name="basket_import_text_file" />
</Menu>
<Action name="basket_backup_restore" />
+ <Separator/>
+ <Action name="check_cleanup" />
</Menu>
<Menu name="edit" >
<text>&amp;Edit</text>
@@ -199,6 +201,8 @@
<Action name="basket_import_text_file" />
</Menu>
<Action name="basket_backup_restore" />
+ <Separator/>
+ <Action name="check_cleanup" />
</Menu>
<Menu name="tab_bar_popup" >
<Action name="basket_new" />
@@ -218,6 +222,8 @@
<Action name="basket_import_text_file" />
</Menu>
<Action name="basket_backup_restore" />
+ <Separator/>
+ <Action name="check_cleanup" />
</Menu>
<Menu noMerge="1" name="note_popup" >
<Action name="note_edit" />
View
6 src/basketui.rc
@@ -41,6 +41,8 @@
</Menu>
<Action name="basket_backup_restore" />
<Separator/>
+ <Action name="check_cleanup" />
+ <Separator/>
<Action name="window_hide" />
<Action name="file_quit" />
</Menu>
@@ -206,6 +208,8 @@
<Action name="basket_import_text_file" />
</Menu>
<Action name="basket_backup_restore" />
+ <Separator/>
+ <Action name="check_cleanup" />
</Menu>
<Menu name="tab_bar_popup" >
<Action name="basket_new" />
@@ -225,6 +229,8 @@
<Action name="basket_import_text_file" />
</Menu>
<Action name="basket_backup_restore" />
+ <Separator/>
+ <Action name="check_cleanup" />
</Menu>
<Menu noMerge="1" name="note_popup" >
<Action name="note_edit" />
View
11 src/basketview.cpp
@@ -104,6 +104,10 @@
#include "kgpgme.h"
#endif
+#ifdef HAVE_NEPOMUK
+#include "nepomukintegration.h"
+#endif
+
/** Class BasketView: */
const int BasketView::FRAME_DELAY = 50/*1500*/; // Delay between two animation "frames" in milliseconds
@@ -901,6 +905,12 @@ bool BasketView::save()
if (!saveToFile(fullPath() + ".basket", "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + document.toString())) {
DEBUG_WIN << "Basket[" + folderName() + "]: <font color=red>FAILED to save</font>!";
return false;
+#ifdef HAVE_NEPOMUK
+ } else {
+ //The .basket file is saved; now updating the Metadata in Nepomuk
+ DEBUG_WIN << "NepomukIntegration: Updating Basket[" + folderName() + "]:"; // <font color=red>Updating Metadata</font>!";
+ nepomukIntegration::updateMetadata(this);
+#endif
}
Global::bnpView->setUnsavedStatus(false);
@@ -1172,6 +1182,7 @@ BasketView::BasketView(QWidget *parent, const QString &folderName)
{
m_action = new KAction(this);
connect(m_action, SIGNAL(triggered()), this, SLOT(activatedShortcut()));
+ m_action->setObjectName(folderName);
m_action->setGlobalShortcut(KShortcut());
// We do this in the basket properties dialog (and keep it in sync with the
// global one)
View
141 src/bnpview.cpp
@@ -568,6 +568,15 @@ void BNPView::setupActions()
a->setText(i18n("&Backup && Restore..."));
a->setShortcut(0);
+ a = ac->addAction("check_cleanup", this, SLOT(checkCleanup()));
+ a->setText(i18n("&Check && Cleanup..."));
+ a->setShortcut(0);
+ if (KCmdLineArgs::parsedArgs() && KCmdLineArgs::parsedArgs()->isSet("debug")) {
+ a->setEnabled(true);
+ } else {
+ a->setEnabled(false);
+ }
+
/** Note : ****************************************************************/
a = ac->addAction("edit_delete", this, SLOT(delNote()));
@@ -1694,6 +1703,126 @@ void BNPView::backupRestore()
dialog.exec();
}
+void checkNote(Note * note, QList<QString> & fileList) {
+ while (note) {
+ note->finishLazyLoad();
+ if ( note->isGroup() ) {
+ checkNote(note->firstChild(), fileList);
+ } else if ( note->content()->useFile() ) {
+ QString noteFileName = note->basket()->folderName() + note->content()->fileName();
+ int basketFileIndex = fileList.indexOf( noteFileName );
+ if (basketFileIndex < 0) {
+ DEBUG_WIN << "<font color='red'>" + noteFileName + " NOT FOUND!</font>";
+ } else {
+ fileList.removeAt(basketFileIndex);
+ }
+ }
+ note = note->next();
+ }
+}
+
+void checkBasket(BasketListViewItem * item, QList<QString> & dirList, QList<QString> & fileList) {
+ BasketView* basket = ((BasketListViewItem *)item)->basket();
+ QString basketFolderName = basket->folderName();
+ int basketFolderIndex = dirList.indexOf( basket->folderName() );
+ if (basketFolderIndex < 0) {
+ DEBUG_WIN << "<font color='red'>" + basketFolderName + " NOT FOUND!</font>";
+ } else {
+ dirList.removeAt(basketFolderIndex);
+ }
+ int basketFileIndex = fileList.indexOf( basket->folderName() + ".basket" );
+ if (basketFileIndex < 0) {
+ DEBUG_WIN << "<font color='red'>.basket file of " + basketFolderName + ".basket NOT FOUND!</font>";
+ } else {
+ fileList.removeAt(basketFileIndex);
+ }
+ if (!basket->loadingLaunched() && !basket->isLocked()) {
+ basket->load();
+ }
+ DEBUG_WIN << "\t********************************************************************************";
+ DEBUG_WIN << basket->basketName() << "(" << basketFolderName << ") loaded.";
+ Note *note = basket->firstNote();
+ if (! note ) {
+ DEBUG_WIN << "\tHas NO notes!";
+ } else {
+ checkNote(note, fileList);
+ }
+ basket->save();
+ kapp->processEvents(QEventLoop::ExcludeUserInputEvents, 100);
+ for ( int i=0; i < item->childCount(); i++) {
+ checkBasket((BasketListViewItem *) item->child(i), dirList, fileList);
+ }
+ if ( basket != Global::bnpView->currentBasket() ) {
+ DEBUG_WIN << basket->basketName() << "(" << basketFolderName << ") unloading...";
+ DEBUG_WIN << "\t********************************************************************************";
+ basket->unbufferizeAll();
+ } else {
+ DEBUG_WIN << basket->basketName() << "(" << basketFolderName << ") is the current basket, not unloading.";
+ DEBUG_WIN << "\t********************************************************************************";
+ }
+ kapp->processEvents(QEventLoop::ExcludeUserInputEvents, 100);
+}
+
+void BNPView::checkCleanup() {
+ DEBUG_WIN << "Starting the check, cleanup and reindexing... (" + Global::basketsFolder() + ")";
+ QList<QString> dirList;
+ QList<QString> fileList;
+ QString topDirEntry;
+ QString subDirEntry;
+ QFileInfo fileInfo;
+ QDir topDir(Global::basketsFolder(), QString::null, QDir::Name | QDir::IgnoreCase, QDir::TypeMask | QDir::Hidden);
+ foreach( topDirEntry, topDir.entryList() ) {
+ if( topDirEntry != "." && topDirEntry != ".." ) {
+ fileInfo.setFile(Global::basketsFolder() + "/" + topDirEntry);
+ if (fileInfo.isDir()) {
+ dirList << topDirEntry + "/";
+ QDir basketDir(Global::basketsFolder() + "/" + topDirEntry,
+ QString::null, QDir::Name | QDir::IgnoreCase, QDir::TypeMask | QDir::Hidden);
+ foreach( subDirEntry, basketDir.entryList() ) {
+ if (subDirEntry != "." && subDirEntry != "..") {
+ fileList << topDirEntry + "/" + subDirEntry;
+ }
+ }
+ } else if (topDirEntry != "." && topDirEntry != ".." && topDirEntry != "baskets.xml") {
+ fileList << topDirEntry;
+ }
+ }
+ }
+ DEBUG_WIN << "Directories found: "+ QString::number(dirList.count());
+ DEBUG_WIN << "Files found: "+ QString::number(fileList.count());
+
+ DEBUG_WIN << "Checking Baskets:";
+ for (int i = 0; i < topLevelItemCount(); i++) {
+ checkBasket( topLevelItem(i), dirList, fileList );
+ }
+ DEBUG_WIN << "Baskets checked.";
+ DEBUG_WIN << "Directories remaining (not in any basket): "+ QString::number(dirList.count());
+ DEBUG_WIN << "Files remaining (not in any basket): "+ QString::number(fileList.count());
+
+ foreach(topDirEntry, dirList) {
+ DEBUG_WIN << "<font color='red'>" + topDirEntry + " does not belong to any basket!</font>";
+ //Tools::deleteRecursively(Global::basketsFolder() + "/" + topDirEntry);
+ //DEBUG_WIN << "<font color='red'>\t" + topDirEntry + " removed!</font>";
+ Tools::trashRecursively(Global::basketsFolder() + "/" + topDirEntry);
+ DEBUG_WIN << "<font color='red'>\t" + topDirEntry + " trashed!</font>";
+ foreach(subDirEntry, fileList) {
+ fileInfo.setFile(Global::basketsFolder() + "/" + subDirEntry);
+ if ( ! fileInfo.isFile() ) {
+ fileList.removeAll( subDirEntry );
+ DEBUG_WIN << "<font color='red'>\t\t" + subDirEntry + " already removed!</font>";
+ }
+ }
+ }
+ foreach(subDirEntry, fileList) {
+ DEBUG_WIN << "<font color='red'>" + subDirEntry + " does not belong to any note!</font>";
+ //Tools::deleteRecursively(Global::basketsFolder() + "/" + subDirEntry);
+ //DEBUG_WIN << "<font color='red'>\t" + subDirEntry + " removed!</font>";
+ Tools::trashRecursively(Global::basketsFolder() + "/" + subDirEntry);
+ DEBUG_WIN << "<font color='red'>\t" + subDirEntry + " trashed!</font>";
+ }
+ DEBUG_WIN << "Check, cleanup and reindexing completed";
+}
+
void BNPView::countsChanged(BasketView *basket)
{
if (basket == currentBasket())
@@ -2118,9 +2247,9 @@ void BNPView::doBasketDeletion(BasketView *basket)
basket->closeEditor();
QTreeWidgetItem *basketItem = listViewItemForBasket(basket);
- for (int i = 0; i < basketItem->childCount(); i++) {
+ while( basketItem->childCount() > 0 ) {
// First delete the child baskets:
- doBasketDeletion(((BasketListViewItem*)basketItem->child(i))->basket());
+ doBasketDeletion(((BasketListViewItem*)basketItem->child(0))->basket());
}
// Then, basket have no child anymore, delete it:
DecoratedBasket *decoBasket = basket->decoration();
@@ -2203,6 +2332,14 @@ void BNPView::delayedOpenArchive()
Archive::open(s_fileToOpen);
}
+QString BNPView::s_basketToOpen = "";
+
+void BNPView::delayedOpenBasket()
+{
+ BasketView *bv = this->basketForFolderName(s_basketToOpen);
+ this->setCurrentBasketInHistory(bv);
+}
+
void BNPView::openArchive()
{
QString filter = "*.baskets|" + i18n("Basket Archives") + "\n*|" + i18n("All Files");
View
3 src/bnpview.h
@@ -126,6 +126,7 @@ public slots:
void importJreepadFile();
void importTextFile();
void backupRestore();
+ void checkCleanup();
/** Note */
void activatedTagShortcut();
@@ -199,6 +200,7 @@ public slots:
void saveAsArchive();
void openArchive();
void delayedOpenArchive();
+ void delayedOpenBasket();
void lockBasket();
void hideOnEscape();
@@ -216,6 +218,7 @@ public slots:
public:
static QString s_fileToOpen;
+ static QString s_basketToOpen;
public slots:
void addWelcomeBaskets();
View
418 src/nepomukintegration.cpp
@@ -0,0 +1,418 @@
+#include "nepomukintegration.h"
+
+#include <QCoreApplication>
+#include <QThread>
+#include <QtConcurrentRun>
+#include <QMutex>
+#include <QMutexLocker>
+#include <QDomNode>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QDBusMessage>
+#include <QDBusConnection>
+#include <QDBusInterface>
+#include <QDBusReply>
+#include <QFileInfo>
+#include <KUrl>
+#include <KDE/KDebug>
+#include <QEventLoop>
+#include <KDE/KApplication>
+
+
+#include "global.h"
+#include "tag.h"
+#include "debugwindow.h"
+#include "basketview.h"
+
+#include <Nepomuk/ResourceManager>
+#include <Nepomuk/Variant>
+#include <Nepomuk/Types/Class>
+/* #include <Nepomuk/File> */
+#include <Nepomuk/Tag>
+#include <Soprano/Vocabulary/NAO>
+#include <Soprano/Vocabulary/RDF>
+#include <Soprano/Vocabulary/RDFS>
+#include "nie.h"
+#include "nfo.h"
+#include "pimo.h"
+
+nepomukIntegration * nepomukIntegration::instance = NULL;
+QMutex nepomukIntegration::instanceMutex;
+
+
+/*
+ * Constructor / Cleanup
+ */
+
+nepomukIntegration::nepomukIntegration(BasketView * basket, int idleTime = 15000) : QObject()
+ , idleTime(idleTime), workerThread(this), cleanupTimer(this), mutex()
+ , basketList(), isDoingUpdate(true), requestedIndexList(), isCleaningupRequestedIndexes(false)
+{
+ connect( this, SIGNAL(updateCompleted(QString, bool)),
+ this, SLOT(checkQueue()),
+ Qt::QueuedConnection
+ );
+ connect( &cleanupTimer, SIGNAL(timeout()),
+ this, SLOT(cleanup()),
+ Qt::QueuedConnection
+ );
+
+ connect( &workerThread, SIGNAL(finished()),
+ this, SLOT(deleteLater()),
+ Qt::QueuedConnection
+ );
+ connect( &workerThread, SIGNAL(terminated()),
+ this, SLOT(deleteLater()),
+ Qt::QueuedConnection
+ );
+
+ QMutexLocker locker(&mutex);
+ basketList << basket;
+
+ moveToThread(&workerThread);
+ QTimer::singleShot(500, this, SLOT(doUpdate()));
+ workerThread.start(QThread::IdlePriority);
+
+ DEBUG_WIN << "nepomukIntegration object constructed";
+}
+
+
+void nepomukIntegration::cleanup() {
+ DEBUG_WIN << "cleanup: starting";
+ QMutexLocker locker(&instanceMutex);
+ //Keep the timer active for a long time
+ cleanupTimer.start(idleTime*100);
+
+ if ( ! basketList.isEmpty() ) {
+ if ( ! isDoingUpdate ) {
+ DEBUG_WIN << "<font color='red'>basketList is NOT empty but isDoingUpdate is false!</font>";
+ QTimer::singleShot(500, this, SLOT(checkQueue()));
+ }
+ DEBUG_WIN << "cleanup: deactivating cleanupTimer and returning.";
+ cleanupTimer.stop();
+ return;
+ }
+ if ( ! requestedIndexList.isEmpty() ) {
+ if ( ! isCleaningupRequestedIndexes ) {
+ DEBUG_WIN << "cleanup: requestedIndexList is NOT empty";
+ QDBusInterface * nepomukstrigiDBusInterface = new QDBusInterface( "org.kde.nepomuk.services.nepomukstrigiservice",
+ "/nepomukstrigiservice", "", QDBusConnection::sessionBus() , this
+ );
+ QDBusReply<bool> isIndexing = nepomukstrigiDBusInterface->call("isIndexing");
+ if ( isIndexing.isValid() && ! isIndexing ) {
+ DEBUG_WIN << "cleanup: nepomukstrigiservice is NOT indexing, going to run cleanupRequestedIndexes.";
+ QDBusConnection::sessionBus().disconnect(
+ "org.kde.nepomuk.services.nepomukstrigiservice", "/nepomukstrigiservice", "", "indexingStopped",
+ this, SLOT(cleanupRequestedIndexes())
+ );
+ cleanupRequestedIndexes();
+ } else if ( ! isDoingUpdate ) {
+ DEBUG_WIN << "requestedIndexList is NOT empty, nepomukstrigiservice isIndexing is true and isDoingUpdate is false.";
+ DEBUG_WIN << "Scheduling checkQueue.";
+ QTimer::singleShot(500, this, SLOT(checkQueue()));
+ }
+ }
+ DEBUG_WIN << "cleanup: deactivating cleanupTimer and returning.";
+ cleanupTimer.stop();
+ return;
+ }
+ instance = NULL;
+ DEBUG_WIN << "nepomukIntegration instance is set to NULL";
+ workerThread.quit();
+ moveToThread(QCoreApplication::instance()->thread());
+}
+
+
+/*
+ * Queue baskets and indexRequests / checkQueue
+ */
+
+void nepomukIntegration::updateMetadata(BasketView * basket) {
+ DEBUG_WIN << "updateMetadata: Going to lock updaterInstanceMutex";
+ QMutexLocker locker(&instanceMutex);
+ if ( instance == NULL ) {
+ instance = new nepomukIntegration(basket);
+ } else {
+ instance->queueBasket(basket);
+ }
+ DEBUG_WIN << "updateMetadata: Done";
+}
+
+void nepomukIntegration::checkQueue() {
+ DEBUG_WIN << "checkQueue: Going to lock";
+ QMutexLocker locker(&mutex);
+ if ( basketList.isEmpty() ) {
+ if ( ! cleanupTimer.isActive() ) {
+ if ( requestedIndexList.isEmpty() ) {
+ cleanupTimer.start(idleTime);
+ DEBUG_WIN << "checkQueue: cleanupTimer started";
+ } else if ( ! isCleaningupRequestedIndexes ) {
+ cleanupTimer.start(idleTime*10);
+ DEBUG_WIN << "checkQueue: requestedIndexList is NOT empty, cleanupTimer started with an interval of idleTime x 10";
+ }
+ }
+ isDoingUpdate = false;
+ } else {
+ cleanupTimer.stop();
+ isDoingUpdate = true;
+ QTimer::singleShot(500, this, SLOT(doUpdate()));
+ }
+ DEBUG_WIN << "checkQueue: Done";
+}
+
+void nepomukIntegration::queueBasket(BasketView * basket) {
+ DEBUG_WIN << "queueBasket: Going to lock";
+ QMutexLocker locker(&mutex);
+ basketList << basket;
+ if ( ! isDoingUpdate ) {
+ cleanupTimer.stop();
+ isDoingUpdate = true;
+ QTimer::singleShot(500, this, SLOT(doUpdate()));
+ DEBUG_WIN << "queueBasket : doUpdate scheduled.";
+ }
+ DEBUG_WIN << "queueBasket: Done";
+}
+
+void nepomukIntegration::queueIndexRequest(KUrl file) {
+ DEBUG_WIN << "queueIndexRequest: Going to lock";
+ QMutexLocker locker(&mutex);
+ if ( requestedIndexList.isEmpty() ) {
+ QDBusConnection::sessionBus().connect(
+ "org.kde.nepomuk.services.nepomukstrigiservice", "/nepomukstrigiservice", "", "indexingStopped",
+ this, SLOT(cleanupRequestedIndexes())
+ );
+ isCleaningupRequestedIndexes = false;
+ }
+ //If there is another one of this file in the queue, do not add it again
+ KUrl indexedFile;
+ foreach (indexedFile, requestedIndexList) {
+ if ( indexedFile == file ) {
+ DEBUG_WIN << "queueIndexRequest: (duplicate) Done";
+ return;
+ }
+ }
+ requestedIndexList << file;
+ DEBUG_WIN << "queueIndexRequest: Done";
+}
+
+
+/*
+ * Dequeue / Process baskets and indexRequests
+ */
+
+void nepomukIntegration::cleanupRequestedIndexes() {
+ DEBUG_WIN << "cleanupRequestedIndexes: Going to lock";
+ if ( ! mutex.tryLock() ) {
+ DEBUG_WIN << "<font color='red'>cleanupRequestedIndexes could NOT get the lock!</font>";
+ DEBUG_WIN << "<font color='red'>Scheduling for a later execution and Returning!</font>";
+ QTimer::singleShot(1000, this, SLOT(cleanupRequestedIndexes()));
+ return;
+ }
+ if ( requestedIndexList.isEmpty() ) {
+ QDBusConnection::sessionBus().disconnect(
+ "org.kde.nepomuk.services.nepomukstrigiservice", "/nepomukstrigiservice", "", "indexingStopped",
+ this, SLOT(cleanupRequestedIndexes())
+ );
+ mutex.unlock();
+ isCleaningupRequestedIndexes = false;
+ DEBUG_WIN << "\tqueue is empty, desconnected from indexingStopped signal and isCleaningupRequestedIndexes set to false.";
+ if ( ! isDoingUpdate ) {
+ //Make sure the timer is not active so that the queues are rechecked
+ // and timeout of the timer is reevaluated and restarted
+ cleanupTimer.stop();
+ QTimer::singleShot(500, this, SLOT(checkQueue()));
+ }
+ DEBUG_WIN << "cleanupRequestedIndexes: Done";
+ return;
+ }
+ isCleaningupRequestedIndexes = true;
+ KUrl indexedFile = requestedIndexList.takeFirst();
+ mutex.unlock();
+ DEBUG_WIN << "cleanupRequestedIndexes: unlocked";
+
+ DEBUG_WIN << "cleanupRequestedIndexes: \tnote : " << indexedFile.pathOrUrl();
+ Nepomuk::Resource noteRes(indexedFile);
+ noteRes.setProperty( Soprano::Vocabulary::RDF::type(), Soprano::Vocabulary::PIMO::Note() );
+ noteRes.setProperty( Soprano::Vocabulary::NIE::mimeType(), "application/x-basket-item" );
+
+ QTimer::singleShot(500, this, SLOT(cleanupRequestedIndexes()));
+ DEBUG_WIN << "cleanupRequestedIndexes: Done. Returning";
+}
+
+void listAllNotes(Note * note, QString basketFolderAbsolutePath, QList<QString> & noteFileList) {
+ while (note) {
+ if ( note->isGroup() ) {
+ listAllNotes(note->firstChild(), basketFolderAbsolutePath, noteFileList);
+ } else if ( note->content()->useFile() ) {
+ noteFileList << basketFolderAbsolutePath + note->content()->fileName();
+ }
+ note = note->next();
+ }
+}
+
+
+void nepomukIntegration::doUpdate() {
+ DEBUG_WIN << "doUpdate: Going to lock";
+ mutex.lock();
+ if ( basketList.isEmpty() ) {
+ DEBUG_WIN << "<font color='red'>doUpdate should not be run with an empty basketList! Returning!</font>";
+ return;
+ }
+ BasketView * basket = basketList.takeFirst();
+ QString basketFolderName = basket->folderName();
+ QString basketFolderAbsolutePath = Global::basketsFolder() + basketFolderName;
+ QString basketName = basket->basketName();
+ //If there is another one of this basket item in the queue, that one will be processed later (instead of the current one)
+ BasketView * tmpBasket;
+ foreach (tmpBasket, basketList) {
+ if ( basketFolderName == tmpBasket->folderName() ) {
+ mutex.unlock();
+ printf("doUpdate: \tDuplicate, unlocked\n"); fflush(stdout);fflush(stderr);
+ emit updateCompleted(basketFolderName, false);
+ return;
+ }
+ }
+ mutex.unlock();
+ DEBUG_WIN << "doUpdate: \tUnlocked";
+ QFileInfo basketDirInfo(basketFolderAbsolutePath);
+ if ( ! basketDirInfo.isDir() ) {
+ DEBUG_WIN << "<font color='red'>Global::basketsFolder() + basket->folderName() does not yield in a valid dir! Returning!</font>";
+ emit updateCompleted(basketFolderName, false);
+ return;
+ }
+ DEBUG_WIN << "Indexing (" << basketFolderName << "): " << basketName ;
+ if ( Nepomuk::ResourceManager::instance()->initialized() || Nepomuk::ResourceManager::instance()->init() ) {
+ DEBUG_WIN << "\tNepomuk::ResourceManager::instance initialized";
+ KUrl basketUri = KUrl( basketFolderAbsolutePath + ".basket" );
+ /* Nepomuk::File basketRes(basketUri); */
+ Nepomuk::Resource basketRes(basketUri);
+ /*addType works better: basketRes.setProperty( Soprano::Vocabulary::RDF::type(), Soprano::Vocabulary::PIMO::Note() ); */
+ basketRes.addType( Soprano::Vocabulary::PIMO::Note() );
+ /* Added by Strigi, no need: basketRes.addType( Soprano::Vocabulary::NFO::FileDataObject() ); */
+ basketRes.setProperty( Soprano::Vocabulary::NIE::mimeType(), "application/x-basket-item" );
+ /* nfo:fileUrl is deprecated in favor of nie:url: basketRes.setProperty( Soprano::Vocabulary::NFO::fileUrl(), basketUri ); */
+ /* This is done internally anyway: basketRes.setProperty( Soprano::Vocabulary::NIE::url(), basketUri ); */
+ basketRes.setProperty( Soprano::Vocabulary::NFO::fileName(), ".basket" );
+ basketRes.setProperty( Soprano::Vocabulary::NIE::title(), basketName);
+ basketRes.setLabel( basketName );
+
+ QList<Tag*> usedTagsList;
+ basket->listUsedTags(usedTagsList);
+ Tag * tmpTag;
+ Nepomuk::Tag basketTag;
+ QList<Nepomuk::Tag> tagList;
+ foreach (tmpTag, usedTagsList) {
+ basketTag = Nepomuk::Tag( tmpTag->name() );
+ basketTag.setLabel( tmpTag->name() );
+ tagList.append( basketTag );
+ }
+ basketRes.setTags( tagList );
+ DEBUG_WIN << "doUpdate: \tTags are set";
+ DEBUG_WIN << "doUpdate: \tQueuing note names:";
+
+ QList<QString> basketFileList;
+ Note *note = basket->firstNote();
+ if (! note ) {
+ DEBUG_WIN << "doUpdate: \tHas NO notes!";
+ } else {
+ listAllNotes(note, basketFolderAbsolutePath, basketFileList);
+ }
+ basketFileList << basketFolderAbsolutePath + ".basket";
+ QString noteContentFile;
+ KUrl noteUrl;
+ foreach (noteContentFile, basketFileList) {
+ DEBUG_WIN << "doUpdate: \t noteContentFile: " << noteContentFile;
+ noteUrl = KUrl( noteContentFile );
+ if ( noteUrl.isRelative() ) {
+ noteUrl = KUrl( Global::basketsFolder() + "/" + noteContentFile );
+ }
+ if ( ! noteUrl.isValid() || ! noteUrl.isLocalFile()
+ || ! QFile::exists(noteUrl.path()) || ! QFileInfo(noteUrl.path()).isFile() ) {
+ DEBUG_WIN << "\tnote : <font color='red'>" + noteContentFile + " NOT indexed!</font>" ;
+ continue;
+ }
+ Nepomuk::Resource noteRes(noteUrl);
+ noteRes.addType( Soprano::Vocabulary::PIMO::Note() );
+ noteRes.setProperty( Soprano::Vocabulary::NIE::mimeType(), "application/x-basket-item" );
+ noteRes.setProperty( Soprano::Vocabulary::PIMO::partOf(), basketRes );
+ //TODO
+ //Is this name OK?
+ noteRes.setProperty( Soprano::Vocabulary::NIE::title(), basketName + " (" + noteContentFile + ")" );
+ noteRes.setLabel( basketName + " (" + noteContentFile + ")" );
+
+ queueIndexRequest( noteUrl );
+ }
+ DEBUG_WIN << "doUpdate: Note queuing completed, now going to request indexing from nepomukstrigiservice:";
+ QDBusMessage nepomukstrigiDBusMessage =
+ QDBusMessage::createMethodCall( "org.kde.nepomuk.services.nepomukstrigiservice",
+ "/nepomukstrigiservice", "", "indexFolder"
+ );
+ DEBUG_WIN << "doUpdate: \tnepomukstrigiDBusMessage created";
+ QList<QVariant> indexingArgs;
+ indexingArgs.append(basketFolderAbsolutePath);
+ indexingArgs.append(false);
+ nepomukstrigiDBusMessage.setArguments(indexingArgs);
+ DEBUG_WIN << "doUpdate: \tnepomukstrigiDBusMessage prepared";
+ if ( QDBusConnection::sessionBus().send(nepomukstrigiDBusMessage) ) {
+ DEBUG_WIN << "doUpdate: \t\tindexing requested via DBus.";
+ } else {
+ DEBUG_WIN << "doUpdate: \t\tindexing request FAILED!";
+ }
+
+ //DEBUG
+ /*
+ QHash<QUrl, Nepomuk::Variant> basketProperties = basketRes.properties();
+ DEBUG_WIN << "\tproperties : ";
+ for( QHash<QUrl, Nepomuk::Variant>::const_iterator it = basketProperties.constBegin();
+ it != basketProperties.constEnd(); ++it ) {
+ QUrl propertyUri = it.key();
+ Nepomuk::Variant value = it.value();
+ Nepomuk::Types::Class propertyType( propertyUri );
+ DEBUG_WIN << "\t" + propertyType.uri().toString() + "/"
+ + propertyType.label() + "/" + propertyType.name() + ": " + value.toString();
+ }
+ */
+ } else {
+ DEBUG_WIN << "\tNepomuk::ResourceManager::instance initialization failed!";
+ emit updateCompleted(basketFolderName, false);
+ return;
+ }
+ DEBUG_WIN << "doUpdate: \tDone";
+ emit updateCompleted(basketFolderName, true);
+ return;
+}
+
+bool nepomukIntegration::doDelete(const QString &fullPath) {
+ DEBUG_WIN << "doDelete: going to lock";
+ instanceMutex.lock();
+ if ( instance != NULL ) {
+ DEBUG_WIN << "doDelete: cleanup any instance of " << fullPath;
+ QString basketsFolder = Global::basketsFolder();
+ int i;
+ for ( i=0; i<instance->basketList.count(); i++ ) {
+ if( basketsFolder + instance->basketList.at(i)->folderName() == fullPath ) {
+ instance->basketList.removeAt(i);
+ }
+ }
+ instance->requestedIndexList.removeAll(KUrl(fullPath));
+ }
+ instanceMutex.unlock();
+
+ if ( Nepomuk::ResourceManager::instance()->initialized() || Nepomuk::ResourceManager::instance()->init() ) {
+ DEBUG_WIN << "\tNepomuk::ResourceManager::instance initialized";
+ KUrl basketUri = KUrl( fullPath );
+ Nepomuk::Resource basketRes(basketUri);
+ basketRes.remove();
+ } else {
+ DEBUG_WIN << "\tNepomuk::ResourceManager::instance initialization failed!";
+ return false;
+ }
+ DEBUG_WIN << "doDelete: Done";
+ return true;
+}
+
+void nepomukIntegration::deleteMetadata(const QString &fullPath) {
+ //Only process files in Global::basketsFolder()
+ if ( fullPath.contains(Global::basketsFolder()) )
+ QtConcurrent::run(doDelete, fullPath);
+}
View
56 src/nepomukintegration.h
@@ -0,0 +1,56 @@
+#ifndef NEPOMUKINTEGRATION_H
+#define NEPOMUKINTEGRATION_H
+
+#include <QThread>
+#include <QPair>
+#include <QMutex>
+#include <QTimer>
+#include <QString>
+#include <QDomDocument>
+#include <KUrl>
+
+#include "basketview.h"
+#include "global.h"
+#include "debugwindow.h"
+
+class nepomukIntegration : public QObject
+{
+ Q_OBJECT
+public:
+ static void updateMetadata(BasketView * basket);
+ static void deleteMetadata(const QString &fullPath);
+ static bool doDelete(const QString &fullPath);
+private:
+ static nepomukIntegration *instance;
+ static QMutex instanceMutex;
+
+ nepomukIntegration(BasketView * basket, int idleTime);
+ ~nepomukIntegration() {
+ //I hope deletion is handled automatically
+ //delete workerThread;
+ //delete cleanupIdle;
+ DEBUG_WIN << "nepomukUpdater object destructed";
+ }
+
+ int idleTime;
+ QThread workerThread;
+ QTimer cleanupTimer;
+ QMutex mutex;
+ QList<BasketView *> basketList;
+ bool isDoingUpdate;
+ QList<KUrl> requestedIndexList;
+ bool isCleaningupRequestedIndexes;
+ void queueBasket(BasketView * basket);
+ void queueIndexRequest(KUrl file);
+signals:
+ void updateCompleted(QString basketFolderName, bool successful);
+ //void indexCleanupCompleted(KUrl file);
+private slots:
+ void doUpdate();
+ void checkQueue();
+ void cleanupRequestedIndexes();
+ void cleanup();
+
+};
+
+#endif // NEPOMUKINTEGRATION_H
View
14 src/notecontent.cpp
@@ -932,7 +932,7 @@ QPixmap UnknownContent::feedbackPixmap(int width, int height)
TextContent::TextContent(Note *parent, const QString &fileName, bool lazyLoad)
: NoteContent(parent, fileName), m_simpleRichText(0)
{
- basket()->addWatchedFile(fullPath());
+ basket()->addWatchedFile(fullPath() + fileName);
loadFromFile(lazyLoad);
}
@@ -1044,7 +1044,7 @@ void TextContent::exportToHTML(HTMLExporter *exporter, int indent)
HtmlContent::HtmlContent(Note *parent, const QString &fileName, bool lazyLoad)
: NoteContent(parent, fileName), m_simpleRichText(0)
{
- basket()->addWatchedFile(fullPath());
+ basket()->addWatchedFile(fullPath() + fileName);
loadFromFile(lazyLoad);
}
@@ -1160,7 +1160,7 @@ void HtmlContent::exportToHTML(HTMLExporter *exporter, int indent)
ImageContent::ImageContent(Note *parent, const QString &fileName, bool lazyLoad)
: NoteContent(parent, fileName), m_format()
{
- basket()->addWatchedFile(fullPath());
+ basket()->addWatchedFile(fullPath() + fileName);
loadFromFile(lazyLoad);
}
@@ -1299,7 +1299,7 @@ AnimationContent::AnimationContent(Note *parent,
, m_buffer(new QBuffer(this))
, m_movie(new QMovie(this))
{
- basket()->addWatchedFile(fullPath());
+ basket()->addWatchedFile(fullPath() + fileName);
loadFromFile(lazyLoad);
connect(m_movie, SIGNAL(updated(QRect)), this, SLOT(movieUpdated()));
connect(m_movie, SIGNAL(resized(QSize)), this, SLOT(movieResized()));
@@ -1395,7 +1395,7 @@ void AnimationContent::exportToHTML(HTMLExporter *exporter, int /*indent*/)
FileContent::FileContent(Note *parent, const QString &fileName)
: NoteContent(parent, fileName), m_previewJob(0)
{
- basket()->addWatchedFile(fullPath());
+ basket()->addWatchedFile(fullPath() + fileName);
setFileName(fileName); // FIXME: TO THAT HERE BECAUSE NoteContent() constructor seems to don't be able to call virtual methods???
}
@@ -2036,7 +2036,7 @@ void CrossReferenceContent::exportToHTML(HTMLExporter *exporter, int /*indent*/)
LauncherContent::LauncherContent(Note *parent, const QString &fileName)
: NoteContent(parent, fileName)
{
- basket()->addWatchedFile(fullPath());
+ basket()->addWatchedFile(fullPath() + fileName);
loadFromFile(/*lazyLoad=*/false);
}
@@ -2431,7 +2431,7 @@ const int UnknownContent::DECORATION_MARGIN = 2;
UnknownContent::UnknownContent(Note *parent, const QString &fileName)
: NoteContent(parent, fileName)
{
- basket()->addWatchedFile(fullPath());
+ basket()->addWatchedFile(fullPath() + fileName);
loadFromFile(/*lazyLoad=*/false);
}
View
45 src/tools.cpp
@@ -35,6 +35,11 @@
#include <QTime>
#include "tools.h"
+#include "debugwindow.h"
+#include "config.h"
+#ifdef HAVE_NEPOMUK
+#include "nepomukintegration.h"
+#endif
//cross reference
#include "global.h"
@@ -128,16 +133,16 @@ QString Tools::tagURLs(const QString &text)
urlPos += urlEx.matchedLength();
else
urlPos = 0;
- urlEx.setPattern("(www\\.(?!\\.)|([a-zA-z]+)://)[\\d\\w\\./,:_~\\?=&;#@\\-\\+\\%\\$]+[\\d\\w/]");
+ urlEx.setPattern("(www\\.(?!\\.)|(fish|(f|ht)tp(|s))://)[\\d\\w\\./,:_~\\?=&;#@\\-\\+\\%\\$]+[\\d\\w/]");
while ((urlPos = urlEx.indexIn(richText, urlPos)) >= 0) {
+ urlLen = urlEx.matchedLength();
//if this match is already a link don't convert it.
if(richText.mid(urlPos - 6, 6) == "href=\"") {
urlPos += urlLen;
continue;
}
- urlLen = urlEx.matchedLength();
QString href = richText.mid(urlPos, urlLen);
//we handle basket links seperately...
if(href.contains("basket://")) {
@@ -149,6 +154,7 @@ QString Tools::tagURLs(const QString &text)
urlPos++;
continue;
}
+ // Don't use QString::arg since %01, %20, etc could be in the string
QString anchor = "<a href=\"" + href + "\">" + href + "</a>";
richText.replace(urlPos, urlLen, anchor);
urlPos += anchor.length();
@@ -525,8 +531,43 @@ void Tools::deleteRecursively(const QString &folderOrFile)
} else
// Delete the file:
QFile::remove(folderOrFile);
+#ifdef HAVE_NEPOMUK
+ //The file/dir is deleted; now deleting the Metadata in Nepomuk
+ DEBUG_WIN << "NepomukIntegration: Deleting File[" + folderOrFile + "]:"; // <font color=red>Updating Metadata</font>!";
+ nepomukIntegration::deleteMetadata(folderOrFile);
+#endif
+}
+
+#include <kio/copyjob.h>
+void Tools::deleteMetadataRecursively(const QString &folderOrFile)
+{
+ QFileInfo fileInfo(folderOrFile);
+ if (fileInfo.isDir()) {
+ // Delete Metadata of the child files:
+ QDir dir(folderOrFile, QString::null, QDir::Name | QDir::IgnoreCase, QDir::TypeMask | QDir::Hidden);
+ QStringList list = dir.entryList();
+ for (QStringList::Iterator it = list.begin(); it != list.end(); ++it)
+ if (*it != "." && *it != "..")
+ deleteMetadataRecursively(folderOrFile + "/" + *it);
+ }
+ DEBUG_WIN << "NepomukIntegration: Deleting File[" + folderOrFile + "]:"; // <font color=red>Updating Metadata</font>!";
+ nepomukIntegration::deleteMetadata(folderOrFile);
+}
+
+void Tools::trashRecursively(const QString &folderOrFile)
+{
+ if (folderOrFile.isEmpty())
+ return;
+
+#ifdef HAVE_NEPOMUK
+ //First, deleting the Metadata in Nepomuk
+ deleteMetadataRecursively(folderOrFile);
+#endif
+
+ KIO::trash( KUrl(folderOrFile), KIO::HideProgressInfo );
}
+
QString Tools::fileNameForNewFile(const QString &wantedName, const QString &destFolder)
{
QString fileName = wantedName;
View
6 src/tools.h
@@ -89,6 +89,12 @@ QPixmap indentPixmap(const QPixmap &source, int depth, int deltaX = 0);
/** Delete the folder @p folderOrFile recursively (to remove sub-folders and child files too).
*/
void deleteRecursively(const QString &folderOrFile);
+/** Trash the folder @p folderOrFile recursively (to move sub-folders and child files to the Trash, too).
+ */
+void trashRecursively(const QString &folderOrFile);
+/** Delete the metadata of file or folder @p folderOrFile from Nepomuk, recursively.
+ */
+void deleteMetadataRecursively(const QString &folderOrFile);
/** @Return a new filename that doesn't already exist in @p destFolder.
* If @p wantedName alread exist in @p destFolder, a dash and a number will be added before the extenssion.
* Id there were already such a number in @p wantedName, it is incremented until a free filename is found.

0 comments on commit 58882a8

Please sign in to comment.