Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

changed: background file manager operations #1541

Merged
6 commits merged into from

3 participants

@ghost

As in the topic. I could probably split this a bit if you insist, but it got so damm entangled..

@ghost

this depends on pr #1530

@opdenkamp
Collaborator

nice

@ghost

better split now and no longer depends on #1530

@jmarshallnz
Owner

Looks good to me. A few functions could be const (You asked for it by changing one that wasn't related...)

@ghost ghost was assigned
@ghost

hah, as if i'd ever do such a thing ;) put it in the correct context now + made the new functions const.

@ghost

no other concerns?

@dersphere

If you are interested in a user opinion: I would like it even more if it would copy or move files one after another with any kind of queue and not parallel.

@ghost

it's sorta what it does. it does two user-initiated operations in parallel. an operation can be copying n files or n dirs or whatever.

@dersphere

Oh, looks like I was not precise enough - sorry.
When I start copying file A and then start copying file B, both copy-jobs are done at the same time (and the progress window switches between the jobs).

@ghost

i got you. if, however, you mark file a and file b and hit copy, they will be copied in sequence. doing it all in sequence is trivial, that's just removing the 2 thread slots. but imo this is better.

@ghost ghost merged commit f69f18c into xbmc:master
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 language/English/strings.po
@@ -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"
View
1  xbmc/interfaces/http-api/XBMChttp.cpp
@@ -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"
View
92 xbmc/utils/FileOperationJob.cpp
@@ -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;
+}
View
21 xbmc/utils/FileOperationJob.h
@@ -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;
};
View
1  xbmc/windows/GUIMediaWindow.cpp
@@ -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"
View
114 xbmc/windows/GUIWindowFileManager.cpp
@@ -21,6 +21,7 @@
#include "system.h"
#include "GUIWindowFileManager.h"
#include "Application.h"
+#include "ApplicationMessenger.h"
#include "Util.h"
#include "filesystem/Directory.h"
#include "filesystem/ZipManager.h"
@@ -40,6 +41,7 @@
#include "dialogs/GUIDialogYesNo.h"
#include "guilib/GUIKeyboardFactory.h"
#include "dialogs/GUIDialogProgress.h"
+#include "dialogs/GUIDialogExtendedProgressBar.h"
#include "Favourites.h"
#include "playlists/PlayList.h"
#include "utils/AsyncFileCopy.h"
@@ -89,9 +91,9 @@ using namespace PLAYLIST;
#define CONTROL_CURRENTDIRLABEL_RIGHT 102
CGUIWindowFileManager::CGUIWindowFileManager(void)
- : CGUIWindow(WINDOW_FILES, "FileManager.xml")
+ : CGUIWindow(WINDOW_FILES, "FileManager.xml"),
+ CJobQueue(false,2)
{
- m_dlgProgress = NULL;
m_Directory[0] = new CFileItem;
m_Directory[1] = new CFileItem;
m_vecItems[0] = new CFileItemList;
@@ -241,6 +243,11 @@ bool CGUIWindowFileManager::OnMessage(CGUIMessage& message)
}
return true;
}
+ else if (message.GetParam1()==GUI_MSG_UPDATE && IsActive())
+ {
+ Refresh();
+ return true;
+ }
}
break;
case GUI_MSG_PLAYBACK_STARTED:
@@ -703,12 +710,10 @@ void CGUIWindowFileManager::OnCopy(int iList)
if (!CGUIDialogYesNo::ShowAndGetInput(120, 123, 0, 0))
return;
- ResetProgressBar();
-
- m_errorHeading = 16201;
- m_errorLine = 16202;
-
- CJobManager::GetInstance().AddJob(new CFileOperationJob(CFileOperationJob::ActionCopy, *m_vecItems[iList], m_Directory[1 - iList]->GetPath()), this);
+ AddJob(new CFileOperationJob(CFileOperationJob::ActionCopy,
+ *m_vecItems[iList],
+ m_Directory[1 - iList]->GetPath(),
+ true, 16201, 16202));
}
void CGUIWindowFileManager::OnMove(int iList)
@@ -716,12 +721,10 @@ void CGUIWindowFileManager::OnMove(int iList)
if (!CGUIDialogYesNo::ShowAndGetInput(121, 124, 0, 0))
return;
- ResetProgressBar();
-
- m_errorHeading = 16203;
- m_errorLine = 16204;
-
- CJobManager::GetInstance().AddJob(new CFileOperationJob(CFileOperationJob::ActionMove, *m_vecItems[iList], m_Directory[1 - iList]->GetPath()), this);
+ AddJob(new CFileOperationJob(CFileOperationJob::ActionMove,
+ *m_vecItems[iList],
+ m_Directory[1 - iList]->GetPath(),
+ true, 16203, 16204));
}
void CGUIWindowFileManager::OnDelete(int iList)
@@ -729,12 +732,10 @@ void CGUIWindowFileManager::OnDelete(int iList)
if (!CGUIDialogYesNo::ShowAndGetInput(122, 125, 0, 0))
return;
- ResetProgressBar(false);
-
- m_errorHeading = 16205;
- m_errorLine = 16206;
-
- CJobManager::GetInstance().AddJob(new CFileOperationJob(CFileOperationJob::ActionDelete, *m_vecItems[iList], m_Directory[iList]->GetPath()), this);
+ AddJob(new CFileOperationJob(CFileOperationJob::ActionDelete,
+ *m_vecItems[iList],
+ m_Directory[iList]->GetPath(),
+ true, 16205, 16206));
}
void CGUIWindowFileManager::OnRename(int iList)
@@ -843,20 +844,6 @@ void CGUIWindowFileManager::GoParentFolder(int iList)
Update(iList, strPath);
}
-bool CGUIWindowFileManager::OnFileCallback(void* pContext, int ipercent, float avgSpeed)
-{
- if (m_dlgProgress)
- {
- m_dlgProgress->SetPercentage(ipercent);
- CStdString speedString;
- speedString.Format("%2.2f KB/s", avgSpeed / 1024);
- m_dlgProgress->SetLine(0, speedString);
- m_dlgProgress->Progress();
- if (m_dlgProgress->IsCanceled()) return false;
- }
- return true;
-}
-
/// \brief Build a directory history string
/// \param pItem Item to build the history string from
/// \param strHistoryString History string build as return value
@@ -1036,6 +1023,8 @@ void CGUIWindowFileManager::OnPopupMenu(int list, int item, bool bContextDriven
choices.Add(10, 5); // Settings
choices.Add(11, 20128); // Go To Root
choices.Add(12, 523); // switch media
+ if (CJobManager::GetInstance().IsProcessing("filemanager"))
+ choices.Add(13, 167);
int btnid = CGUIDialogContextMenu::ShowAndGetChoice(choices);
if (btnid == 1)
@@ -1113,6 +1102,8 @@ void CGUIWindowFileManager::OnPopupMenu(int list, int item, bool bContextDriven
CGUIDialogContextMenu::SwitchMedia("files", m_vecItems[list]->GetPath());
return;
}
+ if (btnid == 13)
+ CancelJobs();
if (bDeselect && item >= 0 && item < m_vecItems[list]->Size())
{ // deselect item as we didn't do anything
@@ -1168,39 +1159,21 @@ int64_t CGUIWindowFileManager::CalculateFolderSize(const CStdString &strDirector
void CGUIWindowFileManager::OnJobComplete(unsigned int jobID, bool success, CJob *job)
{
- m_dlgProgress->SetLine(0, 1040);
- m_dlgProgress->SetLine(1, "");
- m_dlgProgress->SetLine(2, "");
- m_dlgProgress->SetPercentage(100);
- Refresh();
- m_dlgProgress->Close();
-
if(!success)
- CGUIDialogOK::ShowAndGetInput(m_errorHeading, m_errorLine, 16200, 0);
-}
-
-void CGUIWindowFileManager::OnJobProgress(unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job)
-{
- if (m_dlgProgress->IsCanceled())
{
- CJobManager::GetInstance().CancelJob(jobID);
- m_dlgProgress->SetLine(0, 1040);
- m_dlgProgress->SetLine(1, "");
- m_dlgProgress->SetLine(2, "");
- Refresh();
- m_dlgProgress->Close();
+ CFileOperationJob* fileJob = (CFileOperationJob*)job;
+ CGUIDialogOK::ShowAndGetInput(fileJob->GetHeading(),
+ fileJob->GetLine(), 16200, 0);
}
- else
- {
- CFileOperationJob *fileJob = (CFileOperationJob *)job;
- m_dlgProgress->SetLine(0, fileJob->GetCurrentOperation());
- m_dlgProgress->SetLine(1, fileJob->GetCurrentFile());
- m_dlgProgress->SetLine(2, fileJob->GetAverageSpeed());
-
- if (total > 0)
- m_dlgProgress->SetPercentage((int)((float)progress * 100.0f / (float)total));
+ if (IsActive())
+ {
+ CGUIMessage msg(GUI_MSG_NOTIFY_ALL, GetID(), 0, GUI_MSG_UPDATE);
+ CApplicationMessenger::Get().SendGUIMessage(msg, GetID(), false);
}
+
+ if (success)
+ CJobQueue::OnJobComplete(jobID, success, job);
}
void CGUIWindowFileManager::ShowShareErrorMessage(CFileItem* pItem)
@@ -1224,9 +1197,6 @@ void CGUIWindowFileManager::ShowShareErrorMessage(CFileItem* pItem)
void CGUIWindowFileManager::OnInitWindow()
{
- m_dlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
- if (m_dlgProgress) m_dlgProgress->SetHeading(126);
-
for (int i = 0; i < 2; i++)
{
Update(i, m_Directory[i]->GetPath());
@@ -1307,20 +1277,6 @@ void CGUIWindowFileManager::SetInitialPath(const CStdString &path)
if (m_Directory[1]->GetPath() == "?") m_Directory[1]->SetPath("");
}
-void CGUIWindowFileManager::ResetProgressBar(bool showProgress /*= true */)
-{
- if (m_dlgProgress)
- {
- m_dlgProgress->SetHeading(126);
- m_dlgProgress->SetLine(0, 0);
- m_dlgProgress->SetLine(1, 0);
- m_dlgProgress->SetLine(2, 0);
- m_dlgProgress->SetPercentage(0);
- m_dlgProgress->StartModal();
- m_dlgProgress->ShowProgressBar(showProgress);
- }
-}
-
const CFileItem& CGUIWindowFileManager::CurrentDirectory(int indx) const
{
return *m_Directory[indx];
View
10 xbmc/windows/GUIWindowFileManager.h
@@ -24,8 +24,7 @@
#include "filesystem/VirtualDirectory.h"
#include "filesystem/DirectoryHistory.h"
#include "threads/CriticalSection.h"
-#include "filesystem/File.h"
-#include "utils/Job.h"
+#include "utils/JobManager.h"
class CFileItem;
class CFileItemList;
@@ -33,8 +32,7 @@ class CGUIDialogProgress;
class CGUIWindowFileManager :
public CGUIWindow,
- public XFILE::IFileCallback,
- public IJobCallback
+ public CJobQueue
{
public:
@@ -43,14 +41,11 @@ class CGUIWindowFileManager :
virtual bool OnMessage(CGUIMessage& message);
virtual bool OnAction(const CAction &action);
virtual bool OnBack(int actionID);
- virtual bool OnFileCallback(void* pContext, int ipercent, float avgSpeed);
const CFileItem &CurrentDirectory(int indx) const;
- void ResetProgressBar(bool showProgress = true);
static int64_t CalculateFolderSize(const CStdString &strDirectory, CGUIDialogProgress *pProgress = NULL);
virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
- virtual void OnJobProgress(unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job);
protected:
virtual void OnInitWindow();
void SetInitialPath(const CStdString &path);
@@ -98,7 +93,6 @@ class CGUIWindowFileManager :
typedef std::vector <CFileItem*> ::iterator ivecItems;
CFileItem* m_Directory[2];
CStdString m_strParentPath[2];
- CGUIDialogProgress* m_dlgProgress;
CDirectoryHistory m_history[2];
int m_errorHeading, m_errorLine;
Something went wrong with that request. Please try again.