Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
feat: install new interaction.
Browse files Browse the repository at this point in the history
Change-Id: I28cad25e36a0395e1b6108ed35fca0f8ca500de4
  • Loading branch information
reionwong committed Feb 24, 2018
1 parent 68726db commit 976b9f5
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 14 deletions.
6 changes: 4 additions & 2 deletions deepin-font-installer/deepin-font-installer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ HEADERS += homepage.h \
multifilepage.h \
singlefilepage.h \
utils.h \
progress.h
progress.h \
refreshthread.h

SOURCES += homepage.cpp \
listview.cpp \
Expand All @@ -34,7 +35,8 @@ SOURCES += homepage.cpp \
multifilepage.cpp \
singlefilepage.cpp \
utils.cpp \
progress.cpp
progress.cpp \
refreshthread.cpp

RESOURCES += deepin-font-installer.qrc
TRANSLATIONS += translations/deepin-font-installer.ts
Expand Down
47 changes: 40 additions & 7 deletions deepin-font-installer/multifilepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,49 @@ MultiFilePage::MultiFilePage(QWidget *parent)
m_installBtn(new QPushButton),
m_viewFileBtn(new QPushButton),
m_progress(new Progress),
m_iconPixmap(new QPixmap)
m_iconPixmap(new QPixmap),
m_refreshThread(new RefreshThread),
m_bottomLayout(new QStackedLayout),
m_spinner(new DSpinner)
{
const auto ratio = qApp->devicePixelRatio();
*m_iconPixmap = DSvgRenderer::render(":/images/font-x-generic.svg", QSize(32, 32) * ratio);
m_iconPixmap->setDevicePixelRatio(ratio);

// list widget.
QHBoxLayout *contentLayout = new QHBoxLayout;
contentLayout->addSpacing(15);
contentLayout->addWidget(m_listView);
contentLayout->addSpacing(15);

// init buttons page.
QWidget *btnsPage = new QWidget;
QVBoxLayout *bmainLayout = new QVBoxLayout(btnsPage);
QHBoxLayout *btnsLayout = new QHBoxLayout;
btnsLayout->addWidget(m_installBtn, 0, Qt::AlignHCenter);
btnsLayout->addWidget(m_viewFileBtn, 0, Qt::AlignHCenter);
bmainLayout->addWidget(m_tipsLabel, 0, Qt::AlignHCenter);
bmainLayout->addSpacing(8);
bmainLayout->addLayout(btnsLayout);

// init progress page.
QWidget *progPage = new QWidget;
QVBoxLayout *progLayout = new QVBoxLayout(progPage);
progLayout->addWidget(m_progress, 0, Qt::AlignCenter);

// init refresh page.
QWidget *refPage = new QWidget;
QVBoxLayout *refLayout = new QVBoxLayout(refPage);
QLabel *tipsLabel = new QLabel(tr("Refreshing font cache, please wait..."));
tipsLabel->setStyleSheet("QLabel { color: #606060; font-size: 14px; }");
refLayout->addWidget(m_spinner, 0, Qt::AlignHCenter);
refLayout->addSpacing(5);
refLayout->addWidget(tipsLabel, 0, Qt::AlignHCenter);
m_spinner->setFixedSize(30, 30);

m_bottomLayout->addWidget(btnsPage);
m_bottomLayout->addWidget(progPage);
m_bottomLayout->addWidget(refPage);

m_tipsLabel->setStyleSheet("QLabel { color: #47790c; font-size: 14px; }");
m_tipsLabel->setVisible(false);
Expand All @@ -67,15 +96,12 @@ MultiFilePage::MultiFilePage(QWidget *parent)
m_viewFileBtn->setFixedSize(180, 36);
m_viewFileBtn->setVisible(false);
m_viewFileBtn->setVisible(false);
m_progress->setVisible(false);

QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addLayout(contentLayout);
mainLayout->addStretch();
mainLayout->addWidget(m_tipsLabel, 0, Qt::AlignHCenter);
mainLayout->addSpacing(8);
mainLayout->addWidget(m_progress, 0, Qt::AlignHCenter);
mainLayout->addLayout(btnsLayout);
mainLayout->addLayout(m_bottomLayout);

mainLayout->addStretch();
mainLayout->setSpacing(0);
mainLayout->setMargin(0);
Expand All @@ -84,6 +110,7 @@ MultiFilePage::MultiFilePage(QWidget *parent)
connect(m_installBtn, &QPushButton::clicked, this, &MultiFilePage::batchInstallation);
connect(m_viewFileBtn, &QPushButton::clicked, this, &MultiFilePage::onViewFileBtnClicked);
connect(m_fontManager, &DFontManager::installing, this, &MultiFilePage::onProgressChanged);
connect(m_refreshThread, &RefreshThread::refreshFinished, this, &MultiFilePage::onWorkerFinished);
}

MultiFilePage::~MultiFilePage()
Expand Down Expand Up @@ -147,6 +174,7 @@ void MultiFilePage::batchInstallation()

void MultiFilePage::onProgressChanged(const QString &filePath, const double &percent)
{
m_bottomLayout->setCurrentIndex(1);
m_installBtn->setVisible(false);
m_viewFileBtn->setVisible(false);
m_progress->setVisible(true);
Expand All @@ -157,17 +185,22 @@ void MultiFilePage::onProgressChanged(const QString &filePath, const double &per
m_listView->update();

if (percent == 100) {
onWorkerFinished();
m_refreshThread->start();
m_spinner->start();
m_bottomLayout->setCurrentIndex(2);
}
}

void MultiFilePage::onWorkerFinished()
{
m_spinner->stop();
m_bottomLayout->setCurrentIndex(0);
m_tipsLabel->setVisible(true);
m_installBtn->setVisible(false);
m_viewFileBtn->setVisible(true);
m_progress->setVisible(false);
m_progress->setValue(0);

refreshList();
}

Expand Down
8 changes: 8 additions & 0 deletions deepin-font-installer/multifilepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QStackedLayout>
#include "dfontinfomanager.h"
#include "dfontmanager.h"
#include "listview.h"
#include "listitem.h"
#include "progress.h"
#include "refreshthread.h"
#include "dspinner.h"

DWIDGET_USE_NAMESPACE

class MultiFilePage : public QWidget
{
Expand Down Expand Up @@ -59,6 +64,9 @@ private slots:
QPushButton *m_viewFileBtn;
Progress *m_progress;
QPixmap *m_iconPixmap;
RefreshThread *m_refreshThread;
QStackedLayout *m_bottomLayout;
DSpinner *m_spinner;

QList<DFontInfo *> m_fontInfoList;
QMap<QString, ListItem *> m_listItems;
Expand Down
41 changes: 41 additions & 0 deletions deepin-font-installer/refreshthread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: rekols <rekols@foxmail.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 3 of the License, or
* any later version.
*
* 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 "refreshthread.h"
#include <QProcess>

RefreshThread::RefreshThread(QObject *parent)
: QThread(parent)
{

}

RefreshThread::~RefreshThread()
{
}

void RefreshThread::run()
{
QProcess *process = new QProcess;
process->start("fc-cache");
process->waitForFinished(-1);
process->deleteLater();

emit refreshFinished();
}
40 changes: 40 additions & 0 deletions deepin-font-installer/refreshthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: rekols <rekols@foxmail.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 3 of the License, or
* any later version.
*
* 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 REFRESHTHREAD_H
#define REFRESHTHREAD_H

#include <QThread>

class RefreshThread : public QThread
{
Q_OBJECT

public:
RefreshThread(QObject *parent = nullptr);
~RefreshThread();

signals:
void refreshFinished();

protected:
void run();
};

#endif
10 changes: 7 additions & 3 deletions deepin-font-installer/translations/deepin-font-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>Same version installed</source>
<source>Other version installed: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Other version installed: %1</source>
<source>Installing</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Installing</source>
<source>Sample version installed</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down Expand Up @@ -71,6 +71,10 @@
<source>View font directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Refreshing font cache, please wait...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SingleFilePage</name>
Expand Down
7 changes: 6 additions & 1 deletion dfont-install/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QCryptographicHash>
#include <QJsonObject>
#include <QJsonDocument>
#include <QThread>
#include <QFile>
#include <QFileInfo>
#include <QProcess>
Expand Down Expand Up @@ -125,12 +126,13 @@ int main(int argc, char *argv[])
QFile::copy(file, target);
}

FcCacheUpdate();
// FcCacheUpdate();

const int currentIndex = fileList.indexOf(file);
const int count = fileList.count() - 1;

if (fileList.count() == 1) {
FcCacheUpdate();
std::cout << target.toUtf8().data() << std::endl;
} else {
QJsonObject object;
Expand All @@ -142,6 +144,9 @@ int main(int argc, char *argv[])
QByteArray array = document.toJson(QJsonDocument::Compact);

std::cout << array.data() << std::endl;

// output too fast will crash.
QThread::msleep(10);
}
}

Expand Down
1 change: 0 additions & 1 deletion libdeepin-font-installer/dfontmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <QProcess>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>

static DFontManager *INSTANCE = 0;

Expand Down

0 comments on commit 976b9f5

Please sign in to comment.