Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/*
* Copyright 2014 Ahmed Ibrahim Khalil <ahmedibrahimkhali@gmail.com>
*
* Copyright (C) 2014 Ahmed I. Khalil <ahmedibrahimkhali@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 library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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 General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser 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/>.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

Expand Down Expand Up @@ -79,6 +78,11 @@ ShareProvider::ShareProvider(ShareService shareServiceType, QObject *parent)
d->m_shareServiceType = shareServiceType;
}

ShareProvider::~ShareProvider()
{
delete d;
}

void ShareProvider::setShareServiceType(ShareService shareServiceType)
{
delete d->m_sharer;
Expand All @@ -99,10 +103,10 @@ void ShareProvider::publish(const QString& filePath)
KUrl fileUrl(filePath);

KIO::MimetypeJob *mimetypeJob = KIO::mimetype(fileUrl, KIO::HideProgressInfo);
connect(mimetypeJob, SIGNAL(finished(KJob*)), this, SLOT(mimetypeJobFinished(KJob*)));
connect(mimetypeJob, SIGNAL(finished(KJob*)), this, SLOT(onMimetypeJobFinished(KJob*)));
}

void ShareProvider::mimetypeJobFinished(KJob* job)
void ShareProvider::onMimetypeJobFinished(KJob* job)
{
KIO::MimetypeJob *mjob = qobject_cast<KIO::MimetypeJob *>(job);
if (!mjob) {
Expand All @@ -126,21 +130,21 @@ void ShareProvider::mimetypeJobFinished(KJob* job)
}

KIO::FileJob *fjob = KIO::open(mjob->url(), QIODevice::ReadOnly);
connect(fjob, SIGNAL(open(KIO::Job*)), this, SLOT(openFile(KIO::Job*)));
connect(fjob, SIGNAL(open(KIO::Job*)), this, SLOT(onFileOpened(KIO::Job*)));

mjob->deleteLater();
}

void ShareProvider::openFile(KIO::Job* job)
void ShareProvider::onFileOpened(KIO::Job* job)
{
// finished opening the file, now try to read it's content
KIO::FileJob *fjob = static_cast<KIO::FileJob*>(job);
fjob->read(fjob->size());
connect(fjob, SIGNAL(data(KIO::Job*,QByteArray)),
this, SLOT(finishedContentData(KIO::Job*,QByteArray)));
this, SLOT(onFinishedReadingFile(KIO::Job*,QByteArray)));
}

void ShareProvider::finishedContentData(KIO::Job* job, const QByteArray& data)
void ShareProvider::onFinishedReadingFile(KIO::Job* job, const QByteArray& data)
{
job->disconnect(this);
qobject_cast<KIO::FileJob *>(job)->close();
Expand All @@ -160,19 +164,19 @@ void ShareProvider::finishedContentData(KIO::Job* job, const QByteArray& data)
KIO::TransferJob *tJob = KIO::http_post(sharer->url(), sharer->postBody(data), KIO::HideProgressInfo);
tJob->setMetaData(sharer->headers());
connect(tJob, SIGNAL(data(KIO::Job*,QByteArray)),
this, SLOT(transferJobDataReceived(KIO::Job*,QByteArray)));
connect(tJob, SIGNAL(result(KJob*)), this, SLOT(transferJobResultReceived(KJob*)));
this, SLOT(onTransferJobDataReceived(KIO::Job*,QByteArray)));
connect(tJob, SIGNAL(result(KJob*)), this, SLOT(onTransferJobResultReceived(KJob*)));

}
}

void ShareProvider::transferJobDataReceived(KIO::Job* job, QByteArray data)
void ShareProvider::onTransferJobDataReceived(KIO::Job* job, QByteArray data)
{
Q_UNUSED(job);
d->m_data.append(data);
}

void ShareProvider::transferJobResultReceived(KJob* job)
void ShareProvider::onTransferJobResultReceived(KJob* job)
{
if (d->m_data.size() == 0) {
emit finishedError(i18n("Service was not available"));
Expand All @@ -198,15 +202,6 @@ void ShareProvider::transferJobResultReceived(KJob* job)
}
}
}

job->deleteLater();
}



ShareProvider::~ShareProvider()
{
delete d;
}


67 changes: 67 additions & 0 deletions image-sharer/shareprovider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#ifndef SHAREPROVIDER_H
#define SHAREPROVIDER_H

#include <QObject>

class ShareProviderPrivate;
class KJob;

namespace KIO {
class Job;
}

class ShareProvider : public QObject
{
Q_OBJECT

public:
// Available Image Share Services
enum ShareService {
Imgur,
SimplestImageHosting,
ImageBin
};

ShareProvider(ShareService shareServiceType, QObject *parent = 0);
virtual ~ShareProvider();

ShareService shareServiceType() const;
void setShareServiceType(ShareService shareServiceType);

void publish(const QString &filePath);

Q_SIGNALS:
void finishedSuccess(const QString &url);
void finishedError(const QString &msg);

protected Q_SLOTS:
void onMimetypeJobFinished(KJob *job);
void onFileOpened(KIO::Job *job);
void onFinishedReadingFile(KIO::Job *job, const QByteArray &data);
void onTransferJobDataReceived(KIO::Job *job, QByteArray data);
void onTransferJobResultReceived(KJob *job);

private:
ShareProviderPrivate * const d;
};

#endif // SHAREPROVIDER_H
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
* Copyright (C) 2014 Ahmed I. Khalil <ahmedibrahimkhali@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 library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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 General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser 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/>.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

Expand Down
36 changes: 36 additions & 0 deletions image-sharer/simplestimagehostingsharer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#ifndef SIMPLESTIMAGEHOSTINGSHARER_H
#define SIMPLESTIMAGEHOSTINGSHARER_H

#include "abstractsharer.h"
#include "mpform.h"

class SimplestImageHostingSharer : public AbstractSharer
{
public:
SimplestImageHostingSharer(const QString& contentPath);

KUrl url() const;
void parseResponse(const QByteArray& responseData);
QByteArray postBody(const QByteArray& imageData);
};

#endif // SIMPLESTIMAGEHOSTINGSHARER_H
57 changes: 0 additions & 57 deletions ktp-image-sharer/abstractsharer.cpp

This file was deleted.

56 changes: 0 additions & 56 deletions ktp-image-sharer/abstractsharer.h

This file was deleted.

38 changes: 0 additions & 38 deletions ktp-image-sharer/imagebinsharer.h

This file was deleted.

38 changes: 0 additions & 38 deletions ktp-image-sharer/imgursharer.h

This file was deleted.

70 changes: 0 additions & 70 deletions ktp-image-sharer/shareprovider.h

This file was deleted.

39 changes: 0 additions & 39 deletions ktp-image-sharer/simplestimagehostingsharer.h

This file was deleted.

2 changes: 1 addition & 1 deletion ktp-test-exec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ set(ktp-test_SRCS ktp-test.cpp main.cpp)

kde4_add_executable(ktp-test-exec ${ktp-test_SRCS})

target_link_libraries(ktp-test-exec ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ktp-image-sharer)
target_link_libraries(ktp-test-exec ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} image-sharer)

install(TARGETS ktp-test-exec RUNTIME DESTINATION bin)
2 changes: 1 addition & 1 deletion ktp-test-exec/ktp-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <QMessageBox>


#include "ktp-image-sharer/shareprovider.h"
#include "image-sharer/shareprovider.h"

ktp_test::ktp_test()
{
Expand Down