Codebase list mozc / caca91e
Update from the upstream. * Increased the build number to 4180 (2.25.4180). * Code refactoring. Hiroyuki Komatsu 3 years ago
76 changed file(s) with 265 addition(s) and 236 deletion(s). Raw diff Collapse all Expand all
5353 ClockImpl() : timezone_offset_sec_(0) {}
5454 #endif // OS_NACL
5555
56 virtual ~ClockImpl() {}
56 ~ClockImpl() override {}
5757
58 virtual void GetTimeOfDay(uint64 *sec, uint32 *usec) {
58 void GetTimeOfDay(uint64 *sec, uint32 *usec) override {
5959 #ifdef OS_WIN
6060 FILETIME file_time;
6161 GetSystemTimeAsFileTime(&file_time);
8282 #endif // OS_WIN
8383 }
8484
85 virtual uint64 GetTime() {
85 uint64 GetTime() override {
8686 #ifdef OS_WIN
8787 return static_cast<uint64>(_time64(nullptr));
8888 #else
9090 #endif // OS_WIN
9191 }
9292
93 virtual bool GetTmWithOffsetSecond(time_t offset_sec, tm *output) {
93 bool GetTmWithOffsetSecond(time_t offset_sec, tm *output) override {
9494 const time_t current_sec = static_cast<time_t>(this->GetTime());
9595 const time_t modified_sec = current_sec + offset_sec;
9696
111111 return true;
112112 }
113113
114 virtual uint64 GetFrequency() {
114 uint64 GetFrequency() override {
115115 #if defined(OS_WIN)
116116 LARGE_INTEGER timestamp;
117117 // TODO(yukawa): Consider the case where QueryPerformanceCounter is not
131131 #endif // platforms (OS_WIN, __APPLE__, OS_LINUX, ...)
132132 }
133133
134 virtual uint64 GetTicks() {
134 uint64 GetTicks() override {
135135 // TODO(team): Use functions in <chrono> once the use of it is approved.
136136 #if defined(OS_WIN)
137137 LARGE_INTEGER timestamp;
2727 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
2929 #include "base/clock_mock.h"
30
3031 #include "base/util.h"
3132 #include "testing/base/public/googletest.h"
3233 #include "testing/base/public/gunit.h"
4646
4747 class CodeGenByteArrayStreamTest : public testing::Test {
4848 protected:
49 virtual void SetUp() {
49 void SetUp() override {
5050 result_stream_.reset(new std::ostringstream());
5151 codegen_stream_.reset(new mozc::CodeGenByteArrayOutputStream(
5252 result_stream_.get(), mozc::codegenstream::NOT_OWN_STREAM));
5353 }
5454
55 virtual void TearDown() {
55 void TearDown() override {
5656 codegen_stream_.reset();
5757 result_stream_.reset();
5858 }
3535 #include <cstring>
3636 #include <map>
3737 #include <sstream>
38
3839 #include "base/file_stream.h"
3940 #include "base/file_util.h"
4041 #include "base/logging.h"
2626 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
29 #include "base/config_file_stream.h"
30
2931 #include <cstddef>
3032 #include <ios>
3133 #include <istream>
3234 #include <memory>
3335
34 #include "base/config_file_stream.h"
3536 #include "base/file_util.h"
3637 #include "base/system_util.h"
3738 #include "testing/base/public/googletest.h"
6970
7071 class ConfigFileStreamTest : public testing::Test {
7172 protected:
72 virtual void SetUp() {
73 void SetUp() override {
7374 default_profile_directory_ = SystemUtil::GetUserProfileDirectory();
7475 SystemUtil::SetUserProfileDirectory(FLAGS_test_tmpdir);
7576 }
7677
77 virtual void TearDown() {
78 void TearDown() override {
7879 SystemUtil::SetUserProfileDirectory(default_profile_directory_);
7980 }
8081
206207 ASSERT_NE(nullptr, ifs.get());
207208 std::string line;
208209 int line_number = 0; // note that this is 1-origin.
209 while (!getline(*ifs.get(), line).fail()) {
210 while (!std::getline(*ifs, line).fail()) {
210211 ++line_number;
211212 ASSERT_LE(line_number, arraysize(kExpectedLines));
212213 EXPECT_EQ(line, kExpectedLines[line_number - 1])
5959 class CPUStats : public CPUStatsInterface {
6060 public:
6161 CPUStats();
62 virtual ~CPUStats();
62 ~CPUStats() override;
6363
6464 // return 0.0 if CPU load is unknown
65 float GetSystemCPULoad();
65 float GetSystemCPULoad() override;
6666
6767 // return 0.0 if CPU load is unknown
68 float GetCurrentProcessCPULoad();
68 float GetCurrentProcessCPULoad() override;
6969
7070 // return the number of processors
71 size_t GetNumberOfProcessors() const;
71 size_t GetNumberOfProcessors() const override;
7272
7373 private:
7474 uint64 prev_system_total_times_;
4545 class DummyThread : public mozc::Thread {
4646 public:
4747 DummyThread() {}
48 void Run() {
48 void Run() override {
4949 volatile uint64 n = 0;
5050 while (true) {
5151 ++n;
2626 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
29 #include "base/encryptor.h"
30
2931 #include <memory>
3032
31 #include "base/encryptor.h"
3233 #include "base/password_manager.h"
3334 #include "base/system_util.h"
3435 #include "base/util.h"
304304 InputFileStream ifs(to.c_str());
305305 EXPECT_TRUE(ifs.good());
306306 std::string line;
307 getline(ifs, line);
307 std::getline(ifs, line);
308308 EXPECT_EQ("test", line);
309309 }
310310
5050
5151 class FlagsTest : public testing::Test {
5252 protected:
53 void SetUp() {
53 void SetUp() override {
5454 FLAGS_test_string = "hogehoge";
5555 FLAGS_test_int32 = 20;
5656 FLAGS_test_int64 = 29051773239673121LL;
255255 prot |= PROT_WRITE;
256256 }
257257
258 void *ptr = mmap(0, st.st_size, prot, MAP_SHARED, fd, 0);
258 void *ptr = mmap(nullptr, st.st_size, prot, MAP_SHARED, fd, 0);
259259 if (ptr == MAP_FAILED) {
260260 LOG(WARNING) << "mmap() failed: " << filename;
261261 return false;
4848 #endif // OS_NACL
4949
5050 Mmap();
51 virtual ~Mmap() { Close(); }
51 ~Mmap() override { Close(); }
5252
5353 bool Open(const char *filename, const char *mode = "r");
5454 void Close();
4848 InputMultiFile::~InputMultiFile() { ifs_.reset(); }
4949
5050 bool InputMultiFile::ReadLine(std::string *line) {
51 if (ifs_.get() == nullptr) {
51 if (ifs_ == nullptr) {
5252 return false;
5353 }
5454 do {
55 if (!getline(*ifs_, *line).fail()) {
55 if (!std::getline(*ifs_, *line).fail()) {
5656 return true;
5757 }
5858 } while (OpenNext());
159159 // PlainPasswordManager
160160 class PlainPasswordManager : public PasswordManagerInterface {
161161 public:
162 virtual bool SetPassword(const std::string &password) const;
163 virtual bool GetPassword(std::string *password) const;
164 virtual bool RemovePassword() const;
162 bool SetPassword(const std::string &password) const override;
163 bool GetPassword(std::string *password) const override;
164 bool RemovePassword() const override;
165165 };
166166
167167 bool PlainPasswordManager::SetPassword(const std::string &password) const {
2727 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
2929 #include "base/password_manager.h"
30
3031 #include "base/system_util.h"
3132 #include "testing/base/public/googletest.h"
3233 #include "testing/base/public/gunit.h"
3333 #else
3434 #include <string.h>
3535 #include <sys/stat.h>
36
3637 #include <cerrno>
3738 #endif // OS_WIN
3839
4041 #include <fcntl.h>
4142 #include <signal.h>
4243 #include <spawn.h> // for posix_spawn().
44
4345 #include "base/mac_process.h"
4446 #endif // __APPLE__
4547
3030
3131 #ifndef OS_WIN
3232 #include <unistd.h>
33
3334 #include <cstdlib>
3435 #endif // OS_WIN
3536
4647
4748 class ProcessMutexTest : public testing::Test {
4849 protected:
49 virtual void SetUp() {
50 void SetUp() override {
5051 original_user_profile_dir_ = SystemUtil::GetUserProfileDirectory();
5152 SystemUtil::SetUserProfileDirectory(FLAGS_test_tmpdir);
5253 }
5354
54 virtual void TearDown() {
55 void TearDown() override {
5556 ProcessMutex mutex(kName);
5657 if (FileUtil::FileExists(mutex.lock_filename())) {
5758 LOG(FATAL) << "Lock file unexpectedly remains: " << mutex.lock_filename();
171171 Util::SetRandomSeed(static_cast<uint32>(Clock::GetTime()));
172172 }
173173
174 virtual ~SchedulerImpl() { RemoveAllJobs(); }
175
176 virtual void RemoveAllJobs() {
174 ~SchedulerImpl() override { RemoveAllJobs(); }
175
176 void RemoveAllJobs() override {
177177 scoped_lock l(&mutex_);
178178 jobs_.clear();
179179 }
186186 DCHECK(job_setting.callback() != nullptr);
187187 }
188188
189 virtual bool AddJob(const Scheduler::JobSetting &job_setting) {
189 bool AddJob(const Scheduler::JobSetting &job_setting) override {
190190 scoped_lock l(&mutex_);
191191
192192 ValidateSetting(job_setting);
217217 return true;
218218 }
219219
220 virtual bool RemoveJob(const std::string &name) {
220 bool RemoveJob(const std::string &name) override {
221221 scoped_lock l(&mutex_);
222222 if (!HasJob(name)) {
223223 LOG(WARNING) << "Job " << name << " is not registered";
226226 return (jobs_.erase(name) != 0);
227227 }
228228
229 virtual bool HasJob(const std::string &name) const {
229 bool HasJob(const std::string &name) const override {
230230 return (jobs_.find(name) != jobs_.end());
231231 }
232232
5252 class SchedulerStub : public Scheduler::SchedulerInterface {
5353 public:
5454 SchedulerStub();
55 virtual ~SchedulerStub();
55 ~SchedulerStub() override;
5656
5757 // |random_delay| will be ignored.
58 virtual bool AddJob(const Scheduler::JobSetting &job_setting);
59 virtual bool RemoveJob(const std::string &name);
60 virtual void RemoveAllJobs();
61 virtual bool HasJob(const std::string &name) const;
58 bool AddJob(const Scheduler::JobSetting &job_setting) override;
59 bool RemoveJob(const std::string &name) override;
60 void RemoveAllJobs() override;
61 bool HasJob(const std::string &name) const override;
6262
6363 // Puts stub internal clock forward.
6464 // Jobs will be executed according to forwarded time.
4343
4444 class SchedulerStubTest : public ::testing::Test {
4545 protected:
46 virtual void SetUp() {
46 void SetUp() override {
4747 g_counter = 0;
4848 g_result = true;
4949 }
5050
51 virtual void TearDown() {
51 void TearDown() override {
5252 g_counter = 0;
5353 g_result = true;
5454 }
6161 };
6262
6363 protected:
64 virtual void TearDown() { Scheduler::RemoveAllJobs(); }
64 void TearDown() override { Scheduler::RemoveAllJobs(); }
6565 };
6666
6767 TEST_F(SchedulerTest, SimpleJob) {
255255 explicit NameCheckScheduler(const std::string &expected_name)
256256 : expected_name_(expected_name) {}
257257
258 void RemoveAllJobs() {}
259 bool RemoveJob(const std::string &name) { return true; }
260 bool AddJob(const Scheduler::JobSetting &job_setting) {
258 void RemoveAllJobs() override {}
259 bool RemoveJob(const std::string &name) override { return true; }
260 bool AddJob(const Scheduler::JobSetting &job_setting) override {
261261 return (expected_name_ == job_setting.name());
262262 }
263 bool HasJob(const std::string &name) const { return expected_name_ == name; }
263 bool HasJob(const std::string &name) const override {
264 return expected_name_ == name;
265 }
264266
265267 private:
266268 const std::string expected_name_;
3434 #include <string>
3535
3636 #include "base/port.h"
37 #include "testing/base/public/gunit.h"
3738 #include "absl/strings/string_view.h"
38 #include "testing/base/public/gunit.h"
3939
4040 namespace mozc {
4141 namespace {
2727 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
2929 #include "base/singleton.h"
30
3031 #include <stdlib.h>
32
3133 #include "base/thread.h"
3234 #include "base/util.h"
3335 #include "testing/base/public/gunit.h"
5456
5557 class ThreadTest : public Thread {
5658 public:
57 void Run() { instance_ = Singleton<ThreadInstance>::get(); }
59 void Run() override { instance_ = Singleton<ThreadInstance>::get(); }
5860
5961 ThreadInstance *get() { return instance_; }
6062
3939
4040 class StopwatchTest : public testing::Test {
4141 protected:
42 void SetUp() {
42 void SetUp() override {
4343 clock_mock_.reset(new ClockMock(0, 0));
4444 // 1GHz (Accuracy = 1ns)
4545 clock_mock_->SetFrequency(uint64{1000000000});
4646 Clock::SetClockForUnitTest(clock_mock_.get());
4747 }
4848
49 void TearDown() { Clock::SetClockForUnitTest(nullptr); }
49 void TearDown() override { Clock::SetClockForUnitTest(nullptr); }
5050
5151 void PutForwardNanoseconds(uint64 nano_sec) {
5252 clock_mock_->PutClockForwardByTicks(nano_sec);
395395 # else
396396 return "/usr/lib/mozc";
397397 # endif // MOZC_SERVER_DIRECTORY
398
399 #else // OS_LINUX || OS_ANDROID || OS_NACL || OS_WASM
400 # error "unknown platform"
401
402398 #endif // OS_LINUX || OS_ANDROID || OS_NACL || OS_WASM
399
400 // If none of the above platforms is specified, the compiler raises an error
401 // because of no return value.
403402 }
404403
405404 std::string SystemUtil::GetServerPath() {
472471 return ppw->pw_name;
473472 #endif // OS_ANDROID
474473
475 // __APPLE__, OS_LINUX or OS_NACL
474 #if defined(__APPLE__) || defined(OS_LINUX) || defined(OS_WASM)
476475 struct passwd pw, *ppw;
477476 char buf[1024];
478477 CHECK_EQ(0, getpwuid_r(geteuid(), &pw, buf, sizeof(buf), &ppw));
479478 return pw.pw_name;
479 #endif // __APPLE__ || OS_LINUX || OS_WASM
480
481 // If none of the above platforms is specified, the compiler raises an error
482 // because of no return value.
480483 }
481484
482485 #ifdef OS_WIN
885888 # else // defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES)
886889 return 0;
887890 # endif // defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES)
888
889 #else // OS_LINUX || OS_ANDROID || OS_NACL || OS_WASM
890 # error "unknown platform"
891
892891 #endif // OS_LINUX || OS_ANDROID || OS_NACL || OS_WASM
892
893 // If none of the above platforms is specified, the compiler raises an error
894 // because of no return value.
893895 }
894896
895897 } // namespace mozc
3737 class TestThread : public Thread {
3838 public:
3939 explicit TestThread(int time) : time_(time), invoked_(false) {}
40 virtual ~TestThread() {}
40 ~TestThread() override {}
4141
42 virtual void Run() {
42 void Run() override {
4343 invoked_ = true;
4444 Util::Sleep(time_);
4545 }
3636 #include <vector>
3737
3838 #include "base/logging.h"
39 #include "base/util.h"
3940 #include "absl/strings/string_view.h"
40 #include "base/util.h"
4141
4242 namespace mozc {
4343
9393 delete sub_trie;
9494 trie_.erase(std::string(GetKeyHead(key)));
9595 // If the size of trie_ is 0, This trie should be deleted.
96 return trie_.size() == 0;
96 return trie_.empty();
9797 } else {
9898 return false;
9999 }
4343 : event_(event), timeout_(timeout) {}
4444
4545 public:
46 virtual void Run() {
46 void Run() override {
4747 Util::Sleep(timeout_);
4848 LOG(INFO) << "Notify event";
4949 event_->Notify();
2727 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
2929 #include "base/unverified_aes256.h"
30
3031 #include "testing/base/public/googletest.h"
3132 #include "testing/base/public/gunit.h"
3233
2727 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
2929 #include "base/unverified_sha1.h"
30
3031 #include "testing/base/public/googletest.h"
3132 #include "testing/base/public/gunit.h"
3233
12811281 void Util::AppendCGIParams(
12821282 const std::vector<std::pair<std::string, std::string> > &params,
12831283 std::string *base) {
1284 if (params.size() == 0 || base == nullptr) {
1284 if (params.empty() || base == nullptr) {
12851285 return;
12861286 }
12871287
6767
6868 // Read tsv file.
6969 std::string line;
70 while (!getline(finput, line).fail()) {
70 while (!std::getline(finput, line).fail()) {
7171 if (Util::StartsWith(line, "#")) {
7272 // Skip comment line.
7373 continue;
3030 #define MOZC_BASE_VERSION_H_
3131
3232 #include <string>
33
3334 #include "base/port.h"
3435
3536 namespace mozc {
5757 std::string command;
5858 std::string left, focused, right;
5959
60 while (getline(std::cin, command)) {
60 while (std::getline(std::cin, command)) {
6161 if (command == "<") {
6262 composer->MoveCursorLeft();
6363 } else if (command == "<<") {
9393 void TypingCorrector::InsertCharacter(
9494 const absl::string_view key, const ProbableKeyEvents &probable_key_events) {
9595 raw_key_.append(key.data(), key.size());
96 if (!IsAvailable() || probable_key_events.size() == 0) {
96 if (!IsAvailable() || probable_key_events.empty()) {
9797 // If this corrector is not available or no ProbableKeyEvent is available,
9898 // just append |key| to each corrections.
9999 for (size_t i = 0; i < top_n_.size(); ++i) {
492492 mozc::Segments segments;
493493 std::string line;
494494
495 while (!getline(std::cin, line).fail()) {
495 while (!std::getline(std::cin, line).fail()) {
496496 if (mozc::ExecCommand(*converter, &segments, line, request)) {
497497 if (FLAGS_output_debug_string) {
498498 mozc::PrintSegments(segments, &std::cout);
431431
432432 std::string converted;
433433 int segment_num = 0;
434 while (1) {
434 while (true) {
435435 int position = -1;
436436 for (size_t i = 0; i < segments.segment(segment_num).candidates_size();
437437 ++i) {
409409 return false;
410410 }
411411
412 if (key.size() == 0 || key.size() >= kMaxSize) {
412 if (key.empty() || key.size() >= kMaxSize) {
413413 VLOG(1) << "invalid key length";
414414 return false;
415415 }
4949
5050 std::string line;
5151 std::vector<std::string> columns;
52 while (getline(*id_def, line)) {
52 while (std::getline(*id_def, line)) {
5353 columns.clear();
5454 Util::SplitStringUsing(line, " ", &columns);
5555 CHECK_EQ(2, columns.size());
165165 return false;
166166 }
167167 std::string line;
168 while (!getline(ifs, line).fail()) {
168 while (!std::getline(ifs, line).fail()) {
169169 if (line.empty() || line.c_str()[0] == '#') {
170170 continue;
171171 }
3232 MINOR = 25
3333
3434 # Number to be increased. This value may be replaced by other tools.
35 BUILD = 4150
35 BUILD = 4180
3636
3737 # Represent the platform and release channel.
3838 REVISION = 100
242242
243243 // Step 2.
244244 key_info_list->clear();
245 if (reduce_buffer.size() == 0) {
245 if (reduce_buffer.empty()) {
246246 return;
247247 }
248248 KeyInfo last_key_info;
253253 // Move instances to backup vector.
254254 std::vector<UserDictionary::Entry *> backup(entries->pointer_begin(),
255255 entries->pointer_end());
256 while (entries->size() > 0) {
256 while (!entries->empty()) {
257257 entries->ReleaseLast();
258258 }
259259
4949 Process::OpenBrowser(std::string(utf8.data(), utf8.length()));
5050 }
5151
52 inline void Replace(QString &str, const char pattern[], const char repl[]) {
53 str.replace(QLatin1String(pattern), QLatin1String(repl));
54 }
55
56 inline void Replace(QString &str, const char pattern[], const QString &repl) {
57 str.replace(QLatin1String(pattern), repl);
58 }
59
5260 QString ReplaceString(const QString &str) {
5361 QString replaced(str);
54 replaced.replace("[ProductName]", GuiUtil::ProductName());
62 Replace(replaced, "[ProductName]", GuiUtil::ProductName());
5563
5664 #ifdef GOOGLE_JAPANESE_INPUT_BUILD
57 replaced.replace("[ProductUrl]", "https://www.google.co.jp/ime/");
58 replaced.replace("[ForumUrl]",
59 "https://support.google.com/gboard/community?hl=ja");
60 replaced.replace("[ForumName]", QObject::tr("issues"));
65 Replace(replaced, "[ProductUrl]", "https://www.google.co.jp/ime/");
66 Replace(replaced, "[ForumUrl]",
67 "https://support.google.com/gboard/community?hl=ja");
68 Replace(replaced, "[ForumName]", QObject::tr("issues"));
6169 #else
62 replaced.replace("[ProductUrl]", "https://github.com/google/mozc");
63 replaced.replace("[ForumUrl]", "https://github.com/google/mozc/issues");
64 replaced.replace("[ForumName]", QObject::tr("issues"));
70 Replace(replaced, "[ProductUrl]", "https://github.com/google/mozc");
71 Replace(replaced, "[ForumUrl]", "https://github.com/google/mozc/issues");
72 Replace(replaced, "[ForumName]", QObject::tr("issues"));
6573 #endif // GOOGLE_JAPANESE_INPUT_BUILD
6674
6775 const std::string credit_filepath =
6876 FileUtil::JoinPath(SystemUtil::GetDocumentDirectory(), "credits_en.html");
69 replaced.replace("credits_en.html", credit_filepath.c_str());
77 Replace(replaced, "credits_en.html", credit_filepath.c_str());
7078
7179 return replaced;
7280 }
8593 window_palette.setColor(QPalette::Window, QColor(255, 255, 255));
8694 setPalette(window_palette);
8795 setAutoFillBackground(true);
88 QString version_info("(");
89 version_info += Version::GetMozcVersion().c_str();
90 version_info += ")";
91 version_label->setText(version_info);
96 std::string version_info = "(" + Version::GetMozcVersion() + ")";
97 version_label->setText(QLatin1String(version_info.c_str()));
9298 GuiUtil::ReplaceWidgetLabels(this);
9399
94100 QPalette palette;
111117 SetLabelText(label_terms);
112118 SetLabelText(label_credits);
113119
114 product_image_ = absl::make_unique<QImage>(":/product_logo.png");
120 product_image_ =
121 absl::make_unique<QImage>(QLatin1String(":/product_logo.png"));
115122 }
116123
117124 void AboutDialog::paintEvent(QPaintEvent *event) {
122129 const QRect draw_rect(std::max(5, width() - image_rect.width() - 15),
123130 std::max(0, color_frame->y() - image_rect.height()),
124131 image_rect.width(), image_rect.height());
125 painter.drawImage(draw_rect, *product_image_.get());
132 painter.drawImage(draw_rect, *product_image_);
126133 }
127134
128135 void AboutDialog::SetLinkCallback(LinkCallbackInterface *callback) {
4040 namespace mozc {
4141 namespace gui {
4242
43 #ifdef OS_WIN
4344 using mozc::config::StatsConfigUtil;
45 #endif // OS_WIN
4446
4547 AdministrationDialog::AdministrationDialog()
4648 : dialog_title_(
6466
6567 #ifdef CHANNEL_DEV
6668 usageStatsCheckBox->setEnabled(false);
67 #endif
69 #endif // CHANNEL_DEV
6870
6971 usageStatsCheckBox->setChecked(StatsConfigUtil::IsEnabled());
7072
132134 ElevatedProcessDisabledcheckBox->isChecked()) {
133135 if (!RunLevel::SetElevatedProcessDisabled(
134136 ElevatedProcessDisabledcheckBox->isChecked())) {
135 QMessageBox::critical(
136 this, dialog_title_,
137 tr("Failed to save the UAC policy setting. "
138 "Administrator privilege is required to "
139 "change UAC settings."));
137 QMessageBox::critical(this, dialog_title_,
138 tr("Failed to save the UAC policy setting. "
139 "Administrator privilege is required to "
140 "change UAC settings."));
140141 }
141142 }
142143 QWidget::close();
7171
7272 // Load "<translation_path>/qt_<lang>.qm" from a qrc file.
7373 bool loaded = translator->load(
74 QLocale::system(), "qt", "_",
75 QLibraryInfo::location(QLibraryInfo::TranslationsPath), ".qm");
74 QLocale::system(), QLatin1String("qt"), QLatin1String("_"),
75 QLibraryInfo::location(QLibraryInfo::TranslationsPath),
76 QLatin1String(".qm"));
7677 if (loaded) {
7778 qApp->installTranslator(translator);
7879 } else {
8788
8889 // static
8990 std::unique_ptr<QApplication> GuiUtil::InitQt(int &argc, char *argv[]) {
90 QApplication::setStyle(QStyleFactory::create("fusion"));
91 QApplication::setStyle(QStyleFactory::create(QLatin1String("fusion")));
9192 #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
9293 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
9394 #endif
114115 std::unique_ptr<QTranslator> translator(new QTranslator);
115116
116117 // Load ":/<resource_name>_<lang>.qm" from a qrc file.
117 if (translator->load(QLocale::system(), resource_name, "_", ":/", ".qm")) {
118 if (translator->load(QLocale::system(), QLatin1String(resource_name),
119 QLatin1String("_"), QLatin1String(":/"),
120 QLatin1String(".qm"))) {
118121 qApp->installTranslator(translator.get());
119122 translators->emplace(resource_name, std::move(translator));
120123 }
155158 // static
156159 QString GuiUtil::ReplaceString(const QString &str) {
157160 QString replaced(str);
158 return replaced.replace("[ProductName]", GuiUtil::ProductName());
161 return replaced.replace(QLatin1String("[ProductName]"),
162 GuiUtil::ProductName());
159163 }
160164
161165 } // namespace gui
4444 return QObject::eventFilter(obj, event);
4545 }
4646
47 const QString prefix = " (Dev ";
47 const QString prefix = QLatin1String(" (Dev ");
4848 const QString& title = w->windowTitle();
4949 // The window title can be empty, even if it is specified.
5050 // See: https://doc.qt.io/qt-5/qmessagebox.html#setWindowTitle
152152 // Preedit Katakan is always FULLWIDTH
153153 // This item should not be editable
154154 if (group == QObject::tr("Katakana")) {
155 item_preedit->setFlags(0); // disable flag
155 item_preedit->setFlags(nullptr); // disable flag
156156 }
157157
158158 setItem(row, 0, item_group);
3737 #include <algorithm> // for unique
3838 #include <cctype>
3939 #include <sstream>
40 #include <set>
4041 #include <string>
41 #include <vector>
4242
4343 #include "base/file_stream.h"
4444 #include "base/logging.h"
5454 int GetTableHeight(QTableWidget *widget) {
5555 // Dragon Hack:
5656 // Here we use "龍" to calc font size, as it looks almost square
57 const QRect rect = QFontMetrics(widget->font()).boundingRect("龍");
57 const QRect rect =
58 QFontMetrics(widget->font()).boundingRect(QString::fromUtf8("龍"));
5859 #ifdef OS_WIN
5960 return static_cast<int>(rect.height() * 1.3);
6061 #else
131132 }
132133
133134 void GenericTableEditorDialog::DeleteSelectedItems() {
134 std::vector<int> rows;
135 std::set<int> rows;
135136 QList<QTableWidgetItem *> selected = editorTableWidget->selectedItems();
136137
137 // remember the last column as user chooses the
138 // last rows from top to bottom in general.
139 const int column = selected.isEmpty() ? 0 : selected.back()->column();
140
141 for (int i = 0; i < selected.size(); ++i) {
142 rows.push_back(selected[i]->row());
143 }
144
145 std::vector<int>::iterator last = std::unique(rows.begin(), rows.end());
146 rows.erase(last, rows.end());
138 for (auto item : selected) {
139 rows.insert(item->row());
140 }
147141
148142 if (rows.empty()) {
149143 QMessageBox::warning(this, windowTitle(), tr("No entry is selected"));
150144 return;
151145 }
152146
153 // Choose next or prev item.
154 QTableWidgetItem *item = editorTableWidget->item(rows.back() + 1, column);
155 if (item == nullptr) {
156 item = editorTableWidget->item(rows.back() - 1, column);
157 }
158
159 // select item
160 if (item != nullptr) {
161 editorTableWidget->setCurrentItem(item);
162 }
163
164 // remove from the buttom
165 for (int i = rows.size() - 1; i >= 0; --i) {
166 editorTableWidget->removeRow(rows[i]);
147 // Keep the current cursor position after the deletion.
148 {
149 // remember the last column as user chooses the
150 // last rows from top to bottom in general.
151 const int cur_col = selected.back()->column();
152 const int cur_row = selected.back()->row();
153 QTableWidgetItem *cur_item = editorTableWidget->item(cur_row + 1, cur_col);
154 if (cur_item == nullptr) {
155 cur_item = editorTableWidget->item(cur_row - 1, cur_col);
156 }
157
158 // select item
159 if (cur_item != nullptr) {
160 editorTableWidget->setCurrentItem(cur_item);
161 }
162 }
163
164 // remove from the bottom
165 for (auto rit = rows.rbegin(); rit != rows.rend(); ++rit) {
166 editorTableWidget->removeRow(*rit);
167167 }
168168
169169 UpdateMenuStatus();
184184
185185 editorTableWidget->insertRow(row);
186186 for (size_t i = 0; i < column_size_; ++i) {
187 editorTableWidget->setItem(row, i, new QTableWidgetItem(""));
187 editorTableWidget->setItem(row, i, new QTableWidgetItem(QLatin1String("")));
188188 }
189189 QTableWidgetItem *item = editorTableWidget->item(row, 0);
190190 if (item != nullptr) {
258258 return;
259259 }
260260
261 const QString filename =
262 QFileDialog::getSaveFileName(this, tr("export to file"),
263 QDir::homePath() + QDir::separator() +
264 QString(GetDefaultFilename().c_str()));
261 const QString filename = QFileDialog::getSaveFileName(
262 this, tr("export to file"),
263 QDir::homePath() + QDir::separator() +
264 QString::fromUtf8(GetDefaultFilename().c_str()));
265265 if (filename.isEmpty()) {
266266 return;
267267 }
4747 explicit GenericTableEditorDialog(QWidget *parent, size_t column_size);
4848 ~GenericTableEditorDialog() override;
4949
50 bool LoadFromString(const std::string &table);
50 bool LoadFromString(const std::string &str);
5151 const std::string &table() const;
5252
5353 protected slots:
219219 // are pressed. If Hiragana/Eisu key is pressed, we assume that
220220 // the key is already released at the same time.
221221 // Hankaku/Zenkaku key is preserved key and modifier keys are ignored.
222 if (modifier_non_required_key_ == "Hiragana" ||
223 modifier_non_required_key_ == "Katakana" ||
224 modifier_non_required_key_ == "Eisu" ||
225 modifier_non_required_key_ == "Hankaku/Zenkaku") {
222 if (modifier_non_required_key_ == QLatin1String("Hiragana") ||
223 modifier_non_required_key_ == QLatin1String("Katakana") ||
224 modifier_non_required_key_ == QLatin1String("Eisu") ||
225 modifier_non_required_key_ == QLatin1String("Hankaku/Zenkaku")) {
226226 *result = modifier_non_required_key_;
227227 return KeyBindingFilter::SUBMIT_KEY;
228228 }
230230 QStringList results;
231231
232232 if (ctrl_pressed_) {
233 results << "Ctrl";
233 results << QLatin1String("Ctrl");
234234 }
235235
236236 if (shift_pressed_) {
237 results << "Shift";
237 results << QLatin1String("Shift");
238238 }
239239
240240 if (alt_pressed_) {
241241 #ifdef __APPLE__
242 results << "Option";
242 results << QLatin1String("Option");
243243 #else
244244 // Do not support and show keybindings with alt for Windows
245245 // results << "Alt";
364364 for (size_t i = 0; i < arraysize(kQtKeyModifierNonRequiredTable); ++i) {
365365 if (kQtKeyModifierNonRequiredTable[i].qt_key == qt_key) {
366366 modifier_non_required_key_ =
367 kQtKeyModifierNonRequiredTable[i].mozc_key_name;
367 QLatin1String(kQtKeyModifierNonRequiredTable[i].mozc_key_name);
368368 return Encode(result);
369369 }
370370 }
375375 for (size_t i = 0; i < arraysize(kWinVirtualKeyModifierNonRequiredTable);
376376 ++i) {
377377 if (kWinVirtualKeyModifierNonRequiredTable[i].virtual_key == virtual_key) {
378 modifier_non_required_key_ =
379 kWinVirtualKeyModifierNonRequiredTable[i].mozc_key_name;
378 modifier_non_required_key_ = QLatin1String(
379 kWinVirtualKeyModifierNonRequiredTable[i].mozc_key_name);
380380 return Encode(result);
381381 }
382382 }
401401 // 3. Press "Hiragana/Katakana" (shift_pressed_ == false)
402402 const bool with_shift = (key_event.modifiers() & Qt::ShiftModifier) != 0;
403403 if (with_shift && (qt_key == Qt::Key_Hiragana_Katakana)) {
404 modifier_non_required_key_ = "Katakana";
404 modifier_non_required_key_ = QLatin1String("Katakana");
405405 return Encode(result);
406406 }
407407 #endif
408408
409409 if (qt_key == Qt::Key_yen) {
410410 // Japanese Yen mark, treat it as backslash for compatibility
411 modifier_non_required_key_ = "\\";
411 modifier_non_required_key_ = QLatin1String("\\");
412412 return Encode(result);
413413 }
414414
415415 // printable command, which requires modifier keys
416416 if ((qt_key >= 0x21 && qt_key <= 0x60) ||
417417 (qt_key >= 0x7B && qt_key <= 0x7E)) {
418 const char key_char = static_cast<char>(qt_key);
418419 if (qt_key >= 0x41 && qt_key <= 0x5A) {
419 modifier_required_key_ = static_cast<char>(qt_key - 'A' + 'a');
420 modifier_required_key_ = QLatin1Char(key_char - 'A' + 'a');
420421 } else {
421 modifier_required_key_ = static_cast<char>(qt_key);
422 modifier_required_key_ = QLatin1Char(key_char);
422423 }
423424 return Encode(result);
424425 }
440441 }
441442
442443 // TODO(taku): the following sequence doesn't work as once
443 // user relase any of keys, the statues goes to "submitted"
444 // user release any of keys, the statues goes to "submitted"
444445 // 1. Press Ctrl + a
445446 // 2. Release a, but keep pressing Ctrl
446447 // 3. Press b (the result should be "Ctrl + b").
4040
4141 class KeyBindingEditorTriggerButton : public QPushButton {
4242 public:
43 KeyBindingEditorTriggerButton(QWidget *parent)
43 explicit KeyBindingEditorTriggerButton(QWidget *parent)
4444 : QPushButton(parent), editor_(new KeyBindingEditor(parent, this)) {
4545 editor_->setModal(true); // create a modal dialog
4646 setFocusProxy(editor_.get());
506506 } else if (action == actions_[EXPORT_TO_FILE_INDEX]) {
507507 Export();
508508 }
509
510 return;
511509 }
512510
513511 // static
9696 CHECK(ifs.get() != nullptr); // should never happen
9797 std::string line, result;
9898 std::vector<std::string> fields;
99 while (std::getline(*ifs.get(), line)) {
99 while (std::getline(*ifs, line)) {
100100 if (line.empty()) {
101101 continue;
102102 }
258258 } else if (action == actions_[EXPORT_TO_FILE_INDEX]) {
259259 Export();
260260 }
261
262 return;
263261 }
264262
265263 // static
4949 ~RomanTableEditorDialog() override;
5050
5151 // show a modal dialog
52 static bool Show(QWidget *parent, const std::string &current_keymap,
53 std::string *new_keymap);
52 static bool Show(QWidget *parent, const std::string &current_roman_table,
53 std::string *new_roman_table);
5454
5555 protected slots:
5656 void UpdateMenuStatus() override;
8484 }
8585
8686 void DictionaryContentTableWidget::focusInEvent(QFocusEvent *event) {
87 setStyleSheet("");
87 setStyleSheet(QLatin1String(""));
8888 }
8383 using ::mozc::user_dictionary::UserDictionarySession;
8484 using ::mozc::user_dictionary::UserDictionaryStorage;
8585
86 inline QString QUtf8(const char str[]) {
87 return QString::fromUtf8(str);
88 }
89
90 inline QString QUtf8(const string &str) {
91 return QString::fromUtf8(str.c_str());
92 }
93
8694 // set longer timeout because it takes longer time
8795 // to reload all user dictionary.
8896 const int kSessionTimeout = 100000;
9098 int GetTableHeight(QTableWidget *widget) {
9199 // Dragon Hack:
92100 // Here we use "龍" to calc font size, as it looks almsot square
93 const QRect rect = QFontMetrics(widget->font()).boundingRect("龍");
101 const QRect rect = QFontMetrics(widget->font()).boundingRect(QUtf8("龍"));
94102 return static_cast<int>(rect.height() * 1.4);
95103 }
96104
97105 QProgressDialog *CreateProgressDialog(QString message, QWidget *parent,
98106 int size) {
99 QProgressDialog *progress = new QProgressDialog(message, "", 0, size, parent);
107 QProgressDialog *progress =
108 new QProgressDialog(message, QLatin1String(""), 0, size, parent);
100109 CHECK(progress);
101110 progress->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint |
102111 Qt::WindowCloseButtonHint);
397406 pos_list_provider_->GetPOSList(&tmp_pos_vec);
398407 QStringList pos_list;
399408 for (size_t i = 0; i < tmp_pos_vec.size(); ++i) {
400 pos_list.append(tmp_pos_vec[i].c_str());
409 pos_list.append(QUtf8(tmp_pos_vec[i]));
401410 }
402411 ComboBoxDelegate *delegate = new ComboBoxDelegate;
403412 delegate->SetItemList(pos_list);
513522 sort_state_.sorted = false;
514523
515524 // If this is the first time for the user dictionary is used, create
516 // a defautl dictionary.
525 // a default dictionary.
517526 if (!session_->mutable_storage()->Exists()) {
518527 CreateDictionaryHelper(tr("User Dictionary 1"));
519528 }
629638 tr("Updating the current view data..."), this, dic->entries_size()));
630639
631640 for (size_t i = 0; i < dic->entries_size(); ++i) {
632 dic_content_->setItem(
633 i, 0, new QTableWidgetItem(dic->entries(i).key().c_str()));
634 dic_content_->setItem(
635 i, 1, new QTableWidgetItem(dic->entries(i).value().c_str()));
641 const UserDictionary::Entry &entry = dic->entries(i);
642 dic_content_->setItem(i, 0, new QTableWidgetItem(QUtf8(entry.key())));
643 dic_content_->setItem(i, 1, new QTableWidgetItem(QUtf8(entry.value())));
636644 dic_content_->setItem(
637645 i, 2,
638646 new QTableWidgetItem(
639 UserDictionaryUtil::GetStringPosType(dic->entries(i).pos())));
640 dic_content_->setItem(
641 i, 3, new QTableWidgetItem(dic->entries(i).comment().c_str()));
647 QUtf8(UserDictionaryUtil::GetStringPosType(entry.pos()))));
648 dic_content_->setItem(i, 3, new QTableWidgetItem(QUtf8(entry.comment())));
642649 progress->setValue(i);
643650 }
644651 }
668675 return;
669676 }
670677
671 const QString dic_name =
672 PromptForDictionaryName("", tr("Name of the new dictionary"));
678 const QString dic_name = PromptForDictionaryName(
679 QLatin1String(""), tr("Name of the new dictionary"));
673680 if (dic_name.isEmpty()) {
674681 return; // canceld by user
675682 }
791798 QMessageBox::information(this, window_title_,
792799 tr("%1 entries are imported to %2.")
793800 .arg(added_entries_size)
794 .arg(dic_name.c_str()));
801 .arg(QUtf8(dic_name)));
795802 break;
796803 case UserDictionaryImporter::IMPORT_NOT_SUPPORTED:
797804 QMessageBox::information(this, window_title_,
807814 tr("%1 doesn't have enough space to import all words in "
808815 "the file. First %2 entries "
809816 "are imported.")
810 .arg(dic_name.c_str())
817 .arg(QUtf8(dic_name))
811818 .arg(added_entries_size));
812819 break;
813820 case UserDictionaryImporter::IMPORT_INVALID_ENTRIES:
817824 "words were not recognized by %3. "
818825 "Please check the original import file.")
819826 .arg(added_entries_size)
820 .arg(dic_name.c_str())
827 .arg(QUtf8(dic_name))
821828 .arg(window_title_));
822829 break;
823830 case UserDictionaryImporter::IMPORT_FATAL:
836843 if (!IsReadableToImport(file_name)) {
837844 LOG(ERROR) << "File is not readable to import.";
838845 QMessageBox::critical(this, window_title_,
839 tr("Can't open %1.").arg(file_name.c_str()));
846 tr("Can't open %1.").arg(QUtf8(file_name)));
840847 return;
841848 }
842849
974981 if (!IsWritableToExport(file_name)) {
975982 LOG(ERROR) << "File is not writable to export.";
976983 QMessageBox::critical(this, window_title_,
977 tr("Can't open %1.").arg(file_name.c_str()));
984 tr("Can't open %1.").arg(QUtf8(file_name)));
978985 return;
979986 }
980987
10011008 }
10021009
10031010 dic_content_->insertRow(row);
1004 dic_content_->setItem(row, 0, new QTableWidgetItem(""));
1005 dic_content_->setItem(row, 1, new QTableWidgetItem(""));
1011 dic_content_->setItem(row, 0, new QTableWidgetItem(QLatin1String("")));
1012 dic_content_->setItem(row, 1, new QTableWidgetItem(QLatin1String("")));
10061013 dic_content_->setItem(row, 2, new QTableWidgetItem(default_pos_));
1007 dic_content_->setItem(row, 3, new QTableWidgetItem(""));
1014 dic_content_->setItem(row, 3, new QTableWidgetItem(QLatin1String("")));
10081015
10091016 if (row + 1 >= max_entry_size_) {
10101017 new_word_button_->setEnabled(false);
10521059 void DictionaryTool::DeleteWord() {
10531060 std::vector<int> rows;
10541061 GetSortedSelectedRows(&rows);
1055 if (rows.size() == 0) {
1062 if (rows.empty()) {
10561063 return;
10571064 }
10581065
11311138
11321139 std::vector<int> rows;
11331140 GetSortedSelectedRows(&rows);
1134 if (rows.size() == 0) {
1141 if (rows.empty()) {
11351142 return;
11361143 }
11371144
11941201
11951202 bool ok = false;
11961203 const QString new_comment = QInputDialog::getText(
1197 this, window_title_, tr("New comment"), QLineEdit::Normal, "", &ok,
1198 Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
1204 this, window_title_, tr("New comment"), QLineEdit::Normal,
1205 QLatin1String(""), &ok, Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
11991206
12001207 if (!ok) {
12011208 return;
12631270 const QList<QTableWidgetItem *> items = dic_content_->selectedItems();
12641271 QString delete_menu_text = tr("Delete this word");
12651272 QString move_to_menu_text = tr("Move this word to");
1266 if (items.size() > 0) {
1273 if (!items.empty()) {
12671274 const int first_row = items[0]->row();
12681275 for (int i = 1; i < items.size(); ++i) {
12691276 if (items[i]->row() != first_row) {
15371544 }
15381545
15391546 bool DictionaryTool::IsReadableToImport(const std::string &file_name) {
1540 QFileInfo file_info(file_name.c_str());
1547 QFileInfo file_info(QUtf8(file_name));
15411548 return file_info.isFile() && file_info.isReadable();
15421549 }
15431550
15441551 bool DictionaryTool::IsWritableToExport(const std::string &file_name) {
1545 QFileInfo file_info(file_name.c_str());
1552 QFileInfo file_info(QUtf8(file_name));
15461553 if (file_info.exists()) {
15471554 return file_info.isFile() && file_info.isWritable();
15481555 } else {
6262 Q_OBJECT
6363
6464 public:
65 explicit DictionaryTool(QWidget *parent = 0);
65 explicit DictionaryTool(QWidget *parent = nullptr);
6666 ~DictionaryTool() override;
6767
6868 // return true DictionaryTool is available.
7373 }
7474
7575 void FindDialog::closeEvent(QCloseEvent *event) {
76 table_->setStyleSheet("");
76 table_->setStyleSheet(QLatin1String(""));
7777 last_item_ = nullptr;
7878 }
7979
143143 QTableWidgetItem *item = table_->item(matched_row, matched_column);
144144 DCHECK(item);
145145 last_item_ = item;
146 table_->setStyleSheet(kYellowSelectionStyleSheet);
146 table_->setStyleSheet(QLatin1String(kYellowSelectionStyleSheet));
147147 table_->setCurrentItem(item);
148148 table_->scrollToItem(item);
149149 } else {
4949 Q_OBJECT
5050
5151 public:
52 ImportDialog(QWidget *parent = 0);
52 explicit ImportDialog(QWidget *parent = nullptr);
5353 ~ImportDialog() override;
5454
5555 // Accessor methods to get form values.
4747
4848 class ZeroWidthSplitter : public QSplitter {
4949 public:
50 ZeroWidthSplitter(QWidget *parent);
50 explicit ZeroWidthSplitter(QWidget *parent);
5151 QSplitterHandle *createHandle() override;
5252 };
5353
5050 Q_OBJECT
5151
5252 public:
53 DeleyedMessageDialogHandler(QMessageBox *message_box);
53 explicit DeleyedMessageDialogHandler(QMessageBox *message_box);
5454 ~DeleyedMessageDialogHandler() override;
5555
5656 void Exec();
7979 const DWORD buffer_size =
8080 ::GetEnvironmentVariable(wenvname.c_str(), nullptr, 0);
8181 if (buffer_size == 0) {
82 return "";
82 return QLatin1String("");
8383 }
8484 std::unique_ptr<wchar_t[]> buffer(new wchar_t[buffer_size]);
8585 const DWORD num_copied =
9494 return QString::fromUcs4(reinterpret_cast<const uint *>(buffer.get()));
9595 }
9696 }
97 return "";
97 return QLatin1String("");
9898 #endif // OS_WIN
9999 #if defined(__APPLE__) || defined(OS_LINUX)
100 return ::getenv(envname);
100 return QString::fromUtf8(::getenv(envname));
101101 #endif // __APPLE__ or OS_LINUX
102102 // TODO(team): Support other platforms.
103 return "";
103 return QLatin1String("");
104104 }
105105 } // namespace
106106
154154 pos_list_provider_->GetPOSList(&pos_set);
155155 CHECK(!pos_set.empty());
156156
157 for (size_t i = 0; i < pos_set.size(); ++i) {
158 CHECK(!pos_set[i].empty());
159 PartOfSpeechcomboBox->addItem(pos_set[i].c_str());
157 for (const string &pos : pos_set) {
158 CHECK(!pos.empty());
159 PartOfSpeechcomboBox->addItem(QString::fromUtf8(pos.c_str()));
160160 }
161161
162162 // Create new dictionary if empty
176176 {
177177 const UserDictionaryStorage &storage = session_->storage();
178178 CHECK_GT(storage.dictionaries_size(), 0);
179 for (size_t i = 0; i < storage.dictionaries_size(); ++i) {
180 DictionarycomboBox->addItem(storage.dictionaries(i).name().c_str());
179 for (const auto &dictionary : storage.dictionaries()) {
180 DictionarycomboBox->addItem(QString::fromUtf8(dictionary.name().c_str()));
181181 }
182182 }
183183
304304 CHECK(dic);
305305
306306 if (dic->name() != DictionarycomboBox->currentText().toStdString().c_str()) {
307 LOG(ERROR) << "Inconsitent dictionary name";
307 LOG(ERROR) << "Inconsistent dictionary name";
308308 return FATAL_ERROR;
309309 }
310310
351351 const QString WordRegisterDialog::GetReading(const QString &str) {
352352 if (str.isEmpty()) {
353353 LOG(ERROR) << "given string is empty";
354 return "";
354 return QLatin1String("");
355355 }
356356
357357 if (str.count() >= kMaxReverseConversionLength) {
358358 LOG(ERROR) << "too long input";
359 return "";
359 return QLatin1String("");
360360 }
361361
362362 commands::Output output;
365365 key.set_special_key(commands::KeyEvent::ON);
366366 if (!client_->SendKey(key, &output)) {
367367 LOG(ERROR) << "SendKey failed";
368 return "";
368 return QLatin1String("");
369369 }
370370
371371 commands::SessionCommand command;
374374
375375 if (!client_->SendCommand(command, &output)) {
376376 LOG(ERROR) << "SendCommand failed";
377 return "";
377 return QLatin1String("");
378378 }
379379
380380 commands::Output dummy_output;
384384
385385 if (!output.has_preedit()) {
386386 LOG(ERROR) << "No preedit";
387 return "";
387 return QLatin1String("");
388388 }
389389
390390 std::string key;
394394 output.preedit().segment(segment_index);
395395 if (!segment.has_key()) {
396396 LOG(ERROR) << "No segment";
397 return "";
397 return QLatin1String("");
398398 }
399399 key.append(segment.key());
400400 }
401401
402402 if (key.empty() || !UserDictionaryUtil::IsValidReading(key)) {
403403 LOG(WARNING) << "containing invalid characters";
404 return "";
405 }
406
407 return QString(key.c_str());
404 return QLatin1String("");
405 }
406
407 return QString::fromUtf8(key.c_str());
408408 }
409409
410410 // Get default value from Clipboard
452452 LOG(ERROR) << "SendMessageTimeout() failed: " << ::GetLastError();
453453 }
454454 #endif // OS_WIN
455
456 return;
457455 }
458456
459457 bool WordRegisterDialog::SetDefaultEntryFromEnvironmentVariable() {
474472 }
475473
476474 const QString WordRegisterDialog::TrimValue(const QString &str) const {
477 return str.trimmed().replace('\r', "").replace('\n', "");
475 return str.trimmed()
476 .replace(QLatin1Char('\r'), QLatin1String(""))
477 .replace(QLatin1Char('\n'), QLatin1String(""));
478478 }
479479
480480 void WordRegisterDialog::EnableIME() {
9999 bool SetDefaultEntryFromEnvironmentVariable();
100100
101101 // Return reading of value with reverse conversion feature.
102 const QString GetReading(const QString &value);
102 const QString GetReading(const QString &str);
103103
104104 // remove "\n" "\r" from |value|.
105105 // remove whitespace from the start and the end.
106 const QString TrimValue(const QString &value) const;
106 const QString TrimValue(const QString &str) const;
107107
108108 // turn on IME.
109109 // When the dialog is shown, it is better to turn on IME.
13431343 request.composer().GetStringForPreedit(input_key);
13441344 std::set<std::string> expanded_set;
13451345 request.composer().GetQueriesForPrediction(base, &expanded_set);
1346 if (expanded_set.size() > 0) {
1346 if (!expanded_set.empty()) {
13471347 expanded->reset(new Trie<std::string>);
13481348 for (std::set<std::string>::const_iterator itr = expanded_set.begin();
13491349 itr != expanded_set.end(); ++itr) {
17611761 }
17621762
17631763 InsertHistory(request_type, is_suggestion, last_access_time, segments);
1764 return;
17651764 }
17661765
17671766 void UserHistoryPredictor::MakeLearningSegments(
19161915 }
19171916 }
19181917 }
1919
1920 return;
19211918 }
19221919
19231920 void UserHistoryPredictor::Revert(Segments *segments) {
180180 ['(_toolset=="target" and (compiler_target=="clang" or compiler_target=="gcc")) or '
181181 '(_toolset=="host" and (compiler_host=="clang" or compiler_host=="gcc"))', {
182182 'cflags': [
183 '-Wno-tautological-constant-out-of-range-compare',
183184 '-Wno-unused-function',
184185 ],
185186 }],
220221 ['(_toolset=="target" and (compiler_target=="clang" or compiler_target=="gcc")) or '
221222 '(_toolset=="host" and (compiler_host=="clang" or compiler_host=="gcc"))', {
222223 'cflags': [
224 '-Wno-tautological-constant-out-of-range-compare',
223225 '-Wno-unused-const-variable',
224226 '-Wno-unused-function',
225227 '-Wno-unused-private-field',
139139 std::ifstream finput(filename.c_str());
140140 std::string line;
141141 int lineno = 0;
142 while (getline(finput, line)) {
142 while (std::getline(finput, line)) {
143143 ++lineno;
144144
145145 // |line| is of format "expression=answer".
6363
6464 // Make a segments which has some dummy candidates.
6565 void MakeSegments(Segments *segments, const std::string &key,
66 const int &num_segment, const int &num_dummy_candidate) {
66 const int num_segment, const int num_dummy_candidate) {
6767 segments->Clear();
6868
6969 AddSegment(key, segments);
240240
241241 {
242242 if (IsNumberCandidate(seg.candidate(candidate_index))) {
243 bool modified = 0;
243 bool modified = false;
244244 int distance = 0;
245245 for (size_t i = segment_index + 1; i < segments->segments_size(); ++i) {
246246 Segment *target_right_seg = segments->mutable_segment(i);
354354 return;
355355 }
356356 }
357 return;
358357 }
359358
360359 // NormalizeCandidate using config
15071507 // "[半] アルファベット"
15081508 std::string expectation = VariantsRewriter::kHalfWidth;
15091509 const std::string alphabet = VariantsRewriter::kAlphabet;
1510 if (alphabet.size() != 0) {
1510 if (!alphabet.empty()) {
15111511 expectation += ' ' + alphabet;
15121512 }
15131513 EXPECT_EQ(expectation, segments.segment(0).candidate(0).description);
9191 VLOG(1) << "Mozc server starts with timeout mode";
9292 FLAGS_restricted = true;
9393 }
94
95 return;
9694 }
9795
9896 int MozcServer::Run() {
4949 GenericStorageInterface *emoticon = GenericStorageManagerFactory::GetStorage(
5050 commands::GenericStorageEntry::EMOTICON_HISTORY);
5151 GenericStorageInterface *invalid = GenericStorageManagerFactory::GetStorage(
52 (commands::GenericStorageEntry::StorageType)(100));
52 static_cast<commands::GenericStorageEntry::StorageType>(100));
5353
5454 EXPECT_NE(nullptr, symbol);
5555 EXPECT_NE(nullptr, emoticon);
376376 const commands::GenericStorageEntry &storage_entry =
377377 command->input().storage_entry();
378378 if (!storage_entry.has_type() || !storage_entry.has_key() ||
379 storage_entry.value().size() == 0) {
379 storage_entry.value().empty()) {
380380 LOG(WARNING) << "storage_entry lacks some fields.";
381381 return false;
382382 }
9999
100100 // Insert key and bool value
101101 // It is not guaranteed that the data is synced to the disk
102 static bool Insert(const std::string &key, const bool &value) {
102 static bool Insert(const std::string &key, const bool value) {
103103 const uint8 tmp = static_cast<uint8>(value);
104104 return Insert<uint8>(key, tmp);
105105 }
7474 {
7575 bool value = true;
7676 EXPECT_TRUE(Registry::Insert("bool", value));
77 bool expected = 0;
77 bool expected = false;
7878 EXPECT_TRUE(Registry::Lookup("bool", &expected));
7979 EXPECT_EQ(expected, value);
8080 }