// connect the device and ask user to turn device on (if necessary) bool KMobileGnokii::connectDevice(QWidget * /*parent*/) { if (connected()) return true; QString err = businit(); m_connected = err.isEmpty(); PRINT_DEBUG << QString("connectDevice() : %1\n").arg(m_connected ? "Ok" : err); return m_connected; }
static int parse_options(int argc, char *argv[]) { int c; int opt_index = -1; gn_error rc; /* Every option should be in this array. */ static struct option long_options[] = { /* FIXME: these comments are nice, but they would be more useful as docs for the user */ /* Display usage. */ { "help", optional_argument, NULL, OPT_HELP }, /* Display version and build information. */ { "version", no_argument, NULL, OPT_VERSION }, /* Monitor mode */ { "monitor", optional_argument, NULL, OPT_MONITOR }, /* Alternate config file location */ { "config", required_argument, NULL, OPT_CONFIGFILE }, /* Alternate phone section from the config */ { "phone", required_argument, NULL, OPT_CONFIGMODEL }, /* Get Security Code */ { "getsecuritycode", no_argument, NULL, OPT_GETSECURITYCODE }, /* Enter Security Code mode */ { "entersecuritycode", required_argument, NULL, OPT_ENTERSECURITYCODE }, /* Get Security Code status */ { "getsecuritycodestatus", no_argument, NULL, OPT_GETSECURITYCODESTATUS }, /* Change Security Code */ { "changesecuritycode", required_argument, NULL, OPT_CHANGESECURITYCODE }, /* Set date and time */ { "setdatetime", optional_argument, NULL, OPT_SETDATETIME }, /* Get date and time mode */ { "getdatetime", no_argument, NULL, OPT_GETDATETIME }, /* Set alarm */ { "setalarm", optional_argument, NULL, OPT_SETALARM }, /* Get alarm */ { "getalarm", no_argument, NULL, OPT_GETALARM }, /* Voice call mode */ { "dialvoice", required_argument, NULL, OPT_DIALVOICE }, /* Answer the incoming call */ { "answercall", required_argument, NULL, OPT_ANSWERCALL }, /* Hangup call */ { "hangup", required_argument, NULL, OPT_HANGUP }, /* Get ToDo note mode */ { "gettodo", required_argument, NULL, OPT_GETTODO }, /* Write ToDo note mode */ { "writetodo", required_argument, NULL, OPT_WRITETODO }, /* Delete all ToDo notes mode */ { "deletealltodos", no_argument, NULL, OPT_DELETEALLTODOS }, /* Get calendar note mode */ { "getcalendarnote", required_argument, NULL, OPT_GETCALENDARNOTE }, /* Write calendar note mode */ { "writecalendarnote", required_argument, NULL, OPT_WRITECALENDARNOTE }, /* Delete calendar note mode */ { "deletecalendarnote", required_argument, NULL, OPT_DELCALENDARNOTE }, /* Get display status mode */ { "getdisplaystatus", no_argument, NULL, OPT_GETDISPLAYSTATUS }, /* Get memory mode */ { "getphonebook", required_argument, NULL, OPT_GETPHONEBOOK }, /* Write phonebook (memory) mode */ { "writephonebook", optional_argument, NULL, OPT_WRITEPHONEBOOK }, /* Delete phonebook entry from memory mode */ { "deletephonebook", required_argument, NULL, OPT_DELETEPHONEBOOK }, /* Get speed dial mode */ { "getspeeddial", required_argument, NULL, OPT_GETSPEEDDIAL }, /* Set speed dial mode */ { "setspeeddial", required_argument, NULL, OPT_SETSPEEDDIAL }, /* Create SMS folder mode */ { "createsmsfolder", required_argument, NULL, OPT_CREATESMSFOLDER }, /* Delete SMS folder mode */ { "deletesmsfolder", required_argument, NULL, OPT_DELETESMSFOLDER }, /* Show SMS folder names and its attributes */ { "showsmsfolderstatus",no_argument, NULL, OPT_SHOWSMSFOLDERSTATUS }, /* Get SMS message mode */ { "getsms", required_argument, NULL, OPT_GETSMS }, /* Delete SMS message mode */ { "deletesms", required_argument, NULL, OPT_DELETESMS }, /* Send SMS message mode */ { "sendsms", required_argument, NULL, OPT_SENDSMS }, /* Ssve SMS message mode */ { "savesms", optional_argument, NULL, OPT_SAVESMS }, /* Send logo as SMS message mode */ { "sendlogo", required_argument, NULL, OPT_SENDLOGO }, /* Send ringtone as SMS message */ { "sendringtone", required_argument, NULL, OPT_SENDRINGTONE }, /* Get ringtone */ { "getringtone", required_argument, NULL, OPT_GETRINGTONE }, /* Set ringtone */ { "setringtone", required_argument, NULL, OPT_SETRINGTONE }, /* Play ringtone */ { "playringtone", required_argument, NULL, OPT_PLAYRINGTONE }, /* Convert ringtone */ { "ringtoneconvert", required_argument, NULL, OPT_RINGTONECONVERT }, /* Get list of the ringtones */ { "getringtonelist", no_argument, NULL, OPT_GETRINGTONELIST }, /* Delete ringtones */ { "deleteringtone", required_argument, NULL, OPT_DELETERINGTONE }, /* Get SMS center number mode */ { "getsmsc", optional_argument, NULL, OPT_GETSMSC }, /* Set SMS center number mode */ { "setsmsc", no_argument, NULL, OPT_SETSMSC }, /* For development purposes: run in passive monitoring mode */ { "pmon", no_argument, NULL, OPT_PMON }, /* NetMonitor mode */ { "netmonitor", required_argument, NULL, OPT_NETMONITOR }, /* Identify */ { "identify", no_argument, NULL, OPT_IDENTIFY }, /* Send DTMF sequence */ { "senddtmf", required_argument, NULL, OPT_SENDDTMF }, /* Resets the phone */ { "reset", required_argument, NULL, OPT_RESET }, /* Set logo */ { "setlogo", required_argument, NULL, OPT_SETLOGO }, /* Get logo */ { "getlogo", required_argument, NULL, OPT_GETLOGO }, /* View logo */ { "viewlogo", required_argument, NULL, OPT_VIEWLOGO }, /* Show profile */ { "getprofile", optional_argument, NULL, OPT_GETPROFILE }, /* Set profile */ { "setprofile", no_argument, NULL, OPT_SETPROFILE }, /* Get the active profile */ { "getactiveprofile", no_argument, NULL, OPT_GETACTIVEPROFILE }, /* Set the active profile */ { "setactiveprofile", required_argument, NULL, OPT_SETACTIVEPROFILE }, /* Show texts from phone's display */ { "displayoutput", no_argument, NULL, OPT_DISPLAYOUTPUT }, /* Simulate pressing the keys */ { "keysequence", no_argument, NULL, OPT_KEYPRESS }, /* Simulate pressing the keys */ { "enterchar", no_argument, NULL, OPT_ENTERCHAR }, /* Divert calls */ { "divert", no_argument, NULL, OPT_DIVERT }, /* SMS reader */ { "smsreader", no_argument, NULL, OPT_SMSREADER }, /* For development purposes: insert you function calls here */ { "foogle", no_argument, NULL, OPT_FOOGLE }, /* Get WAP bookmark */ { "getwapbookmark", required_argument, NULL, OPT_GETWAPBOOKMARK }, /* Write WAP bookmark */ { "writewapbookmark", required_argument, NULL, OPT_WRITEWAPBOOKMARK }, /* Delete WAP bookmark */ { "deletewapbookmark", required_argument, NULL, OPT_DELETEWAPBOOKMARK }, /* Get WAP setting */ { "getwapsetting", required_argument, NULL, OPT_GETWAPSETTING }, /* Write WAP setting */ { "writewapsetting", no_argument, NULL, OPT_WRITEWAPSETTING }, /* Activate WAP setting */ { "activatewapsetting", required_argument, NULL, OPT_ACTIVATEWAPSETTING }, /* List GSM networks */ { "listnetworks", no_argument, NULL, OPT_LISTNETWORKS }, /* Get network info */ { "getnetworkinfo", no_argument, NULL, OPT_GETNETWORKINFO }, /* Get (sim)lock info */ { "getlocksinfo", no_argument, NULL, OPT_GETLOCKSINFO }, /* Get file list */ { "getfilelist", required_argument, NULL, OPT_GETFILELIST }, /* Get file details by id */ { "getfiledetailsbyid", optional_argument, NULL, OPT_GETFILEDETAILSBYID }, /* Get file id */ { "getfileid", required_argument, NULL, OPT_GETFILEID }, /* Get file */ { "getfile", required_argument, NULL, OPT_GETFILE }, /* Get file by id */ { "getfilebyid", required_argument, NULL, OPT_GETFILEBYID }, /* Get all files */ { "getallfiles", required_argument, NULL, OPT_GETALLFILES }, /* Put a file */ { "putfile", required_argument, NULL, OPT_PUTFILE }, /* Delete a file */ { "deletefile", required_argument, NULL, OPT_DELETEFILE }, /* Delete a file by id */ { "deletefilebyid", required_argument, NULL, OPT_DELETEFILEBYID }, /* Shell like interface */ { "shell", no_argument, NULL, OPT_SHELL }, /* Get MMS message mode */ { "getmms", required_argument, NULL, OPT_GETMMS }, /* Delete MMS message mode */ { "deletemms", required_argument, NULL, OPT_DELETEMMS }, /* Check if the phone responds */ { "ping", no_argument, NULL, OPT_PING }, { 0, 0, 0, 0 }, }; /* Every command which requires arguments should have an appropriate entry in this array. */ static struct gnokii_arg_len gals[] = { { OPT_HELP, 1, 100, 0 }, { OPT_CONFIGFILE, 1, 100, 0 }, { OPT_CONFIGMODEL, 1, 100, 0 }, { OPT_ENTERSECURITYCODE, 1, 100, 0 }, { OPT_CHANGESECURITYCODE,1, 1, 0 }, { OPT_SETDATETIME, 0, 5, 0 }, { OPT_SETALARM, 0, 2, 0 }, { OPT_DIALVOICE, 1, 1, 0 }, { OPT_ANSWERCALL, 1, 1, 0 }, { OPT_HANGUP, 1, 1, 0 }, { OPT_GETTODO, 1, 3, 0 }, { OPT_WRITETODO, 2, 3, 0 }, { OPT_GETCALENDARNOTE, 1, 3, 0 }, { OPT_WRITECALENDARNOTE, 2, 3, 0 }, { OPT_DELCALENDARNOTE, 1, 2, 0 }, { OPT_GETPHONEBOOK, 2, 4, 0 }, { OPT_WRITEPHONEBOOK, 0, 10, 0 }, { OPT_DELETEPHONEBOOK, 2, 3, 0 }, { OPT_GETSPEEDDIAL, 1, 1, 0 }, { OPT_SETSPEEDDIAL, 3, 3, 0 }, { OPT_CREATESMSFOLDER, 1, 1, 0 }, { OPT_DELETESMSFOLDER, 1, 1, 0 }, { OPT_GETSMS, 2, 6, 0 }, { OPT_DELETESMS, 2, 3, 0 }, { OPT_SENDSMS, 1, 10, 0 }, { OPT_SAVESMS, 0, 12, 0 }, { OPT_SENDLOGO, 3, 4, GAL_XOR }, { OPT_SENDRINGTONE, 2, 2, 0 }, { OPT_GETSMSC, 0, 3, 0 }, { OPT_GETWELCOMENOTE, 1, 1, 0 }, { OPT_SETWELCOMENOTE, 1, 1, 0 }, { OPT_NETMONITOR, 1, 1, 0 }, { OPT_SENDDTMF, 1, 1, 0 }, { OPT_SETLOGO, 1, 4, 0 }, { OPT_GETLOGO, 1, 4, 0 }, { OPT_VIEWLOGO, 1, 1, 0 }, { OPT_GETRINGTONE, 1, 3, 0 }, { OPT_SETRINGTONE, 1, 5, 0 }, { OPT_PLAYRINGTONE, 1, 3, 0 }, { OPT_RINGTONECONVERT, 2, 2, 0 }, { OPT_DELETERINGTONE, 1, 2, 0 }, { OPT_RESET, 0, 1, 0 }, { OPT_GETPROFILE, 0, 3, 0 }, { OPT_SETACTIVEPROFILE, 1, 1, 0 }, { OPT_DIVERT, 6, 10, 0 }, { OPT_GETWAPBOOKMARK, 1, 1, 0 }, { OPT_WRITEWAPBOOKMARK, 2, 2, 0 }, { OPT_DELETEWAPBOOKMARK, 1, 1, 0 }, { OPT_GETWAPSETTING, 1, 2, 0 }, { OPT_ACTIVATEWAPSETTING,1, 1, 0 }, { OPT_MONITOR, 0, 1, 0 }, { OPT_GETFILELIST, 1, 1, 0 }, { OPT_GETFILEDETAILSBYID,0, 1, 0 }, { OPT_GETFILEID, 1, 1, 0 }, { OPT_GETFILE, 1, 2, 0 }, { OPT_GETFILEBYID, 1, 2, 0 }, { OPT_GETALLFILES, 1, 1, 0 }, { OPT_PUTFILE, 2, 2, 0 }, { OPT_DELETEFILE, 1, 1, 0 }, { OPT_DELETEFILEBYID, 1, 1, 0 }, { OPT_SHELL, 0, 0, 0 }, { OPT_GETMMS, 2, 6, 0 }, { OPT_DELETEMMS, 2, 3, 0 }, { OPT_FOOGLE, 0, 0, 0 }, { OPT_PING, 0, 0, 0 }, { 0, 0, 0, 0 }, }; /* Handle command line arguments. * -c equals to --config * -p equals to --phone */ c = getopt_long(argc, argv, "c:p:", long_options, &opt_index); switch (c) { /* No argument given - we should display usage. */ case -1: return usage(stderr, -1, NULL); /* First, error conditions */ case '?': case ':': /* --shell command does not set argv[0] */ if (argv[0]) fprintf(stderr, _("Use '%s --help' for usage information.\n"), argv[0]); else fprintf(stderr, _("Use '--help' for usage information.\n")); return 1; /* Then, options with no arguments */ case OPT_VERSION: version(); return 0; /* That's a bit ugly... */ case 'c': c = OPT_CONFIGFILE; opt_index = 0; break; case 'p': c = OPT_CONFIGMODEL; opt_index = 1; break; } /* We have to build an array of the arguments which will be passed to the functions. Please note that every text after the --command will be passed as arguments. A syntax like gnokii --cmd1 args --cmd2 args will not work as expected; instead args --cmd2 args is passed as a parameter. */ if (checkargs(c, gals, argc, long_options[opt_index].has_arg)) { return usage(stderr, -1, NULL); } /* Other options that do not need initialization */ switch (c) { case OPT_CONFIGFILE: if (configfile) return usage(stderr, -1, NULL); configfile = optarg; return parse_options(argc, argv); case OPT_CONFIGMODEL: if (configmodel) return usage(stderr, -1, NULL); configmodel = optarg; return parse_options(argc, argv); case OPT_HELP: return usage(stdout, argc, argv); case OPT_VIEWLOGO: return viewlogo(optarg); case OPT_LISTNETWORKS: list_gsm_networks(); return GN_ERR_NONE; case OPT_RINGTONECONVERT: return ringtoneconvert(argc, argv); } /* Initialise the code for the GSM interface. */ if (c != OPT_FOOGLE && state == NULL && businit()) return -1; switch (c) { /* Monitoring options */ case OPT_MONITOR: rc = monitormode(argc, argv, data, state); break; case OPT_GETDISPLAYSTATUS: rc = getdisplaystatus(data, state); break; case OPT_DISPLAYOUTPUT: rc = displayoutput(data, state); break; case OPT_NETMONITOR: rc = netmonitor(optarg, data, state); break; /* SMS options */ case OPT_SENDSMS: rc = sendsms(argc, argv, data, state); break; case OPT_SAVESMS: rc = savesms(argc, argv, data, state); break; case OPT_GETSMS: rc = getsms(argc, argv, data, state); break; case OPT_DELETESMS: rc = deletesms(argc, argv, data, state); break; case OPT_GETSMSC: rc = getsmsc(argc, argv, data, state); break; case OPT_SETSMSC: rc = setsmsc(data, state); break; case OPT_CREATESMSFOLDER: rc = createsmsfolder(optarg, data, state); break; case OPT_DELETESMSFOLDER: rc = deletesmsfolder(optarg, data, state); break; case OPT_SHOWSMSFOLDERSTATUS: rc = showsmsfolderstatus(data, state); break; case OPT_SMSREADER: rc = smsreader(data, state); break; /* Phonebook options */ case OPT_GETPHONEBOOK: rc = getphonebook(argc, argv, data, state); break; case OPT_WRITEPHONEBOOK: rc = writephonebook(argc, argv, data, state); break; case OPT_DELETEPHONEBOOK: rc = deletephonebook(argc, argv, data, state); break; /* Calendar options */ case OPT_GETCALENDARNOTE: rc = getcalendarnote(argc, argv, data, state); break; case OPT_WRITECALENDARNOTE: rc = writecalendarnote(argc, argv, data, state); break; case OPT_DELCALENDARNOTE: rc = deletecalendarnote(argc, argv, data, state); break; /* ToDo options */ case OPT_GETTODO: rc = gettodo(argc, argv, data, state); break; case OPT_WRITETODO: rc = writetodo(argc, argv, data, state); break; case OPT_DELETEALLTODOS: rc = deletealltodos(data, state); break; /* Dialling and call handling options */ case OPT_GETSPEEDDIAL: rc = getspeeddial(optarg, data, state); break; case OPT_SETSPEEDDIAL: rc = setspeeddial(argv, data, state); break; case OPT_DIALVOICE: rc = dialvoice(optarg, data, state); break; case OPT_SENDDTMF: rc = senddtmf(optarg, data, state); break; case OPT_ANSWERCALL: rc = answercall(optarg, data, state); break; case OPT_HANGUP: rc = hangup(optarg, data, state); break; case OPT_DIVERT: rc = divert(argc, argv, data, state); break; /* Profile options */ case OPT_GETPROFILE: rc = getprofile(argc, argv, data, state); break; case OPT_SETPROFILE: rc = setprofile(data, state); break; case OPT_GETACTIVEPROFILE: rc = getactiveprofile(data, state); break; case OPT_SETACTIVEPROFILE: rc = setactiveprofile(argc, argv, data, state); break; /* Phone settings options */ case OPT_RESET: rc = reset(optarg, data, state); break; case OPT_GETDATETIME: rc = getdatetime(data, state); break; case OPT_SETDATETIME: rc = setdatetime(argc, argv, data, state); break; case OPT_GETALARM: rc = getalarm(data, state); break; case OPT_SETALARM: rc = setalarm(argc, argv, data, state); break; /* WAP options */ case OPT_GETWAPBOOKMARK: rc = getwapbookmark(optarg, data, state); break; case OPT_WRITEWAPBOOKMARK: rc = writewapbookmark(argc, argv, data, state); break; case OPT_DELETEWAPBOOKMARK: rc = deletewapbookmark(optarg, data, state); break; case OPT_GETWAPSETTING: rc = getwapsetting(argc, argv, data, state); break; case OPT_WRITEWAPSETTING: rc = writewapsetting(data, state); break; case OPT_ACTIVATEWAPSETTING: rc = activatewapsetting(optarg, data, state); break; /* Logo options */ case OPT_SENDLOGO: rc = sendlogo(argc, argv, data, state); break; case OPT_SETLOGO: rc = setlogo(argc, argv, data, state); break; case OPT_GETLOGO: rc = getlogo(argc, argv, data, state); break; /* Ringtone options */ case OPT_SENDRINGTONE: rc = sendringtone(argc, argv, data, state); break; case OPT_GETRINGTONE: rc = getringtone(argc, argv, data, state); break; case OPT_SETRINGTONE: rc = setringtone(argc, argv, data, state); break; case OPT_PLAYRINGTONE: rc = playringtone(argc, argv, data, state); break; case OPT_GETRINGTONELIST: rc = getringtonelist(data, state); break; case OPT_DELETERINGTONE: rc = deleteringtone(argc, argv, data, state); break; /* Security options */ case OPT_IDENTIFY: rc = identify(state); break; case OPT_GETLOCKSINFO: rc = getlocksinfo(data, state); break; case OPT_GETSECURITYCODE: rc = getsecuritycode(data, state); break; case OPT_ENTERSECURITYCODE: rc = entersecuritycode(optarg, data, state); if (rc == GN_ERR_NONE && optind < argc) return parse_options(argc, argv); break; case OPT_GETSECURITYCODESTATUS: rc = getsecuritycodestatus(data, state); break; case OPT_CHANGESECURITYCODE: rc = changesecuritycode(optarg, data, state); break; /* File options */ case OPT_GETFILELIST: rc = getfilelist(optarg, data, state); break; case OPT_GETFILEDETAILSBYID: rc = getfiledetailsbyid(argc, argv, data, state); break; case OPT_GETFILEID: rc = getfileid(optarg, data, state); break; case OPT_GETFILE: rc = getfile(argc, argv, data, state); break; case OPT_GETFILEBYID: rc = getfilebyid(argc, argv, data, state); break; case OPT_GETALLFILES: rc = getallfiles(optarg, data, state); break; case OPT_PUTFILE: rc = putfile(argc, argv, data, state); break; case OPT_DELETEFILE: rc = deletefile(optarg, data, state); break; case OPT_DELETEFILEBYID: rc = deletefilebyid(optarg, data, state); break; /* Misc options */ case OPT_PMON: rc = pmon(data, state); break; case OPT_KEYPRESS: rc = presskeysequence(data, state); break; case OPT_ENTERCHAR: rc = enterchar(data, state); break; case OPT_GETNETWORKINFO: rc = getnetworkinfo(data, state); break; case OPT_SHELL: rc = shell(data, state); break; case OPT_PING: rc = ping(data, state); break; #ifndef WIN32 case OPT_FOOGLE: rc = foogle(argc, argv); break; #endif /* MMS options */ case OPT_GETMMS: rc = getmms(argc, argv, data, state); break; case OPT_DELETEMMS: rc = deletemms(argc, argv, data, state); break; default: rc = GN_ERR_FAILED; fprintf(stderr, _("Unknown option: %d\n"), c); break; } return rc; }