Skip to content

Commit

Permalink
Added Fritzing Fab links to recent file list in welcome view.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjell Morgenstern authored and KjellMorgenstern committed Sep 22, 2021
1 parent cb86bd6 commit 17d6db9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions phoenixresources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -374,5 +374,6 @@
<file>resources/images/icons/toolbarSaveCodeDisabled_icon.png</file>
<file>resources/images/icons/toolbarSaveCodeEnabled_icon.png</file>
<file>resources/images/icons/toolbarSaveCodePressed_icon.png</file>
<file>resources/images/icons/aisler_donut-cloud_logo_icon.png</file>
</qresource>
</RCC>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 21 additions & 12 deletions src/dialogs/fabuploadprogress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QTimer>
#include <QLabel>
#include <QDesktopServices>
#include <QSettings>

#include <QDebug>

Expand Down Expand Up @@ -50,6 +51,12 @@ void FabUploadProgress::init(QNetworkAccessManager *manager, QString filename)

void FabUploadProgress::doUpload()
{
QSettings settings;
QString upload_url_str = settings.value("aisler/" + mFilepath, "").toString();
if (!upload_url_str.isEmpty()) {
uploadMultipart(QUrl(upload_url_str), mFilepath);
return;
}
QUrl new_url("https://fritzing.org/fab/upload");
QNetworkRequest request(new_url);
QNetworkReply *reply = mManager->get(request);
Expand All @@ -69,20 +76,22 @@ void FabUploadProgress::onRequestUploadFinished()
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if(statusCode == 301 || statusCode==302) {
QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
qDebug() << redirectUrl.toString();
// qDebug() << redirectUrl.toString();
QNetworkRequest request(redirectUrl);
QNetworkReply *r = mManager->get(request);
connect(r, SIGNAL(finished()), this, SLOT(onRequestUploadFinished()));
connect(r, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError)));
} else {
qDebug() << statusCode << Qt::endl;
// qDebug() << statusCode << Qt::endl;
auto d = reply->readAll();
qDebug() << d << Qt::endl << Qt::flush;
// qDebug() << d << Qt::endl << Qt::flush;
auto j = NetworkHelper::string_to_hash(d);
qDebug() << j["upload_url"].toString() << Qt::endl << Qt::flush;
// qDebug() << j["upload_url"].toString() << Qt::endl << Qt::flush;
QUrl upload_url(QUrl::fromUserInput(j["upload_url"].toString()));
QUrl project_url(j["project_url"].toString());
uploadMultipart(upload_url, mFilepath);
QSettings settings;
settings.setValue("aisler/" + mFilepath, j["upload_url"].toString());
}
} else {
httpError(reply);
Expand All @@ -93,14 +102,14 @@ void FabUploadProgress::onRequestUploadFinished()

void FabUploadProgress::uploadMultipart(const QUrl &url, const QString &file_path)
{
qDebug() << url.toString() << Qt::endl << Qt::flush;
// qDebug() << url.toString() << Qt::endl << Qt::flush;

QHttpMultiPart *httpMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QFile *file = new QFile(file_path);
QHttpPart imagePart;
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"upload[file]\"; filename=\"" + QFileInfo(*file).fileName() + "\""));
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
qDebug() << httpMultiPart->boundary();
// qDebug() << httpMultiPart->boundary();

file->open(QIODevice::ReadOnly);
imagePart.setBodyDevice(file);
Expand All @@ -117,7 +126,7 @@ void FabUploadProgress::uploadMultipart(const QUrl &url, const QString &file_pat
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT (uploadProgress(qint64, qint64)));

auto r = reply->request();
qDebug() << NetworkHelper::debugRequest(r);
// qDebug() << NetworkHelper::debugRequest(r);
}

void FabUploadProgress::uploadProgress(qint64 bytesSent, qint64 bytesTotal) {
Expand Down Expand Up @@ -159,9 +168,9 @@ void FabUploadProgress::uploadDone() {
qDebug() << "----------Finished--------------" << Qt::endl;
if (reply->error() == QNetworkReply::NoError) {
auto d = reply->readAll();
qDebug() << d << Qt::endl << Qt::flush;
// qDebug() << d << Qt::endl << Qt::flush;
auto j = NetworkHelper::string_to_hash(d);
qDebug() << j["upload_url"].toString() << Qt::endl << Qt::flush;
// qDebug() << j["upload_url"].toString() << Qt::endl << Qt::flush;
QUrl callback_url(QUrl::fromUserInput(j["callback"].toString()));
mRedirect_url = j["redirect"].toString();
mActivity = 0;
Expand All @@ -174,7 +183,7 @@ void FabUploadProgress::uploadDone() {

void FabUploadProgress::checkProcessingStatus(QUrl url)
{
qDebug() << url.toString() << Qt::endl << Qt::flush;
// qDebug() << url.toString() << Qt::endl << Qt::flush;
QNetworkRequest request(url);
QNetworkReply *reply = mManager->get(request);
connect(reply, SIGNAL(finished()), this, SLOT(updateProcessingStatus()));
Expand All @@ -187,13 +196,13 @@ void FabUploadProgress::updateProcessingStatus()

if (reply->error() == QNetworkReply::NoError) {
auto d = reply->readAll();
qDebug() << d << Qt::endl << Qt::flush;
// qDebug() << d << Qt::endl << Qt::flush;
auto j = NetworkHelper::string_to_hash(d);
// Produce a funny number which is growing most of the time,
// and somewhat related to what is really happening. It should
// change on every signal, so if it stops, there is a problem.
int progress = j["progress"].toInt();
qDebug() << progress;
// qDebug() << progress;
QString message(j["message"].toString());
if (progress < 0) {
apiError(message);
Expand Down
28 changes: 27 additions & 1 deletion src/sketch/welcomeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,22 @@ QWidget * WelcomeView::initRecent() {
frameLayout->addWidget(titleFrame);

m_recentListWidget = new QListWidget();
m_recentLinksListWidget = new QListWidget();
m_recentListWidget->setObjectName("recentList");
m_recentLinksListWidget->setObjectName("recentList");
m_recentListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_recentLinksListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
connect(m_recentListWidget, SIGNAL(itemClicked (QListWidgetItem *)), this, SLOT(recentItemClicked(QListWidgetItem *)));
connect(m_recentLinksListWidget, SIGNAL(itemClicked (QListWidgetItem *)), this, SLOT(blogItemClicked(QListWidgetItem *)));


frameLayout->addWidget(m_recentListWidget);
QFrame * listsFrame = new QFrame;
QHBoxLayout * listsFrameLayout = new QHBoxLayout;
zeroMargin(listsFrameLayout);
listsFrameLayout->addWidget(m_recentListWidget);
listsFrameLayout->addWidget(m_recentLinksListWidget);
listsFrame ->setLayout(listsFrameLayout);
frameLayout->addWidget(listsFrame);

QStringList names;
names << "recentSpace" << "recentNewSketch" << "recentOpenSketch";
Expand Down Expand Up @@ -653,23 +663,39 @@ void WelcomeView::showEvent(QShowEvent * event) {

void WelcomeView::updateRecent() {
if (!m_recentListWidget) return;
if (!m_recentLinksListWidget) return;

QSettings settings;
auto files = settings.value("recentFileList").toStringList();
m_recentListWidget->clear();
m_recentLinksListWidget->clear();

auto gotOne = false;

QIcon icon(":/resources/images/icons/WS-fzz-icon.png");
QIcon icon2(":/resources/images/icons/aisler_donut-cloud_logo_icon.png");

for (int i = 0; i < files.size(); ++i) {
QFileInfo finfo(files[i]);
if (!finfo.exists()) continue;

gotOne = true;
auto item = new QListWidgetItem(icon, finfo.fileName());
QListWidgetItem * itemLinks = nullptr;
item->setData(Qt::UserRole, finfo.absoluteFilePath());
item->setToolTip(finfo.absoluteFilePath());
QString link = settings.value("aisler/" + finfo.absoluteFilePath(), "").toString();
if (!link.isEmpty()) {
int pos = link.lastIndexOf(QChar('/'));
link = link.left(pos);
itemLinks = new QListWidgetItem(icon2, "Fritzing Fab");
itemLinks->setData(RefRole, link);
itemLinks->setToolTip(link);
} else {
itemLinks = new QListWidgetItem(QString(""));
}
m_recentListWidget->addItem(item);
m_recentLinksListWidget->addItem(itemLinks);
}

if (!gotOne) {
Expand Down
1 change: 1 addition & 0 deletions src/sketch/welcomeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ protected slots:
QWidget * m_projectsUberFrame = nullptr;
QLabel * m_tip = nullptr;
QListWidget * m_recentListWidget = nullptr;
QListWidget * m_recentLinksListWidget = nullptr;
QWidget * m_fabUberFrame = nullptr;
QWidget * m_shopUberFrame = nullptr;
QLabel * m_projectsLabel = nullptr;
Expand Down

0 comments on commit 17d6db9

Please sign in to comment.