OSDN Git Service

Fix original string messages
[qt-creator-jp/qt-creator-jp.git] / src / plugins / remotelinux / publickeydeploymentdialog.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 ** GNU Lesser General Public License Usage
10 **
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
14 ** Please review the following information to ensure the GNU Lesser General
15 ** Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** Other Usage
23 **
24 ** Alternatively, this file may be used in accordance with the terms and
25 ** conditions contained in a signed written agreement between you and Nokia.
26 **
27 ** If you have questions regarding the use of this file, please contact
28 ** Nokia at info@qt.nokia.com.
29 **
30 **************************************************************************/
31 #include "publickeydeploymentdialog.h"
32
33 #include "linuxdeviceconfiguration.h"
34 #include "maemokeydeployer.h"
35
36 #include <QtGui/QFileDialog>
37
38 namespace RemoteLinux {
39 namespace Internal {
40 class PublicKeyDeploymentDialogPrivate
41 {
42 public:
43     MaemoKeyDeployer *keyDeployer;
44     bool done;
45 };
46 } // namespace Internal;
47
48 using namespace Internal;
49
50 PublicKeyDeploymentDialog::PublicKeyDeploymentDialog(const LinuxDeviceConfiguration::ConstPtr &deviceConfig,
51         QWidget *parent)
52     : QProgressDialog(parent), m_d(new PublicKeyDeploymentDialogPrivate)
53 {
54     setAutoReset(false);
55     setAutoClose(false);
56     setMinimumDuration(0);
57     setMaximum(1);
58
59     m_d->keyDeployer = new MaemoKeyDeployer(this);
60     m_d->done = false;
61
62     setLabelText(tr("Waiting for file name..."));
63     const Utils::SshConnectionParameters sshParams = deviceConfig->sshParameters();
64     const QString &dir = QFileInfo(sshParams.privateKeyFile).path();
65     QString publicKeyFileName = QFileDialog::getOpenFileName(this,
66         tr("Choose Public Key File"), dir,
67         tr("Public Key Files (*.pub);;All Files (*)"));
68     if (publicKeyFileName.isEmpty()) {
69         reject();
70         return;
71     }
72
73     setLabelText(tr("Deploying..."));
74     setValue(0);
75     connect(this, SIGNAL(canceled()), SLOT(handleCanceled()));
76     connect(m_d->keyDeployer, SIGNAL(error(QString)), SLOT(handleDeploymentError(QString)));
77     connect(m_d->keyDeployer, SIGNAL(finishedSuccessfully()), SLOT(handleDeploymentSuccess()));
78     m_d->keyDeployer->deployPublicKey(sshParams, publicKeyFileName);
79 }
80
81 PublicKeyDeploymentDialog::~PublicKeyDeploymentDialog()
82 {
83     delete m_d;
84 }
85
86 void PublicKeyDeploymentDialog::handleDeploymentSuccess()
87 {
88     handleDeploymentFinished(QString());
89     setValue(1);
90     m_d->done = true;
91 }
92
93 void PublicKeyDeploymentDialog::handleDeploymentError(const QString &errorMsg)
94 {
95     handleDeploymentFinished(errorMsg);
96 }
97
98 void PublicKeyDeploymentDialog::handleDeploymentFinished(const QString &errorMsg)
99 {
100     QString buttonText;
101     const char *textColor;
102     if (errorMsg.isEmpty()) {
103         buttonText = tr("Deployment finished successfully.");
104         textColor = "blue";
105     } else {
106         buttonText = errorMsg;
107         textColor = "red";
108     }
109     setLabelText(QString::fromLocal8Bit("<font color=\"%1\">%2</font>").arg(textColor, buttonText));
110     setCancelButtonText(tr("Close"));
111 }
112
113 void PublicKeyDeploymentDialog::handleCanceled()
114 {
115     disconnect(m_d->keyDeployer, 0, this, 0);
116     m_d->keyDeployer->stopDeployment();
117     if (m_d->done)
118         accept();
119     else
120         reject();
121 }
122
123 } // namespace RemoteLinux