File indexing completed on 2024-04-21 05:50:21
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 <KBookmarkManager> 0025 #include <QDateTime> 0026 #include <QLocale> 0027 0028 GlobalBookmarkManager *GlobalBookmarkManager::s_mgr = nullptr; 0029 0030 GlobalBookmarkManager::GlobalBookmarkManager() 0031 : QObject(nullptr) 0032 , m_mgr(nullptr) 0033 , m_model(nullptr) 0034 { 0035 } 0036 0037 GlobalBookmarkManager::~GlobalBookmarkManager() 0038 { 0039 } 0040 0041 KBookmarkGroup GlobalBookmarkManager::root() 0042 { 0043 return mgr()->root(); 0044 } 0045 0046 KBookmark GlobalBookmarkManager::bookmarkAt(const QString &a) 0047 { 0048 return self()->mgr()->findByAddress(a); 0049 } 0050 0051 bool GlobalBookmarkManager::managerSave() 0052 { 0053 return mgr()->save(); 0054 } 0055 0056 void GlobalBookmarkManager::saveAs(const QString &fileName) 0057 { 0058 mgr()->saveAs(fileName); 0059 } 0060 0061 QString GlobalBookmarkManager::path() const 0062 { 0063 return mgr()->path(); 0064 } 0065 0066 void GlobalBookmarkManager::createManager(const QString &filename, const QString &dbusObjectName, CommandHistory *commandHistory) 0067 { 0068 // qCDebug(KEDITBOOKMARKS_LOG)<<"DBus Object name: "<<dbusObjectName; 0069 Q_UNUSED(dbusObjectName); 0070 m_mgr = std::make_unique<KBookmarkManager>(filename); 0071 0072 connect(m_mgr.get(), &KBookmarkManager::error, this, &GlobalBookmarkManager::error); 0073 0074 commandHistory->setBookmarkManager(m_mgr.get()); 0075 0076 if (m_model) { 0077 m_model->setRoot(root()); 0078 } else { 0079 m_model = new KBookmarkModel(root(), commandHistory, this); 0080 } 0081 } 0082 0083 void GlobalBookmarkManager::notifyManagers(const KBookmarkGroup &grp) 0084 { 0085 m_model->notifyManagers(grp); 0086 } 0087 0088 void GlobalBookmarkManager::notifyManagers() 0089 { 0090 notifyManagers(root()); 0091 } 0092 0093 QString GlobalBookmarkManager::makeTimeStr(const QString &in) 0094 { 0095 int secs; 0096 bool ok; 0097 secs = in.toInt(&ok); 0098 if (!ok) 0099 return QString(); 0100 return makeTimeStr(secs); 0101 } 0102 0103 QString GlobalBookmarkManager::makeTimeStr(int b) 0104 { 0105 QDateTime dt; 0106 dt.fromSecsSinceEpoch(b); 0107 QLocale l; 0108 return (dt.daysTo(QDateTime::currentDateTime()) > 31) ? l.toString(dt.date(), QLocale::LongFormat) : l.toString(dt, QLocale::LongFormat); 0109 } 0110 0111 #include "moc_globalbookmarkmanager.cpp"