Skip to content
Browse files

Added new service API calls to rename or delete a certain file.

Signed-off-by: Stuart Morgan <smorgan@mythtv.org>
  • Loading branch information...
1 parent 776379c commit c7f317e98f2ff7a59474ee793c90b02102db7960 @rsiebert rsiebert committed with stuartm Mar 12, 2013
View
7 mythtv/libs/libmythservicecontracts/services/contentServices.h
@@ -41,6 +41,8 @@ class SERVICE_PUBLIC ContentServices : public Service //, public QScriptable ??
Q_OBJECT
Q_CLASSINFO( "version" , "1.34" );
Q_CLASSINFO( "DownloadFile_Method", "POST" )
+ Q_CLASSINFO( "DeleteFile_Method", "POST" )
+ Q_CLASSINFO( "RenameFile_Method", "POST" )
public:
@@ -104,6 +106,11 @@ class SERVICE_PUBLIC ContentServices : public Service //, public QScriptable ??
virtual bool DownloadFile ( const QString &URL,
const QString &StorageGroup ) = 0;
+ virtual bool DeleteFile ( const QString &FileName ) = 0;
+
+ virtual bool RenameFile ( const QString &FileName,
+ const QString &NewName ) = 0;
+
virtual DTC::LiveStreamInfo *AddLiveStream ( const QString &StorageGroup,
const QString &FileName,
const QString &HostName,
View
58 mythtv/programs/mythbackend/services/content.cpp
@@ -822,6 +822,64 @@ bool Content::DownloadFile( const QString &sURL, const QString &sStorageGroup )
return false;
}
+/** \fn Content::DeleteImage(const QString &sFileName )
+ * \brief Permanently deletes the given file from the disk.
+ * \param sFileName The full filename that shall be deleted
+ * \return bool True if deletion was successful, otherwise false
+ */
+bool Content::DeleteFile( const QString &sFileName )
+{
+ if (sFileName.isEmpty())
+ {
+ LOG(VB_GENERAL, LOG_ERR, "DeleteFile - FileName is missing");
+ return false;
+ }
+
+ if (!QFile::exists( sFileName ))
+ {
+ LOG(VB_GENERAL, LOG_ERR, "DeleteFile - FileName does not exist.");
+ return false;
+ }
+ return QFile::remove( sFileName );
+}
+
+/** \fn Content::RenameFile(const QString &sFileName,
+ * const QString &sNewFile)
+ * \brief Renames the file to the new name.
+ * \param sFileName The full filename that shall be deleted
+ * \param sNewName The new name of the file (only the name, no path)
+ * \return bool True if renaming was successful, otherwise false
+ */
+bool Content::RenameFile( const QString &sFileName,
+ const QString &sNewName)
+{
+ if (sFileName.isEmpty())
+ {
+ LOG(VB_GENERAL, LOG_ERR, "RenameFile - FileName is missing");
+ return false;
+ }
+
+ if (!QFile::exists( sFileName ))
+ {
+ LOG(VB_GENERAL, LOG_ERR, "RenameFile - FileName does not exist.");
+ return false;
+ }
+
+ QFileInfo fileInfo(sFileName);
+ QString sNewFileName = fileInfo.path() + "/" + sNewName;
+ if (QFile::exists( sNewFileName ))
+ {
+ LOG(VB_GENERAL, LOG_ERR,
+ QString("RenameFile - New file %1 would overwrite "
+ "existing one, not renaming.").arg(sNewFileName));
+ return false;
+ }
+
+ // If the path of the new filename is not the same
+ // as the original one, then the renaming will fail.
+ return QFile::rename( sFileName, sNewFileName );
+}
+
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
View
5 mythtv/programs/mythbackend/services/content.h
@@ -87,6 +87,11 @@ class Content : public ContentServices
bool DownloadFile ( const QString &URL,
const QString &StorageGroup );
+ bool DeleteFile ( const QString &FileName );
+
+ bool RenameFile ( const QString &FileName,
+ const QString &NewName );
+
// HTTP Live Streaming
DTC::LiveStreamInfo *AddLiveStream ( const QString &StorageGroup,
const QString &FileName,
View
169 mythtv/programs/mythfrontend/example.cpp
@@ -0,0 +1,169 @@
+#include "mythmainwindow.h"
+#include "mythscreenstack.h"
+#include "mythscreentype.h"
+#include "mythuiimage.h"
+#include "mythuitext.h"
+
+// .h
+class AirPlayPictureScreen : public MythScreenType
+{
+ public:
+ AirPlayPictureScreen(MythScreenStack *parent);
+ ~AirPlayPictureScreen();
+
+ // These two methods are declared by MythScreenType and their signatures
+ // should not be changed
+ virtual bool Create(void);
+ virtual void Init(void);
+
+ void UpdatePicture(const QString &imageFilename,
+ const QString &imageDescription);
+
+ private:
+ QString m_imageFilename;
+ QString m_imageDescription;
+ MythUIImage *m_airplayImage;
+ MythUIText *m_airplayText;
+};
+
+///////////////////////////////////////////////////
+// .cpp
+
+AirPlayPictureScreen::AirPlayPictureScreen(MythScreenStack *parent)
+ :MythScreenType(parent, "airplaypicture"),
+ m_imageFilename(""), m_imageDescription(""),
+ m_airplayImage(NULL), m_airplayText(NULL)
+{
+}
+
+bool AirPlayPictureScreen::Create(void)
+{
+ bool foundtheme = false;
+
+ // Load the theme for this screen
+ // The xml file containing the screen definition is airplay-ui.xml in this
+ // example, the name of the screen in the xml is airplaypicture. This
+ // should make sense when you look at the xml below
+ foundtheme = LoadWindowFromXML("airplay-ui.xml", "airplaypicture", this);
+
+ if (!foundtheme) // If we cannot load the theme for any reason ...
+ return false;
+
+ // The xml should contain an <imagetype> named 'picture', if it doesn't
+ // then we cannot display the image and may as well abort
+ m_airplayImage = dynamic_cast<MythUIImage*>
+ (GetChild("picture"));
+ if (!m_airplayImage)
+ return false;
+
+ // As an illustration let's say the picture includes a description/title or some other metadata
+ // Let's also say that display of this metadata is entirely optional, so we won't fail if the theme
+ // doesn't include 'description'
+ m_airplayText = dynamic_cast<MythUIText*>
+ (GetChild("description"));
+
+ return true;
+}
+
+void AirPlayPictureScreen::Init(void)
+{
+ if (m_airplayImage)
+ {
+ if (!m_imageFilename.isEmpty())
+ {
+ m_airplayImage->SetFilename(m_imageFilename); // Absolute path, http or SG url
+ m_airplayImage->Load(); // By default the image is loaded in a background thread, use LoadNow() to load in foreground
+ }
+ else
+ {
+ // Will default to displaying whatever placeholder image is defined
+ // in the xml by the themer, means we can show _something_ rather than
+ // a big empty hole. Generally you always want to call Reset() in
+ // these circumstances
+ m_airplayImage->Reset();
+ }
+ }
+
+ if (m_airplayText)
+ {
+ if (!m_imageDescription.isEmpty())
+ {
+ m_airplayText->SetText(m_imageDescription);
+ }
+ else
+ {
+ // Same as above, calling Reset() allows for a sane, themer defined
+ //default to be displayed
+ m_airplayText->Reset();
+ }
+ }
+}
+
+// If want to update the displayed image or text without closing this screen
+// and creating a new one then it might look something like this
+void AirPlayPictureScreen::UpdatePicture(const QString &imageFilename,
+ const QString &imageDescription)
+{
+ m_imageFilename = imageFilename;
+ m_imageDescription = imageDescription;
+
+ Init();
+}
+
+////////////////////////////////////////
+
+// Your AirPlay picture event handler, after writing image to disc
+void SomeClass::AirPlayPictureEventHandler(blah ...)
+{
+ QString filename = "/path/to/image";
+ QString description = "Description of image, from metadata?";
+
+ // .... //
+
+ MythScreenStack *screenStack = GetMythMainWindow()->GetStack("popup stack");
+ AirPlayPictureScreen *picScreen = new AirPlayPictureScreen();
+
+ if (picScreen->Create()) // Reads screen definition from xml, and constructs screen
+ {
+ picScreen->UpdatePicture(filename, description);
+ screenStack->AddScreen(picScreen);
+ }
+ else
+ {
+ // If we can't create the screen then we can't display it, so delete
+ // and abort
+ delete picScreen;
+ return;
+ }
+}
+
+////////////////////////////////////////
+// airplay-ui.xml
+// See http://www.mythtv.org/wiki/MythUI_Theme_Development for more, this is a
+// bare minimum example, the wiki explains everything in detail
+
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE mythuitheme SYSTEM "http://www.mythtv.org/schema/mythuitheme.dtd">
+<mythuitheme>
+
+ <window name="airplaypicture">
+ <!-- No <area> tags for window implies fullscreen -->
+
+ <!-- Required -->
+ <imagetype name="picture">
+ <area>0,0,100%,100%</area> <!-- Same size as screen, i.e. fullscreen -->
+ </imagetype>
+
+ <!-- Optional -->
+ <textarea name="description">
+ <area>50,50,300,200</area> <!-- x,y,w,h - Origin at top left -->
+ <font>basesmall</font> <!-- See base.xml for the theme -->
+ <align>hcenter,vcenter</align> <!-- Centre text in available space -->
+ <multiline>yes</multiline> <!-- Allow wrapping -->
+ </textarea>
+
+ </window>
+
+</mythuitheme>
+
+

0 comments on commit c7f317e

Please sign in to comment.
Something went wrong with that request. Please try again.