author | zautrix <zautrix> | 2004-09-12 09:56:56 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-12 09:56:56 (UTC) |
commit | 31fab1d7e531b492d1075964ddcbebe7a563a41a (patch) (unidiff) | |
tree | 91fe6d49f28003106cba1adc9aed816a9019888d | |
parent | 8d822fd4d97fbb38ab2c4f3f3f64f175ef143cff (diff) | |
download | kdepimpi-31fab1d7e531b492d1075964ddcbebe7a563a41a.zip kdepimpi-31fab1d7e531b492d1075964ddcbebe7a563a41a.tar.gz kdepimpi-31fab1d7e531b492d1075964ddcbebe7a563a41a.tar.bz2 |
Kammu fixes
-rw-r--r-- | gammu/emb/gammu/gammu.c | 47 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 6 |
2 files changed, 50 insertions, 3 deletions
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c index 1d53fb0..5163d81 100644 --- a/gammu/emb/gammu/gammu.c +++ b/gammu/emb/gammu/gammu.c | |||
@@ -8057,300 +8057,345 @@ static void HelpGeneral(void) | |||
8057 | static void HelpSplit(int cols, int len, unsigned char *buff) | 8057 | static void HelpSplit(int cols, int len, unsigned char *buff) |
8058 | { | 8058 | { |
8059 | int l, len2, pos, split; | 8059 | int l, len2, pos, split; |
8060 | bool in_opt,first=true; | 8060 | bool in_opt,first=true; |
8061 | char *remain, spaces[50], buffer[500]; | 8061 | char *remain, spaces[50], buffer[500]; |
8062 | 8062 | ||
8063 | if (cols == 0) { | 8063 | if (cols == 0) { |
8064 | printf(" %s\n", buff); | 8064 | printf(" %s\n", buff); |
8065 | } else { | 8065 | } else { |
8066 | printf(" "); | 8066 | printf(" "); |
8067 | spaces[0] = 0; | 8067 | spaces[0] = 0; |
8068 | len2 = strlen(buff); | 8068 | len2 = strlen(buff); |
8069 | if (len + len2 < cols) { | 8069 | if (len + len2 < cols) { |
8070 | printf("%s\n", buff); | 8070 | printf("%s\n", buff); |
8071 | } else { | 8071 | } else { |
8072 | for(l = 0; l < len; l++) strcat(spaces, " "); | 8072 | for(l = 0; l < len; l++) strcat(spaces, " "); |
8073 | 8073 | ||
8074 | remain = buff; | 8074 | remain = buff; |
8075 | 8075 | ||
8076 | while (strlen(remain) > 0) { | 8076 | while (strlen(remain) > 0) { |
8077 | split= 0; | 8077 | split= 0; |
8078 | pos= 0; | 8078 | pos= 0; |
8079 | in_opt= false; | 8079 | in_opt= false; |
8080 | if (!first) printf(spaces); | 8080 | if (!first) printf(spaces); |
8081 | while (pos < cols - len && remain[pos] != 0) { | 8081 | while (pos < cols - len && remain[pos] != 0) { |
8082 | if (in_opt && remain[pos] == ']') { | 8082 | if (in_opt && remain[pos] == ']') { |
8083 | in_opt = false; | 8083 | in_opt = false; |
8084 | split = pos; | 8084 | split = pos; |
8085 | } else if (remain[pos] == '[') { | 8085 | } else if (remain[pos] == '[') { |
8086 | in_opt = true; | 8086 | in_opt = true; |
8087 | } else if (!in_opt && remain[pos] == ' ') { | 8087 | } else if (!in_opt && remain[pos] == ' ') { |
8088 | split = pos - 1; | 8088 | split = pos - 1; |
8089 | } | 8089 | } |
8090 | pos++; | 8090 | pos++; |
8091 | } | 8091 | } |
8092 | /* Can not be split */ | 8092 | /* Can not be split */ |
8093 | if (split == 0) { | 8093 | if (split == 0) { |
8094 | printf("%s\n", remain); | 8094 | printf("%s\n", remain); |
8095 | remain += strlen(remain); | 8095 | remain += strlen(remain); |
8096 | } else { | 8096 | } else { |
8097 | first = false; | 8097 | first = false; |
8098 | split++; | 8098 | split++; |
8099 | strncpy(buffer, remain, split); | 8099 | strncpy(buffer, remain, split); |
8100 | buffer[split] = 0; | 8100 | buffer[split] = 0; |
8101 | printf("%s\n", buffer); | 8101 | printf("%s\n", buffer); |
8102 | remain += split; | 8102 | remain += split; |
8103 | if (remain[0] == ' ') remain++; | 8103 | if (remain[0] == ' ') remain++; |
8104 | } | 8104 | } |
8105 | } | 8105 | } |
8106 | } | 8106 | } |
8107 | } | 8107 | } |
8108 | } | 8108 | } |
8109 | 8109 | ||
8110 | static void Help(int argc, char *argv[]) | 8110 | static void Help(int argc, char *argv[]) |
8111 | { | 8111 | { |
8112 | int i = 0, j = 0, k, cols; | 8112 | int i = 0, j = 0, k, cols; |
8113 | bool disp; | 8113 | bool disp; |
8114 | #ifdef TIOCGWINSZ | 8114 | #ifdef TIOCGWINSZ |
8115 | struct winsize w; | 8115 | struct winsize w; |
8116 | #endif | 8116 | #endif |
8117 | #if defined(WIN32) || defined(DJGPP) | 8117 | #if defined(WIN32) || defined(DJGPP) |
8118 | #else | 8118 | #else |
8119 | char *columns; | 8119 | char *columns; |
8120 | #endif | 8120 | #endif |
8121 | 8121 | ||
8122 | /* Just --help */ | 8122 | /* Just --help */ |
8123 | if (argc == 2) { | 8123 | if (argc == 2) { |
8124 | HelpGeneral(); | 8124 | HelpGeneral(); |
8125 | return; | 8125 | return; |
8126 | } | 8126 | } |
8127 | 8127 | ||
8128 | if (!strcmp(argv[2],"all")) { | 8128 | if (!strcmp(argv[2],"all")) { |
8129 | HelpHeader(); | 8129 | HelpHeader(); |
8130 | } else { | 8130 | } else { |
8131 | while (HelpDescriptions[i].category != 0) { | 8131 | while (HelpDescriptions[i].category != 0) { |
8132 | if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; | 8132 | if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; |
8133 | i++; | 8133 | i++; |
8134 | } | 8134 | } |
8135 | if (HelpDescriptions[i].category == 0) { | 8135 | if (HelpDescriptions[i].category == 0) { |
8136 | HelpGeneral(); | 8136 | HelpGeneral(); |
8137 | printmsg("Unknown help topic specified!\n"); | 8137 | printmsg("Unknown help topic specified!\n"); |
8138 | return; | 8138 | return; |
8139 | } | 8139 | } |
8140 | HelpHeader(); | 8140 | HelpHeader(); |
8141 | printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description); | 8141 | printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description); |
8142 | } | 8142 | } |
8143 | 8143 | ||
8144 | #if defined(WIN32) || defined(DJGPP) | 8144 | #if defined(WIN32) || defined(DJGPP) |
8145 | cols = 80; | 8145 | cols = 80; |
8146 | #else | 8146 | #else |
8147 | cols = 0; | 8147 | cols = 0; |
8148 | /* If stdout is a tty, we will wrap to columns it has */ | 8148 | /* If stdout is a tty, we will wrap to columns it has */ |
8149 | if (isatty(1)) { | 8149 | if (isatty(1)) { |
8150 | #ifdef TIOCGWINSZ | 8150 | #ifdef TIOCGWINSZ |
8151 | if (ioctl(2, TIOCGWINSZ, &w) == 0) { | 8151 | if (ioctl(2, TIOCGWINSZ, &w) == 0) { |
8152 | if (w.ws_col > 0) cols = w.ws_col; | 8152 | if (w.ws_col > 0) cols = w.ws_col; |
8153 | } | 8153 | } |
8154 | #endif | 8154 | #endif |
8155 | if (cols == 0) { | 8155 | if (cols == 0) { |
8156 | columns = getenv("COLUMNS"); | 8156 | columns = getenv("COLUMNS"); |
8157 | if (columns != NULL) { | 8157 | if (columns != NULL) { |
8158 | cols = atoi(columns); | 8158 | cols = atoi(columns); |
8159 | if (cols <= 0) cols = 0; | 8159 | if (cols <= 0) cols = 0; |
8160 | } | 8160 | } |
8161 | } | 8161 | } |
8162 | 8162 | ||
8163 | if (cols == 0) { | 8163 | if (cols == 0) { |
8164 | /* Fallback */ | 8164 | /* Fallback */ |
8165 | cols = 80; | 8165 | cols = 80; |
8166 | } | 8166 | } |
8167 | } | 8167 | } |
8168 | #endif | 8168 | #endif |
8169 | 8169 | ||
8170 | while (Parameters[j].Function != NULL) { | 8170 | while (Parameters[j].Function != NULL) { |
8171 | k = 0; | 8171 | k = 0; |
8172 | disp = false; | 8172 | disp = false; |
8173 | if (!strcmp(argv[2],"all")) { | 8173 | if (!strcmp(argv[2],"all")) { |
8174 | if (j==0) disp = true; | 8174 | if (j==0) disp = true; |
8175 | if (j!=0) { | 8175 | if (j!=0) { |
8176 | if (strcmp(Parameters[j].help,Parameters[j-1].help)) { | 8176 | if (strcmp(Parameters[j].help,Parameters[j-1].help)) { |
8177 | disp = true; | 8177 | disp = true; |
8178 | } else { | 8178 | } else { |
8179 | if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) { | 8179 | if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) { |
8180 | disp = true; | 8180 | disp = true; |
8181 | } | 8181 | } |
8182 | } | 8182 | } |
8183 | } | 8183 | } |
8184 | } else { | 8184 | } else { |
8185 | while (Parameters[j].help_cat[k] != 0) { | 8185 | while (Parameters[j].help_cat[k] != 0) { |
8186 | if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) { | 8186 | if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) { |
8187 | disp = true; | 8187 | disp = true; |
8188 | break; | 8188 | break; |
8189 | } | 8189 | } |
8190 | k++; | 8190 | k++; |
8191 | } | 8191 | } |
8192 | } | 8192 | } |
8193 | if (disp) { | 8193 | if (disp) { |
8194 | printf("%s", Parameters[j].parameter); | 8194 | printf("%s", Parameters[j].parameter); |
8195 | if (Parameters[j].help[0] == 0) { | 8195 | if (Parameters[j].help[0] == 0) { |
8196 | printf("\n"); | 8196 | printf("\n"); |
8197 | } else { | 8197 | } else { |
8198 | HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help); | 8198 | HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help); |
8199 | } | 8199 | } |
8200 | } | 8200 | } |
8201 | j++; | 8201 | j++; |
8202 | } | 8202 | } |
8203 | } | 8203 | } |
8204 | #if 0 | 8204 | #if 0 |
8205 | #endif // 0 | 8205 | #endif // 0 |
8206 | int main(int argc, char *argv[]) | 8206 | int main(int argc, char *argv[]) |
8207 | { | 8207 | { |
8208 | 8208 | ||
8209 | //fprintf(stderr,"HIIIIIIIIIIIII \n"); | 8209 | //fprintf(stderr,"HIIIIIIIIIIIII \n"); |
8210 | //#if 0 | 8210 | //#if 0 |
8211 | static int z ,start,i; | 8211 | static int z ,start,i; |
8212 | static intonly_config ; | 8212 | static intonly_config ; |
8213 | #if !defined(WIN32) && defined(LOCALE_PATH) | 8213 | #if !defined(WIN32) && defined(LOCALE_PATH) |
8214 | static char*locale, locale_file[201]; | 8214 | static char*locale, locale_file[201]; |
8215 | #endif | 8215 | #endif |
8216 | static char*cp; | 8216 | static char*cp; |
8217 | static boolcount_failed; | 8217 | static boolcount_failed; |
8218 | z = 0; | 8218 | z = 0; |
8219 | start=0;only_config = -1;count_failed = false; | 8219 | start=0;only_config = -1;count_failed = false; |
8220 | s.opened = false; | 8220 | s.opened = false; |
8221 | s.msg = NULL; | 8221 | s.msg = NULL; |
8222 | s.ConfigNum = 0; | 8222 | s.ConfigNum = 0; |
8223 | 8223 | ||
8224 | setlocale(LC_ALL, ""); | 8224 | setlocale(LC_ALL, ""); |
8225 | #ifdef DEBUG | 8225 | #ifdef DEBUG |
8226 | di.dl = DL_TEXTALL; | 8226 | di.dl = DL_TEXTALL; |
8227 | di.df = stdout; | 8227 | di.df = stdout; |
8228 | #endif | 8228 | #endif |
8229 | //#if 0 | 8229 | //#if 0 |
8230 | /* Any parameters? */ | 8230 | /* Any parameters? */ |
8231 | if (argc == 1) { | 8231 | if (argc == 1) { |
8232 | HelpGeneral(); | 8232 | HelpGeneral(); |
8233 | printmsg("Too few parameters!\n"); | 8233 | printmsg("Too few parameters!\n"); |
8234 | exit(1); | 8234 | exit(1); |
8235 | } | 8235 | } |
8236 | 8236 | ||
8237 | /* Help? */ | 8237 | /* Help? */ |
8238 | if (strncmp(argv[1 + start], "--help", 6) == 0) { | 8238 | if (strncmp(argv[1 + start], "--help", 6) == 0) { |
8239 | Help(argc - start, argv + start); | 8239 | Help(argc - start, argv + start); |
8240 | exit(1); | 8240 | exit(1); |
8241 | } | 8241 | } |
8242 | 8242 | ||
8243 | /* Is first parameter numeric? If so treat it as config that should be loaded. */ | 8243 | /* Is first parameter numeric? If so treat it as config that should be loaded. */ |
8244 | if (isdigit(argv[1][0])) { | 8244 | if (isdigit(argv[1][0])) { |
8245 | only_config = atoi(argv[1]); | 8245 | only_config = atoi(argv[1]); |
8246 | if (only_config >= 0) start++; else only_config = -1; | 8246 | if (only_config >= 0) start++; else only_config = -1; |
8247 | } | 8247 | } |
8248 | 8248 | ||
8249 | GSM_ReadConfig(NULL, &s.Config[0], 0); | ||
8250 | s.ConfigNum = 1; | ||
8251 | GSM_Config *con = &s.Config[0]; | ||
8252 | |||
8253 | char* tempC; | ||
8254 | tempC = argv[argc-1]+2; | ||
8255 | if ( *tempC != 0 ) { | ||
8256 | fprintf(stderr,"Using model %s \n",tempC); | ||
8257 | strcpy(con->Model,tempC ); | ||
8258 | } | ||
8259 | tempC = argv[argc-2]+2; | ||
8260 | if ( *tempC != 0 ) { | ||
8261 | fprintf(stderr,"Using device %s \n",tempC); | ||
8262 | con->Device = strdup(tempC); | ||
8263 | con->DefaultDevice = false; | ||
8264 | } | ||
8265 | tempC = argv[argc-3]+2; | ||
8266 | if ( *tempC != 0 ) { | ||
8267 | fprintf(stderr,"Using connection %s \n",tempC); | ||
8268 | con->Connection = strdup(tempC); | ||
8269 | con->DefaultConnection = false; | ||
8270 | } | ||
8271 | argc = argc-3; | ||
8272 | #if 0 | ||
8273 | if ( ! mConnection.isEmpty() ) { | ||
8274 | cfg->Connection = strdup(mConnection.latin1()); | ||
8275 | cfg->DefaultConnection = false; | ||
8276 | qDebug("Connection set %s ", cfg->Connection ); | ||
8277 | |||
8278 | } | ||
8279 | if ( ! mDevice.isEmpty() ) { | ||
8280 | cfg->Device = strdup(mDevice.latin1()); | ||
8281 | cfg->DefaultDevice = false; | ||
8282 | qDebug("Device set %s ", cfg->Device); | ||
8283 | |||
8284 | } | ||
8285 | if ( ! mModel.isEmpty() ) { | ||
8286 | strcpy(cfg->Model,mModel.latin1() ); | ||
8287 | cfg->DefaultModel = false; | ||
8288 | qDebug("Model set %s ",cfg->Model ); | ||
8289 | } | ||
8290 | |||
8291 | #endif | ||
8292 | |||
8293 | #if 0 | ||
8249 | cfg=GSM_FindGammuRC(); | 8294 | cfg=GSM_FindGammuRC(); |
8250 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { | 8295 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { |
8251 | if (cfg!=NULL) { | 8296 | if (cfg!=NULL) { |
8252 | cp = INI_GetValue(cfg, "gammu", "gammucoding", false); | 8297 | cp = INI_GetValue(cfg, "gammu", "gammucoding", false); |
8253 | if (cp) di.coding = cp; | 8298 | if (cp) di.coding = cp; |
8254 | 8299 | ||
8255 | s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); | 8300 | s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); |
8256 | if (s.Config[i].Localize) { | 8301 | if (s.Config[i].Localize) { |
8257 | s.msg=INI_ReadFile(s.Config[i].Localize, true); | 8302 | s.msg=INI_ReadFile(s.Config[i].Localize, true); |
8258 | } else { | 8303 | } else { |
8259 | #if !defined(WIN32) && defined(LOCALE_PATH) | 8304 | #if !defined(WIN32) && defined(LOCALE_PATH) |
8260 | locale = setlocale(LC_MESSAGES, NULL); | 8305 | locale = setlocale(LC_MESSAGES, NULL); |
8261 | if (locale != NULL) { | 8306 | if (locale != NULL) { |
8262 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", | 8307 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", |
8263 | LOCALE_PATH, | 8308 | LOCALE_PATH, |
8264 | tolower(locale[0]), | 8309 | tolower(locale[0]), |
8265 | tolower(locale[1])); | 8310 | tolower(locale[1])); |
8266 | s.msg = INI_ReadFile(locale_file, true); | 8311 | s.msg = INI_ReadFile(locale_file, true); |
8267 | } | 8312 | } |
8268 | #endif | 8313 | #endif |
8269 | } | 8314 | } |
8270 | } | 8315 | } |
8271 | 8316 | ||
8272 | /* Wanted user specific configuration? */ | 8317 | /* Wanted user specific configuration? */ |
8273 | if (only_config != -1) { | 8318 | if (only_config != -1) { |
8274 | /* Here we get only in first for loop */ | 8319 | /* Here we get only in first for loop */ |
8275 | if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; | 8320 | if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; |
8276 | } else { | 8321 | } else { |
8277 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; | 8322 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; |
8278 | } | 8323 | } |
8279 | s.ConfigNum++; | 8324 | s.ConfigNum++; |
8280 | 8325 | ||
8281 | /* We want to use only one file descriptor for global and state machine debug output */ | 8326 | /* We want to use only one file descriptor for global and state machine debug output */ |
8282 | s.Config[i].UseGlobalDebugFile = true; | 8327 | s.Config[i].UseGlobalDebugFile = true; |
8283 | 8328 | ||
8284 | /* It makes no sense to open several debug logs... */ | 8329 | /* It makes no sense to open several debug logs... */ |
8285 | if (i != 0) { | 8330 | if (i != 0) { |
8286 | strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); | 8331 | strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); |
8287 | free(s.Config[i].DebugFile); | 8332 | free(s.Config[i].DebugFile); |
8288 | s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); | 8333 | s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); |
8289 | } else { | 8334 | } else { |
8290 | /* Just for first config */ | 8335 | /* Just for first config */ |
8291 | /* When user gave debug level on command line */ | 8336 | /* When user gave debug level on command line */ |
8292 | if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { | 8337 | if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { |
8293 | /* Debug level from command line will be used with phone too */ | 8338 | /* Debug level from command line will be used with phone too */ |
8294 | strcpy(s.Config[i].DebugLevel,argv[1 + start]); | 8339 | strcpy(s.Config[i].DebugLevel,argv[1 + start]); |
8295 | start++; | 8340 | start++; |
8296 | } else { | 8341 | } else { |
8297 | /* Try to set debug level from config file */ | 8342 | /* Try to set debug level from config file */ |
8298 | GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); | 8343 | GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); |
8299 | } | 8344 | } |
8300 | /* If user gave debug file in gammurc, we will use it */ | 8345 | /* If user gave debug file in gammurc, we will use it */ |
8301 | error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); | 8346 | error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); |
8302 | Print_Error(error); | 8347 | Print_Error(error); |
8303 | } | 8348 | } |
8304 | 8349 | ||
8305 | /* We wanted to read just user specified configuration. */ | 8350 | /* We wanted to read just user specified configuration. */ |
8306 | if (only_config != -1) {break;} | 8351 | if (only_config != -1) {break;} |
8307 | } | 8352 | } |
8308 | 8353 | #endif | |
8309 | /* Do we have enough parameters? */ | 8354 | /* Do we have enough parameters? */ |
8310 | if (argc == 1 + start) { | 8355 | if (argc == 1 + start) { |
8311 | HelpGeneral(); | 8356 | HelpGeneral(); |
8312 | printmsg("Too few parameters!\n"); | 8357 | printmsg("Too few parameters!\n"); |
8313 | exit(-2); | 8358 | exit(-2); |
8314 | } | 8359 | } |
8315 | 8360 | ||
8316 | /* Check used version vs. compiled */ | 8361 | /* Check used version vs. compiled */ |
8317 | if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { | 8362 | if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { |
8318 | printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", | 8363 | printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", |
8319 | GetGammuVersion(),VERSION); | 8364 | GetGammuVersion(),VERSION); |
8320 | exit(-1); | 8365 | exit(-1); |
8321 | } | 8366 | } |
8322 | 8367 | ||
8323 | /* Check parameters */ | 8368 | /* Check parameters */ |
8324 | while (Parameters[z].Function != NULL) { | 8369 | while (Parameters[z].Function != NULL) { |
8325 | if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { | 8370 | if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { |
8326 | if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { | 8371 | if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { |
8327 | Parameters[z].Function(argc - start, argv + start); | 8372 | Parameters[z].Function(argc - start, argv + start); |
8328 | break; | 8373 | break; |
8329 | } else { | 8374 | } else { |
8330 | count_failed = true; | 8375 | count_failed = true; |
8331 | } | 8376 | } |
8332 | } | 8377 | } |
8333 | z++; | 8378 | z++; |
8334 | } | 8379 | } |
8335 | 8380 | ||
8336 | /* Tell user when we did nothing */ | 8381 | /* Tell user when we did nothing */ |
8337 | if (Parameters[z].Function == NULL) { | 8382 | if (Parameters[z].Function == NULL) { |
8338 | HelpGeneral(); | 8383 | HelpGeneral(); |
8339 | if (count_failed) { | 8384 | if (count_failed) { |
8340 | printmsg("Bad parameter count!\n"); | 8385 | printmsg("Bad parameter count!\n"); |
8341 | } else { | 8386 | } else { |
8342 | printmsg("Bad option!\n"); | 8387 | printmsg("Bad option!\n"); |
8343 | } | 8388 | } |
8344 | } | 8389 | } |
8345 | 8390 | ||
8346 | /* Close debug output if opened */ | 8391 | /* Close debug output if opened */ |
8347 | if (di.df!=stdout) fclose(di.df); | 8392 | if (di.df!=stdout) fclose(di.df); |
8348 | //#endif // 0 | 8393 | //#endif // 0 |
8349 | fprintf(stderr,"kammu: Success. End. \n"); | 8394 | fprintf(stderr,"kammu: Success. End. \n"); |
8350 | exit(0); | 8395 | exit(0); |
8351 | } | 8396 | } |
8352 | 8397 | ||
8353 | /* How should editor hadle tabs in this file? Add editor commands here. | 8398 | /* How should editor hadle tabs in this file? Add editor commands here. |
8354 | * vim: noexpandtab sw=8 ts=8 sts=8: | 8399 | * vim: noexpandtab sw=8 ts=8 sts=8: |
8355 | */ | 8400 | */ |
8356 | 8401 | ||
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 0bc9125..2ad1b5a 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -95,487 +95,489 @@ PhoneFormat::~PhoneFormat() | |||
95 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 95 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
96 | { | 96 | { |
97 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 97 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
98 | s->ConfigNum = 1; | 98 | s->ConfigNum = 1; |
99 | GSM_Config *cfg = &s->Config[0]; | 99 | GSM_Config *cfg = &s->Config[0]; |
100 | if ( ! mConnection.isEmpty() ) { | 100 | if ( ! mConnection.isEmpty() ) { |
101 | cfg->Connection = strdup(mConnection.latin1()); | 101 | cfg->Connection = strdup(mConnection.latin1()); |
102 | cfg->DefaultConnection = false; | 102 | cfg->DefaultConnection = false; |
103 | qDebug("Connection set %s ", cfg->Connection ); | 103 | qDebug("Connection set %s ", cfg->Connection ); |
104 | 104 | ||
105 | } | 105 | } |
106 | if ( ! mDevice.isEmpty() ) { | 106 | if ( ! mDevice.isEmpty() ) { |
107 | cfg->Device = strdup(mDevice.latin1()); | 107 | cfg->Device = strdup(mDevice.latin1()); |
108 | cfg->DefaultDevice = false; | 108 | cfg->DefaultDevice = false; |
109 | qDebug("Device set %s ", cfg->Device); | 109 | qDebug("Device set %s ", cfg->Device); |
110 | 110 | ||
111 | } | 111 | } |
112 | if ( ! mModel.isEmpty() ) { | 112 | if ( ! mModel.isEmpty() ) { |
113 | strcpy(cfg->Model,mModel.latin1() ); | 113 | strcpy(cfg->Model,mModel.latin1() ); |
114 | cfg->DefaultModel = false; | 114 | cfg->DefaultModel = false; |
115 | qDebug("Model set %s ",cfg->Model ); | 115 | qDebug("Model set %s ",cfg->Model ); |
116 | } | 116 | } |
117 | int error=GSM_InitConnection(s,3); | 117 | int error=GSM_InitConnection(s,3); |
118 | return error; | 118 | return error; |
119 | } | 119 | } |
120 | #endif | 120 | #endif |
121 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 121 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
122 | { | 122 | { |
123 | QStringList attList; | 123 | QStringList attList; |
124 | if ( todo->hasDueDate() ) | 124 | if ( todo->hasDueDate() ) |
125 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 125 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
126 | attList << todo->summary(); | 126 | attList << todo->summary(); |
127 | QString completedString = "no"; | 127 | QString completedString = "no"; |
128 | if ( todo->isCompleted() ) | 128 | if ( todo->isCompleted() ) |
129 | completedString = "yes"; | 129 | completedString = "yes"; |
130 | attList << completedString; | 130 | attList << completedString; |
131 | attList << QString::number( todo->priority() ); | 131 | attList << QString::number( todo->priority() ); |
132 | QString alarmString = "na"; | 132 | QString alarmString = "na"; |
133 | Alarm *alarm; | 133 | Alarm *alarm; |
134 | if ( todo->alarms().count() > 0 ) { | 134 | if ( todo->alarms().count() > 0 ) { |
135 | alarm = todo->alarms().first(); | 135 | alarm = todo->alarms().first(); |
136 | if ( alarm->enabled() ) { | 136 | if ( alarm->enabled() ) { |
137 | alarmString = QString::number(alarm->startOffset().asSeconds() ); | 137 | alarmString = QString::number(alarm->startOffset().asSeconds() ); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | attList << alarmString; | 140 | attList << alarmString; |
141 | attList << todo->categoriesStr(); | 141 | attList << todo->categoriesStr(); |
142 | attList << todo->secrecyStr(); | 142 | attList << todo->secrecyStr(); |
143 | return PhoneFormat::getCsum(attList ); | 143 | return PhoneFormat::getCsum(attList ); |
144 | 144 | ||
145 | } | 145 | } |
146 | ulong PhoneFormat::getCsumEvent( Event* event ) | 146 | ulong PhoneFormat::getCsumEvent( Event* event ) |
147 | { | 147 | { |
148 | QStringList attList; | 148 | QStringList attList; |
149 | attList << PhoneParser::dtToString ( event->dtStart() ); | 149 | attList << PhoneParser::dtToString ( event->dtStart() ); |
150 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 150 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
151 | attList << event->summary(); | 151 | attList << event->summary(); |
152 | attList << event->location(); | 152 | attList << event->location(); |
153 | QString alarmString = "na"; | 153 | QString alarmString = "na"; |
154 | Alarm *alarm; | 154 | Alarm *alarm; |
155 | if ( event->alarms().count() > 0 ) { | 155 | if ( event->alarms().count() > 0 ) { |
156 | alarm = event->alarms().first(); | 156 | alarm = event->alarms().first(); |
157 | if ( alarm->enabled() ) { | 157 | if ( alarm->enabled() ) { |
158 | alarmString = QString::number( alarm->startOffset().asSeconds() ); | 158 | alarmString = QString::number( alarm->startOffset().asSeconds() ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | attList << alarmString; | 161 | attList << alarmString; |
162 | Recurrence* rec = event->recurrence(); | 162 | Recurrence* rec = event->recurrence(); |
163 | QStringList list; | 163 | QStringList list; |
164 | bool writeEndDate = false; | 164 | bool writeEndDate = false; |
165 | switch ( rec->doesRecur() ) | 165 | switch ( rec->doesRecur() ) |
166 | { | 166 | { |
167 | case Recurrence::rDaily: // 0 | 167 | case Recurrence::rDaily: // 0 |
168 | list.append( "0" ); | 168 | list.append( "0" ); |
169 | list.append( QString::number( rec->frequency() ));//12 | 169 | list.append( QString::number( rec->frequency() ));//12 |
170 | list.append( "0" ); | 170 | list.append( "0" ); |
171 | list.append( "0" ); | 171 | list.append( "0" ); |
172 | writeEndDate = true; | 172 | writeEndDate = true; |
173 | break; | 173 | break; |
174 | case Recurrence::rWeekly:// 1 | 174 | case Recurrence::rWeekly:// 1 |
175 | list.append( "1" ); | 175 | list.append( "1" ); |
176 | list.append( QString::number( rec->frequency()) );//12 | 176 | list.append( QString::number( rec->frequency()) );//12 |
177 | list.append( "0" ); | 177 | list.append( "0" ); |
178 | { | 178 | { |
179 | int days = 0; | 179 | int days = 0; |
180 | QBitArray weekDays = rec->days(); | 180 | QBitArray weekDays = rec->days(); |
181 | int i; | 181 | int i; |
182 | for( i = 1; i <= 7; ++i ) { | 182 | for( i = 1; i <= 7; ++i ) { |
183 | if ( weekDays[i-1] ) { | 183 | if ( weekDays[i-1] ) { |
184 | days += 1 << (i-1); | 184 | days += 1 << (i-1); |
185 | } | 185 | } |
186 | } | 186 | } |
187 | list.append( QString::number( days ) ); | 187 | list.append( QString::number( days ) ); |
188 | } | 188 | } |
189 | //pending weekdays | 189 | //pending weekdays |
190 | writeEndDate = true; | 190 | writeEndDate = true; |
191 | 191 | ||
192 | break; | 192 | break; |
193 | case Recurrence::rMonthlyPos:// 2 | 193 | case Recurrence::rMonthlyPos:// 2 |
194 | list.append( "2" ); | 194 | list.append( "2" ); |
195 | list.append( QString::number( rec->frequency()) );//12 | 195 | list.append( QString::number( rec->frequency()) );//12 |
196 | 196 | ||
197 | writeEndDate = true; | 197 | writeEndDate = true; |
198 | { | 198 | { |
199 | int count = 1; | 199 | int count = 1; |
200 | QPtrList<Recurrence::rMonthPos> rmp; | 200 | QPtrList<Recurrence::rMonthPos> rmp; |
201 | rmp = rec->monthPositions(); | 201 | rmp = rec->monthPositions(); |
202 | if ( rmp.first()->negative ) | 202 | if ( rmp.first()->negative ) |
203 | count = 5 - rmp.first()->rPos - 1; | 203 | count = 5 - rmp.first()->rPos - 1; |
204 | else | 204 | else |
205 | count = rmp.first()->rPos - 1; | 205 | count = rmp.first()->rPos - 1; |
206 | list.append( QString::number( count ) ); | 206 | list.append( QString::number( count ) ); |
207 | 207 | ||
208 | } | 208 | } |
209 | 209 | ||
210 | list.append( "0" ); | 210 | list.append( "0" ); |
211 | break; | 211 | break; |
212 | case Recurrence::rMonthlyDay:// 3 | 212 | case Recurrence::rMonthlyDay:// 3 |
213 | list.append( "3" ); | 213 | list.append( "3" ); |
214 | list.append( QString::number( rec->frequency()) );//12 | 214 | list.append( QString::number( rec->frequency()) );//12 |
215 | list.append( "0" ); | 215 | list.append( "0" ); |
216 | list.append( "0" ); | 216 | list.append( "0" ); |
217 | writeEndDate = true; | 217 | writeEndDate = true; |
218 | break; | 218 | break; |
219 | case Recurrence::rYearlyMonth://4 | 219 | case Recurrence::rYearlyMonth://4 |
220 | list.append( "4" ); | 220 | list.append( "4" ); |
221 | list.append( QString::number( rec->frequency()) );//12 | 221 | list.append( QString::number( rec->frequency()) );//12 |
222 | list.append( "0" ); | 222 | list.append( "0" ); |
223 | list.append( "0" ); | 223 | list.append( "0" ); |
224 | writeEndDate = true; | 224 | writeEndDate = true; |
225 | break; | 225 | break; |
226 | 226 | ||
227 | default: | 227 | default: |
228 | list.append( "255" ); | 228 | list.append( "255" ); |
229 | list.append( QString() ); | 229 | list.append( QString() ); |
230 | list.append( "0" ); | 230 | list.append( "0" ); |
231 | list.append( QString() ); | 231 | list.append( QString() ); |
232 | list.append( "0" ); | 232 | list.append( "0" ); |
233 | list.append( "20991231T000000" ); | 233 | list.append( "20991231T000000" ); |
234 | break; | 234 | break; |
235 | } | 235 | } |
236 | if ( writeEndDate ) { | 236 | if ( writeEndDate ) { |
237 | 237 | ||
238 | if ( rec->endDate().isValid() ) { // 15 + 16 | 238 | if ( rec->endDate().isValid() ) { // 15 + 16 |
239 | list.append( "1" ); | 239 | list.append( "1" ); |
240 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 240 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
241 | } else { | 241 | } else { |
242 | list.append( "0" ); | 242 | list.append( "0" ); |
243 | list.append( "20991231T000000" ); | 243 | list.append( "20991231T000000" ); |
244 | } | 244 | } |
245 | 245 | ||
246 | } | 246 | } |
247 | attList << list.join(""); | 247 | attList << list.join(""); |
248 | attList << event->categoriesStr(); | 248 | attList << event->categoriesStr(); |
249 | attList << event->secrecyStr(); | 249 | attList << event->secrecyStr(); |
250 | return PhoneFormat::getCsum(attList ); | 250 | return PhoneFormat::getCsum(attList ); |
251 | } | 251 | } |
252 | ulong PhoneFormat::getCsum( const QStringList & attList) | 252 | ulong PhoneFormat::getCsum( const QStringList & attList) |
253 | { | 253 | { |
254 | int max = attList.count() -1; | 254 | int max = attList.count() -1; |
255 | ulong cSum = 0; | 255 | ulong cSum = 0; |
256 | int j,k,i; | 256 | int j,k,i; |
257 | int add; | 257 | int add; |
258 | for ( i = 1; i < max ; ++i ) { | 258 | for ( i = 1; i < max ; ++i ) { |
259 | QString s = attList[i]; | 259 | QString s = attList[i]; |
260 | if ( ! s.isEmpty() ){ | 260 | if ( ! s.isEmpty() ){ |
261 | j = s.length(); | 261 | j = s.length(); |
262 | for ( k = 0; k < j; ++k ) { | 262 | for ( k = 0; k < j; ++k ) { |
263 | int mul = k +1; | 263 | int mul = k +1; |
264 | add = s[k].unicode (); | 264 | add = s[k].unicode (); |
265 | if ( k < 16 ) | 265 | if ( k < 16 ) |
266 | mul = mul * mul; | 266 | mul = mul * mul; |
267 | add = add * mul *i*i*i; | 267 | add = add * mul *i*i*i; |
268 | cSum += add; | 268 | cSum += add; |
269 | } | 269 | } |
270 | } | 270 | } |
271 | } | 271 | } |
272 | return cSum; | 272 | return cSum; |
273 | 273 | ||
274 | } | 274 | } |
275 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 275 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
276 | #include <stdlib.h> | 276 | #include <stdlib.h> |
277 | #define DEBUGMODE false | 277 | #define DEBUGMODE false |
278 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 278 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
279 | { | 279 | { |
280 | 280 | ||
281 | QString fileName; | 281 | QString fileName; |
282 | #ifdef _WIN32_ | 282 | #ifdef _WIN32_ |
283 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 283 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
284 | #else | 284 | #else |
285 | fileName = "/tmp/kdepimtemp.vcs"; | 285 | fileName = "/tmp/kdepimtemp.vcs"; |
286 | #endif | 286 | #endif |
287 | QString command ="./kammu --backup " + fileName + " -yes"; | 287 | QString command ="./kammu --backup " + fileName + " -yes -C" + |
288 | mConnection +" -D" + mDevice +" -M" + mModel; | ||
288 | int ret = system ( command.latin1() ); | 289 | int ret = system ( command.latin1() ); |
289 | if ( ret != 0 ) | 290 | if ( ret != 0 ) |
290 | return false; | 291 | return false; |
291 | VCalFormat vfload; | 292 | VCalFormat vfload; |
292 | vfload.setLocalTime ( true ); | 293 | vfload.setLocalTime ( true ); |
293 | if ( ! vfload.load( calendar, fileName ) ) | 294 | if ( ! vfload.load( calendar, fileName ) ) |
294 | return false; | 295 | return false; |
295 | QPtrList<Event> er = calendar->rawEvents(); | 296 | QPtrList<Event> er = calendar->rawEvents(); |
296 | Event* ev = er.first(); | 297 | Event* ev = er.first(); |
297 | while ( ev ) { | 298 | while ( ev ) { |
298 | int id = ev->pilotId(); | 299 | int id = ev->pilotId(); |
299 | Event *event; | 300 | Event *event; |
300 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 301 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
301 | if ( event ) { | 302 | if ( event ) { |
302 | event = (Event*)event->clone(); | 303 | event = (Event*)event->clone(); |
303 | copyEvent( event, ev ); | 304 | copyEvent( event, ev ); |
304 | calendar->deleteEvent( ev ); | 305 | calendar->deleteEvent( ev ); |
305 | calendar->addEvent( event); | 306 | calendar->addEvent( event); |
306 | } | 307 | } |
307 | else | 308 | else |
308 | event = ev; | 309 | event = ev; |
309 | uint cSum; | 310 | uint cSum; |
310 | cSum = PhoneFormat::getCsumEvent( event ); | 311 | cSum = PhoneFormat::getCsumEvent( event ); |
311 | event->setCsum( mProfileName, QString::number( cSum )); | 312 | event->setCsum( mProfileName, QString::number( cSum )); |
312 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 313 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
313 | event->setID( mProfileName,QString::number( id ) ); | 314 | event->setID( mProfileName,QString::number( id ) ); |
314 | ev = er.next(); | 315 | ev = er.next(); |
315 | } | 316 | } |
316 | { | 317 | { |
317 | QPtrList<Todo> tr = calendar->rawTodos(); | 318 | QPtrList<Todo> tr = calendar->rawTodos(); |
318 | Todo* ev = tr.first(); | 319 | Todo* ev = tr.first(); |
319 | while ( ev ) { | 320 | while ( ev ) { |
320 | 321 | ||
321 | QStringList cat = ev->categories(); | 322 | QStringList cat = ev->categories(); |
322 | if ( cat.contains( "MeetingDEF" )) { | 323 | if ( cat.contains( "MeetingDEF" )) { |
323 | ev->setCategories( QStringList() ); | 324 | ev->setCategories( QStringList() ); |
324 | } | 325 | } |
325 | int id = ev->pilotId(); | 326 | int id = ev->pilotId(); |
326 | Todo *event; | 327 | Todo *event; |
327 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 328 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
328 | if ( event ) { | 329 | if ( event ) { |
329 | event = (Todo*)event->clone(); | 330 | event = (Todo*)event->clone(); |
330 | copyTodo( event, ev ); | 331 | copyTodo( event, ev ); |
331 | calendar->deleteTodo( ev ); | 332 | calendar->deleteTodo( ev ); |
332 | calendar->addTodo( event); | 333 | calendar->addTodo( event); |
333 | } | 334 | } |
334 | else | 335 | else |
335 | event = ev; | 336 | event = ev; |
336 | uint cSum; | 337 | uint cSum; |
337 | cSum = PhoneFormat::getCsumTodo( event ); | 338 | cSum = PhoneFormat::getCsumTodo( event ); |
338 | event->setCsum( mProfileName, QString::number( cSum )); | 339 | event->setCsum( mProfileName, QString::number( cSum )); |
339 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 340 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
340 | event->setID( mProfileName,QString::number( id ) ); | 341 | event->setID( mProfileName,QString::number( id ) ); |
341 | ev = tr.next(); | 342 | ev = tr.next(); |
342 | } | 343 | } |
343 | } | 344 | } |
344 | return true; | 345 | return true; |
345 | } | 346 | } |
346 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 347 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
347 | { | 348 | { |
348 | if ( from->dtStart().isValid() ) | 349 | if ( from->dtStart().isValid() ) |
349 | to->setDtStart( from->dtStart() ); | 350 | to->setDtStart( from->dtStart() ); |
350 | if ( from->dtEnd().isValid() ) | 351 | if ( from->dtEnd().isValid() ) |
351 | to->setDtEnd( from->dtEnd() ); | 352 | to->setDtEnd( from->dtEnd() ); |
352 | if ( !from->location().isEmpty() ) | 353 | if ( !from->location().isEmpty() ) |
353 | to->setLocation( from->location() ); | 354 | to->setLocation( from->location() ); |
354 | if ( !from->description().isEmpty() ) | 355 | if ( !from->description().isEmpty() ) |
355 | to->setDescription( from->description() ); | 356 | to->setDescription( from->description() ); |
356 | if ( !from->summary().isEmpty() ) | 357 | if ( !from->summary().isEmpty() ) |
357 | to->setSummary( from->summary() ); | 358 | to->setSummary( from->summary() ); |
358 | 359 | ||
359 | QPtrListIterator<Alarm> it( from->alarms() ); | 360 | QPtrListIterator<Alarm> it( from->alarms() ); |
360 | to->clearAlarms(); | 361 | to->clearAlarms(); |
361 | const Alarm *a; | 362 | const Alarm *a; |
362 | while( (a = it.current()) ) { | 363 | while( (a = it.current()) ) { |
363 | Alarm *b = new Alarm( *a ); | 364 | Alarm *b = new Alarm( *a ); |
364 | b->setParent( to ); | 365 | b->setParent( to ); |
365 | to->addAlarm( b ); | 366 | to->addAlarm( b ); |
366 | ++it; | 367 | ++it; |
367 | } | 368 | } |
368 | QStringList cat = to->categories(); | 369 | QStringList cat = to->categories(); |
369 | QStringList catFrom = from->categories(); | 370 | QStringList catFrom = from->categories(); |
370 | QString nCat; | 371 | QString nCat; |
371 | int iii; | 372 | int iii; |
372 | for ( iii = 0; iii < catFrom.count();++iii ) { | 373 | for ( iii = 0; iii < catFrom.count();++iii ) { |
373 | nCat = catFrom[iii]; | 374 | nCat = catFrom[iii]; |
374 | if ( !nCat.isEmpty() ) | 375 | if ( !nCat.isEmpty() ) |
375 | if ( !cat.contains( nCat )) { | 376 | if ( !cat.contains( nCat )) { |
376 | cat << nCat; | 377 | cat << nCat; |
377 | } | 378 | } |
378 | } | 379 | } |
379 | to->setCategories( cat ); | 380 | to->setCategories( cat ); |
380 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 381 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
381 | to->setRecurrence( r ) ; | 382 | to->setRecurrence( r ) ; |
382 | 383 | ||
383 | 384 | ||
384 | } | 385 | } |
385 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 386 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
386 | { | 387 | { |
387 | if ( from->dtStart().isValid() ) | 388 | if ( from->dtStart().isValid() ) |
388 | to->setDtStart( from->dtStart() ); | 389 | to->setDtStart( from->dtStart() ); |
389 | if ( from->dtDue().isValid() ) | 390 | if ( from->dtDue().isValid() ) |
390 | to->setDtDue( from->dtDue() ); | 391 | to->setDtDue( from->dtDue() ); |
391 | if ( !from->location().isEmpty() ) | 392 | if ( !from->location().isEmpty() ) |
392 | to->setLocation( from->location() ); | 393 | to->setLocation( from->location() ); |
393 | if ( !from->description().isEmpty() ) | 394 | if ( !from->description().isEmpty() ) |
394 | to->setDescription( from->description() ); | 395 | to->setDescription( from->description() ); |
395 | if ( !from->summary().isEmpty() ) | 396 | if ( !from->summary().isEmpty() ) |
396 | to->setSummary( from->summary() ); | 397 | to->setSummary( from->summary() ); |
397 | 398 | ||
398 | QPtrListIterator<Alarm> it( from->alarms() ); | 399 | QPtrListIterator<Alarm> it( from->alarms() ); |
399 | to->clearAlarms(); | 400 | to->clearAlarms(); |
400 | const Alarm *a; | 401 | const Alarm *a; |
401 | while( (a = it.current()) ) { | 402 | while( (a = it.current()) ) { |
402 | Alarm *b = new Alarm( *a ); | 403 | Alarm *b = new Alarm( *a ); |
403 | b->setParent( to ); | 404 | b->setParent( to ); |
404 | to->addAlarm( b ); | 405 | to->addAlarm( b ); |
405 | ++it; | 406 | ++it; |
406 | } | 407 | } |
407 | QStringList cat = to->categories(); | 408 | QStringList cat = to->categories(); |
408 | QStringList catFrom = from->categories(); | 409 | QStringList catFrom = from->categories(); |
409 | QString nCat; | 410 | QString nCat; |
410 | int iii; | 411 | int iii; |
411 | for ( iii = 0; iii < catFrom.count();++iii ) { | 412 | for ( iii = 0; iii < catFrom.count();++iii ) { |
412 | nCat = catFrom[iii]; | 413 | nCat = catFrom[iii]; |
413 | if ( !nCat.isEmpty() ) | 414 | if ( !nCat.isEmpty() ) |
414 | if ( !cat.contains( nCat )) { | 415 | if ( !cat.contains( nCat )) { |
415 | cat << nCat; | 416 | cat << nCat; |
416 | } | 417 | } |
417 | } | 418 | } |
418 | to->setCategories( cat ); | 419 | to->setCategories( cat ); |
419 | if ( from->isCompleted() ) { | 420 | if ( from->isCompleted() ) { |
420 | to->setCompleted( true ); | 421 | to->setCompleted( true ); |
421 | if( from->completed().isValid() ) | 422 | if( from->completed().isValid() ) |
422 | to->setCompleted( from->completed() ); | 423 | to->setCompleted( from->completed() ); |
423 | } else { | 424 | } else { |
424 | // set percentcomplete only, if to->isCompleted() | 425 | // set percentcomplete only, if to->isCompleted() |
425 | if ( to->isCompleted() ) | 426 | if ( to->isCompleted() ) |
426 | to->setPercentComplete(from->percentComplete()); | 427 | to->setPercentComplete(from->percentComplete()); |
427 | } | 428 | } |
428 | to->setPriority(from->priority()); | 429 | to->setPriority(from->priority()); |
429 | 430 | ||
430 | } | 431 | } |
431 | #include <qcstring.h> | 432 | #include <qcstring.h> |
432 | 433 | ||
433 | void PhoneFormat::afterSave( Incidence* inc) | 434 | void PhoneFormat::afterSave( Incidence* inc) |
434 | { | 435 | { |
435 | uint csum; | 436 | uint csum; |
436 | inc->removeID( mProfileName ); | 437 | inc->removeID( mProfileName ); |
437 | if ( inc->type() == "Event") | 438 | if ( inc->type() == "Event") |
438 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 439 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
439 | else | 440 | else |
440 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 441 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
441 | inc->setCsum( mProfileName, QString::number( csum )); | 442 | inc->setCsum( mProfileName, QString::number( csum )); |
442 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 443 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
443 | 444 | ||
444 | } | 445 | } |
445 | bool PhoneFormat::save( Calendar *calendar) | 446 | bool PhoneFormat::save( Calendar *calendar) |
446 | { | 447 | { |
447 | QLabel status ( i18n(" Opening device ..."), 0 ); | 448 | QLabel status ( i18n(" Opening device ..."), 0 ); |
448 | int w = status.sizeHint().width()+20 ; | 449 | int w = status.sizeHint().width()+20 ; |
449 | if ( w < 200 ) w = 230; | 450 | if ( w < 200 ) w = 230; |
450 | int h = status.sizeHint().height()+20 ; | 451 | int h = status.sizeHint().height()+20 ; |
451 | int dw = QApplication::desktop()->width(); | 452 | int dw = QApplication::desktop()->width(); |
452 | int dh = QApplication::desktop()->height(); | 453 | int dh = QApplication::desktop()->height(); |
453 | status.setCaption(i18n("Writing to phone...") ); | 454 | status.setCaption(i18n("Writing to phone...") ); |
454 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 455 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
455 | status.show(); | 456 | status.show(); |
456 | status.raise(); | 457 | status.raise(); |
457 | qApp->processEvents(); | 458 | qApp->processEvents(); |
458 | QString message; | 459 | QString message; |
459 | #ifdef _WIN32_ | 460 | #ifdef _WIN32_ |
460 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 461 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
461 | #else | 462 | #else |
462 | QString fileName = "/tmp/kdepimtemp.vcs"; | 463 | QString fileName = "/tmp/kdepimtemp.vcs"; |
463 | #endif | 464 | #endif |
464 | 465 | ||
465 | // 1 remove events which should be deleted | 466 | // 1 remove events which should be deleted |
466 | QPtrList<Event> er = calendar->rawEvents(); | 467 | QPtrList<Event> er = calendar->rawEvents(); |
467 | Event* ev = er.first(); | 468 | Event* ev = er.first(); |
468 | while ( ev ) { | 469 | while ( ev ) { |
469 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 470 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
470 | calendar->deleteEvent( ev ); | 471 | calendar->deleteEvent( ev ); |
471 | } else { | 472 | } else { |
472 | 473 | ||
473 | } | 474 | } |
474 | ev = er.next(); | 475 | ev = er.next(); |
475 | } | 476 | } |
476 | // 2 remove todos which should be deleted | 477 | // 2 remove todos which should be deleted |
477 | QPtrList<Todo> tl = calendar->rawTodos(); | 478 | QPtrList<Todo> tl = calendar->rawTodos(); |
478 | Todo* to = tl.first(); | 479 | Todo* to = tl.first(); |
479 | while ( to ) { | 480 | while ( to ) { |
480 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 481 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
481 | calendar->deleteTodo( to ); | 482 | calendar->deleteTodo( to ); |
482 | } | 483 | } |
483 | to = tl.next(); | 484 | to = tl.next(); |
484 | } | 485 | } |
485 | // 3 save file | 486 | // 3 save file |
486 | VCalFormat vfsave; | 487 | VCalFormat vfsave; |
487 | vfsave.setLocalTime ( true ); | 488 | vfsave.setLocalTime ( true ); |
488 | if ( ! vfsave.save( calendar, fileName ) ) | 489 | if ( ! vfsave.save( calendar, fileName ) ) |
489 | return false; | 490 | return false; |
490 | // 4 call kammu | 491 | // 4 call kammu |
491 | QString command ="./kammu --restore " + fileName ; | 492 | QString command ="./kammu --restore " + fileName + " -C" + |
493 | mConnection +" -D" + mDevice +" -M" + mModel;; | ||
492 | int ret = system ( command.latin1() ); | 494 | int ret = system ( command.latin1() ); |
493 | if ( ret != 0 ) | 495 | if ( ret != 0 ) |
494 | return false; | 496 | return false; |
495 | // 5 reread data | 497 | // 5 reread data |
496 | message = i18n(" Rereading all data ... "); | 498 | message = i18n(" Rereading all data ... "); |
497 | status.setText ( message ); | 499 | status.setText ( message ); |
498 | qApp->processEvents(); | 500 | qApp->processEvents(); |
499 | CalendarLocal* calendarTemp = new CalendarLocal(); | 501 | CalendarLocal* calendarTemp = new CalendarLocal(); |
500 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 502 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
501 | if ( ! load( calendarTemp,calendar) ){ | 503 | if ( ! load( calendarTemp,calendar) ){ |
502 | qDebug("error reloading calendar "); | 504 | qDebug("error reloading calendar "); |
503 | delete calendarTemp; | 505 | delete calendarTemp; |
504 | return false; | 506 | return false; |
505 | } | 507 | } |
506 | // 6 compare data | 508 | // 6 compare data |
507 | 509 | ||
508 | //algo 6 compare event | 510 | //algo 6 compare event |
509 | er = calendar->rawEvents(); | 511 | er = calendar->rawEvents(); |
510 | ev = er.first(); | 512 | ev = er.first(); |
511 | message = i18n(" Comparing event # "); | 513 | message = i18n(" Comparing event # "); |
512 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 514 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
513 | Event* ev1; | 515 | Event* ev1; |
514 | int procCount = 0; | 516 | int procCount = 0; |
515 | while ( ev ) { | 517 | while ( ev ) { |
516 | qDebug("event new ID "); | 518 | qDebug("event new ID "); |
517 | status.setText ( message + QString::number ( ++procCount ) ); | 519 | status.setText ( message + QString::number ( ++procCount ) ); |
518 | qApp->processEvents(); | 520 | qApp->processEvents(); |
519 | QString cSum = ev->getCsum(mProfileName); | 521 | QString cSum = ev->getCsum(mProfileName); |
520 | ev1 = er1.first(); | 522 | ev1 = er1.first(); |
521 | while ( ev1 ) { | 523 | while ( ev1 ) { |
522 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 524 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
523 | er1.remove( ev1 ); | 525 | er1.remove( ev1 ); |
524 | afterSave( ev ); | 526 | afterSave( ev ); |
525 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 527 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
526 | break; | 528 | break; |
527 | } | 529 | } |
528 | ev1 = er1.next(); | 530 | ev1 = er1.next(); |
529 | } | 531 | } |
530 | if ( ! ev1 ) { | 532 | if ( ! ev1 ) { |
531 | ev->removeID(mProfileName); | 533 | ev->removeID(mProfileName); |
532 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 534 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
533 | } | 535 | } |
534 | 536 | ||
535 | 537 | ||
536 | ev = er.next(); | 538 | ev = er.next(); |
537 | } | 539 | } |
538 | //algo 6 compare todo | 540 | //algo 6 compare todo |
539 | to = tl.first(); | 541 | to = tl.first(); |
540 | procCount = 0; | 542 | procCount = 0; |
541 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 543 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
542 | Todo* to1 ; | 544 | Todo* to1 ; |
543 | message = i18n(" Comparing todo # "); | 545 | message = i18n(" Comparing todo # "); |
544 | while ( to ) { | 546 | while ( to ) { |
545 | qDebug("todo2 %d ", procCount); | 547 | qDebug("todo2 %d ", procCount); |
546 | status.setText ( message + QString::number ( ++procCount ) ); | 548 | status.setText ( message + QString::number ( ++procCount ) ); |
547 | qApp->processEvents(); | 549 | qApp->processEvents(); |
548 | QString cSum = to->getCsum(mProfileName); | 550 | QString cSum = to->getCsum(mProfileName); |
549 | Todo* to1 = tl1.first(); | 551 | Todo* to1 = tl1.first(); |
550 | while ( to1 ) { | 552 | while ( to1 ) { |
551 | if ( to1->getCsum( mProfileName ) == cSum ) { | 553 | if ( to1->getCsum( mProfileName ) == cSum ) { |
552 | tl1.remove( to1 ); | 554 | tl1.remove( to1 ); |
553 | afterSave( to ); | 555 | afterSave( to ); |
554 | to->setID(mProfileName, to1->getID(mProfileName) ); | 556 | to->setID(mProfileName, to1->getID(mProfileName) ); |
555 | break; | 557 | break; |
556 | } | 558 | } |
557 | to1 = tl1.next(); | 559 | to1 = tl1.next(); |
558 | } | 560 | } |
559 | if ( ! to1 ) { | 561 | if ( ! to1 ) { |
560 | to->removeID(mProfileName); | 562 | to->removeID(mProfileName); |
561 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 563 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
562 | } | 564 | } |
563 | 565 | ||
564 | to = tl.next(); | 566 | to = tl.next(); |
565 | } | 567 | } |
566 | delete calendarTemp; | 568 | delete calendarTemp; |
567 | return true; | 569 | return true; |
568 | 570 | ||
569 | 571 | ||
570 | 572 | ||
571 | } | 573 | } |
572 | 574 | ||
573 | 575 | ||
574 | QString PhoneFormat::toString( Calendar * ) | 576 | QString PhoneFormat::toString( Calendar * ) |
575 | { | 577 | { |
576 | return QString::null; | 578 | return QString::null; |
577 | } | 579 | } |
578 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 580 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
579 | { | 581 | { |
580 | return false; | 582 | return false; |
581 | } | 583 | } |