added app list backup, helper shell scripts
[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         explicit ListItemDelegate(QObject *parent=0) : QStyledItemDelegate(parent) {}
60         virtual ~ListItemDelegate() {}
61
62         void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
63         QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
64         void loadIcons();
65
66 private:
67         ListItemDelegate(const ListItemDelegate& old);
68         ListItemDelegate operator= (const ListItemDelegate& old);
69
70         QPixmap iDefaultIcon;
71         QPixmap iIconPkgInstall;
72         QPixmap iIconPkgUpgrade;
73         QPixmap iIconPkgRemove;
74         QPixmap iIconPkgNoOpInstalled;
75         QPixmap iIconPkgNoOpNotInstalled;
76         QPixmap iIconPkgNoOpInstalledUpgradeable;
77 };
78
79
80 class PackageView : public QMainWindow
81 {
82     Q_OBJECT
83
84 public:
85
86         enum sortOrder { SortAlpha, SortDateDesc, SortSizeDesc };
87
88         explicit PackageView(QWidget *parent);
89         virtual ~PackageView();
90
91         void openWin();
92         void resizeEvent(QResizeEvent* event);
93         void setAptInterface(AAptInterface* a_) { iAptInterface=a_; }
94         void setSettings(Settings* s_) { iSettings=s_; }
95         dimmer* mydimmer() { return iDimmer; }
96         void disableMenu();
97         void enableMenu();
98         void setStatFilter(Package::packageStatus f_);
99         void setSortOrder(sortOrder s_) { iSortOrder = s_; }
100         void clearSelections();
101         void setSearchText(QString text);
102         void setSearchOptions(bool pkgname, bool dispname, bool dshort, bool dlong);
103
104         void show() {
105                 if( !isVisible() ) {
106                         /*
107                         QRect r = dynamic_cast<QMainWindow*>(this->parent())->rect();
108                         if(r.width() < r.height()) {
109                                 this->setAttribute(Qt::WA_Maemo5PortraitOrientation);
110                         }
111                         else {
112                                 if( dynamic_cast<QMainWindow*>(this->parent())->testAttribute( Qt::WA_Maemo5AutoOrientation ) ) {
113                                         this->setAttribute( Qt::WA_Maemo5AutoOrientation );
114                                 } else {
115                                         this->setAttribute( Qt::WA_Maemo5LandscapeOrientation );
116                                 }
117                                 this->setAttribute(Qt::WA_Maemo5StackedWindow);
118                                 this->setWindowFlags( Qt::Window );
119                         }
120                         */
121 #ifdef Q_WS_MAEMO_5
122                         this->setAttribute(Qt::WA_Maemo5StackedWindow);
123                         this->setWindowFlags( Qt::Window );
124 #endif
125                 }
126                 QMainWindow::show();
127         }
128
129         static const int CatFilterAllMarked = 0;
130         static const int CatFilterAllUser = 1;
131         static const int CatFilterBlacklisted = 16;
132
133 public slots:
134         void orientationChanged();
135         void on_actionSearch_triggered();
136
137 protected:
138     void changeEvent(QEvent *e);
139         AAptInterface* iAptInterface;
140         //MainWindow::operation iOperation;
141         void closeEvent(QCloseEvent *event);
142
143 private:
144         PackageView(const PackageView& old);
145         PackageView operator= (const PackageView& old);
146
147         bool doFilterCategory(Package* pkg);
148         QString generateSortString(Package* pkg);
149         void addListItem(Package* pkg_, QString listname_);
150         void updateLabel(void);
151         void resetWindow();
152         void clearSearch();
153
154     Ui::PackageView *ui;
155         MainWindow* iMainWindow;
156         QBoxLayout* iPkgLayout;
157         dimmer* iDimmer;
158         QLabel* iListCoverLabel;
159         Settings* iSettings;
160
161         QStringList iCatFilterLabels;
162         QStringList iCatFilterStrings;
163         int iSelectedCatFilter;
164         int iDefaultCatFilter;
165
166         QStringList iStatFilterLabels;
167         int iSelectedStatFilter;
168         sortOrder iSortOrder;
169         bool iSortNoticeShown;
170
171         QList<Package*> iSearchResults;
172         QString iPrevSearchText;
173         KeyEventGrabber* iKeyFilter;
174
175         bool iSearchPkgName;
176         bool iSearchDisplayName;
177         bool iSearchDescShort;
178         bool iSearchDescLong;
179
180         int iPackagesEmptySort;
181
182 private slots:
183         void on_actionStore_list_triggered();
184  void on_pushButton_searchOptions_clicked();
185  void on_actionRestore_all_triggered();
186  void on_actionSave_selections_triggered();
187         void on_actionLoad_selections_triggered();
188         void on_btn_Sort_clicked();
189         void on_actionView_log_triggered();
190         void on_actionUpgrade_all_triggered();
191         void on_lineEdit_textEdited(QString );
192         void on_btn_searchClose_clicked();
193         void on_actionHelp_triggered();
194         void on_btn_StatusFilter_clicked();
195         void on_btn_CategoryFilter_clicked();
196         void on_listWidget_itemClicked(QListWidgetItem* item);
197         void on_actionClear_selections_triggered();
198         void on_btn_Commit_clicked();
199 };
200
201
202 class KeyEventGrabber : public QObject
203 {
204         Q_OBJECT
205 public:
206         KeyEventGrabber(QObject* parent = 0);
207
208 protected:
209         bool eventFilter(QObject *obj, QEvent *event);
210
211 };
212
213
214 #endif // PACKAGEVIEW_H