warn about system upgrade, minor fixes, code cleanup
[fapman] / packageview.h
1 /*
2         This file is part of Faster Application Manager.
3
4         Faster Application Manager is free software: you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation, either version 3 of the License, or
7         (at your option) any later version.
8
9         Faster Application Manager is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with Faster Application Manager.  If not, see <http://www.gnu.org/licenses/>.
16
17         (C) Heikki Holstila 2010
18 */
19
20 #ifndef PACKAGEVIEW_H
21 #define PACKAGEVIEW_H
22
23 #include <QtGui>
24 #include <QMainWindow>
25 #include "mainwindow.h"
26 #include "package.h"
27
28 namespace Ui {
29     class PackageView;
30 }
31
32 class MainWindow;
33 class AptInterface;
34 class Package;
35 class dimmer;
36 class KeyEventGrabber;
37 class Settings;
38
39 enum UserRoles { UserRoleName=Qt::UserRole, UserRoleVersion, UserRoleDescShort,
40                                  UserRoleMarked, UserRoleInstalled, UserRoleUpgradeable, UserRoleAvailVersion,
41                                  UserRoleCurrentStatFilter, UserRoleCurrentCatFilter, UserRoleBlacklisted };
42
43
44 class PackageListWidgetItem : public QListWidgetItem
45 {
46 public:
47         PackageListWidgetItem(Package* p_, QString name_);
48
49         Package* package() { return iPackage; }
50
51 private:
52         Package* iPackage;
53 };
54
55
56 class ListItemDelegate : public QStyledItemDelegate
57 {
58 public:
59         ListItemDelegate(QObject *parent=0) : QStyledItemDelegate (parent) { }
60
61         void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
62         QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
63         void loadIcons();
64
65 private:
66         QPixmap iDefaultIcon;
67         QPixmap iIconPkgInstall;
68         QPixmap iIconPkgUpgrade;
69         QPixmap iIconPkgRemove;
70         QPixmap iIconPkgNoOpInstalled;
71         QPixmap iIconPkgNoOpNotInstalled;
72         QPixmap iIconPkgNoOpInstalledUpgradeable;
73 };
74
75
76 class PackageView : public QMainWindow
77 {
78     Q_OBJECT
79
80 public:
81
82         enum sortOrder { SortAlpha, SortDateDesc, SortSizeDesc };
83
84     explicit PackageView(QWidget *parent = 0);
85     ~PackageView();
86         void openWin();
87         void resizeEvent(QResizeEvent* event);
88         void setAptInterface(AAptInterface* a_) { iAptInterface=a_; }
89         void setSettings(Settings* s_) { iSettings=s_; }
90         dimmer* mydimmer() { return iDimmer; }
91         void disableMenu();
92         void enableMenu();
93         void setStatFilter(Package::packageStatus f_);
94         void setSortOrder(sortOrder s_) { iSortOrder = s_; }
95         void clearSelections();
96         void setSearchText(QString text);
97         void setSearchOptions(bool pkgname, bool dispname, bool dshort, bool dlong);
98
99 #ifdef Q_WS_MAEMO_5             // workaround for buggy Qt autorotation
100         void show() {
101                 if( !isVisible() ) {
102                         QRect r = dynamic_cast<QMainWindow*>(this->parent())->rect();
103                         if(r.width() < r.height()) {
104                                 this->setAttribute(Qt::WA_Maemo5PortraitOrientation);
105                         }
106                         else {
107                                 if( dynamic_cast<QMainWindow*>(this->parent())->testAttribute( Qt::WA_Maemo5AutoOrientation ) ) {
108                                         this->setAttribute( Qt::WA_Maemo5AutoOrientation );
109                                 } else {
110                                         this->setAttribute( Qt::WA_Maemo5LandscapeOrientation );
111                                 }
112                                 this->setAttribute(Qt::WA_Maemo5StackedWindow);
113                                 this->setWindowFlags(Qt::Window);
114                         }
115                 }
116                 QMainWindow::show();
117         }
118 #endif
119
120         static const int CatFilterAllMarked = 0;
121         static const int CatFilterAllUser = 1;
122         static const int CatFilterBlacklisted = 16;
123
124 public slots:
125         void orientationChanged();
126         void on_actionSearch_triggered();
127
128 protected:
129     void changeEvent(QEvent *e);
130         AAptInterface* iAptInterface;
131         //MainWindow::operation iOperation;
132         void closeEvent(QCloseEvent *event);
133
134 private:
135         bool doFilterCategory(Package* pkg);
136         QString generateSortString(Package* pkg);
137         void addListItem(Package* pkg_, QString listname_);
138         void updateLabel(void);
139         void resetWindow();
140         void clearSearch();
141
142     Ui::PackageView *ui;
143         MainWindow* iMainWindow;
144         QBoxLayout* iPkgLayout;
145         dimmer* iDimmer;
146         QLabel* iListCoverLabel;
147         Settings* iSettings;
148
149         QStringList iCatFilterLabels;
150         QStringList iCatFilterStrings;
151         int iSelectedCatFilter;
152         int iDefaultCatFilter;
153
154         QStringList iStatFilterLabels;
155         int iSelectedStatFilter;
156         sortOrder iSortOrder;
157         bool iSortNoticeShown;
158
159         QList<Package*> iSearchResults;
160         QString iPrevSearchText;
161         KeyEventGrabber* iKeyFilter;
162
163         bool iSearchPkgName;
164         bool iSearchDisplayName;
165         bool iSearchDescShort;
166         bool iSearchDescLong;
167
168         int iPackagesEmptySort;
169
170 private slots:
171         void on_pushButton_searchOptions_clicked();
172  void on_actionRestore_all_triggered();
173  void on_actionSave_selections_triggered();
174         void on_actionLoad_selections_triggered();
175         void on_btn_Sort_clicked();
176         void on_actionView_log_triggered();
177         void on_actionUpgrade_all_triggered();
178         void on_lineEdit_textEdited(QString );
179         void on_btn_searchClose_clicked();
180         void on_actionHelp_triggered();
181         void on_btn_StatusFilter_clicked();
182         void on_btn_CategoryFilter_clicked();
183         void on_listWidget_itemClicked(QListWidgetItem* item);
184         void on_actionClear_selections_triggered();
185         void on_btn_Commit_clicked();
186 };
187
188
189 class KeyEventGrabber : public QObject
190 {
191         Q_OBJECT
192 public:
193         KeyEventGrabber(QObject* parent = 0);
194
195 protected:
196         bool eventFilter(QObject *obj, QEvent *event);
197
198 };
199
200
201 #endif // PACKAGEVIEW_H