Initial work on text themes. To be completed.
authorCory Chaplin <cory.chaplin@laposte.net>
Wed, 19 Mar 2014 23:33:42 +0000 (00:33 +0100)
committerCory Chaplin <cory.chaplin@laposte.net>
Wed, 19 Mar 2014 23:33:42 +0000 (00:33 +0100)
client/assets/text_themes/default.json [new file with mode: 0644]
client/build.js
client/src/app.js
client/src/models/channel.js
client/src/models/network.js
client/src/views/channel.js
client/src/views/texttheme.js [new file with mode: 0644]
server/settingsgenerator.js

diff --git a/client/assets/text_themes/default.json b/client/assets/text_themes/default.json
new file mode 100644 (file)
index 0000000..7879be3
--- /dev/null
@@ -0,0 +1,15 @@
+{
+  "client_models_channel_join": "%C3== %I%T",
+  "client_models_channel_part": "%C5== %I%T",
+  "client_models_channel_quit": "%C5== %I%T",
+  "client_models_channel_kicked": "%C5== %I%T",
+  "client_models_channel_selfkick": "%C5== %I%T",
+  "client_models_network_badpassword": "%C3== %I%T",
+  "client_models_network_mode": "%C3== %I%T",
+  "client_models_network_selfmode": "%C3== %I%T",
+  "client_models_network_banned": "%C3== %I%T",
+  "client_models_network_channel_badkey": "%C3== %I%T",
+  "client_models_network_channel_inviteonly": "%C3== %I%T",
+  "client_models_network_channel_limitreached": "%C3== %I%T",
+  "client_models_network_nickname_alreadyinuse": "%C3== %I%T"
+}
\ No newline at end of file
index da317859baf9c8fb2081daf505c2700e5d61b8b0..008a44f9809cef65ef689f25a0ebee08e95d7a7b 100644 (file)
@@ -83,7 +83,8 @@ var source_files = [
     __dirname + '/src/views/topicbar.js',\r
     __dirname + '/src/views/userbox.js',\r
     __dirname + '/src/views/channeltools.js',\r
-    __dirname + '/src/views/channelinfo.js'\r
+    __dirname + '/src/views/channelinfo.js',\r
+    __dirname + '/src/views/texttheme.js'\r
 ];\r
 \r
 \r
index c15b76937c240240515f0dd2470d329e3f71f83a..e9c241b475da99b49ee61ac3327c44ffb4a9ae85 100644 (file)
@@ -114,7 +114,7 @@ _kiwi.global = {
             } else {\r
                 _kiwi.global.i18n = new Jed();\r
             }\r
-\r
+            \r
             _kiwi.app = new _kiwi.model.Application(opts);\r
 \r
             // Start the client up\r
@@ -125,6 +125,12 @@ _kiwi.global = {
 \r
             callback && callback();\r
         };\r
+        \r
+        igniteTextTheme = function(text_theme, s, xhr) {\r
+            _kiwi.global.text_theme = new _kiwi.view.TextTheme(text_theme);\r
+            \r
+            callback && callback();\r
+        }\r
 \r
         // Set up the settings datastore\r
         _kiwi.global.settings = _kiwi.model.DataStore.instance('kiwi.settings');\r
@@ -139,6 +145,14 @@ _kiwi.global = {
         } else {\r
             $.getJSON(opts.base_path + '/assets/locales/' + locale + '.json', continueStart);\r
         }\r
+\r
+        text_theme = _kiwi.global.settings.get('text_theme');\r
+        if (!text_theme) {\r
+            $.getJSON(opts.base_path + '/assets/text_themes/default.json', igniteTextTheme);\r
+        } else {\r
+            $.getJSON(opts.base_path + '/assets/text_themes/' + text_theme + '.json', igniteTextTheme);\r
+        }\r
+\r
     }\r
 };\r
 \r
index 899c450999ea61ae2928b67e9a8e7254accb17dc..04e1ed67f0d7d6014db134da1f9e2f7897fdb0c3 100644 (file)
@@ -22,7 +22,7 @@ _kiwi.model.Channel = _kiwi.model.Panel.extend({
                 return;\r
             }\r
 \r
-            this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_join').fetch(member.displayNick(true)), 'action join', {time: options.kiwi.time});\r
+            this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_join', [member.displayNick(true)]), 'action join', {time: options.kiwi.time});\r
         }, this);\r
 \r
         members.bind("remove", function (member, members, options) {\r
@@ -30,20 +30,21 @@ _kiwi.model.Channel = _kiwi.model.Panel.extend({
             var msg = (options.kiwi.message) ? '(' + options.kiwi.message + ')' : '';\r
 \r
             if (options.kiwi.type === 'quit' && show_message) {\r
-                this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_quit').fetch(member.displayNick(true), msg), 'action quit', {time: options.kiwi.time});\r
+                this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_quit', [member.displayNick(true)], msg), 'action quit', {time: options.kiwi.time});\r
 \r
             } else if (options.kiwi.type === 'kick') {\r
 \r
                 if (!options.kiwi.current_user_kicked) {\r
                     //If user kicked someone, show the message regardless of settings.\r
                     if (show_message || options.kiwi.current_user_initiated) {\r
-                        this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_kicked').fetch(member.displayNick(true), options.kiwi.by, msg), 'action kick', {time: options.kiwi.time});\r
+                        this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_kicked', [member.displayNick(true), options.kiwi.by, msg]), 'action kick', {time: options.kiwi.time});\r
                     }\r
                 } else {\r
-                    this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_selfkick').fetch(options.kiwi.by, msg), 'action kick', {time: options.kiwi.time});\r
+                    this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_selfkick', [options.kiwi.by], msg), 'action kick', {time: options.kiwi.time});\r
                 }\r
             } else if (show_message) {\r
-                this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_part').fetch(member.displayNick(true), msg), 'action part', {time: options.kiwi.time});\r
+                this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_part', [member.displayNick(true)], msg), 'action part', {time: options.kiwi.time});\r
+\r
             }\r
         }, this);\r
     },\r
index b9ecb0d4bbee3d0716e07e1d6421389d4825750f..bb36391a178064cbd9364662e3ed064684b4dbcc 100644 (file)
             member = panel.get('members').getByNick(event.nick);
             if (member) {
                 member.set('nick', event.newnick);
-                panel.addMsg('', '== ' + _kiwi.global.i18n.translate('client_models_network_nickname_changed').fetch(event.nick, event.newnick) , 'action nick', {time: event.time});
+                panel.addMsg('', _kiwi.global.text_theme.styleText('client_models_network_nickname_changed', [event.nick, event.newnick], 'action nick', {time: event.time}));
             }
         });
     }
                     request_updated_banlist = true;
             }
 
-            channel.addMsg('', '== ' + _kiwi.global.i18n.translate('client_models_network_mode').fetch(event.nick, friendlyModeString()), 'action mode', {time: event.time});
+            channel.addMsg('', _kiwi.global.text_theme.styleText('client_models_network_mode', [event.nick, friendlyModeString()]), 'action mode', {time: event.time});
 
             // TODO: Be smart, remove the specific ban from the banlist rather than request a whole banlist
             if (request_updated_banlist)
         } else {
             // This is probably a mode being set on us.
             if (event.target.toLowerCase() === this.get("nick").toLowerCase()) {
-                this.panels.server.addMsg('', '== ' + _kiwi.global.i18n.translate('client_models_network_selfmode').fetch(event.nick, friendlyModeString()), 'action mode');
+                this.panels.server.addMsg('', _kiwi.global.text_theme.styleText('client_models_network_selfmode', [event.nick, friendlyModeString()]), 'action mode');
             } else {
                console.log('MODE command recieved for unknown target %s: ', event.target, event);
             }
 
         switch (event.error) {
         case 'banned_from_channel':
-            panel.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_network_banned').fetch(event.channel, event.reason), 'status');
+            panel.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_banned', [event.channel, event.reason]), 'status');
             _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_banned').fetch(event.channel, event.reason));
             break;
         case 'bad_channel_key':
-            panel.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_network_channel_badkey').fetch(event.channel), 'status');
+            panel.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_channel_badkey', [event.channel]), 'status');
             _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_badkey').fetch(event.channel));
             break;
         case 'invite_only_channel':
-            panel.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_network_channel_inviteonly').fetch(event.channel), 'status');
+            panel.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_channel_inviteonly', [event.channel]), 'status');
             _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_inviteonly').fetch(event.channel));
             break;
         case 'user_on_channel':
             panel.addMsg(' ', '== ' + event.nick + ' is already on this channel');
             break;
         case 'channel_is_full':
-            panel.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_network_channel_limitreached').fetch(event.channel), 'status');
+            panel.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_channel_limitreached', [event.channel]), 'status');
             _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_limitreached').fetch(event.channel));
             break;
         case 'chanop_privs_needed':
             }
             break;
         case 'nickname_in_use':
-            this.panels.server.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_network_nickname_alreadyinuse').fetch( event.nick), 'status');
+            this.panels.server.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_nickname_alreadyinuse', [event.nick]), 'status');
             if (this.panels.server !== this.panels.active) {
                 _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_nickname_alreadyinuse').fetch(event.nick));
             }
             break;
 
         case 'password_mismatch':
-            this.panels.server.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_network_badpassword').fetch(), 'status');
+            this.panels.server.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_badpassword'), 'status');
             break;
         default:
             // We don't know what data contains, so don't do anything with it.
index 28498defb9183fa0e51db426df2c79ee47df93f8..7250b367bcc9d21bb2a9618dbefc1cc63dc79f89 100644 (file)
@@ -228,7 +228,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
             topic = this.model.get("topic");
         }
 
-        this.model.addMsg('', '== ' + _kiwi.global.i18n.translate('client_views_channel_topic').fetch(this.model.get('name'), topic), 'topic');
+        this.model.addMsg('', _kiwi.global.text_theme.styleText('client_views_channel_topic', [this.model.get('name'), topic]), 'topic');
 
         // If this is the active channel then update the topic bar
         if (_kiwi.app.panels().active === this) {
diff --git a/client/src/views/texttheme.js b/client/src/views/texttheme.js
new file mode 100644 (file)
index 0000000..0250ccb
--- /dev/null
@@ -0,0 +1,20 @@
+_kiwi.view.TextTheme = _kiwi.view.Panel.extend({
+       initialize: function(text_theme) {
+               this.text_theme = text_theme;
+       },
+       getText: function(string_id, params, trailing = '') {
+               var translation;
+               
+               translation = _kiwi.global.i18n.translate(string_id).fetch(params);
+               
+               return translation + trailing;
+       },
+       styleText: function(string_id, params, trailing = '') {
+               var style, text;
+               
+               style = formatToIrcMsg(_kiwi.global.text_theme.options[string_id]);
+               text = this.getText(string_id, params, trailing);
+               
+               return style.replace('%T', text);
+       }
+});
\ No newline at end of file
index d79753564a1fcf4a0cead80395ca1dea5f612d83..bf767fba811e658e5ea729590f16221712f4f8b3 100644 (file)
@@ -249,7 +249,8 @@ function addScripts(vars, debug) {
             'src/views/topicbar.js',
             'src/views/userbox.js',
             'src/views/channeltools.js',
-            'src/views/channelinfo.js'
+            'src/views/channelinfo.js',
+            'src/views/texttheme.js'
         ]
     ]);
 }
\ No newline at end of file