/
packagescolumnwidget.cpp
149 lines (130 loc) · 5.23 KB
/
packagescolumnwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/** @file packagescolumnwidget.cpp
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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) 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</small>
*/
#include "ui/home/packagescolumnwidget.h"
#include "ui/widgets/packageswidget.h"
#include "ui/widgets/packageinfodialog.h"
#include "ui/widgets/homeitemwidget.h"
#include "ui/widgets/homemenuwidget.h"
#include <de/CallbackAction>
#include <de/Config>
#include <de/DirectoryListDialog>
#include <de/FileSystem>
#include <de/Loop>
#include <de/Package>
#include <de/PopupMenuWidget>
#include <de/ui/ActionItem>
#include <de/ui/SubwidgetItem>
#include <doomsday/DoomsdayApp>
#include <doomsday/Games>
#include <doomsday/resource/databundle.h>
using namespace de;
static PopupWidget *makePackageFoldersDialog()
{
Variable &pkgFolders = Config::get()["resource.packageFolder"];
auto *dlg = new DirectoryListDialog;
dlg->title().setFont("heading");
dlg->title().setText(QObject::tr("Add-on and Package Folders"));
dlg->message().setText(QObject::tr("The following folders are searched for resource packs and other add-ons:"));
dlg->setValue(pkgFolders.value());
dlg->setAcceptanceAction(new CallbackAction([dlg, &pkgFolders] ()
{
pkgFolders.set(dlg->value());
// Reload packages and recheck for game availability.
DoomsdayApp::app().initPackageFolders();
}));
return dlg;
}
DENG_GUI_PIMPL(PackagesColumnWidget)
{
PackagesWidget *packages;
LabelWidget *countLabel;
ui::ListData actions;
LoopCallback mainCall;
Impl(Public *i) : Base(i)
{
actions << new ui::SubwidgetItem(tr("..."), ui::Left, [this] () -> PopupWidget *
{
return new PackageInfoDialog(packages->actionPackage());
});
countLabel = new LabelWidget;
ScrollAreaWidget &area = self().scrollArea();
area.add(packages = new PackagesWidget(PackagesWidget::PopulationEnabled, "home-packages"));
packages->setActionItems(actions);
packages->setRightClickToOpenContextMenu(true);
packages->rule()
.setInput(Rule::Width, area.contentRule().width())
.setInput(Rule::Top, self().header().rule().bottom() + rule("gap"))
.setInput(Rule::Left, area.contentRule().left());
QObject::connect(packages, &PackagesWidget::itemCountChanged,
[this] (duint shown, duint total)
{
if (shown == total)
{
countLabel->setText(tr("%1 available").arg(total));
}
else
{
countLabel->setText(tr("%1 shown out of %2 available").arg(shown).arg(total));
}
});
// Column menu.
self().header().menuButton().setPopup([this] (PopupButtonWidget const &) -> PopupWidget * {
auto *menu = new PopupMenuWidget;
menu->items()
<< new ui::ActionItem(/*style().images().image("refresh"), */tr("Refresh"),
new CallbackAction([this] () { packages->refreshPackages(); }))
<< new ui::SubwidgetItem(tr("Folders"), ui::Left, makePackageFoldersDialog);
return menu;
}, ui::Down);
}
};
PackagesColumnWidget::PackagesColumnWidget()
: ColumnWidget("packages-column")
, d(new Impl(this))
{
header().title().setText(_E(s) "\n" _E(.) + tr("Packages"));
header().info().setText(tr("Browse available packages and install new ones."));
header().infoPanel().close(0);
// Total number of packages listed.
d->countLabel->setFont("small");
d->countLabel->setSizePolicy(ui::Expand, ui::Fixed);
d->countLabel->rule()
.setInput(Rule::Left, header().menuButton().rule().right())
.setInput(Rule::Height, header().menuButton().rule().height())
.setInput(Rule::Top, header().menuButton().rule().top());
header().add(d->countLabel);
scrollArea().setContentSize(maximumContentWidth(),
header().rule().height() +
rule("gap") +
d->packages->rule().height());
// Additional layout for the packages list.
d->packages->setFilterEditorMinimumY(scrollArea().margins().top());
d->packages->progress().rule().setRect(scrollArea().rule());
}
String PackagesColumnWidget::tabHeading() const
{
return tr("Packages");
}
void PackagesColumnWidget::setHighlighted(bool highlighted)
{
ColumnWidget::setHighlighted(highlighted);
if (highlighted)
{
root().setFocus(&d->packages->searchTermsEditor());
}
}