Warning, file /utilities/keditbookmarks/src/globalbookmarkmanager.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2000, 2010 David Faure <faure@kde.org>
0003    Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU General Public
0007    License version 2 or at your option version 3 as published by
0008    the Free Software Foundation.
0009 
0010    This program is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    General Public License for more details.
0014 
0015    You should have received a copy of the GNU General Public License
0016    along with this program; see the file COPYING.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "globalbookmarkmanager.h"
0022 #include "kbookmarkmodel/commandhistory.h"
0023 #include "kbookmarkmodel/model.h"
0024 #include "keditbookmarks_debug.h"
0025 #include <KBookmarkManager>
0026 #include <QDateTime>
0027 #include <QLocale>
0028 
0029 GlobalBookmarkManager *GlobalBookmarkManager::s_mgr = nullptr;
0030 
0031 GlobalBookmarkManager::GlobalBookmarkManager()
0032     : QObject(nullptr)
0033     , m_mgr(nullptr)
0034     , m_model(nullptr)
0035 {
0036 }
0037 
0038 GlobalBookmarkManager::~GlobalBookmarkManager()
0039 {
0040 }
0041 
0042 KBookmarkGroup GlobalBookmarkManager::root()
0043 {
0044     return mgr()->root();
0045 }
0046 
0047 KBookmark GlobalBookmarkManager::bookmarkAt(const QString &a)
0048 {
0049     return self()->mgr()->findByAddress(a);
0050 }
0051 
0052 bool GlobalBookmarkManager::managerSave()
0053 {
0054     return mgr()->save();
0055 }
0056 
0057 void GlobalBookmarkManager::saveAs(const QString &fileName)
0058 {
0059     mgr()->saveAs(fileName);
0060 }
0061 
0062 void GlobalBookmarkManager::setUpdate(bool update)
0063 {
0064     mgr()->setUpdate(update);
0065 }
0066 
0067 QString GlobalBookmarkManager::path() const
0068 {
0069     return mgr()->path();
0070 }
0071 
0072 void GlobalBookmarkManager::createManager(const QString &filename, const QString &dbusObjectName, CommandHistory *commandHistory)
0073 {
0074     if (m_mgr) {
0075         // qCDebug(KEDITBOOKMARKS_LOG)<<"createManager called twice";
0076         delete m_mgr;
0077     }
0078 
0079     // qCDebug(KEDITBOOKMARKS_LOG)<<"DBus Object name: "<<dbusObjectName;
0080     m_mgr = KBookmarkManager::managerForFile(filename, dbusObjectName);
0081 
0082     commandHistory->setBookmarkManager(m_mgr);
0083 
0084     if (m_model) {
0085         m_model->setRoot(root());
0086     } else {
0087         m_model = new KBookmarkModel(root(), commandHistory, this);
0088     }
0089 }
0090 
0091 void GlobalBookmarkManager::notifyManagers(const KBookmarkGroup &grp)
0092 {
0093     m_model->notifyManagers(grp);
0094 }
0095 
0096 void GlobalBookmarkManager::notifyManagers()
0097 {
0098     notifyManagers(root());
0099 }
0100 
0101 void GlobalBookmarkManager::reloadConfig()
0102 {
0103     mgr()->emitConfigChanged();
0104 }
0105 
0106 QString GlobalBookmarkManager::makeTimeStr(const QString &in)
0107 {
0108     int secs;
0109     bool ok;
0110     secs = in.toInt(&ok);
0111     if (!ok)
0112         return QString();
0113     return makeTimeStr(secs);
0114 }
0115 
0116 QString GlobalBookmarkManager::makeTimeStr(int b)
0117 {
0118     QDateTime dt;
0119     dt.fromSecsSinceEpoch(b);
0120     QLocale l;
0121     return (dt.daysTo(QDateTime::currentDateTime()) > 31) ? l.toString(dt.date(), QLocale::LongFormat) : l.toString(dt, QLocale::LongFormat);
0122 }