mirror of
https://gitflic.ru/project/astankevich/mtpview.git
synced 2024-11-23 15:08:23 +01:00
Send progress notification when upload/download file. Necessity does not checked.
This commit is contained in:
parent
c1cb87a669
commit
1f99ad5551
10
App.cpp
10
App.cpp
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user