OSDN Git Service

Move the directories
[kita/kita.git] / src / libkita / cache.cpp
diff --git a/src/libkita/cache.cpp b/src/libkita/cache.cpp
new file mode 100644 (file)
index 0000000..c988f61
--- /dev/null
@@ -0,0 +1,114 @@
+/***************************************************************************
+*   Copyright (C) 2003 by Hideki Ikemoto                                  *
+*   ikemo@wakaba.jp                                                       *
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+***************************************************************************/
+#include "cache.h"
+
+#include <kglobal.h>
+#include <kstandarddirs.h>
+
+#include "boarddatabase.h"
+
+using namespace Kita;
+
+Cache::Cache(const KUrl& url) : m_url(url)
+{
+}
+
+QString Cache::baseDir()
+{
+    QString dir = KGlobal::dirs() ->saveLocation("cache", "kita");
+    if (dir[ dir.length() - 1 ] != '/')
+        dir += '/';
+
+    return dir;
+}
+
+
+QString Cache::serverDir() const
+{
+    /* Is board enrolled ? */
+    BoardDatabase db(m_url);
+    BoardData * bdata = db.getBoardData();
+    if (bdata == 0) return QString();
+
+    QString root = bdata->hostName() + bdata->rootPath();
+
+    return root.remove("http://").replace('/', '_') + '/';
+}
+
+
+QString Cache::boardDir() const
+{
+    /* Is board enrolled ? */
+    BoardDatabase db(m_url);
+    BoardData * bdata = db.getBoardData();
+    if (bdata == 0) return QString();
+
+    QString bbs = bdata->bbsPath();
+
+    return bbs.mid(1).replace('/', '_') + '/';
+}
+
+
+QString Cache::getPath() const
+{
+    QString path = getDirPath();
+    if (path.isEmpty()) return QString();
+
+    //    qDebug("%s -> %s",url.prettyUrl().ascii(),path.ascii());
+
+    return path + m_url.fileName();
+}
+
+QString Cache::getIndexPath() const
+{
+    QString path = getPath();
+    if (path.isEmpty()) {
+        return QString();
+    } else {
+        return path + ".idx";
+    }
+}
+
+
+/*------------------------------------*/
+/* for SETTING.TXT and BBS history    */
+
+
+/* public */
+QString Cache::getSettingPath() const
+{
+    QString path = getDirPath();
+    if (path.isEmpty()) return QString();
+
+    return path + "SETTING.TXT";
+}
+
+/* public */
+QString Cache::getBBSHistoryPath() const
+{
+    QString path = getDirPath();
+    if (path.isEmpty()) return QString();
+
+    return path + "BBSHISTORY";
+}
+
+/* public */
+QString Cache::getSubjectPath() const
+{
+    QString path = getDirPath();
+    if (path.isEmpty()) return QString();
+
+    return path + "subject.txt";
+}
+
+QString Cache::getDirPath() const
+{
+    return baseDir() + serverDir() + boardDir();
+}