File indexing completed on 2024-05-12 05:22:09

0001 /*
0002     SPDX-FileCopyrightText: 2020 David Barchiesi <david@barchie.si>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QFile>
0010 #include <QMainWindow>
0011 #include <QProgressBar>
0012 
0013 #include "ui_mainwindow.h"
0014 
0015 #include "core/types.h"
0016 
0017 #include "drive/fileresumablecreatejob.h"
0018 
0019 namespace KGAPI2
0020 {
0021 class Job;
0022 }
0023 
0024 class MainWindow : public QMainWindow
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     explicit MainWindow(QWidget *parent = nullptr);
0030 
0031 private Q_SLOTS:
0032     /**
0033      * Retrieves tokens from Google that we will use to authenticate
0034      * further requests
0035      */
0036     void authenticate();
0037 
0038     /**
0039      * Browses files to select the one to upload
0040      */
0041     void browseFiles();
0042 
0043     /**
0044      * Starts resumable file upload of source file to destination directory
0045      */
0046     void uploadFile();
0047 
0048     /**
0049      * FileCreateJob requests data
0050      */
0051     void slotFileCreateJobFinished(KGAPI2::Job *job);
0052 
0053     /**
0054      * FileCreateJob requests data
0055      */
0056     void slotFileCreateJobReadyWrite(KGAPI2::Drive::FileAbstractResumableJob *job);
0057 
0058     /**
0059      * FileCreateJob emits progress
0060      */
0061     void slotFileCreateJobProgress(KGAPI2::Job *job, int base, int total);
0062 
0063 private:
0064     Ui::MainWindow ui;
0065 
0066     KGAPI2::AccountPtr m_account;
0067 
0068     std::unique_ptr<QFile> m_uploadingFile;
0069     int m_bytesUploaded = 0;
0070     std::unique_ptr<QProgressBar> m_fileUploadProgressBar;
0071     std::unique_ptr<QProgressBar> m_jobUploadProgressBar;
0072 
0073     void setInputsEnabled(bool enabled);
0074 };