1 // Copyright 2010-2018, 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/about_dialog/about_dialog.h"
31
32 #include <QtGui/QtGui>
33
34 #include <string>
35
36 #include "base/const.h"
37 #include "base/file_util.h"
38 #include "base/process.h"
39 #include "base/run_level.h"
40 #include "base/system_util.h"
41 #include "base/util.h"
42 #include "base/version.h"
43
44 namespace mozc {
45 namespace gui {
46 namespace {
47
defaultLinkActivated(const QString & str)48 void defaultLinkActivated(const QString &str) {
49 QByteArray utf8 = str.toUtf8();
50 Process::OpenBrowser(string(utf8.data(), utf8.length()));
51 }
52
53 // set document file paths by adding <server_path>/documents/ to file name.
AddLocalPath(string * str)54 bool AddLocalPath(string *str) {
55 const char *filenames[] = { "credits_en.html" };
56 for (size_t i = 0; i < arraysize(filenames); ++i) {
57 if (str->find(filenames[i]) != string::npos) {
58 string tmp;
59 const string file_path =
60 FileUtil::JoinPath(SystemUtil::GetDocumentDirectory(), filenames[i]);
61 Util::StringReplace(*str, filenames[i], file_path, false, &tmp);
62 *str = tmp;
63 return true;
64 }
65 }
66 return false;
67 }
68
SetLabelText(QLabel * label)69 void SetLabelText(QLabel *label) {
70 string label_text = label->text().toStdString();
71 if (AddLocalPath(&label_text)) {
72 label->setText(QString::fromStdString(label_text));
73 }
74 }
75
76 } // namespace
77
AboutDialog(QWidget * parent)78 AboutDialog::AboutDialog(QWidget *parent)
79 : QDialog(parent),
80 callback_(NULL) {
81 setupUi(this);
82 setWindowFlags(Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
83 setWindowModality(Qt::NonModal);
84 QPalette window_palette;
85 window_palette.setColor(QPalette::Window, QColor(255, 255, 255));
86 setPalette(window_palette);
87 setAutoFillBackground(true);
88 QString version_info("(");
89 version_info += Version::GetMozcVersion().c_str();
90 version_info += ")";
91 version_label->setText(version_info);
92
93 QPalette palette;
94 palette.setColor(QPalette::Window, QColor(236, 233, 216));
95 color_frame->setPalette(palette);
96 color_frame->setAutoFillBackground(true);
97
98 // change font size for product name
99 QFont font = label->font();
100 #ifdef OS_WIN
101 font.setPointSize(22);
102 #endif // OS_WIN
103
104 #ifdef OS_MACOSX
105 font.setPointSize(26);
106 #endif // OS_MACOSX
107
108 label->setFont(font);
109
110 SetLabelText(label_terms);
111 SetLabelText(label_credits);
112
113 #ifdef OS_DRAGONFLY
114 product_image_.reset(new QImage(LOCALBASE "/share/mozc-tool/icons/product_logo.png"));
115 #else
116 product_image_.reset(new QImage(":/product_logo.png"));
117 #endif
118 }
119
paintEvent(QPaintEvent * event)120 void AboutDialog::paintEvent(QPaintEvent *event) {
121 // draw product logo
122 QPainter painter(this);
123 const QRect image_rect = product_image_->rect();
124 // allow clipping on right / bottom borders
125 const QRect draw_rect(std::max(5, width() - image_rect.width() - 15),
126 std::max(0, color_frame->y() - image_rect.height()),
127 image_rect.width(), image_rect.height());
128 painter.drawImage(draw_rect, *product_image_.get());
129 }
130
SetLinkCallback(LinkCallbackInterface * callback)131 void AboutDialog::SetLinkCallback(LinkCallbackInterface *callback) {
132 callback_ = callback;
133 }
134
linkActivated(const QString & link)135 void AboutDialog::linkActivated(const QString &link) {
136 // we don't activate the link if about dialog is running as root
137 if (!RunLevel::IsValidClientRunLevel()) {
138 return;
139 }
140 if (callback_ != NULL) {
141 callback_->linkActivated(link);
142 } else {
143 defaultLinkActivated(link);
144 }
145 }
146
147 } // namespace gui
148 } // namespace mozc
149