diff --git a/README.md b/README.md index dc5e1d6..f5150e6 100644 --- a/README.md +++ b/README.md @@ -13,17 +13,14 @@ More features, such as sharing, etc. are planned. ### Limitations/Workaround Due to the way those dolphin plugins work, only repositories that are inside your seafile main directory will work. Additionally, you will have to open this folder once, before the plugin recognizes them. -The reason is, that the plugin reacts on the presence of the `.seafile-data` folder. If you have custom locations outside of the folder, or don't want to always go there first, simply create an empty file called `.seafile-data` in whichever directory you need the plugin to work. +The reason is, that the plugin reacts on the presence of the `.seafile-data` folder. If you have custom locations outside of the folder, or don't want to always go there first, simply create an empty file called `.seafile-data` in whichever directory you need the plugin to work. One useful location would be your home directory, as thats the default directory dolphin opens. -I'll try to work around that issue in future versions. - ## Dependencies -You'll need Dolphin (and thus Qt and KDE frameworks) and Seafile. The plugin only needs the seafile daemon, so make shure you have that one with whatever seafile package you use. Also, ccnet is required, but as it's a depedency of seafile, should always be present. +You'll need Dolphin (and thus Qt and KDE frameworks) and Seafile. The plugin only needs the seafile daemon, so make shure you have that one with whatever seafile package you use. ## Installation -For now, only an AUR package is provided: [`dolphin-seafile-plugin`](https://aur.archlinux.org/packages/dolphin-seafile-plugin) -Debian packages and others I will provide as soon as possible. +For now, only an AUR package is provided: [`dolphin-seafile-plugin`](https://aur.archlinux.org/packages/dolphin-seafile-plugin) Until then, you can simply build it yourself. Install all the stated dependencies and build via: ``` @@ -31,4 +28,4 @@ cd plugin qmake make make install -``` \ No newline at end of file +``` diff --git a/TestLoader/TestLoader.pro b/TestLoader/TestLoader.pro deleted file mode 100644 index 319c176..0000000 --- a/TestLoader/TestLoader.pro +++ /dev/null @@ -1,23 +0,0 @@ -QT += core -QT -= gui - -CONFIG += c++11 - -TARGET = TestLoader -CONFIG += console -CONFIG -= app_bundle - -TEMPLATE = app - -SOURCES += main.cpp - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which as been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 diff --git a/TestLoader/main.cpp b/TestLoader/main.cpp deleted file mode 100644 index b7c2067..0000000 --- a/TestLoader/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QPluginLoader loader("/home/sky/Programming/QtProjects/build-dolphin-seafile-plugin-System_Qt_5_9_1_Arch-Debug/plugin/libfileviewseafileplugin.so"); - qDebug() << loader.metaData(); - qDebug() << loader.load(); - qDebug() << loader.errorString(); - - return 0; -} diff --git a/dolphin-seafile-plugin.pro b/dolphin-seafile-plugin.pro index 00408f0..0408784 100644 --- a/dolphin-seafile-plugin.pro +++ b/dolphin-seafile-plugin.pro @@ -1,5 +1,7 @@ TEMPLATE = subdirs SUBDIRS += plugin \ - TestLoader \ seafile-test + +OTHER_FILES += \ + README.md diff --git a/plugin/fileviewseafileplugin.cpp b/plugin/fileviewseafileplugin.cpp index 57b14d8..f9b9caf 100644 --- a/plugin/fileviewseafileplugin.cpp +++ b/plugin/fileviewseafileplugin.cpp @@ -16,12 +16,11 @@ FileViewSeafilePlugin::FileViewSeafilePlugin(QObject *parent, const QVariantList QString FileViewSeafilePlugin::fileName() const { - return QStringLiteral(".seafile-data");//TODO works, but not for repos outside of the "seafile dir" + return QStringLiteral(".seafile-data"); } bool FileViewSeafilePlugin::beginRetrieval(const QString &directory) { - Q_UNUSED(directory) try { _seaf->engage(); _seaf->reloadRepos(); diff --git a/plugin/plugin.pro b/plugin/plugin.pro index 439570c..7484722 100644 --- a/plugin/plugin.pro +++ b/plugin/plugin.pro @@ -1,28 +1,27 @@ TEMPLATE = lib -QT += core gui widgets KIOCore +QT = core gui widgets KIOCore CONFIG += plugin warning_clean exceptions link_pkgconfig # add seafile, ccnet -PKGCONFIG += libseafile libccnet +PKGCONFIG += libseafile #dolphin LIBS += -ldolphinvcs INCLUDEPATH += /usr/include/Dolphin/ - TARGET = fileviewseafileplugin -VERSION = 1.0.0 +VERSION = 1.1.0 DEFINES += QT_DEPRECATED_WARNINGS QT_ASCII_CAST_WARNINGS HEADERS += \ - fileviewseafileplugin.h \ + fileviewseafileplugin.h \ seafstatus.h SOURCES += \ - fileviewseafileplugin.cpp \ + fileviewseafileplugin.cpp \ seafstatus.cpp DISTFILES += \ diff --git a/plugin/seafstatus.cpp b/plugin/seafstatus.cpp index 816edbe..cf09a7b 100644 --- a/plugin/seafstatus.cpp +++ b/plugin/seafstatus.cpp @@ -59,11 +59,16 @@ void SeafStatus::reloadRepos() g_list_free(res); } -bool SeafStatus::hasRepo(const QString &path) +bool SeafStatus::hasRepo(const QString &path) const { return _repoIds.contains(repoPath(path)); } +QStringList SeafStatus::allRepost() const +{ + return _repoIds.keys(); +} + SeafStatus::SyncStatus SeafStatus::syncStatus(const QString &path) { ensureConnected(); @@ -147,7 +152,7 @@ void SeafStatus::freeConnection() } } -QString SeafStatus::repoPath(const QString &path) +QString SeafStatus::repoPath(const QString &path) const { QFileInfo info(path); auto fullPath = QDir::cleanPath(info.absoluteFilePath()); @@ -161,7 +166,7 @@ QString SeafStatus::repoPath(const QString &path) return QString(); } -SeafStatus::SyncStatus SeafStatus::mapFileStatus(const QByteArray &text) +SeafStatus::SyncStatus SeafStatus::mapFileStatus(const QByteArray &text) const { static const QHash PathStatus { {"none", None}, @@ -177,7 +182,7 @@ SeafStatus::SyncStatus SeafStatus::mapFileStatus(const QByteArray &text) return PathStatus.value(text, Invalid); } -SeafStatus::SyncStatus SeafStatus::mapRepoStatus(const QByteArray &text) +SeafStatus::SyncStatus SeafStatus::mapRepoStatus(const QByteArray &text) const { static const QHash PathStatus { {"synchronized", Synced}, @@ -195,7 +200,7 @@ SeafStatus::SyncStatus SeafStatus::mapRepoStatus(const QByteArray &text) return PathStatus.value(text, None); } -QString SeafStatus::readSeafileIni() +QString SeafStatus::readSeafileIni() const { #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) auto env = qEnvironmentVariable("SEAFILE_DATA_DIR"); diff --git a/plugin/seafstatus.h b/plugin/seafstatus.h index af00853..75573b1 100644 --- a/plugin/seafstatus.h +++ b/plugin/seafstatus.h @@ -56,7 +56,8 @@ class SeafStatus : public QObject void reloadRepos(); - bool hasRepo(const QString &path); + bool hasRepo(const QString &path) const; + QStringList allRepost() const; SyncStatus syncStatus(const QString &path); private slots: @@ -68,10 +69,10 @@ private slots: QHash _repoIds; QTimer *_conTimer; - QString repoPath(const QString &path); - SyncStatus mapFileStatus(const QByteArray &text); - SyncStatus mapRepoStatus(const QByteArray &text); - QString readSeafileIni(); + QString repoPath(const QString &path) const; + SyncStatus mapFileStatus(const QByteArray &text) const; + SyncStatus mapRepoStatus(const QByteArray &text) const; + QString readSeafileIni() const; }; #endif // SEAFSTATUS_H diff --git a/seafile-test/seafile-test.pro b/seafile-test/seafile-test.pro index 7e87937..b93f6d4 100644 --- a/seafile-test/seafile-test.pro +++ b/seafile-test/seafile-test.pro @@ -1,32 +1,16 @@ -QT += core -QT -= gui +TEMPLATE = app -CONFIG += c++11 +QT = core -TARGET = seafile-test -CONFIG += console +CONFIG += link_pkgconfig console CONFIG -= app_bundle +PKGCONFIG += libseafile -TEMPLATE = app +TARGET = seafile-test + +HEADERS += \ + seafstatus.h SOURCES += \ main.cpp \ seafstatus.cpp - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which as been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -CONFIG += link_pkgconfig -PKGCONFIG += libseafile libccnet - -HEADERS += \ - /usr/include/seafile/seafile-rpc.h \ - seafstatus.h diff --git a/seafile-test/seafstatus.cpp b/seafile-test/seafstatus.cpp deleted file mode 100644 index c840735..0000000 --- a/seafile-test/seafstatus.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "seafstatus.h" -#include -#include -#include -extern "C" { -#include -#include -#include -#include -#include -} - -static QHash path_status = { - {"none", SeafStatus::None}, - {"syncing", SeafStatus::Syncing}, - {"error", SeafStatus::Error}, - {"ignored", SeafStatus::Ignored}, - {"synced", SeafStatus::Synced}, - {"paused", SeafStatus::Paused}, - {"readonly", SeafStatus::Readonly}, - {"locked", SeafStatus::Locked}, - {"locked_by_me", SeafStatus::LockedByMe}, - {NULL, SeafStatus::None}, -}; - -SeafStatus::SeafStatus(QObject *parent) : - QObject(parent) -{ - createClient(); - Q_ASSERT(_client); - loadRepos(); -} - -SeafStatus::~SeafStatus() -{ - if(_client) - searpc_free_client_with_pipe_transport(_client); -} - -SeafStatus::SyncStatus SeafStatus::syncStatus(const QString &path) -{ - QFileInfo info(path); - auto fullPath = QDir::cleanPath(info.absoluteFilePath()); - for(const auto &repo : _repoIds.keys()) { - if(fullPath.startsWith(repo)) { - QDir repoDir(repo); - auto id = _repoIds[repo]; - auto idString = id.toByteArray(); - idString = idString.mid(1, idString.size() - 2); - - GError *error = nullptr; - auto res = searpc_client_call__string(_client, "seafile_get_path_sync_status", &error, 3, - "string", idString.constData(), - "string", repoDir.relativeFilePath(path).toUtf8().constData(), - "int", info.isDir()); - if(error) { - qCritical() << error->message; - g_error_free(error); - return SeafStatus::Invalid; - } else - return path_status[res]; - } - } - - return path_status[NULL]; -} - -bool SeafStatus::createClient() -{ - auto path = QDir{QStandardPaths::writableLocation(QStandardPaths::HomeLocation)}.absoluteFilePath(QStringLiteral("Seafile/.seafile-data/seafile.sock")); - auto pipe_client = searpc_create_named_pipe_client(qUtf8Printable(path)); - int ret = searpc_named_pipe_client_connect(pipe_client); - _client = searpc_client_with_named_pipe_transport(pipe_client, "seafile-rpcserver"); - if (ret < 0) { - searpc_free_client_with_pipe_transport(_client); - _client = nullptr; - return false; - } else - return true; -} - -void SeafStatus::loadRepos() -{ - GError *error = nullptr; - //auto res = searpc_client_call__objlist(client, "seafile_get_repo_list", SEAFILE_TYPE_REPO, &error, 2, "int", 0, "int", 5); - auto res = seafile_get_repo_list(_client, 0, -1, &error); - if(error) { - qCritical() << error->message; - g_error_free(error); - } else { - for (auto l = res; l != nullptr; l = l->next) { - auto repo = SEAFILE_REPO(l->data); - _repoIds.insert(QString::fromUtf8(repo->_worktree), - QUuid(repo->_id)); - } - } - g_list_free(res); -} diff --git a/seafile-test/seafstatus.cpp b/seafile-test/seafstatus.cpp new file mode 120000 index 0000000..67b2bc9 --- /dev/null +++ b/seafile-test/seafstatus.cpp @@ -0,0 +1 @@ +../plugin/seafstatus.cpp \ No newline at end of file diff --git a/seafile-test/seafstatus.h b/seafile-test/seafstatus.h deleted file mode 100644 index 924a631..0000000 --- a/seafile-test/seafstatus.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef SEAFSTATUS_H -#define SEAFSTATUS_H - -#include -#include -#include -extern "C" { -#include -} - -class SeafStatus : public QObject -{ - Q_OBJECT - -public: - enum SyncStatus { - None = 0, - Syncing, - Error, - Ignored, - Synced, - Paused, - Readonly, - Locked, - LockedByMe, - Invalid - }; - Q_ENUM(SyncStatus) - - explicit SeafStatus(QObject *parent = nullptr); - ~SeafStatus(); - - SyncStatus syncStatus(const QString &path); - -private: - SearpcClient *_client = nullptr; - QHash _repoIds; - - bool createClient(); - void loadRepos(); -}; - -#endif // SEAFSTATUS_H diff --git a/seafile-test/seafstatus.h b/seafile-test/seafstatus.h new file mode 120000 index 0000000..2c6e6b3 --- /dev/null +++ b/seafile-test/seafstatus.h @@ -0,0 +1 @@ +../plugin/seafstatus.h \ No newline at end of file