Commit 39190a4a authored by Albert Vaca Cintora's avatar Albert Vaca Cintora
Browse files

Share plugin changed name! Please run make uninstall before make install

Sharereceiver is now called share plugin (soon it will not only receive ;)
Added a config dialog to be able to select a directory for incoming files
Changed  Messages.sh to translate config new .ui files too
Fixed typo in pausemusicplugin.cpp
Fixed multiple file transfer notifications bug
Added minimal error checking to share plugin.
parent 2fdffd5c
#!/usr/bin/env bash
$EXTRACTRC `find -name '*.ui' -o -name '*.rc'` >> rc.cpp
$XGETTEXT rc.cpp -o $podir/kdeconnect-kded.pot
rm -f rc.cpp
#.cpp (-j passed to merge into existing file)
$XGETTEXT `find . -name '*.cpp'` -o $podir/kdeconnect-kded.pot
#.desktop and .notifyrc files doesn't need to be included here
......@@ -102,10 +102,9 @@ void FileTransferJob::sourceFinished()
//TODO: MD5 check the file
if (mSize > -1 && mWritten != mSize) {
kDebug(kdeconnect_kded()) << "Received incomplete file";
kDebug(kdeconnect_kded()) << "Received incomplete file (" << mWritten << " of " << mSize << " bytes)";
setError(1);
setErrorText(i18n("Received incomplete file"));
emitResult();
} else {
kDebug(kdeconnect_kded()) << "Finished transfer" << mDestination->url();
}
......
......@@ -7,6 +7,6 @@ add_subdirectory(mpriscontrol)
add_subdirectory(clipboard)
add_subdirectory(telephony)
add_subdirectory(battery)
add_subdirectory(sharereceiver)
add_subdirectory(share)
add_subdirectory(notifications)
......@@ -43,16 +43,14 @@ PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
{
//FIXME: There should be a better way to listen to changes in the config file instead of reading the value each time
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/kdeconnect_pausemusic");
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/pausemusic");
bool pauseOnlyWhenTalking = config->group("pause_condition").readEntry("talking_only", false);
if (pauseOnlyWhenTalking) {
qDebug() << "pause when talking";
if (np.get<QString>("event") != "talking") {
return true;
}
} else { //Pause as soon as it rings
qDebug() << "pause when ringing";
if (np.get<QString>("event") != "ringing" && np.get<QString>("event") != "talking") {
return true;
}
......
......@@ -11,8 +11,8 @@ include_directories(
${CMAKE_SOURCE_DIR}
)
set(kdeconnect_sharereceiver_SRCS
sharereceiverplugin.cpp
set(kdeconnect_share_SRCS
shareplugin.cpp
autoclosingqfile.cpp
../kdeconnectplugin.cpp
../pluginloader.cpp
......@@ -22,9 +22,9 @@ set(kdeconnect_sharereceiver_SRCS
../../kdebugnamespace.cpp
)
kde4_add_plugin(kdeconnect_sharereceiver ${kdeconnect_sharereceiver_SRCS})
kde4_add_plugin(kdeconnect_share ${kdeconnect_share_SRCS})
target_link_libraries(kdeconnect_sharereceiver
target_link_libraries(kdeconnect_share
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
......@@ -33,5 +33,22 @@ target_link_libraries(kdeconnect_sharereceiver
${QCA2_LIBRARIES}
)
install(TARGETS kdeconnect_sharereceiver DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_sharereceiver.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install(TARGETS kdeconnect_share DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_share.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
#######################################
# Config
set( kdeconnect_share_config_SRCS share_config.cpp )
kde4_add_ui_files( kdeconnect_share_config_SRCS share_config.ui )
kde4_add_plugin( kdeconnect_share_config ${kdeconnect_share_config_SRCS} )
target_link_libraries( kdeconnect_share_config
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
)
install(TARGETS kdeconnect_share_config DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_share_config.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=KdeConnect/Plugin
X-KDE-Library=kdeconnect_share
X-KDE-PluginInfo-Author=Albert Vaca
X-KDE-PluginInfo-Email=albertvaka@gmail.com
X-KDE-PluginInfo-Name=kdeconnect_share
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://albertvaka.wordpress.com
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=folder-downloads
Name=Share and receive
Comment=Receive and send files, URLs or plain text easily
X-KdeConnect-SupportedPackageType=kdeconnect.share
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kdeconnect_share_config
X-KDE-ParentComponents=kdeconnect_share
Name=Share plugin settings
Categories=Qt;KDE;X-KDE-settings-kdeconnect;
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "share_config.h"
#include <QDesktopServices>
#include <KPluginFactory>
#include <KSharedConfig>
#include <KConfigGroup>
#include <KUrlRequester>
#include "../../kdebugnamespace.h"
#include "ui_share_config.h"
K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin<ShareConfig>();)
K_EXPORT_PLUGIN(ShareConfigFactory("kdeconnect_share_config", "kdeconnect_share_config"))
ShareConfig::ShareConfig(QWidget *parent, const QVariantList& )
: KCModule(ShareConfigFactory::componentData(), parent)
, m_ui(new Ui::ShareConfigUi())
, m_cfg(KSharedConfig::openConfig("kdeconnect/plugins/share"))
{
m_ui->setupUi(this);
connect(m_ui->kurlrequester, SIGNAL(textChanged(QString)), this, SLOT(changed()));
}
ShareConfig::~ShareConfig()
{
delete m_ui;
}
void ShareConfig::defaults()
{
KCModule::defaults();
//TODO: Set this to the user's xdg download dir
m_ui->kurlrequester->setUrl(KUrl(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)));
Q_EMIT changed(true);
}
void ShareConfig::load()
{
KCModule::load();
m_ui->kurlrequester->setUrl(m_cfg->group("receive").readEntry("path", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)));
Q_EMIT changed(false);
}
void ShareConfig::save()
{
m_cfg->group("receive").writeEntry("path", m_ui->kurlrequester->url());
KCModule::save();
Q_EMIT changed(false);
}
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHARE_CONFIG_H
#define SHARE_CONFIG_H
#include <kcmodule.h>
#include <ksharedconfig.h>
namespace Ui {
class ShareConfigUi;
}
class ShareConfig
: public KCModule
{
Q_OBJECT
public:
ShareConfig(QWidget *parent, const QVariantList&);
virtual ~ShareConfig();
public Q_SLOTS:
virtual void save();
virtual void load();
virtual void defaults();
private:
Ui::ShareConfigUi* m_ui;
KSharedConfigPtr m_cfg;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShareConfigUi</class>
<widget class="QWidget" name="ShareConfigUi">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>411</width>
<height>165</height>
</rect>
</property>
<property name="windowTitle">
<string>Share plugin settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Receiving</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Save files in:</string>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="kurlrequester">
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="mode">
<set>KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly</set>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</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>
<customwidgets>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -18,36 +18,54 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sharereceiverplugin.h"
#include "shareplugin.h"
#include <KIcon>
#include <KLocalizedString>
#include <KStandardDirs>
#include <KSharedConfig>
#include <KConfigGroup>
#include <QFile>
#include <qprocess.h>
#include <QDir>
#include <QDesktopServices>
#include "../../kdebugnamespace.h"
#include "../../filetransferjob.h"
#include "autoclosingqfile.h"
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< ShareReceiverPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_sharereceiver", "kdeconnect_sharereceiver") )
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< SharePlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_share", "kdeconnect_share") )
ShareReceiverPlugin::ShareReceiverPlugin(QObject* parent, const QVariantList& args)
SharePlugin::SharePlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
{
//TODO: Use downloads user path
//TODO: Be able to change this from config
mDestinationDir = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
if (!mDestinationDir.endsWith('/')) mDestinationDir.append('/');
}
QString SharePlugin::destinationDir()
{
//TODO: Change this for the xdg download user dir
QString defaultPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
//FIXME: There should be a better way to listen to changes in the config file instead of reading the value each time
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/share");
QString dir = config->group("receive").readEntry("path", defaultPath);
if (!dir.endsWith('/')) dir.append('/');
QDir().mkpath(KUrl(dir).path()); //Using KUrl to remove file:/// protocol, wich seems to confuse QDir.mkpath
kDebug(kdeconnect_kded()) << dir;
return dir;
}
bool ShareReceiverPlugin::receivePackage(const NetworkPackage& np)
bool SharePlugin::receivePackage(const NetworkPackage& np)
{
/*
//TODO: Move this code to a test and add a diff between files
//TODO: Use this code to write a test
if (np.type() == PACKAGE_TYPE_PING) {
kDebug(kdeconnect_kded()) << "sending file" << (QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc");
......@@ -72,7 +90,7 @@ bool ShareReceiverPlugin::receivePackage(const NetworkPackage& np)
//kDebug(kdeconnect_kded()) << "receiving file";
QString filename = np.get<QString>("filename", QString::number(QDateTime::currentMSecsSinceEpoch()));
//TODO: Ask before overwritting or rename file if it already exists
FileTransferJob* job = np.createPayloadTransferJob(mDestinationDir + filename);
FileTransferJob* job = np.createPayloadTransferJob(destinationDir() + filename);
connect(job, SIGNAL(result(KJob*)), this, SLOT(finished(KJob*)));
job->start();
} else if (np.has("text")) {
......@@ -102,13 +120,15 @@ bool ShareReceiverPlugin::receivePackage(const NetworkPackage& np)
}
void ShareReceiverPlugin::finished(KJob* job)
void SharePlugin::finished(KJob* job)
{
kDebug(kdeconnect_kded()) << "File transfer finished";
bool error = (job->error() != 0);
FileTransferJob* transferJob = (FileTransferJob*)job;
KNotification* notification = new KNotification("pingReceived"); //KNotification::Persistent
notification->setPixmap(KIcon("dialog-ok").pixmap(48, 48));
notification->setPixmap(KIcon(error? "edit-delete" : "dialog-ok").pixmap(48, 48));
notification->setComponentData(KComponentData("kdeconnect", "kdeconnect"));
notification->setTitle(i18n("Transfer finished"));
notification->setText(transferJob->destination().fileName());
......@@ -117,7 +137,7 @@ void ShareReceiverPlugin::finished(KJob* job)
notification->sendEvent();
}
void ShareReceiverPlugin::openDestinationFolder()
void SharePlugin::openDestinationFolder()
{
QDesktopServices::openUrl(mDestinationDir);
QDesktopServices::openUrl(destinationDir());
}
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHARERECEIVERPLUGIN_H
#define SHARERECEIVERPLUGIN_H
#ifndef SHAREPLUGIN_H
#define SHAREPLUGIN_H
#include <KNotification>
#include <KIO/Job>
......@@ -28,13 +28,13 @@
#define PACKAGE_TYPE_SHARE QLatin1String("kdeconnect.share")
class ShareReceiverPlugin
class SharePlugin
: public KdeConnectPlugin
{
Q_OBJECT
public:
explicit ShareReceiverPlugin(QObject *parent, const QVariantList &args);
explicit SharePlugin(QObject *parent, const QVariantList &args);
public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np);
......@@ -45,7 +45,7 @@ private Q_SLOTS:
void openDestinationFolder();
private:
QString mDestinationDir;
QString destinationDir();
};
#endif
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=KdeConnect/Plugin
X-KDE-Library=kdeconnect_sharereceiver
X-KDE-PluginInfo-Author=Albert Vaca
X-KDE-PluginInfo-Email=albertvaka@gmail.com
X-KDE-PluginInfo-Name=kdeconnect_sharereceiver
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://albertvaka.wordpress.com
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=folder-downloads
Name=Share receiver
Name[hu]=Megosztás vevő
Name[it]=Ricezione condivisioni
Name[nl]=Ontvanger delen
Name[pt]=Destinatário da partilha
Name[pt_BR]=Destinatário do compartilhamento
Name[ru]=Сделать ресивер общим
Name[sv]=Dela mottagare
Name[tr]=Paylaşım alıcı
Name[uk]=Отримання спільних даних
Name[x-test]=xxShare receiverxx
Comment=Receive files and URLs shared from your phone
Comment[hu]=A telefonról megosztott fájlok és URL-ek fogadása
Comment[it]=Ricevi file e URL condivisi dal tuo telefono
Comment[nl]=Ontvangen bestanden en URL's gedeeld met uw telefoon
Comment[pt]=Receber os ficheiros e URL's partilhados a partir do seu telefone
Comment[pt_BR]=Recebe os arquivos e URLs compartilhados a partir do seu telefone
Comment[ru]=Получать общие файлы и адреса URL с телефона
Comment[sv]=Ta emot filer och webbadresser att dela från din telefon
Comment[tr]=Telefonunuzdan paylaşılan dosya ve adresleri alın
Comment[uk]=Отримання файлів та адрес, наданих у спільне користування з вашого телефону
Comment[x-test]=xxReceive files and URLs shared from your phonexx
X-KdeConnect-SupportedPackageType=kdeconnect.share
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment