Temporary commit

This commit is contained in:
RigoLigoRLC
2022-01-26 16:50:55 +08:00
parent 974d0032e3
commit 02530de7da
19 changed files with 409 additions and 91 deletions

View File

@@ -56,7 +56,12 @@ namespace SpkUi
void SpkPageAppDetails::SetWebsiteLink(QString url)
{
mWebsite->setText(QString("<a href=\"%1\">%1</a>").arg(url));
mWebsite->setText(QString("<a href=\"%1\">%2</a>").arg(url, tr("Website link")));
}
void SpkPageAppDetails::SetPackagePath(QString url)
{
mPkgPath = url;
}
SpkPageAppDetails::SpkPageAppDetails(QWidget *parent) : SpkPageBase(parent)
@@ -65,16 +70,20 @@ namespace SpkUi
mMainArea->setWidgetResizable(true);
mMainArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mLay4MainArea = new QVBoxLayout(this);
mLay4MainArea->addWidget(mMainArea);
mMainLay = new QVBoxLayout(this);
mMainLay->addWidget(mMainArea);
mMainLay = new QVBoxLayout(mMainArea);
mMainLay->setSizeConstraint(QLayout::SetMinAndMaxSize);
mBottomBar = new QWidget;
mMainLay->addWidget(mBottomBar);
mDetailsLay = new QVBoxLayout(mMainArea);
mDetailsLay->setSizeConstraint(QLayout::SetMinAndMaxSize);
mAppIcon = new QLabel;
mAppTitle = new QLabel;
mAppTitle->setObjectName("styDetTitle");
mAppTitle->setWordWrap(true);
mAppDescription = new QLabel;
mAppDescription->setObjectName("styDetDesc");
@@ -87,9 +96,11 @@ namespace SpkUi
mAppShortDesc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
mAppShortDesc->setMinimumWidth(100);
mVersion = new QLabel;
mVersion->setWordWrap(true);
mWebsite = new QLabel;
mPkgName = new QLabel;
mPkgName->setObjectName("styDetPkg");
mPkgName->setWordWrap(true);
mTitleLay = new QVBoxLayout;
mTitleLay->setAlignment(Qt::AlignTop);
@@ -132,18 +143,49 @@ namespace SpkUi
// mDetailWidget->setLayout(mDetailLay);
// mDetailWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
mMainLay->setAlignment(Qt::AlignTop);
mMainLay->addWidget(mIconTitleWidget);
mMainLay->addLayout(mDetailLay);
mMainLay->addWidget(mAppDescription);
mDetailsLay->setAlignment(Qt::AlignTop);
mDetailsLay->addWidget(mIconTitleWidget);
mDetailsLay->addLayout(mDetailLay);
mDetailsLay->addWidget(mAppDescription);
// mMainLay->addStretch();
mWid4MainArea = new QWidget;
mWid4MainArea->setLayout(mMainLay);
mWid4MainArea->setLayout(mDetailsLay);
mMainArea->setWidget(mWid4MainArea);
mWebsite->setTextFormat(Qt::RichText);
mWebsite->setOpenExternalLinks(true);
// Bottom bar buttons
mBottomBarLay = new QHBoxLayout;
mBottomBar->setLayout(mBottomBarLay);
mBtnDownload = new QPushButton;
mBtnDownload->setText(tr("Download"));
mBtnInstall = new QPushButton;
mBtnInstall->setText(tr("Install"));
mBtnUninstall = new QPushButton;
mBtnUninstall->setText(tr("Uninstall"));
mBtnRequestUpdate = new QPushButton;
mBtnRequestUpdate->setText(tr("Request Update"));
mBtnReport = new QPushButton;
mBtnReport->setText(tr("Report"));
mBottomBarLay->addStretch();
mBottomBarLay->addWidget(mBtnDownload);
mBottomBarLay->addWidget(mBtnInstall);
mBottomBarLay->addWidget(mBtnUninstall);
mBottomBarLay->addWidget(mBtnRequestUpdate);
mBottomBarLay->addWidget(mBtnReport);
connect(mBtnDownload, &QPushButton::clicked,
[=](){ emit RequestDownload(mAppTitle->text(), mPkgName->text(),
"/store/chat/icalingua/icalingua_2.4.4-Deus-non-vult_amd64.deb");
});
}
void SpkPageAppDetails::ResourceAcquisitionFinished(int id, ResourceResult result)

View File

@@ -66,7 +66,6 @@ namespace SpkUi
auto iconRes = RES->RequestResource(id, pkgName, SpkResource::ResourceType::AppIcon,
iconUrl, 0);
// TODO: cache scaled icons
QPixmap icon;
if(iconRes.status == SpkResource::ResourceStatus::Ready)
{
@@ -80,7 +79,6 @@ namespace SpkUi
RES->PurgeCachedResource(pkgName, SpkResource::ResourceType::AppIcon, 0);
}
}
//TODO: [TEST] prepare icons for loading entries
else
item->SetIcon(*mLoadingIcon);

View File

@@ -15,7 +15,18 @@ SpkUi::SpkPageDownloads::SpkPageDownloads(QWidget *parent) :
mScrollArea->setWidget(mScrollWidget);
mScrollArea->setWidgetResizable(true);
mMainLay->addWidget(mScrollArea);
mMainLay->addStretch();
setLayout(mMainLay);
mDownloadMgr = new SpkDownloadMgr(this);
connect(mDownloadMgr, &SpkDownloadMgr::DownloadProgressed,
this, &SpkPageDownloads::DownloadProgress);
mNextDownloadId = 0;
mCurrentStatus = Idle;
connect(mDownloadMgr, &SpkDownloadMgr::DownloadStopped,
this, &SpkPageDownloads::DownloadStopped);
}
SpkUi::SpkPageDownloads::~SpkPageDownloads()
@@ -25,13 +36,80 @@ SpkUi::SpkPageDownloads::~SpkPageDownloads()
void SpkUi::SpkPageDownloads::DownloadProgress(qint64 downloadedBytes, qint64 totalBytes, int id)
{
// TODO
if(!totalBytes)
return;
if(mCurrentStatus == Waiting && totalBytes)
{
mCurrentStatus = Downloading;
mEntries[id]->SetTotalBytes(totalBytes);
mEntries[id]->SetStatus(SpkDownloadEntry::Downloading);
}
mEntries[id]->Progress(downloadedBytes);
}
void SpkUi::SpkPageDownloads::AddDownloadTask(QString name, QString pkgName, QString path)
{
// Add a new download entry into the UI
auto entry = new SpkDownloadEntry;
auto iconData = RES->CacheLookup(pkgName, SpkResource::ResourceType::AppIcon, 0);
QPixmap icon;
if(iconData.status != SpkResource::ResourceStatus::Ready || !icon.loadFromData(iconData.data))
icon.load(":/icons/broken-icon.svg");
entry->SetBasicInfo(name, icon);
entry->SetStatus(SpkDownloadEntry::Waiting);
mEntries[mNextDownloadId] = entry;
mLayEntries->addWidget(entry);
if(mCurrentStatus != Idle)
mWaitingDownloads.enqueue({ mNextDownloadId, path }); // Queue download task for future
else
{
if(!mDownloadMgr->StartNewDownload(path, mNextDownloadId)) // Initiate a download task when idle
emit mDownloadMgr->DownloadStopped(SpkDownloadMgr::FailNoVaibleServer, mNextDownloadId);
else
{
mCurrentStatus = Waiting;
}
}
mNextDownloadId++;
}
void SpkUi::SpkPageDownloads::DownloadStopped(SpkDownloadMgr::TaskResult status, int id)
{
switch(status)
{
case SpkDownloadMgr::Success:
mEntries[id]->SetStatus(SpkDownloadEntry::ToBeInstalled);
break;
case SpkDownloadMgr::FailCannotCreateFile:
mEntries[id]->SetStatus(SpkDownloadEntry::Failed,
tr("Cannot create download file. Download failed."));
break;
case SpkDownloadMgr::FailNoVaibleServer:
mEntries[id]->SetStatus(SpkDownloadEntry::Failed,
tr("Connection unstable or server failure. Download failed."));
break;
case SpkDownloadMgr::Fail:
mEntries[id]->SetStatus(SpkDownloadEntry::Failed,
tr("Unknown error. Download failed."));
break;
}
// Continue next download task
if(!mWaitingDownloads.isEmpty())
{
auto nextTask = mWaitingDownloads.dequeue();
mDownloadMgr->StartNewDownload(nextTask.second, nextTask.first);
mCurrentStatus = Waiting;
}
else
{
mCurrentStatus = Idle;
}
}