OSDN Git Service

Add BoardDatabase class
[kita/kita.git] / kita / src / libkita / cache.cpp
1 /***************************************************************************
2 *   Copyright (C) 2003 by Hideki Ikemoto                                  *
3 *   ikemo@wakaba.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 #include "cache.h"
11
12 #include <kglobal.h>
13 #include <kstandarddirs.h>
14
15 #include "boarddatabase.h"
16
17 using namespace Kita;
18
19 Cache::Cache(const KUrl& url) : m_url(url)
20 {
21 }
22
23 QString Cache::baseDir()
24 {
25     QString dir = KGlobal::dirs() ->saveLocation("cache", "kita");
26     if (dir[ dir.length() - 1 ] != '/')
27         dir += '/';
28
29     return dir;
30 }
31
32
33 QString Cache::serverDir() const
34 {
35     /* Is board enrolled ? */
36     BoardDatabase db(m_url);
37     BoardData * bdata = db.getBoardData();
38     if (bdata == 0) return QString();
39
40     QString root = bdata->hostName() + bdata->rootPath();
41
42     return root.remove("http://").replace('/', '_') + '/';
43 }
44
45
46 QString Cache::boardDir() const
47 {
48     /* Is board enrolled ? */
49     BoardDatabase db(m_url);
50     BoardData * bdata = db.getBoardData();
51     if (bdata == 0) return QString();
52
53     QString bbs = bdata->bbsPath();
54
55     return bbs.mid(1).replace('/', '_') + '/';
56 }
57
58
59 QString Cache::getPath() const
60 {
61     QString path = getDirPath();
62     if (path.isEmpty()) return QString();
63
64     //    qDebug("%s -> %s",url.prettyUrl().ascii(),path.ascii());
65
66     return path + m_url.fileName();
67 }
68
69 QString Cache::getIndexPath() const
70 {
71     QString path = getPath();
72     if (path.isEmpty()) {
73         return QString();
74     } else {
75         return path + ".idx";
76     }
77 }
78
79
80 /*------------------------------------*/
81 /* for SETTING.TXT and BBS history    */
82
83
84 /* public */
85 QString Cache::getSettingPath() const
86 {
87     QString path = getDirPath();
88     if (path.isEmpty()) return QString();
89
90     return path + "SETTING.TXT";
91 }
92
93 /* public */
94 QString Cache::getBBSHistoryPath() const
95 {
96     QString path = getDirPath();
97     if (path.isEmpty()) return QString();
98
99     return path + "BBSHISTORY";
100 }
101
102 /* public */
103 QString Cache::getSubjectPath() const
104 {
105     QString path = getDirPath();
106     if (path.isEmpty()) return QString();
107
108     return path + "subject.txt";
109 }
110
111 QString Cache::getDirPath() const
112 {
113     return baseDir() + serverDir() + boardDir();
114 }