void Scanner_Worker::runScan(int steps, int accuracy) { ScanRunning = true; for(int i = 0; i <= steps; i++) { if(ScanRunning == false) break; Data->mutex.lock(); if(Data->number >= accuracy) { qDebug() << "Current emitted data: Step: " << i << " and counts: " << Data->counts << " and current pos: " << ((qreal)i)/((qreal)steps)*100; emit currentData(qMakePair(i, Data->counts)); emit moveStep(); emit currentPosition(((qreal)i)/((qreal)steps)*100); Data->counts = 0; Data->number = 0; Data->mutex.unlock(); } else { Data->WaitCond.wait(&(Data->mutex)); Data->mutex.unlock(); i--; } } emit ScanFinished(); }
void EkgScan::imageReady() { scanImage = QImage("scan.tiff"); QTransform imageCorrector; imageCorrector = imageCorrector.rotate(90); scanImage = scanImage.transformed(imageCorrector,Qt::SmoothTransformation); scanImage.save("scan.png"); emit ScanFinished(); }
void SubsonicLibraryScanner::OnGetAlbumFinished(QNetworkReply* reply) { reply->deleteLater(); pending_requests_.remove(reply); QXmlStreamReader reader(reply); reader.readNextStartElement(); Q_ASSERT(reader.name() == "subsonic-response"); if (reader.attributes().value("status") != "ok") { // TODO: error handling return; } // Read album information reader.readNextStartElement(); Q_ASSERT(reader.name() == "album"); QString album_artist = reader.attributes().value("artist").toString(); // Read song information while (reader.readNextStartElement()) { Q_ASSERT(reader.name() == "song"); Song song; QString id = reader.attributes().value("id").toString(); song.set_title(reader.attributes().value("title").toString()); song.set_album(reader.attributes().value("album").toString()); song.set_track(reader.attributes().value("track").toString().toInt()); song.set_disc(reader.attributes().value("discNumber").toString().toInt()); song.set_artist(reader.attributes().value("artist").toString()); song.set_albumartist(album_artist); song.set_bitrate(reader.attributes().value("bitRate").toString().toInt()); song.set_year(reader.attributes().value("year").toString().toInt()); song.set_genre(reader.attributes().value("genre").toString()); qint64 length = reader.attributes().value("duration").toString().toInt(); length *= kNsecPerSec; song.set_length_nanosec(length); QUrl url = QUrl(QString("subsonic://%1").arg(id)); song.set_url(url); song.set_filesize(reader.attributes().value("size").toString().toInt()); // We need to set these to satisfy the database constraints song.set_directory_id(0); song.set_mtime(0); song.set_ctime(0); songs_ << song; reader.skipCurrentElement(); } // Start the next request if albums remain if (!album_queue_.empty()) { GetAlbum(album_queue_.dequeue()); } // If this was the last response, we're done! if (album_queue_.empty() && pending_requests_.empty()) { scanning_ = false; emit ScanFinished(); } }
SubsonicService::SubsonicService(Application* app, InternetModel* parent) : InternetService(kServiceName, app, parent, parent), network_(new QNetworkAccessManager(this)), url_handler_(new SubsonicUrlHandler(this, this)), scanner_(new SubsonicLibraryScanner(this, this)), load_database_task_id_(0), context_menu_(NULL), root_(NULL), library_backend_(NULL), library_model_(NULL), library_filter_(NULL), library_sort_model_(new QSortFilterProxyModel(this)), total_song_count_(0), login_state_(LoginState_OtherError), redirect_count_(0) { app_->player()->RegisterUrlHandler(url_handler_); connect(scanner_, SIGNAL(ScanFinished()), SLOT(ReloadDatabaseFinished())); library_backend_ = new LibraryBackend; library_backend_->moveToThread(app_->database()->thread()); library_backend_->Init(app_->database(), kSongsTable, QString::null, QString::null, kFtsTable); connect(library_backend_, SIGNAL(TotalSongCountUpdated(int)), SLOT(UpdateTotalSongCount(int))); library_model_ = new LibraryModel(library_backend_, app_, this); library_model_->set_show_various_artists(false); library_model_->set_show_smart_playlists(false); library_filter_ = new LibraryFilterWidget(0); library_filter_->SetSettingsGroup(kSettingsGroup); library_filter_->SetLibraryModel(library_model_); library_filter_->SetFilterHint(tr("Search Subsonic")); library_filter_->SetAgeFilterEnabled(false); library_sort_model_->setSourceModel(library_model_); library_sort_model_->setSortRole(LibraryModel::Role_SortText); library_sort_model_->setDynamicSortFilter(true); library_sort_model_->setSortLocaleAware(true); library_sort_model_->sort(0); connect(this, SIGNAL(LoginStateChanged(SubsonicService::LoginState)), SLOT(OnLoginStateChanged(SubsonicService::LoginState))); context_menu_ = new QMenu; context_menu_->addActions(GetPlaylistActions()); context_menu_->addSeparator(); context_menu_->addAction( IconLoader::Load("view-refresh"), tr("Refresh catalogue"), this, SLOT(ReloadDatabase())); QAction* config_action = context_menu_->addAction( IconLoader::Load("configure"), tr("Configure Subsonic..."), this, SLOT(ShowConfig())); context_menu_->addSeparator(); context_menu_->addMenu(library_filter_->menu()); library_filter_->AddMenuAction(config_action); app_->global_search()->AddProvider(new LibrarySearchProvider( library_backend_, tr("Subsonic"), "subsonic", QIcon(":/providers/subsonic.png"), true, app_, this)); }
void SubsonicLibraryScanner::ParsingError(const QString& message) { qLog(Warning) << "Subsonic parsing error: " << message; scanning_ = false; emit ScanFinished(); }
void SubsonicLibraryScanner::OnGetAlbumListFinished(QNetworkReply* reply, int offset) { reply->deleteLater(); bool skip_read_albums = false; QXmlStreamReader reader(reply); reader.readNextStartElement(); if (reader.name() != "subsonic-response") { ParsingError("Not a subsonic-response. Aborting scan."); return; } if (reader.attributes().value("status") != "ok") { reader.readNextStartElement(); int error = reader.attributes().value("code").toString().toInt(); // Compatibility with Ampache : // When there is no data, Ampache returns NotFound // whereas Subsonic returns empty albumList2 tag switch (error) { case SubsonicService::ApiError_NotFound: skip_read_albums = true; break; default: ParsingError("Response status not ok. Aborting scan."); return; } } int albums_added = 0; if (!skip_read_albums) { reader.readNextStartElement(); if (reader.name() != "albumList2") { ParsingError("albumList2 tag expected. Aborting scan."); return; } while (reader.readNextStartElement()) { if (reader.name() != "album") { ParsingError("album tag expected. Aborting scan."); return; } album_queue_ << reader.attributes().value("id").toString(); albums_added++; reader.skipCurrentElement(); } } if (albums_added > 0) { // Non-empty reply means potentially more albums to fetch GetAlbumList(offset + kAlbumChunkSize); } else if (album_queue_.size() == 0) { // Empty reply and no albums means an empty Subsonic server scanning_ = false; emit ScanFinished(); } else { // Empty reply but we have some albums, time to start fetching songs // Start up the maximum number of concurrent requests, finished requests get // replaced with new ones for (int i = 0; i < kConcurrentRequests && !album_queue_.empty(); ++i) { GetAlbum(album_queue_.dequeue()); } } }
MyWindow(QWidget * parent = nullptr) : QDialog(parent) { m_layout.addWidget(&m_button); connect(&m_button, SIGNAL(clicked(bool)), this, SLOT(Scan())); connect(this, SIGNAL(ScanFinished()), this, SLOT(OnScanFinished())); }