Example #1
0
static void gmsplit(const FXString & in,FXStringList & output) {
  FXint s=0;
  FXint e=0;
  FXint n=0;
  const FXchar sep=',';

  while(s<in.length()) {

    // trim leading white space
    while(in[s]==' ') s++;

    e=s;

    // find end
    while(in[e]!=sep && in[e]!='\0') e++;

    n=e+1;
    e=e-1;

    // trim end
    while(e>=s && in[e]==' ') e--;

    if (e>=s) {
      output.no(output.no()+1);
      output[output.no()-1].assign(&in[s],(e-s)+1);
      }
    s=n;
    }
  }
Example #2
0
void GMSyncTask::update() {
  GMTrackFilenameList tracklist;
  FXStringList        pathlist;
  FXStat              data;

  database->beginTask();

  taskmanager->setStatus("Updating Files..");

  for (FXint i=0;i<files.no() && processing;i++) {

    database->getPathList(files[i],pathlist);

    for (FXint p=0;p<pathlist.no() && processing;p++) {

      const FXString & path  = pathlist[p];

      if (!options.exclude_folder.empty() && filter_path(options.exclude_folder,path))
        continue;

      const FXint path_index = dbtracks.hasPath(path);

      database->getFileList(path,tracklist);

      for (FXint t=0;t<tracklist.no() && processing;t++) {

        const FXString & name = tracklist[t].filename;

        if (options.exclude_file.empty() || !FXPath::match(name,options.exclude_file,matchflags)) {
          if (FXStat::statFile(path+PATHSEPSTRING+name,data)) {
            if (data.isReadable())
              parse_update(path,name,options_sync.update_always ? forever : data.modified(),path_index);
            else
              parse_update(path,name,0,path_index);
            }
          else if (options_sync.remove_missing) {
            dbtracks.remove(tracklist[t].id);
            changed=true;
            }
          }
        }
      if (processing) update_tracks(path_index);
      }
    }
  if (changed) {
    database->sync_album_year();
    database->sync_tracks_removed();
    }
  database->commitTask();
  }
Example #3
0
void InputThread::ctrl_open_inputs(const FXStringList & urls){
  for (FXint i=0;i<urls.no();i++){
    GM_DEBUG_PRINT("[input] ctrl_open_inputs[%d] %s\n",i,urls[i].text());
    if (urls[i].empty()) continue;

    /// Open Input
    input=open_input(urls[i]);
    if (input==NULL) {
      if (aborted()) break;
      continue;
      }

    /// Open Reader
    reader = open_reader();
    if (reader==NULL) continue;

    if (!reader->init(input))
      continue;

    streamid++;
    set_state(StateProcessing,true);
    return;
    }
  ctrl_close_input();
  set_state(StateIdle,true);
  }
Example #4
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 #5
0
void GMDBTracks::insertTags(FXint track,const FXStringList & tags){
  FXIntList ids(tags.no());

  for (int i=0;i<tags.no();i++) {
    ids[i]=0;
    query_tag.execute(tags[i],ids[i]);
    if (ids[i]==0)
      ids[i] = insert_tag.insert(tags[i]);
    }

  for (FXint i=0;i<ids.no();i++) {
    insert_track_tag.set(0,track);
    insert_track_tag.set(1,ids[i]);
    insert_track_tag.execute();
    }
  }
Example #6
0
void ap_parse_pls(const FXString & data,FXStringList & mrl) {
  FXint start=0,end=0,pos,next;
  for (FXint i=0;i<data.length();i++) {
    if (data[i]=='\n') {
      end=i;
      next=i+1;

      /// Skip white space
      while(start<end && Ascii::isSpace(data[start])) start++;

      /// Skip white space
      while(end>start && Ascii::isSpace(data[end])) end--;

      /// Parse the actual line.
      if ((end-start)>6) {
        if (compare(&data[start],"File",4)==0) {
          pos = data.find('=',start+4);
          if (pos==-1) continue;
          pos++;
          if (end-pos>0) {
            mrl.append(data.mid(pos,1+end-pos));
            }
          }
        }
      start=next;
      }
    }
  }
Example #7
0
void GMDBTracks::updateTags(FXint track,const FXStringList & tags){
  /// Remove current tags
  delete_track_tags.update(track);

  /// Insert new tags
  if (tags.no())
    insertTags(track,tags);
  }
Example #8
0
ReadStatus ASXReader::process(Packet*packet) {
  if (TextReader::process(packet)==ReadDone) {
    gm_parse_asx(textbuffer,uri);
    if (uri.no())
      return ReadRedirect;
    else
      return ReadDone;
    }
  return ReadError;
  }
Example #9
0
void GMSyncTask::remove_missing() {
  FXStringList        pathlist;
  GMTrackFilenameList tracklist;

  database->beginTask();

  taskmanager->setStatus("Clearing Files..");

  for (FXint i=0;i<files.no() && processing;i++) {

    database->getPathList(files[i],pathlist);

    for (FXint p=0;p<pathlist.no() && processing;p++) {

      if (!options.exclude_folder.empty() && filter_path(options.exclude_folder,pathlist[p]))
        continue;

      database->getFileList(pathlist[p],tracklist);

      for (FXint t=0;t<tracklist.no() && processing;t++) {

        const FXString & name = tracklist[t].filename;

        if (database->interrupt)
          database->waitTask();

        if (options.exclude_file.empty() || !FXPath::match(name,options.exclude_file,matchflags)) {
          if (options_sync.remove_all || !FXStat::exists(pathlist[p]+PATHSEPSTRING+name)){
            dbtracks.remove(tracklist[t].id);
            changed=true;
            }
          }
        }
      }
    }
  if (changed) database->sync_tracks_removed();
  database->commitTask();
  }
Example #10
0
FXint GMRenameTask::run() {
  try {
    for (FXint i=0;i<from.no() && processing;i++) {
      if (to[i].empty()) continue;
      if (!FXDir::createDirectories(FXPath::directory(to[i]))) continue;
      if (FXStat::exists(to[i])) continue;
      if (FXFile::moveFiles(from[i],to[i])){
        database->setTrackFilename(tracks[i],to[i]);
        }
      }
    }
  catch(GMDatabaseException&) {
    GM_DEBUG_PRINT("Database Exception\n");
    }
  return 0;
  }
Example #11
0
static FXbool updateTrackFilenames(GMTrackDatabase * db,FXIntList & tracks) {
  register FXint i=0;
  FXint numchanges=0;
  FXString url;
  GMTrack trackinfo;
  FXStringList newurls;
  FXStringList oldurls;

  if (!GMPlayerManager::instance()->getPreferences().export_format_template.contains("%T")) {
    FXMessageBox::error(GMPlayerManager::instance()->getMainWindow(),MBOX_OK,fxtr("Invalid Template"),fxtr("The provided template is invalid. The track title %%T needs to be specified.\nPlease fix the filename template in the preference panel."));
    return false;
    }

  FXTextCodec * codec = GMFilename::findcodec(GMPlayerManager::instance()->getPreferences().export_encoding);
  FXuint options=0;

  if (GMPlayerManager::instance()->getPreferences().export_lowercase)
    options|=GMFilename::LOWERCASE;

  if (GMPlayerManager::instance()->getPreferences().export_lowercase_extension)
    options|=GMFilename::LOWERCASE_EXTENSION;

  if (GMPlayerManager::instance()->getPreferences().export_underscore)
    options|=GMFilename::NOSPACES;

  /// Create New Mrls.
  for (i=0;i<tracks.no();i++) {
    db->begin();
    if (!db->getTrack(tracks[i],trackinfo)) {
      db->commit();
      FXMessageBox::error(GMPlayerManager::instance()->getMainWindow(),MBOX_OK,fxtr("Database Error"),fxtr("Oops. Database Error"));
      return true;
      }
    db->commit();
    if (GMFilename::create(url,trackinfo,GMPlayerManager::instance()->getPreferences().export_format_template,GMPlayerManager::instance()->getPreferences().export_character_filter,options,codec) && url!=trackinfo.url) {
      newurls.append(url);
      oldurls.append(trackinfo.url);
      numchanges++;
      }
    else {
      newurls.append(FXString::null);
      oldurls.append(FXString::null);
      }
    }

  if (numchanges==0){
    FXMessageBox::information(GMPlayerManager::instance()->getMainWindow(),MBOX_OK,fxtr("No changes"),fxtr("Filenames did not require any changes"));
    delete codec;
    return false;
    }


  /// Ask For Permission
  FXDialogBox dialog(GMPlayerManager::instance()->getMainWindow(),fxtr("Rename Audio Files?"),DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE|DECOR_CLOSE,0,0,600,400,0,0,0,0,0,0);
  GMPlayerManager::instance()->getMainWindow()->create_dialog_header(&dialog,fxtr("Renaming Audio Files…"),fxtr("The following audio files are going to be renamed"));

  FXHorizontalFrame *closebox=new FXHorizontalFrame(&dialog,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,0,0,0,0);
  new GMButton(closebox,fxtr("&Rename"),NULL,&dialog,FXDialogBox::ID_ACCEPT,BUTTON_INITIAL|BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK,0,0,0,0, 15,15);
  new GMButton(closebox,fxtr("&Cancel"),NULL,&dialog,FXDialogBox::ID_CANCEL,BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK,0,0,0,0, 15,15);

  FXVerticalFrame * main = new FXVerticalFrame(&dialog,LAYOUT_FILL_X|LAYOUT_FILL_Y);

  GMScrollFrame * sunken = new GMScrollFrame(main);
  GMList * list = new GMList(sunken,NULL,0,LAYOUT_FILL_X|LAYOUT_FILL_Y);

  for (i=0;i<tracks.no();i++) {
    if (!newurls[i].empty()) {
      list->appendItem(newurls[i]);
      }
    }





  if (dialog.execute()) {

    GMRenameTask * task = new GMRenameTask(db,tracks,newurls,oldurls);
//    task->setTarget(GMPlayerManager::instance()->getTrackView()->getSource());
 //   task->setSelector(

    GMPlayerManager::instance()->runTask(task);
/*

    for (i=0;i<tracks.no();i++){
      if (!newmrls[i].empty()) {
        if (gm_make_path(FXPath::directory(newmrls[i]))) {
          if (!FXStat::exists(newmrls[i])) {
            if (FXFile::rename(oldmrls[i],newmrls[i])){
              db->setTrackFilename(tracks[i],newmrls[i]);
              }
            else {
              if (i+1<tracks.no()) {
                if (FXMessageBox::error(GMPlayerManager::instance()->getMainWindow(),MBOX_YES_NO,fxtr("Unable to rename file"),fxtrformat("Unable to rename:\n%s\n\nto:%s\nContinue renaming files?"),oldmrls[i].text(),newmrls[i].text())==MBOX_CLICKED_NO)
                  break;
                }
              else {
                FXMessageBox::error(GMPlayerManager::instance()->getMainWindow(),MBOX_OK,fxtr("Unable to rename file"),fxtrformat("Unable to rename:\n%s\n\nto:%s"),oldmrls[i].text(),newmrls[i].text());
                }
              }
            }
          }
        }
      }
*/
    return true;
    }
  delete codec;
  return false;
  }
Example #12
0
static FXbool updateTrackFilenames(GMTrackDatabase * db,FXIntList & tracks) {
  FXint i=0;
  FXint numchanges=0;
  FXString url;
  GMTrack trackinfo;
  FXStringList newurls;
  FXStringList oldurls;

  if (!GMPlayerManager::instance()->getPreferences().export_format_template.contains("%T")) {
    FXMessageBox::error(GMPlayerManager::instance()->getMainWindow(),MBOX_OK,fxtr("Invalid Template"),fxtr("The provided template is invalid. The track title %%T needs to be specified.\nPlease fix the filename template in the preference panel."));
    return false;
    }

  const FXTextCodec * const codec = ap_get_usercodec(GMPlayerManager::instance()->getPreferences().export_encoding);
  FXuint options=0;

  if (GMPlayerManager::instance()->getPreferences().export_lowercase)
    options|=gm::TrackFormatter::LOWERCASE;

  if (GMPlayerManager::instance()->getPreferences().export_lowercase_extension)
    options|=gm::TrackFormatter::LOWERCASE_EXTENSION;

  if (GMPlayerManager::instance()->getPreferences().export_underscore)
    options|=gm::TrackFormatter::NOSPACE;

  gm::TrackFormatter trackformat(GMPlayerManager::instance()->getPreferences().export_format_template,
                                 codec,
                                 GMPlayerManager::instance()->getPreferences().export_character_filter,
                                 options);

  try {
    GMLockTransaction transaction(db);

    /// Create New Mrls.
    for (i=0;i<tracks.no();i++) {
      if (!db->getTrack(tracks[i],trackinfo)) {
        FXMessageBox::error(GMPlayerManager::instance()->getMainWindow(),MBOX_OK,fxtr("Database Error"),fxtr("Oops. Database Error"));
        return true;
        }
      url = trackformat.getPath(trackinfo);
      if (!url.empty() && url!=trackinfo.url) {
        newurls.append(url);
        oldurls.append(trackinfo.url);
        numchanges++;
        }
      else {
        newurls.append(FXString::null);
        oldurls.append(FXString::null);
        }
      }
    }
  catch(GMDatabaseException&) {
    FXMessageBox::error(GMPlayerManager::instance()->getMainWindow(),MBOX_OK,fxtr("Database Error"),fxtr("Failed to retrieve track filenames"));
    return false;
    }

  if (numchanges==0){
    FXMessageBox::information(GMPlayerManager::instance()->getMainWindow(),MBOX_OK,fxtr("No changes"),fxtr("Filenames did not require any changes"));
    return false;
    }


  /// Ask For Permission
  FXDialogBox dialog(GMPlayerManager::instance()->getMainWindow(),fxtr("Rename Audio Files?"),DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE|DECOR_CLOSE,0,0,600,400,0,0,0,0,0,0);
  GMPlayerManager::instance()->getMainWindow()->create_dialog_header(&dialog,fxtr("Renaming Audio Files…"),fxtr("The following audio files are going to be renamed"));

  FXHorizontalFrame *closebox=new FXHorizontalFrame(&dialog,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,0,0,0,0);
  new GMButton(closebox,fxtr("&Rename"),nullptr,&dialog,FXDialogBox::ID_ACCEPT,BUTTON_INITIAL|BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK,0,0,0,0, 15,15);
  new GMButton(closebox,fxtr("&Cancel"),nullptr,&dialog,FXDialogBox::ID_CANCEL,BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK,0,0,0,0, 15,15);

  FXVerticalFrame * main = new FXVerticalFrame(&dialog,LAYOUT_FILL_X|LAYOUT_FILL_Y);

  GMScrollFrame * sunken = new GMScrollFrame(main);
  GMList * list = new GMList(sunken,nullptr,0,LAYOUT_FILL_X|LAYOUT_FILL_Y);

  for (i=0;i<tracks.no();i++) {
    if (!newurls[i].empty()) {
      if (codec && codec->mibEnum()!=106) {
        // Not UTF8 or Ascii
        // Translate back to UTF-8
        list->appendItem(codec->mb2utf(newurls[i]));
        }
      else {
        list->appendItem(newurls[i]);
        }
      }
    }
  if (dialog.execute()) {
    GMRenameTask * task = new GMRenameTask(db,tracks,newurls,oldurls);
    GMPlayerManager::instance()->runTask(task);
    return true;
    }
  return false;
  }
Example #13
0
FXbool ASXReader::init(InputPlugin*plugin) {
  TextReader::init(plugin);
  uri.clear();
  return true;
  }