Example #1
0
/*
  Display Help/Version
  returns true if application may exit
  TODO expand to all possible options
*/
static bool gm_display_help(int argc,char * argv[]) {
  for (int i=1;i<argc;i++){
    if ( (comparecase(argv[i],"--help")==0) || (comparecase(argv[i],"-h")==0) ) {
      fxmessage("Usage: %s [options]\n\n",FXPath::name(argv[0]).text());
      fxmessage("General options:\n"
                " -h, --help            Display this help page\n"
                " -v, --version         Display version information\n"
                "     --tray            Start minimized to tray\n"
#ifdef HAVE_OPENGL
                "     --disable-opengl  Disables opengl based features\n"
#endif
                "\n"
                "Control running music manager:\n"
                "     --play            Start playback\n"
                "     --play-pause      Toggle pause / playback.\n"
                "     --pause           Pause playback\n"
                "     --previous        Play previous track\n"
                "     --next            Play next track\n"
                "     --stop            Stop playback\n"
                "     --raise           Try to raise the main window\n"
                "     --toggle-shown    Show or Hide the main window\n"
                "     --now-playing     Show now playing notification\n"
                "\n"
                );
      return true;
      }
    else if ( (comparecase(argv[i],"--version")==0) || (comparecase(argv[i],"-v")==0) ) {
      fxmessage("Goggles Music Manager %s\n",APPLICATION_VERSION_STRING);
      return true;
      }
    }
  return false;
  }
Example #2
0
long GMNotifyDaemon::onNotifyCapabilities(FXObject*,FXSelector,void*ptr){
  DBusMessage * msg = static_cast<DBusMessage*>(ptr);
  FXchar ** caps = NULL;
  int ncaps;
  if ((dbus_message_get_type(msg)==DBUS_MESSAGE_TYPE_METHOD_RETURN) && dbus_message_get_args(msg,NULL,DBUS_TYPE_ARRAY,DBUS_TYPE_STRING,&caps,&ncaps,DBUS_TYPE_INVALID)) {
    FXbool has_action_icons=false;
    FXbool has_actions=false;
    FXbool has_persistence=false;

    for (FXint i=0;i<ncaps;i++){
      GM_DEBUG_PRINT("caps[%d]=%s\n",i,caps[i]);
      if (flags&ACTION_ITEMS) {
        if (comparecase(caps[i],"actions")==0)
          has_actions=true;
        else if ((comparecase(caps[i],"action-icons")==0) || (comparecase(caps[i],"x-gnome-icon-buttons")==0))
          has_action_icons=true;
        else if (comparecase(caps[i],"persistence")==0)
          has_persistence=true;
        }
      }

    if (has_actions && has_action_icons && has_persistence) {
      persistent=true;
      reset();
      }

    // Need to delete array of strings returned by dbus_message_get_args
    dbus_free_string_array(caps);
    }
  return 1;
  }
Example #3
0
FXint ASXParser::begin(const FXchar * element,const FXchar ** attributes){
  switch(elem) {
    case Elem_None:
      {
        if (comparecase(element,"asx")==0) {
          elem=Elem_ASX;
          return 1;
          }
      } break;
    case Elem_ASX:
      {
        if (comparecase(element,"entry")==0) {
          elem=Elem_ASX_Entry;
          return 1;
          }
      } break;
    case Elem_ASX_Entry:
      {
        if (comparecase(element,"ref")==0) {
          elem=Elem_ASX_Entry_Ref;
          for (FXint i=0;attributes[i];i+=2){
            if (comparecase(attributes[i],"href")==0) {
              files.append(FXString(attributes[i+1]));
              }
            }
          return 1;
          }
      } break;
    default: return 0; // skip
    }
  return 0;
  }
Example #4
0
// Parse emacs modeline
FXbool Modeline::parseEmacsModeline(const FXchar* s){
  FXString key;
  FXString val;
  while(*s!='\0'){
    while(*s==';' || *s=='\t' || *s==' ') s++;
    if(*s=='\0' || (*s=='-' && *(s+1)=='*' && *(s+2)=='-')) break;
    key=FXString::null;
    val=FXString::null;
    while(*s!='\0' && *s!=':' && *s!=';' && *s!='\t' && *s!=' '){
      key+=*s++;
      }
    while(*s=='\t' || *s==' ') s++;
    if(*s=='\0') break;
    if(*s!=':') continue;
    s++;
    while(*s=='\t' || *s==' ') s++;
    if(*s=='\0') break;
    while(*s!='\0' && *s!=';' &&  *s!='\t' && *s!=' '){
      val+=*s++;
      }
    if(comparecase(key,"Mode")==0){
      setLanguage(val);
      }
    else if(key=="tab-width"){
      setTabWidth(val.toInt());
      }
    else if(key=="indent-tabs-mode"){
      setTabMode(val=="nil");
      }
    else if(key=="autowrap"){
      setWrapMode(val!="nil");
      }
    }
  return true;
  }
Example #5
0
void
MFXImageHelper::checkSupported(FXString ext) {
    if (comparecase(ext, "png") == 0) {
        if (!FXPNGImage::supported) {
            throw InvalidArgument("Fox was compiled without png support!");
        }
    } else if (comparecase(ext, "jpg") == 0 || comparecase(ext, "jpeg") == 0) {
        if (!FXJPGImage::supported) {
            throw InvalidArgument("Fox was compiled without jpg support!");
        }
    } else if (comparecase(ext, "tif") == 0 || comparecase(ext, "tiff") == 0) {
        if (!FXTIFImage::supported) {
            throw InvalidArgument("Fox was compiled without tif support!");
        }
    }
}
Example #6
0
static inline FXbool begins_with_keyword(const FXString & t){
  const FXStringList & keywords = GMPlayerManager::instance()->getPreferences().gui_sort_keywords;
  for (FXint i=0;i<keywords.no();i++){
    if (comparecase(t,keywords[i],keywords[i].length())==0) return true;
    }
  return false;
  }
Example #7
0
void ID3V2::parse_rva2_frame(FXint framesize) {
  if (framesize>6) {
    FXbool is_track_gain=false;
    if (comparecase((const FXchar*)buffer+p,"track\0",6)==0) {
      is_track_gain=true;
      }
    else if (comparecase((const FXchar*)buffer+p,"album\0",6)) {
      return;
      }

    p+=6;
    framesize-=6;

    while(framesize) {
      const FXuchar & type = buffer[p];
      FXdouble        gain = (double)(((signed char)(buffer[p+1]) << 8) | buffer[p+2]) / 512.0;
      const FXuchar & bits = buffer[p+3];
      FXdouble        peak = 0.0;
      FXint nbytes         = (bits+7) / 8;
      if (type==1) {
        if (bits>0)  {
          peak+=buffer[p+4];
          if (bits>8) {
            peak+=buffer[p+5] / 256.0;
            if (bits>16) {
              peak+=buffer[p+6] / 65536.0;
              }
            }
          peak = peak / (double)(1<<((bits-1)&7));
          }
        if (is_track_gain) {
          replaygain.track = gain;
          }
        else {
          replaygain.album = gain;
          }
        break;
        }
      p+=4+nbytes;
      framesize-=4+nbytes;
      }
    }
  }
int main(int ac, char*av[]) {
  char*a,*b;
  puts("\teq , ne , gt , lt , ge , le");
  while (0 < (ac -= 2)) {
    a = *++av, b = *++av;
    compare(a, b);
    comparecase(a, b);
  }
  return 0;
}
Example #9
0
long GMNotifyDaemon::onNotifyServer(FXObject*,FXSelector,void*ptr){
  DBusMessage * msg = static_cast<DBusMessage*>(ptr);
  const FXchar * dname=NULL;
  const FXchar * vendor=NULL;
  const FXchar * version=NULL;
  const FXchar * spec=NULL;

  if ((dbus_message_get_type(msg)==DBUS_MESSAGE_TYPE_METHOD_RETURN) && dbus_message_get_args(msg,NULL,DBUS_TYPE_STRING,&dname,DBUS_TYPE_STRING,&vendor,DBUS_TYPE_STRING,&version,DBUS_TYPE_STRING,&spec,DBUS_TYPE_INVALID)) {

    if (compareversion(spec,"1.1")==0) {
      icondata="image_data";
      }
    else if (compareversion(spec,"1.2")>=0) {
      icondata="image-data";
      }
    else {
      icondata="icon_data";
      }

    if (comparecase(vendor,"xfce")==0 && comparecase(dname,"xfce notify daemon")==0) {
      flags|=IMAGE_WITHOUT_APPICON;
      }

    if (comparecase(dname,"gnome-shell")==0 && comparecase(vendor,"gnome")==0) {
      GMPlayerManager::instance()->getPreferences().gui_tray_icon_disabled=true;
      flags|=ACTION_ITEMS;
      if (compareversion(version,"3.2.0")<0){
        flags|=IMAGE_WITHOUT_APPICON;
        }
      }
#ifdef DEBUG
    fxmessage("name: %s\n",dname);
    fxmessage("vendor: %s\n",vendor);
    fxmessage("version: %s\n",version);
    fxmessage("spec: %s\n",spec);
    fxmessage("icondata: %s\n",icondata.text());
    fxmessage("flags: %x\n",flags);
#endif
    }

  GMPlayerManager::instance()->update_tray_icon();
  return 1;
  }
Example #10
0
FXbool AliasDialog::commandExist(const FXString &command)
{
    StringIt it;
    for(it=m_aliases.begin(); it!=m_aliases.end(); it++)
    {
        if(!comparecase((*it).first, command)) return TRUE;
    }
    if(utils::instance().isCommand(command[0]=='/' ? command.after('/') : command)) return TRUE;
    return FALSE;
}
Example #11
0
// Obtain file path from URI specified as file:///bla/bla/bla...
// If no 'file:' prefix is found, return the input string as is
FXString fileFromURI(FXString uri)
{
	if(comparecase("file:",uri,5)==0)
	{
		if(uri[5]==PATHSEPCHAR && uri[6]==PATHSEPCHAR)
			return uri.mid(7,uri.length()-7);
		return uri.mid(5,uri.length()-5);
	}

	return uri;
}
Example #12
0
long AliasDialog::onModify(FXObject*, FXSelector, void*)
{
    FXint row = m_table->getCurrentItem();
    FXString oldkey = m_table->getItemText(row).before('\t');
    FXDialogBox aliasEdit(this, _("Alias edit"), DECOR_TITLE|DECOR_BORDER, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    FXVerticalFrame *contents = new FXVerticalFrame(&aliasEdit, LAYOUT_SIDE_LEFT|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0, 10, 10, 10, 10, 0, 0);
    FXMatrix *matrix = new FXMatrix(contents, 2, MATRIX_BY_COLUMNS|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y);
    new FXLabel(matrix, _("Alias:"), NULL, JUSTIFY_LEFT|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
    FXTextField *alias = new FXTextField(matrix, 25, NULL, 0, FRAME_THICK|FRAME_SUNKEN|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
    alias->setText(oldkey);
    new FXLabel(matrix, _("Command:"), NULL, JUSTIFY_LEFT|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
    FXTextField *command = new FXTextField(matrix, 25, NULL, 0, FRAME_THICK|FRAME_SUNKEN|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
    command->setText(m_table->getItemText(row).after('\t'));

    FXHorizontalFrame *buttonframe = new FXHorizontalFrame(contents, LAYOUT_FILL_X|LAYOUT_FILL_Y|PACK_UNIFORM_WIDTH);
    new dxEXButton(buttonframe, _("&Cancel"), NULL, &aliasEdit, FXDialogBox::ID_CANCEL, FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT, 0, 0, 0, 0, 10, 10, 2, 2);
    new dxEXButton(buttonframe, _("&OK"), NULL, &aliasEdit, FXDialogBox::ID_ACCEPT, BUTTON_INITIAL|BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT, 0, 0, 0, 0, 10, 10, 2, 2);

    if(aliasEdit.execute(PLACEMENT_OWNER))
        {
        if(alias->getText().empty() || command->getText().empty())
            return 1;
        if(alias->getText()[0] != '/')
        {
            dxEXMessageBox::information(this, MBOX_OK, _("Information"), _("Alias command has to start with '/'"));
            return 1;
        }
        if(alias->getText().contains(' '))
        {
            dxEXMessageBox::information(this, MBOX_OK, _("Information"), _("Alias command cann't contain space"));
            return 1;
        }
        if(commandExist(alias->getText()) && comparecase(alias->getText(), oldkey))
        {
            dxEXMessageBox::information(this, MBOX_OK, _("Information"), _("Command '%s' already exist"), alias->getText().text());
            return 1;
        }
        m_aliases.erase(oldkey);
        m_aliases.insert(StringPair(alias->getText(), command->getText()));
        updateTable();
    }
    return 1;
}
Example #13
0
FXint fxexecute(FXString link) {
#ifdef WIN32
    FXString quoted = FXPath::enquote(link);
    FXint ret =
        (int)ShellExecute(NULL,"open",quoted.text(),NULL,NULL,SW_SHOW) > 32;
    return ret;
#else
    FXString ext = FXPath::extension(link);
    FXString list;
    if (comparecase(link.section(':',0), "http")==0 ||
            comparecase(link.section(':',0), "ftp")==0 ||
            comparecase(ext, "htm")==0 || comparecase(ext, "html")==0 ||
            comparecase(ext, "php")==0 || comparecase(ext, "asp")==0)
        list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx";
    else if (comparecase(ext, "pdf")==0)
        list = "acroread\tkghostview\tgpdf\txpdf";

    if (list.length()) {
        FXString software;
        FXint index=0;
        FXString path = FXSystem::getExecPath();

        software = list.section("\t",index);
        while (!software.empty()) {
            software = FXPath::search(path, software);
            if (software.length())
                return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ",
                                                software.text(),link.text()).text())>0?0:1;
            index++;
            software = list.section("\t",index);
        }
    } else if (FXStat::isExecutable(link))
        return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0:1;
    return 0;
#endif
}
Example #14
0
FXImage*
MFXImageHelper::loadImage(FXApp* a, const std::string& file) {
    FXString ext = FXPath::extension(file.c_str());
    checkSupported(ext);
    FXImage* img = NULL;
    if (comparecase(ext, "gif") == 0) {
        img = new FXGIFImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "bmp") == 0) {
        img = new FXBMPImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "xpm") == 0) {
        img = new FXXPMImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "pcx") == 0) {
        img = new FXPCXImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "ico") == 0 || comparecase(ext, "cur") == 0) {
        img = new FXICOImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "tga") == 0) {
        img = new FXTGAImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "rgb") == 0) {
        img = new FXRGBImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "xbm") == 0) {
        img = new FXXBMImage(a, NULL, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "png") == 0) {
        img = new FXPNGImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "jpg") == 0 || comparecase(ext, "jpeg") == 0) {
        img = new FXJPGImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else if (comparecase(ext, "tif") == 0 || comparecase(ext, "tiff") == 0) {
        img = new FXTIFImage(a, NULL, IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP);
    } else {
        throw InvalidArgument("Unknown file extension '" + toString(ext.text()) + "' for image '" + file + "'!");
    }

    FXFileStream stream;
    if (img != NULL && stream.open(file.c_str(), FXStreamLoad)) {
        a->beginWaitCursor();
        img->loadPixels(stream);
        stream.close();

        img->create();
        a->endWaitCursor();
    } else {
        delete img;
        throw InvalidArgument("Loading failed!");
    }
    return img;
}
Example #15
0
ReaderPlugin* ReaderPlugin::open(AudioEngine * engine,FXuint type) {
  switch(type){
    case Format::WAV      : return ap_wav_reader(engine); break;
#ifdef HAVE_OGG_PLUGIN
    case Format::OGG      : return ap_ogg_reader(engine); break;
#endif
#ifdef HAVE_FLAC_PLUGIN
    case Format::FLAC     : return ap_flac_reader(engine); break;
#endif
#ifdef HAVE_MAD_PLUGIN
    case Format::MP3      : return ap_mad_reader(engine); break;
#endif
#ifdef HAVE_AAC_PLUGIN
    case Format::AAC      : return ap_aac_reader(engine); break;
#endif
#ifdef HAVE_MP4_PLUGIN
    case Format::MP4      : return ap_mp4_reader(engine); break;
#endif
#ifdef HAVE_MUSEPACK_PLUGIN
    case Format::Musepack : return ap_musepack_reader(engine); break;
#endif
#ifdef HAVE_WAVPACK_PLUGIN
    case Format::WavPack  : return ap_wavpack_reader(engine); break;
#endif
#ifdef HAVE_CDDA_PLUGIN
    case Format::CDDA     : return ap_cdda_reader(engine); break;
#endif
    case Format::M3U      : return ap_m3u_reader(engine); break;
    case Format::PLS      : return ap_pls_reader(engine); break;
    case Format::XSPF     : return ap_xspf_reader(engine); break;

#ifdef HAVE_AVC_PLUGIN
    case Format::ASX      : return ap_asx_reader(engine); break;
    case Format::ASF      : return ap_asf_reader(engine); break;
    case Format::ASFX     : {

    FXchar buffer[1024];
    FXival nbuffer=0;
    nbuffer=engine->input->preview(buffer,1024);
    if (nbuffer>0) {
//      fxmessage("got preview buffer of %d\n",nbuffer);
//      fxmessage("%s\n",buffer);
      if (comparecase(buffer,"<ASX",4)==0)
        return ap_asx_reader(engine);
      else
        return ap_asf_reader(engine);
      }

                            }

#endif
    case Format::AIFF      : return ap_aiff_reader(engine); break;






//    case Format::MP3      : return ap_avf_reader(engine); break;
    default               : return NULL; break;
    }
  return NULL;
  }
Example #16
0
FXint genre_list_sort_reverse(const FXListItem* pa,const FXListItem* pb){
  return -comparecase(pa->getText(),pb->getText());
  }
Example #17
0
// smell: yellow (the save functions may have additional options, not regarded)
// Save file
FXbool
MFXImageHelper::saveImage(const std::string& file,
                          int width, int height, FXColor* data) {
    FXString ext = FXPath::extension(file.c_str());
    checkSupported(ext);
    FXFileStream stream;
    if (!stream.open(file.c_str(), FXStreamSave)) {
        throw InvalidArgument("Could not open file for writing!");
    }
    if (comparecase(ext, "gif") == 0) {
        return fxsaveGIF(stream, data, width, height, false /* !!! "fast" */);
    } else if (comparecase(ext, "bmp") == 0) {
        return fxsaveBMP(stream, data, width, height);
    } else if (comparecase(ext, "xpm") == 0) {
        return fxsaveXPM(stream, data, width, height);
    } else if (comparecase(ext, "pcx") == 0) {
        return fxsavePCX(stream, data, width, height);
    } else if (comparecase(ext, "ico") == 0 || comparecase(ext, "cur") == 0) {
        return fxsaveICO(stream, data, width, height);
    } else if (comparecase(ext, "tga") == 0) {
        return fxsaveTGA(stream, data, width, height);
    } else if (comparecase(ext, "rgb") == 0) {
        return fxsaveRGB(stream, data, width, height);
    } else if (comparecase(ext, "xbm") == 0) {
        return fxsaveXBM(stream, data, width, height);
    } else if (comparecase(ext, "png") == 0) {
        return fxsavePNG(stream, data, width, height);
    } else if (comparecase(ext, "jpg") == 0 || comparecase(ext, "jpeg") == 0) {
        return fxsaveJPG(stream, data, width, height, 75);
    } else if (comparecase(ext, "tif") == 0 || comparecase(ext, "tiff") == 0) {
        return fxsaveTIF(stream, data, width, height, 0);
    }
    throw InvalidArgument("Unknown file extension for image!");
}
Example #18
0
FXint generic_name_sort_reverse(const FXListItem* pa,const FXListItem* pb){
  FXint a=0,b=0;
  if (begins_with_keyword(pa->getText())) a=FXMIN(pa->getText().length()-1,pa->getText().find(' ')+1);
  if (begins_with_keyword(pb->getText())) b=FXMIN(pb->getText().length()-1,pb->getText().find(' ')+1);
  return comparecase(&pb->getText()[b],&pa->getText()[a]);
  }
Example #19
0
// Note : the original function from FXAccelTable is buggy!!
// Parse accelerator from string
FXHotKey _parseAccel(const FXString& string)
{
	register FXuint code=0,mods=0;
	register FXint pos=0;

	// Parse leading space
	while(pos<string.length() && Ascii::isSpace(string[pos]))
		pos++;

	// Parse modifiers
	while(pos<string.length())
	{
		// Modifier
		if(comparecase(&string[pos],"ctl",3)==0)
		{
			mods|=CONTROLMASK;
			pos+=3;
		}
		else if(comparecase(&string[pos],"ctrl",4)==0)
		{
			mods|=CONTROLMASK;
			pos+=4;
		}
		else if(comparecase(&string[pos],"alt",3)==0)
		{
			mods|=ALTMASK;
			pos+=3;
		}
		else if(comparecase(&string[pos],"meta",4)==0)
		{
			mods|=METAMASK;
			pos+=4;
		}
		else if(comparecase(&string[pos],"shift",5)==0)
		{
			mods|=SHIFTMASK;
			pos+=5;
		}
		else
			break;

		// Separator
		if(string[pos]=='+' || string[pos]=='-' || Ascii::isSpace(string[pos]))
			pos++;
	}

	// Test for some special keys
	if(comparecase(&string[pos],"home",4)==0)
		code=KEY_Home;
	else if(comparecase(&string[pos],"end",3)==0)
		code=KEY_End;
	else if(comparecase(&string[pos],"pgup",4)==0)
		code=KEY_Page_Up;
	else if(comparecase(&string[pos],"pgdn",4)==0)
		code=KEY_Page_Down;
	else if(comparecase(&string[pos],"left",4)==0)
		code=KEY_Left;
	else if(comparecase(&string[pos],"right",5)==0)
		code=KEY_Right;
	else if(comparecase(&string[pos],"up",2)==0)
		code=KEY_Up;
	else if(comparecase(&string[pos],"down",4)==0)
		code=KEY_Down;
	else if(comparecase(&string[pos],"ins",3)==0)
		code=KEY_Insert;
	else if(comparecase(&string[pos],"del",3)==0)
		code=KEY_Delete;
	else if(comparecase(&string[pos],"esc",3)==0)
		code=KEY_Escape;
	else if(comparecase(&string[pos],"tab",3)==0)
		code=KEY_Tab;
	else if(comparecase(&string[pos],"return",6)==0)
		code=KEY_Return;
	else if(comparecase(&string[pos],"enter",5)==0)
		code=KEY_Return;
	else if(comparecase(&string[pos],"back",4)==0)
		code=KEY_BackSpace;
	else if(comparecase(&string[pos],"spc",3)==0)
		code=KEY_space;
	else if(comparecase(&string[pos],"space",5)==0)
		code=KEY_space;

	// Test for function keys
	else if(Ascii::toLower(string[pos])=='f' && Ascii::isDigit(string[pos+1]))
	{
		if(Ascii::isDigit(string[pos+2]))
		{			
			// !!!! Hack to fix a bug in FOX !!!!
			code=KEY_F1+10*(string[pos+1]-'0')+(string[pos+2]-'0')-1;
			// !!!! End of hack !!!!
		}
		else
			code=KEY_F1+string[pos+1]-'1';
	}
	// Test if hexadecimal code designator
	else if(string[pos]=='#')
		code=strtoul(&string[pos+1],NULL,16);

	// Test if its a single character accelerator
	else if(Ascii::isPrint(string[pos]))
	{
		if(mods&SHIFTMASK)
			code=Ascii::toUpper(string[pos])+KEY_space-' ';
		else
			code=Ascii::toLower(string[pos])+KEY_space-' ';
	}
	return MKUINT(code,mods);
}
Example #20
0
FXbool HttpClient::basic(const FXchar*    method,
                         FXString         url,
                         const FXString & header,
                         const FXString & content,
                         FXString*        moved/*=nullptr*/) {

  int redirect = 0;

  if (request(method,url,header,content)) {
    do {
      switch(parse()) {
        case HTTP_RESPONSE_INFORMATIONAL:
          {
            if (status.code==HTTP_CONTINUE) {
              continue;
              }
            break;
          }
        case HTTP_RESPONSE_REDIRECT     :
          {
            // 304 - Document not changed. We're done
            // 305 - Need to use a proxy. Currently not handled
            // 306 - Unused
            if (status.code==HTTP_NOT_MODIFIED || status.code==HTTP_USE_PROXY || status.code==HTTP_306)
              return true;

            url = getHeader("location");

            // No url given, done here
            if (url.empty())
              return false;

            // Prevent infinite redirects
            if (redirect>10)
              return false;      

            // Save moved url (only on first permanent redirect)
            if (status.code==HTTP_MOVED_PERMANENTLY && redirect==0 && moved) {
              *moved=url;
              }
            // Don't do automatic redirections for non GET/HEAD requests
            if (comparecase(method,"GET") && comparecase(method,"HEAD"))
              return true;

            if (!request(method,url,header,content)) {
              return false;
              }
            redirect++;
            continue;
            break;
          }
        case HTTP_RESPONSE_CLIENT_ERROR  :
          {
            if (status.code==HTTP_UNAUTHORIZED) {

              FXString user     = FXURL::username(url);
              FXString password = FXURL::password(url);

              if (user.empty() || password.empty())
                return true;

              FXString challenge = getHeader("www-authenticate");

              if (comparecase(challenge,"basic",5)==0) {
                FXString auth = "Authorization: Basic " + Base64Encoder::encodeString(user+":"+password) + "\r\n";

                if (!request(method,url,header+auth,content)) {
                  return false;
                  }
                continue;
                }
//              else if (comparecase(challenge,"digest",6)==0){
//                FXASSERT(0);
//                }
              }
          } break;

        case HTTP_RESPONSE_FAILED:  /* something went wrong */
          {
            GM_DEBUG_PRINT("[http] response failed\n");
            return false;
            break;
          }
        default: break;
        }
      return true;
      }
    while(1);
    }
  return false;
  }