~ubuntu-branches/ubuntu/intrepid/digikam/intrepid

« back to all changes in this revision

Viewing changes to digikam/digikam/timelineview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.2.15 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080717202539-6n7dtirbkoo7qvhd
Tags: 2:0.9.4-1
* New upstream release
  - digiKam 0.9.4 Release Plan (KDE3) ~ 13 July 08 (Closes: #490144)
* DEB_CONFIGURE_EXTRA_FLAGS := --without-included-sqlite3
* Debhelper compatibility level V7
* Install pixmaps in debian/*.install
* Add debian/digikam.lintian-overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2007-12-08
 
7
 * Description : Time line sidebar tab contents.
 
8
 *
 
9
 * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 *
 
11
 * This program is free software; you can redistribute it
 
12
 * and/or modify it under the terms of the GNU General
 
13
 * Public License as published by the Free Software Foundation;
 
14
 * either version 2, or (at your option)
 
15
 * any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
// Qt includes.
 
25
 
 
26
#include <qtimer.h>
 
27
#include <qframe.h>
 
28
#include <qhbox.h>
 
29
#include <qlayout.h>
 
30
#include <qcombobox.h>
 
31
#include <qpushbutton.h>
 
32
#include <qhbuttongroup.h> 
 
33
#include <qmap.h>
 
34
#include <qscrollbar.h>
 
35
#include <qwhatsthis.h>
 
36
#include <qtooltip.h>
 
37
 
 
38
// KDE include.
 
39
 
 
40
#include <klocale.h>
 
41
#include <kconfig.h>
 
42
#include <kdialog.h>
 
43
#include <klineedit.h>
 
44
#include <kiconloader.h>
 
45
#include <kapplication.h>
 
46
#include <ksqueezedtextlabel.h>
 
47
#include <kstandarddirs.h>
 
48
#include <kdeversion.h>
 
49
#include <kmessagebox.h>
 
50
 
 
51
#if KDE_IS_VERSION(3,2,0)
 
52
#include <kinputdialog.h>
 
53
#else
 
54
#include <klineeditdlg.h>
 
55
#endif
 
56
 
 
57
// Local includes.
 
58
 
 
59
#include "album.h"
 
60
#include "albummanager.h"
 
61
#include "ddebug.h"
 
62
#include "searchtextbar.h"
 
63
#include "timelinefolderview.h"
 
64
#include "timelinewidget.h"
 
65
#include "timelineview.h"
 
66
#include "timelineview.moc"
 
67
 
 
68
namespace Digikam
 
69
{
 
70
 
 
71
class TimeLineViewPriv
 
72
{
 
73
 
 
74
public:
 
75
 
 
76
    TimeLineViewPriv()
 
77
    {
 
78
        timeUnitCB            = 0;
 
79
        scaleBG               = 0;
 
80
        cursorDateLabel       = 0;
 
81
        cursorCountLabel      = 0;
 
82
        timeLineWidget        = 0;
 
83
        timer                 = 0;
 
84
        resetButton           = 0;
 
85
        saveButton            = 0;
 
86
        scrollBar             = 0;
 
87
        timeLineFolderView    = 0;
 
88
        nameEdit              = 0;
 
89
        searchDateBar         = 0;
 
90
    }
 
91
 
 
92
    QScrollBar         *scrollBar;
 
93
 
 
94
    QTimer             *timer;
 
95
 
 
96
    QComboBox          *timeUnitCB;
 
97
 
 
98
    QHButtonGroup      *scaleBG;
 
99
 
 
100
    QPushButton        *resetButton;
 
101
    QPushButton        *saveButton;
 
102
 
 
103
    QLabel             *cursorCountLabel;
 
104
 
 
105
    KLineEdit          *nameEdit;
 
106
 
 
107
    KSqueezedTextLabel *cursorDateLabel;
 
108
 
 
109
    SearchTextBar      *searchDateBar;
 
110
 
 
111
    TimeLineWidget     *timeLineWidget;
 
112
 
 
113
    TimeLineFolderView *timeLineFolderView;
 
114
};
 
115
 
 
116
TimeLineView::TimeLineView(QWidget *parent)
 
117
            : QWidget(parent, 0, Qt::WDestructiveClose)
 
118
{
 
119
    d = new TimeLineViewPriv;
 
120
    d->timer = new QTimer(this);
 
121
 
 
122
    QVBoxLayout *vlay = new QVBoxLayout(this);
 
123
    QFrame *panel     = new QFrame(this);
 
124
    panel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
 
125
    panel->setLineWidth(1);
 
126
 
 
127
    QGridLayout *grid = new QGridLayout(panel, 4, 3);
 
128
 
 
129
    // ---------------------------------------------------------------
 
130
 
 
131
    QWidget *hbox1    = new QWidget(panel);
 
132
    QHBoxLayout *hlay = new QHBoxLayout(hbox1);
 
133
 
 
134
    QLabel *label1 = new QLabel(i18n("Time Unit:"), hbox1);
 
135
    d->timeUnitCB  = new QComboBox(false, hbox1);
 
136
    d->timeUnitCB->insertItem(i18n("Day"),   TimeLineWidget::Day);
 
137
    d->timeUnitCB->insertItem(i18n("Week"),  TimeLineWidget::Week);
 
138
    d->timeUnitCB->insertItem(i18n("Month"), TimeLineWidget::Month);
 
139
    d->timeUnitCB->insertItem(i18n("Year"),  TimeLineWidget::Year);
 
140
    d->timeUnitCB->setCurrentItem((int)TimeLineWidget::Month);
 
141
    d->timeUnitCB->setFocusPolicy(QWidget::NoFocus);
 
142
    QWhatsThis::add(d->timeUnitCB, i18n("<p>Select the histogram time unit here.<p>"
 
143
                                        "You can change the graph decade to zoom in or zoom out over time."));
 
144
 
 
145
    d->scaleBG = new QHButtonGroup(hbox1);
 
146
    d->scaleBG->setExclusive(true);
 
147
    d->scaleBG->setFrameShape(QFrame::NoFrame);
 
148
    d->scaleBG->setInsideMargin( 0 );
 
149
    QWhatsThis::add(d->scaleBG, i18n("<p>Select the histogram scale here.<p>"
 
150
                                     "If the date count's maximal values are small, you can use the linear scale.<p>"
 
151
                                     "Logarithmic scale can be used when the maximal values are big; "
 
152
                                     "if it is used, all values (small and large) will be visible on the "
 
153
                                     "graph."));
 
154
 
 
155
    QPushButton *linHistoButton = new QPushButton( d->scaleBG );
 
156
    QToolTip::add( linHistoButton, i18n( "<p>Linear" ) );
 
157
    d->scaleBG->insert(linHistoButton, TimeLineWidget::LinScale);
 
158
    KGlobal::dirs()->addResourceType("histogram-lin", KGlobal::dirs()->kde_default("data") + "digikam/data");
 
159
    QString directory = KGlobal::dirs()->findResourceDir("histogram-lin", "histogram-lin.png");
 
160
    linHistoButton->setPixmap( QPixmap( directory + "histogram-lin.png" ) );
 
161
    linHistoButton->setToggleButton(true);
 
162
 
 
163
    QPushButton *logHistoButton = new QPushButton( d->scaleBG );
 
164
    QToolTip::add( logHistoButton, i18n( "<p>Logarithmic" ) );
 
165
    d->scaleBG->insert(logHistoButton, TimeLineWidget::LogScale);
 
166
    KGlobal::dirs()->addResourceType("histogram-log", KGlobal::dirs()->kde_default("data") + "digikam/data");
 
167
    directory = KGlobal::dirs()->findResourceDir("histogram-log", "histogram-log.png");
 
168
    logHistoButton->setPixmap( QPixmap( directory + "histogram-log.png" ) );
 
169
    logHistoButton->setToggleButton(true);
 
170
 
 
171
    hlay->setMargin(0);
 
172
    hlay->setSpacing(KDialog::spacingHint());
 
173
    hlay->addWidget(label1);
 
174
    hlay->addWidget(d->timeUnitCB);
 
175
    hlay->addItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum));
 
176
    hlay->addWidget(d->scaleBG);
 
177
 
 
178
    // ---------------------------------------------------------------
 
179
 
 
180
    d->timeLineWidget = new TimeLineWidget(panel);
 
181
    d->scrollBar      = new QScrollBar(panel);
 
182
    d->scrollBar->setOrientation(Qt::Horizontal);
 
183
    d->scrollBar->setMinValue(0);
 
184
    d->scrollBar->setLineStep(1);
 
185
 
 
186
    d->cursorDateLabel  = new KSqueezedTextLabel(0, panel);
 
187
    d->cursorCountLabel = new QLabel(panel);
 
188
    d->cursorCountLabel->setAlignment(Qt::AlignRight);
 
189
 
 
190
    // ---------------------------------------------------------------
 
191
 
 
192
    QHBox *hbox2 = new QHBox(panel);
 
193
    hbox2->setMargin(0);
 
194
    hbox2->setSpacing(KDialog::spacingHint());
 
195
 
 
196
    d->resetButton = new QPushButton(hbox2);
 
197
    d->resetButton->setPixmap(SmallIcon("reload_page"));
 
198
    QToolTip::add(d->resetButton, i18n("Clear current selection"));
 
199
    QWhatsThis::add(d->resetButton, i18n("<p>If you press this button, current "
 
200
                                        "dates selection from time-line will be "
 
201
                                        "clear."));
 
202
    d->nameEdit    = new KLineEdit(hbox2);
 
203
    QWhatsThis::add(d->nameEdit, i18n("<p>Enter the name of the current dates search to save in the "
 
204
                                      "\"My Date Searches\" view"));
 
205
 
 
206
    d->saveButton  = new QPushButton(hbox2);
 
207
    d->saveButton->setPixmap(SmallIcon("filesave"));
 
208
    d->saveButton->setEnabled(false);
 
209
    QToolTip::add(d->saveButton, i18n("Save current selection to a new virtual Album"));
 
210
    QWhatsThis::add(d->saveButton, i18n("<p>If you press this button, current "
 
211
                                        "dates selection from time-line will be "
 
212
                                        "saved to a new search virtual Album using name "
 
213
                                        "set on the left side."));
 
214
 
 
215
    // ---------------------------------------------------------------
 
216
 
 
217
    grid->addMultiCellWidget(hbox1,               0, 0, 0, 3);
 
218
    grid->addMultiCellWidget(d->cursorDateLabel,  1, 1, 0, 2);
 
219
    grid->addMultiCellWidget(d->cursorCountLabel, 1, 1, 3, 3);
 
220
    grid->addMultiCellWidget(d->timeLineWidget,   2, 2, 0, 3);
 
221
    grid->addMultiCellWidget(d->scrollBar,        3, 3, 0, 3);
 
222
    grid->addMultiCellWidget(hbox2,               4, 4, 0, 3);
 
223
    grid->setColStretch(2, 10);
 
224
    grid->setMargin(KDialog::spacingHint());
 
225
    grid->setSpacing(KDialog::spacingHint());
 
226
 
 
227
    // ---------------------------------------------------------------
 
228
 
 
229
    d->timeLineFolderView = new TimeLineFolderView(this);
 
230
    d->searchDateBar      = new SearchTextBar(this, "TimeLineViewSearchDateBar");
 
231
 
 
232
    vlay->addWidget(panel);
 
233
    vlay->addWidget(d->timeLineFolderView);
 
234
    vlay->addItem(new QSpacerItem(KDialog::spacingHint(), KDialog::spacingHint(), 
 
235
                                  QSizePolicy::Minimum, QSizePolicy::Minimum));
 
236
    vlay->addWidget(d->searchDateBar);
 
237
    vlay->setMargin(0);
 
238
    vlay->setSpacing(0);
 
239
 
 
240
    // ---------------------------------------------------------------
 
241
 
 
242
    connect(AlbumManager::instance(), SIGNAL(signalDatesMapDirty(const QMap<QDateTime, int>&)),
 
243
            d->timeLineWidget, SLOT(slotDatesMap(const QMap<QDateTime, int>&)));
 
244
 
 
245
    connect(d->timeLineFolderView, SIGNAL(signalAlbumSelected(SAlbum*)),
 
246
            this, SLOT(slotAlbumSelected(SAlbum*)));
 
247
 
 
248
    connect(d->timeLineFolderView, SIGNAL(signalRenameAlbum(SAlbum*)),
 
249
            this, SLOT(slotRenameAlbum(SAlbum*)));
 
250
 
 
251
    connect(d->timeLineFolderView, SIGNAL(signalTextSearchFilterMatch(bool)),
 
252
            d->searchDateBar, SLOT(slotSearchResult(bool)));
 
253
 
 
254
    connect(d->searchDateBar, SIGNAL(signalTextChanged(const QString&)),
 
255
            d->timeLineFolderView, SLOT(slotTextSearchFilterChanged(const QString&)));
 
256
 
 
257
    connect(d->timeUnitCB, SIGNAL(activated(int)),
 
258
            this, SLOT(slotTimeUnitChanged(int)));
 
259
 
 
260
    connect(d->scaleBG, SIGNAL(released(int)),
 
261
            this, SLOT(slotScaleChanged(int)));
 
262
 
 
263
    connect(d->timeLineWidget, SIGNAL(signalDateMapChanged()),
 
264
            this, SLOT(slotInit()));
 
265
 
 
266
    connect(d->timeLineWidget, SIGNAL(signalCursorPositionChanged()),
 
267
            this, SLOT(slotCursorPositionChanged()));
 
268
 
 
269
    connect(d->timeLineWidget, SIGNAL(signalSelectionChanged()),
 
270
            this, SLOT(slotSelectionChanged()));
 
271
 
 
272
    connect(d->timeLineWidget, SIGNAL(signalRefDateTimeChanged()),
 
273
            this, SLOT(slotRefDateTimeChanged()));
 
274
 
 
275
    connect(d->timer, SIGNAL(timeout()),
 
276
            this, SLOT(slotUpdateCurrentDateSearchAlbum()));
 
277
 
 
278
    connect(d->resetButton, SIGNAL(clicked()),
 
279
            this, SLOT(slotResetSelection()));
 
280
 
 
281
    connect(d->saveButton, SIGNAL(clicked()),
 
282
            this, SLOT(slotSaveSelection()));
 
283
 
 
284
    connect(d->scrollBar, SIGNAL(valueChanged(int)),
 
285
            this, SLOT(slotScrollBarValueChanged(int)));
 
286
 
 
287
    connect(d->nameEdit, SIGNAL(textChanged(const QString&)),
 
288
            this, SLOT(slotCheckAboutSelection()));
 
289
 
 
290
    connect(d->nameEdit, SIGNAL(returnPressed(const QString&)),
 
291
            d->saveButton, SLOT(animateClick()));
 
292
}
 
293
 
 
294
TimeLineView::~TimeLineView()
 
295
{
 
296
    writeConfig();
 
297
    delete d->timer;
 
298
    delete d;
 
299
}
 
300
 
 
301
TimeLineFolderView* TimeLineView::folderView() const
 
302
{
 
303
    return d->timeLineFolderView;
 
304
}
 
305
 
 
306
SearchTextBar* TimeLineView::searchBar() const
 
307
{
 
308
    return d->searchDateBar;
 
309
}
 
310
 
 
311
void TimeLineView::slotInit()
 
312
{
 
313
    // Date Maps are loaded from AlbumManager to TimeLineWidget after than GUI is initialized.
 
314
    // AlbumManager query Date KIO slave to stats items from database and it can take a while.
 
315
    // We waiting than TimeLineWidget is ready before to set last config from users.
 
316
 
 
317
    readConfig();
 
318
 
 
319
    disconnect(d->timeLineWidget, SIGNAL(signalDateMapChanged()),
 
320
               this, SLOT(slotInit()));
 
321
 
 
322
    connect(d->timeLineWidget, SIGNAL(signalDateMapChanged()),
 
323
            this, SLOT(slotCursorPositionChanged()));
 
324
}
 
325
 
 
326
void TimeLineView::readConfig()
 
327
{
 
328
    KConfig* config = kapp->config();
 
329
    config->setGroup("TimeLine SideBar");
 
330
 
 
331
    d->timeUnitCB->setCurrentItem(config->readNumEntry("Histogram TimeUnit", TimeLineWidget::Month));
 
332
    slotTimeUnitChanged(d->timeUnitCB->currentItem());
 
333
 
 
334
    d->scaleBG->setButton(config->readNumEntry("Histogram Scale", TimeLineWidget::LinScale));
 
335
    slotScaleChanged(d->scaleBG->selectedId());
 
336
 
 
337
    QDateTime now = QDateTime::currentDateTime();
 
338
    d->timeLineWidget->setCursorDateTime(config->readDateTimeEntry("Cursor Position", &now));
 
339
    d->timeLineWidget->setCurrentIndex(d->timeLineWidget->indexForCursorDateTime());
 
340
}
 
341
 
 
342
void TimeLineView::writeConfig()
 
343
{
 
344
    KConfig* config = kapp->config();
 
345
    config->setGroup("TimeLine SideBar");
 
346
    config->writeEntry("Histogram TimeUnit", d->timeUnitCB->currentItem());
 
347
    config->writeEntry("Histogram Scale", d->scaleBG->selectedId());
 
348
    config->writeEntry("Cursor Position", d->timeLineWidget->cursorDateTime());
 
349
    config->sync();
 
350
}
 
351
 
 
352
void TimeLineView::setActive(bool val)
 
353
{
 
354
    if (d->timeLineFolderView->selectedItem()) 
 
355
    {
 
356
        d->timeLineFolderView->setActive(val);
 
357
    }
 
358
    else if (val)
 
359
    {
 
360
        int totalCount = 0;
 
361
        DateRangeList list = d->timeLineWidget->selectedDateRange(totalCount);
 
362
        if (list.isEmpty())
 
363
        {
 
364
            AlbumManager::instance()->setCurrentAlbum(0);
 
365
        }
 
366
        else
 
367
        {
 
368
            AlbumList sList = AlbumManager::instance()->allSAlbums();
 
369
            for (AlbumList::iterator it = sList.begin(); it != sList.end(); ++it)
 
370
            {
 
371
                SAlbum* salbum = (SAlbum*)(*it);
 
372
                if (salbum->title() == d->timeLineFolderView->currentTimeLineSearchName())
 
373
                    AlbumManager::instance()->setCurrentAlbum(salbum);
 
374
            }
 
375
        }
 
376
    }
 
377
}
 
378
 
 
379
void TimeLineView::slotRefDateTimeChanged()
 
380
{
 
381
    d->scrollBar->blockSignals(true);
 
382
    d->scrollBar->setMaxValue(d->timeLineWidget->totalIndex()-1);
 
383
    d->scrollBar->setValue(d->timeLineWidget->indexForRefDateTime()-1);
 
384
    d->scrollBar->blockSignals(false);
 
385
}
 
386
 
 
387
void TimeLineView::slotTimeUnitChanged(int mode)
 
388
{
 
389
    d->timeLineWidget->setTimeUnit((TimeLineWidget::TimeUnit)mode);
 
390
}
 
391
 
 
392
void TimeLineView::slotScrollBarValueChanged(int val)
 
393
{
 
394
    d->timeLineWidget->setCurrentIndex(val);
 
395
}
 
396
 
 
397
void TimeLineView::slotScaleChanged(int mode)
 
398
{
 
399
    d->timeLineWidget->setScaleMode((TimeLineWidget::ScaleMode)mode);
 
400
}
 
401
 
 
402
void TimeLineView::slotCursorPositionChanged()
 
403
{
 
404
    QString txt;
 
405
    int val = d->timeLineWidget->cursorInfo(txt);
 
406
    d->cursorDateLabel->setText(txt);
 
407
    d->cursorCountLabel->setText(QString::number(val));
 
408
}
 
409
 
 
410
void TimeLineView::slotSelectionChanged()
 
411
{
 
412
    d->timer->start(100, true);
 
413
}
 
414
 
 
415
/** Called from d->timer event.*/
 
416
void TimeLineView::slotUpdateCurrentDateSearchAlbum()
 
417
{
 
418
    slotCheckAboutSelection();
 
419
    createNewDateSearchAlbum(d->timeLineFolderView->currentTimeLineSearchName());
 
420
}
 
421
 
 
422
void TimeLineView::slotSaveSelection()
 
423
{
 
424
    QString name = d->nameEdit->text();
 
425
    if (!checkName(name)) 
 
426
        return;
 
427
    createNewDateSearchAlbum(name);
 
428
}
 
429
 
 
430
void TimeLineView::createNewDateSearchAlbum(const QString& name)
 
431
{
 
432
    int totalCount = 0;
 
433
    QDateTime start, end;
 
434
    DateRangeList list = d->timeLineWidget->selectedDateRange(totalCount);
 
435
 
 
436
    if (list.isEmpty())
 
437
    {
 
438
        AlbumManager::instance()->setCurrentAlbum(0);
 
439
        return;
 
440
    }
 
441
 
 
442
    d->timeLineFolderView->blockSignals(true);
 
443
    d->timeLineFolderView->clearSelection();
 
444
    d->timeLineFolderView->blockSignals(false);
 
445
 
 
446
    // We will make now the Url for digiKam Search KIO-Slave
 
447
 
 
448
    KURL url;
 
449
    url.setProtocol("digikamsearch");
 
450
 
 
451
    int grp = list.count();
 
452
    QString path("1 AND 2");
 
453
 
 
454
    if (grp > 1 )
 
455
    {
 
456
        for (int i = 1 ; i < grp; i++)
 
457
        {
 
458
            path.append(" OR ");
 
459
            path.append(QString("%1 AND %2").arg(i*2+1).arg(i*2+2));
 
460
        }
 
461
    }
 
462
    url.setPath(path);
 
463
 
 
464
    int i = 0;
 
465
    DateRangeList::iterator it;
 
466
    for (it = list.begin() ; it != list.end(); ++it)
 
467
    {
 
468
        start = (*it).first;
 
469
        end   = (*it).second;
 
470
        url.addQueryItem(QString("%1.key").arg(i*2+1), QString("imagedate"));
 
471
        url.addQueryItem(QString("%1.op").arg(i*2+1),  QString("GT"));
 
472
        url.addQueryItem(QString("%1.val").arg(i*2+1), start.date().toString(Qt::ISODate));
 
473
        url.addQueryItem(QString("%1.key").arg(i*2+2), QString("imagedate"));
 
474
        url.addQueryItem(QString("%1.op").arg(i*2+2),  QString("LT"));
 
475
        url.addQueryItem(QString("%1.val").arg(i*2+2), end.date().toString(Qt::ISODate));
 
476
        i++;
 
477
    }
 
478
 
 
479
    url.addQueryItem("name", name);
 
480
    url.addQueryItem("count", QString::number(grp*2));
 
481
    url.addQueryItem("type", QString("datesearch"));
 
482
 
 
483
    //DDebug() << url << endl;
 
484
 
 
485
    SAlbum* album = AlbumManager::instance()->createSAlbum(url, false);
 
486
    AlbumManager::instance()->setCurrentAlbum(album);
 
487
}
 
488
 
 
489
void TimeLineView::slotAlbumSelected(SAlbum* salbum)
 
490
{
 
491
    if (!salbum) 
 
492
    {
 
493
        slotResetSelection();
 
494
        return;
 
495
    }
 
496
 
 
497
    // Date Search url for KIO-Slave is something like that :
 
498
    // digikamsearch:1 AND 2 OR 3 AND 4 OR 5 AND 6?
 
499
    //               1.key=imagedate&1.op=GT&1.val=2006-02-06&
 
500
    //               2.key=imagedate&2.op=LT&2.val=2006-02-07&
 
501
    //               3.key=imagedate&3.op=GT&3.val=2006-02-10&
 
502
    //               4.key=imagedate&4.op=LT&4.val=2006-02-11&
 
503
    //               5.key=imagedate&5.op=GT&5.val=2006-02-12&
 
504
    //               6.key=imagedate&6.op=LT&6.val=2006-02-13&
 
505
    //               name=TimeLineSelection&
 
506
    //               count=6
 
507
    //               type=datesearch
 
508
 
 
509
    // Check if a special url query exist to identify a SAlbum dedicaced to Date Search
 
510
    KURL url = salbum->kurl();
 
511
    QMap<QString, QString> queries = url.queryItems();
 
512
    if (queries.isEmpty()) return;
 
513
 
 
514
    QString type = url.queryItem("type");
 
515
    if (type != QString("datesearch")) return;
 
516
 
 
517
    bool ok   = false;
 
518
    int count = url.queryItem("count").toInt(&ok);
 
519
    if (!ok || count <= 0) return;
 
520
 
 
521
    //DDebug() << url << endl;
 
522
 
 
523
    QMap<QString, QString>::iterator it2;
 
524
    QString       key;
 
525
    QDateTime     start, end;
 
526
    DateRangeList list;
 
527
    for (int i = 1 ; i <= count ; i+=2)
 
528
    {
 
529
        key = QString("%1.val").arg(QString::number(i));
 
530
        it2 = queries.find(key);
 
531
        if (it2 != queries.end())
 
532
            start = QDateTime(QDate::fromString(it2.data(), Qt::ISODate));
 
533
 
 
534
        //DDebug() << key << " :: " << it2.data() << endl;
 
535
 
 
536
        key = QString("%1.val").arg(QString::number(i+1));
 
537
        it2 = queries.find(key);
 
538
        if (it2 != queries.end())
 
539
            end = QDateTime(QDate::fromString(it2.data(), Qt::ISODate));
 
540
 
 
541
        //DDebug() << key << " :: " << it2.data() << endl;
 
542
 
 
543
        list.append(DateRange(start, end));
 
544
    }
 
545
 
 
546
    /*
 
547
    DateRangeList::iterator it3;
 
548
    for (it3 = list.begin() ; it3 != list.end(); ++it3)
 
549
        DDebug() << (*it3).first.date().toString(Qt::ISODate) << " :: " 
 
550
                 << (*it3).second.date().toString(Qt::ISODate) << endl;
 
551
    */
 
552
 
 
553
    d->timeLineWidget->setSelectedDateRange(list);
 
554
    AlbumManager::instance()->setCurrentAlbum(salbum);
 
555
}
 
556
 
 
557
void TimeLineView::slotResetSelection()
 
558
{
 
559
    d->timeLineWidget->slotResetSelection();
 
560
    slotCheckAboutSelection();
 
561
    AlbumManager::instance()->setCurrentAlbum(0);
 
562
}
 
563
 
 
564
bool TimeLineView::checkName(QString& name)
 
565
{
 
566
    bool checked = checkAlbum(name);
 
567
 
 
568
    while (!checked) 
 
569
    {
 
570
        QString label = i18n( "Search name already exists.\n"
 
571
                              "Please enter a new name:" );
 
572
        bool ok;
 
573
#if KDE_IS_VERSION(3,2,0)
 
574
        QString newTitle = KInputDialog::getText(i18n("Name exists"), label, name, &ok, this);
 
575
#else
 
576
        QString newTitle = KLineEditDlg::getText(i18n("Name exists"), label, name, ok, this);
 
577
#endif
 
578
        if (!ok) return false;
 
579
 
 
580
        name    = newTitle;
 
581
        checked = checkAlbum(name);
 
582
    }
 
583
 
 
584
    return true;
 
585
}
 
586
 
 
587
bool TimeLineView::checkAlbum(const QString& name) const
 
588
{
 
589
    AlbumList list = AlbumManager::instance()->allSAlbums();
 
590
 
 
591
    for (AlbumList::Iterator it = list.begin() ; it != list.end() ; ++it)
 
592
    {
 
593
        SAlbum *album = (SAlbum*)(*it);
 
594
        if ( album->title() == name )
 
595
            return false;
 
596
    }
 
597
    return true;
 
598
}
 
599
 
 
600
void TimeLineView::slotCheckAboutSelection()
 
601
{
 
602
    int totalCount     = 0;
 
603
    DateRangeList list = d->timeLineWidget->selectedDateRange(totalCount);
 
604
    if (!list.isEmpty())
 
605
    {
 
606
        d->nameEdit->setEnabled(true);
 
607
 
 
608
        if (!d->nameEdit->text().isEmpty())
 
609
            d->saveButton->setEnabled(true);
 
610
    }
 
611
    else
 
612
    {
 
613
        d->nameEdit->setEnabled(false);
 
614
        d->saveButton->setEnabled(false);
 
615
    }
 
616
}
 
617
 
 
618
void TimeLineView::slotRenameAlbum(SAlbum* salbum)
 
619
{
 
620
    if (!salbum) return;
 
621
 
 
622
    QString oldName(salbum->title());
 
623
    bool    ok;
 
624
 
 
625
#if KDE_IS_VERSION(3,2,0)
 
626
    QString name = KInputDialog::getText(i18n("Rename Album (%1)").arg(oldName), 
 
627
                                          i18n("Enter new album name:"),
 
628
                                          oldName, &ok, this);
 
629
#else
 
630
    QString name = KLineEditDlg::getText(i18n("Rename Album (%1)").arg(oldName), 
 
631
                                          i18n("Enter new album name:"),
 
632
                                          oldName, &ok, this);
 
633
#endif
 
634
 
 
635
    if (!ok || name == oldName || name.isEmpty()) return;
 
636
 
 
637
    if (!checkName(name)) return;
 
638
 
 
639
    KURL url = salbum->kurl();
 
640
    url.removeQueryItem("name");
 
641
    url.addQueryItem("name", name);
 
642
    AlbumManager::instance()->updateSAlbum(salbum, url);
 
643
}
 
644
 
 
645
}  // NameSpace Digikam