void ConcertFilesWidget::unmarkForSync()
{
    m_contextMenu->close();
    foreach (const QModelIndex &index, ui->files->selectionModel()->selectedRows(0)) {
        int row = index.model()->data(index, Qt::UserRole).toInt();
        Concert *concert = Manager::instance()->concertModel()->concert(row);
        concert->setSyncNeeded(false);
        ui->files->update(index);
    }
}
Example #2
0
/**
 * @brief Accesses items data
 * @param index Index of item
 * @param role Role
 * @return data
 */
QVariant ConcertModel::data(const QModelIndex &index, int role) const
{
    if (index.row() < 0 || index.row() > m_concerts.count())
        return QVariant();

    if (role == Qt::UserRole)
        return index.row();

    Concert *concert = m_concerts[index.row()];
    if (index.column() == 0 && role == Qt::DisplayRole) {
        return concert->name();
    } else if (index.column() == 0 && role == Qt::ToolTipRole) {
        if (concert->files().size() == 0)
            return QVariant();
        return concert->files().at(0);
    } else if (index.column() == 1 && role == Qt::DisplayRole) {
        return concert->folderName();
    } else if (role == Qt::UserRole+1) {
        return concert->infoLoaded();
    } else if (role == Qt::UserRole+2) {
        return concert->hasChanged();
    } else if (role == Qt::ForegroundRole) {
        if (concert->hasChanged())
            return QColor(255, 0, 0);
    } else if (role == Qt::FontRole) {
        if (concert->hasChanged()) {
            QFont font;
            font.setItalic(true);
            return font;
        }
    }
    return QVariant();
}
void ConcertFilesWidget::markAsUnwatched()
{
    m_contextMenu->close();
    foreach (const QModelIndex &index, ui->files->selectionModel()->selectedRows(0)) {
        int row = index.model()->data(index, Qt::UserRole).toInt();
        Concert *concert = Manager::instance()->concertModel()->concert(row);
        if (concert->watched())
            concert->setWatched(false);
        if (concert->playcount() != 0)
            concert->setPlayCount(0);
    }
    if (ui->files->selectionModel()->selectedRows(0).count() > 0)
        concertSelectedEmitter();
}
void ConcertFilesWidget::openFolder()
{
    m_contextMenu->close();
    int row = ui->files->currentIndex().data(Qt::UserRole).toInt();
    Concert *concert = Manager::instance()->concertModel()->concert(row);
    if (concert->files().isEmpty())
        return;
    QFileInfo fi(concert->files().at(0));
    QUrl url;
    if (fi.absolutePath().startsWith("\\\\") || fi.absolutePath().startsWith("//"))
        url.setUrl(QDir::toNativeSeparators(fi.absolutePath()));
    else
        url = QUrl::fromLocalFile(fi.absolutePath());
    QDesktopServices::openUrl(url);
}
Example #5
0
QList<Concert*> Database::concerts(QString path)
{
    QList<Concert*> concerts;
    QSqlQuery query(db());
    QSqlQuery queryFiles(db());
    query.prepare("SELECT idConcert, content, inSeparateFolder FROM concerts WHERE path=:path");
    query.bindValue(":path", path.toUtf8());
    query.exec();
    while (query.next()) {
        QStringList files;
        queryFiles.prepare("SELECT file FROM concertFiles WHERE idConcert=:idConcert");
        queryFiles.bindValue(":idConcert", query.value(query.record().indexOf("idConcert")).toInt());
        queryFiles.exec();
        while (queryFiles.next())
            files << QString::fromUtf8(queryFiles.value(queryFiles.record().indexOf("file")).toByteArray());

        Concert *concert = new Concert(files, Manager::instance()->concertFileSearcher());
        concert->setDatabaseId(query.value(query.record().indexOf("idConcert")).toInt());
        concert->setInSeparateFolder(query.value(query.record().indexOf("inSeparateFolder")).toInt() == 1);
        concert->setNfoContent(QString::fromUtf8(query.value(query.record().indexOf("content")).toByteArray()));
        concerts.append(concert);
    }
    return concerts;
}
void ConcertFilesWidget::markAsWatched()
{
    m_contextMenu->close();
    foreach (const QModelIndex &index, ui->files->selectionModel()->selectedRows(0)) {
        int row = index.model()->data(index, Qt::UserRole).toInt();
        Concert *concert = Manager::instance()->concertModel()->concert(row);
        concert->setWatched(true);
        if (concert->playcount() < 1)
            concert->setPlayCount(1);
        if (!concert->lastPlayed().isValid())
            concert->setLastPlayed(QDateTime::currentDateTime());
    }
    if (ui->files->selectionModel()->selectedRows(0).count() > 0)
        concertSelectedEmitter();
}
Example #7
0
/**
 * @brief Accesses items data
 * @param index Index of item
 * @param role Role
 * @return data
 */
QVariant ConcertModel::data(const QModelIndex &index, int role) const
{
    if (index.row() < 0 || index.row() > m_concerts.count())
        return QVariant();

    if (role == Qt::UserRole)
        return index.row();

    Concert *concert = m_concerts[index.row()];
    if (index.column() == 0 && role == Qt::DisplayRole) {
        return Helper::appendArticle(concert->name());
    } else if (index.column() == 0 && role == Qt::ToolTipRole) {
        if (concert->files().size() == 0)
            return QVariant();
        return concert->files().at(0);
    } else if (index.column() == 1 && role == Qt::DisplayRole) {
        return concert->folderName();
    } else if (role == Qt::UserRole+1) {
        return concert->controller()->infoLoaded();
    } else if (role == Qt::UserRole+2) {
        return concert->hasChanged();
    } else if (role == Qt::UserRole+3) {
        return concert->syncNeeded();
    /*
    } else if (role == Qt::ForegroundRole) {
        if (concert->hasChanged())
            return QColor(255, 0, 0);
    */
    } else if (role == Qt::FontRole) {
        if (concert->hasChanged()) {
            QFont font;
            font.setItalic(true);
            return font;
        }
    } else if (role == Qt::DecorationRole) {
        if (!concert->controller()->infoLoaded())
            return m_newIcon;
        else if (concert->syncNeeded())
            return m_syncIcon;
    }
    return QVariant();
}
/**
 * @brief Starts the scanning process
 */
void ConcertFileSearcher::reload(bool force)
{
    m_aborted = false;

    if (force)
        Manager::instance()->database()->clearConcerts();

    Manager::instance()->concertModel()->clear();
    emit searchStarted(tr("Searching for Concerts..."), m_progressMessageId);

    QList<Concert*> concerts;
    QList<Concert*> dbConcerts;
    QList<QStringList> contents;
    foreach (SettingsDir dir, m_directories) {
        if (m_aborted)
            return;

        QList<Concert*> concertsFromDb = Manager::instance()->database()->concerts(dir.path);
        if (dir.autoReload || force || concertsFromDb.count() == 0) {
            Manager::instance()->database()->clearConcerts(dir.path);
            scanDir(dir.path, dir.path, contents, dir.separateFolders, true);
        } else {
            dbConcerts.append(concertsFromDb);
        }
    }
    emit currentDir("");

    emit searchStarted(tr("Loading Concerts..."), m_progressMessageId);
    int concertCounter=0;
    int concertSum=contents.size()+dbConcerts.size();

    // Setup concerts
    Manager::instance()->database()->transaction();
    foreach (const QStringList &files, contents) {
        if (m_aborted)
            return;

        bool inSeparateFolder = false;
        QString path;
        // get directory
        if (!files.isEmpty()) {
            int index = -1;
            for (int i=0, n=m_directories.count() ; i<n ; ++i) {
                if (files.at(0).startsWith(m_directories[i].path)) {
                    if (index == -1)
                        index = i;
                    else if (m_directories[index].path.length() < m_directories[i].path.length())
                        index = i;
                }
            }
            if (index != -1) {
                inSeparateFolder = m_directories[index].separateFolders;
                path = m_directories[index].path;
            }
        }
        Concert *concert = new Concert(files, this);
        concert->setInSeparateFolder(inSeparateFolder);
        concert->controller()->loadData(Manager::instance()->mediaCenterInterface());
        emit currentDir(concert->name());
        Manager::instance()->database()->add(concert, path);
        concerts.append(concert);
        emit progress(++concertCounter, concertSum, m_progressMessageId);
    }
    Manager::instance()->database()->commit();

    // Setup concerts loaded from database
    foreach (Concert *concert, dbConcerts) {
        if (m_aborted)
            return;

        concert->controller()->loadData(Manager::instance()->mediaCenterInterface(), false, false);
        emit currentDir(concert->name());
        concerts.append(concert);
        emit progress(++concertCounter, concertSum, m_progressMessageId);
    }

    foreach (Concert *concert, concerts)
        Manager::instance()->concertModel()->addConcert(concert);

    qDebug() << "Searching for concerts done";
    if (!m_aborted)
        emit concertsLoaded(m_progressMessageId);
}