From 31afa6c691776e3688b1caf3e3327d54d933f15b Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 9 May 2022 15:35:44 +0300 Subject: [PATCH] kdirshare: new KDED module and file properties plugin for directory sharing Signed-off-by: Ivailo Monev --- CMakeLists.txt | 1 + kcontrol/dateandtime/helper.cpp | 3 +- kdirshare/CMakeLists.txt | 2 + kdirshare/filepropertiesplugin/CMakeLists.txt | 25 +++ .../filepropertiesplugin/kdirshareplugin.cpp | 97 ++++++++++ .../kdirshareplugin.desktop | 139 ++++++++++++++ .../filepropertiesplugin/kdirshareplugin.h | 42 ++++ .../filepropertiesplugin/kdirshareplugin.ui | 45 +++++ kdirshare/kded/CMakeLists.txt | 38 ++++ kdirshare/kded/kded_kdirshare.cpp | 105 ++++++++++ kdirshare/kded/kded_kdirshare.h | 45 +++++ kdirshare/kded/kdirshare.desktop | 11 ++ kdirshare/kded/kdirshareimpl.cpp | 180 ++++++++++++++++++ kdirshare/kded/kdirshareimpl.h | 46 +++++ kioslave/network/ioslave/networkslave.cpp | 2 +- 15 files changed, 778 insertions(+), 3 deletions(-) create mode 100644 kdirshare/CMakeLists.txt create mode 100644 kdirshare/filepropertiesplugin/CMakeLists.txt create mode 100644 kdirshare/filepropertiesplugin/kdirshareplugin.cpp create mode 100644 kdirshare/filepropertiesplugin/kdirshareplugin.desktop create mode 100644 kdirshare/filepropertiesplugin/kdirshareplugin.h create mode 100644 kdirshare/filepropertiesplugin/kdirshareplugin.ui create mode 100644 kdirshare/kded/CMakeLists.txt create mode 100644 kdirshare/kded/kded_kdirshare.cpp create mode 100644 kdirshare/kded/kded_kdirshare.h create mode 100644 kdirshare/kded/kdirshare.desktop create mode 100644 kdirshare/kded/kdirshareimpl.cpp create mode 100644 kdirshare/kded/kdirshareimpl.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a71c5ed..d22e7b5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -362,6 +362,7 @@ add_subdirectory(kmimetypefinder) # UI Helper applications add_subdirectory(drkonqi) add_subdirectory(knetattach) +add_subdirectory(kdirshare) add_subdirectory(keditfiletype) # Default settings, content and config add_subdirectory(l10n) diff --git a/kcontrol/dateandtime/helper.cpp b/kcontrol/dateandtime/helper.cpp index 153d3e23..0e9be3f7 100644 --- a/kcontrol/dateandtime/helper.cpp +++ b/kcontrol/dateandtime/helper.cpp @@ -92,10 +92,9 @@ ClockHelper::CH_Error ClockHelper::ntp( const QStringList& ntpServers, bool ntpE ClockHelper::CH_Error ClockHelper::date( const QString& newdate, const QString& olddate ) { struct timeval tv; - tv.tv_sec = newdate.toULong() - olddate.toULong() + time(0); tv.tv_usec = 0; - if (settimeofday(&tv, 0)) { + if (::settimeofday(&tv, 0)) { return DateError; } diff --git a/kdirshare/CMakeLists.txt b/kdirshare/CMakeLists.txt new file mode 100644 index 00000000..ee1b6664 --- /dev/null +++ b/kdirshare/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(filepropertiesplugin) +add_subdirectory(kded) diff --git a/kdirshare/filepropertiesplugin/CMakeLists.txt b/kdirshare/filepropertiesplugin/CMakeLists.txt new file mode 100644 index 00000000..704c6a40 --- /dev/null +++ b/kdirshare/filepropertiesplugin/CMakeLists.txt @@ -0,0 +1,25 @@ +########### next target ############### + +set(kdirshareplugin_PART_SRCS + kdirshareplugin.cpp + kdirshareplugin.ui +) + +kde4_add_plugin(kdirshareplugin ${kdirshareplugin_PART_SRCS}) +target_link_libraries(kdirshareplugin + ${KDE4_KIO_LIBS} + ${KDE4_KIO_LIBS} + ${QT_QTDBUS_LIBRARY} +) + +install( + TARGETS kdirshareplugin + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} +) + +########### install files ############### + +install( + FILES kdirshareplugin.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} +) diff --git a/kdirshare/filepropertiesplugin/kdirshareplugin.cpp b/kdirshare/filepropertiesplugin/kdirshareplugin.cpp new file mode 100644 index 00000000..37750dc9 --- /dev/null +++ b/kdirshare/filepropertiesplugin/kdirshareplugin.cpp @@ -0,0 +1,97 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kdirshareplugin.h" + +K_PLUGIN_FACTORY(KDirSharePluginFactory, registerPlugin();) +K_EXPORT_PLUGIN(KDirSharePluginFactory("kdirshareplugin")) + +KDirSharePlugin::KDirSharePlugin(QObject *parent, const QList &args) + : KPropertiesDialogPlugin(qobject_cast(parent)), + m_kdirshareiface(QString::fromLatin1("org.kde.kded"), QString::fromLatin1("/modules/kdirshare"), QString::fromLatin1("org.kde.kdirshare")) +{ + m_url = properties->kurl().path(KUrl::RemoveTrailingSlash); + if (m_url.isEmpty()) { + return; + } + + QFileInfo pathinfo(m_url); + if (!pathinfo.permission(QFile::ReadUser) || !pathinfo.isDir()) { + return; + } + + KGlobal::locale()->insertCatalog("kdirshareplugin"); + + KVBox *kvbox = new KVBox(); + properties->addPage(kvbox, i18n("&Share")); + properties->setFileSharingPage(kvbox); + + QWidget *uiwidget = new QWidget(kvbox); + m_ui.setupUi(uiwidget); + + if (m_kdirshareiface.isValid()) { + QDBusReply kdirsharereply = m_kdirshareiface.call("isShared", m_url); + if (!kdirsharereply.isValid()) { + kWarning() << "Invalid kdirshare module reply"; + m_ui.sharebox->setChecked(false); + } else { + m_ui.sharebox->setChecked(kdirsharereply.value()); + } + } else { + kWarning() << "kdirshare module interface is not valid"; + m_ui.sharebox->setEnabled(false); + } + + connect(m_ui.sharebox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); +} + +KDirSharePlugin::~KDirSharePlugin() +{ +} + +void KDirSharePlugin::applyChanges() +{ + // qDebug() << Q_FUNC_INFO << m_ui.sharebox->isEnabled() << m_ui.sharebox->isChecked(); + if (m_ui.sharebox->isEnabled()) { + QDBusReply kdirsharereply; + if (m_ui.sharebox->isChecked()) { + kdirsharereply = m_kdirshareiface.call("share", m_url); + } else { + kdirsharereply = m_kdirshareiface.call("unshare", m_url); + } + if (!kdirsharereply.isValid()) { + KMessageBox::error(nullptr, i18n("Invalid kdirshare module reply")); + } else { + const QString kdirshareerror = kdirsharereply.value(); + if (!kdirshareerror.isEmpty()) { + KMessageBox::error(nullptr, kdirshareerror); + } + } + } +} + +#include "moc_kdirshareplugin.cpp" diff --git a/kdirshare/filepropertiesplugin/kdirshareplugin.desktop b/kdirshare/filepropertiesplugin/kdirshareplugin.desktop new file mode 100644 index 00000000..8c773e98 --- /dev/null +++ b/kdirshare/filepropertiesplugin/kdirshareplugin.desktop @@ -0,0 +1,139 @@ +[Desktop Entry] +Type=Service +Icon=preferences-system-network-sharing +Name=Fileshare Konqueror Directory Properties Page +Name[ar]=صفحة دليل خصائص مشاركة ملفات كونكيورر +Name[ast]=Páxina de propiedaes del direutoriu pa compartir ficheros de Konqueror +Name[bg]=Настройки за приставката за браузъра за споделяна на файлове +Name[bn]=ফাইল ভাগাভাগি কনকরার ডিরেক্টরী বৈশিষ্ট্যাবলী পাতা +Name[bs]=Stranica Konqueror sa svojstvima direktorija za dijeljenje datoteka +Name[ca]=Pàgina de propietats del directori de compartició de fitxers del Konqueror +Name[ca@valencia]=Pàgina de propietats del directori de compartició de fitxers del Konqueror +Name[cs]=Stránka vlastností adresáře sdílení Konqueroru +Name[da]=Fileshare Konqueror-mappens side med egenskaber +Name[de]=Ordnerfreigabe-Eigenschaftenseite für Konqueror +Name[el]=Σελίδα ιδιοτήτων κοινόχρηστου καταλόγου του Konqueror +Name[en_GB]=Fileshare Konqueror Directory Properties Page +Name[eo]=Paĝo de ecoj de la komunaj dosierujoj de Konkeranto +Name[es]=Página de propiedades del directorio para compartir archivos de Konqueror +Name[et]=Failijagamise Konquerori kataloogi omaduste lehekülg +Name[eu]=Fitxategiak partekatzeko Konqueror-en direktorioaren propietateen orria +Name[fa]=صفحه ویژگیهای فهرست راهنمای اشتراک پرونده Konqueror +Name[fi]=Konquerorin tiedostojakojen ominaisuussivu +Name[fr]=Page des propriétés d'un dossier de partage de Konqueror +Name[ga]=Leathanach Airíonna Konqueror: Comhroinnt Comhadlainne +Name[gl]=Páxina coas propiedades do directorio de ficheiros compartidos de Konqueror +Name[he]=דף מאפייני ספרית קבצים משותפת של Konqueror +Name[hi]=फ़ाइलशेयर कॉन्करर डिरेक्ट्रीज़ गुण पृष्ठ +Name[hne]=फाइलसेयर कान्करर डिरेक्टरीज गुन पेज +Name[hr]=Stranica sa postavkama svojstava Konqueror Directoryja za dijeljenje datoteka +Name[hu]=Fájlmegosztási lap a Konqueror könyvtártulajdonságainál +Name[ia]=Pagina de proprietates de directorio de Konqueror pro compartir de file +Name[is]=Skráastjóraeiginleikar Konqueror +Name[it]=Pagina delle proprietà di Konqueror per la condivisione +Name[ja]=Konqueror でファイル共有するディレクトリのプロパティのページ +Name[kk]=Konqueror файлдарын ортақтастыру каталогының қасиеттер беті +Name[km]=ទំព័រ​លក្ខណៈ​សម្បត្តិ​ថត Konqueror សម្រាប់​ការ​ចែក​រំលែក +Name[ko]=Konqueror 디렉터리 속성 페이지의 파일 공유 탭 +Name[lt]=Failų dalinimosi Konqueror aplanko nustatymų puslapis +Name[lv]=Konqueror mapes koplietošanas īpašību lapa +Name[mk]=Страница со параметри за делен именик во Konqueror +Name[ml]=ഫയല്‍ഷെയര്‍ കോണ്‍ക്വറര്‍ തട്ടിന്റെ ഗുണവിശേഷങ്ങളുടെ താള്‍ +Name[nb]=Fildeler – Side i Konquerors mappegenskaper +Name[nds]=Konqueror Ornerfreegaav-Egenschappensiet +Name[ne]=फाइल साझेदारी कन्क्वेरर डाइरेक्टरी विशेषता पृष्ठ +Name[nl]=Configuratiepagina Konqueror bestanden delen +Name[nn]=Side for katalogeigenskapar til fildeling i Konqueror +Name[pa]=ਫਾਇਲ ਸਾਂਝ ਕੋਨਕਿਊਰੋਰ ਡਾਇਰੈਕਟਰੀ ਵਿਸ਼ੇਸ਼ਤਾ ਪੇਜ਼ +Name[pl]=Strona współdzielenia we właściwościach katalogu w Konquerorze +Name[pt]=Página de Propriedades da Pasta de Partilha do Konqueror +Name[pt_BR]=Página de propriedades da pasta de compartilhamento de arquivos do Konqueror +Name[ru]=Общий доступ к файлам — свойства каталога в Konqueror +Name[si]=ගොනු හුවමාරු Konqueror නාමාවලි වත්කම් පිටුව +Name[sk]=Zdieľanie adresárov pre Konqueror +Name[sl]=Stran z lastnostmi za souporabo mape +Name[sr]=Страница К‑освајача са својствима фасцикле за дељење фајлова +Name[sr@ijekavian]=Страница К‑освајача са својствима фасцикле за дијељење фајлова +Name[sr@ijekavianlatin]=Stranica K‑osvajača sa svojstvima fascikle za dijeljenje fajlova +Name[sr@latin]=Stranica K‑osvajača sa svojstvima fascikle za deljenje fajlova +Name[sv]=Konquerors fildelningssida med katalogegenskaper +Name[ta]=Fileshare Konqueror அடைவு பண்புகளின் பக்கம் +Name[tg]=Саҳифаи Феҳристи Хусусиятҳо оиди Konqueror Истифодабарии Муштараки Файлҳо +Name[tr]=Dosya Paylaşımı Konqueror Dizin Özellikleri Sayfası +Name[ug]=Fileshare Konqueror مۇندەرىجە خاسلىق بېتى +Name[uk]=Сторінка властивостей каталогу для спільного доступу +Name[vi]=Trang thuộc tính của chia sẻ thư mục Konqueror +Name[x-test]=xxFileshare Konqueror Directory Properties Pagexx +Name[zh_CN]=Konqueror 文件共享目录属性页 +Name[zh_HK]=檔案分享 Konqueror 目錄屬性頁 +Name[zh_TW]=Konqueror 檔案分享目錄屬性頁 +Comment=Konqueror properties dialog plugin to share a directory with the local network +Comment[ar]=خصائص حوار إضافة كونكيورر لمشاركة مسار مع الشبكة المحلية +Comment[ast]=Complementu de diálogu de propiedaes de Konqueror pa compartir un direutoriu cola rede llocal +Comment[bg]=Настройка на приставката за браузъра Konqueror за споделяна на директории в локалната мрежа +Comment[bn]=স্থানীয় নেটওয়ার্কের সঙ্গে একটি ডিরেক্টরী ভাগাভাগি করতে কনকরার বৈশিষ্ট্যাবলী ডায়ালগ প্লাগিন +Comment[bs]=Priključak dijaloga Konqueror-a za svojstva dijeljenja direktorija u lokalnoj mreži +Comment[ca]=Diàleg de propietats del connector del Konqueror per compartir un directori amb la xarxa local +Comment[ca@valencia]=Diàleg de propietats del connector del Konqueror per compartir un directori amb la xarxa local +Comment[cs]=Modul dialogu vlastností Konqueroru pro sdílení adresářů v lokální síti +Comment[da]=Konqueror egenskaber-dialog plugin til at dele en mappe med det lokale netværk +Comment[de]=Modul für den Konqueror-Eigenschaftendialog zur Freigabe eines Ordners im Netzwerk +Comment[el]=Πρόσθετος διάλογος ρυθμίσεων του Konqueror για την κοινή χρήση ενός καταλόγου με το τοπικό δίκτυο +Comment[en_GB]=Konqueror properties dialogue plugin to share a directory with the local network +Comment[eo]=Kromaĵo de Konkeranto por komunigi dosierujon sur la loka reto +Comment[es]=Complemento de diálogo de propiedades de Konqueror para compartir un directorio con la red local +Comment[et]=Konquerori omaduste dialoogi plugin kataloogi jagamiseks kohtvõrgus +Comment[eu]=Konqueror-en propietateen elkarrizketa-koadroaren plugina direktorio bat sare lokalean partekatzeko +Comment[fa]=ویژگیهای وصله محاوره Konqueror برای اشتراک فهرست راهنما با شبکه محلی +Comment[fi]=Konquerorin liitännäinen, jolla voi jakaa kansioita lähiverkossa +Comment[fr]=Module externe proposant une boîte de dialogue de propriétés pour Konqueror pour partager un dossier sur le réseau local +Comment[ga]=Breiseán dialóige airíonna Konqueror lenar féidir comhadlann a chomhroinnt leis an líonra logánta +Comment[gl]=Diálogo de propiedades do engadido de Konqueror para compartir un directorio pola rede local +Comment[he]=תוסף מאפייני דו-שיח של Konqueror כדי לשתף סיפריה עם רשת מקומית +Comment[hi]=स्थानीय नेटवर्क के साथ डिरेक्ट्री साझा करने के लिए कॉन्करर गुण संवाद प्लगइन +Comment[hne]=लोकल नेटवर्क के साथ डिरेक्टरी साझा करे बर कान्करर गुन गोठ प्लगइन +Comment[hr]=Dijalogni priključak postavki za Konqueror za dijeljenje direktorija na lokalnoj mreži +Comment[hu]=Konqueror párbeszédablak könyvtár megosztásához a helyi hálózaton +Comment[ia]=Plug-in de dialogo de proprietate de Konqueror pro compartir un directorio con le rete local +Comment[is]=Konqueror properties dialog plugin to share a directory with the local network +Comment[it]=Estensione delle proprietà di Konqueror per condividere una cartella con la rete locale +Comment[ja]=ローカルネットワークでディレクトリを共有する Konqueror プロパティダイアログのプラグイン +Comment[kk]=Каталогты жергілікті желімен ортақтастыратын Konqueror қасиеттер диалогының плагині +Comment[km]=ប្រអប់​លក្ខណៈ​សម្បត្តិ Konqueror ដើម្បី​ចែក​រំលែក​ថត​នៅ​ក្នុង​បណ្ដាញ​មូលដ្ឋាន +Comment[ko]=로컬 네트워크에서 파일을 공유하기 위한 Konqueror 속성 대화 상자 플러그인 +Comment[lt]=Konqueror nustatymų dialogo įskiepis, skirtas dalintis aplanku vietiniame tinkle +Comment[lv]=Konqueror īpašību dialoga spraudnis mapes publicēšanai koplietošanai lokālajā tīklā +Comment[mk]=Приклучок со дијалог за својства во Konqueror за делење на датотеки со локалната мрежа +Comment[ml]=കോണ്‍ക്വററിലെ പ്രാദേശിക ശൃഖലയുമായി തട്ടു് പങ്കുവെക്കാനുള്ള സംയോജകത്തിന്റെ ഗുണവിശേഷങ്ങളുടെ സംവാദജാലകം +Comment[nb]=Programtillegg for Konquerors egenskapsdialog for å dele en mappe på lokalnettet +Comment[nds]=Moduul för en Konqueror-Egenschappendialoog för't Freegeven vun Ornern in't lokale Nettwark +Comment[ne]=स्थानीय सञ्जालसँग डाइरेक्टरी साझेदार गर्न कन्क्वेरर विशेषता संवाद प्लगइन +Comment[nl]=Konqueror-plugin met instellingen om bestanden te delen via het lokale netwerk +Comment[nn]=Konqueror-vising av eigenskapar til ein delt katalog i det lokale nettverket +Comment[pa]=ਕੋਨਕਿਉਰੋਰ ਵਿਸ਼ੇਸ਼ਤਾ ਡਾਈਲਾਗ ਪਲੱਗਇਨ ਜੋ ਲੋਕਲ ਨੈੱਟਵਰਕ ਨਾਲ ਡਾਇਰੈਕਟਰੀ ਸਾਂਝੀ ਕਰਦੀ ਹੈ +Comment[pl]=Wtyczka właściwości dla Konquerora umożliwiająca współdzielenie katalogu w sieci lokalnej +Comment[pt]='Plugin' de janela de propriedades do Konqueror para partilhar uma pasta na rede local +Comment[pt_BR]=Plugin de diálogo de propriedades do Konqueror para o compartilhamento de uma pasta em uma rede local +Comment[ro]=Modul pentru dialogul de proprietăți Konqueror pentru a partaja un director cu rețeaua locală +Comment[ru]=Модуль свойств Konqueror для организации общего доступа к каталогу по локальной сети +Comment[si]=ප්‍රාදේශීය ජාලයක් තුල බහලුමක් හුවමාරු කිරීම සඳහා Konqueror වත්කම් සංවාද ප්ලගිනය +Comment[sk]=Modul Konquerora pre zdieľanie adresára v lokálnej sieti +Comment[sl]=Vstavek za Konqueror s pogovornim oknom za lastnosti za souporabo mape v krajevnem omrežju +Comment[sr]=Прикључак дијалога К‑освајача за својства дељења фасцикли у локалној мрежи +Comment[sr@ijekavian]=Прикључак дијалога К‑освајача за својства дијељења фасцикли у локалној мрежи +Comment[sr@ijekavianlatin]=Priključak dijaloga K‑osvajača za svojstva dijeljenja fascikli u lokalnoj mreži +Comment[sr@latin]=Priključak dijaloga K‑osvajača za svojstva deljenja fascikli u lokalnoj mreži +Comment[sv]=Konqueror-insticksprogram med egenskapsdialogruta för att dela en katalog i det lokala nätverket +Comment[ta]=Konqueror பண்புகளின் உரையாடல் செருகுகள் அடைவை சம்பா சேவையகத்துடன் பகிரவேண்டிய செருகுகள் +Comment[tg]=Модули муколамаи хусусиятҳои Konqueror барои истифодабарии муштараки феҳрист бо шабакаи маҳалллӣ +Comment[tr]=Yerel ağ ile dizin paylaşımı için Konqueror iletişim eklentisi özellikleri +Comment[ug]=بۇKonqueror خاسلىق سۆزلەشكۈ قىستۇرمىسى بىلەن يەرلىك تور مۇندەرىجىنى ھەمبەھىرلەيدۇ +Comment[uk]=Додаток діалогового вікна властивостей Konqueror для уможливлення спільного доступу до каталогу з локальної мережі +Comment[vi]=Phần bổ sung hộp thoại thuộc tính Konqueror dùng để chia sẻ một thư mục trên mạng nội bộ +Comment[x-test]=xxKonqueror properties dialog plugin to share a directory with the local networkxx +Comment[zh_CN]=可将目录与局域网共享的 Konqueror 属性页对话框插件 +Comment[zh_HK]=用於與本地網絡分享目錄的 Konqueror 屬性對話盒插件 +Comment[zh_TW]=Konqueror 屬性對話框外掛程式,用於在本地端網路上分享目錄 +X-KDE-Library=kdirshareplugin +X-KDE-Protocol=file +X-KDE-ServiceTypes=KPropertiesDialog/Plugin,inode/directory diff --git a/kdirshare/filepropertiesplugin/kdirshareplugin.h b/kdirshare/filepropertiesplugin/kdirshareplugin.h new file mode 100644 index 00000000..b51c6f50 --- /dev/null +++ b/kdirshare/filepropertiesplugin/kdirshareplugin.h @@ -0,0 +1,42 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDIRSHAREPLUGIN_H +#define KDIRSHAREPLUGIN_H + +#include +#include + +#include "ui_kdirshareplugin.h" + +class KDirSharePlugin : public KPropertiesDialogPlugin +{ + Q_OBJECT +public: + KDirSharePlugin(QObject *parent, const QList &args); + ~KDirSharePlugin(); + + void applyChanges() final; + +private: + Ui_KDirShareUI m_ui; + QDBusInterface m_kdirshareiface; + QString m_url; +}; + +#endif // KDIRSHAREPLUGIN_H diff --git a/kdirshare/filepropertiesplugin/kdirshareplugin.ui b/kdirshare/filepropertiesplugin/kdirshareplugin.ui new file mode 100644 index 00000000..1d1c0dcb --- /dev/null +++ b/kdirshare/filepropertiesplugin/kdirshareplugin.ui @@ -0,0 +1,45 @@ + + + KDirShareUI + + + + 0 + 0 + 433 + 353 + + + + + + + + + Share with Local Network users + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/kdirshare/kded/CMakeLists.txt b/kdirshare/kded/CMakeLists.txt new file mode 100644 index 00000000..a103e083 --- /dev/null +++ b/kdirshare/kded/CMakeLists.txt @@ -0,0 +1,38 @@ +########### next target ############### + +set(kded_kdirshare_SRCS + kded_kdirshare.cpp + kdirshareimpl.cpp + ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdirshare.xml +) + +qt4_generate_dbus_interface(kded_kdirshare.h org.kde.kdirshare.xml ) + +kde4_add_plugin(kded_kdirshare ${kded_kdirshare_SRCS}) +target_link_libraries(kded_kdirshare PRIVATE + ${KDE4_KDECORE_LIBS} + ${KDE4_KDEUI_LIBS} + ${KDE4_KHTTP_LIBS} + ${KDE4_KDNSSD_LIBS} +) + +if(OPENSSL_FOUND) + target_link_libraries(kded_kdirshare PRIVATE ${OPENSSL_LIBRARIES}) +endif() + +install( + TARGETS kded_kdirshare + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} +) + +install( + FILES kdirshare.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR}/kded +) + +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdirshare.xml + DESTINATION ${KDE4_DBUS_INTERFACES_INSTALL_DIR} +) + + diff --git a/kdirshare/kded/kded_kdirshare.cpp b/kdirshare/kded/kded_kdirshare.cpp new file mode 100644 index 00000000..7f5c513c --- /dev/null +++ b/kdirshare/kded/kded_kdirshare.cpp @@ -0,0 +1,105 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kded_kdirshare.h" + +#include +#include +#include +#include + +static quint16 getRandomPort() +{ + quint16 portnumber = 0; + while (portnumber < 1000 || portnumber > 30000) { + portnumber = quint16(qrand()); + } + return portnumber; +} + +K_PLUGIN_FACTORY(KDirShareModuleFactory, registerPlugin();) +K_EXPORT_PLUGIN(KDirShareModuleFactory("kdirshare")) + +KDirShareModule::KDirShareModule(QObject *parent, const QList&) + : KDEDModule(parent) +{ + KSettings kdirsharesettings("kdirsharerc", KSettings::SimpleConfig); + foreach (const QString &kdirsharekey, kdirsharesettings.keys()) { + const QString kdirsharedir = kdirsharesettings.value(kdirsharekey).toString(); + const QString kdirshareerror = share(kdirsharedir); + if (!kdirshareerror.isEmpty()) { + kWarning() << kdirshareerror; + } + } +} + +KDirShareModule::~KDirShareModule() +{ + KSettings kdirsharesettings("kdirsharerc", KSettings::SimpleConfig); + foreach (const KDirShareImpl *kdirshareimpl, m_dirshares) { + const QByteArray kdirsharekey = kdirshareimpl->directory().toLocal8Bit().toHex(); + kdirsharesettings.setValue(kdirsharekey, kdirshareimpl->directory()); + } + qDeleteAll(m_dirshares); +} + +QString KDirShareModule::share(const QString &dirpath) +{ + KDirShareImpl *kdirshareimpl = new KDirShareImpl(this); + if (!kdirshareimpl->setDirectory(dirpath)) { + kdirshareimpl->deleteLater(); + return i18n("Directory does not exist: %1", dirpath); + } + const quint16 randomport = getRandomPort(); + // qDebug() << Q_FUNC_INFO << randomport; + if (!kdirshareimpl->serve(QHostAddress(QHostAddress::Any), randomport)) { + kdirshareimpl->deleteLater(); + return i18n("Could not serve: %1", kdirshareimpl->errorString()); + } + if (!kdirshareimpl->publishService()) { + kdirshareimpl->deleteLater(); + return i18n("Could not publish service for: %1", dirpath); + } + m_dirshares.append(kdirshareimpl); + return QString(); +} + +QString KDirShareModule::unshare(const QString &dirpath) +{ + foreach (KDirShareImpl *kdirshareimpl, m_dirshares) { + if (kdirshareimpl->directory() == dirpath) { + kdirshareimpl->stop(); + kdirshareimpl->deleteLater(); + m_dirshares.removeAll(kdirshareimpl); + return QString(); + } + } + return i18n("Invalid directory share: %1", dirpath); +} + +bool KDirShareModule::isShared(const QString &dirpath) const +{ + foreach (const KDirShareImpl *kdirshareimpl, m_dirshares) { + if (kdirshareimpl->directory() == dirpath) { + return true; + } + } + return false; +} + +#include "moc_kded_kdirshare.cpp" diff --git a/kdirshare/kded/kded_kdirshare.h b/kdirshare/kded/kded_kdirshare.h new file mode 100644 index 00000000..f46b8453 --- /dev/null +++ b/kdirshare/kded/kded_kdirshare.h @@ -0,0 +1,45 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDIRSHARE_KDED_H +#define KDIRSHARE_KDED_H + +#include +#include +#include "kdirshareimpl.h" + +class KDirShareModule: public KDEDModule +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.kdirshare") + +public: + KDirShareModule(QObject *parent, const QList&); + ~KDirShareModule(); + +public Q_SLOTS: + Q_SCRIPTABLE QString share(const QString &dirpath); + Q_SCRIPTABLE QString unshare(const QString &dirpath); + + Q_SCRIPTABLE bool isShared(const QString &dirpath) const; + +private: + QList m_dirshares; +}; + +#endif // KDIRSHARE_KDED_H diff --git a/kdirshare/kded/kdirshare.desktop b/kdirshare/kded/kdirshare.desktop new file mode 100644 index 00000000..a807b73a --- /dev/null +++ b/kdirshare/kded/kdirshare.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Icon=network-server +Name=Directory share +Comment=Directory share service +Type=Service +X-KDE-ServiceTypes=KDEDModule +X-KDE-Library=kdirshare +X-KDE-DBus-ModuleName=kdirshare +X-KDE-Kded-autoload=true +X-KDE-Kded-load-on-demand=true +OnlyShowIn=KDE; diff --git a/kdirshare/kded/kdirshareimpl.cpp b/kdirshare/kded/kdirshareimpl.cpp new file mode 100644 index 00000000..bde50aac --- /dev/null +++ b/kdirshare/kded/kdirshareimpl.cpp @@ -0,0 +1,180 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kdirshareimpl.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +static QByteArray contentForDirectory(const QString &path, const QString &basedir) +{ + QByteArray data; + data.append(""); + data.append(""); + data.append(" "); + data.append(" "); // icon + data.append(" "); + data.append(" "); + data.append(" "); + data.append(" "); + QDir::Filters dirfilters = (QDir::Files | QDir::AllDirs | QDir::NoDot); + if (QDir::cleanPath(path) == QDir::cleanPath(basedir)) { + dirfilters = (QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot); + } + const QDir::SortFlags dirsortflags = (QDir::Name | QDir::DirsFirst); + QDir dir(path); + foreach (const QFileInfo &fileinfo, dir.entryInfoList(dirfilters, dirsortflags)) { + const QString fullpath = path.toLocal8Bit() + QLatin1Char('/') + fileinfo.fileName(); + // chromium does weird stuff if the link starts with two slashes - removes, the host and + // port part of the link (or rather does not prepend them) and converts the first directory + // to lower-case + const QString cleanpath = QDir::cleanPath(fullpath.mid(basedir.size())); + + data.append(" "); + + const bool isdotdot = (fileinfo.fileName() == QLatin1String("..")); + if (isdotdot) { + const QString fileicon = QString::fromLatin1(""); + data.append(""); + } else { + const QString fileicon = QString::fromLatin1("").arg(KMimeType::iconNameForUrl(KUrl(fullpath))); + data.append(""); + } + + // qDebug() << Q_FUNC_INFO << fullpath << basedir << cleanpath; + data.append(""); + + data.append(""); + + data.append(""); + + data.append(" "); + } + data.append("
FilenameMIMESize
"); + data.append(fileicon.toAscii()); + data.append(""); + data.append(fileicon.toAscii()); + data.append(""); + data.append(fileinfo.fileName().toLocal8Bit()); + data.append("
"); + if (!isdotdot) { + const QString filemime = KMimeType::findByPath(fullpath)->name(); + data.append(filemime.toAscii()); + } + data.append(""); + if (fileinfo.isFile()) { + const QString filesize = KGlobal::locale()->formatByteSize(fileinfo.size(), 1); + data.append(filesize.toAscii()); + } + data.append("
"); + data.append(""); + return data; +} + +KDirShareImpl::KDirShareImpl(QObject *parent) + : KHTTP(parent), + m_directory(QDir::currentPath()), + m_port(0) +{ +} + +KDirShareImpl::~KDirShareImpl() +{ + m_kdnssd.unpublishService(); + stop(); +} + +QString KDirShareImpl::directory() const +{ + return m_directory; +} + +bool KDirShareImpl::setDirectory(const QString &dirpath) +{ + if (!QDir(dirpath).exists()) { + return false; + } + m_directory = dirpath; + return true; +} + +bool KDirShareImpl::serve(const QHostAddress &address, const quint16 port) +{ + m_port = port; + return start(address, port); +} + +bool KDirShareImpl::publishService() +{ + return m_kdnssd.publishService( + "_http._tcp", m_port, + i18n("KDirShare@%1 (%2)", QHostInfo::localHostName(), QFileInfo(m_directory).baseName()) + ); +} + +void KDirShareImpl::respond(const QByteArray &url, QByteArray *outdata, ushort *outhttpstatus, KHTTPHeaders *outheaders) +{ + // qDebug() << Q_FUNC_INFO << url; + + outheaders->insert("Server", "KDirShare"); + + const QString normalizedpath = QUrl::fromPercentEncoding(url); + QFileInfo pathinfo(m_directory + QLatin1Char('/') + normalizedpath); + // qDebug() << Q_FUNC_INFO << normalizedpath << pathinfo.filePath(); + if (normalizedpath.startsWith(QLatin1String("/kdirshare_icons/"))) { + const QPixmap iconpixmap = KIcon(normalizedpath.mid(17)).pixmap(20); + QBuffer iconbuffer; + iconbuffer.open(QBuffer::ReadWrite); + if (!iconpixmap.save(&iconbuffer, "PNG")) { + kWarning() << "could not save image"; + } + + const QByteArray data = iconbuffer.data(); + outdata->append(data); + *outhttpstatus = 200; + outheaders->insert("Content-Type", "image/png"); + } else if (pathinfo.isDir()) { + *outhttpstatus = 200; + outheaders->insert("Content-Type", "text/html; charset=UTF-8"); + const QByteArray data = contentForDirectory(pathinfo.filePath(), m_directory); + outdata->append(data); + } else if (pathinfo.isFile()) { + QFile datafile(pathinfo.filePath()); + datafile.open(QFile::ReadOnly); + const QString filemime = KMimeType::findByPath(pathinfo.filePath())->name(); + const QByteArray data = datafile.readAll(); + + *outhttpstatus = 200; + outheaders->insert("Content-Type", QString::fromLatin1("%1; charset=UTF-8").arg(filemime).toAscii()); + outdata->append(data); + } else { + const QByteArray data("404 Not Found"); + + outdata->append(data); + *outhttpstatus = 404; + outheaders->insert("Content-Type", "text/html; charset=UTF-8"); + } +} diff --git a/kdirshare/kded/kdirshareimpl.h b/kdirshare/kded/kdirshareimpl.h new file mode 100644 index 00000000..19f15f3a --- /dev/null +++ b/kdirshare/kded/kdirshareimpl.h @@ -0,0 +1,46 @@ +/* This file is part of the KDE project + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDIRSHAREIMPL_H +#define KDIRSHAREIMPL_H + +#include +#include + +class KDirShareImpl : public KHTTP +{ + Q_OBJECT +public: + KDirShareImpl(QObject *parent = nullptr); + ~KDirShareImpl(); + + QString directory() const; + bool setDirectory(const QString &dirpath); + bool serve(const QHostAddress &address, const quint16 port); + bool publishService(); + +protected: + void respond(const QByteArray &url, QByteArray *outdata, ushort *outhttpstatus, KHTTPHeaders *outheaders) final; + +private: + QString m_directory; + quint16 m_port; + KDNSSD m_kdnssd; +}; + +#endif // KDIRSHAREIMPL_H diff --git a/kioslave/network/ioslave/networkslave.cpp b/kioslave/network/ioslave/networkslave.cpp index cbabd1be..ac0c6fd5 100644 --- a/kioslave/network/ioslave/networkslave.cpp +++ b/kioslave/network/ioslave/networkslave.cpp @@ -29,7 +29,7 @@ static QString urlForService(const KDNSSDService &kdnssdservice) { - // for compatibility since there is no KIO slave to open rfb protocols + // for compatibility and because there is no KIO slave to open rfb protocol if (kdnssdservice.url.startsWith(QLatin1String("rfb://"))) { QString result = kdnssdservice.url; result = result.replace(QLatin1String("rfb://"), QLatin1String("vnc://"));