History

Add asset uploader to Menu

Ryan Huffman committed 11 years ago

Commit d90ceb21 parent 0bfa0c41 file · +31 −0Browse files

Showing the changes to interface/src/Menu.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Menu.cpp+31−0
@@ -21,6 +21,7 @@ · 20 unmodified lines
21#include <UserActivityLogger.h>21#include <UserActivityLogger.h>
22#include <VrMenu.h>22#include <VrMenu.h>
23 23
24#include <AssetClient.h>
24#include "Application.h"25#include "Application.h"
25#include "AccountManager.h"26#include "AccountManager.h"
26#include "audio/AudioScope.h"27#include "audio/AudioScope.h"
@@ -87,6 +88,36 @@ Menu::Menu() { · 60 unmodified lines
87 addActionToQMenuAndActionHash(fileMenu, MenuOption::RunningScripts, Qt::CTRL | Qt::Key_J,88 addActionToQMenuAndActionHash(fileMenu, MenuOption::RunningScripts, Qt::CTRL | Qt::Key_J,
88 qApp, SLOT(toggleRunningScriptsWidget()));89 qApp, SLOT(toggleRunningScriptsWidget()));
89 90
91 // Asset uploading
92 {
93 auto action = new QAction("Upload File", fileMenu);
94 fileMenu->addAction(action);
95 action->setMenuRole(QAction::NoRole);
96 _actionHash.insert("Upload File", action);
97
98 connect(action, &QAction::triggered, [this](bool checked) {
99 qDebug() << "Clicked upload file";
100 auto filename = QFileDialog::getOpenFileUrl(nullptr, "Select a file to upload");
101 if (!filename.isEmpty()) {
102 qDebug() << "Selected: " << filename;
103 QFile file { filename.path() };
104 if (file.open(QIODevice::ReadOnly)) {
105 auto fileInfo { filename.path() };
106 auto extension = fileInfo.suffix();
107 auto data = file.readAll();
108 auto assetClient = DependencyManager::get<AssetClient>();
109 assetClient->uploadAsset(data, extension, [this](bool result, QString hash) mutable {
110 if (result) {
111 QMessageBox::information(this, "Upload Successful", "URL: apt:/" + hash + "." + extension);
112 } else {
113 QMessageBox::warning(this, "Upload Failed", "There was an error uploading the file.");
114 }
115 });
116 }
117 }
118 });
119 }
120
90 auto addressManager = DependencyManager::get<AddressManager>();121 auto addressManager = DependencyManager::get<AddressManager>();
91 122
92 addDisabledActionAndSeparator(fileMenu, "History");123 addDisabledActionAndSeparator(fileMenu, "History");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t