Permalink
Browse files

Merge pull request #1541 from cptspiff/bgfileops

changed: background file manager operations
  • Loading branch information...
2 parents a4acb0c + ed42416 commit f69f18c7445df7a97c91837d4a0da40444028bea Arne Morten Kvarving committed Oct 6, 2012
@@ -562,7 +562,11 @@ msgctxt "#166"
msgid "Skin"
msgstr ""
-#empty strings from id 167 to 168
+msgctxt "#167"
+msgid "Cancel file operations"
+msgstr ""
+
+#empty string with id 168
msgctxt "#169"
msgid "Resolution"
@@ -47,6 +47,7 @@
#include "settings/AdvancedSettings.h"
#include "settings/GUISettings.h"
#include "filesystem/DirectoryFactory.h"
+#include "filesystem/File.h"
#include "guilib/LocalizeStrings.h"
#include "utils/StringUtils.h"
#include "utils/TimeUtils.h"
@@ -30,6 +30,9 @@
#include "URIUtils.h"
#include "URL.h"
#include "guilib/LocalizeStrings.h"
+#include "guilib/GUIWindowManager.h"
+#include "dialogs/GUIDialogExtendedProgressBar.h"
+
#ifdef HAS_FILESYSTEM_RAR
#include "filesystem/RarManager.h"
#endif
@@ -39,10 +42,19 @@ using namespace XFILE;
CFileOperationJob::CFileOperationJob()
{
+ m_handle = NULL;
+ m_displayProgress = false;
}
-CFileOperationJob::CFileOperationJob(FileAction action, CFileItemList & items, const CStdString& strDestFile)
+CFileOperationJob::CFileOperationJob(FileAction action, CFileItemList & items,
+ const CStdString& strDestFile,
+ bool displayProgress,
+ int heading, int line)
{
+ m_handle = NULL;
+ m_displayProgress = displayProgress;
+ m_heading = heading;
+ m_line = line;
SetFileOperation(action, items, strDestFile);
}
@@ -60,6 +72,14 @@ bool CFileOperationJob::DoWork()
{
FileOperationList ops;
double totalTime = 0.0;
+
+ if (m_displayProgress)
+ {
+ CGUIDialogExtendedProgressBar* dialog =
+ (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS);
+ m_handle = dialog->GetHandle(GetActionString(m_action));
+ }
+
bool success = DoProcess(m_action, m_items, m_strDestFile, ops, totalTime);
unsigned int size = ops.size();
@@ -70,6 +90,9 @@ bool CFileOperationJob::DoWork()
for (unsigned int i = 0; i < size && success; i++)
success &= ops[i].ExecuteOperation(this, current, opWeight);
+ if (m_handle)
+ m_handle->MarkFinished();
+
return success;
}
@@ -193,36 +216,48 @@ struct DataHolder
double opWeight;
};
-bool CFileOperationJob::CFileOperation::ExecuteOperation(CFileOperationJob *base, double &current, double opWeight)
+CStdString CFileOperationJob::GetActionString(FileAction action)
{
- bool bResult = true;
-
- base->m_currentFile = CURL(m_strFileA).GetFileNameWithoutPath();
-
- switch (m_action)
+ CStdString result;
+ switch (action)
{
case ActionCopy:
case ActionReplace:
- base->m_currentOperation = g_localizeStrings.Get(115);
+ result = g_localizeStrings.Get(115);
break;
case ActionMove:
- base->m_currentOperation = g_localizeStrings.Get(116);
+ result = g_localizeStrings.Get(116);
break;
case ActionDelete:
case ActionDeleteFolder:
- base->m_currentOperation = g_localizeStrings.Get(117);
+ result = g_localizeStrings.Get(117);
break;
case ActionCreateFolder:
- base->m_currentOperation = g_localizeStrings.Get(119);
+ result = g_localizeStrings.Get(119);
break;
default:
- base->m_currentOperation = "";
break;
}
+ return result;
+}
+
+bool CFileOperationJob::CFileOperation::ExecuteOperation(CFileOperationJob *base, double &current, double opWeight)
+{
+ bool bResult = true;
+
+ base->m_currentFile = CURL(m_strFileA).GetFileNameWithoutPath();
+ base->m_currentOperation = GetActionString(m_action);
+
if (base->ShouldCancel((unsigned)current, 100))
return false;
+ if (base->m_handle)
+ {
+ base->m_handle->SetText(base->GetCurrentFile());
+ base->m_handle->SetPercentage(current);
+ }
+
DataHolder data = {base, current, opWeight};
switch (m_action)
@@ -302,5 +337,38 @@ bool CFileOperationJob::CFileOperation::OnFileCallback(void* pContext, int iperc
else
data->base->m_avgSpeed.Format("%.1f KB/s", avgSpeed / 1000.0f);
+ if (data->base->m_handle)
+ {
+ CStdString line;
+ line.Format("%s (%s)", data->base->GetCurrentFile().c_str(),
+ data->base->GetAverageSpeed().c_str());
+ data->base->m_handle->SetText(line);
+ data->base->m_handle->SetPercentage(current);
+ }
+
return !data->base->ShouldCancel((unsigned)current, 100);
}
+
+bool CFileOperationJob::operator==(const CJob* job) const
+{
+ if (strcmp(job->GetType(),GetType()) == 0)
+ {
+ const CFileOperationJob* rjob = dynamic_cast<const CFileOperationJob*>(job);
+ if (rjob)
+ {
+ if (GetAction() == rjob->GetAction() &&
+ m_strDestFile == rjob->m_strDestFile &&
+ m_items.Size() == rjob->m_items.Size())
+ {
+ for (int i=0;i<m_items.Size();++i)
+ {
+ if (m_items[i]->GetPath() != rjob->m_items[i]->GetPath() ||
+ m_items[i]->IsSelected() != rjob->m_items[i]->IsSelected())
+ return false;
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+}
@@ -24,6 +24,8 @@
#include "Job.h"
#include "filesystem/File.h"
+class CGUIDialogProgressBarHandle;
+
class CFileOperationJob : public CJob
{
public:
@@ -38,16 +40,27 @@ class CFileOperationJob : public CJob
};
CFileOperationJob();
- CFileOperationJob(FileAction action, CFileItemList & items, const CStdString& strDestFile);
+ CFileOperationJob(FileAction action, CFileItemList & items,
+ const CStdString& strDestFile,
+ bool displayProgress=false,
+ int errorHeading=0, int errorLine=0);
void SetFileOperation(FileAction action, CFileItemList &items, const CStdString &strDestFile);
+ virtual bool operator==(const CJob *job) const;
+
+ static CStdString GetActionString(FileAction action);
+
+ const char* GetType() const { return m_displayProgress?"filemanager":""; }
+
virtual bool DoWork();
const CStdString &GetAverageSpeed() { return m_avgSpeed; }
const CStdString &GetCurrentOperation() { return m_currentOperation; }
const CStdString &GetCurrentFile() { return m_currentFile; }
const CFileItemList &GetItems() { return m_items; }
- FileAction GetAction() { return m_action; }
+ FileAction GetAction() const { return m_action; }
+ int GetHeading() const { return m_heading; }
+ int GetLine() const { return m_line; }
private:
class CFileOperation : public XFILE::IFileCallback
{
@@ -73,4 +86,8 @@ class CFileOperationJob : public CJob
CFileItemList m_items;
CStdString m_strDestFile;
CStdString m_avgSpeed, m_currentOperation, m_currentFile;
+ CGUIDialogProgressBarHandle* m_handle;
+ bool m_displayProgress;
+ int m_heading;
+ int m_line;
};
@@ -54,6 +54,7 @@
#include "utils/URIUtils.h"
#include "guilib/LocalizeStrings.h"
#include "utils/TimeUtils.h"
+#include "filesystem/File.h"
#include "filesystem/FileDirectoryFactory.h"
#include "utils/log.h"
#include "utils/FileUtils.h"
Oops, something went wrong.

0 comments on commit f69f18c

Please sign in to comment.