Send progress notification when upload/download file. Necessity does not checked.

This commit is contained in:
Anton Stankevich 2024-10-17 00:54:36 +00:00
parent c1cb87a669
commit 1f99ad5551
3 changed files with 33 additions and 1 deletions

10
App.cpp
View File

@ -14,11 +14,19 @@ MainWindow *mainwin;
LIBMTP_mtpdevice_t *detected_device=0;
bool finish_read_device = false;
uint64_t prev_progress = 0;
int progress (uint64_t const sent, uint64_t const total,
void const * const data)
{
uint64_t progress_percent = (100*sent)/total;
if (((progress_percent % 10) == 0) && (progress_percent > prev_progress)) {
printf(" Progress %d\n", progress_percent);
mainwin->uploadDownloadNotification->SetProgress((float)sent/total);
prev_progress = (progress_percent < 100)? progress_percent: 0;
mainwin->uploadDownloadNotification->Send();
}
return 0;
}

View File

@ -131,6 +131,10 @@ MainWindow::MainWindow(void)
openPanel = new BFilePanel(B_OPEN_PANEL, messenger, NULL, B_FILE_NODE, false);
//savePanel = new BFilePanel(B_SAVE_PANEL, messenger, NULL, B_DIRECTORY_NODE, false); //B_DIRECTORY_NODE has no effect
savePanel = new BFilePanel(B_SAVE_PANEL, messenger, NULL, B_FILE_NODE, false);
uploadDownloadNotification = new BNotification (B_PROGRESS_NOTIFICATION);
uploadDownloadNotification->SetGroup("mtpview");
selectedItem = NULL;
//openPanel->SetTarget(messenger);
@ -217,6 +221,15 @@ MainWindow::MessageReceived(BMessage *msg)
printf("Try to upload %s to dir %d %s\n", openFileName, selectedItem->fileId(), selectedItem->Text());
int newFileId=0;
uploadDownloadNotification->SetTitle("Uploading");
uploadDownloadNotification->SetContent(openFileName);
uploadDownloadNotification->SetMessageID("mainwindow_progress");
uploadDownloadNotification->SetProgress(0.5);
uploadDownloadNotification->Send();
int send_res = sendfile_function(openFileName, selectedItem->fileId(), newFileId);
if (send_res == 0)
{
@ -257,6 +270,13 @@ MainWindow::MessageReceived(BMessage *msg)
//strcat(fullSaveFileName, selectedItem->Text());
printf("Try to download %d %s to %s\n", selectedItem->fileId(), selectedItem->Text(), fullSaveFileName);
uploadDownloadNotification->SetTitle("Downloading");
uploadDownloadNotification->SetContent(selectedItem->Text());
uploadDownloadNotification->SetMessageID("mainwindow_progress");
uploadDownloadNotification->SetProgress(0.5);
uploadDownloadNotification->Send();
if (LIBMTP_Get_File_To_File(selectedItem->device(), selectedItem->fileId(),
/*selectedItem->Text()*/ fullSaveFileName, progress, NULL) != 0 ){
printf("\nError getting file from MTP device.\n");

View File

@ -5,8 +5,10 @@
#include <OutlineListView.h>
#include <FilePanel.h>
#include <Messenger.h>
#include <Notification.h>
#include <libmtp.h>
class FileItem: public BStringItem
{
public:
@ -31,12 +33,14 @@ public:
void MessageReceived(BMessage *msg);
inline BOutlineListView * listView(){return this->fListView;};
void showErrorAlert(const char * message);
BNotification * uploadDownloadNotification;
private:
BOutlineListView *fListView;
BButton *download;
BButton *upload;
BFilePanel* openPanel;
BFilePanel* savePanel;
BMessenger * messenger;
FileItem * selectedItem;