-rw-r--r-- | noncore/unsupported/oipkg/packagelistitem.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/unsupported/oipkg/packagelistitem.cpp b/noncore/unsupported/oipkg/packagelistitem.cpp index 4380393..51d024b 100644 --- a/noncore/unsupported/oipkg/packagelistitem.cpp +++ b/noncore/unsupported/oipkg/packagelistitem.cpp | |||
@@ -1,239 +1,239 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
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> | 14 | #include <qpopupmenu.h> |
15 | #include <qaction.h> | 15 | #include <qaction.h> |
16 | 16 | ||
17 | #include "debug.h" | 17 | #include "debug.h" |
18 | 18 | ||
19 | static QPixmap *pm_uninstalled=0; | 19 | static QPixmap *pm_uninstalled=0; |
20 | static QPixmap *pm_uninstalled_old=0; | 20 | static QPixmap *pm_uninstalled_old=0; |
21 | static QPixmap *pm_installed=0; | 21 | static QPixmap *pm_installed=0; |
22 | static QPixmap *pm_installed_old=0; | 22 | static QPixmap *pm_installed_old=0; |
23 | static QPixmap *pm_uninstall=0; | 23 | static QPixmap *pm_uninstall=0; |
24 | static QPixmap *pm_install=0; | 24 | static QPixmap *pm_install=0; |
25 | static QPixmap *pm_uninstalled_old_installed_new=0; | 25 | static QPixmap *pm_uninstalled_old_installed_new=0; |
26 | static QPixmap *pm_uninstalled_installed_old=0; | 26 | static QPixmap *pm_uninstalled_installed_old=0; |
27 | 27 | ||
28 | PackageListItem::PackageListItem(ListViewItemOipkg *parent, QString name, Type ittype) | 28 | PackageListItem::PackageListItem(ListViewItemOipkg *parent, QString name, Type ittype) |
29 | : ListViewItemOipkg(parent,name,ittype) | 29 | : ListViewItemOipkg(parent,name,ittype) |
30 | { | 30 | { |
31 | 31 | ||
32 | } | 32 | } |
33 | 33 | ||
34 | PackageListItem::PackageListItem(QListView* lv, OipkgPackage *pi, PackageManagerSettings *s) | 34 | PackageListItem::PackageListItem(QListView* lv, OipkgPackage *pi, PackageManagerSettings *s) |
35 | :ListViewItemOipkg(lv,pi->name(),ListViewItemOipkg::Package) | 35 | :ListViewItemOipkg(lv,pi->name(),ListViewItemOipkg::Package) |
36 | { | 36 | { |
37 | init(pi,s); | 37 | init(pi,s); |
38 | } | 38 | } |
39 | 39 | ||
40 | PackageListItem::PackageListItem(ListViewItemOipkg *lvi, OipkgPackage *pi, PackageManagerSettings *s) | 40 | PackageListItem::PackageListItem(ListViewItemOipkg *lvi, OipkgPackage *pi, PackageManagerSettings *s) |
41 | :ListViewItemOipkg(lvi,pi->name(),ListViewItemOipkg::Package) | 41 | :ListViewItemOipkg(lvi,pi->name(),ListViewItemOipkg::Package) |
42 | { | 42 | { |
43 | init(pi,s); | 43 | init(pi,s); |
44 | } | 44 | } |
45 | PackageListItem::~PackageListItem() | 45 | PackageListItem::~PackageListItem() |
46 | { | 46 | { |
47 | delete popupMenu; | 47 | delete popupMenu; |
48 | delete destsMenu; | 48 | delete destsMenu; |
49 | } | 49 | } |
50 | 50 | ||
51 | void PackageListItem::init( OipkgPackage *pi, PackageManagerSettings *s) | 51 | void PackageListItem::init( OipkgPackage *pi, PackageManagerSettings *s) |
52 | { | 52 | { |
53 | popupMenu = new QPopupMenu( 0 ); | 53 | popupMenu = new QPopupMenu( 0 ); |
54 | destsMenu = new QPopupMenu( 0 ); | 54 | destsMenu = new QPopupMenu( 0 ); |
55 | package = pi; | 55 | package = pi; |
56 | settings = s; | 56 | settings = s; |
57 | setExpandable( true ); | 57 | setExpandable( true ); |
58 | ListViewItemOipkg *item; | 58 | ListViewItemOipkg *item; |
59 | nameItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute,"name" ); | 59 | nameItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute,"name" ); |
60 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Description: ")+pi->desc() ); | 60 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Description: ")+pi->desc() ); |
61 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Size: ")+pi->size() ); | 61 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Size: ")+pi->size() ); |
62 | destItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "dest" ); | 62 | destItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "dest" ); |
63 | linkItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "link" ); | 63 | linkItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "link" ); |
64 | statusItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "status" ); | 64 | statusItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "status" ); |
65 | ListViewItemOipkg *otherItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("other") ); | 65 | ListViewItemOipkg *otherItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("other") ); |
66 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QObject::tr("Install Name: ")+pi->installName() ); | 66 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QObject::tr("Install Name: ")+pi->installName() ); |
67 | QDict<QString> *fields = pi->getFields(); | 67 | QDict<QString> *fields = pi->getFields(); |
68 | QDictIterator<QString> it( *fields ); | 68 | QDictIterator<QString> it( *fields ); |
69 | while ( it.current() ) { | 69 | while ( it.current() ) { |
70 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QString(it.currentKey()+": "+*it.current()) ); | 70 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QString(it.currentKey()+": "+*it.current()) ); |
71 | ++it; | 71 | ++it; |
72 | } | 72 | } |
73 | displayDetails(); | 73 | displayDetails(); |
74 | 74 | ||
75 | if (!pm_uninstalled) | 75 | if (!pm_uninstalled) |
76 | { | 76 | { |
77 | pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled")); | 77 | pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled")); |
78 | pm_uninstalled_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOld")); | 78 | pm_uninstalled_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOld")); |
79 | pm_uninstalled_old_installed_new = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOldinstalledNew")); | 79 | pm_uninstalled_old_installed_new = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOldinstalledNew")); |
80 | pm_uninstalled_installed_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledInstalledOld")); | 80 | pm_uninstalled_installed_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledInstalledOld")); |
81 | pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed")); | 81 | pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed")); |
82 | pm_installed_old = new QPixmap(Resource::loadPixmap("oipkg/installedOld")); | 82 | pm_installed_old = new QPixmap(Resource::loadPixmap("oipkg/installedOld")); |
83 | pm_install = new QPixmap(Resource::loadPixmap("oipkg/install")); | 83 | pm_install = new QPixmap(Resource::loadPixmap("oipkg/install")); |
84 | pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall")); | 84 | pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall")); |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | void PackageListItem::paintCell( QPainter *p, const QColorGroup & cg, | 88 | void PackageListItem::paintCell( QPainter *p, const QColorGroup & cg, |
89 | int column, int width, int alignment ) | 89 | int column, int width, int alignment ) |
90 | { | 90 | { |
91 | if ( !p ) | 91 | if ( !p ) |
92 | return; | 92 | return; |
93 | 93 | ||
94 | p->fillRect( 0, 0, width, height(), | 94 | p->fillRect( 0, 0, width, height(), |
95 | isSelected()? cg.highlight() : cg.base() ); | 95 | isSelected()? cg.highlight() : cg.base() ); |
96 | 96 | ||
97 | if ( column != 0 ) { | 97 | if ( column != 0 ) { |
98 | // The rest is text | 98 | // The rest is text |
99 | QListViewItem::paintCell( p, cg, column, width, alignment ); | 99 | QListViewItem::paintCell( p, cg, column, width, alignment ); |
100 | return; | 100 | return; |
101 | } | 101 | } |
102 | 102 | ||
103 | QListView *lv = listView(); | 103 | QListView *lv = listView(); |
104 | if ( !lv ) | 104 | if ( !lv ) |
105 | return; | 105 | return; |
106 | int marg = lv->itemMargin(); | 106 | int marg = lv->itemMargin(); |
107 | int r = marg; | 107 | int r = marg; |
108 | 108 | ||
109 | QPixmap pm = statePixmap(); | 109 | QPixmap pm = statePixmap(); |
110 | p->drawPixmap(marg,(height()-pm.height())/2,pm); | 110 | p->drawPixmap(marg,(height()-pm.height())/2,pm); |
111 | r += pm.width()+1; | 111 | r += pm.width()+1; |
112 | 112 | ||
113 | p->translate( r, 0 ); | 113 | p->translate( r, 0 ); |
114 | QListViewItem::paintCell( p, cg, column, width - r, alignment ); | 114 | QListViewItem::paintCell( p, cg, column, width - r, alignment ); |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | void PackageListItem::paintFocus( QPainter *p, const QColorGroup & cg, | 118 | void PackageListItem::paintFocus( QPainter *p, const QColorGroup & cg, |
119 | const QRect & r ) | 119 | const QRect & r ) |
120 | { | 120 | { |
121 | // Skip QCheckListItem | 121 | // Skip QCheckListItem |
122 | // (makes you wonder what we're getting from QCheckListItem) | 122 | // (makes you wonder what we're getting from QCheckListItem) |
123 | QListViewItem::paintFocus(p,cg,r); | 123 | QListViewItem::paintFocus(p,cg,r); |
124 | } | 124 | } |
125 | 125 | ||
126 | QPixmap PackageListItem::statePixmap() const | 126 | QPixmap PackageListItem::statePixmap() const |
127 | { | 127 | { |
128 | bool installed = package->installed(); | 128 | bool installed = package->installed(); |
129 | bool old = package->isOld(); | 129 | bool old = package->isOld(); |
130 | bool verinstalled = package->otherInstalled(); | 130 | bool verinstalled = package->otherInstalled(); |
131 | if ( !package->toProcess() ) { | 131 | if ( !package->toProcess() ) { |
132 | if ( !installed ) | 132 | if ( !installed ) |
133 | if (old) | 133 | if (old) |
134 | { | 134 | { |
135 | if (verinstalled) return *pm_uninstalled_old_installed_new; | 135 | if (verinstalled) return *pm_uninstalled_old_installed_new; |
136 | else return *pm_uninstalled_old; | 136 | else return *pm_uninstalled_old; |
137 | } | 137 | } |
138 | else | 138 | else |
139 | { | 139 | { |
140 | if (verinstalled) return *pm_uninstalled_installed_old; | 140 | if (verinstalled) return *pm_uninstalled_installed_old; |
141 | else return *pm_uninstalled; | 141 | else return *pm_uninstalled; |
142 | } | 142 | } |
143 | else | 143 | else |
144 | if (old) return *pm_installed_old; | 144 | if (old) return *pm_installed_old; |
145 | else return *pm_installed; | 145 | else return *pm_installed; |
146 | } else { //toProcess() == true | 146 | } else { //toProcess() == true |
147 | if ( !installed ) | 147 | if ( !installed ) |
148 | return *pm_install; | 148 | return *pm_install; |
149 | else | 149 | else |
150 | return *pm_uninstall; | 150 | return *pm_uninstall; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | QString PackageListItem::key( int column, bool ascending ) const | 154 | QString PackageListItem::key( int column, bool ascending ) const |
155 | { | 155 | { |
156 | if ( column == 2 ) { | 156 | if ( column == 2 ) { |
157 | QString t = text(2); | 157 | QString t = text(2); |
158 | double bytes=t.toDouble(); | 158 | double bytes=t.toDouble(); |
159 | if ( t.contains('M') ) bytes*=1024*1024; | 159 | if ( t.contains('M') ) bytes*=1024*1024; |
160 | else if ( t.contains('K') || t.contains('k') ) bytes*=1024; | 160 | else if ( t.contains('K') || t.contains('k') ) bytes*=1024; |
161 | if ( !ascending ) bytes=999999999-bytes; | 161 | if ( !ascending ) bytes=999999999-bytes; |
162 | return QString().sprintf("%09d",(int)bytes); | 162 | return QString().sprintf("%09d",(int)bytes); |
163 | } else { | 163 | } else { |
164 | return QListViewItem::key(column,ascending); | 164 | return QListViewItem::key(column,ascending); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | void PackageListItem::setOn( bool b ) | 168 | void PackageListItem::setOn( bool b ) |
169 | { | 169 | { |
170 | QCheckListItem::setOn( b ); | 170 | QCheckListItem::setOn( b ); |
171 | package->toggleProcess(); | 171 | package->toggleProcess(); |
172 | package->setLink( settings->createLinks() ); | 172 | package->setLink( settings->createLinks() ); |
173 | displayDetails(); | 173 | displayDetails(); |
174 | } | 174 | } |
175 | 175 | ||
176 | void PackageListItem::displayDetails() | 176 | void PackageListItem::displayDetails() |
177 | { | 177 | { |
178 | QString sod; | 178 | QString sod; |
179 | sod += package->sizeUnits().isEmpty()?QString(""):QString(package->sizeUnits()); | 179 | sod += package->sizeUnits().isEmpty()?QString(""):QString(package->sizeUnits()); |
180 | //sod += QString(package->dest().isEmpty()?"":QObject::tr(" on ")+package->dest()); | 180 | //sod += QString(package->dest().isEmpty()?"":QObject::tr(" on ")+package->dest()); |
181 | sod += package->dest().isEmpty()?QString(""):QString(QObject::tr(" on ")+package->dest()); | 181 | sod += package->dest().isEmpty()?QString(""):QString(QObject::tr(" on ")+package->dest()); |
182 | sod = sod.isEmpty()?QString(""):QString(" ("+sod+")"); | 182 | sod = sod.isEmpty()?QString(""):QString(" ("+sod+")"); |
183 | setText(0, package->name()+sod ); | 183 | setText(0, package->name()+sod ); |
184 | nameItem->setText( 0, QObject::tr("Name: ")+package->name()); | 184 | nameItem->setText( 0, QObject::tr("Name: ")+package->name()); |
185 | 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"))); |
186 | destItem->setText( 0, QObject::tr("Destination: ")+package->dest() ); | 186 | destItem->setText( 0, QObject::tr("Destination: ")+package->dest() ); |
187 | statusItem->setText( 0, QObject::tr("Status: ")+package->status() ); | 187 | statusItem->setText( 0, QObject::tr("Status: ")+package->status() ); |
188 | repaint(); | 188 | repaint(); |
189 | } | 189 | } |
190 | 190 | ||
191 | QPopupMenu* PackageListItem::getPopupMenu() | 191 | QPopupMenu* PackageListItem::getPopupMenu() |
192 | { | 192 | { |
193 | popupMenu->clear(); | 193 | popupMenu->clear(); |
194 | destsMenu->clear(); | 194 | destsMenu->clear(); |
195 | 195 | ||
196 | QAction *popupAction; | 196 | QAction *popupAction; |
197 | qDebug("PackageListItem::showPopup "); | 197 | qDebug("PackageListItem::showPopup "); |
198 | 198 | ||
199 | if (!package->installed()){ | 199 | if (!package->installed()){ |
200 | popupMenu->insertItem( QObject::tr("Install to"), destsMenu ); | 200 | popupMenu->insertItem( QObject::tr("Install to"), destsMenu ); |
201 | QStringList dests = settings->getDestinationNames(); | 201 | QStringList dests = settings->getDestinationNames(); |
202 | QString ad = settings->getDestinationName(); | 202 | QString ad = settings->getDestinationName(); |
203 | for (uint i = 0; i < dests.count(); i++ ) | 203 | for (uint i = 0; i < dests.count(); i++ ) |
204 | { | 204 | { |
205 | popupAction = new QAction( dests[i], QString::null, 0, popupMenu, 0 ); | 205 | popupAction = new QAction( dests[i], QString::null, 0, popupMenu, 0 ); |
206 | popupAction->addTo( destsMenu ); | 206 | popupAction->addTo( destsMenu ); |
207 | if ( dests[i] == ad && getPackage()->toInstall() ) | 207 | if ( dests[i] == ad && getPackage()->toInstall() ) |
208 | { | 208 | { |
209 | popupAction->setToggleAction( true ); | 209 | popupAction->setToggleAction( true ); |
210 | popupAction->setOn(true); | 210 | popupAction->setOn(true); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | connect( destsMenu, SIGNAL( activated( int ) ), | 213 | connect( destsMenu, SIGNAL( activated( int ) ), |
214 | this, SLOT( menuAction( int ) ) ); | 214 | this, SLOT( menuAction( int ) ) ); |
215 | popupMenu->popup( QCursor::pos() ); | 215 | popupMenu->popup( QCursor::pos() ); |
216 | }else{ | 216 | }else{ |
217 | popupMenu->insertItem( QObject::tr("Remove")); | 217 | popupMenu->insertItem( QObject::tr("Remove")); |
218 | connect( popupMenu, SIGNAL( activated( int ) ), | 218 | connect( popupMenu, SIGNAL( activated( int ) ), |
219 | this, SLOT( menuAction( int ) ) ); | 219 | this, SLOT( menuAction( int ) ) ); |
220 | popupMenu->popup( QCursor::pos() ); | 220 | popupMenu->popup( QCursor::pos() ); |
221 | } | 221 | } |
222 | return popupMenu; | 222 | return popupMenu; |
223 | } | 223 | } |
224 | 224 | ||
225 | void PackageListItem::menuAction( int i ) | 225 | void PackageListItem::menuAction( int i ) |
226 | { | 226 | { |
227 | if (package->installed()){ | 227 | if (!package->installed()){ |
228 | package->setDest( destsMenu->text(i) ); | 228 | package->setDest( destsMenu->text(i) ); |
229 | package->setLink( settings->createLinks() ); | 229 | package->setLink( settings->createLinks() ); |
230 | } | 230 | } |
231 | package->setOn(); | 231 | package->setOn(); |
232 | displayDetails(); | 232 | displayDetails(); |
233 | } | 233 | } |
234 | 234 | ||
235 | //void PackageListItem::toggleProcess() | 235 | //void PackageListItem::toggleProcess() |
236 | //{ | 236 | //{ |
237 | // package->toggleProcess() ; | 237 | // package->toggleProcess() ; |
238 | // displayDetails(); | 238 | // displayDetails(); |
239 | //} \ No newline at end of file | 239 | //} |