Commit 4a4c1cf7 authored by Dan Pascu's avatar Dan Pascu

Use API level 2 for QString for better python integration

parent 9376ce46
......@@ -10,14 +10,17 @@ __date__ = 'October 26th, 2012'
import os
import sys
from collections import defaultdict
import sip
import cjson
sip.setapi('QString', 2)
from PyQt4.QtGui import QApplication
from application import log
from application.notification import IObserver, NotificationCenter, NotificationData
from application.python import Null
from application.system import host, makedirs, unlink
from collections import defaultdict
from eventlib import api
from gnutls.crypto import X509Certificate, X509PrivateKey
from gnutls.errors import GNUTLSError
......
......@@ -295,44 +295,44 @@ class AddAccountDialog(base_class, ui_class):
def _get_display_name(self):
if self.panel_view.currentWidget() is self.add_account_panel:
return unicode(self.display_name_editor.text())
return self.display_name_editor.text()
else:
return unicode(self.name_editor.text())
return self.name_editor.text()
def _set_display_name(self, value):
self.display_name_editor.setText(value)
self.name_editor.setText(value)
def _get_username(self):
return unicode(self.username_editor.text())
return self.username_editor.text()
def _set_username(self, value):
self.username_editor.setText(value)
def _get_sip_address(self):
return unicode(self.sip_address_editor.text())
return self.sip_address_editor.text()
def _set_sip_address(self, value):
self.sip_address_editor.setText(value)
def _get_password(self):
if self.panel_view.currentWidget() is self.add_account_panel:
return unicode(self.password_editor.text())
return self.password_editor.text()
else:
return unicode(self.new_password_editor.text())
return self.new_password_editor.text()
def _set_password(self, value):
self.password_editor.setText(value)
self.new_password_editor.setText(value)
def _get_verify_password(self):
return unicode(self.verify_password_editor.text())
return self.verify_password_editor.text()
def _set_verify_password(self, value):
self.verify_password_editor.setText(value)
def _get_email_address(self):
return unicode(self.email_address_editor.text())
return self.email_address_editor.text()
def _set_email_address(self, value):
self.email_address_editor.setText(value)
......@@ -372,7 +372,7 @@ class AddAccountDialog(base_class, ui_class):
self.accept_button.setEnabled(all(input.text_valid for input in inputs))
def _SH_PasswordTextChanged(self, text):
self.verify_password_editor.regexp = re.compile(u'^%s$' % re.escape(unicode(text)))
self.verify_password_editor.regexp = re.compile(u'^%s$' % re.escape(text))
def _SH_ValidityStatusChanged(self):
red = '#cc0000'
......@@ -590,7 +590,7 @@ class ServerToolsWebView(QWebView):
self.last_error = None
def _SH_URLChanged(self, url):
query_items = dict((unicode(name), unicode(value)) for name, value in url.queryItems())
query_items = dict(url.queryItems())
self.tab = query_items.get('tab') or self.tab
self.task = query_items.get('task') or self.task
......
......@@ -13,7 +13,7 @@ import socket
import sys
from PyQt4 import uic
from PyQt4.QtCore import Qt, QAbstractListModel, QByteArray, QEvent, QMimeData, QModelIndex, QPointF, QRectF, QRegExp, QSize, QStringList, pyqtSignal
from PyQt4.QtCore import Qt, QAbstractListModel, QByteArray, QEvent, QMimeData, QModelIndex, QPointF, QRectF, QRegExp, QSize, pyqtSignal
from PyQt4.QtGui import QBrush, QColor, QLinearGradient, QPainter, QPainterPath, QPalette, QPen, QPixmap, QPolygonF, QStyle
from PyQt4.QtGui import QAction, QKeyEvent, QListView, QMenu, QMouseEvent, QRegExpValidator, QSortFilterProxyModel, QStyledItemDelegate
......@@ -108,7 +108,7 @@ class ContactGroup(object):
@updates_contacts_db
def _name_changed(self):
self.name = unicode(self.widget.name_editor.text())
self.name = self.widget.name_editor.text()
def _get_widget(self):
return self.__dict__['widget']
......@@ -533,9 +533,9 @@ class GoogleContactsDialog(base_class, ui_class):
@run_in_green_thread
def _authorize_google_account(self):
red = '#cc0000'
captcha_response = unicode(self.captcha_editor.text()) if self.captcha_token else None
username = unicode(self.username_editor.text())
password = unicode(self.password_editor.text())
captcha_response = self.captcha_editor.text() if self.captcha_token else None
username = self.username_editor.text()
password = self.password_editor.text()
client = ContactsClient()
try:
client.client_login(email=username, password=password, source='Blink', captcha_token=self.captcha_token, captcha_response=captcha_response)
......@@ -640,7 +640,7 @@ class ContactGroupWidget(base_class, ui_class):
return self.name_view.currentWidget() is self.editor_widget
def _get_name(self):
return unicode(self.name_label.text())
return self.name_label.text()
def _set_name(self, value):
self.name_label.setText(value)
......@@ -935,7 +935,7 @@ class ContactModel(QAbstractListModel):
return Qt.CopyAction | Qt.MoveAction
def mimeTypes(self):
return QStringList(['application/x-blink-contact-list'])
return ['application/x-blink-contact-list']
def mimeData(self, indexes):
mime_data = QMimeData()
......@@ -1369,7 +1369,7 @@ class ContactSearchModel(QSortFilterProxyModel):
item = source_model.data(source_index, Qt.DisplayRole)
if isinstance(item, ContactGroup):
return False
search_tokens = unicode(self.filterRegExp().pattern()).lower().split()
search_tokens = self.filterRegExp().pattern().lower().split()
searched_item = unicode(item).lower()
return all(token in searched_item for token in search_tokens)
......@@ -1382,7 +1382,7 @@ class ContactSearchModel(QSortFilterProxyModel):
return Qt.CopyAction
def mimeTypes(self):
return QStringList(['application/x-blink-contact-list'])
return ['application/x-blink-contact-list']
def mimeData(self, indexes):
mime_data = QMimeData()
......@@ -2067,11 +2067,11 @@ class ContactEditorDialog(base_class, ui_class):
@updates_contacts_db
def process_contact(self):
contact_model = self.parent().contact_model
uri = unicode(self.sip_address_editor.text())
name = unicode(self.display_name_editor.text())
uri = self.sip_address_editor.text()
name = self.display_name_editor.text()
image = IconCache().store(self.icon_selector.filename)
preferred_media = unicode(self.preferred_media.currentText())
sip_aliases = [alias.strip() for alias in unicode(self.sip_aliases_editor.text()).split(u';')]
preferred_media = self.preferred_media.currentText()
sip_aliases = [alias.strip() for alias in self.sip_aliases_editor.text().split(u';')]
group_index = self.group.currentIndex()
group_name = self.group.currentText()
if group_name != self.group.itemText(group_index):
......@@ -2080,7 +2080,7 @@ class ContactEditorDialog(base_class, ui_class):
if index >= 0:
group = self.group.itemData(index).toPyObject()
else:
group = ContactGroup(unicode(group_name))
group = ContactGroup(group_name)
else:
group = self.group.itemData(group_index).toPyObject()
if self.edited_contact is None:
......
......@@ -381,7 +381,7 @@ class MainWindow(base_class, ui_class):
list_view = self.contact_list if self.contacts_view.currentWidget() is self.contact_list_panel else self.search_list
selected_indexes = list_view.selectionModel().selectedIndexes()
contact = list_view.model().data(selected_indexes[0]) if selected_indexes else Null
address = contact.uri or unicode(self.search_box.text())
address = contact.uri or self.search_box.text()
name = contact.name or None
session_manager = SessionManager()
session_manager.start_call(name, address, contact=contact, account=BonjourAccount() if isinstance(contact, BonjourNeighbour) else None)
......@@ -403,13 +403,13 @@ class MainWindow(base_class, ui_class):
self.enable_call_buttons(account_manager.default_account is not None and len(selected_items)==1 and isinstance(self.contact_model.data(selected_items[0]), Contact))
def _SH_ContactModelAddedItems(self, items):
if self.search_box.text().isEmpty():
if not self.search_box.text():
return
active_widget = self.search_list_panel if self.contact_search_model.rowCount() else self.not_found_panel
self.search_view.setCurrentWidget(active_widget)
def _SH_ContactModelRemovedItems(self, items):
if self.search_box.text().isEmpty():
if not self.search_box.text():
return
if any(type(item) is Contact for item in items) and self.contact_search_model.rowCount() == 0:
self.search_box.clear()
......@@ -421,7 +421,7 @@ class MainWindow(base_class, ui_class):
self.display_name.clearFocus()
index = self.identity.currentIndex()
if index != -1:
name = unicode(self.display_name.text())
name = self.display_name.text()
account = self.identity.itemData(index).toPyObject().account
account.display_name = name if name else None
account.save()
......@@ -459,7 +459,7 @@ class MainWindow(base_class, ui_class):
SIPApplication.voice_audio_bridge.mixer.muted = muted
def _SH_SearchBoxReturnPressed(self):
address = unicode(self.search_box.text())
address = self.search_box.text()
if address:
session_manager = SessionManager()
session_manager.start_call(None, address)
......@@ -469,17 +469,16 @@ class MainWindow(base_class, ui_class):
account_manager = AccountManager()
if text:
self.switch_view_button.view = SwitchViewButton.ContactView
if self.contacts_view.currentWidget() is not self.search_panel:
self.search_list.selectionModel().clearSelection()
self.contacts_view.setCurrentWidget(self.search_panel)
self.search_view.setCurrentWidget(self.search_list_panel if self.contact_search_model.rowCount() else self.not_found_panel)
selected_items = self.search_list.selectionModel().selectedIndexes()
self.enable_call_buttons(account_manager.default_account is not None and len(selected_items)<=1)
else:
self.contacts_view.setCurrentWidget(self.contact_list_panel)
selected_items = self.contact_list.selectionModel().selectedIndexes()
self.enable_call_buttons(account_manager.default_account is not None and len(selected_items)==1 and type(self.contact_model.data(selected_items[0])) is Contact)
active_widget = self.contact_list_panel if text.isEmpty() else self.search_panel
if active_widget is self.search_panel and self.contacts_view.currentWidget() is not self.search_panel:
self.search_list.selectionModel().clearSelection()
self.contacts_view.setCurrentWidget(active_widget)
active_widget = self.search_list_panel if self.contact_search_model.rowCount() else self.not_found_panel
self.search_view.setCurrentWidget(active_widget)
def _SH_SearchListSelectionChanged(self, selected, deselected):
account_manager = AccountManager()
......
This diff is collapsed.
......@@ -15,7 +15,7 @@ from functools import partial
from itertools import chain, izip, repeat
from PyQt4 import uic
from PyQt4.QtCore import Qt, QAbstractListModel, QByteArray, QEvent, QMimeData, QModelIndex, QObject, QSize, QStringList, QTimer, pyqtSignal
from PyQt4.QtCore import Qt, QAbstractListModel, QByteArray, QEvent, QMimeData, QModelIndex, QObject, QSize, QTimer, pyqtSignal
from PyQt4.QtGui import QApplication, QBrush, QColor, QDrag, QLinearGradient, QListView, QPainter, QPen, QPixmap, QShortcut, QStyledItemDelegate
from application.notification import IObserver, NotificationCenter
......@@ -999,7 +999,7 @@ class SessionModel(QAbstractListModel):
return Qt.CopyAction | Qt.MoveAction
def mimeTypes(self):
return QStringList(['application/x-blink-session-list'])
return ['application/x-blink-session-list']
def mimeData(self, indexes):
mime_data = QMimeData()
......
......@@ -40,7 +40,7 @@ class IconSelector(QLabel):
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton and self.rect().contains(event.pos()):
filename = unicode(QFileDialog.getOpenFileName(self, u'Select Icon', self.last_icon_directory, u"Images (*.png *.tiff *.jpg *.xmp *.svg)"))
filename = QFileDialog.getOpenFileName(self, u'Select Icon', self.last_icon_directory, u"Images (*.png *.tiff *.jpg *.xmp *.svg)")
if filename:
self.last_icon_directory = os.path.dirname(filename)
self.filename = filename if os.path.realpath(filename) != os.path.realpath(Resources.get(self.default_icon)) else None
......
......@@ -100,7 +100,7 @@ class LineEdit(QLineEdit):
def paintEvent(self, event):
QLineEdit.paintEvent(self, event)
if not self.hasFocus() and self.text().isEmpty() and self.inactiveText:
if not self.hasFocus() and not self.text() and self.inactiveText:
options = QStyleOptionFrameV2()
self.initStyleOption(options)
text_rect = self.style().subElementRect(QStyle.SE_LineEditContents, options, self)
......@@ -168,7 +168,7 @@ class ValidatingLineEdit(LineEdit):
self._validate()
def _validate(self):
text = unicode(self.text())
text = self.text()
text_correct = self.regexp.search(text) is not None
text_allowed = text not in self.exceptions
if self.text_correct != text_correct or self.text_allowed != text_allowed:
......@@ -277,7 +277,7 @@ class SearchBox(LineEdit):
self.inactiveText = u"Search"
def _SH_TextChanged(self, text):
self.clear_button.setVisible(not text.isEmpty())
self.clear_button.setVisible(bool(text))
class LocationBar(LineEdit):
......@@ -301,6 +301,6 @@ class LocationBar(LineEdit):
self.locationCleared.emit()
def _SH_TextChanged(self, text):
self.clear_button.setVisible(not text.isEmpty())
self.clear_button.setVisible(bool(text))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment