2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-04-15 11:49:11 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-15 11:49:11 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-04-15 11:49:11 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-04-15 11:49:11 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-15 11:49:11 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-15 11:49:11 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-04-15 11:49:11 +02:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#include "idocument.h"
|
2011-04-15 11:49:11 +02:00
|
|
|
|
2011-05-06 12:48:44 +02:00
|
|
|
#include "infobar.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
2011-05-10 20:43:03 +02:00
|
|
|
|
2011-04-15 11:49:11 +02:00
|
|
|
namespace Core {
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
IDocument::IDocument(QObject *parent) : QObject(parent), m_infoBar(0), m_hasWriteWarning(false), m_restored(false)
|
2011-04-15 11:49:11 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
IDocument::~IDocument()
|
2011-04-15 11:49:11 +02:00
|
|
|
{
|
2011-05-10 20:43:03 +02:00
|
|
|
removeAutoSaveFile();
|
2011-05-06 12:48:44 +02:00
|
|
|
delete m_infoBar;
|
2011-04-15 11:49:11 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
IDocument::ReloadBehavior IDocument::reloadBehavior(ChangeTrigger state, ChangeType type) const
|
2011-04-15 11:53:46 +02:00
|
|
|
{
|
|
|
|
|
if (type == TypePermissions)
|
|
|
|
|
return BehaviorSilent;
|
|
|
|
|
if (type == TypeContents && state == TriggerInternal && !isModified())
|
|
|
|
|
return BehaviorSilent;
|
|
|
|
|
return BehaviorAsk;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
void IDocument::checkPermissions()
|
2011-04-15 11:49:11 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
bool IDocument::shouldAutoSave() const
|
2011-05-10 20:43:03 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
bool IDocument::isFileReadOnly() const
|
2012-02-14 12:10:29 +01:00
|
|
|
{
|
|
|
|
|
if (fileName().isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
return !QFileInfo(fileName()).isWritable();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
bool IDocument::autoSave(QString *errorString, const QString &fileName)
|
2011-05-10 20:43:03 +02:00
|
|
|
{
|
|
|
|
|
if (!save(errorString, fileName, true))
|
|
|
|
|
return false;
|
|
|
|
|
m_autoSaveName = fileName;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char kRestoredAutoSave[] = "RestoredAutoSave";
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
void IDocument::setRestoredFrom(const QString &name)
|
2011-05-10 20:43:03 +02:00
|
|
|
{
|
|
|
|
|
m_autoSaveName = name;
|
|
|
|
|
m_restored = true;
|
2012-11-08 21:12:56 +02:00
|
|
|
InfoBarEntry info(Id(kRestoredAutoSave),
|
2011-05-10 20:43:03 +02:00
|
|
|
tr("File was restored from auto-saved copy. "
|
2012-10-01 10:14:11 +02:00
|
|
|
"Select Save to confirm or Revert to Saved to discard changes."));
|
2011-05-10 20:43:03 +02:00
|
|
|
infoBar()->addInfo(info);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
void IDocument::removeAutoSaveFile()
|
2011-05-10 20:43:03 +02:00
|
|
|
{
|
|
|
|
|
if (!m_autoSaveName.isEmpty()) {
|
|
|
|
|
QFile::remove(m_autoSaveName);
|
|
|
|
|
m_autoSaveName.clear();
|
|
|
|
|
if (m_restored) {
|
|
|
|
|
m_restored = false;
|
2012-11-08 21:12:56 +02:00
|
|
|
infoBar()->removeInfo(Id(kRestoredAutoSave));
|
2011-05-10 20:43:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
InfoBar *IDocument::infoBar()
|
2011-05-06 12:48:44 +02:00
|
|
|
{
|
|
|
|
|
if (!m_infoBar)
|
|
|
|
|
m_infoBar = new InfoBar;
|
|
|
|
|
return m_infoBar;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-15 11:49:11 +02:00
|
|
|
} // namespace Core
|