# UI Helper applications
add_subdirectory(drkonqi)
add_subdirectory(knetattach)
+add_subdirectory(kdirshare)
add_subdirectory(keditfiletype)
# Default settings, content and config
add_subdirectory(l10n)
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;
}
--- /dev/null
+add_subdirectory(filepropertiesplugin)
+add_subdirectory(kded)
--- /dev/null
+########### 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}
+)
--- /dev/null
+/* This file is part of the KDE project
+ Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+ 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 <QDBusReply>
+#include <QFileInfo>
+#include <kvbox.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kdebug.h>
+#include <kpluginfactory.h>
+#include <kpluginloader.h>
+
+#include "kdirshareplugin.h"
+
+K_PLUGIN_FACTORY(KDirSharePluginFactory, registerPlugin<KDirSharePlugin>();)
+K_EXPORT_PLUGIN(KDirSharePluginFactory("kdirshareplugin"))
+
+KDirSharePlugin::KDirSharePlugin(QObject *parent, const QList<QVariant> &args)
+ : KPropertiesDialogPlugin(qobject_cast<KPropertiesDialog *>(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<bool> 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<QString> 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"
--- /dev/null
+[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
--- /dev/null
+/* This file is part of the KDE project
+ Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+ 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 <QDBusInterface>
+#include <kpropertiesdialog.h>
+
+#include "ui_kdirshareplugin.h"
+
+class KDirSharePlugin : public KPropertiesDialogPlugin
+{
+ Q_OBJECT
+public:
+ KDirSharePlugin(QObject *parent, const QList<QVariant> &args);
+ ~KDirSharePlugin();
+
+ void applyChanges() final;
+
+private:
+ Ui_KDirShareUI m_ui;
+ QDBusInterface m_kdirshareiface;
+ QString m_url;
+};
+
+#endif // KDIRSHAREPLUGIN_H
--- /dev/null
+<?xml version="1.0" encoding="System"?>
+<ui version="4.0">
+ <class>KDirShareUI</class>
+ <widget class="QWidget" name="KDirShareUI">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>433</width>
+ <height>353</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QCheckBox" name="sharebox">
+ <property name="text">
+ <string>Share with Local Network users</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
--- /dev/null
+########### 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}
+)
+
+
--- /dev/null
+/* This file is part of the KDE project
+ Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+ 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 <klocale.h>
+#include <ksettings.h>
+#include <kdebug.h>
+#include <kpluginfactory.h>
+
+static quint16 getRandomPort()
+{
+ quint16 portnumber = 0;
+ while (portnumber < 1000 || portnumber > 30000) {
+ portnumber = quint16(qrand());
+ }
+ return portnumber;
+}
+
+K_PLUGIN_FACTORY(KDirShareModuleFactory, registerPlugin<KDirShareModule>();)
+K_EXPORT_PLUGIN(KDirShareModuleFactory("kdirshare"))
+
+KDirShareModule::KDirShareModule(QObject *parent, const QList<QVariant>&)
+ : 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"
--- /dev/null
+/* This file is part of the KDE project
+ Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+ 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 <QList>
+#include <kdedmodule.h>
+#include "kdirshareimpl.h"
+
+class KDirShareModule: public KDEDModule
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "org.kde.kdirshare")
+
+public:
+ KDirShareModule(QObject *parent, const QList<QVariant>&);
+ ~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<KDirShareImpl*> m_dirshares;
+};
+
+#endif // KDIRSHARE_KDED_H
--- /dev/null
+[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;
--- /dev/null
+/* This file is part of the KDE project
+ Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+ 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 <QDir>
+#include <QBuffer>
+#include <QPixmap>
+#include <QHostInfo>
+#include <kicon.h>
+#include <klocale.h>
+#include <kmimetype.h>
+#include <kdebug.h>
+
+static QByteArray contentForDirectory(const QString &path, const QString &basedir)
+{
+ QByteArray data;
+ data.append("<html>");
+ data.append("<table>");
+ data.append(" <tr>");
+ data.append(" <th></th>"); // icon
+ data.append(" <th>Filename</th>");
+ data.append(" <th>MIME</th>");
+ data.append(" <th>Size</th>");
+ data.append(" </tr>");
+ 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(" <tr>");
+
+ const bool isdotdot = (fileinfo.fileName() == QLatin1String(".."));
+ if (isdotdot) {
+ const QString fileicon = QString::fromLatin1("<img src=\"/kdirshare_icons/go-previous\" width=\"20\" height=\"20\">");
+ data.append("<td>");
+ data.append(fileicon.toAscii());
+ data.append("</td>");
+ } else {
+ const QString fileicon = QString::fromLatin1("<img src=\"/kdirshare_icons/%1\" width=\"20\" height=\"20\">").arg(KMimeType::iconNameForUrl(KUrl(fullpath)));
+ data.append("<td>");
+ data.append(fileicon.toAscii());
+ data.append("</td>");
+ }
+
+ // qDebug() << Q_FUNC_INFO << fullpath << basedir << cleanpath;
+ data.append("<td><a href=\"");
+ data.append(cleanpath.toLocal8Bit());
+ data.append("\">");
+ data.append(fileinfo.fileName().toLocal8Bit());
+ data.append("</a><br></td>");
+
+ data.append("<td>");
+ if (!isdotdot) {
+ const QString filemime = KMimeType::findByPath(fullpath)->name();
+ data.append(filemime.toAscii());
+ }
+ data.append("</td>");
+
+ data.append("<td>");
+ if (fileinfo.isFile()) {
+ const QString filesize = KGlobal::locale()->formatByteSize(fileinfo.size(), 1);
+ data.append(filesize.toAscii());
+ }
+ data.append("</td>");
+
+ data.append(" </tr>");
+ }
+ data.append("</table>");
+ data.append("</html>");
+ 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("<html>404 Not Found</html>");
+
+ outdata->append(data);
+ *outhttpstatus = 404;
+ outheaders->insert("Content-Type", "text/html; charset=UTF-8");
+ }
+}
--- /dev/null
+/* This file is part of the KDE project
+ Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+ 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 <khttp.h>
+#include <kdnssd.h>
+
+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
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://"));