OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / libs / utils / reloadpromptutils.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "reloadpromptutils.h"
34
35 #include <QtCore/QCoreApplication>
36 #include <QtCore/QDir>
37 #include <QtGui/QMessageBox>
38 #include <QtGui/QPushButton>
39 #include <QtGui/QAbstractButton>
40
41 using namespace Utils;
42
43 QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
44     Utils::reloadPrompt(const QString &fileName, bool modified, QWidget *parent)
45 {
46
47     const QString title = QCoreApplication::translate("Utils::reloadPrompt", "File Changed");
48     QString msg;
49
50     if (modified)
51         msg = QCoreApplication::translate("Utils::reloadPrompt",
52                                           "The unsaved file <i>%1</i> has been changed outside Qt Creator. Do you want to reload it and discard your changes?");
53     else
54         msg = QCoreApplication::translate("Utils::reloadPrompt",
55                                           "The file <i>%1</i> has changed outside Qt Creator. Do you want to reload it?");
56     msg = msg.arg(QFileInfo(fileName).fileName());
57     return reloadPrompt(title, msg, QDir::toNativeSeparators(fileName), parent);
58 }
59
60 QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
61     Utils::reloadPrompt(const QString &title, const QString &prompt, const QString &details, QWidget *parent)
62 {
63     QMessageBox msg(parent);
64     msg.setStandardButtons(QMessageBox::Yes|QMessageBox::YesToAll|QMessageBox::No|QMessageBox::NoToAll);
65     msg.setDefaultButton(QMessageBox::YesToAll);
66     msg.setWindowTitle(title);
67     msg.setText(prompt);
68     msg.setDetailedText(details);
69
70     switch (msg.exec()) {
71     case QMessageBox::Yes:
72         return  ReloadCurrent;
73     case QMessageBox::YesToAll:
74         return ReloadAll;
75     case QMessageBox::No:
76         return ReloadSkipCurrent;
77     default:
78         break;
79     }
80     return ReloadNone;
81 }
82
83 QTCREATOR_UTILS_EXPORT Utils::FileDeletedPromptAnswer
84         Utils::fileDeletedPrompt(const QString &fileName, QWidget *parent)
85 {
86     const QString title = QCoreApplication::translate("Utils::fileDeletedPrompt", "File has been removed");
87     QString msg;
88      msg = QCoreApplication::translate("Utils::fileDeletedPrompt",
89                                       "The file %1 has been removed outside Qt Creator. Do you want to save it under a different name, or close the editor?").arg(QDir::toNativeSeparators(fileName));
90     QMessageBox box(QMessageBox::Question, title, msg, QMessageBox::NoButton, parent);
91     QPushButton *close = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Close"), QMessageBox::RejectRole);
92     QPushButton *saveas = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Save as..."), QMessageBox::ActionRole);
93     QPushButton *save = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Save"), QMessageBox::AcceptRole);
94     box.setDefaultButton(saveas);
95     box.exec();
96     QAbstractButton *clickedbutton = box.clickedButton();
97     if (clickedbutton == close) {
98         return FileDeletedClose;
99     } else if (clickedbutton == saveas) {
100         return FileDeletedSaveAs;
101     } else if (clickedbutton == save) {
102         return FileDeletedSave;
103     }
104     return FileDeletedClose;
105 }