Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Network
KGet
Commits
66996c4f
Commit
66996c4f
authored
Dec 13, 2021
by
Alexander Lohnau
💬
Browse files
Remove kget extensions
The kget one will be imported in konqueror and the other one has not been build for years.
parent
45ec4cab
Pipeline
#109881
passed with stage
in 2 minutes and 6 seconds
Changes
27
Pipelines
3
Expand all
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
66996c4f
...
...
@@ -143,7 +143,6 @@ add_subdirectory(conf)
add_subdirectory
(
core
)
add_subdirectory
(
ui
)
add_subdirectory
(
transfer-plugins
)
add_subdirectory
(
extensions
)
add_subdirectory
(
sounds
)
add_subdirectory
(
desktop
)
#add_subdirectory(plasma) TODO PORT TO KF5/QML
...
...
extensions/CMakeLists.txt
deleted
100644 → 0
View file @
45ec4cab
add_subdirectory
(
konqueror
)
#add_subdirectory(webinterface)
#TODO: Port this to KDE5
extensions/konqueror/CMakeLists.txt
deleted
100644 → 0
View file @
45ec4cab
add_library
(
kget_browser_integration MODULE
)
set
(
kget_browser_integration_dbus_SRCS
)
qt_add_dbus_interface
(
kget_browser_integration_dbus_SRCS ../../dbus/org.kde.kget.main.xml kget_interface
)
target_sources
(
kget_browser_integration PRIVATE
kget_plug_in.cpp
${
kget_browser_integration_dbus_SRCS
}
)
target_link_libraries
(
kget_browser_integration KF5::CoreAddons KF5::I18n KF5::IconThemes KF5::Parts
)
install
(
TARGETS kget_browser_integration DESTINATION
${
KDE_INSTALL_PLUGINDIR
}
)
########### install files ###############
install
(
FILES kget_plug_in.rc kget_plug_in.desktop DESTINATION
${
KDE_INSTALL_DATADIR
}
/khtml/kpartplugins
)
install
(
FILES kget_plug_in.rc kget_plug_in.desktop DESTINATION
${
KDE_INSTALL_DATADIR
}
/dolphinpart/kpartplugins
)
install
(
FILES kget_plug_in.rc kget_plug_in.desktop DESTINATION
${
KDE_INSTALL_DATADIR
}
/kwebkitpart/kpartplugins
)
extensions/konqueror/Messages.sh
deleted
100644 → 0
View file @
45ec4cab
#! /bin/sh
$EXTRACTRC
*
.rc
>>
rc.cpp
||
exit
11
$XGETTEXT
*
.cpp
-o
$podir
/kgetplugin.pot
rm
-f
rc.cpp
extensions/konqueror/kget_plug_in.cpp
deleted
100644 → 0
View file @
45ec4cab
/* This file is part of the KDE project
Copyright (C) 2002 Patrick Charbonnier <pch@valleeurpe.net>
Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
Copyright (C) 2010 Dawit Alemayehu <adawit@kde.org>
Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include
"kget_plug_in.h"
#include
"kget_interface.h"
#include
<QIcon>
#include
<QMenu>
#include
<QDBusConnection>
#include
<KActionCollection>
#include
<KActionMenu>
#include
<KDialogJobUiDelegate>
#include
<KFileItem>
#include
<KIconLoader>
#include
<KIO/CommandLauncherJob>
#include
<KLocalizedString>
#include
<KMessageBox>
#include
<KPluginFactory>
#include
<KProtocolInfo>
#include
<KParts/FileInfoExtension>
#include
<KParts/HtmlExtension>
#include
<KParts/Part>
#include
<KParts/PartManager>
#include
<KParts/ReadOnlyPart>
#include
<KParts/SelectorInterface>
#include
<KToggleAction>
#include
<KToolInvocation>
#define QL1S(x) QLatin1String(x)
K_PLUGIN_FACTORY
(
KGetPluginFactory
,
registerPlugin
<
KGetPlugin
>
();)
static
QWidget
*
partWidget
(
QObject
*
obj
)
{
auto
*
part
=
qobject_cast
<
KParts
::
ReadOnlyPart
*>
(
obj
);
return
part
?
part
->
widget
()
:
nullptr
;
}
KGetPlugin
::
KGetPlugin
(
QObject
*
parent
,
const
QVariantList
&
)
:
KParts
::
Plugin
(
parent
)
{
auto
*
menu
=
new
KActionMenu
(
QIcon
::
fromTheme
(
"kget"
),
i18n
(
"Download Manager"
),
actionCollection
());
actionCollection
()
->
addAction
(
"kget_menu"
,
menu
);
menu
->
setDelayed
(
false
);
connect
(
menu
->
menu
(),
&
QMenu
::
aboutToShow
,
this
,
&
KGetPlugin
::
showPopup
);
m_dropTargetAction
=
new
KToggleAction
(
i18n
(
"Show Drop Target"
),
actionCollection
());
connect
(
m_dropTargetAction
,
&
QAction
::
triggered
,
this
,
&
KGetPlugin
::
slotShowDrop
);
actionCollection
()
->
addAction
(
QL1S
(
"show_drop"
),
m_dropTargetAction
);
menu
->
addAction
(
m_dropTargetAction
);
QAction
*
showLinksAction
=
actionCollection
()
->
addAction
(
QL1S
(
"show_links"
));
showLinksAction
->
setText
(
i18n
(
"List All Links"
));
connect
(
showLinksAction
,
&
QAction
::
triggered
,
this
,
&
KGetPlugin
::
slotShowLinks
);
menu
->
addAction
(
showLinksAction
);
QAction
*
showSelectedLinksAction
=
actionCollection
()
->
addAction
(
QL1S
(
"show_selected_links"
));
showSelectedLinksAction
->
setText
(
i18n
(
"List Selected Links"
));
connect
(
showSelectedLinksAction
,
&
QAction
::
triggered
,
this
,
&
KGetPlugin
::
slotShowSelectedLinks
);
menu
->
addAction
(
showSelectedLinksAction
);
// Hide this plugin if the parent part does not support either
// The FileInfo or Html extensions...
if
(
!
KParts
::
HtmlExtension
::
childObject
(
parent
)
&&
!
KParts
::
FileInfoExtension
::
childObject
(
parent
))
menu
->
setVisible
(
false
);
}
KGetPlugin
::~
KGetPlugin
()
{
}
static
bool
hasDropTarget
()
{
bool
found
=
false
;
if
(
QDBusConnection
::
sessionBus
().
interface
()
->
isServiceRegistered
(
"org.kde.kget"
))
{
OrgKdeKgetMainInterface
kgetInterface
(
"org.kde.kget"
,
"/KGet"
,
QDBusConnection
::
sessionBus
());
QDBusReply
<
bool
>
reply
=
kgetInterface
.
dropTargetVisible
();
if
(
reply
.
isValid
())
{
found
=
reply
.
value
();
}
}
return
found
;
}
void
KGetPlugin
::
showPopup
()
{
// Check for HtmlExtension support...
KParts
::
HtmlExtension
*
htmlExtn
=
KParts
::
HtmlExtension
::
childObject
(
parent
());
if
(
htmlExtn
)
{
KParts
::
SelectorInterface
*
selector
=
qobject_cast
<
KParts
::
SelectorInterface
*>
(
htmlExtn
);
if
(
selector
)
{
m_dropTargetAction
->
setChecked
(
hasDropTarget
());
const
KParts
::
SelectorInterface
::
QueryMethods
methods
=
selector
->
supportedQueryMethods
();
bool
enable
=
(
methods
&
KParts
::
SelectorInterface
::
EntireContent
);
actionCollection
()
->
action
(
QL1S
(
"show_links"
))
->
setEnabled
(
enable
);
enable
=
(
htmlExtn
->
hasSelection
()
&&
(
methods
&
KParts
::
SelectorInterface
::
SelectedContent
));
actionCollection
()
->
action
(
QL1S
(
"show_selected_links"
))
->
setEnabled
(
enable
);
enable
=
(
actionCollection
()
->
action
(
QL1S
(
"show_links"
))
->
isEnabled
()
||
actionCollection
()
->
action
(
QL1S
(
"show_selected_links"
))
->
isEnabled
());
actionCollection
()
->
action
(
QL1S
(
"show_drop"
))
->
setEnabled
(
enable
);
return
;
}
}
// Check for FileInfoExtension support...
KParts
::
FileInfoExtension
*
fileinfoExtn
=
KParts
::
FileInfoExtension
::
childObject
(
parent
());
if
(
fileinfoExtn
)
{
m_dropTargetAction
->
setChecked
(
hasDropTarget
());
const
KParts
::
FileInfoExtension
::
QueryModes
modes
=
fileinfoExtn
->
supportedQueryModes
();
bool
enable
=
(
modes
&
KParts
::
FileInfoExtension
::
AllItems
);
actionCollection
()
->
action
(
QL1S
(
"show_links"
))
->
setEnabled
(
enable
);
enable
=
(
fileinfoExtn
->
hasSelection
()
&&
(
modes
&
KParts
::
FileInfoExtension
::
SelectedItems
));
actionCollection
()
->
action
(
QL1S
(
"show_selected_links"
))
->
setEnabled
(
enable
);
enable
=
(
actionCollection
()
->
action
(
QL1S
(
"show_links"
))
->
isEnabled
()
||
actionCollection
()
->
action
(
QL1S
(
"show_selected_links"
))
->
isEnabled
());
actionCollection
()
->
action
(
QL1S
(
"show_drop"
))
->
setEnabled
(
enable
);
return
;
}
actionCollection
()
->
action
(
QL1S
(
"show_selected_links"
))
->
setEnabled
(
false
);
actionCollection
()
->
action
(
QL1S
(
"show_links"
))
->
setEnabled
(
false
);
actionCollection
()
->
action
(
QL1S
(
"show_drop"
))
->
setEnabled
(
false
);
if
(
m_dropTargetAction
->
isChecked
())
m_dropTargetAction
->
setChecked
(
false
);
}
void
KGetPlugin
::
slotShowDrop
()
{
if
(
!
QDBusConnection
::
sessionBus
().
interface
()
->
isServiceRegistered
(
"org.kde.kget"
))
{
const
QString
command
=
QStringLiteral
(
"kget --showDropTarget --hideMainWindow"
);
auto
*
job
=
new
KIO
::
CommandLauncherJob
(
command
);
job
->
setDesktopName
(
QStringLiteral
(
"org.kde.kget"
));
job
->
setUiDelegate
(
new
KDialogJobUiDelegate
(
KJobUiDelegate
::
AutoHandlingEnabled
,
partWidget
(
parent
())));
job
->
start
();
}
else
{
OrgKdeKgetMainInterface
kgetInterface
(
"org.kde.kget"
,
"/KGet"
,
QDBusConnection
::
sessionBus
());
kgetInterface
.
setDropTargetVisible
(
m_dropTargetAction
->
isChecked
());
}
}
void
KGetPlugin
::
slotShowLinks
()
{
getLinks
(
false
);
}
void
KGetPlugin
::
slotShowSelectedLinks
()
{
getLinks
(
true
);
}
void
KGetPlugin
::
slotImportLinks
()
{
if
(
m_linkList
.
isEmpty
())
{
KMessageBox
::
sorry
(
partWidget
(
parent
()),
i18n
(
"No downloadable links were found."
),
i18n
(
"No Links"
));
return
;
}
// Remove any duplicates links from the list...
m_linkList
.
removeDuplicates
();
OrgKdeKgetMainInterface
kgetInterface
(
"org.kde.kget"
,
"/KGet"
,
QDBusConnection
::
sessionBus
());
kgetInterface
.
importLinks
(
m_linkList
);
}
void
KGetPlugin
::
getLinks
(
bool
selectedOnly
)
{
KParts
::
HtmlExtension
*
htmlExtn
=
KParts
::
HtmlExtension
::
childObject
(
parent
());
if
(
htmlExtn
)
{
KParts
::
SelectorInterface
*
selector
=
qobject_cast
<
KParts
::
SelectorInterface
*>
(
htmlExtn
);
if
(
selector
)
{
m_linkList
.
clear
();
const
QUrl
baseUrl
=
htmlExtn
->
baseUrl
();
const
QString
query
=
QL1S
(
"a[href], img[src], audio[src], video[src], embed[src], object[data]"
);
const
KParts
::
SelectorInterface
::
QueryMethod
method
=
(
selectedOnly
?
KParts
::
SelectorInterface
::
SelectedContent
:
KParts
::
SelectorInterface
::
EntireContent
);
const
QList
<
KParts
::
SelectorInterface
::
Element
>
elements
=
selector
->
querySelectorAll
(
query
,
method
);
QString
attr
;
Q_FOREACH
(
const
KParts
::
SelectorInterface
::
Element
&
element
,
elements
)
{
if
(
element
.
hasAttribute
(
QL1S
(
"href"
)))
attr
=
QL1S
(
"href"
);
else
if
(
element
.
hasAttribute
(
QL1S
(
"src"
)))
attr
=
QL1S
(
"src"
);
else
if
(
element
.
hasAttribute
(
QL1S
(
"data"
)))
attr
=
QL1S
(
"data"
);
const
QUrl
resolvedUrl
(
baseUrl
.
resolved
(
QUrl
(
element
.
attribute
(
attr
))));
// Only select valid and non-local links for download...
if
(
resolvedUrl
.
isValid
()
&&
!
resolvedUrl
.
isLocalFile
()
&&
!
resolvedUrl
.
host
().
isEmpty
())
{
if
(
element
.
hasAttribute
(
QL1S
(
"type"
)))
m_linkList
<<
QString
(
QL1S
(
"url "
)
+
resolvedUrl
.
url
()
+
QL1S
(
" type "
)
+
element
.
attribute
(
QL1S
(
"type"
)));
else
m_linkList
<<
resolvedUrl
.
url
();
}
}
}
slotImportLinks
();
}
KParts
::
FileInfoExtension
*
fileinfoExtn
=
KParts
::
FileInfoExtension
::
childObject
(
parent
());
if
(
fileinfoExtn
)
{
m_linkList
.
clear
();
const
KParts
::
FileInfoExtension
::
QueryMode
mode
=
(
selectedOnly
?
KParts
::
FileInfoExtension
::
SelectedItems
:
KParts
::
FileInfoExtension
::
AllItems
);
const
KFileItemList
items
=
fileinfoExtn
->
queryFor
(
mode
);
Q_FOREACH
(
const
KFileItem
&
item
,
items
)
{
const
QUrl
url
=
item
.
url
();
// Only select valid and non local links for download...
if
(
item
.
isReadable
()
&&
item
.
isFile
()
&&
!
item
.
isLocalFile
()
&&
!
url
.
host
().
isEmpty
())
{
if
(
item
.
mimetype
().
isEmpty
())
m_linkList
<<
url
.
url
();
else
m_linkList
<<
QString
(
QL1S
(
"url "
)
+
url
.
url
()
+
QL1S
(
" type "
)
+
item
.
mimetype
());
}
}
slotImportLinks
();
}
}
#include
"kget_plug_in.moc"
extensions/konqueror/kget_plug_in.desktop
deleted
100644 → 0
View file @
45ec4cab
[Desktop Entry]
Encoding=UTF-8
Icon=kget
X-KDE-Library=kget_browser_integration
X-KDE-PluginInfo-Author=KGet Maintainers
X-KDE-PluginInfo-Email=kget@kde.org
X-KDE-PluginInfo-Name=kget_browser_integration
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=
X-KDE-PluginInfo-Category=Tools
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Name=Download Manager
Name[bg]=Изтегляне на файлове
Name[bs]=Upravnik preuzimanjima datoteka
Name[ca]=Gestor de baixades
Name[ca@valencia]=Gestor de baixades
Name[cs]=Správce stahování
Name[da]=Downloadhåndtering
Name[de]=Download-Verwaltung
Name[el]=Διαχειριστής λήψεων
Name[en_GB]=Download Manager
Name[eo]=Elŝuta administrilo
Name[es]=Gestor de descargas
Name[et]=Allalaadimiste haldur
Name[eu]=Deskarga-kudeatzailea
Name[fi]=Tiedostonlataaja
Name[fr]=Gestionnaire de téléchargements
Name[ga]=Bainisteoir Íosluchtaithe
Name[gl]=Xestor de descargas
Name[hu]=Letöltéskezelő
Name[ia]=Gerente de discargamento
Name[id]=Unduh Manager
Name[it]=Gestore degli scaricamenti
Name[ja]=ダウンロードマネージャ
Name[kk]=Жүктеп алу менеджері
Name[km]=កម្មវិធីគ្រប់គ្រងការទាញយក
Name[ko]=다운로드 관리자
Name[lt]=Siuntimų valdymas
Name[mr]=डाउनलोड व्यवस्थापक
Name[nb]=Nedlastingsbehandler
Name[nds]=Daalladenpleger
Name[nl]=Downloadbeheerder
Name[nn]=Nedlastingshandsamar
Name[pa]=ਡਾਊਨਲੋਡ ਮੈਨੇਜਰ
Name[pl]=Zarządzanie pobieraniem
Name[pt]=Gestor de Transferências
Name[pt_BR]=Gerenciador de downloads
Name[ro]=Administrator descărcări
Name[ru]=Диспетчер загрузок
Name[si]=බාගත කළමනාකරු
Name[sk]=Správca preberaní
Name[sl]=Upravljalnik prejemov
Name[sr]=Менаџер преузимања
Name[sr@ijekavian]=Менаџер преузимања
Name[sr@ijekavianlatin]=Menadžer preuzimanja
Name[sr@latin]=Menadžer preuzimanja
Name[sv]=Nerladdningshanterare
Name[tr]=İndirme Yöneticisi
Name[ug]=چۈشۈرۈش باشقۇرغۇسى
Name[uk]=Керування отриманнями
Name[x-test]=xxDownload Managerxx
Name[zh_CN]=下载管理器
Name[zh_TW]=下載管理員
Comment=A versatile and easy to use file download manager
Comment[bg]=Удобна и лесна за използване програма за изтегляния
Comment[bs]=Svestran i jednostavan za korištenje upravljač preuzimanjem datoteka
Comment[ca]=Un gestor de baixades de fitxers versàtil i fàcil d'emprar
Comment[ca@valencia]=Un gestor de baixades de fitxers versàtil i fàcil d'emprar
Comment[cs]=Všestranný a jednoduše použitelný správce souborů
Comment[da]=En alsidig og brugervenlig downloadhåndtering
Comment[de]=Ein vielseitiges und einfach zu benutzendes Download-Verwaltungsprogramm
Comment[el]=Ένας ευέλικτος και εύκολος στη χρήση διαχειριστής λήψεων αρχείων
Comment[en_GB]=A versatile and easy to use file download manager
Comment[es]=Una manera sencilla y versátil de usar el gestor de descarga de archivos
Comment[et]=Tubli ja lihtne failide allalaadimise haldur
Comment[eu]=Erabilera askotako eta errazeko fitxategiak deskargatzeko kudeatzailea
Comment[fi]=Monipuolinen ja helppokäyttöinen latauksenhallinta
Comment[fr]=Un gestionnaire de téléchargements facile et polyvalent
Comment[gl]=Un xestor de descargas de ficheiros versátil e fácil de usar.
Comment[hu]=Egy sokoldalú és egyszerűen használható letöltéskezelő
Comment[ia]=Un gestor de discargamento versatile e facile de usar se
Comment[id]=Sebuah unduh manager file yang serbaguna dan mudah digunakan
Comment[is]=Fjölhæfur en einfaldur skráaniðurhalsstjóri
Comment[it]=Un gestore di scaricamenti versatile e facile da usare
Comment[kk]=Әмбебап және ыңғайлы жүктеп алу менеджері
Comment[km]=អាចផ្លាស់ប្ដូរ និងងាយស្រួលប្រើកម្មវិធីគ្រប់គ្រងការទាញយក
Comment[ko]=다운로드 관리자
Comment[lt]=Lanksti ir paprasta failų atsiuntimo tvarkyklė
Comment[mr]=एक बहुमुखी व वापरायला सोपा फाईल डाउनलोड व्यवस्थापक
Comment[nb]=En fleksibel nedlastingsbehandler som er lett å bruke
Comment[nds]=En ansleegsch un eenfach to bruken Daalladenpleger
Comment[nl]=Een veelzijdige en gemakkelijk te gebruiken downloadbeheerder
Comment[nn]=Ein allsidig og brukarvenleg nedlastingshandsamar
Comment[pl]=Wszechstronny i łatwy w użyciu program zarządzający pobieraniem plików
Comment[pt]=Um gestor de transferências de ficheiros simples e versátil de usar
Comment[pt_BR]=Um gerenciador de downloads de arquivos simples e fácil de usar
Comment[ru]=Гибкий и простой в использовании диспетчер файлов
Comment[si]=භාවිතයට පහසු හුරුබුහුටි ගොනු බාගත කළමනාකරු
Comment[sk]=Univerzálny správca preberaní s ľahkým používaním
Comment[sl]=Vsestranski in preprost upravljalnik prejemov
Comment[sr]=Свестран и предусретљив менаџер преузимања фајлова
Comment[sr@ijekavian]=Свестран и предусретљив менаџер преузимања фајлова
Comment[sr@ijekavianlatin]=Svestran i predusretljiv menadžer preuzimanja fajlova
Comment[sr@latin]=Svestran i predusretljiv menadžer preuzimanja fajlova
Comment[sv]=En mångsidig och lättanvänd nerladdningshanterare av filer
Comment[tr]=Çok yetenekli ve kolay kullanımlı bir indirme yöneticisi
Comment[ug]=كۆپ ئىقتىدارلىق، ئىشلىتىش قۇلاي ھۆججەت چۈشۈرۈشنى باشقۇرغۇچ
Comment[uk]=Гнучка і проста у користуванні програма для керування отриманнями
Comment[x-test]=xxA versatile and easy to use file download managerxx
Comment[zh_CN]=简单易用的多功能文件下载管理器
Comment[zh_TW]=一個多功能且容易使用的檔案下載管理員
X-KDE-ParentApp=konqueror
extensions/konqueror/kget_plug_in.h
deleted
100644 → 0
View file @
45ec4cab
/* This file is part of the KDE project
Copyright (C) 2002 Patrick Charbonnier <pch@valleeurpe.net>
Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef KGETPLUGIN_H
#define KGETPLUGIN_H
#include
<KParts/Plugin>
#include
<QPointer>
class
KToggleAction
;
class
KGetPlugin
:
public
KParts
::
Plugin
{
Q_OBJECT
public:
KGetPlugin
(
QObject
*
parent
,
const
QVariantList
&
);
~
KGetPlugin
()
override
;
private
Q_SLOTS
:
void
slotShowDrop
();
void
slotShowLinks
();
void
slotShowSelectedLinks
();
void
slotImportLinks
();
void
showPopup
();
private:
void
getLinks
(
bool
selectedOnly
=
false
);
QStringList
m_linkList
;
KToggleAction
*
m_dropTargetAction
;
};
#endif
extensions/konqueror/kget_plug_in.rc
deleted
100644 → 0
View file @
45ec4cab
<!DOCTYPE kpartplugin>
<kpartplugin
library=
"kget_browser_integration"
name=
"kget_browser_integration"
version=
"4"
>
<MenuBar>
<Menu
name=
"tools"
><text>
&
Tools
</text>
<Action
name=
"kget_menu"
/>
</Menu>
</MenuBar>
<ToolBar
name=
"mainToolBar"
>
<Action
name=
"kget_menu"
/>
</ToolBar>
</kpartplugin>
extensions/webinterface/CMakeLists.txt
deleted
100644 → 0
View file @
45ec4cab
add_subdirectory
(
www
)
extensions/webinterface/httpserver.cpp
deleted
100644 → 0
View file @
45ec4cab
/* This file is part of the KDE project
Copyright (C) 2008 - 2009 Urs Wolfer <uwolfer @ kde.org>
Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>
Copyright (C) 2011 Lukas Appelhans <l.appelhans@gmx.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include
"httpserver.h"
#include
"core/transferhandler.h"
#include
"core/transfergrouphandler.h"
#include
"core/kget.h"
#include
"settings.h"
#include
<QDebug>
#include
<KGlobalSettings>
#include
<kwallet.h>
#include
<QTcpServer>
#include
<QTcpSocket>
#include
<QFile>
#include
<QDir>
#include
<QHttpRequestHeader>
#include
<QDateTime>
#include
<QStandardPaths>
HttpServer
::
HttpServer
(
QWidget
*
parent
)
:
QObject
(
parent
),
m_wallet
(
nullptr
)
{
m_wallet
=
KWallet
::
Wallet
::
openWallet
(
KWallet
::
Wallet
::
LocalWallet
(),
parent
->
winId
(),
///Use MainWindow?
KWallet
::
Wallet
::
Asynchronous
);
if
(
m_wallet
)
{
connect
(
m_wallet
,
SIGNAL
(
walletOpened
(
bool
)),
SLOT
(
init
(
bool
)));
}
else
{
KGet
::
showNotification
(
parent
,
"error"
,
i18n
(
"Unable to start WebInterface: Could not open KWallet"
));
}
}
HttpServer
::~
HttpServer
()
{
delete
m_wallet
;
}
void
HttpServer
::
init
(
bool
opened
)
{
if
(
opened
&&
m_wallet
->
hasFolder
(
"KGet"
)
&&
m_wallet
->
setFolder
(
"KGet"
))
{
m_wallet
->
readPassword
(
"Webinterface"
,
m_pwd
);
}
else
{
KGet
::
showNotification
(
static_cast
<
QWidget
*>
(
parent
()),
"error"
,
i18n
(
"Unable to start WebInterface: Could not open KWallet"
));
return
;
}
m_tcpServer
=
new
QTcpServer
(
this
);
if
(
!
m_tcpServer
->
listen
(
QHostAddress
::
Any
,
Settings
::
webinterfacePort
()))
{
KGet
::
showNotification
(
static_cast
<
QWidget
*>
(
parent
()),
"error"
,
i18nc
(
"@info"
,
"Unable to start WebInterface: %1"
,
m_tcpServer
->
errorString
()));
return
;
}
connect
(
m_tcpServer
,
SIGNAL
(
newConnection
()),
this
,
SLOT
(
handleRequest
()));
}
void
HttpServer
::
settingsChanged
()
{
if
(
m_wallet
)
{
m_wallet
->
readPassword
(
"Webinterface"
,
m_pwd
);
}
}
void
HttpServer
::
handleRequest
()
{
int
responseCode
=
200
;
QString
responseText
=
"OK"
;
QTcpSocket
*
clientConnection
=
m_tcpServer
->
nextPendingConnection
();
connect
(
clientConnection
,
SIGNAL
(
disconnected
()),
clientConnection
,
SLOT
(
deleteLater
()));
if
(
!
clientConnection
->
waitForReadyRead
())
{
clientConnection
->
disconnectFromHost
();
}
QByteArray
request
(
clientConnection
->
readAll
());
QHttpRequestHeader
header
(
request
);
QByteArray
data
;
// for HTTP authorization information see: http://www.governmentsecurity.org/articles/OverviewofHTTPAuthentication.php
QString
auth
=
header
.
value
(
"Authorization"
);
if
(
auth
.
length
()
<
6
||
QByteArray
::
fromBase64
(
auth
.
right
(
auth
.
length
()
-
6
).
toUtf8
())
!=
QString
(
Settings
::
webinterfaceUser
()
+
':'
+
m_pwd
))
{
responseCode
=
401
;
responseText
=
"Authorization Required"
;
// DO NOT TRANSLATE THE FOLLOWING MESSAGE! webserver messages are never translated.
QString
authRequiredText
=
QString
(
"<html><head><title>401 Authorization Required</title></head><body>"
"<h1>Authorization Required</h1>This server could not verify that you "
"are authorized to access the document requested. Either you supplied "
"the wrong credentials (e.g., bad password), or your browser does "
"not understand how to supply the credentials required.</body></html>"
);
data
.
append
(
authRequiredText
.
toUtf8
());
}
else
{
if
(
header
.
path
().
endsWith
(
QLatin1String
(
"data.json"
)))
{
data
.
append
(
"{
\"
downloads
\"
:["
);
bool
needsToBeClosed
=
false
;
foreach
(
TransferHandler
*
transfer
,
KGet
::
allTransfers
())
{
if
(
needsToBeClosed
)
data
.
append
(
","
);
// close the last line
data
.
append
(
QString
(
"{
\"
name
\"
:
\"
"
+
transfer
->
source
().
fileName
()
+
"
\"
,
\"
src
\"
:
\"
"
+
transfer
->
source
().
prettyUrl
()
+
"
\"
,
\"
dest
\"
:
\"
"
+
transfer
->
dest
().
pathOrUrl
()
+
"
\"
,
\"
status
\"
:
\"
"
+
transfer
->
statusText
()
+
"
\"
,
\"
size
\"
:
\"
"
+
KIO
::
convertSize
(
transfer
->
totalSize
())
+
"
\"
,
\"
progress
\"
:
\"
"
+
QString
::
number
(
transfer
->
percent
())
+
"%"
"
\"
,
\"
speed
\"
:
\"
"
+
i18nc
(
"@item speed of transfer per seconds"
,
"%1/s"
,
KIO
::
convertSize
(
transfer
->
downloadSpeed
()))
+
"
\"
}"
).
toUtf8
());
needsToBeClosed
=
true
;
}
data
.
append
(
"]}"
);
}
else
if
(
header
.
path
().
startsWith
(
QLatin1String
(
"/do"
)))
{
qCDebug
(
KGET_DEBUG
)
<<
request
;
QString
args
=
header
.
path
().
right
(
header
.
path
().
length
()
-
4
);
if
(
!
args
.
isEmpty
())
{
QString
action
;
QString
data
;
QString
group
;
QStringList
argList
=
args
.
split
(
'&'
);
foreach
(
const
QString
&
s
,
argList
)
{
QStringList
map
=
s
.
split
(
'='
);
if
(
map
.
at
(
0
)
==
"action"
)
action
=
map
.
at
(
1
);
else
if
(
map
.
at
(
0
)
==
"data"
)
data
=
QUrl
::
fromPercentEncoding
(
QByteArray
(
map
.
at
(
1
).
toUtf8
()));
// action specific parameters
else
if
(
map
.
at
(
0
)
==
"group"
)
group
=
QUrl
::
fromPercentEncoding
(
QByteArray
(
map
.
at
(
1
).
toUtf8
()));