Skip to content

Commit

Permalink
VFS: dropbox - added notification icon and signout (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Dec 29, 2014
1 parent 1d6a707 commit 6132549
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/javascript/locales/en_EN.js
Expand Up @@ -134,7 +134,6 @@

'DIALOG_FONT_TITLE' : 'Font Dialog',


'DIALOG_APPCHOOSER_TITLE' : 'Choose Application',
'DIALOG_APPCHOOSER_MSG' : 'Choose an application to open',
'DIALOG_APPCHOOSER_NO_SELECTION' : 'You need to select an application',
Expand Down Expand Up @@ -170,7 +169,6 @@
'ERR_VFS_DOWNLOAD_FAILED' : 'An error occured while downloading: {0}',
'TOOLTIP_VFS_DOWNLOAD_NOTIFICATION': 'Downloading file',

// VFS -> GoogleDrive
'ERR_VFSMODULE_XHR_ERROR' : 'XHR Error',
'ERR_VFSMODULE_ROOT_ID' : 'Failed to find root folder id',
'ERR_VFSMODULE_NOSUCH' : 'File does not exist',
Expand All @@ -197,6 +195,10 @@
'ERR_VFSMODULE_URL' : 'Failed to get URL for file',
'ERR_VFSMODULE_URL_FMT' : 'Failed to get URL for file: {0}',

// VFS -> Dropbox
'DROPBOX_NOTIFICATION_TITLE' : 'You are signed in to Dropbox API',
'DROPBOX_SIGN_OUT' : 'Sign out from Google API Services',

// DefaultApplication
'ERR_FILE_APP_OPEN' : 'Cannot open file',
'ERR_FILE_APP_OPEN_FMT' : 'The file {0} could not be opened because the mime {1} is not supported',
Expand Down
7 changes: 5 additions & 2 deletions src/javascript/locales/no_NO.js
Expand Up @@ -142,7 +142,7 @@

// GoogleAPI
'GAPI_DISABLED' : 'GoogleAPI Modul dekativert eller ikke konfigurert',
'GAPI_NOTIFICATION_TITLE' : 'Du må logge inn Google API',
'GAPI_NOTIFICATION_TITLE' : 'Du er logget inn i Google API',
'GAPI_SIGN_OUT' : 'Logg ut av Google API Services',
'GAPI_REVOKE' : 'Tilbakekall tillatelse og Logg ut',
'GAPI_AUTH_FAILURE' : 'Google API autentisering feilet eller tok ikke sted',
Expand Down Expand Up @@ -170,7 +170,6 @@
'ERR_VFS_DOWNLOAD_FAILED' : 'En feil oppstod under nedlasting: {0}',
'TOOLTIP_VFS_DOWNLOAD_NOTIFICATION': 'Last ned fil',

// VFS -> GoogleDrive
'ERR_VFSMODULE_XHR_ERROR' : 'XHR Feil',
'ERR_VFSMODULE_ROOT_ID' : 'Klarte ikke hente id for rotmappe',
'ERR_VFSMODULE_NOSUCH' : 'Filen eksister ikke',
Expand All @@ -197,6 +196,10 @@
'ERR_VFSMODULE_URL' : 'Klarte ikke hente URL for fil',
'ERR_VFSMODULE_URL_FMT' : 'Klarte ikke hente URL for fil: {0}',

// VFS -> Dropbox
'DROPBOX_NOTIFICATION_TITLE' : 'Du er logget inn i Dropbox API',
'DROPBOX_SIGN_OUT' : 'Logg ut fra Dropbox API',

// DefaultApplication
'ERR_FILE_APP_OPEN' : 'Kan ikke åpne filen',
'ERR_FILE_APP_OPEN_FMT' : 'Filen {0} ble ikke åpnet fordi MIME {1} ikke er støttet',
Expand Down
99 changes: 81 additions & 18 deletions src/javascript/vfs/dropbox.js
Expand Up @@ -39,6 +39,7 @@
OSjs.VFS = OSjs.VFS || {};
OSjs.VFS.Modules = OSjs.VFS.Modules || {};

var _cachedClient;
var _isMounted = false;

function _getConfig(cfg) {
Expand All @@ -53,6 +54,49 @@
return null;
}

function destroyNotificationIcon() {
var wm = API.getWMInstance();
if ( wm ) {
wm.removeNotificationIcon('GoogleAPIService');
}
}

function createNotificationIcon() {
var wm = API.getWMInstance();

function displayMenu(ev) {
var pos = {x: ev.clientX, y: ev.clientY};
OSjs.GUI.createMenu([{
title: API._('DROPBOX_SIGN_OUT'),
onClick: function() {
signoutDropbox();
}
}], pos);
}

if ( wm ) {
wm.createNotificationIcon('DropboxVFSService', {
onContextMenu: function(ev) {
displayMenu(ev);
return false;
},
onClick: function(ev) {
displayMenu(ev);
return false;
},
onInited: function(el) {
if ( el.firstChild ) {
var img = document.createElement('img');
img.title = API._('DROPBOX_NOTIFICATION_TITLE');
img.alt = img.title;
img.src = API.getThemeResource('status/gtk-dialog-authentication.png', 'icon', '16x16');
el.firstChild.appendChild(img);
}
}
});
}
}

/////////////////////////////////////////////////////////////////////////////
// HELPERS
/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -244,28 +288,47 @@
// WRAPPERS
/////////////////////////////////////////////////////////////////////////////

var getDropbox = (function() {
var client;
return function(callback) {
if ( !client ) {
client = new DropboxVFS();
client.init(function(error) {
if ( error ) {
console.error('Failed to initialize dropbox VFS', error);
callback(null);
return;
}
function getDropbox(callback) {
if ( !_cachedClient ) {
_cachedClient = new DropboxVFS();
_cachedClient.init(function(error) {
if ( error ) {
console.error('Failed to initialize dropbox VFS', error);
callback(null);
return;
}

_isMounted = true;
createNotificationIcon();
API.message('vfs', {type: 'mount', module: 'Dropbox', source: null});

callback(_cachedClient);
});
return;
}
callback(_cachedClient);
}

_isMounted = true;
API.message('vfs', {type: 'mount', module: 'Dropbox', source: null});
function signoutDropbox(cb, options) {
cb = cb || function() {};
options = options || null;

callback(client);
getDropbox(function(client) {
client = client ? client.client : null;
if ( client ) {
client.signOut(options, function() {
_isMounted = false;
_cachedClient = null;

API.message('vfs', {type: 'unmount', module: 'Dropbox', source: null});

destroyNotificationIcon();

cb();
});
return;
}
callback(client);
};
})();
});
}

function makeRequest(name, args, callback, options) {
args = args || [];
Expand Down

0 comments on commit 6132549

Please sign in to comment.