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.
34
#include <QtGui/QtGui>
35
#include "base/base.h"
36
#include "gui/base/debug_util.h"
37
#include "base/run_level.h"
38
#include "base/winmain.h"
40
DEFINE_string(mode, "about_dialog", "mozc_tool mode");
42
// Run* are defiend in each qt module
43
int RunAboutDialog(int argc, char *argv[]);
44
int RunConfigDialog(int argc, char *argv[]);
45
int RunDictionaryTool(int argc, char *argv[]);
46
int RunErrorMessageDialog(int argc, char *argv[]);
49
// (SetDefault|PostInstall|RunAdministartion)Dialog
50
// are used for Windows only
51
int RunSetDefaultDialog(int argc, char *argv[]);
52
int RunPostInstallDialog(int argc, char *argv[]);
53
int RunAdministrationDialog(int argc, char *argv[]);
57
// Confirmation Dialog is used for the update dialog on Mac only.
58
int RunConfirmationDialog(int argc, char *argv[]);
63
char *strdup_with_new(const char *str) {
64
const size_t len = strlen(str);
65
char *v = new char [len + 1];
73
int main(int argc, char *argv[]) {
75
// OSX's app won't accept command line flags.
76
// Here we read the flags by using --fromenv option
77
scoped_array<char *> tmp(new char * [2]);
78
tmp[0] = strdup_with_new(argv[0]);
79
tmp[1] = strdup_with_new("--fromenv=mode,error_type,confirmation_type");
81
char **new_argv = tmp.get();
82
InitGoogleWithBreakPad(new_argv[0], &new_argc, &new_argv, false);
86
InitGoogleWithBreakPad(argv[0], &argc, &argv, false);
89
if (FLAGS_mode != "administration_dialog" &&
90
!mozc::RunLevel::IsValidClientRunLevel()) {
94
// install Qt debug handler
95
qInstallMsgHandler(mozc::gui::DebugUtil::MessageHandler);
97
Q_INIT_RESOURCE(qrc_mozc_tool);
99
// we cannot install the translation of qt_ja_JP here.
100
// as Qpplication is initialized inside Run* function
102
if (FLAGS_mode == "config_dialog") {
103
return RunConfigDialog(argc, argv);
104
} else if (FLAGS_mode == "dictionary_tool") {
105
return RunDictionaryTool(argc, argv);
106
} else if (FLAGS_mode == "error_message_dialog") {
107
return RunErrorMessageDialog(argc, argv);
108
} else if (FLAGS_mode == "about_dialog") {
109
return RunAboutDialog(argc, argv);
111
} else if (FLAGS_mode == "set_default_dialog") {
112
// set_default_dialog is used on Windows only.
113
return RunSetDefaultDialog(argc, argv);
114
} else if (FLAGS_mode == "post_install_dialog") {
115
// post_install_dialog is used on Windows only.
116
return RunPostInstallDialog(argc, argv);
117
} else if (FLAGS_mode == "administration_dialog") {
118
// administration_dialog is used on Windows only.
119
return RunAdministrationDialog(argc, argv);
122
} else if (FLAGS_mode == "confirmation_dialog") {
123
// Confirmation Dialog is used for the update dialog on Mac only.
124
return RunConfirmationDialog(argc, argv);
127
LOG(ERROR) << "Unknown mode: " << FLAGS_mode;