Diffstat (limited to 'noncore/unsupported/oipkg/packagelistitem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/oipkg/packagelistitem.cpp | 159 |
1 files changed, 112 insertions, 47 deletions
diff --git a/noncore/unsupported/oipkg/packagelistitem.cpp b/noncore/unsupported/oipkg/packagelistitem.cpp index 03bf477..4380393 100644 --- a/noncore/unsupported/oipkg/packagelistitem.cpp +++ b/noncore/unsupported/oipkg/packagelistitem.cpp | |||
@@ -8,69 +8,84 @@ | |||
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
10 | #include "packagelistitem.h" | 10 | #include "packagelistitem.h" |
11 | 11 | ||
12 | #include <qpe/resource.h> | 12 | #include <qpe/resource.h> |
13 | #include <qobject.h> | 13 | #include <qobject.h> |
14 | #include <qpopupmenu.h> | ||
15 | #include <qaction.h> | ||
14 | 16 | ||
15 | #include "debug.h" | 17 | #include "debug.h" |
16 | 18 | ||
17 | static QPixmap *pm_uninstalled=0; | 19 | static QPixmap *pm_uninstalled=0; |
18 | static QPixmap *pm_uninstalled_old=0; | 20 | static QPixmap *pm_uninstalled_old=0; |
19 | static QPixmap *pm_installed=0; | 21 | static QPixmap *pm_installed=0; |
20 | static QPixmap *pm_installed_old=0; | 22 | static QPixmap *pm_installed_old=0; |
21 | static QPixmap *pm_uninstall=0; | 23 | static QPixmap *pm_uninstall=0; |
22 | static QPixmap *pm_install=0; | 24 | static QPixmap *pm_install=0; |
23 | static QPixmap *pm_uninstalled_old_installed_new=0; | 25 | static QPixmap *pm_uninstalled_old_installed_new=0; |
24 | static QPixmap *pm_uninstalled_installed_old=0; | 26 | static QPixmap *pm_uninstalled_installed_old=0; |
25 | 27 | ||
26 | PackageListItem::PackageListItem(QListView* lv, Package *pi, PackageManagerSettings *s) | 28 | PackageListItem::PackageListItem(ListViewItemOipkg *parent, QString name, Type ittype) |
27 | :QCheckListItem(lv,pi->name(),CheckBox) | 29 | : ListViewItemOipkg(parent,name,ittype) |
28 | { | 30 | { |
29 | init(pi,s); | 31 | |
30 | } | 32 | } |
31 | 33 | ||
32 | PackageListItem::PackageListItem(QListViewItem *lvi, Package *pi, PackageManagerSettings *s) | 34 | PackageListItem::PackageListItem(QListView* lv, OipkgPackage *pi, PackageManagerSettings *s) |
33 | :QCheckListItem(lvi,pi->name(),CheckBox) | 35 | :ListViewItemOipkg(lv,pi->name(),ListViewItemOipkg::Package) |
34 | { | 36 | { |
35 | init(pi,s); | 37 | init(pi,s); |
36 | } | 38 | } |
37 | 39 | ||
38 | void PackageListItem::init( Package *pi, PackageManagerSettings *s) | 40 | PackageListItem::PackageListItem(ListViewItemOipkg *lvi, OipkgPackage *pi, PackageManagerSettings *s) |
41 | :ListViewItemOipkg(lvi,pi->name(),ListViewItemOipkg::Package) | ||
42 | { | ||
43 | init(pi,s); | ||
44 | } | ||
45 | PackageListItem::~PackageListItem() | ||
39 | { | 46 | { |
47 | delete popupMenu; | ||
48 | delete destsMenu; | ||
49 | } | ||
50 | |||
51 | void PackageListItem::init( OipkgPackage *pi, PackageManagerSettings *s) | ||
52 | { | ||
53 | popupMenu = new QPopupMenu( 0 ); | ||
54 | destsMenu = new QPopupMenu( 0 ); | ||
40 | package = pi; | 55 | package = pi; |
41 | settings = s; | 56 | settings = s; |
42 | setExpandable( true ); | 57 | setExpandable( true ); |
43 | QCheckListItem *item; | 58 | ListViewItemOipkg *item; |
44 | nameItem = new QCheckListItem( this, "" ); | 59 | nameItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute,"name" ); |
45 | item = new QCheckListItem( this, QObject::tr("Description: ")+pi->desc() ); | 60 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Description: ")+pi->desc() ); |
46 | item = new QCheckListItem( this, QObject::tr("Size: ")+pi->size() ); | 61 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Size: ")+pi->size() ); |
47 | destItem = new QCheckListItem( this, "" ); | 62 | destItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "dest" ); |
48 | linkItem = new QCheckListItem( this, "" ); | 63 | linkItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "link" ); |
49 | statusItem = new QCheckListItem( this, "" ); | 64 | statusItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "status" ); |
50 | QCheckListItem *otherItem = new QCheckListItem( this, QObject::tr("other") ); | 65 | ListViewItemOipkg *otherItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("other") ); |
51 | item = new QCheckListItem( otherItem, QObject::tr("Install Name: ")+pi->installName() ); | 66 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QObject::tr("Install Name: ")+pi->installName() ); |
52 | QDict<QString> *fields = pi->getFields(); | 67 | QDict<QString> *fields = pi->getFields(); |
53 | QDictIterator<QString> it( *fields ); | 68 | QDictIterator<QString> it( *fields ); |
54 | while ( it.current() ) { | 69 | while ( it.current() ) { |
55 | item = new QCheckListItem( otherItem, QString(it.currentKey()+": "+*it.current()) ); | 70 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QString(it.currentKey()+": "+*it.current()) ); |
56 | ++it; | 71 | ++it; |
57 | } | 72 | } |
58 | displayDetails(); | 73 | displayDetails(); |
59 | 74 | ||
60 | if (!pm_uninstalled) | 75 | if (!pm_uninstalled) |
61 | { | 76 | { |
62 | pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled")); | 77 | pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled")); |
63 | pm_uninstalled_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOld")); | 78 | pm_uninstalled_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOld")); |
64 | pm_uninstalled_old_installed_new = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOldinstalledNew")); | 79 | pm_uninstalled_old_installed_new = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOldinstalledNew")); |
65 | pm_uninstalled_installed_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledInstalledOld")); | 80 | pm_uninstalled_installed_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledInstalledOld")); |
66 | pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed")); | 81 | pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed")); |
67 | pm_installed_old = new QPixmap(Resource::loadPixmap("oipkg/installedOld")); | 82 | pm_installed_old = new QPixmap(Resource::loadPixmap("oipkg/installedOld")); |
68 | pm_install = new QPixmap(Resource::loadPixmap("oipkg/install")); | 83 | pm_install = new QPixmap(Resource::loadPixmap("oipkg/install")); |
69 | pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall")); | 84 | pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall")); |
70 | } | 85 | } |
71 | } | 86 | } |
72 | 87 | ||
73 | void PackageListItem::paintCell( QPainter *p, const QColorGroup & cg, | 88 | void PackageListItem::paintCell( QPainter *p, const QColorGroup & cg, |
74 | int column, int width, int alignment ) | 89 | int column, int width, int alignment ) |
75 | { | 90 | { |
76 | if ( !p ) | 91 | if ( !p ) |
@@ -112,25 +127,25 @@ QPixmap PackageListItem::statePixmap() const | |||
112 | { | 127 | { |
113 | bool installed = package->installed(); | 128 | bool installed = package->installed(); |
114 | bool old = package->isOld(); | 129 | bool old = package->isOld(); |
115 | bool verinstalled = package->otherInstalled(); | 130 | bool verinstalled = package->otherInstalled(); |
116 | if ( !package->toProcess() ) { | 131 | if ( !package->toProcess() ) { |
117 | if ( !installed ) | 132 | if ( !installed ) |
118 | if (old) | 133 | if (old) |
119 | { | 134 | { |
120 | if (verinstalled) return *pm_uninstalled_old_installed_new; | 135 | if (verinstalled) return *pm_uninstalled_old_installed_new; |
121 | else return *pm_uninstalled_old; | 136 | else return *pm_uninstalled_old; |
122 | } | 137 | } |
123 | else | 138 | else |
124 | { | 139 | { |
125 | if (verinstalled) return *pm_uninstalled_installed_old; | 140 | if (verinstalled) return *pm_uninstalled_installed_old; |
126 | else return *pm_uninstalled; | 141 | else return *pm_uninstalled; |
127 | } | 142 | } |
128 | else | 143 | else |
129 | if (old) return *pm_installed_old; | 144 | if (old) return *pm_installed_old; |
130 | else return *pm_installed; | 145 | else return *pm_installed; |
131 | } else { //toProcess() == true | 146 | } else { //toProcess() == true |
132 | if ( !installed ) | 147 | if ( !installed ) |
133 | return *pm_install; | 148 | return *pm_install; |
134 | else | 149 | else |
135 | return *pm_uninstall; | 150 | return *pm_uninstall; |
136 | } | 151 | } |
@@ -157,18 +172,68 @@ void PackageListItem::setOn( bool b ) | |||
157 | package->setLink( settings->createLinks() ); | 172 | package->setLink( settings->createLinks() ); |
158 | displayDetails(); | 173 | displayDetails(); |
159 | } | 174 | } |
160 | 175 | ||
161 | void PackageListItem::displayDetails() | 176 | void PackageListItem::displayDetails() |
162 | { | 177 | { |
163 | QString sod; | 178 | QString sod; |
164 | sod += package->sizeUnits().isEmpty()?QString(""):QString(package->sizeUnits()); | 179 | sod += package->sizeUnits().isEmpty()?QString(""):QString(package->sizeUnits()); |
165 | //sod += QString(package->dest().isEmpty()?"":QObject::tr(" on ")+package->dest()); | 180 | //sod += QString(package->dest().isEmpty()?"":QObject::tr(" on ")+package->dest()); |
166 | sod += package->dest().isEmpty()?QString(""):QString(QObject::tr(" on ")+package->dest()); | 181 | sod += package->dest().isEmpty()?QString(""):QString(QObject::tr(" on ")+package->dest()); |
167 | sod = sod.isEmpty()?QString(""):QString(" ("+sod+")"); | 182 | sod = sod.isEmpty()?QString(""):QString(" ("+sod+")"); |
168 | setText(0, package->name()+sod ); | 183 | setText(0, package->name()+sod ); |
169 | nameItem->setText( 0, QObject::tr("Name: ")+package->name()); | 184 | nameItem->setText( 0, QObject::tr("Name: ")+package->name()); |
170 | linkItem->setText( 0, QObject::tr("Link: ")+(package->link()?QObject::tr("Yes"):QObject::tr("No"))); | 185 | linkItem->setText( 0, QObject::tr("Link: ")+(package->link()?QObject::tr("Yes"):QObject::tr("No"))); |
171 | destItem->setText( 0, QObject::tr("Destination: ")+package->dest() ); | 186 | destItem->setText( 0, QObject::tr("Destination: ")+package->dest() ); |
172 | statusItem->setText( 0, QObject::tr("Status: ")+package->status() ); | 187 | statusItem->setText( 0, QObject::tr("Status: ")+package->status() ); |
173 | repaint(); | 188 | repaint(); |
174 | } | 189 | } |
190 | |||
191 | QPopupMenu* PackageListItem::getPopupMenu() | ||
192 | { | ||
193 | popupMenu->clear(); | ||
194 | destsMenu->clear(); | ||
195 | |||
196 | QAction *popupAction; | ||
197 | qDebug("PackageListItem::showPopup "); | ||
198 | |||
199 | if (!package->installed()){ | ||
200 | popupMenu->insertItem( QObject::tr("Install to"), destsMenu ); | ||
201 | QStringList dests = settings->getDestinationNames(); | ||
202 | QString ad = settings->getDestinationName(); | ||
203 | for (uint i = 0; i < dests.count(); i++ ) | ||
204 | { | ||
205 | popupAction = new QAction( dests[i], QString::null, 0, popupMenu, 0 ); | ||
206 | popupAction->addTo( destsMenu ); | ||
207 | if ( dests[i] == ad && getPackage()->toInstall() ) | ||
208 | { | ||
209 | popupAction->setToggleAction( true ); | ||
210 | popupAction->setOn(true); | ||
211 | } | ||
212 | } | ||
213 | connect( destsMenu, SIGNAL( activated( int ) ), | ||
214 | this, SLOT( menuAction( int ) ) ); | ||
215 | popupMenu->popup( QCursor::pos() ); | ||
216 | }else{ | ||
217 | popupMenu->insertItem( QObject::tr("Remove")); | ||
218 | connect( popupMenu, SIGNAL( activated( int ) ), | ||
219 | this, SLOT( menuAction( int ) ) ); | ||
220 | popupMenu->popup( QCursor::pos() ); | ||
221 | } | ||
222 | return popupMenu; | ||
223 | } | ||
224 | |||
225 | void PackageListItem::menuAction( int i ) | ||
226 | { | ||
227 | if (package->installed()){ | ||
228 | package->setDest( destsMenu->text(i) ); | ||
229 | package->setLink( settings->createLinks() ); | ||
230 | } | ||
231 | package->setOn(); | ||
232 | displayDetails(); | ||
233 | } | ||
234 | |||
235 | //void PackageListItem::toggleProcess() | ||
236 | //{ | ||
237 | // package->toggleProcess() ; | ||
238 | // displayDetails(); | ||
239 | //} \ No newline at end of file | ||