[gnome-shell/hotplug: 9/13] mount-operation: implement ask-question



commit aed5a7b70e8efd658ac7e5b8f3704a97a3b41784
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Jul 12 11:44:08 2011 -0400

    mount-operation: implement ask-question
    
    Use a system modal dialogs for mount operation questions.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653520

 data/theme/gnome-shell.css   |   17 +++--
 js/ui/automountManager.js    |    1 +
 js/ui/shellMountOperation.js |  141 ++++++++++++++++++++++++++++++++----------
 3 files changed, 119 insertions(+), 40 deletions(-)
---
diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css
index 968eec5..201bd78 100644
--- a/data/theme/gnome-shell.css
+++ b/data/theme/gnome-shell.css
@@ -1666,16 +1666,18 @@ StTooltip StLabel {
     color: #444444;
 }
 
-/* Show Processes Dialog */
+/* ShellMountOperation Dialogs */
 .shell-mount-operation-icon {
     icon-size: 48px;
 }
 
-.show-processes-dialog {
+.show-processes-dialog,
+.mount-question-dialog {
     spacing: 24px;
 }
 
-.show-processes-dialog-subject {
+.show-processes-dialog-subject,
+.mount-question-dialog-subject {
     font-size: 12pt;
     font-weight: bold;
     color: #666666;
@@ -1684,19 +1686,22 @@ StTooltip StLabel {
     padding-bottom: 6px;
 }
 
-.show-processes-dialog-subject:rtl {
+.show-processes-dialog-subject:rtl,
+.mount-question-dialog-subject:rtl {
     padding-left: 0px;
     padding-right: 17px;
 }
 
-.show-processes-dialog-description {
+.show-processes-dialog-description,
+.mount-question-dialog-description {
     font-size: 10pt;
     color: white;
     padding-left: 17px;
     width: 28em;
 }
 
-.show-processes-dialog-description:rtl {
+.show-processes-dialog-description:rtl,
+.mount-question-dialog-description:rtl {
     padding-right: 17px;
 }
 
diff --git a/js/ui/automountManager.js b/js/ui/automountManager.js
index 8babde6..96a8ffb 100644
--- a/js/ui/automountManager.js
+++ b/js/ui/automountManager.js
@@ -6,6 +6,7 @@ const Mainloop = imports.mainloop;
 const Gio = imports.gi.Gio;
 
 const Main = imports.ui.main;
+const ShellMountOperation = imports.ui.shellMountOperation;
 const ScreenSaver = imports.misc.screenSaver;
 
 // GSettings keys
diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js
index b1e3f0a..0f07626 100644
--- a/js/ui/shellMountOperation.js
+++ b/js/ui/shellMountOperation.js
@@ -12,6 +12,7 @@ const ModalDialog = imports.ui.modalDialog;
 
 const LIST_ITEM_ICON_SIZE = 48;
 
+/* ------ Common Utils ------- */
 function _setLabelText(label, text) {
     if (text) {
         label.set_text(text);
@@ -22,6 +23,30 @@ function _setLabelText(label, text) {
     }
 }
 
+function _setButtonsForChoices(dialog, choices) {
+    let buttons = [];
+
+    for (let idx = 0; idx < choices.length; idx++) {
+        let button = idx;
+        buttons.unshift({ label: choices[idx],
+                          action: Lang.bind(dialog, function() {
+                              dialog.emit('response', button);
+                          })});
+    }
+
+    dialog.setButtons(buttons);
+}
+
+function _setLabelsForMessage(dialog, message) {
+    let labels = message.split('\n');
+
+    _setLabelText(dialog.subjectLabel, labels[0]);
+    if (labels.length > 1)
+        _setLabelText(dialog.descriptionLabel, labels[1]);
+}
+
+/* -------------------------------------------------------- */
+
 function ListItem(app) {
     this._init(app);
 }
@@ -67,6 +92,9 @@ function ShellMountOperation(source) {
 
 ShellMountOperation.prototype = {
     _init: function(source) {
+        this._dialog = null;
+        this._processesDialog = null;
+
         this.mountOp = new Shell.MountOperation();
 
         this.mountOp.connect('ask-question',
@@ -83,7 +111,20 @@ ShellMountOperation.prototype = {
     },
 
     _onAskQuestion: function(op, message, choices) {
-        // TODO
+        let questionDialog = new ShellMountQuestionDialog(this._icon);
+        this._dialog = questionDialog;
+        
+        questionDialog.connect('response',
+                               Lang.bind(this, function(object, choice) {
+                                   this.mountOp.set_choice(choice);
+                                   this.mountOp.reply(Gio.MountOperationResult.HANDLED);
+
+                                   questionDialog.close(global.get_current_time());
+                                   this._dialog = null;
+                               }));
+
+        questionDialog.update(message, choices);
+        questionDialog.open(global.get_current_time());
     },
 
     _onAskPassword: function(op, message, defaultUser, defaultDomain, flags) {
@@ -91,7 +132,11 @@ ShellMountOperation.prototype = {
     },
 
     _onAborted: function(op) {
-        // TODO
+        if (!this._dialog)
+            return;
+
+        this._dialog.close(global.get_current_time());
+        this._dialog = null;
     },
 
     _onShowProcesses2: function(op) {
@@ -101,7 +146,9 @@ ShellMountOperation.prototype = {
 
         if (!this._processesDialog) {
             this._processesDialog = new ShellProcessesDialog(this._icon);
-            this._processesDialog.connect('choice-chosen', 
+            this._dialog = this._processesDialog;
+
+            this._processesDialog.connect('response', 
                                           Lang.bind(this, function(object, choice) {
                                               if (choice == -1) {
                                                   this.mountOp.reply(Gio.MountOperationResult.ABORTED);
@@ -111,6 +158,7 @@ ShellMountOperation.prototype = {
                                               }
 
                                               this._processesDialog.close(global.get_current_time());
+                                              this._dialog = null;
                                           }));
             this._processesDialog.open(global.get_current_time());
         }
@@ -119,6 +167,53 @@ ShellMountOperation.prototype = {
     },
 }
 
+function ShellMountQuestionDialog(icon) {
+    this._init(icon);
+}
+
+ShellMountQuestionDialog.prototype = {
+    __proto__: ModalDialog.ModalDialog.prototype,
+
+    _init: function(icon) {
+        ModalDialog.ModalDialog.prototype._init.call(this, { styleClass: 'mount-question-dialog' });
+
+        let mainContentLayout = new St.BoxLayout();
+        this.contentLayout.add(mainContentLayout, { x_fill: true,
+                                                    y_fill: false });
+
+        this._iconBin = new St.Bin({ child: icon });
+        mainContentLayout.add(this._iconBin,
+                              { x_fill:  true,
+                                y_fill:  false,
+                                x_align: St.Align.END,
+                                y_align: St.Align.MIDDLE });
+
+        let messageLayout = new St.BoxLayout({ vertical: true });
+        mainContentLayout.add(messageLayout,
+                              { y_align: St.Align.START });
+
+        this.subjectLabel = new St.Label({ style_class: 'mount-question-dialog-subject' });
+
+        messageLayout.add(this.subjectLabel,
+                          { y_fill:  false,
+                            y_align: St.Align.START });
+
+        this.descriptionLabel = new St.Label({ style_class: 'mount-question-dialog-description' });
+        this.descriptionLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
+        this.descriptionLabel.clutter_text.line_wrap = true;
+
+        messageLayout.add(this.descriptionLabel,
+                          { y_fill:  true,
+                            y_align: St.Align.START });
+    },
+
+    update: function(message, choices) {
+        _setLabelsForMessage(this, message);
+        _setButtonsForChoices(this, choices);
+    }
+}
+Signals.addSignalMethods(ShellMountQuestionDialog.prototype);
+
 function ShellProcessesDialog(icon) {
     this._init(icon);
 }
@@ -148,17 +243,17 @@ ShellProcessesDialog.prototype = {
         mainContentLayout.add(messageLayout,
                               { y_align: St.Align.START });
 
-        this._subjectLabel = new St.Label({ style_class: 'show-processes-dialog-subject' });
+        this.subjectLabel = new St.Label({ style_class: 'show-processes-dialog-subject' });
 
-        messageLayout.add(this._subjectLabel,
+        messageLayout.add(this.subjectLabel,
                           { y_fill:  false,
                             y_align: St.Align.START });
 
-        this._descriptionLabel = new St.Label({ style_class: 'show-processes-dialog-description' });
-        this._descriptionLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
-        this._descriptionLabel.clutter_text.line_wrap = true;
+        this.descriptionLabel = new St.Label({ style_class: 'show-processes-dialog-description' });
+        this.descriptionLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
+        this.descriptionLabel.clutter_text.line_wrap = true;
 
-        messageLayout.add(this._descriptionLabel,
+        messageLayout.add(this.descriptionLabel,
                           { y_fill:  true,
                             y_align: St.Align.START });
 
@@ -190,20 +285,6 @@ ShellProcessesDialog.prototype = {
                                       }));
     },
 
-    _setButtonsForChoices: function(choices) {
-        let buttons = [];
-
-        for (let idx = 0; idx < choices.length; idx++) {
-            let button = idx;
-            buttons.unshift({ label: choices[idx],
-                              action: Lang.bind(this, function() {
-                                  this.emit('choice-chosen', button);
-                              })});
-        }
-
-        this.setButtons(buttons);
-    },
-
     _setAppsForPids: function(pids) {
         // remove all the items
         this._applicationList.destroy_children();
@@ -221,23 +302,15 @@ ShellProcessesDialog.prototype = {
             item.connect('activate',
                          Lang.bind(this, function() {
                              // use -1 to indicate Cancel
-                             this.emit('choice-chosen', -1);
+                             this.emit('response', -1);
                          }));
         }));
     },
 
-    _setLabelsForMessage: function(message) {
-        let labels = message.split('\n');
-
-        _setLabelText(this._subjectLabel, labels[0]);
-        if (labels.length > 1)
-            _setLabelText(this._descriptionLabel, labels[1]);
-    },
-
     update: function(message, processes, choices) {
-        this._setLabelsForMessage(message);
         this._setAppsForPids(processes);
-        this._setButtonsForChoices(choices);
+        _setLabelsForMessage(this, message);
+        _setButtonsForChoices(this, choices);
     }
 }
 Signals.addSignalMethods(ShellProcessesDialog.prototype);
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]