Commit 1783572f authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

No manual memory management for katesession*


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent 54be8771
......@@ -25,12 +25,11 @@ KateSession::KateSession(const QString &file, const QString &name, const bool an
, m_file(file)
, m_anonymous(anonymous)
, m_documents(0)
, m_config(nullptr)
{
Q_ASSERT(!m_file.isEmpty());
if (_config) { // copy data from config instead
m_config = _config->copyTo(m_file);
m_config.reset(_config->copyTo(m_file));
} else if (!QFile::exists(m_file)) { // given file exists, use it to load some stuff
qCDebug(LOG_KATE) << "Warning, session file not found: " << m_file;
return;
......@@ -42,11 +41,6 @@ KateSession::KateSession(const QString &file, const QString &name, const bool an
m_documents = config()->group(opGroupName).readEntry(keyCount, 0);
}
KateSession::~KateSession()
{
delete m_config;
}
const QString &KateSession::file() const
{
return m_file;
......@@ -62,8 +56,7 @@ void KateSession::setFile(const QString &filename)
{
if (m_config) {
KConfig *cfg = m_config->copyTo(filename);
delete m_config;
m_config = cfg;
m_config.reset(cfg);
}
m_file = filename;
......@@ -76,12 +69,12 @@ void KateSession::setName(const QString &name)
KConfig *KateSession::config()
{
if (m_config) {
return m_config;
if (!m_config) {
// reread documents number?
m_config = std::make_unique<KConfig>(m_file, KConfig::SimpleConfig);
}
// reread documents number?
return m_config = new KConfig(m_file, KConfig::SimpleConfig);
return m_config.get();
}
KateSession::Ptr KateSession::create(const QString &file, const QString &name)
......
......@@ -14,6 +14,8 @@
#include <QExplicitlySharedDataPointer>
#include <QString>
#include <memory>
class KConfig;
class KATE_TESTS_EXPORT KateSession : public QSharedData
......@@ -25,7 +27,6 @@ public:
typedef QExplicitlySharedDataPointer<KateSession> Ptr;
public:
~KateSession();
/**
* session name
......@@ -120,7 +121,7 @@ private:
QString m_file;
bool m_anonymous;
unsigned int m_documents;
KConfig *m_config;
std::unique_ptr<KConfig> m_config;
QDateTime m_timestamp;
};
......
......@@ -71,10 +71,6 @@ KateSessionManageDialog::KateSessionManageDialog(QWidget *parent, const QString
updateSessionList();
}
KateSessionManageDialog::~KateSessionManageDialog()
{
}
void KateSessionManageDialog::dontAskToggled()
{
m_templateButton->setEnabled(!m_dontAskCheckBox->isChecked());
......
......@@ -34,7 +34,6 @@ public:
* the @p lastSession in the session list.
*/
KateSessionManageDialog(QWidget *parent, const QString &lastSession);
~KateSessionManageDialog() override;
protected Q_SLOTS:
/**
......
......@@ -29,7 +29,6 @@
#include <QDBusReply>
#include <QDir>
#include <QInputDialog>
#include <QScopedPointer>
#include <QUrl>
#ifndef Q_OS_WIN
......@@ -50,18 +49,13 @@ KateSessionManager::KateSessionManager(QObject *parent, const QString &sessionsD
// create dir if needed
QDir().mkpath(m_sessionsDir);
m_dirWatch = new KDirWatch(this);
m_dirWatch = std::make_unique<KDirWatch>(this);
m_dirWatch->addDir(m_sessionsDir);
connect(m_dirWatch, &KDirWatch::dirty, this, &KateSessionManager::updateSessionList);
connect(m_dirWatch.get(), &KDirWatch::dirty, this, &KateSessionManager::updateSessionList);
updateSessionList();
}
KateSessionManager::~KateSessionManager()
{
delete m_dirWatch;
}
void KateSessionManager::updateSessionList()
{
QStringList list;
......@@ -585,7 +579,7 @@ void KateSessionManager::updateJumpListActions(const QStringList &sessionList)
return;
}
QScopedPointer<KDesktopFile> df(new KDesktopFile(service->entryPath()));
std::unique_ptr<KDesktopFile> df(new KDesktopFile(service->entryPath()));
QStringList newActions = df->readActions();
......
......@@ -13,6 +13,8 @@
#include <QHash>
#include <QObject>
#include <memory>
typedef QList<KateSession::Ptr> KateSessionList;
class KATE_TESTS_EXPORT KateSessionManager : public QObject
......@@ -23,7 +25,6 @@ class KATE_TESTS_EXPORT KateSessionManager : public QObject
public:
KateSessionManager(QObject *parent = nullptr, const QString &sessionsDir = QString());
~KateSessionManager() override;
/**
* allow access to the session list
......@@ -59,7 +60,7 @@ public:
* sessionFile == empty means we have no session around for this instance of kate
* @return session active atm
*/
inline KateSession::Ptr activeSession()
KateSession::Ptr activeSession()
{
return m_activeSession;
}
......@@ -68,7 +69,7 @@ public:
* session dir
* @return global session dir
*/
inline const QString &sessionsDir() const
const QString &sessionsDir() const
{
return m_sessionsDir;
}
......@@ -246,7 +247,7 @@ private:
*/
KateSession::Ptr m_activeSession;
class KDirWatch *m_dirWatch;
std::unique_ptr<class KDirWatch> m_dirWatch;
};
#endif
......@@ -19,9 +19,6 @@ class KATE_TESTS_EXPORT KateSessionsAction : public KActionMenu
public:
KateSessionsAction(const QString &text, QObject *parent, KateSessionManager *manager = nullptr);
~KateSessionsAction() override
{
}
public Q_SLOTS:
void slotAboutToShow();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment