Beispiel #1
0
/** \fn     GalleryViewHelper::SetFileOrientation(int)
 *  \brief  Saves the orientation information of the selected node
 *  \param  fileOrientation The orientation value 1-8
 *  \return void
 */
void GalleryViewHelper::SetFileOrientation(int fileOrientation)
{
    ImageMetadata *im = GetImageMetadataFromSelectedNode();
    if (!im)
        return;

    int oldFileOrientation = im->GetOrientation();

    // Update the orientation, the new value will
    // be calculated with this method. This new
    // value will then be saved in the exif header tag.
    im->SetOrientation(fileOrientation, false);

    // Update the exif tag, if that fails we can restore the original
    // orientation so that the database and image file are not out of sync
    if (m_fileHelper->SetImageOrientation(im))
    {
        m_dbHelper->UpdateData(im);
        m_thumbGenThread->RecreateThumbnail(im);
        m_thumbGenThread->start();
    }
    else
    {
        im->SetOrientation(oldFileOrientation, false);

        LOG(VB_GENERAL, LOG_ERR,
            QString("Could not write the angle %1 into the file %2. "
                    "The database value has not been updated.")
            .arg(im->GetAngle()).arg(im->m_fileName));
    }
}
Beispiel #2
0
/** \fn     GalleryViewHelper::SetFileOrientation(int)
 *  \brief  Saves the orientation information of the selected node
 *  \param  fileOrientation The orientation value 1-8
 *  \return void
 */
void GalleryViewHelper::SetFileOrientation(int fileOrientation)
{
    ImageMetadata *im = GetImageMetadataFromSelectedNode();
    if (!im)
        return;

    int oldFileOrientation = im->GetOrientation();

    // Update the orientation, the new value will
    // be calculated with this method. This new
    // value will then be saved in the exif header tag.
    im->SetOrientation(fileOrientation, false);

    // Request orientation update
    if (m_fileHelper->SetImageOrientation(im))
    {
        // force thumbnail to be regenerated
        m_fileHelper->AddToThumbnailList(im, true);
    }
    else
    {
        // Restore previous orientation
        im->SetOrientation(oldFileOrientation, true);

        LOG(VB_GENERAL, LOG_ERR, QString("Orientation update failed for %1")
            .arg(im->m_fileName));
    }
}
Beispiel #3
0
/** \fn     GalleryViewHelper::LoadTreeData()
 *  \brief  Load all available data from the database and populates the tree.
 *  \return void
 */
void GalleryViewHelper::LoadTreeData()
{
    QList<ImageMetadata *> *dirList = new QList<ImageMetadata *>;
    QList<ImageMetadata *> *fileList = new QList<ImageMetadata *>;

    // Stop generating thumbnails
    // when a new directory is loaded
    m_thumbGenThread->cancel();

    // The parent id is the database index of the
    // directories which subdirectories and files shall be loaded
    int id = 0;

    // Get the selected node. If there is no data available then the
    // plugin has been started for the first time, a synchronization
    // request was made or the settings have changed. In this case
    // use default parent id of the storage group directories.
    ImageMetadata *im = GetImageMetadataFromSelectedNode();
    if (im)
    {
        if (im->m_type == kUpDirectory)
            id = im->m_parentId;

        if (im->m_type == kSubDirectory)
            id = im->m_id;
    }

    // The data from the selected node has used.
    // Clear the list so that it can be populated with new data.
    m_currentNode->deleteAllChildren();

    // If the parentId is not one of the directories in the storage group
    // then add a additional directory at the beginning of the list that
    // is of the type kUpDirectory so that the user can navigate one level up.
    if (!m_dbHelper->GetStorageDirIDs(m_sgDirList).contains(id))
    {
        m_dbHelper->LoadParentDirectory(dirList, id);
        LoadTreeNodeData(dirList, m_currentNode);
    }

    m_dbHelper->LoadDirectories(dirList, id);
    LoadTreeNodeData(dirList, m_currentNode);

    // Load all files with the specified sorting criterias
    m_dbHelper->LoadFiles(fileList, id);
    LoadTreeNodeData(fileList, m_currentNode);

    // Start generating thumbnails if required
    m_thumbGenThread->start();

    // clean up
    if (dirList)
        delete dirList;

    if (fileList)
        delete fileList;
}
Beispiel #4
0
/** \fn     GalleryViewHelper::SetFileZoom(int)
 *  \brief  Saves the zoom information of the selected node
 *  \param  zoom The zoom value in percent
 *  \return void
 */
void GalleryViewHelper::SetFileZoom(int zoom)
{
    ImageMetadata *im = GetImageMetadataFromSelectedNode();
    if (!im)
        return;

    if (zoom == kFileZoomIn)
        im->SetZoom(20);

    if (zoom == kFileZoomOut)
        im->SetZoom(-20);

    m_dbHelper->UpdateData(im);
}
Beispiel #5
0
/** \fn     GalleryViewHelper::SetNodeVisibilityState(int)
 *  \brief  Sets the selected not either to the
            nodeState that the user has specified
 *  \param  nodeState Can be either visible or invisible
 *  \return void
 */
void GalleryViewHelper::SetNodeVisibilityState(int nodeState)
{
    // set the given node as visible / invisible
    ImageMetadata *im = GetImageMetadataFromSelectedNode();
    if (im)
    {
        if (nodeState == kNodeStateVisible)
            im->m_isHidden = false;

        if (nodeState == kNodeStateInvisible)
            im->m_isHidden = true;

        m_dbHelper->UpdateData(im);
    }
}
Beispiel #6
0
/** \fn     GalleryViewHelper::RenameCurrentNode(QString &)
 *  \brief  Renames the file that belongs to the node and updates the database
 *  \param  New name of the file with the full path
 *  \return void
 */
void GalleryViewHelper::RenameCurrentNode(QString &newName)
{
    ImageMetadata *im = GetImageMetadataFromSelectedNode();
    if (!im)
        return;

    if (m_fileHelper->RenameFile(im, newName))
    {
        // replace the original filename with the
        // new one in the pull path + filename variable
        QString newFileName = im->m_fileName.replace(im->m_name, newName);

        im->m_fileName = newFileName;
        im->m_name = newName;
    }
}
Beispiel #7
0
/** \fn     GalleryViewHelper::DeleteCurrentNode()
 *  \brief  Deletes the current node from the generic tree
 *  \return void
 */
void GalleryViewHelper::DeleteCurrentNode()
{
    ImageMetadata *im = GetImageMetadataFromSelectedNode();

    // TODO: Remove directories as well
    if (im && im->m_type >= kImageFile)

        // Delete the file and remove the database entry
        if (m_fileHelper->RemoveFile(im))
        {
            // Remove the entry from the node list
            m_currentNode->deleteNode(m_currentNode->getSelectedChild());

            // Clean up thumbnail cache
            GetMythUI()->RemoveFromCacheByFile(im->m_thumbFileNameList->at(0));
        }
}
Beispiel #8
0
/** \fn     GalleryViewHelper::DeleteCurrentNode()
 *  \brief  Deletes the current node from the generic tree
 *  \return void
 */
void GalleryViewHelper::DeleteCurrentNode()
{
    ImageMetadata *im = GetImageMetadataFromSelectedNode();
    if (!im)
        return;

    // Delete the file and remove the database entry
    if (m_fileHelper->RemoveFile(im))
    {
        // Remove the entry from the node list
        m_currentNode->deleteNode(m_currentNode->getSelectedChild());

        // Only remove the first thumbnail when it is an image or video.
        // If its a folder, it will use thumbnails from other images
        if (im->m_type == kImageFile || im->m_type == kVideoFile)
            QFile::remove(im->m_thumbFileNameList->at(0));

        m_dbHelper->RemoveFile(im);
    }
}
Beispiel #9
0
/** \fn     GalleryViewHelper::RenameCurrentNode(QString &)
 *  \brief  Renames the file that belongs to the node and updates the database
 *  \param  New name of the file with the full path
 *  \return void
 */
void GalleryViewHelper::RenameCurrentNode(QString &newName)
{
    bool fileExist = false;

    // Check if the file with the new name already exists in the current directory
    QList<MythGenericTree *> *nodeTree = m_currentNode->getAllChildren();
    for (int i = 0; i < nodeTree->size(); i++)
    {
        ImageMetadata *im = qVariantValue<ImageMetadata *>(nodeTree->at(i)->GetData());
        if (im)
        {
            if (im->m_name.compare(newName) == 0)
            {
                fileExist = true;
                break;
            }
        }
    }

    // The file with the given new name does not yet exist.
    // Continue with the renaming of the file
    if (!fileExist)
    {
        ImageMetadata *im = GetImageMetadataFromSelectedNode();
        if (!im)
            return;

        if (m_fileHelper->RenameFile(im, newName))
        {
            // replace the original filename with the
            // new one in the pull path + filename variable
            QString newFileName = im->m_fileName.replace(im->m_name, newName);

            im->m_fileName = newFileName;
            im->m_name = newName;

            m_dbHelper->UpdateData(im);
        }
    }
}