From c2e7cb6a9d5f8636846f320007ee60564d5afa52 Mon Sep 17 00:00:00 2001
From: Murai Takashi <tmurai01@gmail.com>
Date: Sat, 26 Oct 2013 06:32:36 +0900
Subject: [PATCH 01/23] CannaIM:copy data files to user setting directory.
---
.../input_server/methods/canna/CannaLooper.cpp | 68 +++++++++++++++++---
.../input_server/methods/canna/CannaLooper.h | 1 +
src/add-ons/input_server/methods/canna/Jamfile | 2 +-
3 files changed, 62 insertions(+), 9 deletions(-)
diff --git a/src/add-ons/input_server/methods/canna/CannaLooper.cpp b/src/add-ons/input_server/methods/canna/CannaLooper.cpp
index 4fbfa50..bd4636f 100644
a
|
b
|
|
18 | 18 | #include <Menu.h> |
19 | 19 | #include <MenuItem.h> |
20 | 20 | #include <Messenger.h> |
| 21 | #include <Entry.h> |
21 | 22 | #include <Path.h> |
22 | 23 | #include <Screen.h> |
| 24 | #include <CopyEngine.h> |
23 | 25 | |
24 | 26 | #include "CannaCommon.h" |
25 | 27 | #include "CannaMethod.h" |
… |
… |
CannaLooper::CannaLooper(CannaMethod* method)
|
44 | 46 | fMenu->AddItem(new BMenuItem("Reload Init file", |
45 | 47 | new BMessage(RELOAD_INIT_FILE))); |
46 | 48 | |
| 49 | font_family family; |
| 50 | font_style style; |
| 51 | strcpy(family, "VL PGothic"); |
| 52 | strcpy(style, "regular"); |
| 53 | |
| 54 | fKouhoFont.SetFamilyAndStyle(family, style); |
| 55 | fKouhoFont.SetSize(12); |
| 56 | |
47 | 57 | if (gSettings.convert_arrowkey) { |
48 | 58 | BMenuItem* item = fMenu->FindItem(ARROW_KEYS_FLIPPED); |
49 | 59 | item->SetMarked(true); |
… |
… |
CannaLooper::Quit()
|
95 | 105 | |
96 | 106 | |
97 | 107 | status_t |
| 108 | CannaLooper::copyData(const char* dstPath) |
| 109 | { |
| 110 | // We should copy data from /boot/system/Data or /boot/home/config/Data |
| 111 | // so that user can drop canna package either to /boot/system/pacages |
| 112 | // or to /boot/home/config/packages. |
| 113 | |
| 114 | bool found = false; |
| 115 | status_t status; |
| 116 | BPath srcPath; |
| 117 | BEntry ent; |
| 118 | directory_which which[] = { |
| 119 | B_USER_DATA_DIRECTORY, |
| 120 | B_SYSTEM_DATA_DIRECTORY |
| 121 | }; |
| 122 | |
| 123 | for(unsigned int i = 0; i < sizeof(which) / sizeof(directory_which); i++) { |
| 124 | status = find_directory(which[i], &srcPath); |
| 125 | if (status != B_OK) |
| 126 | continue; |
| 127 | |
| 128 | srcPath.Append("Canna"); |
| 129 | ent.SetTo(srcPath.Path()); |
| 130 | if (ent.Exists()) { |
| 131 | found = true; |
| 132 | break; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if (!found) { |
| 137 | return B_ERROR; |
| 138 | } |
| 139 | |
| 140 | BCopyEngine CopyEngine(BCopyEngine::COPY_RECURSIVELY); |
| 141 | status = CopyEngine.CopyEntry(srcPath.Path(), dstPath); |
| 142 | if (status != B_OK) |
| 143 | return B_ERROR; |
| 144 | |
| 145 | // TODO: if Haiku goes multi-user, we need SetOwner() to data files |
| 146 | // and directory. |
| 147 | |
| 148 | return B_OK; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | status_t |
98 | 153 | CannaLooper::ReadSettings(char* basePath) |
99 | 154 | { |
100 | 155 | BPath path; |
101 | | status_t status = find_directory(B_SYSTEM_DATA_DIRECTORY, &path); |
| 156 | status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); |
102 | 157 | if (status != B_OK) |
103 | 158 | return status; |
104 | 159 | |
… |
… |
CannaLooper::ReadSettings(char* basePath)
|
107 | 162 | strlcpy(basePath, path.Path(), B_PATH_NAME_LENGTH); |
108 | 163 | strlcat(basePath, "/", B_PATH_NAME_LENGTH); |
109 | 164 | |
110 | | font_family family; |
111 | | font_style style; |
112 | | strcpy(family, "VL PGothic"); |
113 | | strcpy(style, "regular"); |
114 | | |
115 | | fKouhoFont.SetFamilyAndStyle(family, style); |
116 | | fKouhoFont.SetSize(12); |
| 165 | BEntry ent(path.Path()); |
| 166 | if (!ent.Exists()) { |
| 167 | return copyData(path.Path()); |
| 168 | } |
117 | 169 | |
118 | 170 | return B_OK; |
119 | 171 | } |
diff --git a/src/add-ons/input_server/methods/canna/CannaLooper.h b/src/add-ons/input_server/methods/canna/CannaLooper.h
index 60e93a3..f3f7edb 100644
a
|
b
|
public:
|
38 | 38 | void SendInputStarted(); |
39 | 39 | |
40 | 40 | private: |
| 41 | status_t copyData(const char* dstPath); |
41 | 42 | void _HandleKeyDown(BMessage* msg); |
42 | 43 | void _HandleLocationReply(BMessage* msg); |
43 | 44 | void _HandleMethodActivated(bool active); |
diff --git a/src/add-ons/input_server/methods/canna/Jamfile b/src/add-ons/input_server/methods/canna/Jamfile
index 59c7050..211008a 100644
a
|
b
|
SubDir HAIKU_TOP src add-ons input_server methods canna ;
|
2 | 2 | |
3 | 3 | SetSubDirSupportedPlatformsBeOSCompatible ; |
4 | 4 | |
5 | | UsePrivateHeaders interface ; |
| 5 | UsePrivateHeaders interface storage ; |
6 | 6 | |
7 | 7 | SubDirSysHdrs $(SUBDIR) ; |
8 | 8 | SubDirHdrs [ FDirName $(SUBDIR) canna ] ; |