Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#197: various status info in browser window title
Browse files Browse the repository at this point in the history
New option “WindowTitle” under web-interface settings.
  • Loading branch information
hugbug committed May 14, 2016
1 parent 2190eec commit 1508578
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
1 change: 1 addition & 0 deletions webui/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var Downloads = (new function($)
function groups_loaded(_groups)
{
groups = _groups;
Downloads.groups = groups;
prepare();
RPC.next();
}
Expand Down
27 changes: 24 additions & 3 deletions webui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ var UISettings = (new function($)

this.description = [];

this.description['refreshAnimation'] = 'Animation on refresh button (yes, no).';
this.refreshAnimation = true;

this.description['activityAnimation'] = 'Animation on play/pause button (yes, no).';
this.activityAnimation = true;

this.description['refreshAnimation'] = 'Animation on refresh button (yes, no).';
this.refreshAnimation = true;

this.description['slideAnimation'] = 'Animation of tab changes in tabbed dialogs (yes, no).';
this.slideAnimation = true;

Expand All @@ -61,6 +61,25 @@ var UISettings = (new function($)
this.description['rowSelect'] = 'Select records by clicking on any part of the row, not just on the check mark (yes, no).';
this.rowSelect = false;

this.description['windowTitle'] = 'Window-title for browser.\n\n' +
'The following variables can be used within placeholders to insert current data:\n' +
' COUNT - number of items in queue;\n' +
' SPEED - current download speed.\n' +
' TIME - remaining time;\n' +
' PAUSE - "download paused"-indicator.\n\n' +
'To form a placeholder surround variable with percent-characters, for example: %COUNT%.\n\n' +
'To improve formating there is a special syntax. If variable value is empty or null then nothing is inserted:\n' +
'%(VARNAME)% - show variable value inside parenthesis;\n' +
'%[VARNAME]% - show variable value inside square brackets;\n' +
'%VARNAME-% - append hyphen to variable value;\n' +
'%(VARNAME-)% - show variable value with hyphen inside parenthesis;\n' +
'%[VARNAME-]% - show variable value with hyphen inside square brackets.\n\n' +
'Examples:\n' +
' "%(COUNT-)% NZBGet" - show number of downloads in parenthesis followed by a hyphen; don\'t show "(0) - " if queue is empty;\n' +
' "%PAUSE% %(COUNT-)% NZBGet" - as above but also show pause-indicator if paused;\n' +
' "%[COUNT]% %SPEED-% NZBGet" - show number of downloads and speed if not null (default setting).';
this.windowTitle = '%[COUNT]% %SPEED-% NZBGet';

this.description['refreshRetries'] = 'Number of refresh attempts if a communication error occurs (0-99).\n\n' +
'If all attempts fail, an error is displayed and the automatic refresh stops.'
this.refreshRetries = 4;
Expand Down Expand Up @@ -95,6 +114,7 @@ var UISettings = (new function($)
this.showNotifications = this.read('ShowNotifications', this.showNotifications) == 'true';
this.dupeBadges = this.read('DupeBadges', this.dupeBadges) == 'true';
this.rowSelect = this.read('RowSelect', this.rowSelect) == 'true';
this.windowTitle = this.read('WindowTitle', this.windowTitle);
this.refreshRetries = parseFloat(this.read('RefreshRetries', this.refreshRetries));
}

Expand All @@ -108,6 +128,7 @@ var UISettings = (new function($)
this.write('ShowNotifications', this.showNotifications);
this.write('DupeBadges', this.dupeBadges);
this.write('RowSelect', this.rowSelect);
this.write('WindowTitle', this.windowTitle);
this.write('RefreshRetries', this.refreshRetries);
}

Expand Down
74 changes: 73 additions & 1 deletion webui/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var Status = (new function($)
var lastAnimState = 0;
var playInitialized = false;
var modalShown = false;
var titleGen = [];

this.init = function()
{
Expand Down Expand Up @@ -97,6 +98,7 @@ var Status = (new function($)

StatDialog.init();
FilterMenu.init();
initTitle();
}

this.update = function()
Expand Down Expand Up @@ -183,6 +185,8 @@ var Status = (new function($)
$StatusTime.toggleClass('orange', statWarning);
$StatusTimeIcon.toggleClass('icon-time', !statWarning);
$StatusTimeIcon.toggleClass('icon-time-orange', statWarning);

updateTitle();
}

function updatePlayButton()
Expand Down Expand Up @@ -340,7 +344,6 @@ var Status = (new function($)
modalShown = false;
}


this.serverName = function(server)
{
var name = Options.option('Server' + server.ID + '.Name');
Expand All @@ -353,6 +356,75 @@ var Status = (new function($)
return name;
}

function initTitle()
{
function format(pattern, paramFunc)
{
if (UISettings.connectionError)
{
var value = '?';
var isEmpty = false;
}
else
{
var param = paramFunc();
var value = param[0];
var isEmpty = param[1];
}

if (isEmpty && pattern != '%VAR%')
{
return '';
}

switch (pattern)
{
case '%VAR%': return value;
case '%VAR-%': return '' + value + ' - ';
case '%(VAR)%': return '(' + value + ')';
case '%(VAR-)%': return '(' + value + ') - ';
case '%[VAR]%': return '[' + value + ']';
case '%[VAR-]%': return '[' + value + '] - ';
}

return Downloads.groups.length > 0 ? '' + Downloads.groups.length + ' - ' : '';
};

function fill(varname, paramFunc)
{
titleGen['%' + varname + '%'] = function() { return format('%VAR%', paramFunc); };
titleGen['%' + varname + '-%'] = function() { return format('%VAR-%', paramFunc); };
titleGen['%(' + varname + ')%'] = function() { return format('%(VAR)%', paramFunc); };
titleGen['%(' + varname + '-)%'] = function() { return format('%(VAR-)%', paramFunc); };
titleGen['%[' + varname + ']%'] = function() { return format('%[VAR]%', paramFunc); };
titleGen['%[' + varname + '-]%'] = function() { return format('%[VAR-]%', paramFunc); };
}

fill('COUNT', function() { return [Downloads.groups.length, Downloads.groups.length == 0]; });
fill('SPEED', function() { return [$StatusSpeed.text(), status.ServerStandBy]; });
fill('TIME', function() { return [$StatusTime.text(), status.ServerStandBy]; });
fill('PAUSE', function() { return ['||', !status.DownloadPaused]; });
}

function updateTitle()
{
var title = UISettings.windowTitle;

for (var name in titleGen)
{
if (title.indexOf(name) > -1)
{
var value = titleGen[name]();
console.log(name + '=' + value);
title = title.replace(name, value);
}
}

title = title.trim();

window.document.title = title;
}
this.updateTitle = updateTitle;
}(jQuery));


Expand Down

0 comments on commit 1508578

Please sign in to comment.