~dobey/ubuntuone-control-panel/update-13-10

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gui/qt/share_links_search.py

  • Committer: Tarmac
  • Author(s): Michael McCracken
  • Date: 2013-03-07 22:16:24 UTC
  • mfrom: (399.1.4 ubuntuone-control-panel)
  • Revision ID: tarmac-20130307221624-dg4cf23av4whra81
- Use Qt timers to delay and coalesce IPC for files search. (LP: #1150316)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
HOME_DIR = ''
37
37
AVOID_SECOND_ITEM = 2
38
38
NORMAL_INCREMENT = 1
 
39
SEARCH_TYPING_DELAY = 100       # msec
39
40
 
40
41
 
41
42
def get_system_icon_for_filename(file_path):
63
64
        self.current_results = []
64
65
        self.page_index = 0
65
66
        self.page_size = 20
66
 
        self.pending_call = None
67
67
        self._post_key_event = {
68
68
            QtCore.Qt.Key_Escape: lambda *args: self.popup.hide(),
69
69
            QtCore.Qt.Key_Down: self._key_down_pressed,
76
76
        self.popup.list_widget.verticalScrollBar().valueChanged.connect(
77
77
            self._scroll_fetch_more)
78
78
        self.textChanged.connect(self.handle_text_changed)
 
79
        self._do_search_timer = QtCore.QTimer()
 
80
        self._do_search_timer.timeout.connect(self._do_search)
 
81
        self._do_search_timer.setInterval(SEARCH_TYPING_DELAY)
 
82
        self._do_search_timer.setSingleShot(True)
79
83
 
80
84
        self._get_home_path()
81
85
 
94
98
    def handle_text_changed(self, text):
95
99
        """Use delayed IPC to search for filenames after user stops typing."""
96
100
 
97
 
        # Import here to avoid getting the wrong reactor due to import
98
 
        # order. Save in class var to ease patching for tests:
99
 
        if not self.qtreactor:
100
 
            self.qtreactor = __import__('twisted').internet.reactor
101
101
        text = unicode(text)
102
102
        self.page_index = 0
103
103
 
104
104
        if text == '':
105
105
            self.popup.hide()
106
 
            if self.pending_call and self.pending_call.active():
107
 
                self.pending_call.cancel()
108
 
            return
109
 
 
110
 
        if self.pending_call and self.pending_call.active():
111
 
            self.pending_call.reset(0.1)
112
 
            return
113
 
 
114
 
        self.pending_call = self.qtreactor.callLater(0.1, self._do_search)
 
106
            self._do_search_timer.stop()
 
107
            return
 
108
 
 
109
        self._do_search_timer.start(SEARCH_TYPING_DELAY)
115
110
 
116
111
    @inlineCallbacks
117
112
    def _do_search(self):
118
113
 
119
 
        self.pending_call = None
120
 
 
121
114
        search_text = unicode(self.text())
122
115
        results = yield self.backend.search_files(search_text)
123
116