void WmdmDevice::Init() { InitBackendDirectory("/", first_time_, false); model_->Init(); loader_ = new WmdmLoader(app_->task_manager(), backend_, shared_from_this()); loader_->moveToThread(loader_thread_); connect(loader_, SIGNAL(Error(QString)), SIGNAL(Error(QString))); connect(loader_, SIGNAL(TaskStarted(int)), SIGNAL(TaskStarted(int))); connect(loader_, SIGNAL(LoadFinished()), SLOT(LoadFinished())); connect(loader_thread_, SIGNAL(started()), loader_, SLOT(LoadDatabase())); loader_thread_->start(); db_busy_.lock(); }
void WmdmLoader::LoadDatabase() { int task_id = task_manager_->StartTask(tr("Loading Windows Media device")); emit TaskStarted(task_id); boost::scoped_ptr<WmdmThread> thread(new WmdmThread); // Get the device's canonical name boost::shared_ptr<WmdmDevice> connected_device = boost::static_pointer_cast<WmdmDevice>(device_); WmdmLister* lister = static_cast<WmdmLister*>(connected_device->lister()); QString canonical_name = lister->DeviceCanonicalName(connected_device->unique_id()); IWMDMStorage* storage = thread->GetRootStorage(canonical_name); QStringList path_components; RecursiveExploreStorage(storage, &path_components); storage->Release(); thread.reset(); // Need to remove all the existing songs in the database first backend_->DeleteSongs(backend_->FindSongsInDirectory(1)); // Add the songs we've just loaded backend_->AddOrUpdateSongs(songs_); task_manager_->SetTaskFinished(task_id); emit LoadFinished(); }
void MtpLoader::LoadDatabase() { int task_id = task_manager_->StartTask(tr("Loading MTP device")); emit TaskStarted(task_id); TryLoad(); moveToThread(original_thread_); task_manager_->SetTaskFinished(task_id); emit LoadFinished(); }
void GPodLoader::LoadDatabase() { int task_id = task_manager_->StartTask(tr("Loading iPod database")); emit TaskStarted(task_id); // Load the iTunes database GError* error = nullptr; Itdb_iTunesDB* db = itdb_parse(QDir::toNativeSeparators(mount_point_).toLocal8Bit(), &error); // Check for errors if (!db) { if (error) { qLog(Error) << "loading database failed:" << error->message; emit Error(QString::fromUtf8(error->message)); g_error_free(error); } else { emit Error(tr("An error occurred loading the iTunes database")); } task_manager_->SetTaskFinished(task_id); return; } // Convert all the tracks from libgpod structs into Song classes const QString prefix = path_prefix_.isEmpty() ? QDir::fromNativeSeparators(mount_point_) : path_prefix_; SongList songs; for (GList* tracks = db->tracks; tracks != nullptr; tracks = tracks->next) { Itdb_Track* track = static_cast<Itdb_Track*>(tracks->data); Song song; song.InitFromItdb(track, prefix); song.set_directory_id(1); if (type_ != Song::Type_Unknown) song.set_filetype(type_); songs << song; } // Need to remove all the existing songs in the database first backend_->DeleteSongs(backend_->FindSongsInDirectory(1)); // Add the songs we've just loaded backend_->AddOrUpdateSongs(songs); moveToThread(original_thread_); task_manager_->SetTaskFinished(task_id); emit LoadFinished(db); }
void cStructLoaderPlain::Load(bool reload) { if(SL_TSTFLAG(SL_DISABLED) || reload) return; FILE *f=fopen(path,"r"); if(f) { PreLoad(); ListLock(true); SL_SETFLAG(SL_LOADED); PRINTF(L_GEN_INFO,"loading %s from %s",type,path); CheckAccess(); int lineNum=0; char buff[4096]; while(fgets(buff,sizeof(buff),f)) { lineNum++; if(!index(buff,'\n') && !feof(f)) { PRINTF(L_GEN_ERROR,"file %s readbuffer overflow line#%d",path,lineNum); SL_CLRFLAG(SL_LOADED); break; } strreplace(buff,'\n',0); strreplace(buff,'\r',0); // chomp bool hasContent=false; char *ls; for(ls=buff; *ls; ls++) { if(*ls==';' || *ls=='#') break; if(*ls>' ') hasContent=true; } if(hasContent) { *ls=0; if(!ParseLinePlain(skipspace(buff))) PRINTF(L_GEN_ERROR,"file %s has error in line #%d",path,lineNum); } } ListUnlock(); PostLoad(); fclose(f); LoadFinished(); } else OpenFailed(); }
void cStructLoader::Load(bool reload) { if(SL_TSTFLAG(SL_DISABLED) || (reload && !SL_TSTFLAG(SL_WATCH))) return; FILE *f=fopen(path,"r"); if(f) { PreLoad(); int curr_mtime=MTime(true); ListLock(true); bool doload=false; if(!reload) { Clear(); Modified(false); mtime=curr_mtime; doload=true; } else if(mtime<curr_mtime) { PRINTF(L_CORE_LOAD,"detected change of %s",path); if(IsModified()) PRINTF(L_CORE_LOAD,"discarding in-memory changes"); for(cStructItem *a=First(); a; a=Next(a)) DelItem(a); Modified(false); mtime=curr_mtime; doload=true; } if(doload) { SL_SETFLAG(SL_LOADED); PRINTF(L_GEN_INFO,"loading %s from %s",type,path); CheckAccess(); int lineNum=0, num=0; char buff[4096]; while(fgets(buff,sizeof(buff),f)) { lineNum++; if(!index(buff,'\n') && !feof(f)) { PRINTF(L_GEN_ERROR,"file %s readbuffer overflow line#%d",path,lineNum); SL_CLRFLAG(SL_LOADED); break; } strreplace(buff,'\n',0); strreplace(buff,'\r',0); // chomp bool hasContent=false; char *ls; for(ls=buff; *ls; ls++) { if(*ls==';' || *ls=='#') { // comment if(hasContent) while(ls>buff && ls[-1]<=' ') ls--; // search back to non-whitespace break; } if(*ls>' ') hasContent=true; // line contains something usefull } cStructItem *it=0; if(hasContent) { char save=*ls; *ls=0; it=ParseLine(skipspace(buff)); *ls=save; if(!it) { PRINTF(L_GEN_ERROR,"file %s has error in line #%d",path,lineNum); ls=buff; } else num++; } else ls=buff; if(!it) it=new cCommentItem; if(it) { it->SetComment(ls); Add(it); } else { PRINTF(L_GEN_ERROR,"out of memory loading file %s",path); SL_CLRFLAG(SL_LOADED); break; } } ListUnlock(); PRINTF(L_CORE_LOAD,"loaded %d %s from %s",num,type,path); PostLoad(); } else ListUnlock(); fclose(f); LoadFinished(); } else OpenFailed(); }