void updateWorkspaces(Fl_Widget*,void*) { bool showapplet; pGlobalConfig.get("Panel", "Workspaces", showapplet, true); if (!showapplet) { return; } mWorkspace->clear(); mWorkspace->begin(); char **names=0; int count = Fl_WM::get_workspace_count(); int names_count = Fl_WM::get_workspace_names(names); int current = Fl_WM::get_current_workspace(); for(int n=0; n<count; n++) { Fl_Item *i = new Fl_Item(); i->callback(setWorkspace, (long)n); i->type(Fl_Item::RADIO); if(n<names_count && names[n]) { i->label(names[n]); free(names[n]); } else { Fl_String tmp; i->label(tmp.printf(tmp, "%s %d", _("Workspace") ,n+1)); } if(current==n) i->set_value(); } // add a divider if there are no workspaces if (count<1) { new Fl_Menu_Divider(); } if(names) delete []names; mWorkspace->end(); }
void update_property_dialog(Icon *i) { Fl_String val; Fl_Config i_config(i->get_cfg()->filename()); i_config.set_section("Desktop Entry"); val = get_localized_name(i_config); if(!val.empty()) { pr_name->label(val); } if(!i_config.read("Exec", val, 0)) { pr_exec->label(val); } Fl_FileAttr *attr = fl_file_attr(i->get_cfg()->filename()); if(attr) { char size[32]; snprintf(size, 32, _("%d bytes, %s"), (int) attr->size, attr->time); pr_size->label(size); delete attr; } pr_icon->image(i->icon_im); }
EDEFont fl_font_dialog(EDEFont current_font) { EDEFont return_font; create_the_forms(); int numfonts = fl_list_fonts(all_fonts); // populate list of fonts Fl_String currentname = current_font.font->name(); for(int i = 0; i < numfonts; i++) { Fl_String fontname = all_fonts[i]->name(); fontobj->add(fontname); if (currentname.lower_case().pos(fontname.lower_case())==0) // it's a substring fontobj->value(i); } // set bold, italic if (currentname.pos(" bold italic") == currentname.length()-12) { bold_button->value(true); italic_button->value(true); } else if (currentname.pos(" italic") == currentname.length()-7) { italic_button->value(true); } else if (currentname.pos(" bold") == currentname.length()-5) { bold_button->value(true); } // populate other lists textobj->encoding = current_font.encoding; // TODO: what if we're using XFT? font_cb(fontobj,0); for (int i=0; i < sizeobj->children(); i++) { if (atoi(sizeobj->text(i)) == current_font.size) { sizeobj->value(i); size_cb(sizeobj,0); } } form->exec(); form->show(); // we have to construct a proper EDEFont to return return_font.defined = false; if (return_value) { return_font.font = fl_find_font(fontobj->text(fontobj->value())); if (bold_button->value()) return_font.font = return_font.font->bold(); if (italic_button->value()) return_font.font = return_font.font->italic(); int size = atoi(sizeobj->text(sizeobj->value())); return_font.size = find_best_size(return_font.font, size); // on XFT encoding is always Unicode, so this field can be blank if (encobj->children() > 0) return_font.encoding = encobj->text(encobj->value()); else return_font.encoding = ""; return_font.defined = true; } return return_font; }
void MainMenu::clear_favourites() { static Fl_String favourites; if(favourites.empty()) { favourites = fl_homedir(); favourites += "/.ede/favourites/"; if(!fl_file_exists(favourites)) { mkdir( favourites, 0777 ); } } dirent **files; int pNumFiles = fl_filename_list(favourites, &files); if (pNumFiles > 10) { for (int i=0; i<(pNumFiles-10); i++) { if (strcmp(files[i]->d_name, ".") != 0 && strcmp(files[i]->d_name, "..") != 0 ) { Fl_String filename(favourites); filename += files[i]->d_name; unlink(filename); } } } for(int i = 0; i < pNumFiles; i++) free(files[i]); if(pNumFiles && files) free(files); }
void clockRefresh(void *) { // Handle user's format preference Fl_String timestr = Fl_Date_Time::Now().time_string(); Fl_String timestrsec; Fl_String format; pGlobalConfig.get("Clock", "TimeFormat", format, ""); Fl_String seconds = timestr.sub_str(6, 2); Fl_String minutes = timestr.sub_str(3, 2); int hours = atoi(timestr.sub_str(0, 2)); if(format == "12") { if(hours > 12) { hours -= 12; } } timestr = Fl_String(hours) + ":" + minutes; timestrsec = timestr + ":" + seconds; mClockBox->label(timestr); strncpy(Fl_Date_Time::datePartsOrder, _("MDY"), 3); Fl_String pClockTooltip = Fl_Date_Time::Now().day_name() + ", "; pClockTooltip += Fl_Date_Time::Now().date_string() + ", " + timestrsec; mClockBox->tooltip(pClockTooltip); mClockBox->redraw(); Fl::add_timeout(1.0, clockRefresh); }
static void LaunchApp(char *name) { Fl_Config conf(fl_find_config_file("wmanager.conf", false)); Fl_String app; conf.get("Applications", name, app, NULL); if(! app.empty()) fl_start_child_process(app, false); }
double Fl_String::to_double(double defvalue) const { Fl_String t = trim(); if (!t.length()) return defvalue; double value = strtod(t.c_str(), NULL); if (errno == ERANGE) return defvalue; return value; }
float Fl_String::to_float(float defvalue) const { Fl_String t = trim(); if(!t.length()) return defvalue; float value = (float)strtod(t.c_str(), NULL); if(errno == ERANGE) return defvalue; return value; }
int Fl_String::to_int(int defvalue) const { Fl_String t = trim(); if (!t.length()) return defvalue; int value = strtol(t.c_str(), NULL, 10); if(errno == ERANGE) return defvalue; if(value == 0 && t != "0") return defvalue; return value; }
void saveSchemeAs() { const char *schemeName = fl_input(_("Save scheme as:"), _("New scheme")); if (schemeName) { Fl_String pathScheme; pathScheme.printf("%s/.ede/schemes/%s.scheme", fl_homedir().c_str(), schemeName); saveScheme(pathScheme); schemeListBox->add(fl_file_filename(pathScheme)); } }
// Start utility, like "time/date" or "volume" void startUtility(Fl_Button *, void *pName) { Fl_String value; pGlobalConfig.get("Panel", (char*)pName, value, ""); if(!pGlobalConfig.error() && !value.empty()) { value = "ede-launch \""+value; value += "\""; fl_start_child_process(value, false); } }
Fl_String Fl_String::operator + (const Fl_String& s) const { int len = length() + s.length(); char *temp = (char*)malloc(len+1); strncpy(temp, str_, length()); if(s.length()) strncpy(temp+length(), s.c_str(), s.length()); temp[len] = '\0'; Fl_String s1(temp, len, true); return s1; }
// update a string member: int storestring(const char *n, Fl_String& p, int nostrip) { if(!n) { p.clear(); return 0; } if(p==n) return 0; Fl_String N = n; if(!nostrip) p = N.trim(); else p = N; modflag = 1; return 1; }
// This function is now implemented in ede-launch void MainMenu::resolve_program(Fl_String cmd) { char pRun[FL_PATH_MAX]; snprintf(pRun, sizeof(pRun)-1, "ede-launch \"%s\"", cmd.c_str()); fl_start_child_process(pRun, false); }
// FONT STUFF: // returns nice name for a font Fl_String font_nice_name(EDEFont font) { if (!font.defined) return Fl_String("Unknown"); Fl_String nicename = font.font->name(); // capitalize bold, italic nicename.sub_replace("bold","Bold"); nicename.sub_replace("italic","Italic"); nicename = nicename + " ("; nicename = nicename + Fl_String(font.size); nicename = nicename + ")"; return nicename; }
Fl_String Fl_String::from_codeset(int conv_index, const char *str, int str_len) { if(str_len<=0) str_len = strlen(str); int outsize = str_len*3; char *outbuf = (char*)malloc(outsize); int len = fl_convert2utf(conv_index, (const uchar*)str, str_len, outbuf, outsize); Fl_String ret; if(len>0) ret.append(outbuf, len); //else ret.append(str, str_len); free(outbuf); return ret; }
const char *fl_font_change_attrib(const char *name, int word, const char *replace) { int att = font_word_pos(name, word); if(att==-1) return strdup(name); att++; int att_end = font_word_pos(name, word+1); if(att_end==-1) att_end = strlen(name); int len = att_end-att; Fl_String newname; newname.append(name, att); newname.append(replace, strlen(replace)); newname.append(name+att+len, strlen(name)-att_end); return strdup(newname.c_str()); }
Fl_String MainMenu::get_item_name(Fl_XmlNode *node) { Fl_String name; for(uint n=0; n<node->children(); n++) { Fl_XmlNode *np = node->child(n); if(np->is_element() && np->name()=="Name") { Fl_String &lang = np->get_attribute("Lang"); if(lang=="" && name.length()==0) { name.clear(); np->text(name); } else if(lang==locale()) { name.clear(); np->text(name); break; } } } return name; }
void update_iconeditdialog(Icon *i) { i_link->value(i->get_cfg()->filename()); Fl_Config &i_config = *i->get_cfg(); Fl_String val; i_config.set_section("Desktop Entry"); val = get_localized_name(i_config); if(!val.empty()) { i_name->value(val); } if(!i_config.read("Exec", val, 0)) { i_location->value(val); } if(!i_config.read("Icon", val, 0)) { i_filename->value(val); } }
void Fl_Led_Window::led_color(Fl_String col) { const char *color = strdup(col.c_str()); if (strcmp(color,"green") == 0) { color_index = FL_GREEN; return; } if (strcmp(color,"red") == 0) { color_index = FL_RED; return; } if (strcmp(color,"yellow") == 0) { color_index = FL_YELLOW; return; } }
void Fl_Type::read_property(const Fl_String &c) { if (!strcmp(c,"label")) label(read_word()); else if (!strcmp(c,"tooltip")) tooltip(read_word()); else if (!strcmp(c,"user_data")) user_data(read_word()); else if (!strcmp(c,"user_data_type")) user_data_type(read_word()); else if (!strcmp(c,"callback")) callback(read_word()); else if (!strcmp(c,"open")) open_ = 1; else if (!strcmp(c,"selected")) select(this,1); else read_error("Unknown property \"%s\"", c.c_str()); }
Fl_String get_localized_string() { Fl_String locale = setlocale(LC_MESSAGES, NULL); // int pos = locale.rpos('_'); // if(pos>0) locale.sub_delete(pos, locale.length()-pos); if(locale=="C" || locale=="POSIX") locale.clear(); Fl_String localName; if(locale.empty()) localName = "Name"; else localName.printf("Name[%s]", locale.c_str()); return localName; }
void go_callback(Fl_Widget *,void *) { header.clear(); content_len = 0; p_bar->range(0,1); p_bar->value(0); p_text->label("..."); textbuf->text(""); textdisp->redraw(); Fl_String host_name = input->value(); Fl_String page_name = "/index.html"; if(!strncmp(host_name, "http://", 7) || !strncmp(host_name, "HTTP://", 7)) { host_name.sub_delete(0, 7); } int pos = host_name.pos("/"); if (pos > 0) { page_name = host_name.sub_str(pos,255); host_name.set_length(pos); } try { sock->open(host_name,80); char host_header[256]; int len = sprintf(host_header,"GET %s HTTP/1.0\nHost: %s:80\n\n",page_name.c_str(),host_name.c_str()); sock->write(host_header, len); // Add socket to eFLTK socket lookup list Fl::add_fd(sock->handle(), FL_READ, socket_cb, sock); } catch(Fl_Exception &exception) { Fl::warning(exception.text()); return; } }
void parse_header(Fl_Buffer &buf) { if(!header.empty()) return; char *ptr = buf.data(); char *header_end = strstr(ptr, "\r\n\r\n"); if(header_end) { header = Fl_String(ptr, header_end-ptr); int hlen = header.length()+4; buf.set(buf.data()+hlen, buf.bytes()-hlen); printf("HEADER (%s)\n", header.c_str()); int pos = header.pos("Content-Length"); if(pos>-1) { pos += 15; int pos2 = header.pos("\r\n", pos); content_len = header.sub_str(pos, pos2-pos).to_int(); p_bar->range(0, content_len); } } }
void apply_colors_gtk(Fl_Color fg, Fl_Color bg, Fl_Color selection, Fl_Color selection_text, Fl_Color tooltip, Fl_Color tooltip_text, Fl_Color text, Fl_String font) { uchar r, g, b; uchar text_r, text_g, text_b; //, b1, r2, g2, b2; uchar selection_r, selection_g, selection_b; uchar selection_text_r, selection_text_g, selection_text_b; uchar tooltip_r, tooltip_g, tooltip_b; uchar tooltip_text_r, tooltip_text_g, tooltip_text_b; fl_get_color(bg, r, g, b); fl_get_color(fg, text_r, text_g, text_b); fl_get_color(selection, selection_r, selection_g, selection_b); fl_get_color(selection_text, selection_text_r, selection_text_g, selection_text_b); fl_get_color(tooltip, tooltip_r, tooltip_g, tooltip_b); fl_get_color(tooltip_text, tooltip_text_r, tooltip_text_g, tooltip_text_b); // fl_get_color(text, r2, g2, b2); Fl_String filePath(fl_homedir()); filePath += "/.gtkrc"; FILE *gtkFile = fopen(filePath.c_str(), "w"); fprintf(gtkFile, "style \"default\" \n"); fprintf(gtkFile, "{\n"); fprintf(gtkFile, "fontset = \"%s\" \n", font.c_str()); fprintf(gtkFile, "bg[NORMAL] = \"#%02X%02X%02X\"\n", r, g, b); fprintf(gtkFile, "fg[NORMAL] = \"#%02X%02X%02X\"\n", text_r, text_g, text_b); fprintf(gtkFile, "bg[PRELIGHT] = \"#%02X%02X%02X\"\n", r, g, b); fprintf(gtkFile, "fg[PRELIGHT] = \"#%02X%02X%02X\"\n", text_r, text_g, text_b); fprintf(gtkFile, "bg[ACTIVE] = \"#%02X%02X%02X\"\n", r, g, b); fprintf(gtkFile, "fg[ACTIVE] = \"#%02X%02X%02X\"\n", text_r, text_g, text_b); fprintf(gtkFile, "bg[SELECTED] = \"#%02X%02X%02X\"\n", selection_r, selection_g, selection_b); fprintf(gtkFile, "fg[SELECTED] = \"#%02X%02X%02X\"\n", selection_text_r, selection_text_g, selection_text_b); fprintf(gtkFile, "}\n"); fprintf(gtkFile, "style \"menu\" \n"); fprintf(gtkFile, "{\n"); fprintf(gtkFile, "bg[PRELIGHT] = \"#%02X%02X%02X\"\n", selection_r, selection_g, selection_b); fprintf(gtkFile, "fg[PRELIGHT] = \"#%02X%02X%02X\"\n", selection_text_r, selection_text_g, selection_text_b); fprintf(gtkFile, "}\n"); fprintf(gtkFile, "style \"tooltip\" \n"); fprintf(gtkFile, "{\n"); fprintf(gtkFile, "bg[NORMAL] = \"#%02X%02X%02X\"\n", tooltip_r, tooltip_g, tooltip_b); fprintf(gtkFile, "fg[NORMAL] = \"#%02X%02X%02X\"\n", tooltip_text_r, tooltip_text_g, tooltip_text_b); fprintf(gtkFile, "}\n"); fprintf(gtkFile, "class \"*\" style \"default\"\n"); fprintf(gtkFile, "widget_class \"*Menu*\" style \"menu\" \n"); fprintf(gtkFile, "widget \"gtk-tooltips\" style \"tooltip\" \n"); fclose(gtkFile); }
// 'Fl_FileBrowser::load()' - Load a directory into the browser. int // O - Number of files loaded Fl_File_Browser::load(const Fl_String &dir) // I - Directory to load { Fl_String old_dir(directory()); m_dir_ds.directory(dir); clear(); clear_columns(); sort_col(1); m_up_item = 0; if(dir.empty()) { header()->add_column("", 20); // No directory specified: // - For UNIX list all mount points. // - For Win32 list all valid drive letters. //icon = Fl_FileIcon::find("any", Fl_FileIcon::DEVICE); //if (icon == (Fl_FileIcon *)0) // icon = Fl_FileIcon::find("any", Fl_FileIcon::DIR); begin(); char filename[FL_PATH_MAX]; #ifdef _WIN32 header()->add_column(_("File"), 100); header()->add_column(_("Type"), 100); header()->add_column(_("Capacity"), 100); header()->add_column(_("Free Space"), 100); // Drive available bits DWORD drives = GetLogicalDrives(); for(int i = 'A'; i <= 'Z'; i ++, drives >>= 1) { if (drives & 1) { Fl_ListView_Item *item = new Fl_ListView_Item(); item->image(&hd_pix); snprintf(filename, sizeof(filename)-1, "%c:\\", i); item->label(1, filename); Fl_File_Attr *attr = fl_file_attr(filename); if(attr->flags & Fl_File_Attr::DEVICE) { uint type = GetDriveTypeA(filename); const char *typestr=_(types[0]); if (type==DRIVE_CDROM) { typestr=_(types[4]); item->image(&cd_pix); } else if (type==DRIVE_REMOVABLE) { typestr=_(types[5]); item->image(&floppy_pix); } else if (type==DRIVE_FIXED) typestr=_(types[6]); else if (type==DRIVE_REMOTE) typestr=_(types[7]); else if (type==DRIVE_RAMDISK) typestr=_(types[8]); item->label(2, typestr); uint s = 0; Fl_String suffix; if((s = get_dev_size(attr->capacity, suffix))>0) { item->label(3, Fl_String(s)+" "+suffix); } if((s = get_dev_size(attr->free, suffix))>0) { item->label(4, Fl_String(s)+" "+suffix); } /* //TOO SLOW!!! char drivename[255]; if(GetVolumeInformation( filename, drivename, sizeof(drivename)-1, NULL, NULL, NULL, NULL, 0)) { if(drivename[0]) snprintf(fname, sizeof(fname)-1, "%s (%s)", filename, drivename); } */ } } } #else header()->add_column(_("File"), 100); header()->add_column(_("Device"), 100); header()->add_column(_("Type"), 100); FILE *mtab = 0; // /etc/mtab or /etc/mnttab file char line[1024]; // Input line char dev[256]; // Device name char fstype[256]; // Filesystem type // Open the file that contains a list of mounted filesystems... # if defined(__hpux) || defined(__sun) // Fairly standard mtab = fl_fopen("/etc/mnttab", "r"); # elif defined(__sgi) || defined(linux) // More standard mtab = fl_fopen("/etc/mtab", "r"); # endif // Otherwise fallback to full list if(mtab == NULL) mtab = fl_fopen("/etc/fstab", "r"); if(mtab == NULL) mtab = fl_fopen("/etc/vfstab", "r"); if (mtab != NULL) { while (fgets(line, sizeof(line), mtab) != NULL) { if (line[0] == '#' || line[0] == '\n') continue; if (sscanf(line, "%255s%4095s%255s", dev, filename, fstype) != 3) continue; if(!strcasecmp(dev, "none")) continue; Fl_ListView_Item *item = new Fl_ListView_Item(); item->image(&hd_pix); item->label(1, filename); item->label(2, dev); item->label(3, fstype); } fclose(mtab); } #endif // _WIN32 end(); resizable_col(0, false); return children(); } else {
Fl_String Fl_String::trim() const { Fl_String s = trim_right(); return s.trim_left(); }
Fl_String Fl_String::from_codeset(Fl_String codeset, const char *str, int str_len) { return Fl_String::from_codeset(fl_find_converter(codeset.c_str()), str, str_len); }
void Fl_Query::sql(const Fl_String& _sql) { // Looking up for SQL parameters Fl_String paramName; char delimitter[] = " "; char delimitters[] = "'\":'"; char *s = strdup(_sql.c_str()); char *paramStart = s; char *paramEnd; int paramNumber = 0; for (unsigned i = 0; i < m_params.count(); i++) { Fl_Param& param = m_params[i]; param.bind_clear(); } Fl_String odbcSQL = ""; bool endOfString; for (;;) { paramEnd = strpbrk(paramStart,delimitters); if ( !paramEnd ) { odbcSQL += paramStart; break; } *delimitter = *paramEnd; if (*paramEnd == ':') { if (paramEnd != s && isalnum(*(paramEnd-1)) ) { *paramEnd = char(0); odbcSQL += paramStart; odbcSQL += ":"; paramStart = paramEnd + 1; continue; } if (paramEnd[1] == ':') { paramEnd++; *paramEnd = char(0); odbcSQL += paramStart; paramStart = paramEnd + 1; continue; } } if ( *paramEnd == '\'' || *paramEnd == '"' ) { paramEnd = strpbrk(paramEnd + 1,delimitter); if ( !paramEnd ) { break; // Unmatched quotes } *paramEnd = char(0); odbcSQL += paramStart; odbcSQL += delimitter; paramStart = paramEnd + 1; continue; } *paramEnd = char(0); odbcSQL += paramStart; paramStart = paramEnd + 1; delimitter[0] = 0; char *ptr = paramStart; for (; *ptr; ptr++) { char c = *ptr; if ( c == '_' ) continue; if (!isalnum(c)) { delimitter[0] = c; break; } } paramEnd = ptr; endOfString = (*paramEnd == 0); *paramEnd = char(0); if (ptr != paramStart) { //Fl_Param *param; int index = m_params.param_index(paramStart); if ( index == -1 ) { theParam = new Fl_Param(paramStart); m_params.add(theParam); } else { theParam = &m_params[index]; } theParam->bind_add(paramNumber); paramNumber++; odbcSQL += "?"; odbcSQL += delimitter; } else { odbcSQL += ":"; } paramStart = paramEnd + 1; if (endOfString) break; } free(s); for (int p = m_params.count() - 1; p >= 0; p--) if (!m_params[p].bind_count()) m_params.remove(p); if (m_sql != odbcSQL) { m_sql = odbcSQL; if (m_database) { if ( active() ) close(); free_stmt(); } } }