~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to cervisia/updateview_items.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (C) 1999-2002 Bernd Gehrmann <bernd@mail.berlios.de>
3
 
 * Copyright (c) 2003-2007 AndrĆ© Wƶbbeking <Woebbeking@kde.org>
 
3
 * Copyright (c) 2003-2008 AndrĆ© Wƶbbeking <Woebbeking@kde.org>
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
6
6
 * it under the terms of the GNU General Public License as published by
24
24
 
25
25
#include <qdir.h>
26
26
#include <qpainter.h>
27
 
#include <qregexp.h>
 
27
//Added by qt3to4:
 
28
#include <QPixmap>
 
29
#include <QTextStream>
28
30
 
29
31
#include <kdebug.h>
30
 
#include <kglobalsettings.h>
 
32
#include <kcolorscheme.h>
31
33
#include <kiconloader.h>
32
34
#include <klocale.h>
33
 
#include <kmimetype.h>
34
35
 
35
36
#include "cvsdir.h"
36
37
#include "entry.h"
70
71
QString UpdateItem::filePath() const
71
72
{
72
73
    // the filePath of the root item is '.'
73
 
    return parent() ? dirPath() + m_entry.m_name : QChar('.');
 
74
    return parent() ? dirPath() + m_entry.m_name : QLatin1String(".");
74
75
}
75
76
 
76
77
 
154
155
            }
155
156
            fileItem->setRevTag(entry.m_revision, entry.m_tag);
156
157
            fileItem->setDate(entry.m_dateTime);
157
 
            fileItem->setPixmap(0, isBinary ? SmallIcon("binary") : QPixmap());
 
158
            fileItem->setPixmap(0, isBinary ? SmallIcon("application-octet-stream") 
 
159
                                            : QPixmap());
158
160
        }
159
161
        return;
160
162
    }
178
180
    const QFileInfoList *files = dir.entryInfoList();
179
181
    if (files)
180
182
    {
181
 
        QFileInfoListIterator it(*files);
182
 
        for (; it.current(); ++it)
 
183
        Q_FOREACH (QFileInfo info, *files)
183
184
        {
184
185
            Entry entry;
185
 
            entry.m_name = it.current()->fileName();
186
 
            if (it.current()->isDir())
 
186
            entry.m_name = info.fileName();
 
187
            if (info.isDir())
187
188
            {
188
189
                entry.m_type = Entry::Dir;
189
190
                createDirItem(entry);
217
218
 
218
219
UpdateItem* UpdateDirItem::insertItem(UpdateItem* item)
219
220
{
220
 
    QPair<TMapItemsByName::iterator, bool> result
221
 
        = m_itemsByName.insert(TMapItemsByName::value_type(item->entry().m_name, item));
222
 
    if (!result.second)
 
221
    const TMapItemsByName::iterator it = m_itemsByName.find(item->entry().m_name);
 
222
    if (it != m_itemsByName.end())
223
223
    {
224
224
        // OK, an item with that name already exists. If the item type is the
225
225
        // same then keep the old one to preserve it's status information
226
 
        UpdateItem* existingItem = *result.first;
 
226
        UpdateItem* existingItem = *it;
227
227
        if (existingItem->rtti() == item->rtti())
228
228
        {
229
229
            delete item;
232
232
        else
233
233
        {
234
234
            delete existingItem;
235
 
            *result.first = item;
 
235
            *it = item;
236
236
        }
237
237
    }
 
238
    else
 
239
    {
 
240
        m_itemsByName.insert(item->entry().m_name, item);
 
241
    }
238
242
 
239
243
    return item;
240
244
}
247
251
    return (it != m_itemsByName.end()) ? *it : 0;
248
252
}
249
253
 
250
 
// Qt-3.3.8 changed the parsing in QDateTime::fromString() but introduced
251
 
// a bug which leads to the problem that days with 1 digit will incorrectly being
252
 
// parsed as day 0 - which is invalid.
253
 
// workaround with the implementation from Qt-3.3.6
254
 
QDateTime parseDateTime(const QString &s)
255
 
{
256
 
        static const char * const qt_shortMonthNames[] = {
257
 
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
258
 
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
259
 
 
260
 
        QString monthName( s.mid( 4, 3 ) );
261
 
        int month = -1;
262
 
        // Assume that English monthnames are the default
263
 
        for ( int i = 0; i < 12; ++i ) {
264
 
            if ( monthName == qt_shortMonthNames[i] ) {
265
 
                month = i + 1;
266
 
                break;
267
 
            }
268
 
        }
269
 
        // If English names can't be found, search the localized ones
270
 
        if ( month == -1 ) {
271
 
            for ( int i = 1; i <= 12; ++i ) {
272
 
                if ( monthName == QDate::shortMonthName( i ) ) {
273
 
                    month = i;
274
 
                    break;
275
 
                }
276
 
            }
277
 
        }
278
 
        if ( month < 1 || month > 12 ) {
279
 
            qWarning( "QDateTime::fromString: Parameter out of range" );
280
 
            QDateTime dt;
281
 
            return dt;
282
 
        }
283
 
        int day = s.mid( 8, 2 ).simplifyWhiteSpace().toInt();
284
 
        int year = s.right( 4 ).toInt();
285
 
        QDate date( year, month, day );
286
 
        QTime time;
287
 
        int hour, minute, second;
288
 
        int pivot = s.find( QRegExp(QString::fromLatin1("[0-9][0-9]:[0-9][0-9]:[0-9][0-9]")) );
289
 
        if ( pivot != -1 ) {
290
 
            hour = s.mid( pivot, 2 ).toInt();
291
 
            minute = s.mid( pivot+3, 2 ).toInt();
292
 
            second = s.mid( pivot+6, 2 ).toInt();
293
 
            time.setHMS( hour, minute, second );
294
 
        }
295
 
        return QDateTime( date, time );
296
 
}
297
254
 
298
255
// Format of the CVS/Entries file:
299
256
//   /NAME/REVISION/[CONFLICT+]TIMESTAMP/OPTIONS/TAGDATE
303
260
    const QString path(filePath() + QDir::separator());
304
261
 
305
262
    QFile f(path + "CVS/Entries");
306
 
    if( f.open(IO_ReadOnly) )
 
263
    if( f.open(QIODevice::ReadOnly) )
307
264
    {
308
265
        QTextStream stream(&f);
309
 
        while( !stream.eof() )
 
266
        while( !stream.atEnd() )
310
267
        {
311
268
            QString line = stream.readLine();
312
269
 
334
291
                const QString options(line.section('/', 4, 4));
335
292
                entry.m_tag = line.section('/', 5, 5);
336
293
 
337
 
                const bool isBinary(options.find("-kb") >= 0);
 
294
                const bool isBinary = options.contains("-kb");
338
295
 
339
296
                // file date in local time
340
297
                entry.m_dateTime = QFileInfo(path + entry.m_name).lastModified();
346
303
                    entry.m_status = Cervisia::LocallyRemoved;
347
304
                    rev.remove(0, 1);
348
305
                }
349
 
                else if (timestamp.find('+') >= 0)
 
306
                else if (timestamp.contains('+'))
350
307
                {
351
308
                    entry.m_status = Cervisia::Conflict;
352
309
                }
353
310
                else
354
311
                {
355
 
                    // workaround Qt-3.3.8 bug with our own function (see function above)
356
 
                    // const QDateTime date(QDateTime::fromString(timestamp)); // UTC Time
357
 
                    const QDateTime date(parseDateTime(timestamp)); // UTC Time
358
 
                    QDateTime fileDateUTC;
359
 
                    fileDateUTC.setTime_t(entry.m_dateTime.toTime_t(), Qt::UTC);
 
312
                    QDateTime date(QDateTime::fromString(timestamp)); // UTC Time
 
313
                    date.setTimeSpec(Qt::UTC);
 
314
                    const QDateTime fileDateUTC(entry.m_dateTime.toUTC());
360
315
                    if (date != fileDateUTC)
361
316
                        entry.m_status = Cervisia::LocallyModified;
362
317
                }
390
345
            if (!dir.exists(it.key()))
391
346
            {
392
347
                fileItem->setStatus(Cervisia::Removed);
393
 
                fileItem->setRevTag(QString::null, QString::null);
 
348
                fileItem->setRevTag(QString(), QString());
394
349
            }
395
350
        }
396
351
    }
457
412
            view->setFilter(view->filter());
458
413
    }
459
414
 
460
 
    QListViewItem::setOpen(open);
 
415
    Q3ListViewItem::setOpen(open);
461
416
}
462
417
 
463
418
 
464
 
int UpdateDirItem::compare(QListViewItem* i,
 
419
int UpdateDirItem::compare(Q3ListViewItem* i,
465
420
                           int /*column*/,
466
421
                           bool bAscending) const
467
422
{
522
477
    bool visible(true);
523
478
    if (filter & UpdateView::OnlyDirectories)
524
479
        visible = false;
525
 
    
526
 
    bool unmodified = (entry().m_status == Cervisia::UpToDate) || 
 
480
 
 
481
    bool unmodified = (entry().m_status == Cervisia::UpToDate) ||
527
482
                      (entry().m_status == Cervisia::Unknown);
528
483
    if ((filter & UpdateView::NoUpToDate) && unmodified)
529
484
        visible = false;
646
601
}
647
602
 
648
603
 
649
 
int UpdateFileItem::compare(QListViewItem* i,
 
604
int UpdateFileItem::compare(Q3ListViewItem* i,
650
605
                            int column,
651
606
                            bool bAscending) const
652
607
{
662
617
    case Name:
663
618
        iResult = entry().m_name.localeAwareCompare(item->entry().m_name);
664
619
        break;
665
 
    case MimeType:
666
 
        iResult = KMimeType::findByPath(entry().m_name)->comment().localeAwareCompare(KMimeType::findByPath(item->entry().m_name)->comment());
667
 
        break;
668
620
    case Status:
669
621
        if ((iResult = ::compare(statusClass(), item->statusClass())) == 0)
670
622
            iResult = entry().m_name.localeAwareCompare(item->entry().m_name);
692
644
    case Name:
693
645
        result = entry().m_name;
694
646
        break;
695
 
    case MimeType:
696
 
        result = KMimeType::findByPath(entry().m_name)->comment();
697
 
        break;
698
647
    case Status:
699
648
        result = toString(entry().m_status);
700
649
        break;
751
700
 
752
701
    const QFont oldFont(p->font());
753
702
    QColorGroup mycg(cg);
754
 
    if (color.isValid() && color != KGlobalSettings::textColor())
 
703
    if (color.isValid() && color != KColorScheme(QPalette::Active, KColorScheme::View).foreground().color())
755
704
    {
756
705
        QFont myFont(oldFont);
757
706
        myFont.setBold(true);
758
707
        p->setFont(myFont);
759
 
        mycg.setColor(QColorGroup::Text, color);
 
708
        mycg.setColor(QPalette::Text, color);
760
709
    }
761
710
 
762
 
    QListViewItem::paintCell(p, mycg, col, width, align);
 
711
    Q3ListViewItem::paintCell(p, mycg, col, width, align);
763
712
 
764
713
    if (color.isValid())
765
714
    {
780
729
 
781
730
    UpdateDirItem* dirItem(rootItem);
782
731
 
783
 
    if (dirPath != QChar('.'))
 
732
    if (dirPath != QLatin1String("."))
784
733
    {
785
 
        const QStringList& dirNames(QStringList::split('/', dirPath));
 
734
        const QStringList& dirNames(dirPath.split('/'));
786
735
        const QStringList::const_iterator itDirNameEnd(dirNames.end());
787
736
        for (QStringList::const_iterator itDirName(dirNames.begin());
788
737
             itDirName != itDirNameEnd; ++itDirName)
792
741
            UpdateItem* item = dirItem->findItem(dirName);
793
742
            if (isFileItem(item))
794
743
            {
795
 
                kdDebug(8050) << "findOrCreateDirItem(): file changed to dir " << dirName << endl;
 
744
                kDebug(8050) << "file changed to dir " << dirName;
796
745
                delete item;
797
746
                item = 0;
798
747
            }
799
748
 
800
749
            if (!item)
801
750
            {
802
 
                kdDebug(8050) << "findOrCreateDirItem(): create dir item " << dirName << endl;
 
751
                kDebug(8050) << "create dir item " << dirName;
803
752
                Entry entry;
804
753
                entry.m_name = dirName;
805
754
                entry.m_type = Entry::Dir;