|
Lines 30-35
Link Here
|
| 30 |
#include "mediaapplet.h" |
30 |
#include "mediaapplet.h" |
| 31 |
|
31 |
|
| 32 |
#include "preferencesdialog.h" |
32 |
#include "preferencesdialog.h" |
|
|
33 |
#include "prefs.h" |
| 33 |
|
34 |
|
| 34 |
extern "C" |
35 |
extern "C" |
| 35 |
{ |
36 |
{ |
|
Lines 48-62
MediaApplet::MediaApplet(const TQString& configFile, Type type, int actions, TQW
Link Here
|
| 48 |
{ |
49 |
{ |
| 49 |
if (!parent) |
50 |
if (!parent) |
| 50 |
setBackgroundMode(X11ParentRelative); |
51 |
setBackgroundMode(X11ParentRelative); |
| 51 |
|
52 |
|
| 52 |
setBackgroundOrigin(AncestorOrigin); |
53 |
setBackgroundOrigin(AncestorOrigin); |
| 53 |
|
54 |
|
| 54 |
setAcceptDrops(true); |
55 |
setAcceptDrops(true); |
| 55 |
|
56 |
|
| 56 |
loadConfig(); |
57 |
loadConfig(); |
| 57 |
|
58 |
|
|
|
59 |
m_manager = new FlowGridManager; |
| 60 |
m_manager->setConserveSpace(true); |
| 61 |
|
| 58 |
mpDirLister = new KDirLister(); |
62 |
mpDirLister = new KDirLister(); |
| 59 |
|
63 |
|
| 60 |
connect( mpDirLister, TQT_SIGNAL( clear() ), |
64 |
connect( mpDirLister, TQT_SIGNAL( clear() ), |
| 61 |
this, TQT_SLOT( slotClear() ) ); |
65 |
this, TQT_SLOT( slotClear() ) ); |
| 62 |
connect( mpDirLister, TQT_SIGNAL( started(const KURL&) ), |
66 |
connect( mpDirLister, TQT_SIGNAL( started(const KURL&) ), |
|
Lines 69-89
MediaApplet::MediaApplet(const TQString& configFile, Type type, int actions, TQW
Link Here
|
| 69 |
this, TQT_SLOT( slotDeleteItem( KFileItem * ) ) ); |
73 |
this, TQT_SLOT( slotDeleteItem( KFileItem * ) ) ); |
| 70 |
connect( mpDirLister, TQT_SIGNAL( refreshItems( const KFileItemList & ) ), |
74 |
connect( mpDirLister, TQT_SIGNAL( refreshItems( const KFileItemList & ) ), |
| 71 |
this, TQT_SLOT( slotRefreshItems( const KFileItemList & ) ) ); |
75 |
this, TQT_SLOT( slotRefreshItems( const KFileItemList & ) ) ); |
| 72 |
|
76 |
|
| 73 |
reloadList(); |
77 |
reloadList(); |
|
|
78 |
|
| 79 |
mpConfigAction = new KAction(i18n("Configure Storage Media..."), "configure", KShortcut(), |
| 80 |
this, SLOT(preferences()), this); |
| 81 |
|
| 82 |
mpAppletPopup = new TQPopupMenu(this); |
| 83 |
mpConfigAction->plug(mpAppletPopup); |
| 74 |
} |
84 |
} |
| 75 |
|
85 |
|
| 76 |
MediaApplet::~MediaApplet() |
86 |
MediaApplet::~MediaApplet() |
| 77 |
{ |
87 |
{ |
| 78 |
delete mpDirLister; |
88 |
delete mpDirLister; |
| 79 |
|
89 |
delete m_manager; |
|
|
90 |
delete mpAppletPopup; |
| 91 |
|
| 80 |
while (!mButtonList.isEmpty()) |
92 |
while (!mButtonList.isEmpty()) |
| 81 |
{ |
93 |
{ |
| 82 |
MediumButton *b = mButtonList.first(); |
94 |
MediumButton *b = mButtonList.first(); |
| 83 |
mButtonList.remove(b); |
95 |
mButtonList.remove(b); |
| 84 |
delete b; |
96 |
delete b; |
| 85 |
} |
97 |
} |
| 86 |
|
98 |
|
|
|
99 |
delete mpConfigAction; |
| 100 |
|
| 87 |
KGlobal::locale()->removeCatalogue("mediaapplet"); |
101 |
KGlobal::locale()->removeCatalogue("mediaapplet"); |
| 88 |
} |
102 |
} |
| 89 |
|
103 |
|
|
Lines 115-125
void MediaApplet::preferences()
Link Here
|
| 115 |
|
129 |
|
| 116 |
dialog.setExcludedMediumTypes(mExcludedTypesList); |
130 |
dialog.setExcludedMediumTypes(mExcludedTypesList); |
| 117 |
dialog.setExcludedMedia(mExcludedList); |
131 |
dialog.setExcludedMedia(mExcludedList); |
|
|
132 |
dialog.setIconDim(mIconDim); |
| 118 |
|
133 |
|
| 119 |
if(dialog.exec()) |
134 |
if(dialog.exec()) |
| 120 |
{ |
135 |
{ |
| 121 |
mExcludedTypesList = dialog.excludedMediumTypes(); |
136 |
mExcludedTypesList = dialog.excludedMediumTypes(); |
| 122 |
mExcludedList = dialog.excludedMedia(); |
137 |
mExcludedList = dialog.excludedMedia(); |
|
|
138 |
mIconDim = dialog.iconDim(); |
| 123 |
saveConfig(); |
139 |
saveConfig(); |
| 124 |
reloadList(); |
140 |
reloadList(); |
| 125 |
} |
141 |
} |
|
Lines 142-244
void MediaApplet::resizeEvent( TQResizeEvent *)
Link Here
|
| 142 |
|
158 |
|
| 143 |
void MediaApplet::arrangeButtons() |
159 |
void MediaApplet::arrangeButtons() |
| 144 |
{ |
160 |
{ |
| 145 |
int button_size = 1; |
161 |
unsigned border(2 + dimension()/12), space(1); |
| 146 |
int x_offset = 0; |
162 |
int idim, d(dimension() - border * 2); |
| 147 |
int y_offset = 0; |
163 |
// determine button size |
| 148 |
|
164 |
if (mIconDim == PreferencesDialog::SIZE_AUTO) |
| 149 |
// Determine upper bound for the button size |
|
|
| 150 |
MediumButtonList::iterator it; |
| 151 |
MediumButtonList::iterator end = mButtonList.end(); |
| 152 |
for ( it = mButtonList.begin(); it != end; ++it ) |
| 153 |
{ |
| 154 |
MediumButton *button = *it; |
| 155 |
|
| 156 |
button_size = std::max(button_size, |
| 157 |
orientation() == Qt::Vertical ? |
| 158 |
button->heightForWidth(width()) : |
| 159 |
button->widthForHeight(height()) ); |
| 160 |
// button->widthForHeight(height()) : |
| 161 |
// button->heightForWidth(width()) ); |
| 162 |
} |
| 163 |
|
| 164 |
int kicker_size; |
| 165 |
if (orientation() == Qt::Vertical) |
| 166 |
{ |
| 167 |
kicker_size = width(); |
| 168 |
} |
| 169 |
else |
| 170 |
{ |
| 171 |
kicker_size = height(); |
| 172 |
} |
| 173 |
|
| 174 |
unsigned int max_packed_buttons = kicker_size / button_size; |
| 175 |
// Center icons if we only have one column/row |
| 176 |
if (mButtonList.count() < max_packed_buttons) |
| 177 |
{ |
165 |
{ |
| 178 |
max_packed_buttons = TQMAX(uint(1), mButtonList.count()); |
166 |
if (d < 18) |
| 179 |
} |
|
|
| 180 |
max_packed_buttons = TQMAX(uint(1), max_packed_buttons); |
| 181 |
|
| 182 |
int padded_button_size = kicker_size / max_packed_buttons; |
| 183 |
mButtonSizeSum = 0; |
| 184 |
unsigned int pack_count = 0; |
| 185 |
|
| 186 |
// Arrange the buttons. If kicker is more than twice as high/wide |
| 187 |
// as the maximum preferred size of an icon, we put several icons |
| 188 |
// in one column/row |
| 189 |
for ( it = mButtonList.begin(); it != end; ++it ) |
| 190 |
{ |
| 191 |
MediumButton *button = *it; |
| 192 |
|
| 193 |
button->move(x_offset, y_offset); |
| 194 |
button->setPanelPosition(position()); |
| 195 |
|
| 196 |
if(pack_count == 0) |
| 197 |
{ |
167 |
{ |
| 198 |
mButtonSizeSum += button_size; |
168 |
idim = std::min(16, d); |
| 199 |
} |
169 |
} |
| 200 |
|
170 |
else if (d < 64) |
| 201 |
++pack_count; |
|
|
| 202 |
|
| 203 |
if(orientation() == Qt::Vertical) |
| 204 |
{ |
| 205 |
if (pack_count < max_packed_buttons) |
| 206 |
{ |
171 |
{ |
| 207 |
x_offset += padded_button_size; |
172 |
idim = 16; |
| 208 |
} |
173 |
} |
| 209 |
else |
174 |
else if (d < 80) |
| 210 |
{ |
175 |
{ |
| 211 |
x_offset = 0; |
176 |
idim = 20; |
| 212 |
y_offset += button_size; |
|
|
| 213 |
pack_count = 0; |
| 214 |
} |
| 215 |
|
| 216 |
button->resize(padded_button_size, button_size); |
| 217 |
} |
177 |
} |
| 218 |
else |
178 |
else if (d < 122) |
| 219 |
{ |
|
|
| 220 |
if (pack_count < max_packed_buttons) |
| 221 |
{ |
179 |
{ |
| 222 |
y_offset += padded_button_size; |
180 |
idim = 24; |
| 223 |
} |
181 |
} |
| 224 |
else |
182 |
else |
| 225 |
{ |
183 |
{ |
| 226 |
y_offset = 0; |
184 |
idim = 28; |
| 227 |
x_offset += button_size; |
|
|
| 228 |
pack_count = 0; |
| 229 |
} |
185 |
} |
| 230 |
|
186 |
} |
| 231 |
button->resize(button_size, padded_button_size); |
187 |
else |
| 232 |
} |
188 |
{ |
| 233 |
|
189 |
idim=std::min(mIconDim, d); |
|
|
190 |
} |
| 191 |
m_manager->setOrientation(orientation()); |
| 192 |
m_manager->setNumItems(mButtonList.size()); |
| 193 |
m_manager->setFrameSize(size()); |
| 194 |
m_manager->setItemSize(TQSize(idim, idim)); |
| 195 |
m_manager->setSpaceSize(TQSize(space, space)); |
| 196 |
m_manager->setBorderSize(orientation() == Horizontal ? |
| 197 |
TQSize(space, border) : TQSize(border, space)); |
| 198 |
|
| 199 |
for (unsigned index = 0; index < mButtonList.size(); index++) |
| 200 |
{ |
| 201 |
TQPoint pos = m_manager->pos(index); |
| 202 |
MediumButton *button = mButtonList[index]; |
| 203 |
button->move(pos.x(), pos.y()); |
| 204 |
button->setPanelPosition(position()); |
| 205 |
button->resize(m_manager->itemSize()); |
| 234 |
button->unsetPalette(); |
206 |
button->unsetPalette(); |
| 235 |
button->setBackgroundOrigin(AncestorOrigin); |
207 |
button->setBackgroundOrigin(AncestorOrigin); |
| 236 |
} |
208 |
} |
| 237 |
|
209 |
|
|
|
210 |
mButtonSizeSum = orientation() == Horizontal ? |
| 211 |
m_manager->frameSize().width() : |
| 212 |
m_manager->frameSize().height(); |
| 213 |
|
| 238 |
updateGeometry(); |
214 |
updateGeometry(); |
| 239 |
emit updateLayout(); |
215 |
emit updateLayout(); |
| 240 |
} |
216 |
} |
| 241 |
|
217 |
|
|
|
218 |
int MediaApplet::dimension() const |
| 219 |
{ |
| 220 |
if (orientation()==Qt::Vertical) |
| 221 |
{ |
| 222 |
return size().width(); |
| 223 |
} |
| 224 |
return size().height(); |
| 225 |
} |
| 226 |
|
| 242 |
void MediaApplet::slotClear() |
227 |
void MediaApplet::slotClear() |
| 243 |
{ |
228 |
{ |
| 244 |
kdDebug()<<"MediaApplet::slotClear"<<endl; |
229 |
kdDebug()<<"MediaApplet::slotClear"<<endl; |
|
Lines 275-295
void MediaApplet::slotNewItems(const KFileItemList &entries)
Link Here
|
| 275 |
MediumButtonList::iterator end = mButtonList.end(); |
260 |
MediumButtonList::iterator end = mButtonList.end(); |
| 276 |
for ( it2 = mButtonList.begin(); it2 != end; ++it2 ) |
261 |
for ( it2 = mButtonList.begin(); it2 != end; ++it2 ) |
| 277 |
{ |
262 |
{ |
| 278 |
MediumButton *button = *it2; |
263 |
MediumButton *button = *it2; |
| 279 |
|
264 |
|
| 280 |
if(button->fileItem().url()==it.current()->url()) |
265 |
if(button->fileItem().url()==it.current()->url()) |
| 281 |
{ |
266 |
{ |
| 282 |
found = true; |
267 |
found = true; |
| 283 |
button->setFileItem(*it.current()); |
268 |
button->setFileItem(*it.current()); |
| 284 |
break; |
269 |
break; |
| 285 |
} |
270 |
} |
| 286 |
} |
271 |
} |
| 287 |
|
272 |
|
| 288 |
if(!found && !mExcludedList.contains(it.current()->url().url()) ) |
273 |
if(!found && !mExcludedList.contains(it.current()->url().url()) ) |
| 289 |
{ |
274 |
{ |
| 290 |
MediumButton *button = new MediumButton(this, *it.current()); |
275 |
MediumButton *button = new MediumButton(this, *it.current()); |
| 291 |
button->show(); |
276 |
button->show(); |
| 292 |
mButtonList.append(button); |
277 |
mButtonList.append(button); |
| 293 |
} |
278 |
} |
| 294 |
} |
279 |
} |
| 295 |
|
280 |
|
|
Lines 308-316
void MediaApplet::slotDeleteItem(KFileItem *fileItem)
Link Here
|
| 308 |
|
293 |
|
| 309 |
if(button->fileItem().url()==fileItem->url()) |
294 |
if(button->fileItem().url()==fileItem->url()) |
| 310 |
{ |
295 |
{ |
| 311 |
mButtonList.remove(button); |
296 |
mButtonList.remove(button); |
| 312 |
delete button; |
297 |
delete button; |
| 313 |
break; |
298 |
break; |
| 314 |
} |
299 |
} |
| 315 |
} |
300 |
} |
| 316 |
slotCompleted(); |
301 |
slotCompleted(); |
|
Lines 332-360
void MediaApplet::slotRefreshItems(const KFileItemList &entries)
Link Here
|
| 332 |
MediumButtonList::iterator end = mButtonList.end(); |
317 |
MediumButtonList::iterator end = mButtonList.end(); |
| 333 |
for ( it2 = mButtonList.begin(); it2 != end; ++it2 ) |
318 |
for ( it2 = mButtonList.begin(); it2 != end; ++it2 ) |
| 334 |
{ |
319 |
{ |
| 335 |
MediumButton *button = *it2; |
320 |
MediumButton *button = *it2; |
| 336 |
|
321 |
|
| 337 |
if(button->fileItem().url()==(*it.current()).url()) |
322 |
if(button->fileItem().url()==(*it.current()).url()) |
| 338 |
{ |
|
|
| 339 |
if(mExcludedTypesList.contains(mimetype)) |
| 340 |
{ |
323 |
{ |
| 341 |
mButtonList.remove(button); |
324 |
if(mExcludedTypesList.contains(mimetype)) |
| 342 |
delete button; |
325 |
{ |
| 343 |
} |
326 |
mButtonList.remove(button); |
| 344 |
else |
327 |
delete button; |
| 345 |
{ |
328 |
} |
| 346 |
button->setFileItem(*it.current()); |
329 |
else |
|
|
330 |
{ |
| 331 |
button->setFileItem(*it.current()); |
| 332 |
} |
| 333 |
found = true; |
| 334 |
break; |
| 347 |
} |
335 |
} |
| 348 |
found = true; |
|
|
| 349 |
break; |
| 350 |
} |
| 351 |
} |
336 |
} |
| 352 |
|
337 |
|
| 353 |
if(!found && !mExcludedTypesList.contains(mimetype) && !mExcludedList.contains(it.current()->url().url()) ) |
338 |
if(!found && !mExcludedTypesList.contains(mimetype) && !mExcludedList.contains(it.current()->url().url()) ) |
| 354 |
{ |
339 |
{ |
| 355 |
MediumButton *button = new MediumButton(this, *it.current()); |
340 |
MediumButton *button = new MediumButton(this, *it.current()); |
| 356 |
button->show(); |
341 |
button->show(); |
| 357 |
mButtonList.append(button); |
342 |
mButtonList.append(button); |
| 358 |
} |
343 |
} |
| 359 |
} |
344 |
} |
| 360 |
|
345 |
|
|
Lines 394-399
void MediaApplet::loadConfig()
Link Here
|
| 394 |
{ |
379 |
{ |
| 395 |
mExcludedList.clear(); |
380 |
mExcludedList.clear(); |
| 396 |
} |
381 |
} |
|
|
382 |
mIconDim = c->readNumEntry("IconDim"); |
| 397 |
} |
383 |
} |
| 398 |
|
384 |
|
| 399 |
void MediaApplet::saveConfig() |
385 |
void MediaApplet::saveConfig() |
|
Lines 403-408
void MediaApplet::saveConfig()
Link Here
|
| 403 |
|
389 |
|
| 404 |
c->writeEntry("ExcludedTypes", mExcludedTypesList, ';'); |
390 |
c->writeEntry("ExcludedTypes", mExcludedTypesList, ';'); |
| 405 |
c->writeEntry("ExcludedMedia", mExcludedList, ';'); |
391 |
c->writeEntry("ExcludedMedia", mExcludedList, ';'); |
|
|
392 |
c->writeEntry("IconDim", mIconDim); |
| 406 |
|
393 |
|
| 407 |
c->sync(); |
394 |
c->sync(); |
| 408 |
} |
395 |
} |
|
Lines 425-443
void MediaApplet::reloadList()
Link Here
|
| 425 |
|
412 |
|
| 426 |
void MediaApplet::mousePressEvent(TQMouseEvent *e) |
413 |
void MediaApplet::mousePressEvent(TQMouseEvent *e) |
| 427 |
{ |
414 |
{ |
| 428 |
if(e->button()==Qt::RightButton) |
415 |
if( e->button() == Qt::RightButton ) |
| 429 |
{ |
416 |
{ |
| 430 |
KPopupMenu menu(this); |
417 |
mpAppletPopup->popup(e->globalPos()); |
| 431 |
|
|
|
| 432 |
menu.insertTitle(i18n("Media")); |
| 433 |
menu.insertItem(SmallIcon("configure"), i18n("&Configure..."), 1); |
| 434 |
|
| 435 |
int choice = menu.exec(this->mapToGlobal(e->pos())); |
| 436 |
|
| 437 |
if(choice==1) |
| 438 |
{ |
| 439 |
preferences(); |
| 440 |
} |
| 441 |
} |
418 |
} |
| 442 |
} |
419 |
} |
| 443 |
|
420 |
|