~ubuntu-branches/ubuntu/oneiric/mozc/oneiric

« back to all changes in this revision

Viewing changes to gui/tool/mozc_tool_main.cc

  • Committer: Bazaar Package Importer
  • Author(s): Nobuhiro Iwamatsu
  • Date: 2010-07-14 03:26:47 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100714032647-13qjisj6m8cm8jdx
Tags: 0.12.410.102-1
* New upstream release (Closes: #588971).
  - Add mozc-server, mozc-utils-gui and scim-mozc packages.
* Update debian/rules.
  Add --gypdir option to build_mozc.py.
* Update debian/control.
  - Bumped standards-version to 3.9.0.
  - Update description.
* Add mozc icon (Closes: #588972).
* Add patch which revises issue 18.
  ibus_mozc_issue18.patch
* kFreeBSD build support.
  support_kfreebsd.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2010, Google Inc.
 
2
// All rights reserved.
 
3
//
 
4
// Redistribution and use in source and binary forms, with or without
 
5
// modification, are permitted provided that the following conditions are
 
6
// met:
 
7
//
 
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
 
13
// distribution.
 
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.
 
17
//
 
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.
 
29
 
 
30
#ifdef OS_WINDOWS
 
31
#include <windows.h>
 
32
#endif
 
33
 
 
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"
 
39
 
 
40
DEFINE_string(mode, "about_dialog", "mozc_tool mode");
 
41
 
 
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[]);
 
47
 
 
48
#ifdef OS_WINDOWS
 
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[]);
 
54
#endif  // OS_WINDOWS
 
55
 
 
56
#ifdef OS_MACOSX
 
57
// Confirmation Dialog is used for the update dialog on Mac only.
 
58
int RunConfirmationDialog(int argc, char *argv[]);
 
59
#endif  // OS_MACOSX
 
60
 
 
61
#ifdef OS_MACOSX
 
62
namespace {
 
63
char *strdup_with_new(const char *str) {
 
64
  const size_t len = strlen(str);
 
65
  char *v = new char [len + 1];
 
66
  memcpy(v, str, len);
 
67
  v[len] = '\0';
 
68
  return v;
 
69
}
 
70
}  // namespace
 
71
#endif  // OS_MACOSX
 
72
 
 
73
int main(int argc, char *argv[]) {
 
74
#ifdef OS_MACOSX
 
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");
 
80
  int new_argc = 2;
 
81
  char **new_argv = tmp.get();
 
82
  InitGoogleWithBreakPad(new_argv[0], &new_argc, &new_argv, false);
 
83
  delete [] tmp[0];
 
84
  delete [] tmp[1];
 
85
#else  // OS_MACOSX
 
86
  InitGoogleWithBreakPad(argv[0], &argc, &argv, false);
 
87
#endif  // OS_MACOSX
 
88
 
 
89
  if (FLAGS_mode != "administration_dialog" &&
 
90
      !mozc::RunLevel::IsValidClientRunLevel()) {
 
91
    return -1;
 
92
  }
 
93
 
 
94
  // install Qt debug handler
 
95
  qInstallMsgHandler(mozc::gui::DebugUtil::MessageHandler);
 
96
 
 
97
  Q_INIT_RESOURCE(qrc_mozc_tool);
 
98
 
 
99
  // we cannot install the translation of qt_ja_JP here.
 
100
  // as Qpplication is initialized inside Run* function
 
101
 
 
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);
 
110
#ifdef OS_WINDOWS
 
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);
 
120
#endif  // OS_WINDOWS
 
121
#ifdef OS_MACOSX
 
122
  } else if (FLAGS_mode == "confirmation_dialog") {
 
123
    // Confirmation Dialog is used for the update dialog on Mac only.
 
124
    return RunConfirmationDialog(argc, argv);
 
125
#endif  // OS_MACOSX
 
126
  } else {
 
127
    LOG(ERROR) << "Unknown mode: " << FLAGS_mode;
 
128
    return -1;
 
129
  }
 
130
 
 
131
  return 0;
 
132
}