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

« back to all changes in this revision

Viewing changes to gui/error_message_dialog/error_message_dialog.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
#include "gui/error_message_dialog/error_message_dialog.h"
 
31
 
 
32
#include <QtCore/QTimer>
 
33
#include <QtGui/QtGui>
 
34
#include <QtGui/QMessageBox>
 
35
#include "base/base.h"
 
36
 
 
37
DEFINE_string(error_type, "", "type of error");
 
38
 
 
39
namespace mozc {
 
40
namespace gui {
 
41
namespace {
 
42
 
 
43
void OnFatal(const QString &message) {
 
44
  // we don't use QMessageBox::critical() here
 
45
  // to set WindowStaysOnTopHint
 
46
  QMessageBox message_box(QMessageBox::Critical,
 
47
                          QObject::tr("Mozc Fatal Error"),
 
48
                          message, QMessageBox::Ok, NULL,
 
49
                          Qt::Dialog |
 
50
                          Qt::MSWindowsFixedSizeDialogHint |
 
51
                          Qt::WindowStaysOnTopHint);
 
52
  DeleyedMessageDialogHandler handler(&message_box);
 
53
  handler.Exec();
 
54
}
 
55
}  // namespace
 
56
 
 
57
DeleyedMessageDialogHandler::DeleyedMessageDialogHandler(
 
58
    QMessageBox *message_box)
 
59
    : message_box_(message_box) {}
 
60
 
 
61
DeleyedMessageDialogHandler::~DeleyedMessageDialogHandler() {}
 
62
 
 
63
void DeleyedMessageDialogHandler::Exec() {
 
64
  const int kDisableInterval = 3000;
 
65
  QTimer::singleShot(kDisableInterval, this, SLOT(EnableOkButton()));
 
66
  QAbstractButton *button = message_box_->button(QMessageBox::Ok);
 
67
  if (button != NULL) {
 
68
    button->setEnabled(false);
 
69
  }
 
70
  message_box_->exec();
 
71
}
 
72
 
 
73
void DeleyedMessageDialogHandler::EnableOkButton() {
 
74
  QAbstractButton *button = message_box_->button(QMessageBox::Ok);
 
75
  if (button != NULL) {
 
76
    button->setEnabled(true);
 
77
  }
 
78
}
 
79
 
 
80
void ErrorMessageDialog::Show() {
 
81
  // defining all literal messages inside Show() method
 
82
  // for easy i18n/i10n
 
83
  if (FLAGS_error_type == "server_timeout") {
 
84
    OnFatal(QObject::tr("Conversion engine is not responding. "
 
85
                        "Please restart this application."));
 
86
  } else if (FLAGS_error_type == "server_broken_message") {
 
87
    OnFatal(QObject::tr("Connecting to an incompatible conversion engine. "
 
88
                        "Please restart your computer to enable Mozc. "
 
89
                        "If this problem persists, please uninstall Mozc "
 
90
                        "and install it again."));
 
91
  } else if (FLAGS_error_type == "server_version_mismatch") {
 
92
    OnFatal(QObject::tr("Conversion engine has been upgraded. "
 
93
                        "Please restart this application to enable conversion engine. "
 
94
                        "If the problem persists, please restart your computer."));
 
95
  } else if (FLAGS_error_type == "server_shutdown") {
 
96
    OnFatal(QObject::tr("Conversion engine is killed unexceptionally. "
 
97
                        "Restarting the engine..."));
 
98
  } else if (FLAGS_error_type == "server_fatal") {
 
99
    OnFatal(QObject::tr("Cannot start conversion engine. "
 
100
                        "Please restart your computer."));
 
101
  } else if (FLAGS_error_type == "renderer_version_mismatch") {
 
102
    OnFatal(QObject::tr("Candidate window renderer has been upgraded. "
 
103
                        "Please restart this application to enable new candidate window renderer. "
 
104
                        "If the problem persists, please restart your computer."));
 
105
  } else if (FLAGS_error_type == "renderer_fatal") {
 
106
    OnFatal(QObject::tr("Cannot start candidate window renderer. "
 
107
                        "Please restart your computer."));
 
108
  }
 
109
}
 
110
}  // gui
 
111
}  // mozc