1
// Copyright 2010, Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
8
// * Redistributions of source code must retain the above copyright
9
// notice, this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above
11
// copyright notice, this list of conditions and the following disclaimer
12
// in the documentation and/or other materials provided with the
14
// * Neither the name of Google Inc. nor the names of its
15
// contributors may be used to endorse or promote products derived from
16
// this software without specific prior written permission.
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
#include "gui/post_install_dialog/post_install_dialog.h"
36
#include <QtGui/QtGui>
37
#include "base/base.h"
38
#include "base/process.h"
39
#include "base/run_level.h"
40
#include "base/util.h"
41
#include "base/win_util.h"
42
#include "dictionary/user_dictionary_importer.h"
43
#include "dictionary/user_dictionary_storage.h"
44
#include "dictionary/user_dictionary_util.h"
45
#include "usage_stats/usage_stats.h"
49
#include "win32/base/imm_util.h"
55
PostInstallDialog::PostInstallDialog()
56
: logoff_required_(false),
58
new UserDictionaryStorage(
59
UserDictionaryUtil::GetUserDictionaryFileName())) {
61
if (!mozc::ImeUtil::IsCuasEnabled()) {
62
logoff_required_ = true;
63
mozc::ImeUtil::SetCuasEnabled(true);
68
setWindowFlags(Qt::WindowSystemMenuHint |
69
Qt::MSWindowsFixedSizeDialogHint |
70
Qt::WindowStaysOnTopHint);
71
setWindowModality(Qt::NonModal);
73
QObject::connect(logoffNowButton,
77
QObject::connect(logoffLaterButton,
80
SLOT(OnLogoffLater()));
81
QObject::connect(okButton,
86
// We change buttons to be displayed depending on the condition this dialog
88
// The following table summarizes which buttons are displayed by conditions.
90
// ----------------------------------------------
91
// | OK | Later | Now | help | logoff |
92
// ----------------------------------------------
93
// | D | N | N | true | true |
94
// | D | N | N | true | false |
95
// | N | D | D | false | true |
96
// | D | N | N | false | false |
97
// ----------------------------------------------
99
// The followings are meanings of the words used in the table.
101
// Later : logoffLaterButton
102
// Now : logoffNowButton
103
// help : The result of IsShowHelpPageRequired()
104
// logoff : The result of IsLogoffRequired()
108
if (IsShowHelpPageRequired()) {
109
usage_stats::UsageStats::IncrementCount("PostInstallShowPageRequired");
110
thanksLabel->setText(tr("Thanks for installing.\n"
111
"You need to configure your computer before using "
112
"Mozc. Please follow the "
113
"instructions on the help page."));
114
logoffNowButton->setVisible(false);
115
logoffLaterButton->setVisible(false);
117
if (logoff_required()) {
118
usage_stats::UsageStats::IncrementCount("PostInstallLogoffRequired");
119
thanksLabel->setText(tr("Thanks for installing.\nYou must log off before "
121
// remove OK button and move the other buttons to right.
122
const int rows = gridLayout->rowCount();
123
const int cols = gridLayout->columnCount();
124
okButton->setVisible(false);
125
gridLayout->removeWidget(okButton);
126
gridLayout->addWidget(logoffNowButton, rows - 1, cols - 2);
127
gridLayout->addWidget(logoffLaterButton, rows - 1, cols - 1);
129
usage_stats::UsageStats::IncrementCount("PostInstallNothingRequired");
130
logoffNowButton->setVisible(false);
131
logoffLaterButton->setVisible(false);
132
gridLayout->removeWidget(logoffNowButton);
133
gridLayout->removeWidget(logoffLaterButton);
137
// set the default state of migrateDefaultIMEUserDictionaryCheckBox
138
const bool status = (!RunLevel::IsElevatedByUAC() && storage_->Lock());
139
migrateDefaultIMEUserDictionaryCheckBox->setVisible(status);
141
// import MS-IME by default
142
migrateDefaultIMEUserDictionaryCheckBox->setChecked(true);
145
PostInstallDialog::~PostInstallDialog() {
148
bool PostInstallDialog::logoff_required() {
149
return logoff_required_;
152
bool PostInstallDialog::ShowHelpPageIfRequired() {
153
if (PostInstallDialog::IsShowHelpPageRequired()) {
154
const char kHelpPageUrl[] =
155
"http://www.google.com/support/ime/japanese/bin/answer.py?hl=jp&answer="
157
return mozc::Process::OpenBrowser(kHelpPageUrl);
162
// NOTE(mazda): UsageStats class is not currently multi-process safe so it is
163
// possible that usagestats is incorrectly collected.
164
// For example if the user activate Mozc in another application before closing
165
// this dialog, the usagestats collected in the application can be overwritten
166
// when this dialog is closed.
167
// But this case is very rare since this dialog is launched immediately after
169
// So we accept the potential error until this limitation is fixed.
170
void PostInstallDialog::OnLogoffNow() {
171
usage_stats::UsageStats::IncrementCount("PostInstallLogoffNowButton");
174
mozc::WinUtil::Logoff();
176
// not supported on Mac and Linux
178
done(QDialog::Accepted);
181
void PostInstallDialog::OnLogoffLater() {
182
usage_stats::UsageStats::IncrementCount("PostInstallLogoffLaterButton");
184
done(QDialog::Rejected);
187
void PostInstallDialog::OnOk() {
188
usage_stats::UsageStats::IncrementCount("PostInstallOkButton");
190
done(QDialog::Accepted);
193
void PostInstallDialog::reject() {
194
usage_stats::UsageStats::IncrementCount("PostInstallRejectButton");
195
done(QDialog::Rejected);
198
void PostInstallDialog::ApplySettings() {
200
if (setAsDefaultCheckBox->isChecked()) {
201
usage_stats::UsageStats::IncrementCount("PostInstallSetDefault");
202
ImeUtil::SetDefault();
204
usage_stats::UsageStats::IncrementCount("PostInstallNotSetDefault");
207
if (migrateDefaultIMEUserDictionaryCheckBox->isChecked() &&
208
migrateDefaultIMEUserDictionaryCheckBox->isVisible()) {
210
// create UserDictionary if the current user dictionary is empty
211
if (!storage_->Exists()) {
212
const QString name = tr("User Dictionary 1");
214
if (!storage_->CreateDictionary(name.toStdString(),
216
LOG(ERROR) << "Failed to create a new dictionary.";
221
// Import MS-IME's dictionary to an unique dictionary labeled
224
const QString name = tr("MS-IME User Dictionary");
225
for (size_t i = 0; i < storage_->dictionaries_size(); ++i) {
226
if (storage_->dictionaries(i).name() == name.toStdString()) {
227
dic_id = storage_->dictionaries(i).id();
233
if (!storage_->CreateDictionary(name.toStdString(),
235
LOG(ERROR) << "Failed to create a new dictionary.";
240
UserDictionaryStorage::UserDictionary *dic =
241
storage_->GetUserDictionary(dic_id);
243
LOG(ERROR) << "GetUserDictionary returned NULL";
247
if (UserDictionaryImporter::ImportFromMSIME(dic) !=
248
UserDictionaryImporter::IMPORT_NO_ERROR) {
249
LOG(ERROR) << "ImportFromMSIME failed";
255
// not supported on Mac and Linux
259
bool PostInstallDialog::IsShowHelpPageRequired() {
261
return !ImeUtil::IsCtfmonRunning();
263
// not supported on Mac and Linux