OSDN Git Service

QMap -> QDict
[kita/kita.git] / kita / src / favoritelistview.cpp
1 /***************************************************************************
2  *   Copyright (C) 2003 by Hideki Ikemoto                                  *
3  *   ikemo@users.sourceforge.jp                                            *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10
11 #include "favoritelistview.h"
12
13 #include "libkita/favoritethreads.h"
14 #include "libkita/board.h"
15
16 #include <qmap.h>
17
18 #include <klocale.h>
19
20 enum FavoriteListViewRows {
21   Row_Board,
22   Row_Icon,
23   Row_Subject,
24   Row_ResNum,
25   Row_Vested,
26   Row_Unread,
27   Row_DatName,
28   Row_DatURL
29 };
30
31 FavoriteListView::FavoriteListView(QWidget* parent, const char *name)
32  : KListView(parent, name)
33 {
34   addColumn(i18n("Board"));
35   addColumn("");
36   addColumn(i18n("Title"));
37   addColumn(i18n("ResNum"));
38   addColumn(i18n("Vested"));
39   addColumn(i18n("Unread"));
40   addColumn(i18n("Dat"));
41
42   setColumnWidth(Row_Subject, 400);
43   setColumnWidthMode(Row_Subject, QListView::Manual);
44
45   connect( this, SIGNAL( clicked(QListViewItem*) ),
46                  SLOT( loadThread(QListViewItem*) ) );
47 }
48
49 FavoriteListView::~FavoriteListView()
50 {
51 }
52
53 void FavoriteListView::update()
54 {
55   const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
56 //  FavoriteThreads::const_iterator it;
57
58   clear();
59
60   QDictIterator<Kita::Thread> it( threads );
61   for(; it.current(); ++it) {
62     const Kita::Thread* thread = it.current();
63     const Kita::Board* board = thread->getBoard();
64
65     new KListViewItem( this,
66                        board->name(),
67                        "",
68                        thread->name(),
69                        QString("%1").arg(thread->resNum(), 4),
70                        "",
71                        "",
72                        thread->datURL().fileName(),
73                        thread->datURL().prettyURL() );
74   }
75 }
76
77 void FavoriteListView::loadThread( QListViewItem* item )
78 {
79   if( ! item ) return;
80
81   const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
82 //  FavoriteThreads::const_iterator it;
83
84   QDictIterator<Kita::Thread> it( threads );
85   for(; it.current(); ++it) {
86     const Kita::Thread* thread = it.current();
87
88     if( thread->datURL().prettyURL() == item->text( Row_DatURL ) ) {
89       emit signalShowThread( *thread );
90     }
91   }
92 }
93