summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
committerTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
commitcfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch)
tree18d94153a302445196fc0c18586abf44a1ce4a38 /Swift
parent1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff)
downloadswift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip
swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines in the process. Changed CheckTabs.py tool to disallow hard tabs in source files. Test-Information: Manually checked 30 random files that the conversion worked as expected. Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/AdHocController.cpp12
-rw-r--r--Swift/Controllers/AdHocController.h12
-rw-r--r--Swift/Controllers/AdHocManager.cpp96
-rw-r--r--Swift/Controllers/AdHocManager.h30
-rw-r--r--Swift/Controllers/BlockListController.cpp256
-rw-r--r--Swift/Controllers/BlockListController.h30
-rw-r--r--Swift/Controllers/CertificateMemoryStorageFactory.h24
-rw-r--r--Swift/Controllers/Chat/AutoAcceptMUCInviteDecider.h64
-rw-r--r--Swift/Controllers/Chat/ChatController.cpp696
-rw-r--r--Swift/Controllers/Chat/ChatController.h192
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.cpp562
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.h194
-rw-r--r--Swift/Controllers/Chat/ChatMessageParser.cpp346
-rw-r--r--Swift/Controllers/Chat/ChatMessageParser.h22
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp1594
-rw-r--r--Swift/Controllers/Chat/ChatsManager.h310
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp1796
-rw-r--r--Swift/Controllers/Chat/MUCController.h308
-rw-r--r--Swift/Controllers/Chat/MUCSearchController.cpp228
-rw-r--r--Swift/Controllers/Chat/MUCSearchController.h198
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp516
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp1592
-rw-r--r--Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp998
-rw-r--r--Swift/Controllers/Chat/UnitTest/MockChatListWindow.h28
-rw-r--r--Swift/Controllers/Chat/UserSearchController.cpp564
-rw-r--r--Swift/Controllers/Chat/UserSearchController.h132
-rw-r--r--Swift/Controllers/ChatMessageSummarizer.cpp52
-rw-r--r--Swift/Controllers/ChatMessageSummarizer.h8
-rw-r--r--Swift/Controllers/ConnectionSettings.h54
-rw-r--r--Swift/Controllers/Contact.cpp74
-rw-r--r--Swift/Controllers/Contact.h24
-rw-r--r--Swift/Controllers/ContactEditController.cpp124
-rw-r--r--Swift/Controllers/ContactEditController.h66
-rw-r--r--Swift/Controllers/ContactProvider.h6
-rw-r--r--Swift/Controllers/ContactSuggester.cpp62
-rw-r--r--Swift/Controllers/ContactSuggester.h40
-rw-r--r--Swift/Controllers/ContactsFromXMPPRoster.cpp18
-rw-r--r--Swift/Controllers/ContactsFromXMPPRoster.h18
-rw-r--r--Swift/Controllers/DummySoundPlayer.h8
-rw-r--r--Swift/Controllers/DummySystemTray.h12
-rw-r--r--Swift/Controllers/EventNotifier.cpp74
-rw-r--r--Swift/Controllers/EventNotifier.h50
-rw-r--r--Swift/Controllers/EventWindowController.cpp52
-rw-r--r--Swift/Controllers/EventWindowController.h24
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferController.cpp172
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferController.h68
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferOverview.cpp82
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferOverview.h28
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferProgressInfo.cpp18
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferProgressInfo.h14
-rw-r--r--Swift/Controllers/FileTransferListController.cpp34
-rw-r--r--Swift/Controllers/FileTransferListController.h14
-rw-r--r--Swift/Controllers/HighlightAction.cpp52
-rw-r--r--Swift/Controllers/HighlightAction.h118
-rw-r--r--Swift/Controllers/HighlightEditorController.cpp30
-rw-r--r--Swift/Controllers/HighlightEditorController.h40
-rw-r--r--Swift/Controllers/HighlightManager.cpp114
-rw-r--r--Swift/Controllers/HighlightManager.h112
-rw-r--r--Swift/Controllers/HighlightRule.cpp212
-rw-r--r--Swift/Controllers/HighlightRule.h112
-rw-r--r--Swift/Controllers/Highlighter.cpp32
-rw-r--r--Swift/Controllers/Highlighter.h32
-rw-r--r--Swift/Controllers/HistoryController.cpp26
-rw-r--r--Swift/Controllers/HistoryController.h32
-rw-r--r--Swift/Controllers/HistoryViewController.cpp530
-rw-r--r--Swift/Controllers/HistoryViewController.h84
-rw-r--r--Swift/Controllers/Intl.h2
-rw-r--r--Swift/Controllers/MainController.cpp1402
-rw-r--r--Swift/Controllers/MainController.h326
-rw-r--r--Swift/Controllers/PresenceNotifier.cpp168
-rw-r--r--Swift/Controllers/PresenceNotifier.h78
-rw-r--r--Swift/Controllers/PreviousStatusStore.cpp46
-rw-r--r--Swift/Controllers/PreviousStatusStore.h22
-rw-r--r--Swift/Controllers/ProfileController.cpp126
-rw-r--r--Swift/Controllers/ProfileController.h62
-rw-r--r--Swift/Controllers/ProfileSettingsProvider.cpp62
-rw-r--r--Swift/Controllers/ProfileSettingsProvider.h28
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.cpp120
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.h126
-rw-r--r--Swift/Controllers/Roster/FuzzyRosterFilter.h30
-rw-r--r--Swift/Controllers/Roster/GroupRosterItem.cpp304
-rw-r--r--Swift/Controllers/Roster/GroupRosterItem.h58
-rw-r--r--Swift/Controllers/Roster/ItemOperations/AppearOffline.h20
-rw-r--r--Swift/Controllers/Roster/ItemOperations/RosterItemOperation.h28
-rw-r--r--Swift/Controllers/Roster/ItemOperations/SetAvailableFeatures.h30
-rw-r--r--Swift/Controllers/Roster/ItemOperations/SetAvatar.h30
-rw-r--r--Swift/Controllers/Roster/ItemOperations/SetBlockingState.h48
-rw-r--r--Swift/Controllers/Roster/ItemOperations/SetMUC.h34
-rw-r--r--Swift/Controllers/Roster/ItemOperations/SetName.h30
-rw-r--r--Swift/Controllers/Roster/ItemOperations/SetPresence.h28
-rw-r--r--Swift/Controllers/Roster/ItemOperations/SetVCard.h30
-rw-r--r--Swift/Controllers/Roster/LeastCommonSubsequence.h170
-rw-r--r--Swift/Controllers/Roster/OfflineRosterFilter.h12
-rw-r--r--Swift/Controllers/Roster/Roster.cpp364
-rw-r--r--Swift/Controllers/Roster/Roster.h74
-rw-r--r--Swift/Controllers/Roster/RosterController.cpp516
-rw-r--r--Swift/Controllers/Roster/RosterController.h186
-rw-r--r--Swift/Controllers/Roster/RosterFilter.h6
-rw-r--r--Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp54
-rw-r--r--Swift/Controllers/Roster/RosterGroupExpandinessPersister.h24
-rw-r--r--Swift/Controllers/Roster/RosterItem.cpp20
-rw-r--r--Swift/Controllers/Roster/RosterItem.h24
-rw-r--r--Swift/Controllers/Roster/RosterVCardProvider.cpp14
-rw-r--r--Swift/Controllers/Roster/RosterVCardProvider.h28
-rw-r--r--Swift/Controllers/Roster/TableRoster.cpp278
-rw-r--r--Swift/Controllers/Roster/TableRoster.h132
-rw-r--r--Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp558
-rw-r--r--Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp684
-rw-r--r--Swift/Controllers/Roster/UnitTest/RosterTest.cpp248
-rw-r--r--Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp126
-rw-r--r--Swift/Controllers/SettingConstants.h192
-rw-r--r--Swift/Controllers/Settings/DummySettingsProvider.h76
-rw-r--r--Swift/Controllers/Settings/SettingsProvider.h102
-rw-r--r--Swift/Controllers/Settings/SettingsProviderHierachy.cpp120
-rw-r--r--Swift/Controllers/Settings/SettingsProviderHierachy.h56
-rw-r--r--Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp118
-rw-r--r--Swift/Controllers/Settings/XMLSettingsProvider.cpp114
-rw-r--r--Swift/Controllers/Settings/XMLSettingsProvider.h68
-rw-r--r--Swift/Controllers/ShowProfileController.cpp72
-rw-r--r--Swift/Controllers/ShowProfileController.h42
-rw-r--r--Swift/Controllers/SoundEventController.cpp38
-rw-r--r--Swift/Controllers/SoundEventController.h36
-rw-r--r--Swift/Controllers/SoundPlayer.h12
-rw-r--r--Swift/Controllers/StatusCache.cpp118
-rw-r--r--Swift/Controllers/StatusCache.h36
-rw-r--r--Swift/Controllers/StatusTracker.cpp56
-rw-r--r--Swift/Controllers/StatusTracker.h24
-rw-r--r--Swift/Controllers/StatusUtil.cpp20
-rw-r--r--Swift/Controllers/StatusUtil.h2
-rw-r--r--Swift/Controllers/Storages/AvatarFileStorage.cpp122
-rw-r--r--Swift/Controllers/Storages/AvatarFileStorage.h38
-rw-r--r--Swift/Controllers/Storages/CapsFileStorage.cpp10
-rw-r--r--Swift/Controllers/Storages/CapsFileStorage.h20
-rw-r--r--Swift/Controllers/Storages/CertificateFileStorage.cpp60
-rw-r--r--Swift/Controllers/Storages/CertificateFileStorage.h28
-rw-r--r--Swift/Controllers/Storages/CertificateFileStorageFactory.h28
-rw-r--r--Swift/Controllers/Storages/CertificateMemoryStorage.cpp14
-rw-r--r--Swift/Controllers/Storages/CertificateMemoryStorage.h16
-rw-r--r--Swift/Controllers/Storages/CertificateStorage.h12
-rw-r--r--Swift/Controllers/Storages/CertificateStorageFactory.h14
-rw-r--r--Swift/Controllers/Storages/CertificateStorageTrustChecker.h36
-rw-r--r--Swift/Controllers/Storages/FileStorages.cpp36
-rw-r--r--Swift/Controllers/Storages/FileStorages.h80
-rw-r--r--Swift/Controllers/Storages/FileStoragesFactory.h22
-rw-r--r--Swift/Controllers/Storages/MemoryStoragesFactory.h22
-rw-r--r--Swift/Controllers/Storages/RosterFileStorage.cpp4
-rw-r--r--Swift/Controllers/Storages/RosterFileStorage.h16
-rw-r--r--Swift/Controllers/Storages/StoragesFactory.h14
-rw-r--r--Swift/Controllers/Storages/VCardFileStorage.cpp150
-rw-r--r--Swift/Controllers/Storages/VCardFileStorage.h40
-rw-r--r--Swift/Controllers/SystemTray.h14
-rw-r--r--Swift/Controllers/SystemTrayController.cpp28
-rw-r--r--Swift/Controllers/SystemTrayController.h26
-rw-r--r--Swift/Controllers/Translator.cpp8
-rw-r--r--Swift/Controllers/Translator.h22
-rw-r--r--Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h16
-rw-r--r--Swift/Controllers/UIEvents/AddContactUIEvent.h42
-rw-r--r--Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h14
-rw-r--r--Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h16
-rw-r--r--Swift/Controllers/UIEvents/CreateImpromptuMUCUIEvent.h18
-rw-r--r--Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h18
-rw-r--r--Swift/Controllers/UIEvents/InviteToMUCUIEvent.h48
-rw-r--r--Swift/Controllers/UIEvents/JoinMUCUIEvent.h40
-rw-r--r--Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h14
-rw-r--r--Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h12
-rw-r--r--Swift/Controllers/UIEvents/RenameGroupUIEvent.h28
-rw-r--r--Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h18
-rw-r--r--Swift/Controllers/UIEvents/RequestAdHocUIEvent.h14
-rw-r--r--Swift/Controllers/UIEvents/RequestAdHocWithJIDUIEvent.h18
-rw-r--r--Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h20
-rw-r--r--Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h38
-rw-r--r--Swift/Controllers/UIEvents/RequestChatUIEvent.h14
-rw-r--r--Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h4
-rw-r--r--Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h22
-rw-r--r--Swift/Controllers/UIEvents/RequestHighlightEditorUIEvent.h4
-rw-r--r--Swift/Controllers/UIEvents/RequestHistoryUIEvent.h4
-rw-r--r--Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h60
-rw-r--r--Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h22
-rw-r--r--Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h8
-rw-r--r--Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h14
-rw-r--r--Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h4
-rw-r--r--Swift/Controllers/UIEvents/SendFileUIEvent.h38
-rw-r--r--Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h16
-rw-r--r--Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h14
-rw-r--r--Swift/Controllers/UIEvents/UIEvent.h10
-rw-r--r--Swift/Controllers/UIEvents/UIEventStream.h14
-rw-r--r--Swift/Controllers/UIInterfaces/AdHocCommandWindow.h12
-rw-r--r--Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h10
-rw-r--r--Swift/Controllers/UIInterfaces/BlockListEditorWidget.h24
-rw-r--r--Swift/Controllers/UIInterfaces/BlockListEditorWidgetFactory.h12
-rw-r--r--Swift/Controllers/UIInterfaces/ChatListWindow.h154
-rw-r--r--Swift/Controllers/UIInterfaces/ChatListWindowFactory.h12
-rw-r--r--Swift/Controllers/UIInterfaces/ChatWindow.h456
-rw-r--r--Swift/Controllers/UIInterfaces/ChatWindowFactory.h20
-rw-r--r--Swift/Controllers/UIInterfaces/ContactEditWindow.h26
-rw-r--r--Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h10
-rw-r--r--Swift/Controllers/UIInterfaces/EventWindow.h24
-rw-r--r--Swift/Controllers/UIInterfaces/EventWindowFactory.h18
-rw-r--r--Swift/Controllers/UIInterfaces/FileTransferListWidget.h8
-rw-r--r--Swift/Controllers/UIInterfaces/FileTransferListWidgetFactory.h4
-rw-r--r--Swift/Controllers/UIInterfaces/HighlightEditorWidget.h14
-rw-r--r--Swift/Controllers/UIInterfaces/HighlightEditorWidgetFactory.h12
-rw-r--r--Swift/Controllers/UIInterfaces/HighlightEditorWindow.h12
-rw-r--r--Swift/Controllers/UIInterfaces/HighlightEditorWindowFactory.h12
-rw-r--r--Swift/Controllers/UIInterfaces/HistoryWindow.h38
-rw-r--r--Swift/Controllers/UIInterfaces/HistoryWindowFactory.h12
-rw-r--r--Swift/Controllers/UIInterfaces/JoinMUCWindow.h16
-rw-r--r--Swift/Controllers/UIInterfaces/JoinMUCWindowFactory.h12
-rw-r--r--Swift/Controllers/UIInterfaces/LoginWindow.h44
-rw-r--r--Swift/Controllers/UIInterfaces/LoginWindowFactory.h28
-rw-r--r--Swift/Controllers/UIInterfaces/MUCSearchWindow.h22
-rw-r--r--Swift/Controllers/UIInterfaces/MUCSearchWindowFactory.h12
-rw-r--r--Swift/Controllers/UIInterfaces/MainWindow.h64
-rw-r--r--Swift/Controllers/UIInterfaces/MainWindowFactory.h18
-rw-r--r--Swift/Controllers/UIInterfaces/ProfileWindow.h30
-rw-r--r--Swift/Controllers/UIInterfaces/ProfileWindowFactory.h10
-rw-r--r--Swift/Controllers/UIInterfaces/UIFactory.h42
-rw-r--r--Swift/Controllers/UIInterfaces/UserSearchWindow.h72
-rw-r--r--Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h12
-rw-r--r--Swift/Controllers/UIInterfaces/WhiteboardWindow.h20
-rw-r--r--Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h14
-rw-r--r--Swift/Controllers/UIInterfaces/XMLConsoleWidget.h16
-rw-r--r--Swift/Controllers/UIInterfaces/XMLConsoleWidgetFactory.h12
-rw-r--r--Swift/Controllers/UnitTest/ChatMessageSummarizerTest.cpp202
-rw-r--r--Swift/Controllers/UnitTest/ContactSuggesterTest.cpp204
-rw-r--r--Swift/Controllers/UnitTest/HighlightRuleTest.cpp484
-rw-r--r--Swift/Controllers/UnitTest/MockChatWindow.h196
-rw-r--r--Swift/Controllers/UnitTest/MockMainWindow.h38
-rw-r--r--Swift/Controllers/UnitTest/MockMainWindowFactory.h24
-rw-r--r--Swift/Controllers/UnitTest/PresenceNotifierTest.cpp520
-rw-r--r--Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp40
-rw-r--r--Swift/Controllers/WhiteboardManager.cpp224
-rw-r--r--Swift/Controllers/WhiteboardManager.h62
-rw-r--r--Swift/Controllers/XMLConsoleController.cpp32
-rw-r--r--Swift/Controllers/XMLConsoleController.h40
-rw-r--r--Swift/Controllers/XMPPEvents/ErrorEvent.h22
-rw-r--r--Swift/Controllers/XMPPEvents/EventController.cpp72
-rw-r--r--Swift/Controllers/XMPPEvents/EventController.h34
-rw-r--r--Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h20
-rw-r--r--Swift/Controllers/XMPPEvents/MUCInviteEvent.h44
-rw-r--r--Swift/Controllers/XMPPEvents/MessageEvent.h46
-rw-r--r--Swift/Controllers/XMPPEvents/StanzaEvent.h28
-rw-r--r--Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h52
-rw-r--r--Swift/Controllers/XMPPURIController.cpp22
-rw-r--r--Swift/Controllers/XMPPURIController.h30
-rw-r--r--Swift/QtUI/ApplicationTest/main.cpp44
-rw-r--r--Swift/QtUI/CAPICertificateSelector.cpp114
-rw-r--r--Swift/QtUI/CAPICertificateSelector.h4
-rw-r--r--Swift/QtUI/ChatList/ChatListDelegate.cpp184
-rw-r--r--Swift/QtUI/ChatList/ChatListDelegate.h42
-rw-r--r--Swift/QtUI/ChatList/ChatListGroupItem.h58
-rw-r--r--Swift/QtUI/ChatList/ChatListItem.h20
-rw-r--r--Swift/QtUI/ChatList/ChatListMUCItem.cpp24
-rw-r--r--Swift/QtUI/ChatList/ChatListMUCItem.h30
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.cpp228
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.h66
-rw-r--r--Swift/QtUI/ChatList/ChatListRecentItem.cpp26
-rw-r--r--Swift/QtUI/ChatList/ChatListRecentItem.h32
-rw-r--r--Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp50
-rw-r--r--Swift/QtUI/ChatList/ChatListWhiteboardItem.h30
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.cpp248
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.h84
-rw-r--r--Swift/QtUI/ChatSnippet.cpp116
-rw-r--r--Swift/QtUI/ChatSnippet.h100
-rw-r--r--Swift/QtUI/ChatView/main.cpp260
-rw-r--r--Swift/QtUI/CocoaApplicationActivateHelper.h28
-rw-r--r--Swift/QtUI/CocoaApplicationActivateHelper.mm32
-rw-r--r--Swift/QtUI/CocoaUIHelpers.h2
-rw-r--r--Swift/QtUI/CocoaUIHelpers.mm34
-rw-r--r--Swift/QtUI/EventViewer/EventDelegate.cpp106
-rw-r--r--Swift/QtUI/EventViewer/EventDelegate.h32
-rw-r--r--Swift/QtUI/EventViewer/EventModel.cpp126
-rw-r--r--Swift/QtUI/EventViewer/EventModel.h30
-rw-r--r--Swift/QtUI/EventViewer/EventView.cpp2
-rw-r--r--Swift/QtUI/EventViewer/EventView.h10
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.cpp128
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.h28
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindow.cpp140
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindow.h42
-rw-r--r--Swift/QtUI/EventViewer/TwoLineDelegate.cpp70
-rw-r--r--Swift/QtUI/EventViewer/TwoLineDelegate.h24
-rw-r--r--Swift/QtUI/EventViewer/main.cpp26
-rw-r--r--Swift/QtUI/FreeDesktopNotifier.cpp62
-rw-r--r--Swift/QtUI/FreeDesktopNotifier.h18
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp96
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchDelegate.h22
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp30
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h18
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchItem.h10
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchModel.cpp104
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchModel.h34
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp12
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchRoomItem.h22
-rw-r--r--Swift/QtUI/MUCSearch/MUCSearchServiceItem.h34
-rw-r--r--Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp238
-rw-r--r--Swift/QtUI/MUCSearch/QtMUCSearchWindow.h74
-rw-r--r--Swift/QtUI/MessageSnippet.cpp54
-rw-r--r--Swift/QtUI/MessageSnippet.h26
-rw-r--r--Swift/QtUI/NotifierTest/NotifierTest.cpp10
-rw-r--r--Swift/QtUI/QtAboutWidget.cpp98
-rw-r--r--Swift/QtUI/QtAboutWidget.h14
-rw-r--r--Swift/QtUI/QtAdHocCommandWindow.cpp222
-rw-r--r--Swift/QtUI/QtAdHocCommandWindow.h74
-rw-r--r--Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp46
-rw-r--r--Swift/QtUI/QtAdHocCommandWithJIDWindow.h30
-rw-r--r--Swift/QtUI/QtAddBookmarkWindow.cpp22
-rw-r--r--Swift/QtUI/QtAddBookmarkWindow.h18
-rw-r--r--Swift/QtUI/QtAffiliationEditor.cpp78
-rw-r--r--Swift/QtUI/QtAffiliationEditor.h36
-rw-r--r--Swift/QtUI/QtAvatarWidget.cpp146
-rw-r--r--Swift/QtUI/QtAvatarWidget.h64
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.cpp290
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.h48
-rw-r--r--Swift/QtUI/QtBookmarkDetailWindow.cpp94
-rw-r--r--Swift/QtUI/QtBookmarkDetailWindow.h26
-rw-r--r--Swift/QtUI/QtCachedImageScaler.cpp38
-rw-r--r--Swift/QtUI/QtCachedImageScaler.h10
-rw-r--r--Swift/QtUI/QtCertificateViewerDialog.cpp178
-rw-r--r--Swift/QtUI/QtCertificateViewerDialog.h28
-rw-r--r--Swift/QtUI/QtChatTabs.cpp618
-rw-r--r--Swift/QtUI/QtChatTabs.h114
-rw-r--r--Swift/QtUI/QtChatTabsBase.h8
-rw-r--r--Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp98
-rw-r--r--Swift/QtUI/QtChatTabsShortcutOnlySubstitute.h28
-rw-r--r--Swift/QtUI/QtChatTheme.cpp88
-rw-r--r--Swift/QtUI/QtChatTheme.h54
-rw-r--r--Swift/QtUI/QtChatView.cpp2
-rw-r--r--Swift/QtUI/QtChatView.h76
-rw-r--r--Swift/QtUI/QtChatWindow.cpp1270
-rw-r--r--Swift/QtUI/QtChatWindow.h398
-rw-r--r--Swift/QtUI/QtChatWindowFactory.cpp88
-rw-r--r--Swift/QtUI/QtChatWindowFactory.h48
-rw-r--r--Swift/QtUI/QtChatWindowJSBridge.cpp4
-rw-r--r--Swift/QtUI/QtChatWindowJSBridge.h8
-rw-r--r--Swift/QtUI/QtClickableLabel.cpp2
-rw-r--r--Swift/QtUI/QtClickableLabel.h16
-rw-r--r--Swift/QtUI/QtClosableLineEdit.cpp48
-rw-r--r--Swift/QtUI/QtClosableLineEdit.h22
-rw-r--r--Swift/QtUI/QtColorToolButton.cpp30
-rw-r--r--Swift/QtUI/QtColorToolButton.h36
-rw-r--r--Swift/QtUI/QtConnectionSettingsWindow.cpp260
-rw-r--r--Swift/QtUI/QtConnectionSettingsWindow.h42
-rw-r--r--Swift/QtUI/QtContactEditWidget.cpp248
-rw-r--r--Swift/QtUI/QtContactEditWidget.h64
-rw-r--r--Swift/QtUI/QtContactEditWindow.cpp102
-rw-r--r--Swift/QtUI/QtContactEditWindow.h42
-rw-r--r--Swift/QtUI/QtDBUSURIHandler.cpp38
-rw-r--r--Swift/QtUI/QtDBUSURIHandler.h8
-rw-r--r--Swift/QtUI/QtEditBookmarkWindow.cpp22
-rw-r--r--Swift/QtUI/QtEditBookmarkWindow.h20
-rw-r--r--Swift/QtUI/QtElidingLabel.cpp56
-rw-r--r--Swift/QtUI/QtElidingLabel.h34
-rw-r--r--Swift/QtUI/QtEmoticonCell.cpp14
-rw-r--r--Swift/QtUI/QtEmoticonCell.h26
-rw-r--r--Swift/QtUI/QtEmoticonsGrid.cpp50
-rw-r--r--Swift/QtUI/QtEmoticonsGrid.h26
-rw-r--r--Swift/QtUI/QtFileTransferListItemModel.cpp152
-rw-r--r--Swift/QtUI/QtFileTransferListItemModel.h46
-rw-r--r--Swift/QtUI/QtFileTransferListWidget.cpp94
-rw-r--r--Swift/QtUI/QtFileTransferListWidget.h30
-rw-r--r--Swift/QtUI/QtFormResultItemModel.cpp80
-rw-r--r--Swift/QtUI/QtFormResultItemModel.h28
-rw-r--r--Swift/QtUI/QtFormWidget.cpp374
-rw-r--r--Swift/QtUI/QtFormWidget.h26
-rw-r--r--Swift/QtUI/QtHighlightEditor.cpp782
-rw-r--r--Swift/QtUI/QtHighlightEditor.h90
-rw-r--r--Swift/QtUI/QtHistoryWindow.cpp312
-rw-r--r--Swift/QtUI/QtHistoryWindow.h114
-rw-r--r--Swift/QtUI/QtJoinMUCWindow.cpp66
-rw-r--r--Swift/QtUI/QtJoinMUCWindow.h112
-rw-r--r--Swift/QtUI/QtLineEdit.cpp8
-rw-r--r--Swift/QtUI/QtLineEdit.h18
-rw-r--r--Swift/QtUI/QtLoginWindow.cpp750
-rw-r--r--Swift/QtUI/QtLoginWindow.h156
-rw-r--r--Swift/QtUI/QtMUCConfigurationWindow.cpp62
-rw-r--r--Swift/QtUI/QtMUCConfigurationWindow.h38
-rw-r--r--Swift/QtUI/QtMainWindow.cpp496
-rw-r--r--Swift/QtUI/QtMainWindow.h154
-rw-r--r--Swift/QtUI/QtNameWidget.cpp114
-rw-r--r--Swift/QtUI/QtNameWidget.h66
-rw-r--r--Swift/QtUI/QtPlainChatView.cpp598
-rw-r--r--Swift/QtUI/QtPlainChatView.h216
-rw-r--r--Swift/QtUI/QtProfileWindow.cpp174
-rw-r--r--Swift/QtUI/QtProfileWindow.h50
-rw-r--r--Swift/QtUI/QtResourceHelper.cpp20
-rw-r--r--Swift/QtUI/QtRosterHeader.cpp152
-rw-r--r--Swift/QtUI/QtRosterHeader.h72
-rw-r--r--Swift/QtUI/QtScaledAvatarCache.cpp66
-rw-r--r--Swift/QtUI/QtScaledAvatarCache.h14
-rw-r--r--Swift/QtUI/QtSettingsProvider.cpp120
-rw-r--r--Swift/QtUI/QtSettingsProvider.h44
-rw-r--r--Swift/QtUI/QtSingleWindow.cpp60
-rw-r--r--Swift/QtUI/QtSingleWindow.h46
-rw-r--r--Swift/QtUI/QtSoundPlayer.cpp32
-rw-r--r--Swift/QtUI/QtSoundPlayer.h24
-rw-r--r--Swift/QtUI/QtSpellCheckHighlighter.cpp20
-rw-r--r--Swift/QtUI/QtSpellCheckHighlighter.h14
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.cpp120
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.h40
-rw-r--r--Swift/QtUI/QtStatusWidget.cpp424
-rw-r--r--Swift/QtUI/QtStatusWidget.h98
-rw-r--r--Swift/QtUI/QtSubscriptionRequestWindow.cpp98
-rw-r--r--Swift/QtUI/QtSubscriptionRequestWindow.h36
-rw-r--r--Swift/QtUI/QtSwift.cpp332
-rw-r--r--Swift/QtUI/QtSwift.h118
-rw-r--r--Swift/QtUI/QtSystemTray.cpp86
-rw-r--r--Swift/QtUI/QtSystemTray.h60
-rw-r--r--Swift/QtUI/QtTabWidget.cpp4
-rw-r--r--Swift/QtUI/QtTabWidget.h16
-rw-r--r--Swift/QtUI/QtTabbable.cpp58
-rw-r--r--Swift/QtUI/QtTabbable.h46
-rw-r--r--Swift/QtUI/QtTextEdit.cpp290
-rw-r--r--Swift/QtUI/QtTextEdit.h86
-rw-r--r--Swift/QtUI/QtTranslator.h14
-rw-r--r--Swift/QtUI/QtUIFactory.cpp150
-rw-r--r--Swift/QtUI/QtUIFactory.h122
-rw-r--r--Swift/QtUI/QtUISettingConstants.h24
-rw-r--r--Swift/QtUI/QtURIHandler.cpp18
-rw-r--r--Swift/QtUI/QtURIHandler.h12
-rw-r--r--Swift/QtUI/QtURLValidator.cpp8
-rw-r--r--Swift/QtUI/QtURLValidator.h12
-rw-r--r--Swift/QtUI/QtUtilities.cpp20
-rw-r--r--Swift/QtUI/QtUtilities.h14
-rw-r--r--Swift/QtUI/QtVCardWidget/QtCloseButton.cpp32
-rw-r--r--Swift/QtUI/QtVCardWidget/QtCloseButton.h18
-rw-r--r--Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp50
-rw-r--r--Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h18
-rw-r--r--Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp38
-rw-r--r--Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h28
-rw-r--r--Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp104
-rw-r--r--Swift/QtUI/QtVCardWidget/QtTagComboBox.h40
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp234
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressField.h72
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp106
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h36
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp40
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h30
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp50
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h28
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h64
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp172
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h122
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp14
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h20
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp78
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h30
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp60
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardJIDField.h30
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp172
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h44
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp120
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h60
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp24
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardRoleField.h28
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp122
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h28
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp26
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardTitleField.h28
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp60
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardURLField.h30
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp666
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardWidget.h82
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp1344
-rw-r--r--Swift/QtUI/QtWebKitChatView.h328
-rw-r--r--Swift/QtUI/QtWebView.cpp102
-rw-r--r--Swift/QtUI/QtWebView.h44
-rw-r--r--Swift/QtUI/QtWin32NotifierWindow.h26
-rw-r--r--Swift/QtUI/QtXMLConsoleWidget.cpp116
-rw-r--r--Swift/QtUI/QtXMLConsoleWidget.h36
-rw-r--r--Swift/QtUI/Roster/DelegateCommons.cpp168
-rw-r--r--Swift/QtUI/Roster/DelegateCommons.h44
-rw-r--r--Swift/QtUI/Roster/GroupItemDelegate.cpp164
-rw-r--r--Swift/QtUI/Roster/GroupItemDelegate.h26
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.cpp210
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.h52
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.cpp74
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.h20
-rw-r--r--Swift/QtUI/Roster/QtRosterWidget.cpp208
-rw-r--r--Swift/QtUI/Roster/QtRosterWidget.h20
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp300
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h92
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp66
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.h36
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp332
-rw-r--r--Swift/QtUI/Roster/RosterModel.h102
-rw-r--r--Swift/QtUI/Roster/RosterTooltip.cpp260
-rw-r--r--Swift/QtUI/Roster/RosterTooltip.h10
-rw-r--r--Swift/QtUI/Roster/main.cpp88
-rw-r--r--Swift/QtUI/SystemMessageSnippet.cpp20
-rw-r--r--Swift/QtUI/SystemMessageSnippet.h22
-rw-r--r--Swift/QtUI/Trellis/QtDNDTabBar.cpp218
-rw-r--r--Swift/QtUI/Trellis/QtDNDTabBar.h50
-rw-r--r--Swift/QtUI/Trellis/QtDynamicGridLayout.cpp748
-rw-r--r--Swift/QtUI/Trellis/QtDynamicGridLayout.h94
-rw-r--r--Swift/QtUI/Trellis/QtGridSelectionDialog.cpp188
-rw-r--r--Swift/QtUI/Trellis/QtGridSelectionDialog.h86
-rw-r--r--Swift/QtUI/UserSearch/ContactListDelegate.cpp34
-rw-r--r--Swift/QtUI/UserSearch/ContactListDelegate.h20
-rw-r--r--Swift/QtUI/UserSearch/ContactListModel.cpp140
-rw-r--r--Swift/QtUI/UserSearch/ContactListModel.h72
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.cpp80
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.h34
-rw-r--r--Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp274
-rw-r--r--Swift/QtUI/UserSearch/QtSuggestingJIDInput.h56
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp20
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h36
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFieldsPage.cpp32
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFieldsPage.h24
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp108
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h62
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp50
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstPage.h30
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchResultsPage.cpp32
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchResultsPage.h22
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp888
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.h160
-rw-r--r--Swift/QtUI/UserSearch/UserSearchDelegate.cpp72
-rw-r--r--Swift/QtUI/UserSearch/UserSearchDelegate.h24
-rw-r--r--Swift/QtUI/UserSearch/UserSearchModel.cpp86
-rw-r--r--Swift/QtUI/UserSearch/UserSearchModel.h46
-rw-r--r--Swift/QtUI/Whiteboard/ColorWidget.cpp46
-rw-r--r--Swift/QtUI/Whiteboard/ColorWidget.h30
-rw-r--r--Swift/QtUI/Whiteboard/FreehandLineItem.cpp150
-rw-r--r--Swift/QtUI/Whiteboard/FreehandLineItem.h36
-rw-r--r--Swift/QtUI/Whiteboard/GView.cpp970
-rw-r--r--Swift/QtUI/Whiteboard/GView.h102
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp730
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.h106
-rw-r--r--Swift/QtUI/Whiteboard/TextDialog.cpp84
-rw-r--r--Swift/QtUI/Whiteboard/TextDialog.h44
-rw-r--r--Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h336
-rw-r--r--Swift/QtUI/WinUIHelpers.cpp66
-rw-r--r--Swift/QtUI/WinUIHelpers.h2
-rw-r--r--Swift/QtUI/WindowsNotifier.cpp40
-rw-r--r--Swift/QtUI/WindowsNotifier.h30
-rw-r--r--Swift/QtUI/main.cpp96
-rw-r--r--Swift/QtUI/swift-open-uri.cpp26
537 files changed, 29097 insertions, 29097 deletions
diff --git a/Swift/Controllers/AdHocController.cpp b/Swift/Controllers/AdHocController.cpp
index 38b0fc5..4b93f2b 100644
--- a/Swift/Controllers/AdHocController.cpp
+++ b/Swift/Controllers/AdHocController.cpp
@@ -13,21 +13,21 @@
namespace Swift {
AdHocController::AdHocController(AdHocCommandWindowFactory* factory, boost::shared_ptr<OutgoingAdHocCommandSession> command) {
- window_ = factory->createAdHocCommandWindow(command);
- window_->onClosing.connect(boost::bind(&AdHocController::handleWindowClosed, this));
+ window_ = factory->createAdHocCommandWindow(command);
+ window_->onClosing.connect(boost::bind(&AdHocController::handleWindowClosed, this));
}
AdHocController::~AdHocController() {
- window_->onClosing.disconnect(boost::bind(&AdHocController::handleWindowClosed, this));
- delete window_;
+ window_->onClosing.disconnect(boost::bind(&AdHocController::handleWindowClosed, this));
+ delete window_;
}
void AdHocController::setOnline(bool online) {
- window_->setOnline(online);
+ window_->setOnline(online);
}
void AdHocController::handleWindowClosed() {
- onDeleting();
+ onDeleting();
}
}
diff --git a/Swift/Controllers/AdHocController.h b/Swift/Controllers/AdHocController.h
index e2b93df..4694991 100644
--- a/Swift/Controllers/AdHocController.h
+++ b/Swift/Controllers/AdHocController.h
@@ -17,13 +17,13 @@ class AdHocCommandWindow;
class AdHocController {
public:
- AdHocController(AdHocCommandWindowFactory* factory, boost::shared_ptr<OutgoingAdHocCommandSession> command);
- ~AdHocController();
- boost::signal<void ()> onDeleting;
- void setOnline(bool online);
+ AdHocController(AdHocCommandWindowFactory* factory, boost::shared_ptr<OutgoingAdHocCommandSession> command);
+ ~AdHocController();
+ boost::signal<void ()> onDeleting;
+ void setOnline(bool online);
private:
- void handleWindowClosed();
- AdHocCommandWindow* window_;
+ void handleWindowClosed();
+ AdHocCommandWindow* window_;
};
}
diff --git a/Swift/Controllers/AdHocManager.cpp b/Swift/Controllers/AdHocManager.cpp
index 4733b57..1dcefbd 100644
--- a/Swift/Controllers/AdHocManager.cpp
+++ b/Swift/Controllers/AdHocManager.cpp
@@ -23,73 +23,73 @@
namespace Swift {
AdHocManager::AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow) : jid_(jid) {
- iqRouter_ = iqRouter;
- uiEventStream_ = uiEventStream;
- mainWindow_ = mainWindow;
- factory_ = factory;
+ iqRouter_ = iqRouter;
+ uiEventStream_ = uiEventStream;
+ mainWindow_ = mainWindow;
+ factory_ = factory;
- uiEventStream_->onUIEvent.connect(boost::bind(&AdHocManager::handleUIEvent, this, _1));
+ uiEventStream_->onUIEvent.connect(boost::bind(&AdHocManager::handleUIEvent, this, _1));
}
AdHocManager::~AdHocManager() {
- uiEventStream_->onUIEvent.disconnect(boost::bind(&AdHocManager::handleUIEvent, this, _1));
- for (size_t i = 0; i < controllers_.size(); ++i) {
- controllers_[i]->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controllers_[i]));
- }
+ uiEventStream_->onUIEvent.disconnect(boost::bind(&AdHocManager::handleUIEvent, this, _1));
+ for (size_t i = 0; i < controllers_.size(); ++i) {
+ controllers_[i]->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controllers_[i]));
+ }
}
void AdHocManager::removeController(boost::shared_ptr<AdHocController> controller) {
- controller->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controller));
- controllers_.erase(std::find(controllers_.begin(), controllers_.end(), controller));
+ controller->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controller));
+ controllers_.erase(std::find(controllers_.begin(), controllers_.end(), controller));
}
void AdHocManager::setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info) {
- if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::CommandsFeature)) {
- if (discoItemsRequest_) {
- discoItemsRequest_->onResponse.disconnect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2));
- discoItemsRequest_.reset();
- }
- discoItemsRequest_ = GetDiscoItemsRequest::create(JID(jid_.getDomain()), DiscoInfo::CommandsFeature, iqRouter_);
- discoItemsRequest_->onResponse.connect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2));
- discoItemsRequest_->send();
- } else {
- mainWindow_->setAvailableAdHocCommands(std::vector<DiscoItems::Item>());
- }
+ if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::CommandsFeature)) {
+ if (discoItemsRequest_) {
+ discoItemsRequest_->onResponse.disconnect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2));
+ discoItemsRequest_.reset();
+ }
+ discoItemsRequest_ = GetDiscoItemsRequest::create(JID(jid_.getDomain()), DiscoInfo::CommandsFeature, iqRouter_);
+ discoItemsRequest_->onResponse.connect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2));
+ discoItemsRequest_->send();
+ } else {
+ mainWindow_->setAvailableAdHocCommands(std::vector<DiscoItems::Item>());
+ }
}
void AdHocManager::setOnline(bool online) {
- foreach (boost::shared_ptr<AdHocController> controller, controllers_) {
- controller->setOnline(online);
- }
+ foreach (boost::shared_ptr<AdHocController> controller, controllers_) {
+ controller->setOnline(online);
+ }
}
void AdHocManager::handleServerDiscoItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error) {
- std::vector<DiscoItems::Item> commands;
- if (!error) {
- foreach (DiscoItems::Item item, items->getItems()) {
- if (item.getNode() != "http://isode.com/xmpp/commands#test") {
- commands.push_back(item);
- }
- }
- }
- mainWindow_->setAvailableAdHocCommands(commands);
+ std::vector<DiscoItems::Item> commands;
+ if (!error) {
+ foreach (DiscoItems::Item item, items->getItems()) {
+ if (item.getNode() != "http://isode.com/xmpp/commands#test") {
+ commands.push_back(item);
+ }
+ }
+ }
+ mainWindow_->setAvailableAdHocCommands(commands);
}
void AdHocManager::handleUIEvent(boost::shared_ptr<UIEvent> event) {
- boost::shared_ptr<RequestAdHocUIEvent> adHocEvent = boost::dynamic_pointer_cast<RequestAdHocUIEvent>(event);
- if (adHocEvent) {
- boost::shared_ptr<OutgoingAdHocCommandSession> command = boost::make_shared<OutgoingAdHocCommandSession>(adHocEvent->getCommand().getJID(), adHocEvent->getCommand().getNode(), iqRouter_);
- boost::shared_ptr<AdHocController> controller = boost::make_shared<AdHocController>(factory_, command);
- controller->onDeleting.connect(boost::bind(&AdHocManager::removeController, this, controller));
- controllers_.push_back(controller);
- }
- boost::shared_ptr<RequestAdHocWithJIDUIEvent> adHocJIDEvent = boost::dynamic_pointer_cast<RequestAdHocWithJIDUIEvent>(event);
- if (!!adHocJIDEvent) {
- boost::shared_ptr<OutgoingAdHocCommandSession> command = boost::make_shared<OutgoingAdHocCommandSession>(adHocJIDEvent->getJID(), adHocJIDEvent->getNode(), iqRouter_);
- boost::shared_ptr<AdHocController> controller = boost::make_shared<AdHocController>(factory_, command);
- controller->onDeleting.connect(boost::bind(&AdHocManager::removeController, this, controller));
- controllers_.push_back(controller);
- }
+ boost::shared_ptr<RequestAdHocUIEvent> adHocEvent = boost::dynamic_pointer_cast<RequestAdHocUIEvent>(event);
+ if (adHocEvent) {
+ boost::shared_ptr<OutgoingAdHocCommandSession> command = boost::make_shared<OutgoingAdHocCommandSession>(adHocEvent->getCommand().getJID(), adHocEvent->getCommand().getNode(), iqRouter_);
+ boost::shared_ptr<AdHocController> controller = boost::make_shared<AdHocController>(factory_, command);
+ controller->onDeleting.connect(boost::bind(&AdHocManager::removeController, this, controller));
+ controllers_.push_back(controller);
+ }
+ boost::shared_ptr<RequestAdHocWithJIDUIEvent> adHocJIDEvent = boost::dynamic_pointer_cast<RequestAdHocWithJIDUIEvent>(event);
+ if (!!adHocJIDEvent) {
+ boost::shared_ptr<OutgoingAdHocCommandSession> command = boost::make_shared<OutgoingAdHocCommandSession>(adHocJIDEvent->getJID(), adHocJIDEvent->getNode(), iqRouter_);
+ boost::shared_ptr<AdHocController> controller = boost::make_shared<AdHocController>(factory_, command);
+ controller->onDeleting.connect(boost::bind(&AdHocManager::removeController, this, controller));
+ controllers_.push_back(controller);
+ }
}
}
diff --git a/Swift/Controllers/AdHocManager.h b/Swift/Controllers/AdHocManager.h
index 00289b0..73c057c 100644
--- a/Swift/Controllers/AdHocManager.h
+++ b/Swift/Controllers/AdHocManager.h
@@ -23,22 +23,22 @@ class UIEventStream;
class AdHocCommandWindowFactory;
class AdHocManager {
public:
- AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow);
- ~AdHocManager();
- void removeController(boost::shared_ptr<AdHocController> contoller);
- void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
- void setOnline(bool online);
+ AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow);
+ ~AdHocManager();
+ void removeController(boost::shared_ptr<AdHocController> contoller);
+ void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
+ void setOnline(bool online);
private:
- void handleServerDiscoItemsResponse(boost::shared_ptr<DiscoItems>, ErrorPayload::ref error);
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
- boost::signal<void (const AdHocController&)> onControllerComplete;
- JID jid_;
- IQRouter* iqRouter_;
- UIEventStream* uiEventStream_;
- MainWindow* mainWindow_;
- AdHocCommandWindowFactory* factory_;
- GetDiscoItemsRequest::ref discoItemsRequest_;
- std::vector<boost::shared_ptr<AdHocController> > controllers_;
+ void handleServerDiscoItemsResponse(boost::shared_ptr<DiscoItems>, ErrorPayload::ref error);
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ boost::signal<void (const AdHocController&)> onControllerComplete;
+ JID jid_;
+ IQRouter* iqRouter_;
+ UIEventStream* uiEventStream_;
+ MainWindow* mainWindow_;
+ AdHocCommandWindowFactory* factory_;
+ GetDiscoItemsRequest::ref discoItemsRequest_;
+ std::vector<boost::shared_ptr<AdHocController> > controllers_;
};
}
diff --git a/Swift/Controllers/BlockListController.cpp b/Swift/Controllers/BlockListController.cpp
index 2c8d401..6fbf6b3 100644
--- a/Swift/Controllers/BlockListController.cpp
+++ b/Swift/Controllers/BlockListController.cpp
@@ -28,159 +28,159 @@
namespace Swift {
BlockListController::BlockListController(ClientBlockListManager* blockListManager, UIEventStream* uiEventStream, BlockListEditorWidgetFactory* blockListEditorWidgetFactory, EventController* eventController) : blockListManager_(blockListManager), blockListEditorWidgetFactory_(blockListEditorWidgetFactory), blockListEditorWidget_(0), eventController_(eventController), remainingRequests_(0), uiEventStream_(uiEventStream) {
- uiEventStream->onUIEvent.connect(boost::bind(&BlockListController::handleUIEvent, this, _1));
- blockListManager_->getBlockList()->onItemAdded.connect(boost::bind(&BlockListController::handleBlockListChanged, this));
- blockListManager_->getBlockList()->onItemRemoved.connect(boost::bind(&BlockListController::handleBlockListChanged, this));
+ uiEventStream->onUIEvent.connect(boost::bind(&BlockListController::handleUIEvent, this, _1));
+ blockListManager_->getBlockList()->onItemAdded.connect(boost::bind(&BlockListController::handleBlockListChanged, this));
+ blockListManager_->getBlockList()->onItemRemoved.connect(boost::bind(&BlockListController::handleBlockListChanged, this));
}
BlockListController::~BlockListController() {
- uiEventStream_->onUIEvent.disconnect(boost::bind(&BlockListController::handleUIEvent, this, _1));
- blockListManager_->getBlockList()->onItemAdded.disconnect(boost::bind(&BlockListController::handleBlockListChanged, this));
- blockListManager_->getBlockList()->onItemRemoved.disconnect(boost::bind(&BlockListController::handleBlockListChanged, this));
+ uiEventStream_->onUIEvent.disconnect(boost::bind(&BlockListController::handleUIEvent, this, _1));
+ blockListManager_->getBlockList()->onItemAdded.disconnect(boost::bind(&BlockListController::handleBlockListChanged, this));
+ blockListManager_->getBlockList()->onItemRemoved.disconnect(boost::bind(&BlockListController::handleBlockListChanged, this));
}
void BlockListController::blockListDifferences(const std::vector<JID> &newBlockList, std::vector<JID> &jidsToUnblock, std::vector<JID> &jidsToBlock) const {
- foreach (const JID& jid, blockListBeforeEdit) {
- if (std::find(newBlockList.begin(), newBlockList.end(), jid) == newBlockList.end()) {
- jidsToUnblock.push_back(jid);
- }
- }
-
- foreach (const JID& jid, newBlockList) {
- if (std::find(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid) == blockListBeforeEdit.end()) {
- jidsToBlock.push_back(jid);
- }
- }
+ foreach (const JID& jid, blockListBeforeEdit) {
+ if (std::find(newBlockList.begin(), newBlockList.end(), jid) == newBlockList.end()) {
+ jidsToUnblock.push_back(jid);
+ }
+ }
+
+ foreach (const JID& jid, newBlockList) {
+ if (std::find(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid) == blockListBeforeEdit.end()) {
+ jidsToBlock.push_back(jid);
+ }
+ }
}
void BlockListController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
- // handle UI dialog
- boost::shared_ptr<RequestBlockListDialogUIEvent> requestDialogEvent = boost::dynamic_pointer_cast<RequestBlockListDialogUIEvent>(rawEvent);
- if (requestDialogEvent != NULL) {
- if (blockListEditorWidget_ == NULL) {
- blockListEditorWidget_ = blockListEditorWidgetFactory_->createBlockListEditorWidget();
- blockListEditorWidget_->onSetNewBlockList.connect(boost::bind(&BlockListController::handleSetNewBlockList, this, _1));
- }
- blockListBeforeEdit = blockListManager_->getBlockList()->getItems();
- blockListEditorWidget_->setCurrentBlockList(blockListBeforeEdit);
- blockListEditorWidget_->setError("");
- blockListEditorWidget_->show();
- return;
- }
-
- // handle block state change
- boost::shared_ptr<RequestChangeBlockStateUIEvent> changeStateEvent = boost::dynamic_pointer_cast<RequestChangeBlockStateUIEvent>(rawEvent);
- if (changeStateEvent != NULL) {
- if (changeStateEvent->getBlockState() == RequestChangeBlockStateUIEvent::Blocked) {
- GenericRequest<BlockPayload>::ref blockRequest = blockListManager_->createBlockJIDRequest(changeStateEvent->getContact());
- blockRequest->onResponse.connect(boost::bind(&BlockListController::handleBlockResponse, this, blockRequest, _1, _2, std::vector<JID>(1, changeStateEvent->getContact()), false));
- blockRequest->send();
- } else if (changeStateEvent->getBlockState() == RequestChangeBlockStateUIEvent::Unblocked) {
- GenericRequest<UnblockPayload>::ref unblockRequest = blockListManager_->createUnblockJIDRequest(changeStateEvent->getContact());
- unblockRequest->onResponse.connect(boost::bind(&BlockListController::handleUnblockResponse, this, unblockRequest, _1, _2, std::vector<JID>(1, changeStateEvent->getContact()), false));
- unblockRequest->send();
- }
- return;
- }
+ // handle UI dialog
+ boost::shared_ptr<RequestBlockListDialogUIEvent> requestDialogEvent = boost::dynamic_pointer_cast<RequestBlockListDialogUIEvent>(rawEvent);
+ if (requestDialogEvent != NULL) {
+ if (blockListEditorWidget_ == NULL) {
+ blockListEditorWidget_ = blockListEditorWidgetFactory_->createBlockListEditorWidget();
+ blockListEditorWidget_->onSetNewBlockList.connect(boost::bind(&BlockListController::handleSetNewBlockList, this, _1));
+ }
+ blockListBeforeEdit = blockListManager_->getBlockList()->getItems();
+ blockListEditorWidget_->setCurrentBlockList(blockListBeforeEdit);
+ blockListEditorWidget_->setError("");
+ blockListEditorWidget_->show();
+ return;
+ }
+
+ // handle block state change
+ boost::shared_ptr<RequestChangeBlockStateUIEvent> changeStateEvent = boost::dynamic_pointer_cast<RequestChangeBlockStateUIEvent>(rawEvent);
+ if (changeStateEvent != NULL) {
+ if (changeStateEvent->getBlockState() == RequestChangeBlockStateUIEvent::Blocked) {
+ GenericRequest<BlockPayload>::ref blockRequest = blockListManager_->createBlockJIDRequest(changeStateEvent->getContact());
+ blockRequest->onResponse.connect(boost::bind(&BlockListController::handleBlockResponse, this, blockRequest, _1, _2, std::vector<JID>(1, changeStateEvent->getContact()), false));
+ blockRequest->send();
+ } else if (changeStateEvent->getBlockState() == RequestChangeBlockStateUIEvent::Unblocked) {
+ GenericRequest<UnblockPayload>::ref unblockRequest = blockListManager_->createUnblockJIDRequest(changeStateEvent->getContact());
+ unblockRequest->onResponse.connect(boost::bind(&BlockListController::handleUnblockResponse, this, unblockRequest, _1, _2, std::vector<JID>(1, changeStateEvent->getContact()), false));
+ unblockRequest->send();
+ }
+ return;
+ }
}
void BlockListController::handleBlockResponse(GenericRequest<BlockPayload>::ref request, boost::shared_ptr<BlockPayload>, ErrorPayload::ref error, const std::vector<JID>& jids, bool originEditor) {
- if (error) {
- std::string errorMessage;
- // FIXME: Handle reporting of list of JIDs in a translatable way.
- errorMessage = str(format(QT_TRANSLATE_NOOP("", "Failed to block %1%.")) % jids.at(0).toString());
- if (!error->getText().empty()) {
- errorMessage = str(format(QT_TRANSLATE_NOOP("", "%1%: %2%.")) % errorMessage % error->getText());
- }
- if (blockListEditorWidget_ && originEditor) {
- blockListEditorWidget_->setError(errorMessage);
- blockListEditorWidget_->setBusy(false);
- }
- else {
- eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage));
- }
- }
- if (originEditor) {
- remainingRequests_--;
- if (blockListEditorWidget_ && (remainingRequests_ == 0) && !error) {
- blockListEditorWidget_->setBusy(false);
- blockListEditorWidget_->hide();
- }
- }
+ if (error) {
+ std::string errorMessage;
+ // FIXME: Handle reporting of list of JIDs in a translatable way.
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "Failed to block %1%.")) % jids.at(0).toString());
+ if (!error->getText().empty()) {
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "%1%: %2%.")) % errorMessage % error->getText());
+ }
+ if (blockListEditorWidget_ && originEditor) {
+ blockListEditorWidget_->setError(errorMessage);
+ blockListEditorWidget_->setBusy(false);
+ }
+ else {
+ eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage));
+ }
+ }
+ if (originEditor) {
+ remainingRequests_--;
+ if (blockListEditorWidget_ && (remainingRequests_ == 0) && !error) {
+ blockListEditorWidget_->setBusy(false);
+ blockListEditorWidget_->hide();
+ }
+ }
}
void BlockListController::handleUnblockResponse(GenericRequest<UnblockPayload>::ref request, boost::shared_ptr<UnblockPayload>, ErrorPayload::ref error, const std::vector<JID>& jids, bool originEditor) {
- if (error) {
- std::string errorMessage;
- // FIXME: Handle reporting of list of JIDs in a translatable way.
- errorMessage = str(format(QT_TRANSLATE_NOOP("", "Failed to unblock %1%.")) % jids.at(0).toString());
- if (!error->getText().empty()) {
- errorMessage = str(format(QT_TRANSLATE_NOOP("", "%1%: %2%.")) % errorMessage % error->getText());
- }
- if (blockListEditorWidget_ && originEditor) {
- blockListEditorWidget_->setError(errorMessage);
- blockListEditorWidget_->setBusy(false);
- }
- else {
- eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage));
- }
- }
- if (originEditor) {
- remainingRequests_--;
- if (blockListEditorWidget_ && (remainingRequests_ == 0) && !error) {
- blockListEditorWidget_->setBusy(false);
- blockListEditorWidget_->hide();
- }
- }
+ if (error) {
+ std::string errorMessage;
+ // FIXME: Handle reporting of list of JIDs in a translatable way.
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "Failed to unblock %1%.")) % jids.at(0).toString());
+ if (!error->getText().empty()) {
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "%1%: %2%.")) % errorMessage % error->getText());
+ }
+ if (blockListEditorWidget_ && originEditor) {
+ blockListEditorWidget_->setError(errorMessage);
+ blockListEditorWidget_->setBusy(false);
+ }
+ else {
+ eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage));
+ }
+ }
+ if (originEditor) {
+ remainingRequests_--;
+ if (blockListEditorWidget_ && (remainingRequests_ == 0) && !error) {
+ blockListEditorWidget_->setBusy(false);
+ blockListEditorWidget_->hide();
+ }
+ }
}
void BlockListController::handleSetNewBlockList(const std::vector<JID> &newBlockList) {
- std::vector<JID> jidsToBlock;
- std::vector<JID> jidsToUnblock;
-
- blockListDifferences(newBlockList, jidsToUnblock, jidsToBlock);
-
- if (!jidsToBlock.empty()) {
- remainingRequests_++;
- GenericRequest<BlockPayload>::ref blockRequest = blockListManager_->createBlockJIDsRequest(jidsToBlock);
- blockRequest->onResponse.connect(boost::bind(&BlockListController::handleBlockResponse, this, blockRequest, _1, _2, jidsToBlock, true));
- blockRequest->send();
- }
- if (!jidsToUnblock.empty()) {
- remainingRequests_++;
- GenericRequest<UnblockPayload>::ref unblockRequest = blockListManager_->createUnblockJIDsRequest(jidsToUnblock);
- unblockRequest->onResponse.connect(boost::bind(&BlockListController::handleUnblockResponse, this, unblockRequest, _1, _2, jidsToUnblock, true));
- unblockRequest->send();
- }
- if (!jidsToBlock.empty() || !jidsToUnblock.empty()) {
- assert(blockListEditorWidget_);
- blockListEditorWidget_->setBusy(true);
- blockListEditorWidget_->setError("");
- } else {
- blockListEditorWidget_->hide();
- }
+ std::vector<JID> jidsToBlock;
+ std::vector<JID> jidsToUnblock;
+
+ blockListDifferences(newBlockList, jidsToUnblock, jidsToBlock);
+
+ if (!jidsToBlock.empty()) {
+ remainingRequests_++;
+ GenericRequest<BlockPayload>::ref blockRequest = blockListManager_->createBlockJIDsRequest(jidsToBlock);
+ blockRequest->onResponse.connect(boost::bind(&BlockListController::handleBlockResponse, this, blockRequest, _1, _2, jidsToBlock, true));
+ blockRequest->send();
+ }
+ if (!jidsToUnblock.empty()) {
+ remainingRequests_++;
+ GenericRequest<UnblockPayload>::ref unblockRequest = blockListManager_->createUnblockJIDsRequest(jidsToUnblock);
+ unblockRequest->onResponse.connect(boost::bind(&BlockListController::handleUnblockResponse, this, unblockRequest, _1, _2, jidsToUnblock, true));
+ unblockRequest->send();
+ }
+ if (!jidsToBlock.empty() || !jidsToUnblock.empty()) {
+ assert(blockListEditorWidget_);
+ blockListEditorWidget_->setBusy(true);
+ blockListEditorWidget_->setError("");
+ } else {
+ blockListEditorWidget_->hide();
+ }
}
void BlockListController::handleBlockListChanged() {
- if (blockListEditorWidget_) {
- std::vector<JID> jidsToBlock;
- std::vector<JID> jidsToUnblock;
+ if (blockListEditorWidget_) {
+ std::vector<JID> jidsToBlock;
+ std::vector<JID> jidsToUnblock;
- blockListDifferences(blockListEditorWidget_->getCurrentBlockList(), jidsToUnblock, jidsToBlock);
- blockListBeforeEdit = blockListManager_->getBlockList()->getItems();
+ blockListDifferences(blockListEditorWidget_->getCurrentBlockList(), jidsToUnblock, jidsToBlock);
+ blockListBeforeEdit = blockListManager_->getBlockList()->getItems();
- foreach (const JID& jid, jidsToBlock) {
- if (std::find(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid) == blockListBeforeEdit.end()) {
- blockListBeforeEdit.push_back(jid);
- }
- }
+ foreach (const JID& jid, jidsToBlock) {
+ if (std::find(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid) == blockListBeforeEdit.end()) {
+ blockListBeforeEdit.push_back(jid);
+ }
+ }
- foreach (const JID& jid, jidsToUnblock) {
- blockListBeforeEdit.erase(std::remove(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid), blockListBeforeEdit.end());
- }
+ foreach (const JID& jid, jidsToUnblock) {
+ blockListBeforeEdit.erase(std::remove(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid), blockListBeforeEdit.end());
+ }
- blockListEditorWidget_->setCurrentBlockList(blockListBeforeEdit);
- }
+ blockListEditorWidget_->setCurrentBlockList(blockListBeforeEdit);
+ }
}
}
diff --git a/Swift/Controllers/BlockListController.h b/Swift/Controllers/BlockListController.h
index c911344..f9ee5a6 100644
--- a/Swift/Controllers/BlockListController.h
+++ b/Swift/Controllers/BlockListController.h
@@ -28,29 +28,29 @@ class EventController;
class BlockListController {
public:
- BlockListController(ClientBlockListManager* blockListManager, UIEventStream* uiEventStream, BlockListEditorWidgetFactory* blockListEditorWidgetFactory, EventController* eventController);
- ~BlockListController();
+ BlockListController(ClientBlockListManager* blockListManager, UIEventStream* uiEventStream, BlockListEditorWidgetFactory* blockListEditorWidgetFactory, EventController* eventController);
+ ~BlockListController();
private:
- void blockListDifferences(const std::vector<JID> &newBlockList, std::vector<JID>& jidsToUnblock, std::vector<JID>& jidsToBlock) const;
+ void blockListDifferences(const std::vector<JID> &newBlockList, std::vector<JID>& jidsToUnblock, std::vector<JID>& jidsToBlock) const;
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void handleBlockResponse(GenericRequest<BlockPayload>::ref, boost::shared_ptr<BlockPayload>, ErrorPayload::ref error, const std::vector<JID>& jids, bool originEditor);
- void handleUnblockResponse(GenericRequest<UnblockPayload>::ref, boost::shared_ptr<UnblockPayload>, ErrorPayload::ref error, const std::vector<JID>& jids, bool originEditor);
+ void handleBlockResponse(GenericRequest<BlockPayload>::ref, boost::shared_ptr<BlockPayload>, ErrorPayload::ref error, const std::vector<JID>& jids, bool originEditor);
+ void handleUnblockResponse(GenericRequest<UnblockPayload>::ref, boost::shared_ptr<UnblockPayload>, ErrorPayload::ref error, const std::vector<JID>& jids, bool originEditor);
- void handleSetNewBlockList(const std::vector<JID>& newBlockList);
+ void handleSetNewBlockList(const std::vector<JID>& newBlockList);
- void handleBlockListChanged();
+ void handleBlockListChanged();
private:
- ClientBlockListManager* blockListManager_;
- BlockListEditorWidgetFactory* blockListEditorWidgetFactory_;
- BlockListEditorWidget* blockListEditorWidget_;
- EventController* eventController_;
- std::vector<JID> blockListBeforeEdit;
- int remainingRequests_;
- UIEventStream* uiEventStream_;
+ ClientBlockListManager* blockListManager_;
+ BlockListEditorWidgetFactory* blockListEditorWidgetFactory_;
+ BlockListEditorWidget* blockListEditorWidget_;
+ EventController* eventController_;
+ std::vector<JID> blockListBeforeEdit;
+ int remainingRequests_;
+ UIEventStream* uiEventStream_;
};
}
diff --git a/Swift/Controllers/CertificateMemoryStorageFactory.h b/Swift/Controllers/CertificateMemoryStorageFactory.h
index de9f3fe..080b157 100644
--- a/Swift/Controllers/CertificateMemoryStorageFactory.h
+++ b/Swift/Controllers/CertificateMemoryStorageFactory.h
@@ -10,19 +10,19 @@
#include <Swift/Controllers/Storages/CertificateStorageFactory.h>
namespace Swift {
- class CertificateFactory;
+ class CertificateFactory;
- class CertificateMemoryStorageFactory : public CertificateStorageFactory {
- public:
- CertificateMemoryStorageFactory() {
- }
+ class CertificateMemoryStorageFactory : public CertificateStorageFactory {
+ public:
+ CertificateMemoryStorageFactory() {
+ }
- virtual CertificateStorage* createCertificateStorage(const JID&) const {
- return new CertificateMemoryStorage();
- }
+ virtual CertificateStorage* createCertificateStorage(const JID&) const {
+ return new CertificateMemoryStorage();
+ }
- private:
- boost::filesystem::path basePath;
- CertificateFactory* certificateFactory;
- };
+ private:
+ boost::filesystem::path basePath;
+ CertificateFactory* certificateFactory;
+ };
}
diff --git a/Swift/Controllers/Chat/AutoAcceptMUCInviteDecider.h b/Swift/Controllers/Chat/AutoAcceptMUCInviteDecider.h
index 8ea6dff..646612b 100644
--- a/Swift/Controllers/Chat/AutoAcceptMUCInviteDecider.h
+++ b/Swift/Controllers/Chat/AutoAcceptMUCInviteDecider.h
@@ -19,36 +19,36 @@
#include <Swift/Controllers/Settings/SettingsProvider.h>
namespace Swift {
- class AutoAcceptMUCInviteDecider {
- public:
- AutoAcceptMUCInviteDecider(const JID& domain, XMPPRoster* roster, SettingsProvider* settings) : domain_(domain), roster_(roster), settings_(settings) {
- }
-
- bool isAutoAcceptedInvite(const JID& from, MUCInvitationPayload::ref invite) {
- if (!invite->getIsImpromptu()) {
- return false; /* always ask the user for normal MUC invites */
- }
-
- if (invite->getIsContinuation()) {
- return true;
- }
-
- std::string auto_accept_mode = settings_->getSetting(SettingConstants::INVITE_AUTO_ACCEPT_MODE);
- if (auto_accept_mode == "no") {
- return false;
- } else if (auto_accept_mode == "presence") {
- return roster_->getSubscriptionStateForJID(from) == RosterItemPayload::From || roster_->getSubscriptionStateForJID(from) == RosterItemPayload::Both;
- } else if (auto_accept_mode == "domain") {
- return roster_->getSubscriptionStateForJID(from) == RosterItemPayload::From || roster_->getSubscriptionStateForJID(from) == RosterItemPayload::Both || from.getDomain() == domain_;
- } else {
- assert(false);
- return false;
- }
- }
-
- private:
- JID domain_;
- XMPPRoster* roster_;
- SettingsProvider* settings_;
- };
+ class AutoAcceptMUCInviteDecider {
+ public:
+ AutoAcceptMUCInviteDecider(const JID& domain, XMPPRoster* roster, SettingsProvider* settings) : domain_(domain), roster_(roster), settings_(settings) {
+ }
+
+ bool isAutoAcceptedInvite(const JID& from, MUCInvitationPayload::ref invite) {
+ if (!invite->getIsImpromptu()) {
+ return false; /* always ask the user for normal MUC invites */
+ }
+
+ if (invite->getIsContinuation()) {
+ return true;
+ }
+
+ std::string auto_accept_mode = settings_->getSetting(SettingConstants::INVITE_AUTO_ACCEPT_MODE);
+ if (auto_accept_mode == "no") {
+ return false;
+ } else if (auto_accept_mode == "presence") {
+ return roster_->getSubscriptionStateForJID(from) == RosterItemPayload::From || roster_->getSubscriptionStateForJID(from) == RosterItemPayload::Both;
+ } else if (auto_accept_mode == "domain") {
+ return roster_->getSubscriptionStateForJID(from) == RosterItemPayload::From || roster_->getSubscriptionStateForJID(from) == RosterItemPayload::Both || from.getDomain() == domain_;
+ } else {
+ assert(false);
+ return false;
+ }
+ }
+
+ private:
+ JID domain_;
+ XMPPRoster* roster_;
+ SettingsProvider* settings_;
+ };
}
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp
index 7f62c36..5302492 100644
--- a/Swift/Controllers/Chat/ChatController.cpp
+++ b/Swift/Controllers/Chat/ChatController.cpp
@@ -45,489 +45,489 @@
#include <Swift/Controllers/XMPPEvents/EventController.h>
namespace Swift {
-
+
/**
* The controller does not gain ownership of the stanzaChannel, nor the factory.
*/
ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts, SettingsProvider* settings, HistoryController* historyController, MUCRegistry* mucRegistry, HighlightManager* highlightManager, ClientBlockListManager* clientBlockListManager, boost::shared_ptr<ChatMessageParser> chatMessageParser, AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider)
- : ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager, useDelayForLatency, eventStream, eventController, timerFactory, entityCapsProvider, historyController, mucRegistry, highlightManager, chatMessageParser, autoAcceptMUCInviteDecider), eventStream_(eventStream), userWantsReceipts_(userWantsReceipts), settings_(settings), clientBlockListManager_(clientBlockListManager) {
- isInMUC_ = isInMUC;
- lastWasPresence_ = false;
- chatStateNotifier_ = new ChatStateNotifier(stanzaChannel, contact, entityCapsProvider);
- chatStateTracker_ = new ChatStateTracker();
- nickResolver_ = nickResolver;
- presenceOracle_->onPresenceChange.connect(boost::bind(&ChatController::handlePresenceChange, this, _1));
- chatStateTracker_->onChatStateChange.connect(boost::bind(&ChatWindow::setContactChatState, chatWindow_, _1));
- stanzaChannel_->onStanzaAcked.connect(boost::bind(&ChatController::handleStanzaAcked, this, _1));
- nickResolver_->onNickChanged.connect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2));
- std::string nick = nickResolver_->jidToNick(toJID_);
- chatWindow_->setName(nick);
- std::string startMessage;
- Presence::ref theirPresence;
- if (isInMUC) {
- startMessage = str(format(QT_TRANSLATE_NOOP("", "Starting chat with %1% in chatroom %2%")) % nick % contact.toBare().toString());
- theirPresence = presenceOracle->getLastPresence(contact);
- } else {
- startMessage = str(format(QT_TRANSLATE_NOOP("", "Starting chat with %1% - %2%")) % nick % contact.toBare().toString());
- theirPresence = contact.isBare() ? presenceOracle->getAccountPresence(contact) : presenceOracle->getLastPresence(contact);
- }
- Idle::ref idle;
- if (theirPresence && (idle = theirPresence->getPayload<Idle>())) {
- startMessage += str(format(QT_TRANSLATE_NOOP("", ", who has been idle since %1%")) % dateTimeToLocalString(idle->getSince()));
- }
- startMessage += ": " + statusShowTypeToFriendlyName(theirPresence ? theirPresence->getShow() : StatusShow::None);
- if (theirPresence && !theirPresence->getStatus().empty()) {
- startMessage += " (" + theirPresence->getStatus() + ")";
- }
- lastShownStatus_ = theirPresence ? theirPresence->getShow() : StatusShow::None;
- chatStateNotifier_->setContactIsOnline(theirPresence && theirPresence->getType() == Presence::Available);
- startMessage += ".";
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(startMessage), ChatWindow::DefaultDirection);
- chatWindow_->onUserTyping.connect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_));
- chatWindow_->onUserCancelsTyping.connect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_));
- chatWindow_->onFileTransferStart.connect(boost::bind(&ChatController::handleFileTransferStart, this, _1, _2));
- chatWindow_->onFileTransferAccept.connect(boost::bind(&ChatController::handleFileTransferAccept, this, _1, _2));
- chatWindow_->onFileTransferCancel.connect(boost::bind(&ChatController::handleFileTransferCancel, this, _1));
- chatWindow_->onSendFileRequest.connect(boost::bind(&ChatController::handleSendFileRequest, this, _1));
- chatWindow_->onWhiteboardSessionAccept.connect(boost::bind(&ChatController::handleWhiteboardSessionAccept, this));
- chatWindow_->onWhiteboardSessionCancel.connect(boost::bind(&ChatController::handleWhiteboardSessionCancel, this));
- chatWindow_->onWhiteboardWindowShow.connect(boost::bind(&ChatController::handleWhiteboardWindowShow, this));
- chatWindow_->onBlockUserRequest.connect(boost::bind(&ChatController::handleBlockUserRequest, this));
- chatWindow_->onUnblockUserRequest.connect(boost::bind(&ChatController::handleUnblockUserRequest, this));
- chatWindow_->onInviteToChat.connect(boost::bind(&ChatController::handleInviteToChat, this, _1));
- chatWindow_->onClosed.connect(boost::bind(&ChatController::handleWindowClosed, this));
- ChatController::handleBareJIDCapsChanged(toJID_);
-
- settings_->onSettingChanged.connect(boost::bind(&ChatController::handleSettingChanged, this, _1));
- eventStream_->onUIEvent.connect(boost::bind(&ChatController::handleUIEvent, this, _1));
+ : ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager, useDelayForLatency, eventStream, eventController, timerFactory, entityCapsProvider, historyController, mucRegistry, highlightManager, chatMessageParser, autoAcceptMUCInviteDecider), eventStream_(eventStream), userWantsReceipts_(userWantsReceipts), settings_(settings), clientBlockListManager_(clientBlockListManager) {
+ isInMUC_ = isInMUC;
+ lastWasPresence_ = false;
+ chatStateNotifier_ = new ChatStateNotifier(stanzaChannel, contact, entityCapsProvider);
+ chatStateTracker_ = new ChatStateTracker();
+ nickResolver_ = nickResolver;
+ presenceOracle_->onPresenceChange.connect(boost::bind(&ChatController::handlePresenceChange, this, _1));
+ chatStateTracker_->onChatStateChange.connect(boost::bind(&ChatWindow::setContactChatState, chatWindow_, _1));
+ stanzaChannel_->onStanzaAcked.connect(boost::bind(&ChatController::handleStanzaAcked, this, _1));
+ nickResolver_->onNickChanged.connect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2));
+ std::string nick = nickResolver_->jidToNick(toJID_);
+ chatWindow_->setName(nick);
+ std::string startMessage;
+ Presence::ref theirPresence;
+ if (isInMUC) {
+ startMessage = str(format(QT_TRANSLATE_NOOP("", "Starting chat with %1% in chatroom %2%")) % nick % contact.toBare().toString());
+ theirPresence = presenceOracle->getLastPresence(contact);
+ } else {
+ startMessage = str(format(QT_TRANSLATE_NOOP("", "Starting chat with %1% - %2%")) % nick % contact.toBare().toString());
+ theirPresence = contact.isBare() ? presenceOracle->getAccountPresence(contact) : presenceOracle->getLastPresence(contact);
+ }
+ Idle::ref idle;
+ if (theirPresence && (idle = theirPresence->getPayload<Idle>())) {
+ startMessage += str(format(QT_TRANSLATE_NOOP("", ", who has been idle since %1%")) % dateTimeToLocalString(idle->getSince()));
+ }
+ startMessage += ": " + statusShowTypeToFriendlyName(theirPresence ? theirPresence->getShow() : StatusShow::None);
+ if (theirPresence && !theirPresence->getStatus().empty()) {
+ startMessage += " (" + theirPresence->getStatus() + ")";
+ }
+ lastShownStatus_ = theirPresence ? theirPresence->getShow() : StatusShow::None;
+ chatStateNotifier_->setContactIsOnline(theirPresence && theirPresence->getType() == Presence::Available);
+ startMessage += ".";
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(startMessage), ChatWindow::DefaultDirection);
+ chatWindow_->onUserTyping.connect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_));
+ chatWindow_->onUserCancelsTyping.connect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_));
+ chatWindow_->onFileTransferStart.connect(boost::bind(&ChatController::handleFileTransferStart, this, _1, _2));
+ chatWindow_->onFileTransferAccept.connect(boost::bind(&ChatController::handleFileTransferAccept, this, _1, _2));
+ chatWindow_->onFileTransferCancel.connect(boost::bind(&ChatController::handleFileTransferCancel, this, _1));
+ chatWindow_->onSendFileRequest.connect(boost::bind(&ChatController::handleSendFileRequest, this, _1));
+ chatWindow_->onWhiteboardSessionAccept.connect(boost::bind(&ChatController::handleWhiteboardSessionAccept, this));
+ chatWindow_->onWhiteboardSessionCancel.connect(boost::bind(&ChatController::handleWhiteboardSessionCancel, this));
+ chatWindow_->onWhiteboardWindowShow.connect(boost::bind(&ChatController::handleWhiteboardWindowShow, this));
+ chatWindow_->onBlockUserRequest.connect(boost::bind(&ChatController::handleBlockUserRequest, this));
+ chatWindow_->onUnblockUserRequest.connect(boost::bind(&ChatController::handleUnblockUserRequest, this));
+ chatWindow_->onInviteToChat.connect(boost::bind(&ChatController::handleInviteToChat, this, _1));
+ chatWindow_->onClosed.connect(boost::bind(&ChatController::handleWindowClosed, this));
+ ChatController::handleBareJIDCapsChanged(toJID_);
+
+ settings_->onSettingChanged.connect(boost::bind(&ChatController::handleSettingChanged, this, _1));
+ eventStream_->onUIEvent.connect(boost::bind(&ChatController::handleUIEvent, this, _1));
}
void ChatController::handleContactNickChanged(const JID& jid, const std::string& /*oldNick*/) {
- if (jid.toBare() == toJID_.toBare()) {
- chatWindow_->setName(nickResolver_->jidToNick(toJID_));
- }
+ if (jid.toBare() == toJID_.toBare()) {
+ chatWindow_->setName(nickResolver_->jidToNick(toJID_));
+ }
}
ChatController::~ChatController() {
- eventStream_->onUIEvent.disconnect(boost::bind(&ChatController::handleUIEvent, this, _1));
- settings_->onSettingChanged.disconnect(boost::bind(&ChatController::handleSettingChanged, this, _1));
- nickResolver_->onNickChanged.disconnect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2));
- delete chatStateNotifier_;
- delete chatStateTracker_;
+ eventStream_->onUIEvent.disconnect(boost::bind(&ChatController::handleUIEvent, this, _1));
+ settings_->onSettingChanged.disconnect(boost::bind(&ChatController::handleSettingChanged, this, _1));
+ nickResolver_->onNickChanged.disconnect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2));
+ delete chatStateNotifier_;
+ delete chatStateTracker_;
}
JID ChatController::getBaseJID() {
- return isInMUC_ ? toJID_ : ChatControllerBase::getBaseJID();
+ return isInMUC_ ? toJID_ : ChatControllerBase::getBaseJID();
}
void ChatController::cancelReplaces() {
- lastWasPresence_ = false;
+ lastWasPresence_ = false;
}
void ChatController::handleBareJIDCapsChanged(const JID& /*jid*/) {
- FeatureOracle featureOracle(entityCapsProvider_, presenceOracle_);
+ FeatureOracle featureOracle(entityCapsProvider_, presenceOracle_);
- chatWindow_->setCorrectionEnabled(featureOracle.isMessageCorrectionSupported(toJID_));
- chatWindow_->setFileTransferEnabled(isInMUC_ ? No : featureOracle.isFileTransferSupported(toJID_));
- contactSupportsReceipts_ = featureOracle.isMessageReceiptsSupported(toJID_);
+ chatWindow_->setCorrectionEnabled(featureOracle.isMessageCorrectionSupported(toJID_));
+ chatWindow_->setFileTransferEnabled(isInMUC_ ? No : featureOracle.isFileTransferSupported(toJID_));
+ contactSupportsReceipts_ = featureOracle.isMessageReceiptsSupported(toJID_);
- checkForDisplayingDisplayReceiptsAlert();
+ checkForDisplayingDisplayReceiptsAlert();
}
void ChatController::setToJID(const JID& jid) {
- chatStateNotifier_->setContact(jid);
- ChatControllerBase::setToJID(jid);
- Presence::ref presence;
- if (isInMUC_) {
- presence = presenceOracle_->getLastPresence(jid);
- } else {
- presence = jid.isBare() ? presenceOracle_->getAccountPresence(jid.toBare()) : presenceOracle_->getLastPresence(jid);
- }
- chatStateNotifier_->setContactIsOnline(presence && presence->getType() == Presence::Available);
- handleBareJIDCapsChanged(toJID_);
+ chatStateNotifier_->setContact(jid);
+ ChatControllerBase::setToJID(jid);
+ Presence::ref presence;
+ if (isInMUC_) {
+ presence = presenceOracle_->getLastPresence(jid);
+ } else {
+ presence = jid.isBare() ? presenceOracle_->getAccountPresence(jid.toBare()) : presenceOracle_->getLastPresence(jid);
+ }
+ chatStateNotifier_->setContactIsOnline(presence && presence->getType() == Presence::Available);
+ handleBareJIDCapsChanged(toJID_);
}
void ChatController::setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info) {
- ChatControllerBase::setAvailableServerFeatures(info);
- if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::BlockingCommandFeature)) {
- boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
+ ChatControllerBase::setAvailableServerFeatures(info);
+ if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::BlockingCommandFeature)) {
+ boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
- blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
- blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
- blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
+ blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
+ blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
+ blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
- handleBlockingStateChanged();
- }
+ handleBlockingStateChanged();
+ }
}
bool ChatController::isIncomingMessageFromMe(boost::shared_ptr<Message>) {
- return false;
+ return false;
}
void ChatController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
- if (messageEvent->isReadable()) {
- chatWindow_->flash();
- lastWasPresence_ = false;
- }
- boost::shared_ptr<Message> message = messageEvent->getStanza();
- JID from = message->getFrom();
- if (!from.equals(toJID_, JID::WithResource)) {
- if (toJID_.equals(from, JID::WithoutResource) && toJID_.isBare()){
- // Bind controller to a full JID if message contains body text or is a typing chat state.
- ChatState::ref chatState = message->getPayload<ChatState>();
- if (!message->getBody().get_value_or("").empty() || (chatState && chatState->getChatState() == ChatState::Composing)) {
- setToJID(from);
- }
- }
- }
- chatStateTracker_->handleMessageReceived(message);
- chatStateNotifier_->receivedMessageFromContact(!!message->getPayload<ChatState>());
-
- // handle XEP-0184 Message Receipts
- // incomming receipts
- if (boost::shared_ptr<DeliveryReceipt> receipt = message->getPayload<DeliveryReceipt>()) {
- SWIFT_LOG(debug) << "received receipt for id: " << receipt->getReceivedID() << std::endl;
- if (requestedReceipts_.find(receipt->getReceivedID()) != requestedReceipts_.end()) {
- chatWindow_->setMessageReceiptState(requestedReceipts_[receipt->getReceivedID()], ChatWindow::ReceiptReceived);
- requestedReceipts_.erase(receipt->getReceivedID());
- }
- // incomming errors in response to send out receipts
- } else if (message->getPayload<DeliveryReceiptRequest>() && (message->getType() == Message::Error)) {
- if (requestedReceipts_.find(message->getID()) != requestedReceipts_.end()) {
- chatWindow_->setMessageReceiptState(requestedReceipts_[message->getID()], ChatWindow::ReceiptFailed);
- requestedReceipts_.erase(message->getID());
- }
- // incoming receipt requests
- } else if (message->getPayload<DeliveryReceiptRequest>()) {
- if (receivingPresenceFromUs_) {
- boost::shared_ptr<Message> receiptMessage = boost::make_shared<Message>();
- receiptMessage->setTo(toJID_);
- receiptMessage->addPayload(boost::make_shared<DeliveryReceipt>(message->getID()));
- stanzaChannel_->sendMessage(receiptMessage);
- }
- }
+ if (messageEvent->isReadable()) {
+ chatWindow_->flash();
+ lastWasPresence_ = false;
+ }
+ boost::shared_ptr<Message> message = messageEvent->getStanza();
+ JID from = message->getFrom();
+ if (!from.equals(toJID_, JID::WithResource)) {
+ if (toJID_.equals(from, JID::WithoutResource) && toJID_.isBare()){
+ // Bind controller to a full JID if message contains body text or is a typing chat state.
+ ChatState::ref chatState = message->getPayload<ChatState>();
+ if (!message->getBody().get_value_or("").empty() || (chatState && chatState->getChatState() == ChatState::Composing)) {
+ setToJID(from);
+ }
+ }
+ }
+ chatStateTracker_->handleMessageReceived(message);
+ chatStateNotifier_->receivedMessageFromContact(!!message->getPayload<ChatState>());
+
+ // handle XEP-0184 Message Receipts
+ // incomming receipts
+ if (boost::shared_ptr<DeliveryReceipt> receipt = message->getPayload<DeliveryReceipt>()) {
+ SWIFT_LOG(debug) << "received receipt for id: " << receipt->getReceivedID() << std::endl;
+ if (requestedReceipts_.find(receipt->getReceivedID()) != requestedReceipts_.end()) {
+ chatWindow_->setMessageReceiptState(requestedReceipts_[receipt->getReceivedID()], ChatWindow::ReceiptReceived);
+ requestedReceipts_.erase(receipt->getReceivedID());
+ }
+ // incomming errors in response to send out receipts
+ } else if (message->getPayload<DeliveryReceiptRequest>() && (message->getType() == Message::Error)) {
+ if (requestedReceipts_.find(message->getID()) != requestedReceipts_.end()) {
+ chatWindow_->setMessageReceiptState(requestedReceipts_[message->getID()], ChatWindow::ReceiptFailed);
+ requestedReceipts_.erase(message->getID());
+ }
+ // incoming receipt requests
+ } else if (message->getPayload<DeliveryReceiptRequest>()) {
+ if (receivingPresenceFromUs_) {
+ boost::shared_ptr<Message> receiptMessage = boost::make_shared<Message>();
+ receiptMessage->setTo(toJID_);
+ receiptMessage->addPayload(boost::make_shared<DeliveryReceipt>(message->getID()));
+ stanzaChannel_->sendMessage(receiptMessage);
+ }
+ }
}
void ChatController::postHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent, const ChatWindow::ChatMessage& chatMessage) {
- eventController_->handleIncomingEvent(messageEvent);
- if (!messageEvent->getConcluded()) {
- handleHighlightActions(chatMessage);
- }
+ eventController_->handleIncomingEvent(messageEvent);
+ if (!messageEvent->getConcluded()) {
+ handleHighlightActions(chatMessage);
+ }
}
void ChatController::preSendMessageRequest(boost::shared_ptr<Message> message) {
- chatStateNotifier_->addChatStateRequest(message);
- if (userWantsReceipts_ && (contactSupportsReceipts_ != No) && message) {
- message->addPayload(boost::make_shared<DeliveryReceiptRequest>());
- }
+ chatStateNotifier_->addChatStateRequest(message);
+ if (userWantsReceipts_ && (contactSupportsReceipts_ != No) && message) {
+ message->addPayload(boost::make_shared<DeliveryReceiptRequest>());
+ }
}
void ChatController::setContactIsReceivingPresence(bool isReceivingPresence) {
- receivingPresenceFromUs_ = isReceivingPresence;
+ receivingPresenceFromUs_ = isReceivingPresence;
}
void ChatController::handleSettingChanged(const std::string& settingPath) {
- if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) {
- userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS);
- checkForDisplayingDisplayReceiptsAlert();
- }
+ if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) {
+ userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS);
+ checkForDisplayingDisplayReceiptsAlert();
+ }
}
void ChatController::checkForDisplayingDisplayReceiptsAlert() {
- boost::optional<ChatWindow::AlertID> newDeliverReceiptAlert;
- if (userWantsReceipts_ && (contactSupportsReceipts_ == No)) {
- newDeliverReceiptAlert = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "This chat doesn't support delivery receipts."));
- } else if (userWantsReceipts_ && (contactSupportsReceipts_ == Maybe)) {
- newDeliverReceiptAlert = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "This chat may not support delivery receipts. You might not receive delivery receipts for the messages you send."));
- } else {
- if (deliveryReceiptAlert_) {
- chatWindow_->removeAlert(*deliveryReceiptAlert_);
- deliveryReceiptAlert_.reset();
- }
- }
- if (newDeliverReceiptAlert) {
- if (deliveryReceiptAlert_) {
- chatWindow_->removeAlert(*deliveryReceiptAlert_);
- }
- deliveryReceiptAlert_ = newDeliverReceiptAlert;
- }
+ boost::optional<ChatWindow::AlertID> newDeliverReceiptAlert;
+ if (userWantsReceipts_ && (contactSupportsReceipts_ == No)) {
+ newDeliverReceiptAlert = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "This chat doesn't support delivery receipts."));
+ } else if (userWantsReceipts_ && (contactSupportsReceipts_ == Maybe)) {
+ newDeliverReceiptAlert = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "This chat may not support delivery receipts. You might not receive delivery receipts for the messages you send."));
+ } else {
+ if (deliveryReceiptAlert_) {
+ chatWindow_->removeAlert(*deliveryReceiptAlert_);
+ deliveryReceiptAlert_.reset();
+ }
+ }
+ if (newDeliverReceiptAlert) {
+ if (deliveryReceiptAlert_) {
+ chatWindow_->removeAlert(*deliveryReceiptAlert_);
+ }
+ deliveryReceiptAlert_ = newDeliverReceiptAlert;
+ }
}
void ChatController::handleBlockingStateChanged() {
- boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
- if (blockList->getState() == BlockList::Available) {
- if (isInMUC_ ? blockList->isBlocked(toJID_) : blockList->isBlocked(toJID_.toBare())) {
- if (!blockedContactAlert_) {
- blockedContactAlert_ = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "You've currently blocked this contact. To continue your conversation you have to unblock the contact first."));
- }
- chatWindow_->setBlockingState(ChatWindow::IsBlocked);
-
- // disconnect typing events to prevent chat state notifciations to blocked contacts
- chatWindow_->onUserTyping.disconnect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_));
- chatWindow_->onUserCancelsTyping.disconnect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_));
- } else {
- if (blockedContactAlert_) {
- chatWindow_->removeAlert(*blockedContactAlert_);
- blockedContactAlert_.reset();
- }
- chatWindow_->setBlockingState(ChatWindow::IsUnblocked);
-
- chatWindow_->onUserTyping.connect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_));
- chatWindow_->onUserCancelsTyping.connect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_));
- }
- }
+ boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
+ if (blockList->getState() == BlockList::Available) {
+ if (isInMUC_ ? blockList->isBlocked(toJID_) : blockList->isBlocked(toJID_.toBare())) {
+ if (!blockedContactAlert_) {
+ blockedContactAlert_ = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "You've currently blocked this contact. To continue your conversation you have to unblock the contact first."));
+ }
+ chatWindow_->setBlockingState(ChatWindow::IsBlocked);
+
+ // disconnect typing events to prevent chat state notifciations to blocked contacts
+ chatWindow_->onUserTyping.disconnect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_));
+ chatWindow_->onUserCancelsTyping.disconnect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_));
+ } else {
+ if (blockedContactAlert_) {
+ chatWindow_->removeAlert(*blockedContactAlert_);
+ blockedContactAlert_.reset();
+ }
+ chatWindow_->setBlockingState(ChatWindow::IsUnblocked);
+
+ chatWindow_->onUserTyping.connect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_));
+ chatWindow_->onUserCancelsTyping.connect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_));
+ }
+ }
}
void ChatController::handleBlockUserRequest() {
- if (isInMUC_) {
- eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Blocked, toJID_));
- } else {
- eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Blocked, toJID_.toBare()));
- }
+ if (isInMUC_) {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Blocked, toJID_));
+ } else {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Blocked, toJID_.toBare()));
+ }
}
void ChatController::handleUnblockUserRequest() {
- if (isInMUC_) {
- eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, toJID_));
- } else {
- eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, toJID_.toBare()));
- }
+ if (isInMUC_) {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, toJID_));
+ } else {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, toJID_.toBare()));
+ }
}
void ChatController::handleInviteToChat(const std::vector<JID>& droppedJIDs) {
- boost::shared_ptr<UIEvent> event(new RequestInviteToMUCUIEvent(toJID_.toBare(), droppedJIDs, RequestInviteToMUCUIEvent::Impromptu));
- eventStream_->send(event);
+ boost::shared_ptr<UIEvent> event(new RequestInviteToMUCUIEvent(toJID_.toBare(), droppedJIDs, RequestInviteToMUCUIEvent::Impromptu));
+ eventStream_->send(event);
}
void ChatController::handleWindowClosed() {
- onWindowClosed();
+ onWindowClosed();
}
void ChatController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
- boost::shared_ptr<InviteToMUCUIEvent> inviteEvent = boost::dynamic_pointer_cast<InviteToMUCUIEvent>(event);
- if (inviteEvent && inviteEvent->getRoom() == toJID_.toBare()) {
- onConvertToMUC(detachChatWindow(), inviteEvent->getInvites(), inviteEvent->getReason());
- }
+ boost::shared_ptr<InviteToMUCUIEvent> inviteEvent = boost::dynamic_pointer_cast<InviteToMUCUIEvent>(event);
+ if (inviteEvent && inviteEvent->getRoom() == toJID_.toBare()) {
+ onConvertToMUC(detachChatWindow(), inviteEvent->getInvites(), inviteEvent->getReason());
+ }
}
void ChatController::postSendMessage(const std::string& body, boost::shared_ptr<Stanza> sentStanza) {
- boost::shared_ptr<Replace> replace = sentStanza->getPayload<Replace>();
- if (replace) {
- eraseIf(unackedStanzas_, PairSecondEquals<boost::shared_ptr<Stanza>, std::string>(myLastMessageUIID_));
- replaceMessage(chatMessageParser_->parseMessageBody(body, "", true), myLastMessageUIID_, boost::posix_time::microsec_clock::universal_time());
- } else {
- myLastMessageUIID_ = addMessage(chatMessageParser_->parseMessageBody(body, "", true), QT_TRANSLATE_NOOP("", "me"), true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel().getLabel() : boost::shared_ptr<SecurityLabel>(), avatarManager_->getAvatarPath(selfJID_), boost::posix_time::microsec_clock::universal_time());
- }
+ boost::shared_ptr<Replace> replace = sentStanza->getPayload<Replace>();
+ if (replace) {
+ eraseIf(unackedStanzas_, PairSecondEquals<boost::shared_ptr<Stanza>, std::string>(myLastMessageUIID_));
+ replaceMessage(chatMessageParser_->parseMessageBody(body, "", true), myLastMessageUIID_, boost::posix_time::microsec_clock::universal_time());
+ } else {
+ myLastMessageUIID_ = addMessage(chatMessageParser_->parseMessageBody(body, "", true), QT_TRANSLATE_NOOP("", "me"), true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel().getLabel() : boost::shared_ptr<SecurityLabel>(), avatarManager_->getAvatarPath(selfJID_), boost::posix_time::microsec_clock::universal_time());
+ }
- if (stanzaChannel_->getStreamManagementEnabled() && !myLastMessageUIID_.empty() ) {
- chatWindow_->setAckState(myLastMessageUIID_, ChatWindow::Pending);
- unackedStanzas_[sentStanza] = myLastMessageUIID_;
- }
+ if (stanzaChannel_->getStreamManagementEnabled() && !myLastMessageUIID_.empty() ) {
+ chatWindow_->setAckState(myLastMessageUIID_, ChatWindow::Pending);
+ unackedStanzas_[sentStanza] = myLastMessageUIID_;
+ }
- if (sentStanza->getPayload<DeliveryReceiptRequest>()) {
- requestedReceipts_[sentStanza->getID()] = myLastMessageUIID_;
- chatWindow_->setMessageReceiptState(myLastMessageUIID_, ChatWindow::ReceiptRequested);
- }
+ if (sentStanza->getPayload<DeliveryReceiptRequest>()) {
+ requestedReceipts_[sentStanza->getID()] = myLastMessageUIID_;
+ chatWindow_->setMessageReceiptState(myLastMessageUIID_, ChatWindow::ReceiptRequested);
+ }
- lastWasPresence_ = false;
- chatStateNotifier_->userSentMessage();
+ lastWasPresence_ = false;
+ chatStateNotifier_->userSentMessage();
}
void ChatController::handleStanzaAcked(boost::shared_ptr<Stanza> stanza) {
- std::map<boost::shared_ptr<Stanza>, std::string>::iterator unackedStanza = unackedStanzas_.find(stanza);
- if (unackedStanza != unackedStanzas_.end()) {
- chatWindow_->setAckState(unackedStanza->second, ChatWindow::Received);
- unackedStanzas_.erase(unackedStanza);
- }
+ std::map<boost::shared_ptr<Stanza>, std::string>::iterator unackedStanza = unackedStanzas_.find(stanza);
+ if (unackedStanza != unackedStanzas_.end()) {
+ chatWindow_->setAckState(unackedStanza->second, ChatWindow::Received);
+ unackedStanzas_.erase(unackedStanza);
+ }
}
void ChatController::setOnline(bool online) {
- if (!online) {
- std::map<boost::shared_ptr<Stanza>, std::string>::iterator it = unackedStanzas_.begin();
- for ( ; it != unackedStanzas_.end(); ++it) {
- chatWindow_->setAckState(it->second, ChatWindow::Failed);
- }
- unackedStanzas_.clear();
+ if (!online) {
+ std::map<boost::shared_ptr<Stanza>, std::string>::iterator it = unackedStanzas_.begin();
+ for ( ; it != unackedStanzas_.end(); ++it) {
+ chatWindow_->setAckState(it->second, ChatWindow::Failed);
+ }
+ unackedStanzas_.clear();
- Presence::ref fakeOffline(new Presence());
- fakeOffline->setFrom(toJID_);
- fakeOffline->setType(Presence::Unavailable);
- chatStateTracker_->handlePresenceChange(fakeOffline);
- }
- ChatControllerBase::setOnline(online);
+ Presence::ref fakeOffline(new Presence());
+ fakeOffline->setFrom(toJID_);
+ fakeOffline->setType(Presence::Unavailable);
+ chatStateTracker_->handlePresenceChange(fakeOffline);
+ }
+ ChatControllerBase::setOnline(online);
}
void ChatController::handleNewFileTransferController(FileTransferController* ftc) {
- std::string nick = senderDisplayNameFromMessage(ftc->getOtherParty());
- std::string ftID = ftc->setChatWindow(chatWindow_, nick);
- ftControllers[ftID] = ftc;
- lastWasPresence_ = false;
+ std::string nick = senderDisplayNameFromMessage(ftc->getOtherParty());
+ std::string ftID = ftc->setChatWindow(chatWindow_, nick);
+ ftControllers[ftID] = ftc;
+ lastWasPresence_ = false;
}
void ChatController::handleWhiteboardSessionRequest(bool senderIsSelf) {
- lastWbID_ = chatWindow_->addWhiteboardRequest(senderIsSelf);
+ lastWbID_ = chatWindow_->addWhiteboardRequest(senderIsSelf);
}
void ChatController::handleWhiteboardStateChange(const ChatWindow::WhiteboardSessionState state) {
- chatWindow_->setWhiteboardSessionStatus(lastWbID_, state);
+ chatWindow_->setWhiteboardSessionStatus(lastWbID_, state);
}
void ChatController::handleFileTransferCancel(std::string id) {
- SWIFT_LOG(debug) << "handleFileTransferCancel(" << id << ")" << std::endl;
- if (ftControllers.find(id) != ftControllers.end()) {
- ftControllers[id]->cancel();
- } else {
- std::cerr << "unknown file transfer UI id" << std::endl;
- }
+ SWIFT_LOG(debug) << "handleFileTransferCancel(" << id << ")" << std::endl;
+ if (ftControllers.find(id) != ftControllers.end()) {
+ ftControllers[id]->cancel();
+ } else {
+ std::cerr << "unknown file transfer UI id" << std::endl;
+ }
}
void ChatController::handleFileTransferStart(std::string id, std::string description) {
- SWIFT_LOG(debug) << "handleFileTransferStart(" << id << ", " << description << ")" << std::endl;
- if (ftControllers.find(id) != ftControllers.end()) {
- ftControllers[id]->start(description);
- } else {
- std::cerr << "unknown file transfer UI id" << std::endl;
- }
+ SWIFT_LOG(debug) << "handleFileTransferStart(" << id << ", " << description << ")" << std::endl;
+ if (ftControllers.find(id) != ftControllers.end()) {
+ ftControllers[id]->start(description);
+ } else {
+ std::cerr << "unknown file transfer UI id" << std::endl;
+ }
}
void ChatController::handleFileTransferAccept(std::string id, std::string filename) {
- SWIFT_LOG(debug) << "handleFileTransferAccept(" << id << ", " << filename << ")" << std::endl;
- if (ftControllers.find(id) != ftControllers.end()) {
- ftControllers[id]->accept(filename);
- } else {
- std::cerr << "unknown file transfer UI id" << std::endl;
- }
+ SWIFT_LOG(debug) << "handleFileTransferAccept(" << id << ", " << filename << ")" << std::endl;
+ if (ftControllers.find(id) != ftControllers.end()) {
+ ftControllers[id]->accept(filename);
+ } else {
+ std::cerr << "unknown file transfer UI id" << std::endl;
+ }
}
void ChatController::handleSendFileRequest(std::string filename) {
- SWIFT_LOG(debug) << "ChatController::handleSendFileRequest(" << filename << ")" << std::endl;
- eventStream_->send(boost::make_shared<SendFileUIEvent>(getToJID(), filename));
+ SWIFT_LOG(debug) << "ChatController::handleSendFileRequest(" << filename << ")" << std::endl;
+ eventStream_->send(boost::make_shared<SendFileUIEvent>(getToJID(), filename));
}
void ChatController::handleWhiteboardSessionAccept() {
- eventStream_->send(boost::make_shared<AcceptWhiteboardSessionUIEvent>(toJID_));
+ eventStream_->send(boost::make_shared<AcceptWhiteboardSessionUIEvent>(toJID_));
}
void ChatController::handleWhiteboardSessionCancel() {
- eventStream_->send(boost::make_shared<CancelWhiteboardSessionUIEvent>(toJID_));
+ eventStream_->send(boost::make_shared<CancelWhiteboardSessionUIEvent>(toJID_));
}
void ChatController::handleWhiteboardWindowShow() {
- eventStream_->send(boost::make_shared<ShowWhiteboardUIEvent>(toJID_));
+ eventStream_->send(boost::make_shared<ShowWhiteboardUIEvent>(toJID_));
}
std::string ChatController::senderHighlightNameFromMessage(const JID& from) {
- if (isInMUC_) {
- return nickResolver_->jidToNick(from);
- }
- else {
- return from.toBare().toString();
- }
+ if (isInMUC_) {
+ return nickResolver_->jidToNick(from);
+ }
+ else {
+ return from.toBare().toString();
+ }
}
std::string ChatController::senderDisplayNameFromMessage(const JID& from) {
- return nickResolver_->jidToNick(from);
+ return nickResolver_->jidToNick(from);
}
std::string ChatController::getStatusChangeString(boost::shared_ptr<Presence> presence) {
- std::string nick = senderDisplayNameFromMessage(presence->getFrom());
- std::string response;
- if (!presence || presence->getType() == Presence::Unavailable || presence->getType() == Presence::Error) {
- response = QT_TRANSLATE_NOOP("", "%1% has gone offline");
- } else if (presence->getType() == Presence::Available) {
- StatusShow::Type show = presence->getShow();
- if (show == StatusShow::Online || show == StatusShow::FFC) {
- response = QT_TRANSLATE_NOOP("", "%1% has become available");
- } else if (show == StatusShow::Away || show == StatusShow::XA) {
- response = QT_TRANSLATE_NOOP("", "%1% has gone away");
- } else if (show == StatusShow::DND) {
- response = QT_TRANSLATE_NOOP("", "%1% is now busy");
- }
- }
- Idle::ref idle;
- if ((idle = presence->getPayload<Idle>())) {
- response += str(format(QT_TRANSLATE_NOOP("", " and has been idle since %1%")) % dateTimeToLocalString(idle->getSince()));
- }
-
- if (!response.empty()) {
- response = str(format(response) % nick);
- }
-
- if (!presence->getStatus().empty()) {
- response += " (" + presence->getStatus() + ")";
- }
- return response + ".";
+ std::string nick = senderDisplayNameFromMessage(presence->getFrom());
+ std::string response;
+ if (!presence || presence->getType() == Presence::Unavailable || presence->getType() == Presence::Error) {
+ response = QT_TRANSLATE_NOOP("", "%1% has gone offline");
+ } else if (presence->getType() == Presence::Available) {
+ StatusShow::Type show = presence->getShow();
+ if (show == StatusShow::Online || show == StatusShow::FFC) {
+ response = QT_TRANSLATE_NOOP("", "%1% has become available");
+ } else if (show == StatusShow::Away || show == StatusShow::XA) {
+ response = QT_TRANSLATE_NOOP("", "%1% has gone away");
+ } else if (show == StatusShow::DND) {
+ response = QT_TRANSLATE_NOOP("", "%1% is now busy");
+ }
+ }
+ Idle::ref idle;
+ if ((idle = presence->getPayload<Idle>())) {
+ response += str(format(QT_TRANSLATE_NOOP("", " and has been idle since %1%")) % dateTimeToLocalString(idle->getSince()));
+ }
+
+ if (!response.empty()) {
+ response = str(format(response) % nick);
+ }
+
+ if (!presence->getStatus().empty()) {
+ response += " (" + presence->getStatus() + ")";
+ }
+ return response + ".";
}
void ChatController::handlePresenceChange(boost::shared_ptr<Presence> newPresence) {
- bool relevantPresence = false;
-
- if (isInMUC_) {
- // For MUC participants we only have a single presence to choose one and
- // even for multi-session nicknames multiple resources are not distinguishable
- // to other participants.
- if (toJID_.equals(newPresence->getFrom(), JID::WithResource)) {
- relevantPresence = true;
- }
- }
- else {
- // For standard chats we retrieve the account presence from the PresenceOracle,
- // as there can be multiple presences to choose from.
- if (toJID_.equals(newPresence->getFrom(), JID::WithoutResource)) {
- // Presence matches ChatController JID.
- newPresence = presenceOracle_->getAccountPresence(toJID_);
- relevantPresence = true;
- }
- }
-
- if (!relevantPresence) {
- return;
- }
-
- if (!newPresence) {
- newPresence = boost::make_shared<Presence>();
- newPresence->setType(Presence::Unavailable);
- }
- lastShownStatus_ = newPresence->getShow();
-
- chatStateTracker_->handlePresenceChange(newPresence);
- chatStateNotifier_->setContactIsOnline(newPresence->getType() == Presence::Available);
- std::string newStatusChangeString = getStatusChangeString(newPresence);
- if (newStatusChangeString != lastStatusChangeString_) {
- if (lastWasPresence_) {
- chatWindow_->replaceLastMessage(chatMessageParser_->parseMessageBody(newStatusChangeString), ChatWindow::UpdateTimestamp);
- } else {
- chatWindow_->addPresenceMessage(chatMessageParser_->parseMessageBody(newStatusChangeString), ChatWindow::DefaultDirection);
- }
- lastStatusChangeString_ = newStatusChangeString;
- lastWasPresence_ = true;
- }
+ bool relevantPresence = false;
+
+ if (isInMUC_) {
+ // For MUC participants we only have a single presence to choose one and
+ // even for multi-session nicknames multiple resources are not distinguishable
+ // to other participants.
+ if (toJID_.equals(newPresence->getFrom(), JID::WithResource)) {
+ relevantPresence = true;
+ }
+ }
+ else {
+ // For standard chats we retrieve the account presence from the PresenceOracle,
+ // as there can be multiple presences to choose from.
+ if (toJID_.equals(newPresence->getFrom(), JID::WithoutResource)) {
+ // Presence matches ChatController JID.
+ newPresence = presenceOracle_->getAccountPresence(toJID_);
+ relevantPresence = true;
+ }
+ }
+
+ if (!relevantPresence) {
+ return;
+ }
+
+ if (!newPresence) {
+ newPresence = boost::make_shared<Presence>();
+ newPresence->setType(Presence::Unavailable);
+ }
+ lastShownStatus_ = newPresence->getShow();
+
+ chatStateTracker_->handlePresenceChange(newPresence);
+ chatStateNotifier_->setContactIsOnline(newPresence->getType() == Presence::Available);
+ std::string newStatusChangeString = getStatusChangeString(newPresence);
+ if (newStatusChangeString != lastStatusChangeString_) {
+ if (lastWasPresence_) {
+ chatWindow_->replaceLastMessage(chatMessageParser_->parseMessageBody(newStatusChangeString), ChatWindow::UpdateTimestamp);
+ } else {
+ chatWindow_->addPresenceMessage(chatMessageParser_->parseMessageBody(newStatusChangeString), ChatWindow::DefaultDirection);
+ }
+ lastStatusChangeString_ = newStatusChangeString;
+ lastWasPresence_ = true;
+ }
}
boost::optional<boost::posix_time::ptime> ChatController::getMessageTimestamp(boost::shared_ptr<Message> message) const {
- return message->getTimestamp();
+ return message->getTimestamp();
}
void ChatController::logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool /* isIncoming */) {
- HistoryMessage::Type type;
- if (mucRegistry_->isMUC(fromJID.toBare()) || mucRegistry_->isMUC(toJID.toBare())) {
- type = HistoryMessage::PrivateMessage;
- }
- else {
- type = HistoryMessage::Chat;
- }
+ HistoryMessage::Type type;
+ if (mucRegistry_->isMUC(fromJID.toBare()) || mucRegistry_->isMUC(toJID.toBare())) {
+ type = HistoryMessage::PrivateMessage;
+ }
+ else {
+ type = HistoryMessage::Chat;
+ }
- if (historyController_) {
- historyController_->addMessage(message, fromJID, toJID, type, timeStamp);
- }
+ if (historyController_) {
+ historyController_->addMessage(message, fromJID, toJID, type, timeStamp);
+ }
}
ChatWindow* ChatController::detachChatWindow() {
- chatWindow_->onUserTyping.disconnect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_));
- chatWindow_->onUserCancelsTyping.disconnect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_));
- return ChatControllerBase::detachChatWindow();
+ chatWindow_->onUserTyping.disconnect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_));
+ chatWindow_->onUserCancelsTyping.disconnect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_));
+ return ChatControllerBase::detachChatWindow();
}
}
diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h
index 6ec19df..aa2b203 100644
--- a/Swift/Controllers/Chat/ChatController.h
+++ b/Swift/Controllers/Chat/ChatController.h
@@ -16,101 +16,101 @@
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
namespace Swift {
- class AvatarManager;
- class ChatStateNotifier;
- class ChatStateTracker;
- class NickResolver;
- class EntityCapsProvider;
- class FileTransferController;
- class SettingsProvider;
- class HistoryController;
- class HighlightManager;
- class ClientBlockListManager;
- class UIEvent;
-
- class ChatController : public ChatControllerBase {
- public:
- ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts, SettingsProvider* settings, HistoryController* historyController, MUCRegistry* mucRegistry, HighlightManager* highlightManager, ClientBlockListManager* clientBlockListManager, boost::shared_ptr<ChatMessageParser> chatMessageParser, AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider);
- virtual ~ChatController();
- virtual void setToJID(const JID& jid) SWIFTEN_OVERRIDE;
- virtual void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info) SWIFTEN_OVERRIDE;
- virtual void setOnline(bool online) SWIFTEN_OVERRIDE;
- virtual void handleNewFileTransferController(FileTransferController* ftc);
- virtual void handleWhiteboardSessionRequest(bool senderIsSelf);
- virtual void handleWhiteboardStateChange(const ChatWindow::WhiteboardSessionState state);
- virtual void setContactIsReceivingPresence(bool /*isReceivingPresence*/) SWIFTEN_OVERRIDE;
- virtual ChatWindow* detachChatWindow() SWIFTEN_OVERRIDE;
-
- protected:
- virtual void cancelReplaces() SWIFTEN_OVERRIDE;
- virtual JID getBaseJID() SWIFTEN_OVERRIDE;
- virtual void logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) SWIFTEN_OVERRIDE;
-
- private:
- void handlePresenceChange(boost::shared_ptr<Presence> newPresence);
- std::string getStatusChangeString(boost::shared_ptr<Presence> presence);
- virtual bool isIncomingMessageFromMe(boost::shared_ptr<Message> message) SWIFTEN_OVERRIDE;
- virtual void postSendMessage(const std::string &body, boost::shared_ptr<Stanza> sentStanza) SWIFTEN_OVERRIDE;
- virtual void preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) SWIFTEN_OVERRIDE;
- virtual void postHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent, const ChatWindow::ChatMessage& chatMessage) SWIFTEN_OVERRIDE;
- virtual void preSendMessageRequest(boost::shared_ptr<Message>) SWIFTEN_OVERRIDE;
- virtual std::string senderHighlightNameFromMessage(const JID& from) SWIFTEN_OVERRIDE;
- virtual std::string senderDisplayNameFromMessage(const JID& from) SWIFTEN_OVERRIDE;
- virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message>) const SWIFTEN_OVERRIDE;
- void handleStanzaAcked(boost::shared_ptr<Stanza> stanza);
- virtual void dayTicked() SWIFTEN_OVERRIDE { lastWasPresence_ = false; }
- void handleContactNickChanged(const JID& jid, const std::string& /*oldNick*/);
- virtual void handleBareJIDCapsChanged(const JID& jid) SWIFTEN_OVERRIDE;
-
- void handleFileTransferCancel(std::string /* id */);
- void handleFileTransferStart(std::string /* id */, std::string /* description */);
- void handleFileTransferAccept(std::string /* id */, std::string /* filename */);
- void handleSendFileRequest(std::string filename);
-
- void handleWhiteboardSessionAccept();
- void handleWhiteboardSessionCancel();
- void handleWhiteboardWindowShow();
-
- void handleSettingChanged(const std::string& settingPath);
- void checkForDisplayingDisplayReceiptsAlert();
-
- void handleBlockingStateChanged();
- void handleBlockUserRequest();
- void handleUnblockUserRequest();
-
- void handleInviteToChat(const std::vector<JID>& droppedJIDs);
-
- void handleWindowClosed();
-
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
-
- private:
- NickResolver* nickResolver_;
- ChatStateNotifier* chatStateNotifier_;
- ChatStateTracker* chatStateTracker_;
- std::string myLastMessageUIID_;
- bool isInMUC_;
- bool lastWasPresence_;
- std::string lastStatusChangeString_;
- std::map<boost::shared_ptr<Stanza>, std::string> unackedStanzas_;
- std::map<std::string, std::string> requestedReceipts_;
- StatusShow::Type lastShownStatus_;
- UIEventStream* eventStream_;
-
- Tristate contactSupportsReceipts_;
- bool receivingPresenceFromUs_;
- bool userWantsReceipts_;
- std::map<std::string, FileTransferController*> ftControllers;
- SettingsProvider* settings_;
- std::string lastWbID_;
-
- ClientBlockListManager* clientBlockListManager_;
- boost::bsignals::scoped_connection blockingOnStateChangedConnection_;
- boost::bsignals::scoped_connection blockingOnItemAddedConnection_;
- boost::bsignals::scoped_connection blockingOnItemRemovedConnection_;
-
- boost::optional<ChatWindow::AlertID> deliveryReceiptAlert_;
- boost::optional<ChatWindow::AlertID> blockedContactAlert_;
- };
+ class AvatarManager;
+ class ChatStateNotifier;
+ class ChatStateTracker;
+ class NickResolver;
+ class EntityCapsProvider;
+ class FileTransferController;
+ class SettingsProvider;
+ class HistoryController;
+ class HighlightManager;
+ class ClientBlockListManager;
+ class UIEvent;
+
+ class ChatController : public ChatControllerBase {
+ public:
+ ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts, SettingsProvider* settings, HistoryController* historyController, MUCRegistry* mucRegistry, HighlightManager* highlightManager, ClientBlockListManager* clientBlockListManager, boost::shared_ptr<ChatMessageParser> chatMessageParser, AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider);
+ virtual ~ChatController();
+ virtual void setToJID(const JID& jid) SWIFTEN_OVERRIDE;
+ virtual void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info) SWIFTEN_OVERRIDE;
+ virtual void setOnline(bool online) SWIFTEN_OVERRIDE;
+ virtual void handleNewFileTransferController(FileTransferController* ftc);
+ virtual void handleWhiteboardSessionRequest(bool senderIsSelf);
+ virtual void handleWhiteboardStateChange(const ChatWindow::WhiteboardSessionState state);
+ virtual void setContactIsReceivingPresence(bool /*isReceivingPresence*/) SWIFTEN_OVERRIDE;
+ virtual ChatWindow* detachChatWindow() SWIFTEN_OVERRIDE;
+
+ protected:
+ virtual void cancelReplaces() SWIFTEN_OVERRIDE;
+ virtual JID getBaseJID() SWIFTEN_OVERRIDE;
+ virtual void logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) SWIFTEN_OVERRIDE;
+
+ private:
+ void handlePresenceChange(boost::shared_ptr<Presence> newPresence);
+ std::string getStatusChangeString(boost::shared_ptr<Presence> presence);
+ virtual bool isIncomingMessageFromMe(boost::shared_ptr<Message> message) SWIFTEN_OVERRIDE;
+ virtual void postSendMessage(const std::string &body, boost::shared_ptr<Stanza> sentStanza) SWIFTEN_OVERRIDE;
+ virtual void preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) SWIFTEN_OVERRIDE;
+ virtual void postHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent, const ChatWindow::ChatMessage& chatMessage) SWIFTEN_OVERRIDE;
+ virtual void preSendMessageRequest(boost::shared_ptr<Message>) SWIFTEN_OVERRIDE;
+ virtual std::string senderHighlightNameFromMessage(const JID& from) SWIFTEN_OVERRIDE;
+ virtual std::string senderDisplayNameFromMessage(const JID& from) SWIFTEN_OVERRIDE;
+ virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message>) const SWIFTEN_OVERRIDE;
+ void handleStanzaAcked(boost::shared_ptr<Stanza> stanza);
+ virtual void dayTicked() SWIFTEN_OVERRIDE { lastWasPresence_ = false; }
+ void handleContactNickChanged(const JID& jid, const std::string& /*oldNick*/);
+ virtual void handleBareJIDCapsChanged(const JID& jid) SWIFTEN_OVERRIDE;
+
+ void handleFileTransferCancel(std::string /* id */);
+ void handleFileTransferStart(std::string /* id */, std::string /* description */);
+ void handleFileTransferAccept(std::string /* id */, std::string /* filename */);
+ void handleSendFileRequest(std::string filename);
+
+ void handleWhiteboardSessionAccept();
+ void handleWhiteboardSessionCancel();
+ void handleWhiteboardWindowShow();
+
+ void handleSettingChanged(const std::string& settingPath);
+ void checkForDisplayingDisplayReceiptsAlert();
+
+ void handleBlockingStateChanged();
+ void handleBlockUserRequest();
+ void handleUnblockUserRequest();
+
+ void handleInviteToChat(const std::vector<JID>& droppedJIDs);
+
+ void handleWindowClosed();
+
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+
+ private:
+ NickResolver* nickResolver_;
+ ChatStateNotifier* chatStateNotifier_;
+ ChatStateTracker* chatStateTracker_;
+ std::string myLastMessageUIID_;
+ bool isInMUC_;
+ bool lastWasPresence_;
+ std::string lastStatusChangeString_;
+ std::map<boost::shared_ptr<Stanza>, std::string> unackedStanzas_;
+ std::map<std::string, std::string> requestedReceipts_;
+ StatusShow::Type lastShownStatus_;
+ UIEventStream* eventStream_;
+
+ Tristate contactSupportsReceipts_;
+ bool receivingPresenceFromUs_;
+ bool userWantsReceipts_;
+ std::map<std::string, FileTransferController*> ftControllers;
+ SettingsProvider* settings_;
+ std::string lastWbID_;
+
+ ClientBlockListManager* clientBlockListManager_;
+ boost::bsignals::scoped_connection blockingOnStateChangedConnection_;
+ boost::bsignals::scoped_connection blockingOnItemAddedConnection_;
+ boost::bsignals::scoped_connection blockingOnItemRemovedConnection_;
+
+ boost::optional<ChatWindow::AlertID> deliveryReceiptAlert_;
+ boost::optional<ChatWindow::AlertID> blockedContactAlert_;
+ };
}
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index c790cce..d478e2a 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -43,378 +43,378 @@
namespace Swift {
ChatControllerBase::ChatControllerBase(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, HistoryController* historyController, MUCRegistry* mucRegistry, HighlightManager* highlightManager, boost::shared_ptr<ChatMessageParser> chatMessageParser, AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider) : selfJID_(self), stanzaChannel_(stanzaChannel), iqRouter_(iqRouter), chatWindowFactory_(chatWindowFactory), toJID_(toJID), labelsEnabled_(false), presenceOracle_(presenceOracle), avatarManager_(avatarManager), useDelayForLatency_(useDelayForLatency), eventController_(eventController), timerFactory_(timerFactory), entityCapsProvider_(entityCapsProvider), historyController_(historyController), mucRegistry_(mucRegistry), chatMessageParser_(chatMessageParser), autoAcceptMUCInviteDecider_(autoAcceptMUCInviteDecider), eventStream_(eventStream) {
- chatWindow_ = chatWindowFactory_->createChatWindow(toJID, eventStream);
- chatWindow_->onAllMessagesRead.connect(boost::bind(&ChatControllerBase::handleAllMessagesRead, this));
- chatWindow_->onSendMessageRequest.connect(boost::bind(&ChatControllerBase::handleSendMessageRequest, this, _1, _2));
- chatWindow_->onLogCleared.connect(boost::bind(&ChatControllerBase::handleLogCleared, this));
- entityCapsProvider_->onCapsChanged.connect(boost::bind(&ChatControllerBase::handleCapsChanged, this, _1));
- highlighter_ = highlightManager->createHighlighter();
- ChatControllerBase::setOnline(stanzaChannel->isAvailable() && iqRouter->isAvailable());
- createDayChangeTimer();
+ chatWindow_ = chatWindowFactory_->createChatWindow(toJID, eventStream);
+ chatWindow_->onAllMessagesRead.connect(boost::bind(&ChatControllerBase::handleAllMessagesRead, this));
+ chatWindow_->onSendMessageRequest.connect(boost::bind(&ChatControllerBase::handleSendMessageRequest, this, _1, _2));
+ chatWindow_->onLogCleared.connect(boost::bind(&ChatControllerBase::handleLogCleared, this));
+ entityCapsProvider_->onCapsChanged.connect(boost::bind(&ChatControllerBase::handleCapsChanged, this, _1));
+ highlighter_ = highlightManager->createHighlighter();
+ ChatControllerBase::setOnline(stanzaChannel->isAvailable() && iqRouter->isAvailable());
+ createDayChangeTimer();
}
ChatControllerBase::~ChatControllerBase() {
- if (dateChangeTimer_) {
- dateChangeTimer_->onTick.disconnect(boost::bind(&ChatControllerBase::handleDayChangeTick, this));
- dateChangeTimer_->stop();
- }
+ if (dateChangeTimer_) {
+ dateChangeTimer_->onTick.disconnect(boost::bind(&ChatControllerBase::handleDayChangeTick, this));
+ dateChangeTimer_->stop();
+ }
- delete highlighter_;
- delete chatWindow_;
+ delete highlighter_;
+ delete chatWindow_;
}
void ChatControllerBase::handleLogCleared() {
- cancelReplaces();
+ cancelReplaces();
}
ChatWindow* ChatControllerBase::detachChatWindow() {
- ChatWindow* chatWindow = chatWindow_;
- chatWindow_ = NULL;
- return chatWindow;
+ ChatWindow* chatWindow = chatWindow_;
+ chatWindow_ = NULL;
+ return chatWindow;
}
void ChatControllerBase::handleCapsChanged(const JID& jid) {
- if (jid.compare(toJID_, JID::WithoutResource) == 0) {
- handleBareJIDCapsChanged(jid);
- }
+ if (jid.compare(toJID_, JID::WithoutResource) == 0) {
+ handleBareJIDCapsChanged(jid);
+ }
}
void ChatControllerBase::setCanStartImpromptuChats(bool supportsImpromptu) {
- if (chatWindow_) {
- chatWindow_->setCanInitiateImpromptuChats(supportsImpromptu);
- }
+ if (chatWindow_) {
+ chatWindow_->setCanInitiateImpromptuChats(supportsImpromptu);
+ }
}
void ChatControllerBase::createDayChangeTimer() {
- if (timerFactory_) {
- boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
- boost::posix_time::ptime midnight(now.date() + boost::gregorian::days(1));
- int millisecondsUntilMidnight = boost::numeric_cast<int>((midnight - now).total_milliseconds());
- dateChangeTimer_ = timerFactory_->createTimer(millisecondsUntilMidnight);
- dateChangeTimer_->onTick.connect(boost::bind(&ChatControllerBase::handleDayChangeTick, this));
- dateChangeTimer_->start();
- }
+ if (timerFactory_) {
+ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
+ boost::posix_time::ptime midnight(now.date() + boost::gregorian::days(1));
+ int millisecondsUntilMidnight = boost::numeric_cast<int>((midnight - now).total_milliseconds());
+ dateChangeTimer_ = timerFactory_->createTimer(millisecondsUntilMidnight);
+ dateChangeTimer_->onTick.connect(boost::bind(&ChatControllerBase::handleDayChangeTick, this));
+ dateChangeTimer_->start();
+ }
}
void ChatControllerBase::handleDayChangeTick() {
- dateChangeTimer_->stop();
- boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "The day is now %1%")) % std::string(boost::posix_time::to_iso_extended_string(now)).substr(0,10))), ChatWindow::DefaultDirection);
- dayTicked();
- createDayChangeTimer();
+ dateChangeTimer_->stop();
+ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "The day is now %1%")) % std::string(boost::posix_time::to_iso_extended_string(now)).substr(0,10))), ChatWindow::DefaultDirection);
+ dayTicked();
+ createDayChangeTimer();
}
void ChatControllerBase::setEnabled(bool enabled) {
- chatWindow_->setOnline(enabled);
- chatWindow_->setCanInitiateImpromptuChats(false);
+ chatWindow_->setOnline(enabled);
+ chatWindow_->setCanInitiateImpromptuChats(false);
}
void ChatControllerBase::setOnline(bool online) {
- setEnabled(online);
+ setEnabled(online);
}
JID ChatControllerBase::getBaseJID() {
- return JID(toJID_.toBare());
+ return JID(toJID_.toBare());
}
void ChatControllerBase::setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info) {
- if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::SecurityLabelsCatalogFeature)) {
- GetSecurityLabelsCatalogRequest::ref request = GetSecurityLabelsCatalogRequest::create(getBaseJID(), iqRouter_);
- request->onResponse.connect(boost::bind(&ChatControllerBase::handleSecurityLabelsCatalogResponse, this, _1, _2));
- request->send();
- } else {
- chatWindow_->setSecurityLabelsEnabled(false);
- labelsEnabled_ = false;
- }
+ if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::SecurityLabelsCatalogFeature)) {
+ GetSecurityLabelsCatalogRequest::ref request = GetSecurityLabelsCatalogRequest::create(getBaseJID(), iqRouter_);
+ request->onResponse.connect(boost::bind(&ChatControllerBase::handleSecurityLabelsCatalogResponse, this, _1, _2));
+ request->send();
+ } else {
+ chatWindow_->setSecurityLabelsEnabled(false);
+ labelsEnabled_ = false;
+ }
}
void ChatControllerBase::handleAllMessagesRead() {
- if (!unreadMessages_.empty()) {
- targetedUnreadMessages_.clear();
- foreach (boost::shared_ptr<StanzaEvent> stanzaEvent, unreadMessages_) {
- stanzaEvent->conclude();
- }
- unreadMessages_.clear();
- chatWindow_->setUnreadMessageCount(0);
- onUnreadCountChanged();
- }
+ if (!unreadMessages_.empty()) {
+ targetedUnreadMessages_.clear();
+ foreach (boost::shared_ptr<StanzaEvent> stanzaEvent, unreadMessages_) {
+ stanzaEvent->conclude();
+ }
+ unreadMessages_.clear();
+ chatWindow_->setUnreadMessageCount(0);
+ onUnreadCountChanged();
+ }
}
int ChatControllerBase::getUnreadCount() {
- return boost::numeric_cast<int>(targetedUnreadMessages_.size());
+ return boost::numeric_cast<int>(targetedUnreadMessages_.size());
}
void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool isCorrectionMessage) {
- if (!stanzaChannel_->isAvailable() || body.empty()) {
- return;
- }
- boost::shared_ptr<Message> message(new Message());
- message->setTo(toJID_);
- message->setType(Swift::Message::Chat);
- message->setBody(body);
- if (labelsEnabled_) {
- if (!isCorrectionMessage) {
- lastLabel_ = chatWindow_->getSelectedSecurityLabel();
- }
- SecurityLabelsCatalog::Item labelItem = lastLabel_;
- if (labelItem.getLabel()) {
- message->addPayload(labelItem.getLabel());
- }
- }
- preSendMessageRequest(message);
-
- boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
- if (useDelayForLatency_) {
- message->addPayload(boost::make_shared<Delay>(now, selfJID_));
- }
- if (isCorrectionMessage) {
- message->addPayload(boost::shared_ptr<Replace> (new Replace(lastSentMessageStanzaID_)));
- }
- message->setID(lastSentMessageStanzaID_ = idGenerator_.generateID());
- stanzaChannel_->sendMessage(message);
- postSendMessage(message->getBody().get(), boost::dynamic_pointer_cast<Stanza>(message));
- onActivity(message->getBody().get());
+ if (!stanzaChannel_->isAvailable() || body.empty()) {
+ return;
+ }
+ boost::shared_ptr<Message> message(new Message());
+ message->setTo(toJID_);
+ message->setType(Swift::Message::Chat);
+ message->setBody(body);
+ if (labelsEnabled_) {
+ if (!isCorrectionMessage) {
+ lastLabel_ = chatWindow_->getSelectedSecurityLabel();
+ }
+ SecurityLabelsCatalog::Item labelItem = lastLabel_;
+ if (labelItem.getLabel()) {
+ message->addPayload(labelItem.getLabel());
+ }
+ }
+ preSendMessageRequest(message);
+
+ boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
+ if (useDelayForLatency_) {
+ message->addPayload(boost::make_shared<Delay>(now, selfJID_));
+ }
+ if (isCorrectionMessage) {
+ message->addPayload(boost::shared_ptr<Replace> (new Replace(lastSentMessageStanzaID_)));
+ }
+ message->setID(lastSentMessageStanzaID_ = idGenerator_.generateID());
+ stanzaChannel_->sendMessage(message);
+ postSendMessage(message->getBody().get(), boost::dynamic_pointer_cast<Stanza>(message));
+ onActivity(message->getBody().get());
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- logMessage(body, selfJID_, toJID_, now, false);
+ logMessage(body, selfJID_, toJID_, now, false);
#endif
}
void ChatControllerBase::handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog> catalog, ErrorPayload::ref error) {
- if (catalog && !error) {
- if (catalog->getItems().size() == 0) {
- chatWindow_->setSecurityLabelsEnabled(false);
- labelsEnabled_ = false;
- } else {
- labelsEnabled_ = true;
- chatWindow_->setAvailableSecurityLabels(catalog->getItems());
- chatWindow_->setSecurityLabelsEnabled(true);
- }
- } else {
- labelsEnabled_ = false;
- chatWindow_->setSecurityLabelsError();
- }
+ if (catalog && !error) {
+ if (catalog->getItems().size() == 0) {
+ chatWindow_->setSecurityLabelsEnabled(false);
+ labelsEnabled_ = false;
+ } else {
+ labelsEnabled_ = true;
+ chatWindow_->setAvailableSecurityLabels(catalog->getItems());
+ chatWindow_->setSecurityLabelsEnabled(true);
+ }
+ } else {
+ labelsEnabled_ = false;
+ chatWindow_->setSecurityLabelsError();
+ }
}
void ChatControllerBase::showChatWindow() {
- chatWindow_->show();
+ chatWindow_->show();
}
void ChatControllerBase::activateChatWindow() {
- chatWindow_->activate();
+ chatWindow_->activate();
}
bool ChatControllerBase::hasOpenWindow() const {
- return chatWindow_ && chatWindow_->isVisible();
+ return chatWindow_ && chatWindow_->isVisible();
}
ChatWindow::ChatMessage ChatControllerBase::buildChatWindowChatMessage(const std::string& message, bool senderIsSelf, const HighlightAction& fullMessageHighlightAction) {
- ChatWindow::ChatMessage chatMessage;
- if (boost::starts_with(message, "/me ")) {
- chatMessage = chatMessageParser_->parseMessageBody(String::getSplittedAtFirst(message, ' ').second);
- }
- else {
- chatMessage = chatMessageParser_->parseMessageBody(message, highlighter_->getNick(), senderIsSelf);
- }
- chatMessage.setFullMessageHighlightAction(fullMessageHighlightAction);
- return chatMessage;
+ ChatWindow::ChatMessage chatMessage;
+ if (boost::starts_with(message, "/me ")) {
+ chatMessage = chatMessageParser_->parseMessageBody(String::getSplittedAtFirst(message, ' ').second);
+ }
+ else {
+ chatMessage = chatMessageParser_->parseMessageBody(message, highlighter_->getNick(), senderIsSelf);
+ }
+ chatMessage.setFullMessageHighlightAction(fullMessageHighlightAction);
+ return chatMessage;
}
void ChatControllerBase::handleHighlightActions(const ChatWindow::ChatMessage& chatMessage) {
- std::set<std::string> playedSounds;
- if (chatMessage.getFullMessageHighlightAction().playSound()) {
- highlighter_->handleHighlightAction(chatMessage.getFullMessageHighlightAction());
- playedSounds.insert(chatMessage.getFullMessageHighlightAction().getSoundFile());
- }
- foreach(boost::shared_ptr<ChatWindow::ChatMessagePart> part, chatMessage.getParts()) {
- boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightMessage = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part);
- if (highlightMessage && highlightMessage->action.playSound()) {
- if (playedSounds.find(highlightMessage->action.getSoundFile()) == playedSounds.end()) {
- highlighter_->handleHighlightAction(highlightMessage->action);
- playedSounds.insert(highlightMessage->action.getSoundFile());
- }
- }
- }
+ std::set<std::string> playedSounds;
+ if (chatMessage.getFullMessageHighlightAction().playSound()) {
+ highlighter_->handleHighlightAction(chatMessage.getFullMessageHighlightAction());
+ playedSounds.insert(chatMessage.getFullMessageHighlightAction().getSoundFile());
+ }
+ foreach(boost::shared_ptr<ChatWindow::ChatMessagePart> part, chatMessage.getParts()) {
+ boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightMessage = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part);
+ if (highlightMessage && highlightMessage->action.playSound()) {
+ if (playedSounds.find(highlightMessage->action.getSoundFile()) == playedSounds.end()) {
+ highlighter_->handleHighlightAction(highlightMessage->action);
+ playedSounds.insert(highlightMessage->action.getSoundFile());
+ }
+ }
+ }
}
std::string ChatControllerBase::addMessage(const ChatWindow::ChatMessage& chatMessage, const std::string& senderName, bool senderIsSelf, const boost::shared_ptr<SecurityLabel> label, const boost::filesystem::path& avatarPath, const boost::posix_time::ptime& time) {
- if (chatMessage.isMeCommand()) {
- return chatWindow_->addAction(chatMessage, senderName, senderIsSelf, label, pathToString(avatarPath), time);
- }
- else {
- return chatWindow_->addMessage(chatMessage, senderName, senderIsSelf, label, pathToString(avatarPath), time);
- }
+ if (chatMessage.isMeCommand()) {
+ return chatWindow_->addAction(chatMessage, senderName, senderIsSelf, label, pathToString(avatarPath), time);
+ }
+ else {
+ return chatWindow_->addMessage(chatMessage, senderName, senderIsSelf, label, pathToString(avatarPath), time);
+ }
}
void ChatControllerBase::replaceMessage(const ChatWindow::ChatMessage& chatMessage, const std::string& id, const boost::posix_time::ptime& time) {
- if (chatMessage.isMeCommand()) {
- chatWindow_->replaceWithAction(chatMessage, id, time);
- }
- else {
- chatWindow_->replaceMessage(chatMessage, id, time);
- }
+ if (chatMessage.isMeCommand()) {
+ chatWindow_->replaceWithAction(chatMessage, id, time);
+ }
+ else {
+ chatWindow_->replaceMessage(chatMessage, id, time);
+ }
}
bool ChatControllerBase::isFromContact(const JID& from) {
- return from.toBare() == toJID_.toBare();
+ return from.toBare() == toJID_.toBare();
}
void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
- preHandleIncomingMessage(messageEvent);
- if (messageEvent->isReadable() && !messageEvent->getConcluded()) {
- unreadMessages_.push_back(messageEvent);
- if (messageEvent->targetsMe()) {
- targetedUnreadMessages_.push_back(messageEvent);
- }
- }
-
- boost::shared_ptr<Message> message = messageEvent->getStanza();
- ChatWindow::ChatMessage chatMessage;
- boost::optional<std::string> optionalBody = message->getBody();
- std::string body = optionalBody.get_value_or("");
- if (message->isError()) {
- if (!message->getTo().getResource().empty()) {
- std::string errorMessage = str(format(QT_TRANSLATE_NOOP("", "Couldn't send message: %1%")) % getErrorMessage(message->getPayload<ErrorPayload>()));
- chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
- }
- }
- else if (messageEvent->getStanza()->getPayload<MUCInvitationPayload>()) {
- handleMUCInvitation(messageEvent->getStanza());
- return;
- }
- else if (messageEvent->getStanza()->getPayload<MUCUserPayload>() && messageEvent->getStanza()->getPayload<MUCUserPayload>()->getInvite()) {
- handleMediatedMUCInvitation(messageEvent->getStanza());
- return;
- }
- else {
- if (!messageEvent->isReadable()) {
- return;
- }
- showChatWindow();
- JID from = message->getFrom();
- std::vector<boost::shared_ptr<Delay> > delayPayloads = message->getPayloads<Delay>();
- for (size_t i = 0; useDelayForLatency_ && i < delayPayloads.size(); i++) {
- if (!delayPayloads[i]->getFrom()) {
- continue;
- }
- boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
- std::ostringstream s;
- s << "The following message took " << (now - delayPayloads[i]->getStamp()).total_milliseconds() / 1000.0 << " seconds to be delivered from " << delayPayloads[i]->getFrom()->toString() << ".";
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(std::string(s.str())), ChatWindow::DefaultDirection);
- }
- boost::shared_ptr<SecurityLabel> label = message->getPayload<SecurityLabel>();
-
- // Determine the timestamp
- boost::posix_time::ptime timeStamp = boost::posix_time::microsec_clock::universal_time();
- boost::optional<boost::posix_time::ptime> messageTimeStamp = getMessageTimestamp(message);
- if (messageTimeStamp) {
- timeStamp = *messageTimeStamp;
- }
- onActivity(body);
-
- // Highlight
- HighlightAction fullMessageHighlight;
- if (!isIncomingMessageFromMe(message)) {
- fullMessageHighlight = highlighter_->findFirstFullMessageMatchAction(body, senderHighlightNameFromMessage(from));
- }
-
- boost::shared_ptr<Replace> replace = message->getPayload<Replace>();
- bool senderIsSelf = isIncomingMessageFromMe(message);
- if (replace) {
- // Should check if the user has a previous message
- std::map<JID, std::string>::iterator lastMessage;
- lastMessage = lastMessagesUIID_.find(from);
- if (lastMessage != lastMessagesUIID_.end()) {
- chatMessage = buildChatWindowChatMessage(body, senderIsSelf, fullMessageHighlight);
- replaceMessage(chatMessage, lastMessagesUIID_[from], timeStamp);
- }
- }
- else {
- chatMessage = buildChatWindowChatMessage(body, senderIsSelf, fullMessageHighlight);
- addMessageHandleIncomingMessage(from, chatMessage, senderIsSelf, label, timeStamp);
- }
-
- logMessage(body, from, selfJID_, timeStamp, true);
- }
- chatWindow_->show();
- chatWindow_->setUnreadMessageCount(boost::numeric_cast<int>(unreadMessages_.size()));
- onUnreadCountChanged();
- postHandleIncomingMessage(messageEvent, chatMessage);
+ preHandleIncomingMessage(messageEvent);
+ if (messageEvent->isReadable() && !messageEvent->getConcluded()) {
+ unreadMessages_.push_back(messageEvent);
+ if (messageEvent->targetsMe()) {
+ targetedUnreadMessages_.push_back(messageEvent);
+ }
+ }
+
+ boost::shared_ptr<Message> message = messageEvent->getStanza();
+ ChatWindow::ChatMessage chatMessage;
+ boost::optional<std::string> optionalBody = message->getBody();
+ std::string body = optionalBody.get_value_or("");
+ if (message->isError()) {
+ if (!message->getTo().getResource().empty()) {
+ std::string errorMessage = str(format(QT_TRANSLATE_NOOP("", "Couldn't send message: %1%")) % getErrorMessage(message->getPayload<ErrorPayload>()));
+ chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
+ }
+ }
+ else if (messageEvent->getStanza()->getPayload<MUCInvitationPayload>()) {
+ handleMUCInvitation(messageEvent->getStanza());
+ return;
+ }
+ else if (messageEvent->getStanza()->getPayload<MUCUserPayload>() && messageEvent->getStanza()->getPayload<MUCUserPayload>()->getInvite()) {
+ handleMediatedMUCInvitation(messageEvent->getStanza());
+ return;
+ }
+ else {
+ if (!messageEvent->isReadable()) {
+ return;
+ }
+ showChatWindow();
+ JID from = message->getFrom();
+ std::vector<boost::shared_ptr<Delay> > delayPayloads = message->getPayloads<Delay>();
+ for (size_t i = 0; useDelayForLatency_ && i < delayPayloads.size(); i++) {
+ if (!delayPayloads[i]->getFrom()) {
+ continue;
+ }
+ boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
+ std::ostringstream s;
+ s << "The following message took " << (now - delayPayloads[i]->getStamp()).total_milliseconds() / 1000.0 << " seconds to be delivered from " << delayPayloads[i]->getFrom()->toString() << ".";
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(std::string(s.str())), ChatWindow::DefaultDirection);
+ }
+ boost::shared_ptr<SecurityLabel> label = message->getPayload<SecurityLabel>();
+
+ // Determine the timestamp
+ boost::posix_time::ptime timeStamp = boost::posix_time::microsec_clock::universal_time();
+ boost::optional<boost::posix_time::ptime> messageTimeStamp = getMessageTimestamp(message);
+ if (messageTimeStamp) {
+ timeStamp = *messageTimeStamp;
+ }
+ onActivity(body);
+
+ // Highlight
+ HighlightAction fullMessageHighlight;
+ if (!isIncomingMessageFromMe(message)) {
+ fullMessageHighlight = highlighter_->findFirstFullMessageMatchAction(body, senderHighlightNameFromMessage(from));
+ }
+
+ boost::shared_ptr<Replace> replace = message->getPayload<Replace>();
+ bool senderIsSelf = isIncomingMessageFromMe(message);
+ if (replace) {
+ // Should check if the user has a previous message
+ std::map<JID, std::string>::iterator lastMessage;
+ lastMessage = lastMessagesUIID_.find(from);
+ if (lastMessage != lastMessagesUIID_.end()) {
+ chatMessage = buildChatWindowChatMessage(body, senderIsSelf, fullMessageHighlight);
+ replaceMessage(chatMessage, lastMessagesUIID_[from], timeStamp);
+ }
+ }
+ else {
+ chatMessage = buildChatWindowChatMessage(body, senderIsSelf, fullMessageHighlight);
+ addMessageHandleIncomingMessage(from, chatMessage, senderIsSelf, label, timeStamp);
+ }
+
+ logMessage(body, from, selfJID_, timeStamp, true);
+ }
+ chatWindow_->show();
+ chatWindow_->setUnreadMessageCount(boost::numeric_cast<int>(unreadMessages_.size()));
+ onUnreadCountChanged();
+ postHandleIncomingMessage(messageEvent, chatMessage);
}
void ChatControllerBase::addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& timeStamp) {
- lastMessagesUIID_[from] = addMessage(message, senderDisplayNameFromMessage(from), senderIsSelf, label, avatarManager_->getAvatarPath(from), timeStamp);
+ lastMessagesUIID_[from] = addMessage(message, senderDisplayNameFromMessage(from), senderIsSelf, label, avatarManager_->getAvatarPath(from), timeStamp);
}
std::string ChatControllerBase::getErrorMessage(boost::shared_ptr<ErrorPayload> error) {
- std::string defaultMessage = QT_TRANSLATE_NOOP("", "Error sending message");
- if (!error->getText().empty()) {
- return error->getText();
- }
- else {
- switch (error->getCondition()) {
- case ErrorPayload::BadRequest: return QT_TRANSLATE_NOOP("", "Bad request");
- case ErrorPayload::Conflict: return QT_TRANSLATE_NOOP("", "Conflict");
- case ErrorPayload::FeatureNotImplemented: return QT_TRANSLATE_NOOP("", "This feature is not implemented");
- case ErrorPayload::Forbidden: return QT_TRANSLATE_NOOP("", "Forbidden");
- case ErrorPayload::Gone: return QT_TRANSLATE_NOOP("", "Recipient can no longer be contacted");
- case ErrorPayload::InternalServerError: return QT_TRANSLATE_NOOP("", "Internal server error");
- case ErrorPayload::ItemNotFound: return QT_TRANSLATE_NOOP("", "Item not found");
- case ErrorPayload::JIDMalformed: return QT_TRANSLATE_NOOP("", "JID Malformed");
- case ErrorPayload::NotAcceptable: return QT_TRANSLATE_NOOP("", "Message was rejected");
- case ErrorPayload::NotAllowed: return QT_TRANSLATE_NOOP("", "Not allowed");
- case ErrorPayload::NotAuthorized: return QT_TRANSLATE_NOOP("", "Not authorized");
- case ErrorPayload::PaymentRequired: return QT_TRANSLATE_NOOP("", "Payment is required");
- case ErrorPayload::RecipientUnavailable: return QT_TRANSLATE_NOOP("", "Recipient is unavailable");
- case ErrorPayload::Redirect: return QT_TRANSLATE_NOOP("", "Redirect");
- case ErrorPayload::RegistrationRequired: return QT_TRANSLATE_NOOP("", "Registration required");
- case ErrorPayload::RemoteServerNotFound: return QT_TRANSLATE_NOOP("", "Recipient's server not found");
- case ErrorPayload::RemoteServerTimeout: return QT_TRANSLATE_NOOP("", "Remote server timeout");
- case ErrorPayload::ResourceConstraint: return QT_TRANSLATE_NOOP("", "The server is low on resources");
- case ErrorPayload::ServiceUnavailable: return QT_TRANSLATE_NOOP("", "The service is unavailable");
- case ErrorPayload::SubscriptionRequired: return QT_TRANSLATE_NOOP("", "A subscription is required");
- case ErrorPayload::UndefinedCondition: return QT_TRANSLATE_NOOP("", "Undefined condition");
- case ErrorPayload::UnexpectedRequest: return QT_TRANSLATE_NOOP("", "Unexpected request");
- }
- }
- assert(false);
- return defaultMessage;
+ std::string defaultMessage = QT_TRANSLATE_NOOP("", "Error sending message");
+ if (!error->getText().empty()) {
+ return error->getText();
+ }
+ else {
+ switch (error->getCondition()) {
+ case ErrorPayload::BadRequest: return QT_TRANSLATE_NOOP("", "Bad request");
+ case ErrorPayload::Conflict: return QT_TRANSLATE_NOOP("", "Conflict");
+ case ErrorPayload::FeatureNotImplemented: return QT_TRANSLATE_NOOP("", "This feature is not implemented");
+ case ErrorPayload::Forbidden: return QT_TRANSLATE_NOOP("", "Forbidden");
+ case ErrorPayload::Gone: return QT_TRANSLATE_NOOP("", "Recipient can no longer be contacted");
+ case ErrorPayload::InternalServerError: return QT_TRANSLATE_NOOP("", "Internal server error");
+ case ErrorPayload::ItemNotFound: return QT_TRANSLATE_NOOP("", "Item not found");
+ case ErrorPayload::JIDMalformed: return QT_TRANSLATE_NOOP("", "JID Malformed");
+ case ErrorPayload::NotAcceptable: return QT_TRANSLATE_NOOP("", "Message was rejected");
+ case ErrorPayload::NotAllowed: return QT_TRANSLATE_NOOP("", "Not allowed");
+ case ErrorPayload::NotAuthorized: return QT_TRANSLATE_NOOP("", "Not authorized");
+ case ErrorPayload::PaymentRequired: return QT_TRANSLATE_NOOP("", "Payment is required");
+ case ErrorPayload::RecipientUnavailable: return QT_TRANSLATE_NOOP("", "Recipient is unavailable");
+ case ErrorPayload::Redirect: return QT_TRANSLATE_NOOP("", "Redirect");
+ case ErrorPayload::RegistrationRequired: return QT_TRANSLATE_NOOP("", "Registration required");
+ case ErrorPayload::RemoteServerNotFound: return QT_TRANSLATE_NOOP("", "Recipient's server not found");
+ case ErrorPayload::RemoteServerTimeout: return QT_TRANSLATE_NOOP("", "Remote server timeout");
+ case ErrorPayload::ResourceConstraint: return QT_TRANSLATE_NOOP("", "The server is low on resources");
+ case ErrorPayload::ServiceUnavailable: return QT_TRANSLATE_NOOP("", "The service is unavailable");
+ case ErrorPayload::SubscriptionRequired: return QT_TRANSLATE_NOOP("", "A subscription is required");
+ case ErrorPayload::UndefinedCondition: return QT_TRANSLATE_NOOP("", "Undefined condition");
+ case ErrorPayload::UnexpectedRequest: return QT_TRANSLATE_NOOP("", "Unexpected request");
+ }
+ }
+ assert(false);
+ return defaultMessage;
}
void ChatControllerBase::handleGeneralMUCInvitation(MUCInviteEvent::ref event) {
- unreadMessages_.push_back(event);
- chatWindow_->show();
- chatWindow_->setUnreadMessageCount(boost::numeric_cast<int>(unreadMessages_.size()));
- onUnreadCountChanged();
- chatWindow_->addMUCInvitation(senderDisplayNameFromMessage(event->getInviter()), event->getRoomJID(), event->getReason(), event->getPassword(), event->getDirect(), event->getImpromptu());
- eventController_->handleIncomingEvent(event);
+ unreadMessages_.push_back(event);
+ chatWindow_->show();
+ chatWindow_->setUnreadMessageCount(boost::numeric_cast<int>(unreadMessages_.size()));
+ onUnreadCountChanged();
+ chatWindow_->addMUCInvitation(senderDisplayNameFromMessage(event->getInviter()), event->getRoomJID(), event->getReason(), event->getPassword(), event->getDirect(), event->getImpromptu());
+ eventController_->handleIncomingEvent(event);
}
void ChatControllerBase::handleMUCInvitation(Message::ref message) {
- MUCInvitationPayload::ref invite = message->getPayload<MUCInvitationPayload>();
-
- if (autoAcceptMUCInviteDecider_->isAutoAcceptedInvite(message->getFrom(), invite)) {
- eventStream_->send(boost::make_shared<JoinMUCUIEvent>(invite->getJID(), boost::optional<std::string>(), boost::optional<std::string>(), false, false, true));
- } else {
- MUCInviteEvent::ref inviteEvent = boost::make_shared<MUCInviteEvent>(toJID_, invite->getJID(), invite->getReason(), invite->getPassword(), true, invite->getIsImpromptu());
- handleGeneralMUCInvitation(inviteEvent);
- }
+ MUCInvitationPayload::ref invite = message->getPayload<MUCInvitationPayload>();
+
+ if (autoAcceptMUCInviteDecider_->isAutoAcceptedInvite(message->getFrom(), invite)) {
+ eventStream_->send(boost::make_shared<JoinMUCUIEvent>(invite->getJID(), boost::optional<std::string>(), boost::optional<std::string>(), false, false, true));
+ } else {
+ MUCInviteEvent::ref inviteEvent = boost::make_shared<MUCInviteEvent>(toJID_, invite->getJID(), invite->getReason(), invite->getPassword(), true, invite->getIsImpromptu());
+ handleGeneralMUCInvitation(inviteEvent);
+ }
}
void ChatControllerBase::handleMediatedMUCInvitation(Message::ref message) {
- MUCUserPayload::Invite invite = *message->getPayload<MUCUserPayload>()->getInvite();
- JID from = message->getFrom();
- std::string reason;
- if (!invite.reason.empty()) {
- reason = invite.reason;
- }
- std::string password;
- if (message->getPayload<MUCUserPayload>()->getPassword()) {
- password = *message->getPayload<MUCUserPayload>()->getPassword();
- }
-
- MUCInviteEvent::ref inviteEvent = boost::make_shared<MUCInviteEvent>(invite.from, from, reason, password, false, false);
- handleGeneralMUCInvitation(inviteEvent);
+ MUCUserPayload::Invite invite = *message->getPayload<MUCUserPayload>()->getInvite();
+ JID from = message->getFrom();
+ std::string reason;
+ if (!invite.reason.empty()) {
+ reason = invite.reason;
+ }
+ std::string password;
+ if (message->getPayload<MUCUserPayload>()->getPassword()) {
+ password = *message->getPayload<MUCUserPayload>()->getPassword();
+ }
+
+ MUCInviteEvent::ref inviteEvent = boost::make_shared<MUCInviteEvent>(invite.from, from, reason, password, false, false);
+ handleGeneralMUCInvitation(inviteEvent);
}
}
diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h
index 98f0ab0..bd8ba0f 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.h
+++ b/Swift/Controllers/Chat/ChatControllerBase.h
@@ -35,107 +35,107 @@
#include <Swift/Controllers/XMPPEvents/MessageEvent.h>
namespace Swift {
- class IQRouter;
- class StanzaChannel;
- class ChatWindowFactory;
- class AvatarManager;
- class UIEventStream;
- class EventController;
- class EntityCapsProvider;
- class HighlightManager;
- class Highlighter;
- class ChatMessageParser;
- class AutoAcceptMUCInviteDecider;
+ class IQRouter;
+ class StanzaChannel;
+ class ChatWindowFactory;
+ class AvatarManager;
+ class UIEventStream;
+ class EventController;
+ class EntityCapsProvider;
+ class HighlightManager;
+ class Highlighter;
+ class ChatMessageParser;
+ class AutoAcceptMUCInviteDecider;
- class ChatControllerBase : public boost::bsignals::trackable {
- public:
- virtual ~ChatControllerBase();
- void showChatWindow();
- void activateChatWindow();
- bool hasOpenWindow() const;
- virtual void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info);
- void handleIncomingMessage(boost::shared_ptr<MessageEvent> message);
- std::string addMessage(const ChatWindow::ChatMessage& chatMessage, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::filesystem::path& avatarPath, const boost::posix_time::ptime& time);
- void replaceMessage(const ChatWindow::ChatMessage& chatMessage, const std::string& id, const boost::posix_time::ptime& time);
- virtual void setOnline(bool online);
- void setEnabled(bool enabled);
- virtual void setToJID(const JID& jid) {toJID_ = jid;}
- /** Used for determining when something is recent.*/
- boost::signal<void (const std::string& /*activity*/)> onActivity;
- boost::signal<void ()> onUnreadCountChanged;
- boost::signal<void ()> onWindowClosed;
- int getUnreadCount();
- const JID& getToJID() {return toJID_;}
- void handleCapsChanged(const JID& jid);
- void setCanStartImpromptuChats(bool supportsImpromptu);
- virtual ChatWindow* detachChatWindow();
- boost::signal<void(ChatWindow* /*window to reuse*/, const std::vector<JID>& /*invite people*/, const std::string& /*reason*/)> onConvertToMUC;
+ class ChatControllerBase : public boost::bsignals::trackable {
+ public:
+ virtual ~ChatControllerBase();
+ void showChatWindow();
+ void activateChatWindow();
+ bool hasOpenWindow() const;
+ virtual void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info);
+ void handleIncomingMessage(boost::shared_ptr<MessageEvent> message);
+ std::string addMessage(const ChatWindow::ChatMessage& chatMessage, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::filesystem::path& avatarPath, const boost::posix_time::ptime& time);
+ void replaceMessage(const ChatWindow::ChatMessage& chatMessage, const std::string& id, const boost::posix_time::ptime& time);
+ virtual void setOnline(bool online);
+ void setEnabled(bool enabled);
+ virtual void setToJID(const JID& jid) {toJID_ = jid;}
+ /** Used for determining when something is recent.*/
+ boost::signal<void (const std::string& /*activity*/)> onActivity;
+ boost::signal<void ()> onUnreadCountChanged;
+ boost::signal<void ()> onWindowClosed;
+ int getUnreadCount();
+ const JID& getToJID() {return toJID_;}
+ void handleCapsChanged(const JID& jid);
+ void setCanStartImpromptuChats(bool supportsImpromptu);
+ virtual ChatWindow* detachChatWindow();
+ boost::signal<void(ChatWindow* /*window to reuse*/, const std::vector<JID>& /*invite people*/, const std::string& /*reason*/)> onConvertToMUC;
- protected:
- ChatControllerBase(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, HistoryController* historyController, MUCRegistry* mucRegistry, HighlightManager* highlightManager, boost::shared_ptr<ChatMessageParser> chatMessageParser, AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider);
+ protected:
+ ChatControllerBase(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, HistoryController* historyController, MUCRegistry* mucRegistry, HighlightManager* highlightManager, boost::shared_ptr<ChatMessageParser> chatMessageParser, AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider);
- /**
- * Pass the Message appended, and the stanza used to send it.
- */
- virtual void postSendMessage(const std::string&, boost::shared_ptr<Stanza>) {}
- virtual std::string senderDisplayNameFromMessage(const JID& from) = 0;
- virtual std::string senderHighlightNameFromMessage(const JID& from) = 0;
- virtual bool isIncomingMessageFromMe(boost::shared_ptr<Message>) = 0;
- virtual void preHandleIncomingMessage(boost::shared_ptr<MessageEvent>) {}
- virtual void addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& time);
- virtual void postHandleIncomingMessage(boost::shared_ptr<MessageEvent>, const ChatWindow::ChatMessage&) {}
- virtual void preSendMessageRequest(boost::shared_ptr<Message>) {}
- virtual bool isFromContact(const JID& from);
- virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message>) const = 0;
- virtual void dayTicked() {}
- virtual void handleBareJIDCapsChanged(const JID& jid) = 0;
- std::string getErrorMessage(boost::shared_ptr<ErrorPayload>);
- virtual void setContactIsReceivingPresence(bool /* isReceivingPresence */) {}
- virtual void cancelReplaces() = 0;
- /** JID any iq for account should go to - bare except for PMs */
- virtual JID getBaseJID();
- virtual void logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) = 0;
- ChatWindow::ChatMessage buildChatWindowChatMessage(const std::string& message, bool senderIsSelf, const HighlightAction& fullMessageHighlightAction);
- void handleHighlightActions(const ChatWindow::ChatMessage& chatMessage);
+ /**
+ * Pass the Message appended, and the stanza used to send it.
+ */
+ virtual void postSendMessage(const std::string&, boost::shared_ptr<Stanza>) {}
+ virtual std::string senderDisplayNameFromMessage(const JID& from) = 0;
+ virtual std::string senderHighlightNameFromMessage(const JID& from) = 0;
+ virtual bool isIncomingMessageFromMe(boost::shared_ptr<Message>) = 0;
+ virtual void preHandleIncomingMessage(boost::shared_ptr<MessageEvent>) {}
+ virtual void addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& time);
+ virtual void postHandleIncomingMessage(boost::shared_ptr<MessageEvent>, const ChatWindow::ChatMessage&) {}
+ virtual void preSendMessageRequest(boost::shared_ptr<Message>) {}
+ virtual bool isFromContact(const JID& from);
+ virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message>) const = 0;
+ virtual void dayTicked() {}
+ virtual void handleBareJIDCapsChanged(const JID& jid) = 0;
+ std::string getErrorMessage(boost::shared_ptr<ErrorPayload>);
+ virtual void setContactIsReceivingPresence(bool /* isReceivingPresence */) {}
+ virtual void cancelReplaces() = 0;
+ /** JID any iq for account should go to - bare except for PMs */
+ virtual JID getBaseJID();
+ virtual void logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) = 0;
+ ChatWindow::ChatMessage buildChatWindowChatMessage(const std::string& message, bool senderIsSelf, const HighlightAction& fullMessageHighlightAction);
+ void handleHighlightActions(const ChatWindow::ChatMessage& chatMessage);
- private:
- IDGenerator idGenerator_;
- std::string lastSentMessageStanzaID_;
- void createDayChangeTimer();
+ private:
+ IDGenerator idGenerator_;
+ std::string lastSentMessageStanzaID_;
+ void createDayChangeTimer();
- void handleSendMessageRequest(const std::string &body, bool isCorrectionMessage);
- void handleAllMessagesRead();
- void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, ErrorPayload::ref error);
- void handleDayChangeTick();
- void handleMUCInvitation(Message::ref message);
- void handleMediatedMUCInvitation(Message::ref message);
- void handleGeneralMUCInvitation(MUCInviteEvent::ref event);
- void handleLogCleared();
+ void handleSendMessageRequest(const std::string &body, bool isCorrectionMessage);
+ void handleAllMessagesRead();
+ void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, ErrorPayload::ref error);
+ void handleDayChangeTick();
+ void handleMUCInvitation(Message::ref message);
+ void handleMediatedMUCInvitation(Message::ref message);
+ void handleGeneralMUCInvitation(MUCInviteEvent::ref event);
+ void handleLogCleared();
- protected:
- JID selfJID_;
- std::vector<boost::shared_ptr<StanzaEvent> > unreadMessages_;
- std::vector<boost::shared_ptr<StanzaEvent> > targetedUnreadMessages_;
- StanzaChannel* stanzaChannel_;
- IQRouter* iqRouter_;
- ChatWindowFactory* chatWindowFactory_;
- ChatWindow* chatWindow_;
- JID toJID_;
- bool labelsEnabled_;
- std::map<JID, std::string> lastMessagesUIID_;
- PresenceOracle* presenceOracle_;
- AvatarManager* avatarManager_;
- bool useDelayForLatency_;
- EventController* eventController_;
- boost::shared_ptr<Timer> dateChangeTimer_;
- TimerFactory* timerFactory_;
- EntityCapsProvider* entityCapsProvider_;
- SecurityLabelsCatalog::Item lastLabel_;
- HistoryController* historyController_;
- MUCRegistry* mucRegistry_;
- Highlighter* highlighter_;
- boost::shared_ptr<ChatMessageParser> chatMessageParser_;
- AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider_;
- UIEventStream* eventStream_;
- };
+ protected:
+ JID selfJID_;
+ std::vector<boost::shared_ptr<StanzaEvent> > unreadMessages_;
+ std::vector<boost::shared_ptr<StanzaEvent> > targetedUnreadMessages_;
+ StanzaChannel* stanzaChannel_;
+ IQRouter* iqRouter_;
+ ChatWindowFactory* chatWindowFactory_;
+ ChatWindow* chatWindow_;
+ JID toJID_;
+ bool labelsEnabled_;
+ std::map<JID, std::string> lastMessagesUIID_;
+ PresenceOracle* presenceOracle_;
+ AvatarManager* avatarManager_;
+ bool useDelayForLatency_;
+ EventController* eventController_;
+ boost::shared_ptr<Timer> dateChangeTimer_;
+ TimerFactory* timerFactory_;
+ EntityCapsProvider* entityCapsProvider_;
+ SecurityLabelsCatalog::Item lastLabel_;
+ HistoryController* historyController_;
+ MUCRegistry* mucRegistry_;
+ Highlighter* highlighter_;
+ boost::shared_ptr<ChatMessageParser> chatMessageParser_;
+ AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider_;
+ UIEventStream* eventStream_;
+ };
}
diff --git a/Swift/Controllers/Chat/ChatMessageParser.cpp b/Swift/Controllers/Chat/ChatMessageParser.cpp
index 53c7588..08e4fcd 100644
--- a/Swift/Controllers/Chat/ChatMessageParser.cpp
+++ b/Swift/Controllers/Chat/ChatMessageParser.cpp
@@ -19,177 +19,177 @@
namespace Swift {
- ChatMessageParser::ChatMessageParser(const std::map<std::string, std::string>& emoticons, HighlightRulesListPtr highlightRules, bool mucMode)
- : emoticons_(emoticons), highlightRules_(highlightRules), mucMode_(mucMode) {
- }
-
- typedef std::pair<std::string, std::string> StringPair;
-
- ChatWindow::ChatMessage ChatMessageParser::parseMessageBody(const std::string& body, const std::string& nick, bool senderIsSelf) {
- ChatWindow::ChatMessage parsedMessage;
- std::string remaining = body;
- /* Parse one, URLs */
- while (!remaining.empty()) {
- bool found = false;
- std::pair<std::vector<std::string>, size_t> links = Linkify::splitLink(remaining);
- remaining = "";
- for (size_t i = 0; i < links.first.size(); i++) {
- const std::string& part = links.first[i];
- if (found) {
- // Must be on the last part, then
- remaining = part;
- }
- else {
- if (i == links.second) {
- found = true;
- parsedMessage.append(boost::make_shared<ChatWindow::ChatURIMessagePart>(part));
- }
- else {
- parsedMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(part));
- }
- }
- }
- }
-
- /* do emoticon substitution */
- parsedMessage = emoticonHighlight(parsedMessage);
-
- if (!senderIsSelf) { /* do not highlight our own messsages */
- /* do word-based color highlighting */
- parsedMessage = splitHighlight(parsedMessage, nick);
- }
-
- return parsedMessage;
- }
-
- ChatWindow::ChatMessage ChatMessageParser::emoticonHighlight(const ChatWindow::ChatMessage& message)
- {
- ChatWindow::ChatMessage parsedMessage = message;
-
- std::string regexString;
- /* Parse two, emoticons */
- foreach (StringPair emoticon, emoticons_) {
- /* Construct a regexp that finds an instance of any of the emoticons inside a group
- * at the start or end of the line, or beside whitespace.
- */
- regexString += regexString.empty() ? "" : "|";
- std::string escaped = "(" + Regex::escape(emoticon.first) + ")";
- regexString += "^" + escaped + "|";
- regexString += escaped + "$|";
- regexString += "\\s" + escaped + "|";
- regexString += escaped + "\\s";
-
- }
- if (!regexString.empty()) {
- regexString += "";
- boost::regex emoticonRegex(regexString);
-
- ChatWindow::ChatMessage newMessage;
- foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, parsedMessage.getParts()) {
- boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
- if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
- try {
- boost::match_results<std::string::const_iterator> match;
- const std::string& text = textPart->text;
- std::string::const_iterator start = text.begin();
- while (regex_search(start, text.end(), match, emoticonRegex)) {
- int matchIndex = 0;
- for (matchIndex = 1; matchIndex < static_cast<int>(match.size()); matchIndex++) {
- if (match[matchIndex].length() > 0) {
- //This is the matching subgroup
- break;
- }
- }
- std::string::const_iterator matchStart = match[matchIndex].first;
- std::string::const_iterator matchEnd = match[matchIndex].second;
- if (start != matchStart) {
- /* If we're skipping over plain text since the previous emoticon, record it as plain text */
- newMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, matchStart)));
- }
- boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart = boost::make_shared<ChatWindow::ChatEmoticonMessagePart>();
- std::string matchString = match[matchIndex].str();
- std::map<std::string, std::string>::const_iterator emoticonIterator = emoticons_.find(matchString);
- assert (emoticonIterator != emoticons_.end());
- const StringPair& emoticon = *emoticonIterator;
- emoticonPart->imagePath = emoticon.second;
- emoticonPart->alternativeText = emoticon.first;
- newMessage.append(emoticonPart);
- start = matchEnd;
- }
- if (start != text.end()) {
- /* If there's plain text after the last emoticon, record it */
- newMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, text.end())));
- }
-
- }
- catch (std::runtime_error) {
- /* Basically too expensive to compute the regex results and it gave up, so pass through as text */
- newMessage.append(part);
- }
- }
- else {
- newMessage.append(part);
- }
- }
- parsedMessage = newMessage;
-
- }
- return parsedMessage;
- }
-
- ChatWindow::ChatMessage ChatMessageParser::splitHighlight(const ChatWindow::ChatMessage& message, const std::string& nick)
- {
- ChatWindow::ChatMessage parsedMessage = message;
-
- for (size_t i = 0; i < highlightRules_->getSize(); ++i) {
- const HighlightRule& rule = highlightRules_->getRule(i);
- if (rule.getMatchMUC() && !mucMode_) {
- continue; /* this rule only applies to MUC's, and this is a CHAT */
- } else if (rule.getMatchChat() && mucMode_) {
- continue; /* this rule only applies to CHAT's, and this is a MUC */
- } else if (rule.getAction().getTextBackground().empty() && rule.getAction().getTextColor().empty()) {
- continue; /* do not try to highlight text, if no highlight color is specified */
- }
- const std::vector<boost::regex> keywordRegex = rule.getKeywordRegex(nick);
- foreach(const boost::regex& regex, keywordRegex) {
- ChatWindow::ChatMessage newMessage;
- foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, parsedMessage.getParts()) {
- boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
- if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
- try {
- boost::match_results<std::string::const_iterator> match;
- const std::string& text = textPart->text;
- std::string::const_iterator start = text.begin();
- while (regex_search(start, text.end(), match, regex)) {
- std::string::const_iterator matchStart = match[0].first;
- std::string::const_iterator matchEnd = match[0].second;
- if (start != matchStart) {
- /* If we're skipping over plain text since the previous emoticon, record it as plain text */
- newMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, matchStart)));
- }
- boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart = boost::make_shared<ChatWindow::ChatHighlightingMessagePart>();
- highlightPart->text = match.str();
- highlightPart->action = rule.getAction();
- newMessage.append(highlightPart);
- start = matchEnd;
- }
- if (start != text.end()) {
- /* If there's plain text after the last emoticon, record it */
- newMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, text.end())));
- }
- }
- catch (std::runtime_error) {
- /* Basically too expensive to compute the regex results and it gave up, so pass through as text */
- newMessage.append(part);
- }
- } else {
- newMessage.append(part);
- }
- }
- parsedMessage = newMessage;
- }
- }
-
- return parsedMessage;
- }
+ ChatMessageParser::ChatMessageParser(const std::map<std::string, std::string>& emoticons, HighlightRulesListPtr highlightRules, bool mucMode)
+ : emoticons_(emoticons), highlightRules_(highlightRules), mucMode_(mucMode) {
+ }
+
+ typedef std::pair<std::string, std::string> StringPair;
+
+ ChatWindow::ChatMessage ChatMessageParser::parseMessageBody(const std::string& body, const std::string& nick, bool senderIsSelf) {
+ ChatWindow::ChatMessage parsedMessage;
+ std::string remaining = body;
+ /* Parse one, URLs */
+ while (!remaining.empty()) {
+ bool found = false;
+ std::pair<std::vector<std::string>, size_t> links = Linkify::splitLink(remaining);
+ remaining = "";
+ for (size_t i = 0; i < links.first.size(); i++) {
+ const std::string& part = links.first[i];
+ if (found) {
+ // Must be on the last part, then
+ remaining = part;
+ }
+ else {
+ if (i == links.second) {
+ found = true;
+ parsedMessage.append(boost::make_shared<ChatWindow::ChatURIMessagePart>(part));
+ }
+ else {
+ parsedMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(part));
+ }
+ }
+ }
+ }
+
+ /* do emoticon substitution */
+ parsedMessage = emoticonHighlight(parsedMessage);
+
+ if (!senderIsSelf) { /* do not highlight our own messsages */
+ /* do word-based color highlighting */
+ parsedMessage = splitHighlight(parsedMessage, nick);
+ }
+
+ return parsedMessage;
+ }
+
+ ChatWindow::ChatMessage ChatMessageParser::emoticonHighlight(const ChatWindow::ChatMessage& message)
+ {
+ ChatWindow::ChatMessage parsedMessage = message;
+
+ std::string regexString;
+ /* Parse two, emoticons */
+ foreach (StringPair emoticon, emoticons_) {
+ /* Construct a regexp that finds an instance of any of the emoticons inside a group
+ * at the start or end of the line, or beside whitespace.
+ */
+ regexString += regexString.empty() ? "" : "|";
+ std::string escaped = "(" + Regex::escape(emoticon.first) + ")";
+ regexString += "^" + escaped + "|";
+ regexString += escaped + "$|";
+ regexString += "\\s" + escaped + "|";
+ regexString += escaped + "\\s";
+
+ }
+ if (!regexString.empty()) {
+ regexString += "";
+ boost::regex emoticonRegex(regexString);
+
+ ChatWindow::ChatMessage newMessage;
+ foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, parsedMessage.getParts()) {
+ boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
+ if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
+ try {
+ boost::match_results<std::string::const_iterator> match;
+ const std::string& text = textPart->text;
+ std::string::const_iterator start = text.begin();
+ while (regex_search(start, text.end(), match, emoticonRegex)) {
+ int matchIndex = 0;
+ for (matchIndex = 1; matchIndex < static_cast<int>(match.size()); matchIndex++) {
+ if (match[matchIndex].length() > 0) {
+ //This is the matching subgroup
+ break;
+ }
+ }
+ std::string::const_iterator matchStart = match[matchIndex].first;
+ std::string::const_iterator matchEnd = match[matchIndex].second;
+ if (start != matchStart) {
+ /* If we're skipping over plain text since the previous emoticon, record it as plain text */
+ newMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, matchStart)));
+ }
+ boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart = boost::make_shared<ChatWindow::ChatEmoticonMessagePart>();
+ std::string matchString = match[matchIndex].str();
+ std::map<std::string, std::string>::const_iterator emoticonIterator = emoticons_.find(matchString);
+ assert (emoticonIterator != emoticons_.end());
+ const StringPair& emoticon = *emoticonIterator;
+ emoticonPart->imagePath = emoticon.second;
+ emoticonPart->alternativeText = emoticon.first;
+ newMessage.append(emoticonPart);
+ start = matchEnd;
+ }
+ if (start != text.end()) {
+ /* If there's plain text after the last emoticon, record it */
+ newMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, text.end())));
+ }
+
+ }
+ catch (std::runtime_error) {
+ /* Basically too expensive to compute the regex results and it gave up, so pass through as text */
+ newMessage.append(part);
+ }
+ }
+ else {
+ newMessage.append(part);
+ }
+ }
+ parsedMessage = newMessage;
+
+ }
+ return parsedMessage;
+ }
+
+ ChatWindow::ChatMessage ChatMessageParser::splitHighlight(const ChatWindow::ChatMessage& message, const std::string& nick)
+ {
+ ChatWindow::ChatMessage parsedMessage = message;
+
+ for (size_t i = 0; i < highlightRules_->getSize(); ++i) {
+ const HighlightRule& rule = highlightRules_->getRule(i);
+ if (rule.getMatchMUC() && !mucMode_) {
+ continue; /* this rule only applies to MUC's, and this is a CHAT */
+ } else if (rule.getMatchChat() && mucMode_) {
+ continue; /* this rule only applies to CHAT's, and this is a MUC */
+ } else if (rule.getAction().getTextBackground().empty() && rule.getAction().getTextColor().empty()) {
+ continue; /* do not try to highlight text, if no highlight color is specified */
+ }
+ const std::vector<boost::regex> keywordRegex = rule.getKeywordRegex(nick);
+ foreach(const boost::regex& regex, keywordRegex) {
+ ChatWindow::ChatMessage newMessage;
+ foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, parsedMessage.getParts()) {
+ boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
+ if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
+ try {
+ boost::match_results<std::string::const_iterator> match;
+ const std::string& text = textPart->text;
+ std::string::const_iterator start = text.begin();
+ while (regex_search(start, text.end(), match, regex)) {
+ std::string::const_iterator matchStart = match[0].first;
+ std::string::const_iterator matchEnd = match[0].second;
+ if (start != matchStart) {
+ /* If we're skipping over plain text since the previous emoticon, record it as plain text */
+ newMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, matchStart)));
+ }
+ boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart = boost::make_shared<ChatWindow::ChatHighlightingMessagePart>();
+ highlightPart->text = match.str();
+ highlightPart->action = rule.getAction();
+ newMessage.append(highlightPart);
+ start = matchEnd;
+ }
+ if (start != text.end()) {
+ /* If there's plain text after the last emoticon, record it */
+ newMessage.append(boost::make_shared<ChatWindow::ChatTextMessagePart>(std::string(start, text.end())));
+ }
+ }
+ catch (std::runtime_error) {
+ /* Basically too expensive to compute the regex results and it gave up, so pass through as text */
+ newMessage.append(part);
+ }
+ } else {
+ newMessage.append(part);
+ }
+ }
+ parsedMessage = newMessage;
+ }
+ }
+
+ return parsedMessage;
+ }
}
diff --git a/Swift/Controllers/Chat/ChatMessageParser.h b/Swift/Controllers/Chat/ChatMessageParser.h
index e56d21b..4bed669 100644
--- a/Swift/Controllers/Chat/ChatMessageParser.h
+++ b/Swift/Controllers/Chat/ChatMessageParser.h
@@ -12,15 +12,15 @@
namespace Swift {
- class ChatMessageParser {
- public:
- ChatMessageParser(const std::map<std::string, std::string>& emoticons, HighlightRulesListPtr highlightRules, bool mucMode = false);
- ChatWindow::ChatMessage parseMessageBody(const std::string& body, const std::string& nick = "", bool senderIsSelf = false);
- private:
- ChatWindow::ChatMessage emoticonHighlight(const ChatWindow::ChatMessage& parsedMessage);
- ChatWindow::ChatMessage splitHighlight(const ChatWindow::ChatMessage& parsedMessage, const std::string& nick);
- std::map<std::string, std::string> emoticons_;
- HighlightRulesListPtr highlightRules_;
- bool mucMode_;
- };
+ class ChatMessageParser {
+ public:
+ ChatMessageParser(const std::map<std::string, std::string>& emoticons, HighlightRulesListPtr highlightRules, bool mucMode = false);
+ ChatWindow::ChatMessage parseMessageBody(const std::string& body, const std::string& nick = "", bool senderIsSelf = false);
+ private:
+ ChatWindow::ChatMessage emoticonHighlight(const ChatWindow::ChatMessage& parsedMessage);
+ ChatWindow::ChatMessage splitHighlight(const ChatWindow::ChatMessage& parsedMessage, const std::string& nick);
+ std::map<std::string, std::string> emoticons_;
+ HighlightRulesListPtr highlightRules_;
+ bool mucMode_;
+ };
}
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index 49caee4..32da58a 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -67,32 +67,32 @@ BOOST_CLASS_VERSION(Swift::ChatListWindow::Chat, 1)
namespace boost {
namespace serialization {
- template<class Archive> void save(Archive& ar, const Swift::JID& jid, const unsigned int /*version*/) {
- std::string jidStr = jid.toString();
- ar << jidStr;
- }
-
- template<class Archive> void load(Archive& ar, Swift::JID& jid, const unsigned int /*version*/) {
- std::string stringJID;
- ar >> stringJID;
- jid = Swift::JID(stringJID);
- }
-
- template<class Archive> inline void serialize(Archive& ar, Swift::JID& t, const unsigned int file_version){
- split_free(ar, t, file_version);
- }
-
- template<class Archive> void serialize(Archive& ar, Swift::ChatListWindow::Chat& chat, const unsigned int version) {
- ar & chat.jid;
- ar & chat.chatName;
- ar & chat.activity;
- ar & chat.isMUC;
- ar & chat.nick;
- ar & chat.impromptuJIDs;
- if (version > 0) {
- ar & chat.password;
- }
- }
+ template<class Archive> void save(Archive& ar, const Swift::JID& jid, const unsigned int /*version*/) {
+ std::string jidStr = jid.toString();
+ ar << jidStr;
+ }
+
+ template<class Archive> void load(Archive& ar, Swift::JID& jid, const unsigned int /*version*/) {
+ std::string stringJID;
+ ar >> stringJID;
+ jid = Swift::JID(stringJID);
+ }
+
+ template<class Archive> inline void serialize(Archive& ar, Swift::JID& t, const unsigned int file_version){
+ split_free(ar, t, file_version);
+ }
+
+ template<class Archive> void serialize(Archive& ar, Swift::ChatListWindow::Chat& chat, const unsigned int version) {
+ ar & chat.jid;
+ ar & chat.chatName;
+ ar & chat.activity;
+ ar & chat.isMUC;
+ ar & chat.nick;
+ ar & chat.impromptuJIDs;
+ if (version > 0) {
+ ar & chat.password;
+ }
+ }
}
}
@@ -104,950 +104,950 @@ typedef std::pair<JID, MUCController*> JIDMUCControllerPair;
#define RECENT_CHATS "recent_chats"
ChatsManager::ChatsManager(
- JID jid, StanzaChannel* stanzaChannel,
- IQRouter* iqRouter,
- EventController* eventController,
- ChatWindowFactory* chatWindowFactory,
- JoinMUCWindowFactory* joinMUCWindowFactory,
- NickResolver* nickResolver,
- PresenceOracle* presenceOracle,
- PresenceSender* presenceSender,
- UIEventStream* uiEventStream,
- ChatListWindowFactory* chatListWindowFactory,
- bool useDelayForLatency,
- TimerFactory* timerFactory,
- MUCRegistry* mucRegistry,
- EntityCapsProvider* entityCapsProvider,
- MUCManager* mucManager,
- MUCSearchWindowFactory* mucSearchWindowFactory,
- ProfileSettingsProvider* profileSettings,
- FileTransferOverview* ftOverview,
- XMPPRoster* roster,
- bool eagleMode,
- SettingsProvider* settings,
- HistoryController* historyController,
- WhiteboardManager* whiteboardManager,
- HighlightManager* highlightManager,
- ClientBlockListManager* clientBlockListManager,
- const std::map<std::string, std::string>& emoticons,
- VCardManager* vcardManager) :
- jid_(jid),
- joinMUCWindowFactory_(joinMUCWindowFactory),
- useDelayForLatency_(useDelayForLatency),
- mucRegistry_(mucRegistry),
- entityCapsProvider_(entityCapsProvider),
- mucManager(mucManager),
- ftOverview_(ftOverview),
- roster_(roster),
- eagleMode_(eagleMode),
- settings_(settings),
- historyController_(historyController),
- whiteboardManager_(whiteboardManager),
- highlightManager_(highlightManager),
- emoticons_(emoticons),
- clientBlockListManager_(clientBlockListManager),
- vcardManager_(vcardManager) {
- timerFactory_ = timerFactory;
- eventController_ = eventController;
- stanzaChannel_ = stanzaChannel;
- iqRouter_ = iqRouter;
- chatWindowFactory_ = chatWindowFactory;
- nickResolver_ = nickResolver;
- presenceOracle_ = presenceOracle;
- avatarManager_ = NULL;
- serverDiscoInfo_ = boost::make_shared<DiscoInfo>();
- presenceSender_ = presenceSender;
- uiEventStream_ = uiEventStream;
- mucBookmarkManager_ = NULL;
- profileSettings_ = profileSettings;
- presenceOracle_->onPresenceChange.connect(boost::bind(&ChatsManager::handlePresenceChange, this, _1));
- uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&ChatsManager::handleUIEvent, this, _1));
-
- chatListWindow_ = chatListWindowFactory->createChatListWindow(uiEventStream_);
- chatListWindow_->onMUCBookmarkActivated.connect(boost::bind(&ChatsManager::handleMUCBookmarkActivated, this, _1));
- chatListWindow_->onRecentActivated.connect(boost::bind(&ChatsManager::handleRecentActivated, this, _1));
- chatListWindow_->onClearRecentsRequested.connect(boost::bind(&ChatsManager::handleClearRecentsRequested, this));
-
- joinMUCWindow_ = NULL;
- mucSearchController_ = new MUCSearchController(jid_, mucSearchWindowFactory, iqRouter, profileSettings_);
- mucSearchController_->onMUCSelected.connect(boost::bind(&ChatsManager::handleMUCSelectedAfterSearch, this, _1));
- ftOverview_->onNewFileTransferController.connect(boost::bind(&ChatsManager::handleNewFileTransferController, this, _1));
- whiteboardManager_->onSessionRequest.connect(boost::bind(&ChatsManager::handleWhiteboardSessionRequest, this, _1, _2));
- whiteboardManager_->onRequestAccepted.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardAccepted));
- whiteboardManager_->onSessionTerminate.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardTerminated));
- whiteboardManager_->onRequestRejected.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardRejected));
- roster_->onJIDAdded.connect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1));
- roster_->onJIDRemoved.connect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1));
- roster_->onJIDUpdated.connect(boost::bind(&ChatsManager::handleJIDUpdatedInRoster, this, _1));
- roster_->onRosterCleared.connect(boost::bind(&ChatsManager::handleRosterCleared, this));
-
- settings_->onSettingChanged.connect(boost::bind(&ChatsManager::handleSettingChanged, this, _1));
-
- userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS);
-
- setupBookmarks();
- loadRecents();
-
- autoAcceptMUCInviteDecider_ = new AutoAcceptMUCInviteDecider(jid.getDomain(), roster_, settings_);
+ JID jid, StanzaChannel* stanzaChannel,
+ IQRouter* iqRouter,
+ EventController* eventController,
+ ChatWindowFactory* chatWindowFactory,
+ JoinMUCWindowFactory* joinMUCWindowFactory,
+ NickResolver* nickResolver,
+ PresenceOracle* presenceOracle,
+ PresenceSender* presenceSender,
+ UIEventStream* uiEventStream,
+ ChatListWindowFactory* chatListWindowFactory,
+ bool useDelayForLatency,
+ TimerFactory* timerFactory,
+ MUCRegistry* mucRegistry,
+ EntityCapsProvider* entityCapsProvider,
+ MUCManager* mucManager,
+ MUCSearchWindowFactory* mucSearchWindowFactory,
+ ProfileSettingsProvider* profileSettings,
+ FileTransferOverview* ftOverview,
+ XMPPRoster* roster,
+ bool eagleMode,
+ SettingsProvider* settings,
+ HistoryController* historyController,
+ WhiteboardManager* whiteboardManager,
+ HighlightManager* highlightManager,
+ ClientBlockListManager* clientBlockListManager,
+ const std::map<std::string, std::string>& emoticons,
+ VCardManager* vcardManager) :
+ jid_(jid),
+ joinMUCWindowFactory_(joinMUCWindowFactory),
+ useDelayForLatency_(useDelayForLatency),
+ mucRegistry_(mucRegistry),
+ entityCapsProvider_(entityCapsProvider),
+ mucManager(mucManager),
+ ftOverview_(ftOverview),
+ roster_(roster),
+ eagleMode_(eagleMode),
+ settings_(settings),
+ historyController_(historyController),
+ whiteboardManager_(whiteboardManager),
+ highlightManager_(highlightManager),
+ emoticons_(emoticons),
+ clientBlockListManager_(clientBlockListManager),
+ vcardManager_(vcardManager) {
+ timerFactory_ = timerFactory;
+ eventController_ = eventController;
+ stanzaChannel_ = stanzaChannel;
+ iqRouter_ = iqRouter;
+ chatWindowFactory_ = chatWindowFactory;
+ nickResolver_ = nickResolver;
+ presenceOracle_ = presenceOracle;
+ avatarManager_ = NULL;
+ serverDiscoInfo_ = boost::make_shared<DiscoInfo>();
+ presenceSender_ = presenceSender;
+ uiEventStream_ = uiEventStream;
+ mucBookmarkManager_ = NULL;
+ profileSettings_ = profileSettings;
+ presenceOracle_->onPresenceChange.connect(boost::bind(&ChatsManager::handlePresenceChange, this, _1));
+ uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&ChatsManager::handleUIEvent, this, _1));
+
+ chatListWindow_ = chatListWindowFactory->createChatListWindow(uiEventStream_);
+ chatListWindow_->onMUCBookmarkActivated.connect(boost::bind(&ChatsManager::handleMUCBookmarkActivated, this, _1));
+ chatListWindow_->onRecentActivated.connect(boost::bind(&ChatsManager::handleRecentActivated, this, _1));
+ chatListWindow_->onClearRecentsRequested.connect(boost::bind(&ChatsManager::handleClearRecentsRequested, this));
+
+ joinMUCWindow_ = NULL;
+ mucSearchController_ = new MUCSearchController(jid_, mucSearchWindowFactory, iqRouter, profileSettings_);
+ mucSearchController_->onMUCSelected.connect(boost::bind(&ChatsManager::handleMUCSelectedAfterSearch, this, _1));
+ ftOverview_->onNewFileTransferController.connect(boost::bind(&ChatsManager::handleNewFileTransferController, this, _1));
+ whiteboardManager_->onSessionRequest.connect(boost::bind(&ChatsManager::handleWhiteboardSessionRequest, this, _1, _2));
+ whiteboardManager_->onRequestAccepted.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardAccepted));
+ whiteboardManager_->onSessionTerminate.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardTerminated));
+ whiteboardManager_->onRequestRejected.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardRejected));
+ roster_->onJIDAdded.connect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1));
+ roster_->onJIDRemoved.connect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1));
+ roster_->onJIDUpdated.connect(boost::bind(&ChatsManager::handleJIDUpdatedInRoster, this, _1));
+ roster_->onRosterCleared.connect(boost::bind(&ChatsManager::handleRosterCleared, this));
+
+ settings_->onSettingChanged.connect(boost::bind(&ChatsManager::handleSettingChanged, this, _1));
+
+ userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS);
+
+ setupBookmarks();
+ loadRecents();
+
+ autoAcceptMUCInviteDecider_ = new AutoAcceptMUCInviteDecider(jid.getDomain(), roster_, settings_);
}
ChatsManager::~ChatsManager() {
- settings_->onSettingChanged.disconnect(boost::bind(&ChatsManager::handleSettingChanged, this, _1));
- roster_->onJIDAdded.disconnect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1));
- roster_->onJIDRemoved.disconnect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1));
- roster_->onJIDUpdated.disconnect(boost::bind(&ChatsManager::handleJIDUpdatedInRoster, this, _1));
- roster_->onRosterCleared.disconnect(boost::bind(&ChatsManager::handleRosterCleared, this));
- delete joinMUCWindow_;
- foreach (JIDChatControllerPair controllerPair, chatControllers_) {
- delete controllerPair.second;
- }
- foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
- delete controllerPair.second;
- }
- delete mucBookmarkManager_;
- delete mucSearchController_;
- delete autoAcceptMUCInviteDecider_;
+ settings_->onSettingChanged.disconnect(boost::bind(&ChatsManager::handleSettingChanged, this, _1));
+ roster_->onJIDAdded.disconnect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1));
+ roster_->onJIDRemoved.disconnect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1));
+ roster_->onJIDUpdated.disconnect(boost::bind(&ChatsManager::handleJIDUpdatedInRoster, this, _1));
+ roster_->onRosterCleared.disconnect(boost::bind(&ChatsManager::handleRosterCleared, this));
+ delete joinMUCWindow_;
+ foreach (JIDChatControllerPair controllerPair, chatControllers_) {
+ delete controllerPair.second;
+ }
+ foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
+ delete controllerPair.second;
+ }
+ delete mucBookmarkManager_;
+ delete mucSearchController_;
+ delete autoAcceptMUCInviteDecider_;
}
void ChatsManager::saveRecents() {
- std::stringstream serializeStream;
- boost::archive::text_oarchive oa(serializeStream);
- std::vector<ChatListWindow::Chat> recentsLimited = std::vector<ChatListWindow::Chat>(recentChats_.begin(), recentChats_.end());
- if (recentsLimited.size() > 25) {
- recentsLimited.erase(recentsLimited.begin() + 25, recentsLimited.end());
- }
- if (eagleMode_) {
- foreach(ChatListWindow::Chat& chat, recentsLimited) {
- chat.activity = "";
- }
- }
-
- class RemoveRecent {
- public:
- static bool ifPrivateMessage(const ChatListWindow::Chat& chat) {
- return chat.isPrivateMessage;
- }
- };
-
- recentsLimited.erase(std::remove_if(recentsLimited.begin(), recentsLimited.end(), RemoveRecent::ifPrivateMessage), recentsLimited.end());
-
- oa << recentsLimited;
- std::string serializedStr = Base64::encode(createByteArray(serializeStream.str()));
- profileSettings_->storeString(RECENT_CHATS, serializedStr);
+ std::stringstream serializeStream;
+ boost::archive::text_oarchive oa(serializeStream);
+ std::vector<ChatListWindow::Chat> recentsLimited = std::vector<ChatListWindow::Chat>(recentChats_.begin(), recentChats_.end());
+ if (recentsLimited.size() > 25) {
+ recentsLimited.erase(recentsLimited.begin() + 25, recentsLimited.end());
+ }
+ if (eagleMode_) {
+ foreach(ChatListWindow::Chat& chat, recentsLimited) {
+ chat.activity = "";
+ }
+ }
+
+ class RemoveRecent {
+ public:
+ static bool ifPrivateMessage(const ChatListWindow::Chat& chat) {
+ return chat.isPrivateMessage;
+ }
+ };
+
+ recentsLimited.erase(std::remove_if(recentsLimited.begin(), recentsLimited.end(), RemoveRecent::ifPrivateMessage), recentsLimited.end());
+
+ oa << recentsLimited;
+ std::string serializedStr = Base64::encode(createByteArray(serializeStream.str()));
+ profileSettings_->storeString(RECENT_CHATS, serializedStr);
}
void ChatsManager::handleClearRecentsRequested() {
- recentChats_.clear();
- saveRecents();
- handleUnreadCountChanged(NULL);
+ recentChats_.clear();
+ saveRecents();
+ handleUnreadCountChanged(NULL);
}
void ChatsManager::handleJIDAddedToRoster(const JID &jid) {
- updatePresenceReceivingStateOnChatController(jid);
+ updatePresenceReceivingStateOnChatController(jid);
}
void ChatsManager::handleJIDRemovedFromRoster(const JID &jid) {
- updatePresenceReceivingStateOnChatController(jid);
+ updatePresenceReceivingStateOnChatController(jid);
}
void ChatsManager::handleJIDUpdatedInRoster(const JID &jid) {
- updatePresenceReceivingStateOnChatController(jid);
+ updatePresenceReceivingStateOnChatController(jid);
}
void ChatsManager::handleRosterCleared() {
- /* Setting that all chat controllers aren't receiving presence anymore;
- including MUC 1-to-1 chats due to the assumtion that this handler
- is only called on log out. */
- foreach(JIDChatControllerPair pair, chatControllers_) {
- pair.second->setContactIsReceivingPresence(false);
- }
+ /* Setting that all chat controllers aren't receiving presence anymore;
+ including MUC 1-to-1 chats due to the assumtion that this handler
+ is only called on log out. */
+ foreach(JIDChatControllerPair pair, chatControllers_) {
+ pair.second->setContactIsReceivingPresence(false);
+ }
}
void ChatsManager::updatePresenceReceivingStateOnChatController(const JID &jid) {
- ChatController* controller = getChatControllerIfExists(jid);
- if (controller) {
- if (!mucRegistry_->isMUC(jid.toBare())) {
- RosterItemPayload::Subscription subscription = roster_->getSubscriptionStateForJID(jid);
- controller->setContactIsReceivingPresence(subscription == RosterItemPayload::From || subscription == RosterItemPayload::Both);
- } else {
- controller->setContactIsReceivingPresence(true);
- }
- }
+ ChatController* controller = getChatControllerIfExists(jid);
+ if (controller) {
+ if (!mucRegistry_->isMUC(jid.toBare())) {
+ RosterItemPayload::Subscription subscription = roster_->getSubscriptionStateForJID(jid);
+ controller->setContactIsReceivingPresence(subscription == RosterItemPayload::From || subscription == RosterItemPayload::Both);
+ } else {
+ controller->setContactIsReceivingPresence(true);
+ }
+ }
}
ChatListWindow::Chat ChatsManager::updateChatStatusAndAvatarHelper(const ChatListWindow::Chat& chat) const {
- ChatListWindow::Chat fixedChat = chat;
- if (fixedChat.isMUC) {
- if (mucControllers_.find(fixedChat.jid.toBare()) != mucControllers_.end()) {
- fixedChat.statusType = StatusShow::Online;
- }
- } else {
- if (avatarManager_) {
- fixedChat.avatarPath = avatarManager_->getAvatarPath(fixedChat.jid);
- }
- Presence::ref presence = presenceOracle_->getAccountPresence(fixedChat.jid.toBare());
- fixedChat.statusType = presence ? presence->getShow() : StatusShow::None;
- }
- return fixedChat;
+ ChatListWindow::Chat fixedChat = chat;
+ if (fixedChat.isMUC) {
+ if (mucControllers_.find(fixedChat.jid.toBare()) != mucControllers_.end()) {
+ fixedChat.statusType = StatusShow::Online;
+ }
+ } else {
+ if (avatarManager_) {
+ fixedChat.avatarPath = avatarManager_->getAvatarPath(fixedChat.jid);
+ }
+ Presence::ref presence = presenceOracle_->getAccountPresence(fixedChat.jid.toBare());
+ fixedChat.statusType = presence ? presence->getShow() : StatusShow::None;
+ }
+ return fixedChat;
}
void ChatsManager::loadRecents() {
- std::string recentsString(profileSettings_->getStringSetting(RECENT_CHATS));
- if (recentsString.find("\t") != std::string::npos) {
- // old format
- std::vector<std::string> recents;
- boost::split(recents, recentsString, boost::is_any_of("\n"));
- int i = 0;
- foreach (std::string recentString, recents) {
- if (i++ > 30) {
- break;
- }
- std::vector<std::string> recent;
- boost::split(recent, recentString, boost::is_any_of("\t"));
- if (recent.size() < 4) {
- continue;
- }
- JID jid(recent[0]);
- if (!jid.isValid()) {
- continue;
- }
- std::string activity(recent[1]);
- bool isMUC = recent[2] == "true";
- std::string nick(recent[3]);
- StatusShow::Type type = StatusShow::None;
- boost::filesystem::path path;
-
- ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, 0, type, path, isMUC, false, nick);
- chat = updateChatStatusAndAvatarHelper(chat);
- prependRecent(chat);
- }
- } else if (!recentsString.empty()){
- // boost searilaize based format
- ByteArray debase64 = Base64::decode(recentsString);
- std::vector<ChatListWindow::Chat> recentChats;
- std::stringstream deserializeStream(std::string(reinterpret_cast<const char*>(vecptr(debase64)), debase64.size()));
- try {
- boost::archive::text_iarchive ia(deserializeStream);
- ia >> recentChats;
- } catch (const boost::archive::archive_exception& e) {
- SWIFT_LOG(debug) << "Failed to load recents: " << e.what() << std::endl;
- return;
- }
-
- foreach(ChatListWindow::Chat chat, recentChats) {
- chat.statusType = StatusShow::None;
- chat = updateChatStatusAndAvatarHelper(chat);
- prependRecent(chat);
- }
- }
- handleUnreadCountChanged(NULL);
+ std::string recentsString(profileSettings_->getStringSetting(RECENT_CHATS));
+ if (recentsString.find("\t") != std::string::npos) {
+ // old format
+ std::vector<std::string> recents;
+ boost::split(recents, recentsString, boost::is_any_of("\n"));
+ int i = 0;
+ foreach (std::string recentString, recents) {
+ if (i++ > 30) {
+ break;
+ }
+ std::vector<std::string> recent;
+ boost::split(recent, recentString, boost::is_any_of("\t"));
+ if (recent.size() < 4) {
+ continue;
+ }
+ JID jid(recent[0]);
+ if (!jid.isValid()) {
+ continue;
+ }
+ std::string activity(recent[1]);
+ bool isMUC = recent[2] == "true";
+ std::string nick(recent[3]);
+ StatusShow::Type type = StatusShow::None;
+ boost::filesystem::path path;
+
+ ChatListWindow::Chat chat(jid, nickResolver_->jidToNick(jid), activity, 0, type, path, isMUC, false, nick);
+ chat = updateChatStatusAndAvatarHelper(chat);
+ prependRecent(chat);
+ }
+ } else if (!recentsString.empty()){
+ // boost searilaize based format
+ ByteArray debase64 = Base64::decode(recentsString);
+ std::vector<ChatListWindow::Chat> recentChats;
+ std::stringstream deserializeStream(std::string(reinterpret_cast<const char*>(vecptr(debase64)), debase64.size()));
+ try {
+ boost::archive::text_iarchive ia(deserializeStream);
+ ia >> recentChats;
+ } catch (const boost::archive::archive_exception& e) {
+ SWIFT_LOG(debug) << "Failed to load recents: " << e.what() << std::endl;
+ return;
+ }
+
+ foreach(ChatListWindow::Chat chat, recentChats) {
+ chat.statusType = StatusShow::None;
+ chat = updateChatStatusAndAvatarHelper(chat);
+ prependRecent(chat);
+ }
+ }
+ handleUnreadCountChanged(NULL);
}
void ChatsManager::setupBookmarks() {
- if (!mucBookmarkManager_) {
- mucBookmarkManager_ = new MUCBookmarkManager(iqRouter_);
- mucBookmarkManager_->onBookmarksReady.connect(boost::bind(&ChatsManager::handleBookmarksReady, this));
- mucBookmarkManager_->onBookmarkAdded.connect(boost::bind(&ChatsManager::handleMUCBookmarkAdded, this, _1));
- mucBookmarkManager_->onBookmarkRemoved.connect(boost::bind(&ChatsManager::handleMUCBookmarkRemoved, this, _1));
-
- if (chatListWindow_) {
- chatListWindow_->setBookmarksEnabled(false);
- chatListWindow_->clearBookmarks();
- }
- }
+ if (!mucBookmarkManager_) {
+ mucBookmarkManager_ = new MUCBookmarkManager(iqRouter_);
+ mucBookmarkManager_->onBookmarksReady.connect(boost::bind(&ChatsManager::handleBookmarksReady, this));
+ mucBookmarkManager_->onBookmarkAdded.connect(boost::bind(&ChatsManager::handleMUCBookmarkAdded, this, _1));
+ mucBookmarkManager_->onBookmarkRemoved.connect(boost::bind(&ChatsManager::handleMUCBookmarkRemoved, this, _1));
+
+ if (chatListWindow_) {
+ chatListWindow_->setBookmarksEnabled(false);
+ chatListWindow_->clearBookmarks();
+ }
+ }
}
void ChatsManager::handleBookmarksReady() {
- if (chatListWindow_) {
- chatListWindow_->setBookmarksEnabled(true);
- }
+ if (chatListWindow_) {
+ chatListWindow_->setBookmarksEnabled(true);
+ }
}
void ChatsManager::handleMUCBookmarkAdded(const MUCBookmark& bookmark) {
- std::map<JID, MUCController*>::iterator it = mucControllers_.find(bookmark.getRoom());
- if (it == mucControllers_.end() && bookmark.getAutojoin()) {
- handleJoinMUCRequest(bookmark.getRoom(), bookmark.getPassword(), bookmark.getNick(), false, false, false );
- }
- chatListWindow_->addMUCBookmark(bookmark);
+ std::map<JID, MUCController*>::iterator it = mucControllers_.find(bookmark.getRoom());
+ if (it == mucControllers_.end() && bookmark.getAutojoin()) {
+ handleJoinMUCRequest(bookmark.getRoom(), bookmark.getPassword(), bookmark.getNick(), false, false, false );
+ }
+ chatListWindow_->addMUCBookmark(bookmark);
}
void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) {
- chatListWindow_->removeMUCBookmark(bookmark);
+ chatListWindow_->removeMUCBookmark(bookmark);
}
ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const std::string& activity, bool privateMessage) {
- int unreadCount = 0;
- if (mucRegistry_->isMUC(jid)) {
- MUCController* controller = mucControllers_[jid.toBare()];
- StatusShow::Type type = StatusShow::None;
- std::string nick = "";
- std::string password = "";
- if (controller) {
- unreadCount = controller->getUnreadCount();
- if (controller->isJoined()) {
- type = StatusShow::Online;
- }
- nick = controller->getNick();
-
- if (controller->getPassword()) {
- password = *controller->getPassword();
- }
-
- if (controller->isImpromptu()) {
- ChatListWindow::Chat chat = ChatListWindow::Chat(jid, jid.toString(), activity, unreadCount, type, boost::filesystem::path(), true, privateMessage, nick, password);
- std::map<std::string, JID> participants = controller->getParticipantJIDs();
- chat.impromptuJIDs = participants;
- return chat;
- }
- }
- return ChatListWindow::Chat(jid, jid.toString(), activity, unreadCount, type, boost::filesystem::path(), true, privateMessage, nick, password);
- } else {
- ChatController* controller = getChatControllerIfExists(jid, false);
- if (controller) {
- unreadCount = controller->getUnreadCount();
- }
- JID bareishJID = mucRegistry_->isMUC(jid.toBare()) ? jid : jid.toBare();
- Presence::ref presence = presenceOracle_->getAccountPresence(bareishJID);
- StatusShow::Type type = presence ? presence->getShow() : StatusShow::None;
- boost::filesystem::path avatarPath = avatarManager_ ? avatarManager_->getAvatarPath(bareishJID) : boost::filesystem::path();
- return ChatListWindow::Chat(bareishJID, nickResolver_->jidToNick(bareishJID), activity, unreadCount, type, avatarPath, false, privateMessage);
- }
+ int unreadCount = 0;
+ if (mucRegistry_->isMUC(jid)) {
+ MUCController* controller = mucControllers_[jid.toBare()];
+ StatusShow::Type type = StatusShow::None;
+ std::string nick = "";
+ std::string password = "";
+ if (controller) {
+ unreadCount = controller->getUnreadCount();
+ if (controller->isJoined()) {
+ type = StatusShow::Online;
+ }
+ nick = controller->getNick();
+
+ if (controller->getPassword()) {
+ password = *controller->getPassword();
+ }
+
+ if (controller->isImpromptu()) {
+ ChatListWindow::Chat chat = ChatListWindow::Chat(jid, jid.toString(), activity, unreadCount, type, boost::filesystem::path(), true, privateMessage, nick, password);
+ std::map<std::string, JID> participants = controller->getParticipantJIDs();
+ chat.impromptuJIDs = participants;
+ return chat;
+ }
+ }
+ return ChatListWindow::Chat(jid, jid.toString(), activity, unreadCount, type, boost::filesystem::path(), true, privateMessage, nick, password);
+ } else {
+ ChatController* controller = getChatControllerIfExists(jid, false);
+ if (controller) {
+ unreadCount = controller->getUnreadCount();
+ }
+ JID bareishJID = mucRegistry_->isMUC(jid.toBare()) ? jid : jid.toBare();
+ Presence::ref presence = presenceOracle_->getAccountPresence(bareishJID);
+ StatusShow::Type type = presence ? presence->getShow() : StatusShow::None;
+ boost::filesystem::path avatarPath = avatarManager_ ? avatarManager_->getAvatarPath(bareishJID) : boost::filesystem::path();
+ return ChatListWindow::Chat(bareishJID, nickResolver_->jidToNick(bareishJID), activity, unreadCount, type, avatarPath, false, privateMessage);
+ }
}
void ChatsManager::handleChatActivity(const JID& jid, const std::string& activity, bool isMUC) {
- const bool privateMessage = mucRegistry_->isMUC(jid.toBare()) && !isMUC;
- ChatListWindow::Chat chat = createChatListChatItem(jid, activity, privateMessage);
- /* FIXME: handle nick changes */
- appendRecent(chat);
- handleUnreadCountChanged(NULL);
- saveRecents();
+ const bool privateMessage = mucRegistry_->isMUC(jid.toBare()) && !isMUC;
+ ChatListWindow::Chat chat = createChatListChatItem(jid, activity, privateMessage);
+ /* FIXME: handle nick changes */
+ appendRecent(chat);
+ handleUnreadCountChanged(NULL);
+ saveRecents();
}
void ChatsManager::handleChatClosed(const JID& /*jid*/) {
- cleanupPrivateMessageRecents();
- chatListWindow_->setRecents(recentChats_);
+ cleanupPrivateMessageRecents();
+ chatListWindow_->setRecents(recentChats_);
}
void ChatsManager::handleUnreadCountChanged(ChatControllerBase* controller) {
- int unreadTotal = 0;
- bool controllerIsMUC = dynamic_cast<MUCController*>(controller);
- bool isPM = controller && !controllerIsMUC && mucRegistry_->isMUC(controller->getToJID().toBare());
- foreach (ChatListWindow::Chat& chatItem, recentChats_) {
- bool match = false;
- if (controller) {
- /* Matching MUC item */
- match |= chatItem.isMUC == controllerIsMUC && chatItem.jid.toBare() == controller->getToJID().toBare();
- /* Matching PM */
- match |= isPM && chatItem.jid == controller->getToJID();
- /* Matching non-PM */
- match |= !isPM && !controllerIsMUC && chatItem.jid.toBare() == controller->getToJID().toBare();
- }
- if (match) {
- chatItem.setUnreadCount(controller->getUnreadCount());
- }
- unreadTotal += chatItem.unreadCount;
- }
- chatListWindow_->setRecents(recentChats_);
- chatListWindow_->setUnreadCount(unreadTotal);
+ int unreadTotal = 0;
+ bool controllerIsMUC = dynamic_cast<MUCController*>(controller);
+ bool isPM = controller && !controllerIsMUC && mucRegistry_->isMUC(controller->getToJID().toBare());
+ foreach (ChatListWindow::Chat& chatItem, recentChats_) {
+ bool match = false;
+ if (controller) {
+ /* Matching MUC item */
+ match |= chatItem.isMUC == controllerIsMUC && chatItem.jid.toBare() == controller->getToJID().toBare();
+ /* Matching PM */
+ match |= isPM && chatItem.jid == controller->getToJID();
+ /* Matching non-PM */
+ match |= !isPM && !controllerIsMUC && chatItem.jid.toBare() == controller->getToJID().toBare();
+ }
+ if (match) {
+ chatItem.setUnreadCount(controller->getUnreadCount());
+ }
+ unreadTotal += chatItem.unreadCount;
+ }
+ chatListWindow_->setRecents(recentChats_);
+ chatListWindow_->setUnreadCount(unreadTotal);
}
boost::optional<ChatListWindow::Chat> ChatsManager::removeExistingChat(const ChatListWindow::Chat& chat) {
- std::list<ChatListWindow::Chat>::iterator result = std::find(recentChats_.begin(), recentChats_.end(), chat);
- if (result != recentChats_.end()) {
- ChatListWindow::Chat existingChat = *result;
- recentChats_.erase(std::remove(recentChats_.begin(), recentChats_.end(), chat), recentChats_.end());
- return boost::optional<ChatListWindow::Chat>(existingChat);
- } else {
- return boost::optional<ChatListWindow::Chat>();
- }
+ std::list<ChatListWindow::Chat>::iterator result = std::find(recentChats_.begin(), recentChats_.end(), chat);
+ if (result != recentChats_.end()) {
+ ChatListWindow::Chat existingChat = *result;
+ recentChats_.erase(std::remove(recentChats_.begin(), recentChats_.end(), chat), recentChats_.end());
+ return boost::optional<ChatListWindow::Chat>(existingChat);
+ } else {
+ return boost::optional<ChatListWindow::Chat>();
+ }
}
void ChatsManager::cleanupPrivateMessageRecents() {
- /* if we leave a MUC and close a PM, remove it's recent chat entry */
- const std::list<ChatListWindow::Chat> chats = recentChats_;
- foreach (const ChatListWindow::Chat& chat, chats) {
- if (chat.isPrivateMessage) {
- typedef std::map<JID, MUCController*> ControllerMap;
- ControllerMap::iterator muc = mucControllers_.find(chat.jid.toBare());
- if (muc == mucControllers_.end() || !muc->second->isJoined()) {
- ChatController* chatController = getChatControllerIfExists(chat.jid);
- if (!chatController || !chatController->hasOpenWindow()) {
- removeExistingChat(chat);
- break;
- }
- }
- }
- }
+ /* if we leave a MUC and close a PM, remove it's recent chat entry */
+ const std::list<ChatListWindow::Chat> chats = recentChats_;
+ foreach (const ChatListWindow::Chat& chat, chats) {
+ if (chat.isPrivateMessage) {
+ typedef std::map<JID, MUCController*> ControllerMap;
+ ControllerMap::iterator muc = mucControllers_.find(chat.jid.toBare());
+ if (muc == mucControllers_.end() || !muc->second->isJoined()) {
+ ChatController* chatController = getChatControllerIfExists(chat.jid);
+ if (!chatController || !chatController->hasOpenWindow()) {
+ removeExistingChat(chat);
+ break;
+ }
+ }
+ }
+ }
}
void ChatsManager::appendRecent(const ChatListWindow::Chat& chat) {
- boost::optional<ChatListWindow::Chat> oldChat = removeExistingChat(chat);
- ChatListWindow::Chat mergedChat = chat;
- if (oldChat && !oldChat->impromptuJIDs.empty()) {
- mergedChat.impromptuJIDs.insert(oldChat->impromptuJIDs.begin(), oldChat->impromptuJIDs.end());
- }
- recentChats_.push_front(mergedChat);
+ boost::optional<ChatListWindow::Chat> oldChat = removeExistingChat(chat);
+ ChatListWindow::Chat mergedChat = chat;
+ if (oldChat && !oldChat->impromptuJIDs.empty()) {
+ mergedChat.impromptuJIDs.insert(oldChat->impromptuJIDs.begin(), oldChat->impromptuJIDs.end());
+ }
+ recentChats_.push_front(mergedChat);
}
void ChatsManager::prependRecent(const ChatListWindow::Chat& chat) {
- boost::optional<ChatListWindow::Chat> oldChat = removeExistingChat(chat);
- ChatListWindow::Chat mergedChat = chat;
- if (oldChat && !oldChat->impromptuJIDs.empty()) {
- mergedChat.impromptuJIDs.insert(oldChat->impromptuJIDs.begin(), oldChat->impromptuJIDs.end());
- }
- recentChats_.push_back(mergedChat);
+ boost::optional<ChatListWindow::Chat> oldChat = removeExistingChat(chat);
+ ChatListWindow::Chat mergedChat = chat;
+ if (oldChat && !oldChat->impromptuJIDs.empty()) {
+ mergedChat.impromptuJIDs.insert(oldChat->impromptuJIDs.begin(), oldChat->impromptuJIDs.end());
+ }
+ recentChats_.push_back(mergedChat);
}
void ChatsManager::handleUserLeftMUC(MUCController* mucController) {
- std::map<JID, MUCController*>::iterator it;
- for (it = mucControllers_.begin(); it != mucControllers_.end(); ++it) {
- if ((*it).second == mucController) {
- foreach (ChatListWindow::Chat& chat, recentChats_) {
- if (chat.isMUC && chat.jid == (*it).first) {
- chat.statusType = StatusShow::None;
- }
- }
- mucControllers_.erase(it);
- delete mucController;
- break;
- }
- }
- cleanupPrivateMessageRecents();
- chatListWindow_->setRecents(recentChats_);
+ std::map<JID, MUCController*>::iterator it;
+ for (it = mucControllers_.begin(); it != mucControllers_.end(); ++it) {
+ if ((*it).second == mucController) {
+ foreach (ChatListWindow::Chat& chat, recentChats_) {
+ if (chat.isMUC && chat.jid == (*it).first) {
+ chat.statusType = StatusShow::None;
+ }
+ }
+ mucControllers_.erase(it);
+ delete mucController;
+ break;
+ }
+ }
+ cleanupPrivateMessageRecents();
+ chatListWindow_->setRecents(recentChats_);
}
void ChatsManager::handleSettingChanged(const std::string& settingPath) {
- if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) {
- userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS);
- return;
- }
+ if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) {
+ userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS);
+ return;
+ }
}
void ChatsManager::finalizeImpromptuJoin(MUC::ref muc, const std::vector<JID>& jidsToInvite, const std::string& reason, const boost::optional<JID>& reuseChatJID) {
- // send impromptu invites for the new MUC
- std::vector<JID> missingJIDsToInvite = jidsToInvite;
-
- typedef std::pair<std::string, MUCOccupant> StringMUCOccupantPair;
- std::map<std::string, MUCOccupant> occupants = muc->getOccupants();
- foreach(StringMUCOccupantPair occupant, occupants) {
- boost::optional<JID> realJID = occupant.second.getRealJID();
- if (realJID) {
- missingJIDsToInvite.erase(std::remove(missingJIDsToInvite.begin(), missingJIDsToInvite.end(), realJID->toBare()), missingJIDsToInvite.end());
- }
- }
-
- if (reuseChatJID) {
- muc->invitePerson(reuseChatJID.get(), reason, true, true);
- }
- foreach(const JID& jid, missingJIDsToInvite) {
- muc->invitePerson(jid, reason, true);
- }
+ // send impromptu invites for the new MUC
+ std::vector<JID> missingJIDsToInvite = jidsToInvite;
+
+ typedef std::pair<std::string, MUCOccupant> StringMUCOccupantPair;
+ std::map<std::string, MUCOccupant> occupants = muc->getOccupants();
+ foreach(StringMUCOccupantPair occupant, occupants) {
+ boost::optional<JID> realJID = occupant.second.getRealJID();
+ if (realJID) {
+ missingJIDsToInvite.erase(std::remove(missingJIDsToInvite.begin(), missingJIDsToInvite.end(), realJID->toBare()), missingJIDsToInvite.end());
+ }
+ }
+
+ if (reuseChatJID) {
+ muc->invitePerson(reuseChatJID.get(), reason, true, true);
+ }
+ foreach(const JID& jid, missingJIDsToInvite) {
+ muc->invitePerson(jid, reason, true);
+ }
}
void ChatsManager::handleUIEvent(boost::shared_ptr<UIEvent> event) {
- boost::shared_ptr<RequestChatUIEvent> chatEvent = boost::dynamic_pointer_cast<RequestChatUIEvent>(event);
- if (chatEvent) {
- handleChatRequest(chatEvent->getContact());
- return;
- }
- boost::shared_ptr<RemoveMUCBookmarkUIEvent> removeMUCBookmarkEvent = boost::dynamic_pointer_cast<RemoveMUCBookmarkUIEvent>(event);
- if (removeMUCBookmarkEvent) {
- mucBookmarkManager_->removeBookmark(removeMUCBookmarkEvent->getBookmark());
- return;
- }
- boost::shared_ptr<AddMUCBookmarkUIEvent> addMUCBookmarkEvent = boost::dynamic_pointer_cast<AddMUCBookmarkUIEvent>(event);
- if (addMUCBookmarkEvent) {
- mucBookmarkManager_->addBookmark(addMUCBookmarkEvent->getBookmark());
- return;
- }
-
- boost::shared_ptr<CreateImpromptuMUCUIEvent> createImpromptuMUCEvent = boost::dynamic_pointer_cast<CreateImpromptuMUCUIEvent>(event);
- if (createImpromptuMUCEvent) {
- assert(!localMUCServiceJID_.toString().empty());
- // create new muc
- JID roomJID = createImpromptuMUCEvent->getRoomJID().toString().empty() ? JID(idGenerator_.generateID(), localMUCServiceJID_) : createImpromptuMUCEvent->getRoomJID();
-
- // join muc
- MUC::ref muc = handleJoinMUCRequest(roomJID, boost::optional<std::string>(), nickResolver_->jidToNick(jid_), false, true, true);
- mucControllers_[roomJID]->onImpromptuConfigCompleted.connect(boost::bind(&ChatsManager::finalizeImpromptuJoin, this, muc, createImpromptuMUCEvent->getJIDs(), createImpromptuMUCEvent->getReason(), boost::optional<JID>()));
- mucControllers_[roomJID]->activateChatWindow();
- }
-
- boost::shared_ptr<EditMUCBookmarkUIEvent> editMUCBookmarkEvent = boost::dynamic_pointer_cast<EditMUCBookmarkUIEvent>(event);
- if (editMUCBookmarkEvent) {
- mucBookmarkManager_->replaceBookmark(editMUCBookmarkEvent->getOldBookmark(), editMUCBookmarkEvent->getNewBookmark());
- }
- else if (JoinMUCUIEvent::ref joinEvent = boost::dynamic_pointer_cast<JoinMUCUIEvent>(event)) {
- handleJoinMUCRequest(joinEvent->getJID(), joinEvent->getPassword(), joinEvent->getNick(), joinEvent->getShouldJoinAutomatically(), joinEvent->getCreateAsReservedRoomIfNew(), joinEvent->isImpromptu());
- mucControllers_[joinEvent->getJID()]->activateChatWindow();
- }
- else if (boost::shared_ptr<RequestJoinMUCUIEvent> joinEvent = boost::dynamic_pointer_cast<RequestJoinMUCUIEvent>(event)) {
- if (!joinMUCWindow_) {
- joinMUCWindow_ = joinMUCWindowFactory_->createJoinMUCWindow(uiEventStream_);
- joinMUCWindow_->onSearchMUC.connect(boost::bind(&ChatsManager::handleSearchMUCRequest, this));
- }
- joinMUCWindow_->setMUC(joinEvent->getRoom());
- joinMUCWindow_->setNick(nickResolver_->jidToNick(jid_));
- joinMUCWindow_->show();
- }
+ boost::shared_ptr<RequestChatUIEvent> chatEvent = boost::dynamic_pointer_cast<RequestChatUIEvent>(event);
+ if (chatEvent) {
+ handleChatRequest(chatEvent->getContact());
+ return;
+ }
+ boost::shared_ptr<RemoveMUCBookmarkUIEvent> removeMUCBookmarkEvent = boost::dynamic_pointer_cast<RemoveMUCBookmarkUIEvent>(event);
+ if (removeMUCBookmarkEvent) {
+ mucBookmarkManager_->removeBookmark(removeMUCBookmarkEvent->getBookmark());
+ return;
+ }
+ boost::shared_ptr<AddMUCBookmarkUIEvent> addMUCBookmarkEvent = boost::dynamic_pointer_cast<AddMUCBookmarkUIEvent>(event);
+ if (addMUCBookmarkEvent) {
+ mucBookmarkManager_->addBookmark(addMUCBookmarkEvent->getBookmark());
+ return;
+ }
+
+ boost::shared_ptr<CreateImpromptuMUCUIEvent> createImpromptuMUCEvent = boost::dynamic_pointer_cast<CreateImpromptuMUCUIEvent>(event);
+ if (createImpromptuMUCEvent) {
+ assert(!localMUCServiceJID_.toString().empty());
+ // create new muc
+ JID roomJID = createImpromptuMUCEvent->getRoomJID().toString().empty() ? JID(idGenerator_.generateID(), localMUCServiceJID_) : createImpromptuMUCEvent->getRoomJID();
+
+ // join muc
+ MUC::ref muc = handleJoinMUCRequest(roomJID, boost::optional<std::string>(), nickResolver_->jidToNick(jid_), false, true, true);
+ mucControllers_[roomJID]->onImpromptuConfigCompleted.connect(boost::bind(&ChatsManager::finalizeImpromptuJoin, this, muc, createImpromptuMUCEvent->getJIDs(), createImpromptuMUCEvent->getReason(), boost::optional<JID>()));
+ mucControllers_[roomJID]->activateChatWindow();
+ }
+
+ boost::shared_ptr<EditMUCBookmarkUIEvent> editMUCBookmarkEvent = boost::dynamic_pointer_cast<EditMUCBookmarkUIEvent>(event);
+ if (editMUCBookmarkEvent) {
+ mucBookmarkManager_->replaceBookmark(editMUCBookmarkEvent->getOldBookmark(), editMUCBookmarkEvent->getNewBookmark());
+ }
+ else if (JoinMUCUIEvent::ref joinEvent = boost::dynamic_pointer_cast<JoinMUCUIEvent>(event)) {
+ handleJoinMUCRequest(joinEvent->getJID(), joinEvent->getPassword(), joinEvent->getNick(), joinEvent->getShouldJoinAutomatically(), joinEvent->getCreateAsReservedRoomIfNew(), joinEvent->isImpromptu());
+ mucControllers_[joinEvent->getJID()]->activateChatWindow();
+ }
+ else if (boost::shared_ptr<RequestJoinMUCUIEvent> joinEvent = boost::dynamic_pointer_cast<RequestJoinMUCUIEvent>(event)) {
+ if (!joinMUCWindow_) {
+ joinMUCWindow_ = joinMUCWindowFactory_->createJoinMUCWindow(uiEventStream_);
+ joinMUCWindow_->onSearchMUC.connect(boost::bind(&ChatsManager::handleSearchMUCRequest, this));
+ }
+ joinMUCWindow_->setMUC(joinEvent->getRoom());
+ joinMUCWindow_->setNick(nickResolver_->jidToNick(jid_));
+ joinMUCWindow_->show();
+ }
}
void ChatsManager::markAllRecentsOffline() {
- foreach (ChatListWindow::Chat& chat, recentChats_) {
- chat.setStatusType(StatusShow::None);
- }
+ foreach (ChatListWindow::Chat& chat, recentChats_) {
+ chat.setStatusType(StatusShow::None);
+ }
- chatListWindow_->setRecents(recentChats_);
+ chatListWindow_->setRecents(recentChats_);
}
void ChatsManager::handleTransformChatToMUC(ChatController* chatController, ChatWindow* chatWindow, const std::vector<JID>& jidsToInvite, const std::string& reason) {
- JID reuseChatInvite = chatController->getToJID();
- chatControllers_.erase(chatController->getToJID());
- delete chatController;
+ JID reuseChatInvite = chatController->getToJID();
+ chatControllers_.erase(chatController->getToJID());
+ delete chatController;
- // join new impromptu muc
- assert(!localMUCServiceJID_.toString().empty());
+ // join new impromptu muc
+ assert(!localMUCServiceJID_.toString().empty());
- // create new muc
- JID roomJID = JID(idGenerator_.generateID(), localMUCServiceJID_);
+ // create new muc
+ JID roomJID = JID(idGenerator_.generateID(), localMUCServiceJID_);
- // join muc
- MUC::ref muc = handleJoinMUCRequest(roomJID, boost::optional<std::string>(), nickResolver_->jidToNick(jid_), false, true, true, chatWindow);
- mucControllers_[roomJID]->onImpromptuConfigCompleted.connect(boost::bind(&ChatsManager::finalizeImpromptuJoin, this, muc, jidsToInvite, reason, boost::optional<JID>(reuseChatInvite)));
+ // join muc
+ MUC::ref muc = handleJoinMUCRequest(roomJID, boost::optional<std::string>(), nickResolver_->jidToNick(jid_), false, true, true, chatWindow);
+ mucControllers_[roomJID]->onImpromptuConfigCompleted.connect(boost::bind(&ChatsManager::finalizeImpromptuJoin, this, muc, jidsToInvite, reason, boost::optional<JID>(reuseChatInvite)));
}
/**
* If a resource goes offline, release bound chatdialog to that resource.
*/
void ChatsManager::handlePresenceChange(boost::shared_ptr<Presence> newPresence) {
- if (mucRegistry_->isMUC(newPresence->getFrom().toBare())) return;
-
- foreach (ChatListWindow::Chat& chat, recentChats_) {
- if (newPresence->getFrom().toBare() == chat.jid.toBare() && !chat.isMUC) {
- Presence::ref presence = presenceOracle_->getHighestPriorityPresence(chat.jid.toBare());
- chat.setStatusType(presence ? presence->getShow() : StatusShow::None);
- chatListWindow_->setRecents(recentChats_);
- break;
- }
- }
-
- //if (newPresence->getType() != Presence::Unavailable) return;
- JID fullJID(newPresence->getFrom());
- std::map<JID, ChatController*>::iterator it = chatControllers_.find(fullJID);
- if (it == chatControllers_.end()) return;
- JID bareJID(fullJID.toBare());
- //It doesn't make sense to have two unbound dialogs.
- if (chatControllers_.find(bareJID) != chatControllers_.end()) return;
- rebindControllerJID(fullJID, bareJID);
+ if (mucRegistry_->isMUC(newPresence->getFrom().toBare())) return;
+
+ foreach (ChatListWindow::Chat& chat, recentChats_) {
+ if (newPresence->getFrom().toBare() == chat.jid.toBare() && !chat.isMUC) {
+ Presence::ref presence = presenceOracle_->getHighestPriorityPresence(chat.jid.toBare());
+ chat.setStatusType(presence ? presence->getShow() : StatusShow::None);
+ chatListWindow_->setRecents(recentChats_);
+ break;
+ }
+ }
+
+ //if (newPresence->getType() != Presence::Unavailable) return;
+ JID fullJID(newPresence->getFrom());
+ std::map<JID, ChatController*>::iterator it = chatControllers_.find(fullJID);
+ if (it == chatControllers_.end()) return;
+ JID bareJID(fullJID.toBare());
+ //It doesn't make sense to have two unbound dialogs.
+ if (chatControllers_.find(bareJID) != chatControllers_.end()) return;
+ rebindControllerJID(fullJID, bareJID);
}
void ChatsManager::setAvatarManager(AvatarManager* avatarManager) {
- if (avatarManager_) {
- avatarManager_->onAvatarChanged.disconnect(boost::bind(&ChatsManager::handleAvatarChanged, this, _1));
- }
- avatarManager_ = avatarManager;
- foreach (ChatListWindow::Chat& chat, recentChats_) {
- if (!chat.isMUC) {
- chat.setAvatarPath(avatarManager_->getAvatarPath(chat.jid));
- }
- }
- avatarManager_->onAvatarChanged.connect(boost::bind(&ChatsManager::handleAvatarChanged, this, _1));
+ if (avatarManager_) {
+ avatarManager_->onAvatarChanged.disconnect(boost::bind(&ChatsManager::handleAvatarChanged, this, _1));
+ }
+ avatarManager_ = avatarManager;
+ foreach (ChatListWindow::Chat& chat, recentChats_) {
+ if (!chat.isMUC) {
+ chat.setAvatarPath(avatarManager_->getAvatarPath(chat.jid));
+ }
+ }
+ avatarManager_->onAvatarChanged.connect(boost::bind(&ChatsManager::handleAvatarChanged, this, _1));
}
void ChatsManager::handleAvatarChanged(const JID& jid) {
- foreach (ChatListWindow::Chat& chat, recentChats_) {
- if (!chat.isMUC && jid.toBare() == chat.jid.toBare()) {
- chat.setAvatarPath(avatarManager_->getAvatarPath(jid));
- break;
- }
- }
+ foreach (ChatListWindow::Chat& chat, recentChats_) {
+ if (!chat.isMUC && jid.toBare() == chat.jid.toBare()) {
+ chat.setAvatarPath(avatarManager_->getAvatarPath(jid));
+ break;
+ }
+ }
}
void ChatsManager::setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info) {
- serverDiscoInfo_ = info;
- foreach (JIDChatControllerPair pair, chatControllers_) {
- pair.second->setAvailableServerFeatures(info);
- }
- foreach (JIDMUCControllerPair pair, mucControllers_) {
- pair.second->setAvailableServerFeatures(info);
- }
+ serverDiscoInfo_ = info;
+ foreach (JIDChatControllerPair pair, chatControllers_) {
+ pair.second->setAvailableServerFeatures(info);
+ }
+ foreach (JIDMUCControllerPair pair, mucControllers_) {
+ pair.second->setAvailableServerFeatures(info);
+ }
}
/**
* This is to be called on connect/disconnect.
- */
+ */
void ChatsManager::setOnline(bool enabled) {
- foreach (JIDChatControllerPair controllerPair, chatControllers_) {
- controllerPair.second->setOnline(enabled);
- }
- foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
- controllerPair.second->setOnline(enabled);
- if (enabled) {
- controllerPair.second->rejoin();
- }
- }
- if (!enabled) {
- markAllRecentsOffline();
- } else {
- setupBookmarks();
- localMUCServiceJID_ = JID();
- localMUCServiceFinderWalker_ = boost::make_shared<DiscoServiceWalker>(jid_.getDomain(), iqRouter_);
- localMUCServiceFinderWalker_->onServiceFound.connect(boost::bind(&ChatsManager::handleLocalServiceFound, this, _1, _2));
- localMUCServiceFinderWalker_->onWalkAborted.connect(boost::bind(&ChatsManager::handleLocalServiceWalkFinished, this));
- localMUCServiceFinderWalker_->onWalkComplete.connect(boost::bind(&ChatsManager::handleLocalServiceWalkFinished, this));
- localMUCServiceFinderWalker_->beginWalk();
- }
-
- if (chatListWindow_) {
- chatListWindow_->setBookmarksEnabled(enabled);
- }
+ foreach (JIDChatControllerPair controllerPair, chatControllers_) {
+ controllerPair.second->setOnline(enabled);
+ }
+ foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
+ controllerPair.second->setOnline(enabled);
+ if (enabled) {
+ controllerPair.second->rejoin();
+ }
+ }
+ if (!enabled) {
+ markAllRecentsOffline();
+ } else {
+ setupBookmarks();
+ localMUCServiceJID_ = JID();
+ localMUCServiceFinderWalker_ = boost::make_shared<DiscoServiceWalker>(jid_.getDomain(), iqRouter_);
+ localMUCServiceFinderWalker_->onServiceFound.connect(boost::bind(&ChatsManager::handleLocalServiceFound, this, _1, _2));
+ localMUCServiceFinderWalker_->onWalkAborted.connect(boost::bind(&ChatsManager::handleLocalServiceWalkFinished, this));
+ localMUCServiceFinderWalker_->onWalkComplete.connect(boost::bind(&ChatsManager::handleLocalServiceWalkFinished, this));
+ localMUCServiceFinderWalker_->beginWalk();
+ }
+
+ if (chatListWindow_) {
+ chatListWindow_->setBookmarksEnabled(enabled);
+ }
}
void ChatsManager::handleChatRequest(const std::string &contact) {
- ChatController* controller = getChatControllerOrFindAnother(JID(contact));
- controller->activateChatWindow();
+ ChatController* controller = getChatControllerOrFindAnother(JID(contact));
+ controller->activateChatWindow();
}
ChatController* ChatsManager::getChatControllerOrFindAnother(const JID &contact) {
- ChatController* controller = getChatControllerIfExists(contact);
- if (!controller && !mucRegistry_->isMUC(contact.toBare())) {
- foreach (JIDChatControllerPair pair, chatControllers_) {
- if (pair.first.toBare() == contact.toBare()) {
- controller = pair.second;
- break;
- }
- }
- }
- return controller ? controller : createNewChatController(contact);
+ ChatController* controller = getChatControllerIfExists(contact);
+ if (!controller && !mucRegistry_->isMUC(contact.toBare())) {
+ foreach (JIDChatControllerPair pair, chatControllers_) {
+ if (pair.first.toBare() == contact.toBare()) {
+ controller = pair.second;
+ break;
+ }
+ }
+ }
+ return controller ? controller : createNewChatController(contact);
}
ChatController* ChatsManager::createNewChatController(const JID& contact) {
- assert(chatControllers_.find(contact) == chatControllers_.end());
- boost::shared_ptr<ChatMessageParser> chatMessageParser = boost::make_shared<ChatMessageParser>(emoticons_, highlightManager_->getRules(), false); /* a message parser that knows this is a chat (not a room/MUC) */
- ChatController* controller = new ChatController(jid_, stanzaChannel_, iqRouter_, chatWindowFactory_, contact, nickResolver_, presenceOracle_, avatarManager_, mucRegistry_->isMUC(contact.toBare()), useDelayForLatency_, uiEventStream_, eventController_, timerFactory_, entityCapsProvider_, userWantsReceipts_, settings_, historyController_, mucRegistry_, highlightManager_, clientBlockListManager_, chatMessageParser, autoAcceptMUCInviteDecider_);
- chatControllers_[contact] = controller;
- controller->setAvailableServerFeatures(serverDiscoInfo_);
- controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, contact, _1, false));
- controller->onWindowClosed.connect(boost::bind(&ChatsManager::handleChatClosed, this, contact));
- controller->onUnreadCountChanged.connect(boost::bind(&ChatsManager::handleUnreadCountChanged, this, controller));
- controller->onConvertToMUC.connect(boost::bind(&ChatsManager::handleTransformChatToMUC, this, controller, _1, _2, _3));
- updatePresenceReceivingStateOnChatController(contact);
- controller->setCanStartImpromptuChats(!localMUCServiceJID_.toString().empty());
- return controller;
+ assert(chatControllers_.find(contact) == chatControllers_.end());
+ boost::shared_ptr<ChatMessageParser> chatMessageParser = boost::make_shared<ChatMessageParser>(emoticons_, highlightManager_->getRules(), false); /* a message parser that knows this is a chat (not a room/MUC) */
+ ChatController* controller = new ChatController(jid_, stanzaChannel_, iqRouter_, chatWindowFactory_, contact, nickResolver_, presenceOracle_, avatarManager_, mucRegistry_->isMUC(contact.toBare()), useDelayForLatency_, uiEventStream_, eventController_, timerFactory_, entityCapsProvider_, userWantsReceipts_, settings_, historyController_, mucRegistry_, highlightManager_, clientBlockListManager_, chatMessageParser, autoAcceptMUCInviteDecider_);
+ chatControllers_[contact] = controller;
+ controller->setAvailableServerFeatures(serverDiscoInfo_);
+ controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, contact, _1, false));
+ controller->onWindowClosed.connect(boost::bind(&ChatsManager::handleChatClosed, this, contact));
+ controller->onUnreadCountChanged.connect(boost::bind(&ChatsManager::handleUnreadCountChanged, this, controller));
+ controller->onConvertToMUC.connect(boost::bind(&ChatsManager::handleTransformChatToMUC, this, controller, _1, _2, _3));
+ updatePresenceReceivingStateOnChatController(contact);
+ controller->setCanStartImpromptuChats(!localMUCServiceJID_.toString().empty());
+ return controller;
}
ChatController* ChatsManager::getChatControllerOrCreate(const JID &contact) {
- ChatController* controller = getChatControllerIfExists(contact);
- return controller ? controller : createNewChatController(contact);
+ ChatController* controller = getChatControllerIfExists(contact);
+ return controller ? controller : createNewChatController(contact);
}
ChatController* ChatsManager::getChatControllerIfExists(const JID &contact, bool rebindIfNeeded) {
- if (chatControllers_.find(contact) == chatControllers_.end()) {
- if (mucRegistry_->isMUC(contact.toBare())) {
- return NULL;
- }
- //Need to look for an unbound window to bind first
- JID bare(contact.toBare());
- if (chatControllers_.find(bare) != chatControllers_.end()) {
- if (rebindIfNeeded) {
- rebindControllerJID(bare, contact);
- }
- else {
- return chatControllers_[bare];
- }
- } else {
- foreach (JIDChatControllerPair pair, chatControllers_) {
- if (pair.first.toBare() == contact.toBare()) {
- if (rebindIfNeeded) {
- rebindControllerJID(pair.first, contact);
- return chatControllers_[contact];
- } else {
- return pair.second;
- }
- }
- }
- return NULL;
- }
- }
- return chatControllers_[contact];
+ if (chatControllers_.find(contact) == chatControllers_.end()) {
+ if (mucRegistry_->isMUC(contact.toBare())) {
+ return NULL;
+ }
+ //Need to look for an unbound window to bind first
+ JID bare(contact.toBare());
+ if (chatControllers_.find(bare) != chatControllers_.end()) {
+ if (rebindIfNeeded) {
+ rebindControllerJID(bare, contact);
+ }
+ else {
+ return chatControllers_[bare];
+ }
+ } else {
+ foreach (JIDChatControllerPair pair, chatControllers_) {
+ if (pair.first.toBare() == contact.toBare()) {
+ if (rebindIfNeeded) {
+ rebindControllerJID(pair.first, contact);
+ return chatControllers_[contact];
+ } else {
+ return pair.second;
+ }
+ }
+ }
+ return NULL;
+ }
+ }
+ return chatControllers_[contact];
}
void ChatsManager::rebindControllerJID(const JID& from, const JID& to) {
- chatControllers_[to] = chatControllers_[from];
- chatControllers_.erase(from);
- chatControllers_[to]->setToJID(to);
+ chatControllers_[to] = chatControllers_[from];
+ chatControllers_.erase(from);
+ chatControllers_[to]->setToJID(to);
}
MUC::ref ChatsManager::handleJoinMUCRequest(const JID &mucJID, const boost::optional<std::string>& password, const boost::optional<std::string>& nickMaybe, bool addAutoJoin, bool createAsReservedIfNew, bool isImpromptu, ChatWindow* reuseChatwindow) {
- MUC::ref muc;
- if (addAutoJoin) {
- MUCBookmark bookmark(mucJID, mucJID.getNode());
- bookmark.setAutojoin(true);
- if (nickMaybe) {
- bookmark.setNick(*nickMaybe);
- }
- if (password) {
- bookmark.setPassword(*password);
- }
- mucBookmarkManager_->addBookmark(bookmark);
- }
-
- std::map<JID, MUCController*>::iterator it = mucControllers_.find(mucJID);
- if (it != mucControllers_.end()) {
- if (stanzaChannel_->isAvailable()) {
- it->second->rejoin();
- }
- } else {
- std::string nick = (nickMaybe && !(*nickMaybe).empty()) ? nickMaybe.get() : nickResolver_->jidToNick(jid_);
- muc = mucManager->createMUC(mucJID);
- if (createAsReservedIfNew) {
- muc->setCreateAsReservedIfNew();
- }
- if (isImpromptu) {
- muc->setCreateAsReservedIfNew();
- }
-
- MUCController* controller = NULL;
- SingleChatWindowFactoryAdapter* chatWindowFactoryAdapter = NULL;
- if (reuseChatwindow) {
- chatWindowFactoryAdapter = new SingleChatWindowFactoryAdapter(reuseChatwindow);
- }
- boost::shared_ptr<ChatMessageParser> chatMessageParser = boost::make_shared<ChatMessageParser>(emoticons_, highlightManager_->getRules(), true); /* a message parser that knows this is a room/MUC (not a chat) */
- controller = new MUCController(jid_, muc, password, nick, stanzaChannel_, iqRouter_, reuseChatwindow ? chatWindowFactoryAdapter : chatWindowFactory_, presenceOracle_, avatarManager_, uiEventStream_, false, timerFactory_, eventController_, entityCapsProvider_, roster_, historyController_, mucRegistry_, highlightManager_, clientBlockListManager_, chatMessageParser, isImpromptu, autoAcceptMUCInviteDecider_, vcardManager_, mucBookmarkManager_);
- if (chatWindowFactoryAdapter) {
- /* The adapters are only passed to chat windows, which are deleted in their
- * controllers' dtor, which are deleted in ChatManager's dtor. The adapters
- * are also deleted there.*/
- chatWindowFactoryAdapters_[controller] = chatWindowFactoryAdapter;
- }
-
- mucControllers_[mucJID] = controller;
- controller->setAvailableServerFeatures(serverDiscoInfo_);
- controller->onUserLeft.connect(boost::bind(&ChatsManager::handleUserLeftMUC, this, controller));
- controller->onUserJoined.connect(boost::bind(&ChatsManager::handleChatActivity, this, mucJID.toBare(), "", true));
- controller->onUserNicknameChanged.connect(boost::bind(&ChatsManager::handleUserNicknameChanged, this, controller, _1, _2));
- controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, mucJID.toBare(), _1, true));
- controller->onUnreadCountChanged.connect(boost::bind(&ChatsManager::handleUnreadCountChanged, this, controller));
- if (!stanzaChannel_->isAvailable()) {
- /* When online, the MUC is added to the registry in MUCImpl::internalJoin. This method is not
- * called when Swift is offline, so we add it here as only MUCs in the registry are rejoined
- * when going back online.
- */
- mucRegistry_->addMUC(mucJID.toBare());
- }
- handleChatActivity(mucJID.toBare(), "", true);
- }
-
- mucControllers_[mucJID]->showChatWindow();
- return muc;
+ MUC::ref muc;
+ if (addAutoJoin) {
+ MUCBookmark bookmark(mucJID, mucJID.getNode());
+ bookmark.setAutojoin(true);
+ if (nickMaybe) {
+ bookmark.setNick(*nickMaybe);
+ }
+ if (password) {
+ bookmark.setPassword(*password);
+ }
+ mucBookmarkManager_->addBookmark(bookmark);
+ }
+
+ std::map<JID, MUCController*>::iterator it = mucControllers_.find(mucJID);
+ if (it != mucControllers_.end()) {
+ if (stanzaChannel_->isAvailable()) {
+ it->second->rejoin();
+ }
+ } else {
+ std::string nick = (nickMaybe && !(*nickMaybe).empty()) ? nickMaybe.get() : nickResolver_->jidToNick(jid_);
+ muc = mucManager->createMUC(mucJID);
+ if (createAsReservedIfNew) {
+ muc->setCreateAsReservedIfNew();
+ }
+ if (isImpromptu) {
+ muc->setCreateAsReservedIfNew();
+ }
+
+ MUCController* controller = NULL;
+ SingleChatWindowFactoryAdapter* chatWindowFactoryAdapter = NULL;
+ if (reuseChatwindow) {
+ chatWindowFactoryAdapter = new SingleChatWindowFactoryAdapter(reuseChatwindow);
+ }
+ boost::shared_ptr<ChatMessageParser> chatMessageParser = boost::make_shared<ChatMessageParser>(emoticons_, highlightManager_->getRules(), true); /* a message parser that knows this is a room/MUC (not a chat) */
+ controller = new MUCController(jid_, muc, password, nick, stanzaChannel_, iqRouter_, reuseChatwindow ? chatWindowFactoryAdapter : chatWindowFactory_, presenceOracle_, avatarManager_, uiEventStream_, false, timerFactory_, eventController_, entityCapsProvider_, roster_, historyController_, mucRegistry_, highlightManager_, clientBlockListManager_, chatMessageParser, isImpromptu, autoAcceptMUCInviteDecider_, vcardManager_, mucBookmarkManager_);
+ if (chatWindowFactoryAdapter) {
+ /* The adapters are only passed to chat windows, which are deleted in their
+ * controllers' dtor, which are deleted in ChatManager's dtor. The adapters
+ * are also deleted there.*/
+ chatWindowFactoryAdapters_[controller] = chatWindowFactoryAdapter;
+ }
+
+ mucControllers_[mucJID] = controller;
+ controller->setAvailableServerFeatures(serverDiscoInfo_);
+ controller->onUserLeft.connect(boost::bind(&ChatsManager::handleUserLeftMUC, this, controller));
+ controller->onUserJoined.connect(boost::bind(&ChatsManager::handleChatActivity, this, mucJID.toBare(), "", true));
+ controller->onUserNicknameChanged.connect(boost::bind(&ChatsManager::handleUserNicknameChanged, this, controller, _1, _2));
+ controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, mucJID.toBare(), _1, true));
+ controller->onUnreadCountChanged.connect(boost::bind(&ChatsManager::handleUnreadCountChanged, this, controller));
+ if (!stanzaChannel_->isAvailable()) {
+ /* When online, the MUC is added to the registry in MUCImpl::internalJoin. This method is not
+ * called when Swift is offline, so we add it here as only MUCs in the registry are rejoined
+ * when going back online.
+ */
+ mucRegistry_->addMUC(mucJID.toBare());
+ }
+ handleChatActivity(mucJID.toBare(), "", true);
+ }
+
+ mucControllers_[mucJID]->showChatWindow();
+ return muc;
}
void ChatsManager::handleSearchMUCRequest() {
- mucSearchController_->openSearchWindow();
+ mucSearchController_->openSearchWindow();
}
void ChatsManager::handleUserNicknameChanged(MUCController* mucController, const std::string& oldNickname, const std::string& newNickname) {
- JID oldMUCChatJID = mucController->getToJID().withResource(oldNickname);
- JID newMUCChatJID = mucController->getToJID().withResource(newNickname);
-
- SWIFT_LOG(debug) << "nickname change in " << mucController->getToJID().toString() << " from " << oldNickname << " to " << newNickname << std::endl;
-
- // get current chat controller
- ChatController *chatController = getChatControllerIfExists(oldMUCChatJID);
- if (chatController) {
- // adjust chat controller
- chatController->setToJID(newMUCChatJID);
- nickResolver_->onNickChanged(newMUCChatJID, oldNickname);
- chatControllers_.erase(oldMUCChatJID);
- chatControllers_[newMUCChatJID] = chatController;
-
- chatController->onActivity.disconnect(boost::bind(&ChatsManager::handleChatActivity, this, oldMUCChatJID, _1, false));
- chatController->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, newMUCChatJID, _1, false));
- }
+ JID oldMUCChatJID = mucController->getToJID().withResource(oldNickname);
+ JID newMUCChatJID = mucController->getToJID().withResource(newNickname);
+
+ SWIFT_LOG(debug) << "nickname change in " << mucController->getToJID().toString() << " from " << oldNickname << " to " << newNickname << std::endl;
+
+ // get current chat controller
+ ChatController *chatController = getChatControllerIfExists(oldMUCChatJID);
+ if (chatController) {
+ // adjust chat controller
+ chatController->setToJID(newMUCChatJID);
+ nickResolver_->onNickChanged(newMUCChatJID, oldNickname);
+ chatControllers_.erase(oldMUCChatJID);
+ chatControllers_[newMUCChatJID] = chatController;
+
+ chatController->onActivity.disconnect(boost::bind(&ChatsManager::handleChatActivity, this, oldMUCChatJID, _1, false));
+ chatController->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, newMUCChatJID, _1, false));
+ }
}
void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) {
- JID jid = message->getFrom();
- boost::shared_ptr<MessageEvent> event(new MessageEvent(message));
- bool isInvite = !!message->getPayload<MUCInvitationPayload>();
- bool isMediatedInvite = (message->getPayload<MUCUserPayload>() && message->getPayload<MUCUserPayload>()->getInvite());
- if (isMediatedInvite) {
- jid = (*message->getPayload<MUCUserPayload>()->getInvite()).from;
- }
- if (!event->isReadable() && !message->getPayload<ChatState>() && !message->getPayload<DeliveryReceipt>() && !message->getPayload<DeliveryReceiptRequest>() && !isInvite && !isMediatedInvite && !message->hasSubject()) {
- return;
- }
-
- // Try to deliver it to a MUC
- if (message->getType() == Message::Groupchat || message->getType() == Message::Error /*|| (isInvite && message->getType() == Message::Normal)*/) {
- std::map<JID, MUCController*>::iterator i = mucControllers_.find(jid.toBare());
- if (i != mucControllers_.end()) {
- i->second->handleIncomingMessage(event);
- return;
- }
- else if (message->getType() == Message::Groupchat) {
- //FIXME: Error handling - groupchat messages from an unknown muc.
- return;
- }
- }
-
- // check for impromptu invite to potentially auto-accept
- MUCInvitationPayload::ref invite = message->getPayload<MUCInvitationPayload>();
- if (invite && autoAcceptMUCInviteDecider_->isAutoAcceptedInvite(message->getFrom(), invite)) {
- if (invite->getIsContinuation()) {
- // check for existing chat controller for the from JID
- ChatController* controller = getChatControllerIfExists(jid);
- if (controller) {
- ChatWindow* window = controller->detachChatWindow();
- chatControllers_.erase(jid);
- delete controller;
- handleJoinMUCRequest(invite->getJID(), boost::optional<std::string>(), boost::optional<std::string>(), false, false, true, window);
- return;
- }
- } else {
- handleJoinMUCRequest(invite->getJID(), boost::optional<std::string>(), boost::optional<std::string>(), false, false, true);
- return;
- }
- }
-
- //if not a mucroom
- if (!event->isReadable() && !isInvite && !isMediatedInvite) {
- /* Only route such messages if a window exists, don't open new windows for them.*/
-
- // Do not bind a controller to a full JID, for delivery receipts or chat state notifications.
- bool bindControllerToJID = false;
- ChatState::ref chatState = message->getPayload<ChatState>();
- if (!message->getBody().get_value_or("").empty() || (chatState && chatState->getChatState() == ChatState::Composing)) {
- bindControllerToJID = true;
- }
-
- ChatController* controller = getChatControllerIfExists(jid, bindControllerToJID);
- if (controller) {
- controller->handleIncomingMessage(event);
- }
- } else {
- getChatControllerOrCreate(jid)->handleIncomingMessage(event);
- }
+ JID jid = message->getFrom();
+ boost::shared_ptr<MessageEvent> event(new MessageEvent(message));
+ bool isInvite = !!message->getPayload<MUCInvitationPayload>();
+ bool isMediatedInvite = (message->getPayload<MUCUserPayload>() && message->getPayload<MUCUserPayload>()->getInvite());
+ if (isMediatedInvite) {
+ jid = (*message->getPayload<MUCUserPayload>()->getInvite()).from;
+ }
+ if (!event->isReadable() && !message->getPayload<ChatState>() && !message->getPayload<DeliveryReceipt>() && !message->getPayload<DeliveryReceiptRequest>() && !isInvite && !isMediatedInvite && !message->hasSubject()) {
+ return;
+ }
+
+ // Try to deliver it to a MUC
+ if (message->getType() == Message::Groupchat || message->getType() == Message::Error /*|| (isInvite && message->getType() == Message::Normal)*/) {
+ std::map<JID, MUCController*>::iterator i = mucControllers_.find(jid.toBare());
+ if (i != mucControllers_.end()) {
+ i->second->handleIncomingMessage(event);
+ return;
+ }
+ else if (message->getType() == Message::Groupchat) {
+ //FIXME: Error handling - groupchat messages from an unknown muc.
+ return;
+ }
+ }
+
+ // check for impromptu invite to potentially auto-accept
+ MUCInvitationPayload::ref invite = message->getPayload<MUCInvitationPayload>();
+ if (invite && autoAcceptMUCInviteDecider_->isAutoAcceptedInvite(message->getFrom(), invite)) {
+ if (invite->getIsContinuation()) {
+ // check for existing chat controller for the from JID
+ ChatController* controller = getChatControllerIfExists(jid);
+ if (controller) {
+ ChatWindow* window = controller->detachChatWindow();
+ chatControllers_.erase(jid);
+ delete controller;
+ handleJoinMUCRequest(invite->getJID(), boost::optional<std::string>(), boost::optional<std::string>(), false, false, true, window);
+ return;
+ }
+ } else {
+ handleJoinMUCRequest(invite->getJID(), boost::optional<std::string>(), boost::optional<std::string>(), false, false, true);
+ return;
+ }
+ }
+
+ //if not a mucroom
+ if (!event->isReadable() && !isInvite && !isMediatedInvite) {
+ /* Only route such messages if a window exists, don't open new windows for them.*/
+
+ // Do not bind a controller to a full JID, for delivery receipts or chat state notifications.
+ bool bindControllerToJID = false;
+ ChatState::ref chatState = message->getPayload<ChatState>();
+ if (!message->getBody().get_value_or("").empty() || (chatState && chatState->getChatState() == ChatState::Composing)) {
+ bindControllerToJID = true;
+ }
+
+ ChatController* controller = getChatControllerIfExists(jid, bindControllerToJID);
+ if (controller) {
+ controller->handleIncomingMessage(event);
+ }
+ } else {
+ getChatControllerOrCreate(jid)->handleIncomingMessage(event);
+ }
}
void ChatsManager::handleMUCSelectedAfterSearch(const JID& muc) {
- if (joinMUCWindow_) {
- joinMUCWindow_->setMUC(muc.toString());
- }
+ if (joinMUCWindow_) {
+ joinMUCWindow_->setMUC(muc.toString());
+ }
}
void ChatsManager::handleMUCBookmarkActivated(const MUCBookmark& mucBookmark) {
- uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(mucBookmark.getRoom(), mucBookmark.getPassword(), mucBookmark.getNick()));
+ uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(mucBookmark.getRoom(), mucBookmark.getPassword(), mucBookmark.getNick()));
}
void ChatsManager::handleNewFileTransferController(FileTransferController* ftc) {
- ChatController* chatController = getChatControllerOrCreate(ftc->getOtherParty());
- chatController->handleNewFileTransferController(ftc);
- chatController->activateChatWindow();
- if (ftc->isIncoming()) {
- eventController_->handleIncomingEvent(boost::make_shared<IncomingFileTransferEvent>(ftc->getOtherParty()));
- }
+ ChatController* chatController = getChatControllerOrCreate(ftc->getOtherParty());
+ chatController->handleNewFileTransferController(ftc);
+ chatController->activateChatWindow();
+ if (ftc->isIncoming()) {
+ eventController_->handleIncomingEvent(boost::make_shared<IncomingFileTransferEvent>(ftc->getOtherParty()));
+ }
}
void ChatsManager::handleWhiteboardSessionRequest(const JID& contact, bool senderIsSelf) {
- ChatController* chatController = getChatControllerOrCreate(contact);
- chatController->handleWhiteboardSessionRequest(senderIsSelf);
- chatController->activateChatWindow();
+ ChatController* chatController = getChatControllerOrCreate(contact);
+ chatController->handleWhiteboardSessionRequest(senderIsSelf);
+ chatController->activateChatWindow();
}
void ChatsManager::handleWhiteboardStateChange(const JID& contact, const ChatWindow::WhiteboardSessionState state) {
- ChatController* chatController = getChatControllerOrCreate(contact);
- chatController->handleWhiteboardStateChange(state);
- chatController->activateChatWindow();
- if (state == ChatWindow::WhiteboardAccepted) {
- boost::filesystem::path path;
- JID bareJID = contact.toBare();
- if (avatarManager_) {
- path = avatarManager_->getAvatarPath(bareJID);
- }
- ChatListWindow::Chat chat(bareJID, nickResolver_->jidToNick(bareJID), "", 0, StatusShow::None, path, false);
- chatListWindow_->addWhiteboardSession(chat);
- } else {
- chatListWindow_->removeWhiteboardSession(contact.toBare());
- }
+ ChatController* chatController = getChatControllerOrCreate(contact);
+ chatController->handleWhiteboardStateChange(state);
+ chatController->activateChatWindow();
+ if (state == ChatWindow::WhiteboardAccepted) {
+ boost::filesystem::path path;
+ JID bareJID = contact.toBare();
+ if (avatarManager_) {
+ path = avatarManager_->getAvatarPath(bareJID);
+ }
+ ChatListWindow::Chat chat(bareJID, nickResolver_->jidToNick(bareJID), "", 0, StatusShow::None, path, false);
+ chatListWindow_->addWhiteboardSession(chat);
+ } else {
+ chatListWindow_->removeWhiteboardSession(contact.toBare());
+ }
}
void ChatsManager::handleRecentActivated(const ChatListWindow::Chat& chat) {
- if (chat.isMUC && !chat.impromptuJIDs.empty()) {
- typedef std::pair<std::string, JID> StringJIDPair;
- std::vector<JID> inviteJIDs;
- foreach(StringJIDPair pair, chat.impromptuJIDs) {
- inviteJIDs.push_back(pair.second);
- }
- uiEventStream_->send(boost::make_shared<CreateImpromptuMUCUIEvent>(inviteJIDs, chat.jid, ""));
- }
- else if (chat.isMUC) {
- /* FIXME: This means that recents requiring passwords will just flat-out not work */
- uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(chat.jid, boost::optional<std::string>(), chat.nick));
- }
- else {
- uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(chat.jid));
- }
+ if (chat.isMUC && !chat.impromptuJIDs.empty()) {
+ typedef std::pair<std::string, JID> StringJIDPair;
+ std::vector<JID> inviteJIDs;
+ foreach(StringJIDPair pair, chat.impromptuJIDs) {
+ inviteJIDs.push_back(pair.second);
+ }
+ uiEventStream_->send(boost::make_shared<CreateImpromptuMUCUIEvent>(inviteJIDs, chat.jid, ""));
+ }
+ else if (chat.isMUC) {
+ /* FIXME: This means that recents requiring passwords will just flat-out not work */
+ uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(chat.jid, boost::optional<std::string>(), chat.nick));
+ }
+ else {
+ uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(chat.jid));
+ }
}
void ChatsManager::handleLocalServiceFound(const JID& service, boost::shared_ptr<DiscoInfo> info) {
- foreach (DiscoInfo::Identity identity, info->getIdentities()) {
- if ((identity.getCategory() == "directory"
- && identity.getType() == "chatroom")
- || (identity.getCategory() == "conference"
- && identity.getType() == "text")) {
- localMUCServiceJID_ = service;
- localMUCServiceFinderWalker_->endWalk();
- SWIFT_LOG(debug) << "Use following MUC service for impromptu chats: " << localMUCServiceJID_ << std::endl;
- break;
- }
- }
+ foreach (DiscoInfo::Identity identity, info->getIdentities()) {
+ if ((identity.getCategory() == "directory"
+ && identity.getType() == "chatroom")
+ || (identity.getCategory() == "conference"
+ && identity.getType() == "text")) {
+ localMUCServiceJID_ = service;
+ localMUCServiceFinderWalker_->endWalk();
+ SWIFT_LOG(debug) << "Use following MUC service for impromptu chats: " << localMUCServiceJID_ << std::endl;
+ break;
+ }
+ }
}
void ChatsManager::handleLocalServiceWalkFinished() {
- bool impromptuMUCSupported = !localMUCServiceJID_.toString().empty();
- foreach (JIDChatControllerPair controllerPair, chatControllers_) {
- controllerPair.second->setCanStartImpromptuChats(impromptuMUCSupported);
- }
- foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
- controllerPair.second->setCanStartImpromptuChats(impromptuMUCSupported);
- }
- onImpromptuMUCServiceDiscovered(impromptuMUCSupported);
+ bool impromptuMUCSupported = !localMUCServiceJID_.toString().empty();
+ foreach (JIDChatControllerPair controllerPair, chatControllers_) {
+ controllerPair.second->setCanStartImpromptuChats(impromptuMUCSupported);
+ }
+ foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
+ controllerPair.second->setCanStartImpromptuChats(impromptuMUCSupported);
+ }
+ onImpromptuMUCServiceDiscovered(impromptuMUCSupported);
}
std::vector<ChatListWindow::Chat> ChatsManager::getRecentChats() const {
- return std::vector<ChatListWindow::Chat>(recentChats_.begin(), recentChats_.end());
+ return std::vector<ChatListWindow::Chat>(recentChats_.begin(), recentChats_.end());
}
std::vector<Contact::ref> Swift::ChatsManager::getContacts(bool withMUCNicks) {
- std::vector<Contact::ref> result;
- foreach (ChatListWindow::Chat chat, recentChats_) {
- if (!chat.isMUC) {
- result.push_back(boost::make_shared<Contact>(chat.chatName.empty() ? chat.jid.toString() : chat.chatName, chat.jid, chat.statusType, chat.avatarPath));
- }
- }
- if (withMUCNicks) {
- /* collect MUC nicks */
- typedef std::map<JID, MUCController*>::value_type Item;
- foreach (const Item& item, mucControllers_) {
- JID mucJID = item.second->getToJID();
- std::map<std::string, JID> participants = item.second->getParticipantJIDs();
- typedef std::map<std::string, JID>::value_type ParticipantType;
- foreach (const ParticipantType& participant, participants) {
- const JID nickJID = JID(mucJID.getNode(), mucJID.getDomain(), participant.first);
- Presence::ref presence = presenceOracle_->getLastPresence(nickJID);
- const boost::filesystem::path avatar = avatarManager_->getAvatarPath(nickJID);
- result.push_back(boost::make_shared<Contact>(participant.first, JID(), presence->getShow(), avatar));
- }
- }
- }
- return result;
+ std::vector<Contact::ref> result;
+ foreach (ChatListWindow::Chat chat, recentChats_) {
+ if (!chat.isMUC) {
+ result.push_back(boost::make_shared<Contact>(chat.chatName.empty() ? chat.jid.toString() : chat.chatName, chat.jid, chat.statusType, chat.avatarPath));
+ }
+ }
+ if (withMUCNicks) {
+ /* collect MUC nicks */
+ typedef std::map<JID, MUCController*>::value_type Item;
+ foreach (const Item& item, mucControllers_) {
+ JID mucJID = item.second->getToJID();
+ std::map<std::string, JID> participants = item.second->getParticipantJIDs();
+ typedef std::map<std::string, JID>::value_type ParticipantType;
+ foreach (const ParticipantType& participant, participants) {
+ const JID nickJID = JID(mucJID.getNode(), mucJID.getDomain(), participant.first);
+ Presence::ref presence = presenceOracle_->getLastPresence(nickJID);
+ const boost::filesystem::path avatar = avatarManager_->getAvatarPath(nickJID);
+ result.push_back(boost::make_shared<Contact>(participant.first, JID(), presence->getShow(), avatar));
+ }
+ }
+ }
+ return result;
}
ChatsManager::SingleChatWindowFactoryAdapter::SingleChatWindowFactoryAdapter(ChatWindow* chatWindow) : chatWindow_(chatWindow) {}
ChatsManager::SingleChatWindowFactoryAdapter::~SingleChatWindowFactoryAdapter() {}
ChatWindow* ChatsManager::SingleChatWindowFactoryAdapter::createChatWindow(const JID &, UIEventStream*) {
- return chatWindow_;
+ return chatWindow_;
}
}
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index 58a9017..7bba219 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -27,159 +27,159 @@
#include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h>
namespace Swift {
- class EventController;
- class ChatController;
- class ChatControllerBase;
- class MUCController;
- class MUCManager;
- class JoinMUCWindow;
- class JoinMUCWindowFactory;
- class NickResolver;
- class PresenceOracle;
- class AvatarManager;
- class StanzaChannel;
- class IQRouter;
- class PresenceSender;
- class MUCBookmarkManager;
- class ChatListWindowFactory;
- class TimerFactory;
- class EntityCapsProvider;
- class DirectedPresenceSender;
- class MUCSearchWindowFactory;
- class ProfileSettingsProvider;
- class MUCSearchController;
- class FileTransferOverview;
- class FileTransferController;
- class XMPPRoster;
- class SettingsProvider;
- class WhiteboardManager;
- class HistoryController;
- class HighlightManager;
- class ClientBlockListManager;
- class ChatMessageParser;
- class DiscoServiceWalker;
- class AutoAcceptMUCInviteDecider;
- class VCardManager;
-
- class ChatsManager : public ContactProvider {
- public:
- ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, JoinMUCWindowFactory* joinMUCWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, PresenceSender* presenceSender, UIEventStream* uiEventStream, ChatListWindowFactory* chatListWindowFactory, bool useDelayForLatency, TimerFactory* timerFactory, MUCRegistry* mucRegistry, EntityCapsProvider* entityCapsProvider, MUCManager* mucManager, MUCSearchWindowFactory* mucSearchWindowFactory, ProfileSettingsProvider* profileSettings, FileTransferOverview* ftOverview, XMPPRoster* roster, bool eagleMode, SettingsProvider* settings, HistoryController* historyController_, WhiteboardManager* whiteboardManager, HighlightManager* highlightManager, ClientBlockListManager* clientBlockListManager, const std::map<std::string, std::string>& emoticons, VCardManager* vcardManager);
- virtual ~ChatsManager();
- void setAvatarManager(AvatarManager* avatarManager);
- void setOnline(bool enabled);
- void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
- void handleIncomingMessage(boost::shared_ptr<Message> message);
- std::vector<ChatListWindow::Chat> getRecentChats() const;
- virtual std::vector<Contact::ref> getContacts(bool withMUCNicks);
-
- boost::signal<void (bool supportsImpromptu)> onImpromptuMUCServiceDiscovered;
-
- private:
- class SingleChatWindowFactoryAdapter : public ChatWindowFactory {
- public:
- SingleChatWindowFactoryAdapter(ChatWindow* chatWindow);
- virtual ~SingleChatWindowFactoryAdapter();
- virtual ChatWindow* createChatWindow(const JID &, UIEventStream*);
-
- private:
- ChatWindow* chatWindow_;
- };
-
- private:
- ChatListWindow::Chat createChatListChatItem(const JID& jid, const std::string& activity, bool privateMessage);
- void handleChatRequest(const std::string& contact);
- void finalizeImpromptuJoin(MUC::ref muc, const std::vector<JID>& jidsToInvite, const std::string& reason, const boost::optional<JID>& reuseChatJID = boost::optional<JID>());
- MUC::ref handleJoinMUCRequest(const JID& muc, const boost::optional<std::string>& password, const boost::optional<std::string>& nick, bool addAutoJoin, bool createAsReservedIfNew, bool isImpromptu, ChatWindow* reuseChatwindow = 0);
- void handleSearchMUCRequest();
- void handleMUCSelectedAfterSearch(const JID&);
- void rebindControllerJID(const JID& from, const JID& to);
- void handlePresenceChange(boost::shared_ptr<Presence> newPresence);
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void handleMUCBookmarkAdded(const MUCBookmark& bookmark);
- void handleMUCBookmarkRemoved(const MUCBookmark& bookmark);
- void handleUserLeftMUC(MUCController* mucController);
- void handleUserNicknameChanged(MUCController* mucController, const std::string& oldNickname, const std::string& newNickname);
- void handleBookmarksReady();
- void handleChatActivity(const JID& jid, const std::string& activity, bool isMUC);
- void handleChatClosed(const JID& jid);
- void handleNewFileTransferController(FileTransferController*);
- void handleWhiteboardSessionRequest(const JID& contact, bool senderIsSelf);
- void handleWhiteboardStateChange(const JID& contact, const ChatWindow::WhiteboardSessionState state);
- boost::optional<ChatListWindow::Chat> removeExistingChat(const ChatListWindow::Chat& chat);
- void cleanupPrivateMessageRecents();
- void appendRecent(const ChatListWindow::Chat& chat);
- void prependRecent(const ChatListWindow::Chat& chat);
- void setupBookmarks();
- void loadRecents();
- void saveRecents();
- void handleChatMadeRecent();
- void handleMUCBookmarkActivated(const MUCBookmark&);
- void handleRecentActivated(const ChatListWindow::Chat&);
- void handleUnreadCountChanged(ChatControllerBase* controller);
- void handleAvatarChanged(const JID& jid);
- void handleClearRecentsRequested();
- void handleJIDAddedToRoster(const JID&);
- void handleJIDRemovedFromRoster(const JID&);
- void handleJIDUpdatedInRoster(const JID&);
- void handleRosterCleared();
- void handleSettingChanged(const std::string& settingPath);
- void markAllRecentsOffline();
- void handleTransformChatToMUC(ChatController* chatController, ChatWindow* chatWindow, const std::vector<JID>& jidsToInvite, const std::string& reason);
-
- void handleLocalServiceFound(const JID& service, boost::shared_ptr<DiscoInfo> info);
- void handleLocalServiceWalkFinished();
-
- void updatePresenceReceivingStateOnChatController(const JID&);
- ChatListWindow::Chat updateChatStatusAndAvatarHelper(const ChatListWindow::Chat& chat) const;
-
-
- ChatController* getChatControllerOrFindAnother(const JID &contact);
- ChatController* createNewChatController(const JID &contact);
- ChatController* getChatControllerOrCreate(const JID &contact);
- ChatController* getChatControllerIfExists(const JID &contact, bool rebindIfNeeded = true);
-
- private:
- std::map<JID, MUCController*> mucControllers_;
- std::map<JID, ChatController*> chatControllers_;
- std::map<ChatControllerBase*, SingleChatWindowFactoryAdapter*> chatWindowFactoryAdapters_;
- EventController* eventController_;
- JID jid_;
- StanzaChannel* stanzaChannel_;
- IQRouter* iqRouter_;
- ChatWindowFactory* chatWindowFactory_;
- JoinMUCWindowFactory* joinMUCWindowFactory_;
- NickResolver* nickResolver_;
- PresenceOracle* presenceOracle_;
- AvatarManager* avatarManager_;
- PresenceSender* presenceSender_;
- UIEventStream* uiEventStream_;
- MUCBookmarkManager* mucBookmarkManager_;
- boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
- ChatListWindow* chatListWindow_;
- JoinMUCWindow* joinMUCWindow_;
- boost::bsignals::scoped_connection uiEventConnection_;
- bool useDelayForLatency_;
- TimerFactory* timerFactory_;
- MUCRegistry* mucRegistry_;
- EntityCapsProvider* entityCapsProvider_;
- MUCManager* mucManager;
- MUCSearchController* mucSearchController_;
- std::list<ChatListWindow::Chat> recentChats_;
- ProfileSettingsProvider* profileSettings_;
- FileTransferOverview* ftOverview_;
- XMPPRoster* roster_;
- bool eagleMode_;
- bool userWantsReceipts_;
- SettingsProvider* settings_;
- HistoryController* historyController_;
- WhiteboardManager* whiteboardManager_;
- HighlightManager* highlightManager_;
- std::map<std::string, std::string> emoticons_;
- ClientBlockListManager* clientBlockListManager_;
- JID localMUCServiceJID_;
- boost::shared_ptr<DiscoServiceWalker> localMUCServiceFinderWalker_;
- AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider_;
- IDGenerator idGenerator_;
- VCardManager* vcardManager_;
- };
+ class EventController;
+ class ChatController;
+ class ChatControllerBase;
+ class MUCController;
+ class MUCManager;
+ class JoinMUCWindow;
+ class JoinMUCWindowFactory;
+ class NickResolver;
+ class PresenceOracle;
+ class AvatarManager;
+ class StanzaChannel;
+ class IQRouter;
+ class PresenceSender;
+ class MUCBookmarkManager;
+ class ChatListWindowFactory;
+ class TimerFactory;
+ class EntityCapsProvider;
+ class DirectedPresenceSender;
+ class MUCSearchWindowFactory;
+ class ProfileSettingsProvider;
+ class MUCSearchController;
+ class FileTransferOverview;
+ class FileTransferController;
+ class XMPPRoster;
+ class SettingsProvider;
+ class WhiteboardManager;
+ class HistoryController;
+ class HighlightManager;
+ class ClientBlockListManager;
+ class ChatMessageParser;
+ class DiscoServiceWalker;
+ class AutoAcceptMUCInviteDecider;
+ class VCardManager;
+
+ class ChatsManager : public ContactProvider {
+ public:
+ ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, JoinMUCWindowFactory* joinMUCWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, PresenceSender* presenceSender, UIEventStream* uiEventStream, ChatListWindowFactory* chatListWindowFactory, bool useDelayForLatency, TimerFactory* timerFactory, MUCRegistry* mucRegistry, EntityCapsProvider* entityCapsProvider, MUCManager* mucManager, MUCSearchWindowFactory* mucSearchWindowFactory, ProfileSettingsProvider* profileSettings, FileTransferOverview* ftOverview, XMPPRoster* roster, bool eagleMode, SettingsProvider* settings, HistoryController* historyController_, WhiteboardManager* whiteboardManager, HighlightManager* highlightManager, ClientBlockListManager* clientBlockListManager, const std::map<std::string, std::string>& emoticons, VCardManager* vcardManager);
+ virtual ~ChatsManager();
+ void setAvatarManager(AvatarManager* avatarManager);
+ void setOnline(bool enabled);
+ void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
+ void handleIncomingMessage(boost::shared_ptr<Message> message);
+ std::vector<ChatListWindow::Chat> getRecentChats() const;
+ virtual std::vector<Contact::ref> getContacts(bool withMUCNicks);
+
+ boost::signal<void (bool supportsImpromptu)> onImpromptuMUCServiceDiscovered;
+
+ private:
+ class SingleChatWindowFactoryAdapter : public ChatWindowFactory {
+ public:
+ SingleChatWindowFactoryAdapter(ChatWindow* chatWindow);
+ virtual ~SingleChatWindowFactoryAdapter();
+ virtual ChatWindow* createChatWindow(const JID &, UIEventStream*);
+
+ private:
+ ChatWindow* chatWindow_;
+ };
+
+ private:
+ ChatListWindow::Chat createChatListChatItem(const JID& jid, const std::string& activity, bool privateMessage);
+ void handleChatRequest(const std::string& contact);
+ void finalizeImpromptuJoin(MUC::ref muc, const std::vector<JID>& jidsToInvite, const std::string& reason, const boost::optional<JID>& reuseChatJID = boost::optional<JID>());
+ MUC::ref handleJoinMUCRequest(const JID& muc, const boost::optional<std::string>& password, const boost::optional<std::string>& nick, bool addAutoJoin, bool createAsReservedIfNew, bool isImpromptu, ChatWindow* reuseChatwindow = 0);
+ void handleSearchMUCRequest();
+ void handleMUCSelectedAfterSearch(const JID&);
+ void rebindControllerJID(const JID& from, const JID& to);
+ void handlePresenceChange(boost::shared_ptr<Presence> newPresence);
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleMUCBookmarkAdded(const MUCBookmark& bookmark);
+ void handleMUCBookmarkRemoved(const MUCBookmark& bookmark);
+ void handleUserLeftMUC(MUCController* mucController);
+ void handleUserNicknameChanged(MUCController* mucController, const std::string& oldNickname, const std::string& newNickname);
+ void handleBookmarksReady();
+ void handleChatActivity(const JID& jid, const std::string& activity, bool isMUC);
+ void handleChatClosed(const JID& jid);
+ void handleNewFileTransferController(FileTransferController*);
+ void handleWhiteboardSessionRequest(const JID& contact, bool senderIsSelf);
+ void handleWhiteboardStateChange(const JID& contact, const ChatWindow::WhiteboardSessionState state);
+ boost::optional<ChatListWindow::Chat> removeExistingChat(const ChatListWindow::Chat& chat);
+ void cleanupPrivateMessageRecents();
+ void appendRecent(const ChatListWindow::Chat& chat);
+ void prependRecent(const ChatListWindow::Chat& chat);
+ void setupBookmarks();
+ void loadRecents();
+ void saveRecents();
+ void handleChatMadeRecent();
+ void handleMUCBookmarkActivated(const MUCBookmark&);
+ void handleRecentActivated(const ChatListWindow::Chat&);
+ void handleUnreadCountChanged(ChatControllerBase* controller);
+ void handleAvatarChanged(const JID& jid);
+ void handleClearRecentsRequested();
+ void handleJIDAddedToRoster(const JID&);
+ void handleJIDRemovedFromRoster(const JID&);
+ void handleJIDUpdatedInRoster(const JID&);
+ void handleRosterCleared();
+ void handleSettingChanged(const std::string& settingPath);
+ void markAllRecentsOffline();
+ void handleTransformChatToMUC(ChatController* chatController, ChatWindow* chatWindow, const std::vector<JID>& jidsToInvite, const std::string& reason);
+
+ void handleLocalServiceFound(const JID& service, boost::shared_ptr<DiscoInfo> info);
+ void handleLocalServiceWalkFinished();
+
+ void updatePresenceReceivingStateOnChatController(const JID&);
+ ChatListWindow::Chat updateChatStatusAndAvatarHelper(const ChatListWindow::Chat& chat) const;
+
+
+ ChatController* getChatControllerOrFindAnother(const JID &contact);
+ ChatController* createNewChatController(const JID &contact);
+ ChatController* getChatControllerOrCreate(const JID &contact);
+ ChatController* getChatControllerIfExists(const JID &contact, bool rebindIfNeeded = true);
+
+ private:
+ std::map<JID, MUCController*> mucControllers_;
+ std::map<JID, ChatController*> chatControllers_;
+ std::map<ChatControllerBase*, SingleChatWindowFactoryAdapter*> chatWindowFactoryAdapters_;
+ EventController* eventController_;
+ JID jid_;
+ StanzaChannel* stanzaChannel_;
+ IQRouter* iqRouter_;
+ ChatWindowFactory* chatWindowFactory_;
+ JoinMUCWindowFactory* joinMUCWindowFactory_;
+ NickResolver* nickResolver_;
+ PresenceOracle* presenceOracle_;
+ AvatarManager* avatarManager_;
+ PresenceSender* presenceSender_;
+ UIEventStream* uiEventStream_;
+ MUCBookmarkManager* mucBookmarkManager_;
+ boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
+ ChatListWindow* chatListWindow_;
+ JoinMUCWindow* joinMUCWindow_;
+ boost::bsignals::scoped_connection uiEventConnection_;
+ bool useDelayForLatency_;
+ TimerFactory* timerFactory_;
+ MUCRegistry* mucRegistry_;
+ EntityCapsProvider* entityCapsProvider_;
+ MUCManager* mucManager;
+ MUCSearchController* mucSearchController_;
+ std::list<ChatListWindow::Chat> recentChats_;
+ ProfileSettingsProvider* profileSettings_;
+ FileTransferOverview* ftOverview_;
+ XMPPRoster* roster_;
+ bool eagleMode_;
+ bool userWantsReceipts_;
+ SettingsProvider* settings_;
+ HistoryController* historyController_;
+ WhiteboardManager* whiteboardManager_;
+ HighlightManager* highlightManager_;
+ std::map<std::string, std::string> emoticons_;
+ ClientBlockListManager* clientBlockListManager_;
+ JID localMUCServiceJID_;
+ boost::shared_ptr<DiscoServiceWalker> localMUCServiceFinderWalker_;
+ AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider_;
+ IDGenerator idGenerator_;
+ VCardManager* vcardManager_;
+ };
}
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 0bb670d..1e2b7ad 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -58,1163 +58,1163 @@
namespace Swift {
class MUCBookmarkPredicate {
- public:
- MUCBookmarkPredicate(const JID& mucJID) : roomJID_(mucJID) { }
- bool operator()(const MUCBookmark& operand) {
- return operand.getRoom() == roomJID_;
- }
-
- private:
- JID roomJID_;
+ public:
+ MUCBookmarkPredicate(const JID& mucJID) : roomJID_(mucJID) { }
+ bool operator()(const MUCBookmark& operand) {
+ return operand.getRoom() == roomJID_;
+ }
+
+ private:
+ JID roomJID_;
};
/**
* The controller does not gain ownership of the stanzaChannel, nor the factory.
*/
MUCController::MUCController (
- const JID& self,
- MUC::ref muc,
- const boost::optional<std::string>& password,
- const std::string &nick,
- StanzaChannel* stanzaChannel,
- IQRouter* iqRouter,
- ChatWindowFactory* chatWindowFactory,
- PresenceOracle* presenceOracle,
- AvatarManager* avatarManager,
- UIEventStream* uiEventStream,
- bool useDelayForLatency,
- TimerFactory* timerFactory,
- EventController* eventController,
- EntityCapsProvider* entityCapsProvider,
- XMPPRoster* roster,
- HistoryController* historyController,
- MUCRegistry* mucRegistry,
- HighlightManager* highlightManager,
- ClientBlockListManager* clientBlockListManager,
- boost::shared_ptr<ChatMessageParser> chatMessageParser,
- bool isImpromptu,
- AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider,
- VCardManager* vcardManager,
- MUCBookmarkManager* mucBookmarkManager) :
- ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, muc->getJID(), presenceOracle, avatarManager, useDelayForLatency, uiEventStream, eventController, timerFactory, entityCapsProvider, historyController, mucRegistry, highlightManager, chatMessageParser, autoAcceptMUCInviteDecider), muc_(muc), nick_(nick), desiredNick_(nick), password_(password), renameCounter_(0), isImpromptu_(isImpromptu), isImpromptuAlreadyConfigured_(false), clientBlockListManager_(clientBlockListManager), mucBookmarkManager_(mucBookmarkManager) {
- parting_ = true;
- joined_ = false;
- lastWasPresence_ = false;
- shouldJoinOnReconnect_ = true;
- doneGettingHistory_ = false;
- events_ = uiEventStream;
- xmppRoster_ = roster;
-
- roster_ = new Roster(false, true);
- rosterVCardProvider_ = new RosterVCardProvider(roster_, vcardManager, JID::WithResource);
- completer_ = new TabComplete();
- chatWindow_->setRosterModel(roster_);
- chatWindow_->setTabComplete(completer_);
- chatWindow_->onClosed.connect(boost::bind(&MUCController::handleWindowClosed, this));
- chatWindow_->onOccupantSelectionChanged.connect(boost::bind(&MUCController::handleWindowOccupantSelectionChanged, this, _1));
- chatWindow_->onOccupantActionSelected.connect(boost::bind(&MUCController::handleActionRequestedOnOccupant, this, _1, _2));
- chatWindow_->onChangeSubjectRequest.connect(boost::bind(&MUCController::handleChangeSubjectRequest, this, _1));
- chatWindow_->onBookmarkRequest.connect(boost::bind(&MUCController::handleBookmarkRequest, this));
- chatWindow_->onConfigureRequest.connect(boost::bind(&MUCController::handleConfigureRequest, this, _1));
- chatWindow_->onConfigurationFormCancelled.connect(boost::bind(&MUCController::handleConfigurationCancelled, this));
- chatWindow_->onDestroyRequest.connect(boost::bind(&MUCController::handleDestroyRoomRequest, this));
- chatWindow_->onInviteToChat.connect(boost::bind(&MUCController::handleInvitePersonToThisMUCRequest, this, _1));
- chatWindow_->onGetAffiliationsRequest.connect(boost::bind(&MUCController::handleGetAffiliationsRequest, this));
- chatWindow_->onChangeAffiliationsRequest.connect(boost::bind(&MUCController::handleChangeAffiliationsRequest, this, _1));
- chatWindow_->onUnblockUserRequest.connect(boost::bind(&MUCController::handleUnblockUserRequest, this));
- muc_->onJoinComplete.connect(boost::bind(&MUCController::handleJoinComplete, this, _1));
- muc_->onJoinFailed.connect(boost::bind(&MUCController::handleJoinFailed, this, _1));
- muc_->onOccupantJoined.connect(boost::bind(&MUCController::handleOccupantJoined, this, _1));
- muc_->onOccupantNicknameChanged.connect(boost::bind(&MUCController::handleOccupantNicknameChanged, this, _1, _2));
- muc_->onOccupantPresenceChange.connect(boost::bind(&MUCController::handleOccupantPresenceChange, this, _1));
- muc_->onOccupantLeft.connect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
- muc_->onRoleChangeFailed.connect(boost::bind(&MUCController::handleOccupantRoleChangeFailed, this, _1, _2, _3));
- muc_->onAffiliationListReceived.connect(boost::bind(&MUCController::handleAffiliationListReceived, this, _1, _2));
- muc_->onConfigurationFailed.connect(boost::bind(&MUCController::handleConfigurationFailed, this, _1));
- muc_->onConfigurationFormReceived.connect(boost::bind(&MUCController::handleConfigurationFormReceived, this, _1));
- highlighter_->setMode(isImpromptu_ ? Highlighter::ChatMode : Highlighter::MUCMode);
- highlighter_->setNick(nick_);
- if (timerFactory && stanzaChannel_->isAvailable()) {
- loginCheckTimer_ = boost::shared_ptr<Timer>(timerFactory->createTimer(MUC_JOIN_WARNING_TIMEOUT_MILLISECONDS));
- loginCheckTimer_->onTick.connect(boost::bind(&MUCController::handleJoinTimeoutTick, this));
- loginCheckTimer_->start();
- }
- else {
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "You are currently offline. You will enter this room when you are connected.")), ChatWindow::DefaultDirection);
- }
- if (isImpromptu) {
- muc_->onUnlocked.connect(boost::bind(&MUCController::handleRoomUnlocked, this));
- chatWindow_->convertToMUC(ChatWindow::ImpromptuMUC);
- } else {
- muc_->onOccupantRoleChanged.connect(boost::bind(&MUCController::handleOccupantRoleChanged, this, _1, _2, _3));
- muc_->onOccupantAffiliationChanged.connect(boost::bind(&MUCController::handleOccupantAffiliationChanged, this, _1, _2, _3));
- chatWindow_->convertToMUC(ChatWindow::StandardMUC);
- chatWindow_->setName(muc->getJID().getNode());
- }
- if (stanzaChannel->isAvailable()) {
- MUCController::setOnline(true);
- }
- if (avatarManager_ != NULL) {
- avatarChangedConnection_ = (avatarManager_->onAvatarChanged.connect(boost::bind(&MUCController::handleAvatarChanged, this, _1)));
- }
- MUCController::handleBareJIDCapsChanged(muc->getJID());
- eventStream_->onUIEvent.connect(boost::bind(&MUCController::handleUIEvent, this, _1));
-
-
- // setup handling of MUC bookmark changes
- mucBookmarkManagerBookmarkAddedConnection_ = (mucBookmarkManager_->onBookmarkAdded.connect(boost::bind(&MUCController::handleMUCBookmarkAdded, this, _1)));
- mucBookmarkManagerBookmarkRemovedConnection_ = (mucBookmarkManager_->onBookmarkRemoved.connect(boost::bind(&MUCController::handleMUCBookmarkRemoved, this, _1)));
-
- std::vector<MUCBookmark> mucBookmarks = mucBookmarkManager_->getBookmarks();
- std::vector<MUCBookmark>::iterator bookmarkIterator = std::find_if(mucBookmarks.begin(), mucBookmarks.end(), MUCBookmarkPredicate(muc->getJID()));
- if (bookmarkIterator != mucBookmarks.end()) {
- updateChatWindowBookmarkStatus(*bookmarkIterator);
- }
- else {
- updateChatWindowBookmarkStatus(boost::optional<MUCBookmark>());
- }
+ const JID& self,
+ MUC::ref muc,
+ const boost::optional<std::string>& password,
+ const std::string &nick,
+ StanzaChannel* stanzaChannel,
+ IQRouter* iqRouter,
+ ChatWindowFactory* chatWindowFactory,
+ PresenceOracle* presenceOracle,
+ AvatarManager* avatarManager,
+ UIEventStream* uiEventStream,
+ bool useDelayForLatency,
+ TimerFactory* timerFactory,
+ EventController* eventController,
+ EntityCapsProvider* entityCapsProvider,
+ XMPPRoster* roster,
+ HistoryController* historyController,
+ MUCRegistry* mucRegistry,
+ HighlightManager* highlightManager,
+ ClientBlockListManager* clientBlockListManager,
+ boost::shared_ptr<ChatMessageParser> chatMessageParser,
+ bool isImpromptu,
+ AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider,
+ VCardManager* vcardManager,
+ MUCBookmarkManager* mucBookmarkManager) :
+ ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, muc->getJID(), presenceOracle, avatarManager, useDelayForLatency, uiEventStream, eventController, timerFactory, entityCapsProvider, historyController, mucRegistry, highlightManager, chatMessageParser, autoAcceptMUCInviteDecider), muc_(muc), nick_(nick), desiredNick_(nick), password_(password), renameCounter_(0), isImpromptu_(isImpromptu), isImpromptuAlreadyConfigured_(false), clientBlockListManager_(clientBlockListManager), mucBookmarkManager_(mucBookmarkManager) {
+ parting_ = true;
+ joined_ = false;
+ lastWasPresence_ = false;
+ shouldJoinOnReconnect_ = true;
+ doneGettingHistory_ = false;
+ events_ = uiEventStream;
+ xmppRoster_ = roster;
+
+ roster_ = new Roster(false, true);
+ rosterVCardProvider_ = new RosterVCardProvider(roster_, vcardManager, JID::WithResource);
+ completer_ = new TabComplete();
+ chatWindow_->setRosterModel(roster_);
+ chatWindow_->setTabComplete(completer_);
+ chatWindow_->onClosed.connect(boost::bind(&MUCController::handleWindowClosed, this));
+ chatWindow_->onOccupantSelectionChanged.connect(boost::bind(&MUCController::handleWindowOccupantSelectionChanged, this, _1));
+ chatWindow_->onOccupantActionSelected.connect(boost::bind(&MUCController::handleActionRequestedOnOccupant, this, _1, _2));
+ chatWindow_->onChangeSubjectRequest.connect(boost::bind(&MUCController::handleChangeSubjectRequest, this, _1));
+ chatWindow_->onBookmarkRequest.connect(boost::bind(&MUCController::handleBookmarkRequest, this));
+ chatWindow_->onConfigureRequest.connect(boost::bind(&MUCController::handleConfigureRequest, this, _1));
+ chatWindow_->onConfigurationFormCancelled.connect(boost::bind(&MUCController::handleConfigurationCancelled, this));
+ chatWindow_->onDestroyRequest.connect(boost::bind(&MUCController::handleDestroyRoomRequest, this));
+ chatWindow_->onInviteToChat.connect(boost::bind(&MUCController::handleInvitePersonToThisMUCRequest, this, _1));
+ chatWindow_->onGetAffiliationsRequest.connect(boost::bind(&MUCController::handleGetAffiliationsRequest, this));
+ chatWindow_->onChangeAffiliationsRequest.connect(boost::bind(&MUCController::handleChangeAffiliationsRequest, this, _1));
+ chatWindow_->onUnblockUserRequest.connect(boost::bind(&MUCController::handleUnblockUserRequest, this));
+ muc_->onJoinComplete.connect(boost::bind(&MUCController::handleJoinComplete, this, _1));
+ muc_->onJoinFailed.connect(boost::bind(&MUCController::handleJoinFailed, this, _1));
+ muc_->onOccupantJoined.connect(boost::bind(&MUCController::handleOccupantJoined, this, _1));
+ muc_->onOccupantNicknameChanged.connect(boost::bind(&MUCController::handleOccupantNicknameChanged, this, _1, _2));
+ muc_->onOccupantPresenceChange.connect(boost::bind(&MUCController::handleOccupantPresenceChange, this, _1));
+ muc_->onOccupantLeft.connect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
+ muc_->onRoleChangeFailed.connect(boost::bind(&MUCController::handleOccupantRoleChangeFailed, this, _1, _2, _3));
+ muc_->onAffiliationListReceived.connect(boost::bind(&MUCController::handleAffiliationListReceived, this, _1, _2));
+ muc_->onConfigurationFailed.connect(boost::bind(&MUCController::handleConfigurationFailed, this, _1));
+ muc_->onConfigurationFormReceived.connect(boost::bind(&MUCController::handleConfigurationFormReceived, this, _1));
+ highlighter_->setMode(isImpromptu_ ? Highlighter::ChatMode : Highlighter::MUCMode);
+ highlighter_->setNick(nick_);
+ if (timerFactory && stanzaChannel_->isAvailable()) {
+ loginCheckTimer_ = boost::shared_ptr<Timer>(timerFactory->createTimer(MUC_JOIN_WARNING_TIMEOUT_MILLISECONDS));
+ loginCheckTimer_->onTick.connect(boost::bind(&MUCController::handleJoinTimeoutTick, this));
+ loginCheckTimer_->start();
+ }
+ else {
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "You are currently offline. You will enter this room when you are connected.")), ChatWindow::DefaultDirection);
+ }
+ if (isImpromptu) {
+ muc_->onUnlocked.connect(boost::bind(&MUCController::handleRoomUnlocked, this));
+ chatWindow_->convertToMUC(ChatWindow::ImpromptuMUC);
+ } else {
+ muc_->onOccupantRoleChanged.connect(boost::bind(&MUCController::handleOccupantRoleChanged, this, _1, _2, _3));
+ muc_->onOccupantAffiliationChanged.connect(boost::bind(&MUCController::handleOccupantAffiliationChanged, this, _1, _2, _3));
+ chatWindow_->convertToMUC(ChatWindow::StandardMUC);
+ chatWindow_->setName(muc->getJID().getNode());
+ }
+ if (stanzaChannel->isAvailable()) {
+ MUCController::setOnline(true);
+ }
+ if (avatarManager_ != NULL) {
+ avatarChangedConnection_ = (avatarManager_->onAvatarChanged.connect(boost::bind(&MUCController::handleAvatarChanged, this, _1)));
+ }
+ MUCController::handleBareJIDCapsChanged(muc->getJID());
+ eventStream_->onUIEvent.connect(boost::bind(&MUCController::handleUIEvent, this, _1));
+
+
+ // setup handling of MUC bookmark changes
+ mucBookmarkManagerBookmarkAddedConnection_ = (mucBookmarkManager_->onBookmarkAdded.connect(boost::bind(&MUCController::handleMUCBookmarkAdded, this, _1)));
+ mucBookmarkManagerBookmarkRemovedConnection_ = (mucBookmarkManager_->onBookmarkRemoved.connect(boost::bind(&MUCController::handleMUCBookmarkRemoved, this, _1)));
+
+ std::vector<MUCBookmark> mucBookmarks = mucBookmarkManager_->getBookmarks();
+ std::vector<MUCBookmark>::iterator bookmarkIterator = std::find_if(mucBookmarks.begin(), mucBookmarks.end(), MUCBookmarkPredicate(muc->getJID()));
+ if (bookmarkIterator != mucBookmarks.end()) {
+ updateChatWindowBookmarkStatus(*bookmarkIterator);
+ }
+ else {
+ updateChatWindowBookmarkStatus(boost::optional<MUCBookmark>());
+ }
}
MUCController::~MUCController() {
- eventStream_->onUIEvent.disconnect(boost::bind(&MUCController::handleUIEvent, this, _1));
- chatWindow_->setRosterModel(NULL);
- delete rosterVCardProvider_;
- delete roster_;
- if (loginCheckTimer_) {
- loginCheckTimer_->stop();
- }
- chatWindow_->setTabComplete(NULL);
- delete completer_;
+ eventStream_->onUIEvent.disconnect(boost::bind(&MUCController::handleUIEvent, this, _1));
+ chatWindow_->setRosterModel(NULL);
+ delete rosterVCardProvider_;
+ delete roster_;
+ if (loginCheckTimer_) {
+ loginCheckTimer_->stop();
+ }
+ chatWindow_->setTabComplete(NULL);
+ delete completer_;
}
void MUCController::cancelReplaces() {
- lastWasPresence_ = false;
+ lastWasPresence_ = false;
}
void MUCController::handleWindowOccupantSelectionChanged(ContactRosterItem* item) {
- std::vector<ChatWindow::OccupantAction> actions;
-
- if (item) {
- MUCOccupant::Affiliation affiliation = muc_->getOccupant(getNick()).getAffiliation();
- MUCOccupant::Role role = muc_->getOccupant(getNick()).getRole();
- if (role == MUCOccupant::Moderator && !isImpromptu_)
- {
- if (affiliation == MUCOccupant::Admin || affiliation == MUCOccupant::Owner) {
- actions.push_back(ChatWindow::Ban);
- }
-
- actions.push_back(ChatWindow::Kick);
- actions.push_back(ChatWindow::MakeModerator);
- actions.push_back(ChatWindow::MakeParticipant);
- actions.push_back(ChatWindow::MakeVisitor);
- }
- // Add contact is available only if the real JID is also available
- if (muc_->getOccupant(item->getJID().getResource()).getRealJID()) {
- actions.push_back(ChatWindow::AddContact);
- }
- actions.push_back(ChatWindow::ShowProfile);
- }
- chatWindow_->setAvailableOccupantActions(actions);
+ std::vector<ChatWindow::OccupantAction> actions;
+
+ if (item) {
+ MUCOccupant::Affiliation affiliation = muc_->getOccupant(getNick()).getAffiliation();
+ MUCOccupant::Role role = muc_->getOccupant(getNick()).getRole();
+ if (role == MUCOccupant::Moderator && !isImpromptu_)
+ {
+ if (affiliation == MUCOccupant::Admin || affiliation == MUCOccupant::Owner) {
+ actions.push_back(ChatWindow::Ban);
+ }
+
+ actions.push_back(ChatWindow::Kick);
+ actions.push_back(ChatWindow::MakeModerator);
+ actions.push_back(ChatWindow::MakeParticipant);
+ actions.push_back(ChatWindow::MakeVisitor);
+ }
+ // Add contact is available only if the real JID is also available
+ if (muc_->getOccupant(item->getJID().getResource()).getRealJID()) {
+ actions.push_back(ChatWindow::AddContact);
+ }
+ actions.push_back(ChatWindow::ShowProfile);
+ }
+ chatWindow_->setAvailableOccupantActions(actions);
}
void MUCController::handleActionRequestedOnOccupant(ChatWindow::OccupantAction action, ContactRosterItem* item) {
- JID mucJID = item->getJID();
- MUCOccupant occupant = muc_->getOccupant(mucJID.getResource());
- JID realJID;
- if (occupant.getRealJID()) {
- realJID = occupant.getRealJID().get();
- }
- switch (action) {
- case ChatWindow::Kick: muc_->kickOccupant(mucJID);break;
- case ChatWindow::Ban: muc_->changeAffiliation(realJID, MUCOccupant::Outcast);break;
- case ChatWindow::MakeModerator: muc_->changeOccupantRole(mucJID, MUCOccupant::Moderator);break;
- case ChatWindow::MakeParticipant: muc_->changeOccupantRole(mucJID, MUCOccupant::Participant);break;
- case ChatWindow::MakeVisitor: muc_->changeOccupantRole(mucJID, MUCOccupant::Visitor);break;
- case ChatWindow::AddContact: if (occupant.getRealJID()) events_->send(boost::make_shared<RequestAddUserDialogUIEvent>(realJID, occupant.getNick()));break;
- case ChatWindow::ShowProfile: events_->send(boost::make_shared<ShowProfileForRosterItemUIEvent>(mucJID));break;
- }
+ JID mucJID = item->getJID();
+ MUCOccupant occupant = muc_->getOccupant(mucJID.getResource());
+ JID realJID;
+ if (occupant.getRealJID()) {
+ realJID = occupant.getRealJID().get();
+ }
+ switch (action) {
+ case ChatWindow::Kick: muc_->kickOccupant(mucJID);break;
+ case ChatWindow::Ban: muc_->changeAffiliation(realJID, MUCOccupant::Outcast);break;
+ case ChatWindow::MakeModerator: muc_->changeOccupantRole(mucJID, MUCOccupant::Moderator);break;
+ case ChatWindow::MakeParticipant: muc_->changeOccupantRole(mucJID, MUCOccupant::Participant);break;
+ case ChatWindow::MakeVisitor: muc_->changeOccupantRole(mucJID, MUCOccupant::Visitor);break;
+ case ChatWindow::AddContact: if (occupant.getRealJID()) events_->send(boost::make_shared<RequestAddUserDialogUIEvent>(realJID, occupant.getNick()));break;
+ case ChatWindow::ShowProfile: events_->send(boost::make_shared<ShowProfileForRosterItemUIEvent>(mucJID));break;
+ }
}
void MUCController::handleBareJIDCapsChanged(const JID& /*jid*/) {
- Tristate support = Yes;
- bool any = false;
- foreach (const std::string& nick, currentOccupants_) {
- DiscoInfo::ref disco = entityCapsProvider_->getCaps(toJID_.toBare().toString() + "/" + nick);
- if (disco && disco->hasFeature(DiscoInfo::MessageCorrectionFeature)) {
- any = true;
- } else {
- support = Maybe;
- }
- }
- if (!any) {
- support = No;
- }
- chatWindow_->setCorrectionEnabled(support);
+ Tristate support = Yes;
+ bool any = false;
+ foreach (const std::string& nick, currentOccupants_) {
+ DiscoInfo::ref disco = entityCapsProvider_->getCaps(toJID_.toBare().toString() + "/" + nick);
+ if (disco && disco->hasFeature(DiscoInfo::MessageCorrectionFeature)) {
+ any = true;
+ } else {
+ support = Maybe;
+ }
+ }
+ if (!any) {
+ support = No;
+ }
+ chatWindow_->setCorrectionEnabled(support);
}
/**
* Join the MUC if not already in it.
*/
void MUCController::rejoin() {
- if (parting_) {
- joined_ = false;
- parting_ = false;
- if (password_) {
- muc_->setPassword(*password_);
- }
- //FIXME: check for received activity
+ if (parting_) {
+ joined_ = false;
+ parting_ = false;
+ if (password_) {
+ muc_->setPassword(*password_);
+ }
+ //FIXME: check for received activity
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- if (lastActivity_ == boost::posix_time::not_a_date_time && historyController_) {
- lastActivity_ = historyController_->getLastTimeStampFromMUC(selfJID_, toJID_);
- }
+ if (lastActivity_ == boost::posix_time::not_a_date_time && historyController_) {
+ lastActivity_ = historyController_->getLastTimeStampFromMUC(selfJID_, toJID_);
+ }
#endif
- if (lastActivity_ == boost::posix_time::not_a_date_time) {
- muc_->joinAs(nick_);
- }
- else {
- muc_->joinWithContextSince(nick_, lastActivity_);
- }
- }
+ if (lastActivity_ == boost::posix_time::not_a_date_time) {
+ muc_->joinAs(nick_);
+ }
+ else {
+ muc_->joinWithContextSince(nick_, lastActivity_);
+ }
+ }
}
bool MUCController::isJoined() {
- return joined_;
+ return joined_;
}
const std::string& MUCController::getNick() {
- return nick_;
+ return nick_;
}
const boost::optional<std::string> MUCController::getPassword() const {
- return password_;
+ return password_;
}
bool MUCController::isImpromptu() const {
- return isImpromptu_;
+ return isImpromptu_;
}
std::map<std::string, JID> MUCController::getParticipantJIDs() const {
- std::map<std::string, JID> participants;
- typedef std::pair<std::string, MUCOccupant> MUCOccupantPair;
- std::map<std::string, MUCOccupant> occupants = muc_->getOccupants();
- foreach(const MUCOccupantPair& occupant, occupants) {
- if (occupant.first != nick_) {
- participants[occupant.first] = occupant.second.getRealJID().is_initialized() ? occupant.second.getRealJID().get().toBare() : JID();
- }
- }
- return participants;
+ std::map<std::string, JID> participants;
+ typedef std::pair<std::string, MUCOccupant> MUCOccupantPair;
+ std::map<std::string, MUCOccupant> occupants = muc_->getOccupants();
+ foreach(const MUCOccupantPair& occupant, occupants) {
+ if (occupant.first != nick_) {
+ participants[occupant.first] = occupant.second.getRealJID().is_initialized() ? occupant.second.getRealJID().get().toBare() : JID();
+ }
+ }
+ return participants;
}
void MUCController::sendInvites(const std::vector<JID>& jids, const std::string& reason) const {
- foreach (const JID& jid, jids) {
- muc_->invitePerson(jid, reason, isImpromptu_);
- }
+ foreach (const JID& jid, jids) {
+ muc_->invitePerson(jid, reason, isImpromptu_);
+ }
}
void MUCController::handleJoinTimeoutTick() {
- receivedActivity();
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "Room %1% is not responding. This operation may never complete.")) % toJID_.toString())), ChatWindow::DefaultDirection);
+ receivedActivity();
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "Room %1% is not responding. This operation may never complete.")) % toJID_.toString())), ChatWindow::DefaultDirection);
}
void MUCController::receivedActivity() {
- if (loginCheckTimer_) {
- loginCheckTimer_->stop();
- }
+ if (loginCheckTimer_) {
+ loginCheckTimer_->stop();
+ }
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wswitch-enum"
void MUCController::handleJoinFailed(boost::shared_ptr<ErrorPayload> error) {
- receivedActivity();
- std::string errorMessage = QT_TRANSLATE_NOOP("", "Unable to enter this room");
- std::string rejoinNick;
- if (error) {
- switch (error->getCondition()) {
- case ErrorPayload::Conflict:
- rejoinNick = nick_ + "_";
- errorMessage = str(format(QT_TRANSLATE_NOOP("", "Unable to enter this room as %1%, retrying as %2%")) % nick_ % rejoinNick);
- break;
- case ErrorPayload::JIDMalformed:
- errorMessage += ": ";
- errorMessage += QT_TRANSLATE_NOOP("", "No nickname specified");
- break;
- case ErrorPayload::NotAuthorized:
- errorMessage += ": ";
- errorMessage += QT_TRANSLATE_NOOP("", "The correct room password is needed");
- break;
- case ErrorPayload::RegistrationRequired:
- errorMessage += ": ";
- errorMessage += QT_TRANSLATE_NOOP("", "Only members may enter");
- break;
- case ErrorPayload::Forbidden:
- errorMessage += ": ";
- errorMessage += QT_TRANSLATE_NOOP("", "You are banned from the room");
- break;
- case ErrorPayload::ServiceUnavailable:
- errorMessage += ": ";
- errorMessage += QT_TRANSLATE_NOOP("", "The room is full");
- break;
- case ErrorPayload::ItemNotFound:
- errorMessage += ": ";
- errorMessage += QT_TRANSLATE_NOOP("", "The room does not exist");
- break;
-
- default: break;
- }
- }
- errorMessage = str(format(QT_TRANSLATE_NOOP("", "Couldn't enter room: %1%.")) % errorMessage);
- chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
- parting_ = true;
- if (!rejoinNick.empty() && renameCounter_ < 10) {
- renameCounter_++;
- setNick(rejoinNick);
- rejoin();
- }
+ receivedActivity();
+ std::string errorMessage = QT_TRANSLATE_NOOP("", "Unable to enter this room");
+ std::string rejoinNick;
+ if (error) {
+ switch (error->getCondition()) {
+ case ErrorPayload::Conflict:
+ rejoinNick = nick_ + "_";
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "Unable to enter this room as %1%, retrying as %2%")) % nick_ % rejoinNick);
+ break;
+ case ErrorPayload::JIDMalformed:
+ errorMessage += ": ";
+ errorMessage += QT_TRANSLATE_NOOP("", "No nickname specified");
+ break;
+ case ErrorPayload::NotAuthorized:
+ errorMessage += ": ";
+ errorMessage += QT_TRANSLATE_NOOP("", "The correct room password is needed");
+ break;
+ case ErrorPayload::RegistrationRequired:
+ errorMessage += ": ";
+ errorMessage += QT_TRANSLATE_NOOP("", "Only members may enter");
+ break;
+ case ErrorPayload::Forbidden:
+ errorMessage += ": ";
+ errorMessage += QT_TRANSLATE_NOOP("", "You are banned from the room");
+ break;
+ case ErrorPayload::ServiceUnavailable:
+ errorMessage += ": ";
+ errorMessage += QT_TRANSLATE_NOOP("", "The room is full");
+ break;
+ case ErrorPayload::ItemNotFound:
+ errorMessage += ": ";
+ errorMessage += QT_TRANSLATE_NOOP("", "The room does not exist");
+ break;
+
+ default: break;
+ }
+ }
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "Couldn't enter room: %1%.")) % errorMessage);
+ chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
+ parting_ = true;
+ if (!rejoinNick.empty() && renameCounter_ < 10) {
+ renameCounter_++;
+ setNick(rejoinNick);
+ rejoin();
+ }
}
#pragma clang diagnostic pop
void MUCController::handleJoinComplete(const std::string& nick) {
- receivedActivity();
- renameCounter_ = 0;
- joined_ = true;
- std::string joinMessage;
- if (isImpromptu_) {
- joinMessage = str(format(QT_TRANSLATE_NOOP("", "You have joined the chat as %1%.")) % nick);
- } else {
- joinMessage = str(format(QT_TRANSLATE_NOOP("", "You have entered room %1% as %2%.")) % toJID_.toString() % nick);
- }
- setNick(nick);
- chatWindow_->replaceSystemMessage(chatMessageParser_->parseMessageBody(joinMessage), lastJoinMessageUID_, ChatWindow::UpdateTimestamp);
- lastJoinMessageUID_ = "";
+ receivedActivity();
+ renameCounter_ = 0;
+ joined_ = true;
+ std::string joinMessage;
+ if (isImpromptu_) {
+ joinMessage = str(format(QT_TRANSLATE_NOOP("", "You have joined the chat as %1%.")) % nick);
+ } else {
+ joinMessage = str(format(QT_TRANSLATE_NOOP("", "You have entered room %1% as %2%.")) % toJID_.toString() % nick);
+ }
+ setNick(nick);
+ chatWindow_->replaceSystemMessage(chatMessageParser_->parseMessageBody(joinMessage), lastJoinMessageUID_, ChatWindow::UpdateTimestamp);
+ lastJoinMessageUID_ = "";
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- addRecentLogs();
+ addRecentLogs();
#endif
- clearPresenceQueue();
- shouldJoinOnReconnect_ = true;
- setEnabled(true);
- if (isImpromptu_) {
- setAvailableRoomActions(MUCOccupant::NoAffiliation, MUCOccupant::Participant);
- } else {
- MUCOccupant occupant = muc_->getOccupant(nick);
- setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole());
- }
- onUserJoined();
+ clearPresenceQueue();
+ shouldJoinOnReconnect_ = true;
+ setEnabled(true);
+ if (isImpromptu_) {
+ setAvailableRoomActions(MUCOccupant::NoAffiliation, MUCOccupant::Participant);
+ } else {
+ MUCOccupant occupant = muc_->getOccupant(nick);
+ setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole());
+ }
+ onUserJoined();
- if (isImpromptu_) {
- setImpromptuWindowTitle();
- }
+ if (isImpromptu_) {
+ setImpromptuWindowTitle();
+ }
}
void MUCController::handleAvatarChanged(const JID& jid) {
- if (parting_ || !jid.equals(toJID_, JID::WithoutResource)) {
- return;
- }
- roster_->applyOnItems(SetAvatar(jid, avatarManager_->getAvatarPath(jid), JID::WithResource));
+ if (parting_ || !jid.equals(toJID_, JID::WithoutResource)) {
+ return;
+ }
+ roster_->applyOnItems(SetAvatar(jid, avatarManager_->getAvatarPath(jid), JID::WithResource));
}
void MUCController::handleWindowClosed() {
- parting_ = true;
- shouldJoinOnReconnect_ = false;
- muc_->part();
- onUserLeft();
+ parting_ = true;
+ shouldJoinOnReconnect_ = false;
+ muc_->part();
+ onUserLeft();
}
void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {
- if (nick_ != occupant.getNick()) {
- completer_->addWord(occupant.getNick());
- }
- receivedActivity();
- JID jid(nickToJID(occupant.getNick()));
- JID realJID;
- if (occupant.getRealJID()) {
- realJID = occupant.getRealJID().get();
- }
- currentOccupants_.insert(occupant.getNick());
- NickJoinPart event(occupant.getNick(), Join);
- appendToJoinParts(joinParts_, event);
- MUCOccupant::Role role = MUCOccupant::Participant;
- MUCOccupant::Affiliation affiliation = MUCOccupant::NoAffiliation;
- if (!isImpromptu_) {
- role = occupant.getRole();
- affiliation = occupant.getAffiliation();
- }
- std::string groupName(roleToGroupName(role));
- roster_->addContact(jid, realJID, occupant.getNick(), groupName, avatarManager_->getAvatarPath(jid));
- roster_->applyOnItems(SetMUC(jid, role, affiliation));
- roster_->getGroup(groupName)->setManualSort(roleToSortName(role));
- if (joined_) {
- std::string joinString;
- if (role != MUCOccupant::NoRole && role != MUCOccupant::Participant) {
- joinString = str(format(QT_TRANSLATE_NOOP("", "%1% has entered the %3% as a %2%.")) % occupant.getNick() % roleToFriendlyName(role) % (isImpromptu_ ? QT_TRANSLATE_NOOP("", "chat") : QT_TRANSLATE_NOOP("", "room")));
- }
- else {
- joinString = str(format(QT_TRANSLATE_NOOP("", "%1% has entered the %2%.")) % occupant.getNick() % (isImpromptu_ ? QT_TRANSLATE_NOOP("", "chat") : QT_TRANSLATE_NOOP("", "room")));
- }
- if (shouldUpdateJoinParts()) {
- updateJoinParts();
- } else {
- addPresenceMessage(joinString);
- }
-
- if (isImpromptu_) {
- setImpromptuWindowTitle();
- onActivity("");
- }
- }
- if (avatarManager_ != NULL) {
- handleAvatarChanged(jid);
- }
+ if (nick_ != occupant.getNick()) {
+ completer_->addWord(occupant.getNick());
+ }
+ receivedActivity();
+ JID jid(nickToJID(occupant.getNick()));
+ JID realJID;
+ if (occupant.getRealJID()) {
+ realJID = occupant.getRealJID().get();
+ }
+ currentOccupants_.insert(occupant.getNick());
+ NickJoinPart event(occupant.getNick(), Join);
+ appendToJoinParts(joinParts_, event);
+ MUCOccupant::Role role = MUCOccupant::Participant;
+ MUCOccupant::Affiliation affiliation = MUCOccupant::NoAffiliation;
+ if (!isImpromptu_) {
+ role = occupant.getRole();
+ affiliation = occupant.getAffiliation();
+ }
+ std::string groupName(roleToGroupName(role));
+ roster_->addContact(jid, realJID, occupant.getNick(), groupName, avatarManager_->getAvatarPath(jid));
+ roster_->applyOnItems(SetMUC(jid, role, affiliation));
+ roster_->getGroup(groupName)->setManualSort(roleToSortName(role));
+ if (joined_) {
+ std::string joinString;
+ if (role != MUCOccupant::NoRole && role != MUCOccupant::Participant) {
+ joinString = str(format(QT_TRANSLATE_NOOP("", "%1% has entered the %3% as a %2%.")) % occupant.getNick() % roleToFriendlyName(role) % (isImpromptu_ ? QT_TRANSLATE_NOOP("", "chat") : QT_TRANSLATE_NOOP("", "room")));
+ }
+ else {
+ joinString = str(format(QT_TRANSLATE_NOOP("", "%1% has entered the %2%.")) % occupant.getNick() % (isImpromptu_ ? QT_TRANSLATE_NOOP("", "chat") : QT_TRANSLATE_NOOP("", "room")));
+ }
+ if (shouldUpdateJoinParts()) {
+ updateJoinParts();
+ } else {
+ addPresenceMessage(joinString);
+ }
+
+ if (isImpromptu_) {
+ setImpromptuWindowTitle();
+ onActivity("");
+ }
+ }
+ if (avatarManager_ != NULL) {
+ handleAvatarChanged(jid);
+ }
}
void MUCController::addPresenceMessage(const std::string& message) {
- lastWasPresence_ = true;
- chatWindow_->addPresenceMessage(chatMessageParser_->parseMessageBody(message), ChatWindow::DefaultDirection);
+ lastWasPresence_ = true;
+ chatWindow_->addPresenceMessage(chatMessageParser_->parseMessageBody(message), ChatWindow::DefaultDirection);
}
void MUCController::setAvailableRoomActions(const MUCOccupant::Affiliation& affiliation, const MUCOccupant::Role& role)
{
- std::vector<ChatWindow::RoomAction> actions;
-
- if (role <= MUCOccupant::Participant) {
- actions.push_back(ChatWindow::ChangeSubject);
- }
- if (affiliation == MUCOccupant::Owner) {
- actions.push_back(ChatWindow::Configure);
- }
- if (affiliation <= MUCOccupant::Admin) {
- actions.push_back(ChatWindow::Affiliations);
- }
- if (affiliation == MUCOccupant::Owner) {
- actions.push_back(ChatWindow::Destroy);
- }
- if (role <= MUCOccupant::Visitor) {
- actions.push_back(ChatWindow::Invite);
- }
- chatWindow_->setAvailableRoomActions(actions);
+ std::vector<ChatWindow::RoomAction> actions;
+
+ if (role <= MUCOccupant::Participant) {
+ actions.push_back(ChatWindow::ChangeSubject);
+ }
+ if (affiliation == MUCOccupant::Owner) {
+ actions.push_back(ChatWindow::Configure);
+ }
+ if (affiliation <= MUCOccupant::Admin) {
+ actions.push_back(ChatWindow::Affiliations);
+ }
+ if (affiliation == MUCOccupant::Owner) {
+ actions.push_back(ChatWindow::Destroy);
+ }
+ if (role <= MUCOccupant::Visitor) {
+ actions.push_back(ChatWindow::Invite);
+ }
+ chatWindow_->setAvailableRoomActions(actions);
}
void MUCController::clearPresenceQueue() {
- lastWasPresence_ = false;
- joinParts_.clear();
+ lastWasPresence_ = false;
+ joinParts_.clear();
}
std::string MUCController::roleToFriendlyName(MUCOccupant::Role role) {
- switch (role) {
- case MUCOccupant::Moderator: return QT_TRANSLATE_NOOP("", "moderator");
- case MUCOccupant::Participant: return QT_TRANSLATE_NOOP("", "participant");
- case MUCOccupant::Visitor: return QT_TRANSLATE_NOOP("", "visitor");
- case MUCOccupant::NoRole: return "";
- }
- assert(false);
- return "";
+ switch (role) {
+ case MUCOccupant::Moderator: return QT_TRANSLATE_NOOP("", "moderator");
+ case MUCOccupant::Participant: return QT_TRANSLATE_NOOP("", "participant");
+ case MUCOccupant::Visitor: return QT_TRANSLATE_NOOP("", "visitor");
+ case MUCOccupant::NoRole: return "";
+ }
+ assert(false);
+ return "";
}
std::string MUCController::roleToSortName(MUCOccupant::Role role) {
- switch (role) {
- case MUCOccupant::Moderator: return "1";
- case MUCOccupant::Participant: return "2";
- case MUCOccupant::Visitor: return "3";
- case MUCOccupant::NoRole: return "4";
- }
- assert(false);
- return "5";
+ switch (role) {
+ case MUCOccupant::Moderator: return "1";
+ case MUCOccupant::Participant: return "2";
+ case MUCOccupant::Visitor: return "3";
+ case MUCOccupant::NoRole: return "4";
+ }
+ assert(false);
+ return "5";
}
JID MUCController::nickToJID(const std::string& nick) {
- return muc_->getJID().withResource(nick);
+ return muc_->getJID().withResource(nick);
}
bool MUCController::messageTargetsMe(boost::shared_ptr<Message> message) {
- std::string stringRegexp(".*\\b" + boost::to_lower_copy(nick_) + "\\b.*");
- boost::regex myRegexp(stringRegexp);
- return boost::regex_match(boost::to_lower_copy(message->getBody().get_value_or("")), myRegexp);
+ std::string stringRegexp(".*\\b" + boost::to_lower_copy(nick_) + "\\b.*");
+ boost::regex myRegexp(stringRegexp);
+ return boost::regex_match(boost::to_lower_copy(message->getBody().get_value_or("")), myRegexp);
}
void MUCController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
- if (messageEvent->getStanza()->getType() == Message::Groupchat) {
- lastActivity_ = boost::posix_time::microsec_clock::universal_time();
- }
- clearPresenceQueue();
- boost::shared_ptr<Message> message = messageEvent->getStanza();
- if (joined_ && messageEvent->getStanza()->getFrom().getResource() != nick_ && messageTargetsMe(message) && !message->getPayload<Delay>() && messageEvent->isReadable()) {
- chatWindow_->flash();
- }
- else {
- messageEvent->setTargetsMe(false);
- }
- if (messageEvent->isReadable() && isImpromptu_) {
- chatWindow_->flash(); /* behave like a regular char*/
- }
- if (joined_) {
- std::string nick = message->getFrom().getResource();
- if (nick != nick_ && currentOccupants_.find(nick) != currentOccupants_.end()) {
- completer_->addWord(nick);
- }
- }
- /*Buggy implementations never send the status code, so use an incoming message as a hint that joining's done (e.g. the old ejabberd on psi-im.org).*/
- receivedActivity();
- joined_ = true;
-
- if (message->hasSubject() && !message->getPayload<Body>() && !message->getPayload<Thread>()) {
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "The room subject is now: %1%")) % message->getSubject())), ChatWindow::DefaultDirection);
- chatWindow_->setSubject(message->getSubject());
- doneGettingHistory_ = true;
- }
-
- if (!doneGettingHistory_ && !message->getPayload<Delay>()) {
- doneGettingHistory_ = true;
- }
-
- if (!doneGettingHistory_) {
- checkDuplicates(message);
- messageEvent->conclude();
- }
+ if (messageEvent->getStanza()->getType() == Message::Groupchat) {
+ lastActivity_ = boost::posix_time::microsec_clock::universal_time();
+ }
+ clearPresenceQueue();
+ boost::shared_ptr<Message> message = messageEvent->getStanza();
+ if (joined_ && messageEvent->getStanza()->getFrom().getResource() != nick_ && messageTargetsMe(message) && !message->getPayload<Delay>() && messageEvent->isReadable()) {
+ chatWindow_->flash();
+ }
+ else {
+ messageEvent->setTargetsMe(false);
+ }
+ if (messageEvent->isReadable() && isImpromptu_) {
+ chatWindow_->flash(); /* behave like a regular char*/
+ }
+ if (joined_) {
+ std::string nick = message->getFrom().getResource();
+ if (nick != nick_ && currentOccupants_.find(nick) != currentOccupants_.end()) {
+ completer_->addWord(nick);
+ }
+ }
+ /*Buggy implementations never send the status code, so use an incoming message as a hint that joining's done (e.g. the old ejabberd on psi-im.org).*/
+ receivedActivity();
+ joined_ = true;
+
+ if (message->hasSubject() && !message->getPayload<Body>() && !message->getPayload<Thread>()) {
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "The room subject is now: %1%")) % message->getSubject())), ChatWindow::DefaultDirection);
+ chatWindow_->setSubject(message->getSubject());
+ doneGettingHistory_ = true;
+ }
+
+ if (!doneGettingHistory_ && !message->getPayload<Delay>()) {
+ doneGettingHistory_ = true;
+ }
+
+ if (!doneGettingHistory_) {
+ checkDuplicates(message);
+ messageEvent->conclude();
+ }
}
void MUCController::addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& time) {
- if (from.isBare()) {
- chatWindow_->addSystemMessage(message, ChatWindow::DefaultDirection);
- }
- else {
- ChatControllerBase::addMessageHandleIncomingMessage(from, message, senderIsSelf, label, time);
- }
+ if (from.isBare()) {
+ chatWindow_->addSystemMessage(message, ChatWindow::DefaultDirection);
+ }
+ else {
+ ChatControllerBase::addMessageHandleIncomingMessage(from, message, senderIsSelf, label, time);
+ }
}
void MUCController::postHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent, const ChatWindow::ChatMessage& chatMessage) {
- boost::shared_ptr<Message> message = messageEvent->getStanza();
- if (joined_ && messageEvent->getStanza()->getFrom().getResource() != nick_ && !message->getPayload<Delay>()) {
- if (messageTargetsMe(message) || isImpromptu_) {
- eventController_->handleIncomingEvent(messageEvent);
- }
- if (!messageEvent->getConcluded()) {
- handleHighlightActions(chatMessage);
- }
- }
+ boost::shared_ptr<Message> message = messageEvent->getStanza();
+ if (joined_ && messageEvent->getStanza()->getFrom().getResource() != nick_ && !message->getPayload<Delay>()) {
+ if (messageTargetsMe(message) || isImpromptu_) {
+ eventController_->handleIncomingEvent(messageEvent);
+ }
+ if (!messageEvent->getConcluded()) {
+ handleHighlightActions(chatMessage);
+ }
+ }
}
void MUCController::handleOccupantRoleChanged(const std::string& nick, const MUCOccupant& occupant, const MUCOccupant::Role& oldRole) {
- clearPresenceQueue();
- receivedActivity();
- JID jid(nickToJID(nick));
- roster_->removeContactFromGroup(jid, roleToGroupName(oldRole));
- JID realJID;
- if (occupant.getRealJID()) {
- realJID = occupant.getRealJID().get();
- }
- std::string group(roleToGroupName(occupant.getRole()));
- roster_->addContact(jid, realJID, nick, group, avatarManager_->getAvatarPath(jid));
- roster_->getGroup(group)->setManualSort(roleToSortName(occupant.getRole()));
- roster_->applyOnItems(SetMUC(jid, occupant.getRole(), occupant.getAffiliation()));
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "%1% is now a %2%")) % nick % roleToFriendlyName(occupant.getRole()))), ChatWindow::DefaultDirection);
- if (nick == nick_) {
- setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole());
- }
+ clearPresenceQueue();
+ receivedActivity();
+ JID jid(nickToJID(nick));
+ roster_->removeContactFromGroup(jid, roleToGroupName(oldRole));
+ JID realJID;
+ if (occupant.getRealJID()) {
+ realJID = occupant.getRealJID().get();
+ }
+ std::string group(roleToGroupName(occupant.getRole()));
+ roster_->addContact(jid, realJID, nick, group, avatarManager_->getAvatarPath(jid));
+ roster_->getGroup(group)->setManualSort(roleToSortName(occupant.getRole()));
+ roster_->applyOnItems(SetMUC(jid, occupant.getRole(), occupant.getAffiliation()));
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "%1% is now a %2%")) % nick % roleToFriendlyName(occupant.getRole()))), ChatWindow::DefaultDirection);
+ if (nick == nick_) {
+ setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole());
+ }
}
void MUCController::handleOccupantAffiliationChanged(const std::string& nick, const MUCOccupant::Affiliation& affiliation, const MUCOccupant::Affiliation& /*oldAffiliation*/)
{
- if (nick == nick_) {
- setAvailableRoomActions(affiliation, muc_->getOccupant(nick_).getRole());
- }
- JID jid(nickToJID(nick));
- MUCOccupant occupant = muc_->getOccupant(nick);
- roster_->applyOnItems(SetMUC(jid, occupant.getRole(), affiliation));
+ if (nick == nick_) {
+ setAvailableRoomActions(affiliation, muc_->getOccupant(nick_).getRole());
+ }
+ JID jid(nickToJID(nick));
+ MUCOccupant occupant = muc_->getOccupant(nick);
+ roster_->applyOnItems(SetMUC(jid, occupant.getRole(), affiliation));
}
std::string MUCController::roleToGroupName(MUCOccupant::Role role) {
- std::string result;
- switch (role) {
- case MUCOccupant::Moderator: result = QT_TRANSLATE_NOOP("", "Moderators"); break;
- case MUCOccupant::Participant: result = QT_TRANSLATE_NOOP("", "Participants"); break;
- case MUCOccupant::Visitor: result = QT_TRANSLATE_NOOP("", "Visitors"); break;
- case MUCOccupant::NoRole: result = QT_TRANSLATE_NOOP("", "Occupants"); break;
- }
- return result;
+ std::string result;
+ switch (role) {
+ case MUCOccupant::Moderator: result = QT_TRANSLATE_NOOP("", "Moderators"); break;
+ case MUCOccupant::Participant: result = QT_TRANSLATE_NOOP("", "Participants"); break;
+ case MUCOccupant::Visitor: result = QT_TRANSLATE_NOOP("", "Visitors"); break;
+ case MUCOccupant::NoRole: result = QT_TRANSLATE_NOOP("", "Occupants"); break;
+ }
+ return result;
}
void MUCController::setOnline(bool online) {
- ChatControllerBase::setOnline(online);
- if (!online) {
- muc_->part();
- parting_ = true;
- processUserPart();
- } else {
- if (shouldJoinOnReconnect_) {
- renameCounter_ = 0;
- boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
- if (blockList && blockList->isBlocked(muc_->getJID())) {
- handleBlockingStateChanged();
- lastJoinMessageUID_ = chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "You've blocked this room. To enter the room, first unblock it using the cog menu and try again")), ChatWindow::DefaultDirection);
- }
- else {
- if (isImpromptu_) {
- lastJoinMessageUID_ = chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "Trying to join chat")), ChatWindow::DefaultDirection);
- } else {
- lastJoinMessageUID_ = chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "Trying to enter room %1%")) % toJID_.toString())), ChatWindow::DefaultDirection);
- }
- if (loginCheckTimer_) {
- loginCheckTimer_->start();
- }
- setNick(desiredNick_);
- rejoin();
- }
- }
- }
+ ChatControllerBase::setOnline(online);
+ if (!online) {
+ muc_->part();
+ parting_ = true;
+ processUserPart();
+ } else {
+ if (shouldJoinOnReconnect_) {
+ renameCounter_ = 0;
+ boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
+ if (blockList && blockList->isBlocked(muc_->getJID())) {
+ handleBlockingStateChanged();
+ lastJoinMessageUID_ = chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "You've blocked this room. To enter the room, first unblock it using the cog menu and try again")), ChatWindow::DefaultDirection);
+ }
+ else {
+ if (isImpromptu_) {
+ lastJoinMessageUID_ = chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "Trying to join chat")), ChatWindow::DefaultDirection);
+ } else {
+ lastJoinMessageUID_ = chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "Trying to enter room %1%")) % toJID_.toString())), ChatWindow::DefaultDirection);
+ }
+ if (loginCheckTimer_) {
+ loginCheckTimer_->start();
+ }
+ setNick(desiredNick_);
+ rejoin();
+ }
+ }
+ }
}
void MUCController::processUserPart() {
- roster_->removeAll();
- /* handleUserLeft won't throw a part back up unless this is called
- when it doesn't yet know we've left - which only happens on
- disconnect, so call with disconnect here so if the signal does
- bubble back up, it'll be with the right type.*/
- muc_->handleUserLeft(MUC::Disconnect);
- setEnabled(false);
+ roster_->removeAll();
+ /* handleUserLeft won't throw a part back up unless this is called
+ when it doesn't yet know we've left - which only happens on
+ disconnect, so call with disconnect here so if the signal does
+ bubble back up, it'll be with the right type.*/
+ muc_->handleUserLeft(MUC::Disconnect);
+ setEnabled(false);
}
bool MUCController::shouldUpdateJoinParts() {
- return lastWasPresence_;
+ return lastWasPresence_;
}
void MUCController::handleOccupantLeft(const MUCOccupant& occupant, MUC::LeavingType type, const std::string& reason) {
- NickJoinPart event(occupant.getNick(), Part);
- appendToJoinParts(joinParts_, event);
- currentOccupants_.erase(occupant.getNick());
- completer_->removeWord(occupant.getNick());
- std::string partMessage;
- bool clearAfter = false;
- if (occupant.getNick() != nick_) {
- std::string partType;
- switch (type) {
- case MUC::LeaveKick: clearPresenceQueue(); clearAfter = true; partType = " (kicked)"; break;
- case MUC::LeaveBan: clearPresenceQueue(); clearAfter = true; partType = " (banned)"; break;
- case MUC::LeaveNotMember: clearPresenceQueue(); clearAfter = true; partType = " (no longer a member)"; break;
- case MUC::LeaveDestroy:
- case MUC::Disconnect:
- case MUC::LeavePart: break;
- }
- if (isImpromptu_) {
- partMessage = str(format(QT_TRANSLATE_NOOP("", "%1% has left the chat%2%")) % occupant.getNick() % partType);
- } else {
- partMessage = str(format(QT_TRANSLATE_NOOP("", "%1% has left the room%2%")) % occupant.getNick() % partType);
- }
- }
- else if (isImpromptu_) {
- switch (type) {
- case MUC::LeaveKick:
- case MUC::LeaveBan: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been removed from this chat"); break;
- case MUC::LeaveNotMember: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been removed from this chat"); break;
- case MUC::LeaveDestroy: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "This chat has ended"); break;
- case MUC::Disconnect:
- case MUC::LeavePart: partMessage = QT_TRANSLATE_NOOP("", "You have left the chat");
- }
- }
- else {
- switch (type) {
- case MUC::LeaveKick: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been kicked out of the room"); break;
- case MUC::LeaveBan: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been banned from the room"); break;
- case MUC::LeaveNotMember: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You are no longer a member of the room and have been removed"); break;
- case MUC::LeaveDestroy: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "The room has been destroyed"); break;
- case MUC::Disconnect:
- case MUC::LeavePart: partMessage = QT_TRANSLATE_NOOP("", "You have left the room");
- }
- }
- if (!reason.empty()) {
- partMessage += " (" + reason + ")";
- }
- partMessage += ".";
-
- if (occupant.getNick() != nick_) {
- if (shouldUpdateJoinParts()) {
- updateJoinParts();
- } else {
- addPresenceMessage(partMessage);
- }
- roster_->removeContact(JID(toJID_.getNode(), toJID_.getDomain(), occupant.getNick()));
- } else {
- addPresenceMessage(partMessage);
- parting_ = true;
- processUserPart();
- }
- if (clearAfter) {
- clearPresenceQueue();
- }
-
- if (isImpromptu_) {
- setImpromptuWindowTitle();
- }
+ NickJoinPart event(occupant.getNick(), Part);
+ appendToJoinParts(joinParts_, event);
+ currentOccupants_.erase(occupant.getNick());
+ completer_->removeWord(occupant.getNick());
+ std::string partMessage;
+ bool clearAfter = false;
+ if (occupant.getNick() != nick_) {
+ std::string partType;
+ switch (type) {
+ case MUC::LeaveKick: clearPresenceQueue(); clearAfter = true; partType = " (kicked)"; break;
+ case MUC::LeaveBan: clearPresenceQueue(); clearAfter = true; partType = " (banned)"; break;
+ case MUC::LeaveNotMember: clearPresenceQueue(); clearAfter = true; partType = " (no longer a member)"; break;
+ case MUC::LeaveDestroy:
+ case MUC::Disconnect:
+ case MUC::LeavePart: break;
+ }
+ if (isImpromptu_) {
+ partMessage = str(format(QT_TRANSLATE_NOOP("", "%1% has left the chat%2%")) % occupant.getNick() % partType);
+ } else {
+ partMessage = str(format(QT_TRANSLATE_NOOP("", "%1% has left the room%2%")) % occupant.getNick() % partType);
+ }
+ }
+ else if (isImpromptu_) {
+ switch (type) {
+ case MUC::LeaveKick:
+ case MUC::LeaveBan: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been removed from this chat"); break;
+ case MUC::LeaveNotMember: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been removed from this chat"); break;
+ case MUC::LeaveDestroy: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "This chat has ended"); break;
+ case MUC::Disconnect:
+ case MUC::LeavePart: partMessage = QT_TRANSLATE_NOOP("", "You have left the chat");
+ }
+ }
+ else {
+ switch (type) {
+ case MUC::LeaveKick: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been kicked out of the room"); break;
+ case MUC::LeaveBan: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been banned from the room"); break;
+ case MUC::LeaveNotMember: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You are no longer a member of the room and have been removed"); break;
+ case MUC::LeaveDestroy: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "The room has been destroyed"); break;
+ case MUC::Disconnect:
+ case MUC::LeavePart: partMessage = QT_TRANSLATE_NOOP("", "You have left the room");
+ }
+ }
+ if (!reason.empty()) {
+ partMessage += " (" + reason + ")";
+ }
+ partMessage += ".";
+
+ if (occupant.getNick() != nick_) {
+ if (shouldUpdateJoinParts()) {
+ updateJoinParts();
+ } else {
+ addPresenceMessage(partMessage);
+ }
+ roster_->removeContact(JID(toJID_.getNode(), toJID_.getDomain(), occupant.getNick()));
+ } else {
+ addPresenceMessage(partMessage);
+ parting_ = true;
+ processUserPart();
+ }
+ if (clearAfter) {
+ clearPresenceQueue();
+ }
+
+ if (isImpromptu_) {
+ setImpromptuWindowTitle();
+ }
}
void MUCController::handleOccupantNicknameChanged(const std::string& oldNickname, const std::string& newNickname) {
- addPresenceMessage(generateNicknameChangeString(oldNickname, newNickname));
- JID oldJID = muc_->getJID().withResource(oldNickname);
- JID newJID = muc_->getJID().withResource(newNickname);
-
- // adjust occupants
- currentOccupants_.erase(oldNickname);
- currentOccupants_.insert(newNickname);
-
- // adjust completer
- completer_->removeWord(oldNickname);
- completer_->addWord(newNickname);
-
- // update contact
- roster_->removeContact(oldJID);
- MUCOccupant occupant = muc_->getOccupant(newNickname);
-
- JID realJID;
- if (occupant.getRealJID()) {
- realJID = occupant.getRealJID().get();
- }
- MUCOccupant::Role role = MUCOccupant::Participant;
- MUCOccupant::Affiliation affiliation = MUCOccupant::NoAffiliation;
- if (!isImpromptu_) {
- role = occupant.getRole();
- affiliation = occupant.getAffiliation();
- }
- std::string groupName(roleToGroupName(role));
- roster_->addContact(newJID, realJID, newNickname, groupName, avatarManager_->getAvatarPath(newJID));
- roster_->applyOnItems(SetMUC(newJID, role, affiliation));
- if (avatarManager_ != NULL) {
- handleAvatarChanged(newJID);
- }
-
- clearPresenceQueue();
- onUserNicknameChanged(oldNickname, newNickname);
+ addPresenceMessage(generateNicknameChangeString(oldNickname, newNickname));
+ JID oldJID = muc_->getJID().withResource(oldNickname);
+ JID newJID = muc_->getJID().withResource(newNickname);
+
+ // adjust occupants
+ currentOccupants_.erase(oldNickname);
+ currentOccupants_.insert(newNickname);
+
+ // adjust completer
+ completer_->removeWord(oldNickname);
+ completer_->addWord(newNickname);
+
+ // update contact
+ roster_->removeContact(oldJID);
+ MUCOccupant occupant = muc_->getOccupant(newNickname);
+
+ JID realJID;
+ if (occupant.getRealJID()) {
+ realJID = occupant.getRealJID().get();
+ }
+ MUCOccupant::Role role = MUCOccupant::Participant;
+ MUCOccupant::Affiliation affiliation = MUCOccupant::NoAffiliation;
+ if (!isImpromptu_) {
+ role = occupant.getRole();
+ affiliation = occupant.getAffiliation();
+ }
+ std::string groupName(roleToGroupName(role));
+ roster_->addContact(newJID, realJID, newNickname, groupName, avatarManager_->getAvatarPath(newJID));
+ roster_->applyOnItems(SetMUC(newJID, role, affiliation));
+ if (avatarManager_ != NULL) {
+ handleAvatarChanged(newJID);
+ }
+
+ clearPresenceQueue();
+ onUserNicknameChanged(oldNickname, newNickname);
}
void MUCController::handleOccupantPresenceChange(boost::shared_ptr<Presence> presence) {
- receivedActivity();
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+ receivedActivity();
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
}
bool MUCController::isIncomingMessageFromMe(boost::shared_ptr<Message> message) {
- JID from = message->getFrom();
- return nick_ == from.getResource();
+ JID from = message->getFrom();
+ return nick_ == from.getResource();
}
std::string MUCController::senderHighlightNameFromMessage(const JID& from) {
- return from.getResource();
+ return from.getResource();
}
std::string MUCController::senderDisplayNameFromMessage(const JID& from) {
- return from.getResource();
+ return from.getResource();
}
void MUCController::preSendMessageRequest(boost::shared_ptr<Message> message) {
- message->setType(Swift::Message::Groupchat);
+ message->setType(Swift::Message::Groupchat);
}
boost::optional<boost::posix_time::ptime> MUCController::getMessageTimestamp(boost::shared_ptr<Message> message) const {
- return message->getTimestampFrom(toJID_);
+ return message->getTimestampFrom(toJID_);
}
void MUCController::updateJoinParts() {
- chatWindow_->replaceLastMessage(chatMessageParser_->parseMessageBody(generateJoinPartString(joinParts_, isImpromptu())), ChatWindow::UpdateTimestamp);
+ chatWindow_->replaceLastMessage(chatMessageParser_->parseMessageBody(generateJoinPartString(joinParts_, isImpromptu())), ChatWindow::UpdateTimestamp);
}
void MUCController::appendToJoinParts(std::vector<NickJoinPart>& joinParts, const NickJoinPart& newEvent) {
- std::vector<NickJoinPart>::iterator it = joinParts.begin();
- bool matched = false;
- for (; it != joinParts.end(); ++it) {
- if ((*it).nick == newEvent.nick) {
- matched = true;
- JoinPart type = (*it).type;
- switch (newEvent.type) {
- case Join: type = (type == Part) ? PartThenJoin : Join; break;
- case Part: type = (type == Join) ? JoinThenPart : Part; break;
- case PartThenJoin: break;
- case JoinThenPart: break;
- }
- (*it).type = type;
- break;
- }
- }
- if (!matched) {
- joinParts.push_back(newEvent);
- }
+ std::vector<NickJoinPart>::iterator it = joinParts.begin();
+ bool matched = false;
+ for (; it != joinParts.end(); ++it) {
+ if ((*it).nick == newEvent.nick) {
+ matched = true;
+ JoinPart type = (*it).type;
+ switch (newEvent.type) {
+ case Join: type = (type == Part) ? PartThenJoin : Join; break;
+ case Part: type = (type == Join) ? JoinThenPart : Part; break;
+ case PartThenJoin: break;
+ case JoinThenPart: break;
+ }
+ (*it).type = type;
+ break;
+ }
+ }
+ if (!matched) {
+ joinParts.push_back(newEvent);
+ }
}
std::string MUCController::concatenateListOfNames(const std::vector<NickJoinPart>& joinParts) {
- std::string result;
- for (size_t i = 0; i < joinParts.size(); i++) {
- if (i > 0) {
- if (i < joinParts.size() - 1) {
- result += ", ";
- } else {
- result += QT_TRANSLATE_NOOP("", " and ");
- }
- }
- NickJoinPart event = joinParts[i];
- result += event.nick;
- }
- return result;
+ std::string result;
+ for (size_t i = 0; i < joinParts.size(); i++) {
+ if (i > 0) {
+ if (i < joinParts.size() - 1) {
+ result += ", ";
+ } else {
+ result += QT_TRANSLATE_NOOP("", " and ");
+ }
+ }
+ NickJoinPart event = joinParts[i];
+ result += event.nick;
+ }
+ return result;
}
std::string MUCController::generateJoinPartString(const std::vector<NickJoinPart>& joinParts, bool isImpromptu) {
- std::vector<NickJoinPart> sorted[4];
- std::string eventStrings[4];
- foreach (NickJoinPart event, joinParts) {
- sorted[event.type].push_back(event);
- }
- std::string result;
- std::vector<JoinPart> populatedEvents;
- for (size_t i = 0; i < 4; i++) {
- std::string names = concatenateListOfNames(sorted[i]);
- if (!names.empty()) {
- std::string eventString;
- switch (i) {
- case Join:
- if (sorted[i].size() > 1) {
- eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have joined the chat") : QT_TRANSLATE_NOOP("", "%1% have entered the room"));
- }
- else {
- eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% has joined the chat") : QT_TRANSLATE_NOOP("", "%1% has entered the room"));
- }
- break;
- case Part:
- if (sorted[i].size() > 1) {
- eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have left the chat") : QT_TRANSLATE_NOOP("", "%1% have left the room"));
- }
- else {
- eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have left the chat") : QT_TRANSLATE_NOOP("", "%1% has left the room"));
- }
- break;
- case JoinThenPart:
- if (sorted[i].size() > 1) {
- eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have joined then left the chat") : QT_TRANSLATE_NOOP("", "%1% have entered then left the room"));
- }
- else {
- eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% has joined then left the chat") : QT_TRANSLATE_NOOP("", "%1% has entered then left the room"));
- }
- break;
- case PartThenJoin:
- if (sorted[i].size() > 1) {
- eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have left then returned to the chat") : QT_TRANSLATE_NOOP("", "%1% have left then returned to the room"));
- }
- else {
- eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% has left then returned to the chat") : QT_TRANSLATE_NOOP("", "%1% has left then returned to the room"));
- }
- break;
- }
- populatedEvents.push_back(static_cast<JoinPart>(i));
- eventStrings[i] = str(boost::format(eventString) % names);
- }
- }
- for (size_t i = 0; i < populatedEvents.size(); i++) {
- if (i > 0) {
- if (i < populatedEvents.size() - 1) {
- result += ", ";
- } else {
- result += QT_TRANSLATE_NOOP("", " and ");
- }
- }
- result += eventStrings[populatedEvents[i]];
- }
- return result;
+ std::vector<NickJoinPart> sorted[4];
+ std::string eventStrings[4];
+ foreach (NickJoinPart event, joinParts) {
+ sorted[event.type].push_back(event);
+ }
+ std::string result;
+ std::vector<JoinPart> populatedEvents;
+ for (size_t i = 0; i < 4; i++) {
+ std::string names = concatenateListOfNames(sorted[i]);
+ if (!names.empty()) {
+ std::string eventString;
+ switch (i) {
+ case Join:
+ if (sorted[i].size() > 1) {
+ eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have joined the chat") : QT_TRANSLATE_NOOP("", "%1% have entered the room"));
+ }
+ else {
+ eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% has joined the chat") : QT_TRANSLATE_NOOP("", "%1% has entered the room"));
+ }
+ break;
+ case Part:
+ if (sorted[i].size() > 1) {
+ eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have left the chat") : QT_TRANSLATE_NOOP("", "%1% have left the room"));
+ }
+ else {
+ eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have left the chat") : QT_TRANSLATE_NOOP("", "%1% has left the room"));
+ }
+ break;
+ case JoinThenPart:
+ if (sorted[i].size() > 1) {
+ eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have joined then left the chat") : QT_TRANSLATE_NOOP("", "%1% have entered then left the room"));
+ }
+ else {
+ eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% has joined then left the chat") : QT_TRANSLATE_NOOP("", "%1% has entered then left the room"));
+ }
+ break;
+ case PartThenJoin:
+ if (sorted[i].size() > 1) {
+ eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have left then returned to the chat") : QT_TRANSLATE_NOOP("", "%1% have left then returned to the room"));
+ }
+ else {
+ eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% has left then returned to the chat") : QT_TRANSLATE_NOOP("", "%1% has left then returned to the room"));
+ }
+ break;
+ }
+ populatedEvents.push_back(static_cast<JoinPart>(i));
+ eventStrings[i] = str(boost::format(eventString) % names);
+ }
+ }
+ for (size_t i = 0; i < populatedEvents.size(); i++) {
+ if (i > 0) {
+ if (i < populatedEvents.size() - 1) {
+ result += ", ";
+ } else {
+ result += QT_TRANSLATE_NOOP("", " and ");
+ }
+ }
+ result += eventStrings[populatedEvents[i]];
+ }
+ return result;
}
std::string MUCController::generateNicknameChangeString(const std::string& oldNickname, const std::string& newNickname) {
- return str(boost::format(QT_TRANSLATE_NOOP("", "%1% is now known as %2%.")) % oldNickname % newNickname);
+ return str(boost::format(QT_TRANSLATE_NOOP("", "%1% is now known as %2%.")) % oldNickname % newNickname);
}
void MUCController::handleChangeSubjectRequest(const std::string& subject) {
- muc_->changeSubject(subject);
+ muc_->changeSubject(subject);
}
void MUCController::handleBookmarkRequest() {
- const JID jid = muc_->getJID();
+ const JID jid = muc_->getJID();
- // Prepare new bookmark for this room.
- MUCBookmark roomBookmark(jid, jid.toBare().toString());
- roomBookmark.setPassword(password_);
- roomBookmark.setNick(nick_);
+ // Prepare new bookmark for this room.
+ MUCBookmark roomBookmark(jid, jid.toBare().toString());
+ roomBookmark.setPassword(password_);
+ roomBookmark.setNick(nick_);
- // Check for existing bookmark for this room and, if it exists, use it instead.
- std::vector<MUCBookmark> bookmarks = mucBookmarkManager_->getBookmarks();
- foreach (const MUCBookmark& bookmark, bookmarks) {
- if (bookmark.getRoom() == jid.toBare()) {
- roomBookmark = bookmark;
- break;
- }
- }
+ // Check for existing bookmark for this room and, if it exists, use it instead.
+ std::vector<MUCBookmark> bookmarks = mucBookmarkManager_->getBookmarks();
+ foreach (const MUCBookmark& bookmark, bookmarks) {
+ if (bookmark.getRoom() == jid.toBare()) {
+ roomBookmark = bookmark;
+ break;
+ }
+ }
- chatWindow_->showBookmarkWindow(roomBookmark);
+ chatWindow_->showBookmarkWindow(roomBookmark);
}
void MUCController::handleConfigureRequest(Form::ref form) {
- if (form) {
- muc_->configureRoom(form);
- }
- else {
- muc_->requestConfigurationForm();
- }
+ if (form) {
+ muc_->configureRoom(form);
+ }
+ else {
+ muc_->requestConfigurationForm();
+ }
}
void MUCController::handleConfigurationFailed(ErrorPayload::ref error) {
- std::string errorMessage = getErrorMessage(error);
- errorMessage = str(format(QT_TRANSLATE_NOOP("", "Room configuration failed: %1%.")) % errorMessage);
- chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
+ std::string errorMessage = getErrorMessage(error);
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "Room configuration failed: %1%.")) % errorMessage);
+ chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
}
void MUCController::handleOccupantRoleChangeFailed(ErrorPayload::ref error, const JID&, MUCOccupant::Role) {
- std::string errorMessage = getErrorMessage(error);
- errorMessage = str(format(QT_TRANSLATE_NOOP("", "Occupant role change failed: %1%.")) % errorMessage);
- chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
+ std::string errorMessage = getErrorMessage(error);
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "Occupant role change failed: %1%.")) % errorMessage);
+ chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
}
void MUCController::configureAsImpromptuRoom(Form::ref form) {
- muc_->configureRoom(buildImpromptuRoomConfiguration(form));
- isImpromptuAlreadyConfigured_ = true;
- onImpromptuConfigCompleted();
+ muc_->configureRoom(buildImpromptuRoomConfiguration(form));
+ isImpromptuAlreadyConfigured_ = true;
+ onImpromptuConfigCompleted();
}
void MUCController::handleConfigurationFormReceived(Form::ref form) {
- if (isImpromptu_) {
- if (!isImpromptuAlreadyConfigured_) {
- configureAsImpromptuRoom(form);
- }
- } else {
- chatWindow_->showRoomConfigurationForm(form);
- }
+ if (isImpromptu_) {
+ if (!isImpromptuAlreadyConfigured_) {
+ configureAsImpromptuRoom(form);
+ }
+ } else {
+ chatWindow_->showRoomConfigurationForm(form);
+ }
}
void MUCController::handleConfigurationCancelled() {
- muc_->cancelConfigureRoom();
+ muc_->cancelConfigureRoom();
}
void MUCController::handleDestroyRoomRequest() {
- muc_->destroyRoom();
+ muc_->destroyRoom();
}
void MUCController::handleInvitePersonToThisMUCRequest(const std::vector<JID>& jidsToInvite) {
- RequestInviteToMUCUIEvent::ImpromptuMode mode = isImpromptu_ ? RequestInviteToMUCUIEvent::Impromptu : RequestInviteToMUCUIEvent::NotImpromptu;
- boost::shared_ptr<UIEvent> event(new RequestInviteToMUCUIEvent(muc_->getJID(), jidsToInvite, mode));
- eventStream_->send(event);
+ RequestInviteToMUCUIEvent::ImpromptuMode mode = isImpromptu_ ? RequestInviteToMUCUIEvent::Impromptu : RequestInviteToMUCUIEvent::NotImpromptu;
+ boost::shared_ptr<UIEvent> event(new RequestInviteToMUCUIEvent(muc_->getJID(), jidsToInvite, mode));
+ eventStream_->send(event);
}
void MUCController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
- boost::shared_ptr<InviteToMUCUIEvent> inviteEvent = boost::dynamic_pointer_cast<InviteToMUCUIEvent>(event);
- if (inviteEvent && inviteEvent->getRoom() == muc_->getJID()) {
- foreach (const JID& jid, inviteEvent->getInvites()) {
- muc_->invitePerson(jid, inviteEvent->getReason(), isImpromptu_);
- }
- }
+ boost::shared_ptr<InviteToMUCUIEvent> inviteEvent = boost::dynamic_pointer_cast<InviteToMUCUIEvent>(event);
+ if (inviteEvent && inviteEvent->getRoom() == muc_->getJID()) {
+ foreach (const JID& jid, inviteEvent->getInvites()) {
+ muc_->invitePerson(jid, inviteEvent->getReason(), isImpromptu_);
+ }
+ }
}
void MUCController::handleGetAffiliationsRequest() {
- muc_->requestAffiliationList(MUCOccupant::Owner);
- muc_->requestAffiliationList(MUCOccupant::Admin);
- muc_->requestAffiliationList(MUCOccupant::Member);
- muc_->requestAffiliationList(MUCOccupant::Outcast);
+ muc_->requestAffiliationList(MUCOccupant::Owner);
+ muc_->requestAffiliationList(MUCOccupant::Admin);
+ muc_->requestAffiliationList(MUCOccupant::Member);
+ muc_->requestAffiliationList(MUCOccupant::Outcast);
}
typedef std::pair<MUCOccupant::Affiliation, JID> AffiliationChangePair;
void MUCController::handleChangeAffiliationsRequest(const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& changes) {
- std::set<JID> addedJIDs;
- foreach (const AffiliationChangePair& change, changes) {
- if (change.first != MUCOccupant::NoAffiliation) {
- addedJIDs.insert(change.second);
- }
- }
- foreach (const AffiliationChangePair& change, changes) {
- if (change.first != MUCOccupant::NoAffiliation || addedJIDs.find(change.second) == addedJIDs.end()) {
- muc_->changeAffiliation(change.second, change.first);
- }
- }
+ std::set<JID> addedJIDs;
+ foreach (const AffiliationChangePair& change, changes) {
+ if (change.first != MUCOccupant::NoAffiliation) {
+ addedJIDs.insert(change.second);
+ }
+ }
+ foreach (const AffiliationChangePair& change, changes) {
+ if (change.first != MUCOccupant::NoAffiliation || addedJIDs.find(change.second) == addedJIDs.end()) {
+ muc_->changeAffiliation(change.second, change.first);
+ }
+ }
}
void MUCController::handleUnblockUserRequest() {
- eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, muc_->getJID()));
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, muc_->getJID()));
}
void MUCController::handleBlockingStateChanged() {
- boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
- if (blockList->getState() == BlockList::Available) {
- if (blockList->isBlocked(toJID_)) {
- if (!blockedContactAlert_) {
- blockedContactAlert_ = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "You've blocked this room. To enter the room, first unblock it using the cog menu and try again"));
- }
- chatWindow_->setBlockingState(ChatWindow::IsBlocked);
- } else {
- if (blockedContactAlert_) {
- chatWindow_->removeAlert(*blockedContactAlert_);
- blockedContactAlert_.reset();
- }
- chatWindow_->setBlockingState(ChatWindow::IsUnblocked);
- }
- }
+ boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
+ if (blockList->getState() == BlockList::Available) {
+ if (blockList->isBlocked(toJID_)) {
+ if (!blockedContactAlert_) {
+ blockedContactAlert_ = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "You've blocked this room. To enter the room, first unblock it using the cog menu and try again"));
+ }
+ chatWindow_->setBlockingState(ChatWindow::IsBlocked);
+ } else {
+ if (blockedContactAlert_) {
+ chatWindow_->removeAlert(*blockedContactAlert_);
+ blockedContactAlert_.reset();
+ }
+ chatWindow_->setBlockingState(ChatWindow::IsUnblocked);
+ }
+ }
}
void MUCController::handleAffiliationListReceived(MUCOccupant::Affiliation affiliation, const std::vector<JID>& jids) {
- chatWindow_->setAffiliations(affiliation, jids);
+ chatWindow_->setAffiliations(affiliation, jids);
}
void MUCController::logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) {
- // log only incoming messages
- if (isIncoming && historyController_) {
- historyController_->addMessage(message, fromJID, toJID, HistoryMessage::Groupchat, timeStamp);
- }
+ // log only incoming messages
+ if (isIncoming && historyController_) {
+ historyController_->addMessage(message, fromJID, toJID, HistoryMessage::Groupchat, timeStamp);
+ }
}
void MUCController::addRecentLogs() {
- if (!historyController_) {
- return;
- }
+ if (!historyController_) {
+ return;
+ }
- joinContext_ = historyController_->getMUCContext(selfJID_, toJID_, lastActivity_);
+ joinContext_ = historyController_->getMUCContext(selfJID_, toJID_, lastActivity_);
- foreach (const HistoryMessage& message, joinContext_) {
- bool senderIsSelf = nick_ == message.getFromJID().getResource();
+ foreach (const HistoryMessage& message, joinContext_) {
+ bool senderIsSelf = nick_ == message.getFromJID().getResource();
- // the chatWindow uses utc timestamps
- addMessage(chatMessageParser_->parseMessageBody(message.getMessage()), senderDisplayNameFromMessage(message.getFromJID()), senderIsSelf, boost::shared_ptr<SecurityLabel>(new SecurityLabel()), avatarManager_->getAvatarPath(message.getFromJID()), message.getTime() - boost::posix_time::hours(message.getOffset()));
- }
+ // the chatWindow uses utc timestamps
+ addMessage(chatMessageParser_->parseMessageBody(message.getMessage()), senderDisplayNameFromMessage(message.getFromJID()), senderIsSelf, boost::shared_ptr<SecurityLabel>(new SecurityLabel()), avatarManager_->getAvatarPath(message.getFromJID()), message.getTime() - boost::posix_time::hours(message.getOffset()));
+ }
}
void MUCController::checkDuplicates(boost::shared_ptr<Message> newMessage) {
- std::string body = newMessage->getBody().get_value_or("");
- JID jid = newMessage->getFrom();
- boost::optional<boost::posix_time::ptime> time = newMessage->getTimestamp();
-
- reverse_foreach (const HistoryMessage& message, joinContext_) {
- boost::posix_time::ptime messageTime = message.getTime() - boost::posix_time::hours(message.getOffset());
- if (time && time < messageTime) {
- break;
- }
- if (time && time != messageTime) {
- continue;
- }
- if (message.getFromJID() != jid) {
- continue;
- }
- if (message.getMessage() != body) {
- continue;
- }
-
- // Mark the message as unreadable
- newMessage->setBody("");
- }
+ std::string body = newMessage->getBody().get_value_or("");
+ JID jid = newMessage->getFrom();
+ boost::optional<boost::posix_time::ptime> time = newMessage->getTimestamp();
+
+ reverse_foreach (const HistoryMessage& message, joinContext_) {
+ boost::posix_time::ptime messageTime = message.getTime() - boost::posix_time::hours(message.getOffset());
+ if (time && time < messageTime) {
+ break;
+ }
+ if (time && time != messageTime) {
+ continue;
+ }
+ if (message.getFromJID() != jid) {
+ continue;
+ }
+ if (message.getMessage() != body) {
+ continue;
+ }
+
+ // Mark the message as unreadable
+ newMessage->setBody("");
+ }
}
void MUCController::setNick(const std::string& nick) {
- nick_ = nick;
- highlighter_->setNick(nick_);
+ nick_ = nick;
+ highlighter_->setNick(nick_);
}
Form::ref MUCController::buildImpromptuRoomConfiguration(Form::ref roomConfigurationForm) {
- Form::ref result = boost::make_shared<Form>(Form::SubmitType);
- std::string impromptuConfigs[] = { "muc#roomconfig_enablelogging", "muc#roomconfig_persistentroom", "muc#roomconfig_publicroom", "muc#roomconfig_whois"};
- std::set<std::string> impromptuConfigsMissing(impromptuConfigs, impromptuConfigs + 4);
- foreach (boost::shared_ptr<FormField> field, roomConfigurationForm->getFields()) {
- boost::shared_ptr<FormField> resultField;
- if (field->getName() == "muc#roomconfig_enablelogging") {
- resultField = boost::make_shared<FormField>(FormField::BooleanType, "0");
- }
- if (field->getName() == "muc#roomconfig_persistentroom") {
- resultField = boost::make_shared<FormField>(FormField::BooleanType, "0");
- }
- if (field->getName() == "muc#roomconfig_publicroom") {
- resultField = boost::make_shared<FormField>(FormField::BooleanType, "0");
- }
- if (field->getName() == "muc#roomconfig_whois") {
- resultField = boost::make_shared<FormField>(FormField::ListSingleType, "anyone");
- }
-
- if (field->getName() == "FORM_TYPE") {
- resultField = boost::make_shared<FormField>(FormField::HiddenType, "http://jabber.org/protocol/muc#roomconfig");
- }
-
- if (resultField) {
- impromptuConfigsMissing.erase(field->getName());
- resultField->setName(field->getName());
- result->addField(resultField);
- }
- }
-
- foreach (const std::string& config, impromptuConfigsMissing) {
- if (config == "muc#roomconfig_publicroom") {
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support hiding your chat from other users.")), ChatWindow::DefaultDirection);
- } else if (config == "muc#roomconfig_whois") {
- chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support sharing people's real identity in this chat.")), ChatWindow::DefaultDirection);
- }
- }
-
- return result;
+ Form::ref result = boost::make_shared<Form>(Form::SubmitType);
+ std::string impromptuConfigs[] = { "muc#roomconfig_enablelogging", "muc#roomconfig_persistentroom", "muc#roomconfig_publicroom", "muc#roomconfig_whois"};
+ std::set<std::string> impromptuConfigsMissing(impromptuConfigs, impromptuConfigs + 4);
+ foreach (boost::shared_ptr<FormField> field, roomConfigurationForm->getFields()) {
+ boost::shared_ptr<FormField> resultField;
+ if (field->getName() == "muc#roomconfig_enablelogging") {
+ resultField = boost::make_shared<FormField>(FormField::BooleanType, "0");
+ }
+ if (field->getName() == "muc#roomconfig_persistentroom") {
+ resultField = boost::make_shared<FormField>(FormField::BooleanType, "0");
+ }
+ if (field->getName() == "muc#roomconfig_publicroom") {
+ resultField = boost::make_shared<FormField>(FormField::BooleanType, "0");
+ }
+ if (field->getName() == "muc#roomconfig_whois") {
+ resultField = boost::make_shared<FormField>(FormField::ListSingleType, "anyone");
+ }
+
+ if (field->getName() == "FORM_TYPE") {
+ resultField = boost::make_shared<FormField>(FormField::HiddenType, "http://jabber.org/protocol/muc#roomconfig");
+ }
+
+ if (resultField) {
+ impromptuConfigsMissing.erase(field->getName());
+ resultField->setName(field->getName());
+ result->addField(resultField);
+ }
+ }
+
+ foreach (const std::string& config, impromptuConfigsMissing) {
+ if (config == "muc#roomconfig_publicroom") {
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support hiding your chat from other users.")), ChatWindow::DefaultDirection);
+ } else if (config == "muc#roomconfig_whois") {
+ chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support sharing people's real identity in this chat.")), ChatWindow::DefaultDirection);
+ }
+ }
+
+ return result;
}
void MUCController::setImpromptuWindowTitle() {
- std::string title;
- typedef std::pair<std::string, MUCOccupant> StringMUCOccupantPair;
- std::map<std::string, MUCOccupant> occupants = muc_->getOccupants();
- if (occupants.size() <= 1) {
- title = QT_TRANSLATE_NOOP("", "Empty Chat");
- } else {
- foreach (StringMUCOccupantPair pair, occupants) {
- if (pair.first != nick_) {
- title += (title.empty() ? "" : ", ") + pair.first;
- }
- }
- }
- chatWindow_->setName(title);
+ std::string title;
+ typedef std::pair<std::string, MUCOccupant> StringMUCOccupantPair;
+ std::map<std::string, MUCOccupant> occupants = muc_->getOccupants();
+ if (occupants.size() <= 1) {
+ title = QT_TRANSLATE_NOOP("", "Empty Chat");
+ } else {
+ foreach (StringMUCOccupantPair pair, occupants) {
+ if (pair.first != nick_) {
+ title += (title.empty() ? "" : ", ") + pair.first;
+ }
+ }
+ }
+ chatWindow_->setName(title);
}
void MUCController::handleRoomUnlocked() {
- // Handle buggy MUC implementations where the joined room already exists and is unlocked.
- // Configure the room again in this case.
- if (!isImpromptuAlreadyConfigured_) {
- if (isImpromptu_ && (muc_->getOccupant(nick_).getAffiliation() == MUCOccupant::Owner)) {
- muc_->requestConfigurationForm();
- } else if (isImpromptu_) {
- onImpromptuConfigCompleted();
- }
- }
+ // Handle buggy MUC implementations where the joined room already exists and is unlocked.
+ // Configure the room again in this case.
+ if (!isImpromptuAlreadyConfigured_) {
+ if (isImpromptu_ && (muc_->getOccupant(nick_).getAffiliation() == MUCOccupant::Owner)) {
+ muc_->requestConfigurationForm();
+ } else if (isImpromptu_) {
+ onImpromptuConfigCompleted();
+ }
+ }
}
void MUCController::setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info) {
- ChatControllerBase::setAvailableServerFeatures(info);
- if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::BlockingCommandFeature)) {
- boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
+ ChatControllerBase::setAvailableServerFeatures(info);
+ if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::BlockingCommandFeature)) {
+ boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
- blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
- blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
- blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
+ blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
+ blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
+ blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
- handleBlockingStateChanged();
- }
+ handleBlockingStateChanged();
+ }
}
void MUCController::handleMUCBookmarkAdded(const MUCBookmark& bookmark) {
- if (bookmark.getRoom() == muc_->getJID()) {
- updateChatWindowBookmarkStatus(bookmark);
- }
+ if (bookmark.getRoom() == muc_->getJID()) {
+ updateChatWindowBookmarkStatus(bookmark);
+ }
}
void MUCController::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) {
- if (bookmark.getRoom() == muc_->getJID()) {
- updateChatWindowBookmarkStatus(boost::optional<MUCBookmark>());
- }
+ if (bookmark.getRoom() == muc_->getJID()) {
+ updateChatWindowBookmarkStatus(boost::optional<MUCBookmark>());
+ }
}
void MUCController::updateChatWindowBookmarkStatus(const boost::optional<MUCBookmark>& bookmark) {
- assert(chatWindow_);
- if (bookmark) {
- if (bookmark->getAutojoin()) {
- chatWindow_->setBookmarkState(ChatWindow::RoomAutoJoined);
- }
- else {
- chatWindow_->setBookmarkState(ChatWindow::RoomBookmarked);
- }
- }
- else {
- chatWindow_->setBookmarkState(ChatWindow::RoomNotBookmarked);
- }
+ assert(chatWindow_);
+ if (bookmark) {
+ if (bookmark->getAutojoin()) {
+ chatWindow_->setBookmarkState(ChatWindow::RoomAutoJoined);
+ }
+ else {
+ chatWindow_->setBookmarkState(ChatWindow::RoomBookmarked);
+ }
+ }
+ else {
+ chatWindow_->setBookmarkState(ChatWindow::RoomNotBookmarked);
+ }
}
}
diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h
index 0fb739a..3a61952 100644
--- a/Swift/Controllers/Chat/MUCController.h
+++ b/Swift/Controllers/Chat/MUCController.h
@@ -27,159 +27,159 @@
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
namespace Swift {
- class StanzaChannel;
- class IQRouter;
- class ChatWindowFactory;
- class Roster;
- class AvatarManager;
- class UIEventStream;
- class TimerFactory;
- class TabComplete;
- class XMPPRoster;
- class HighlightManager;
- class UIEvent;
- class VCardManager;
- class RosterVCardProvider;
- class ClientBlockListManager;
- class MUCBookmarkManager;
- class MUCBookmark;
-
- enum JoinPart {Join, Part, JoinThenPart, PartThenJoin};
-
- struct NickJoinPart {
- NickJoinPart(const std::string& nick, JoinPart type) : nick(nick), type(type) {}
- std::string nick;
- JoinPart type;
- };
-
- class MUCController : public ChatControllerBase {
- public:
- MUCController(const JID& self, MUC::ref muc, const boost::optional<std::string>& password, const std::string &nick, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, PresenceOracle* presenceOracle, AvatarManager* avatarManager, UIEventStream* events, bool useDelayForLatency, TimerFactory* timerFactory, EventController* eventController, EntityCapsProvider* entityCapsProvider, XMPPRoster* roster, HistoryController* historyController, MUCRegistry* mucRegistry, HighlightManager* highlightManager, ClientBlockListManager* clientBlockListManager, boost::shared_ptr<ChatMessageParser> chatMessageParser, bool isImpromptu, AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider, VCardManager* vcardManager, MUCBookmarkManager* mucBookmarkManager);
- virtual ~MUCController();
- boost::signal<void ()> onUserLeft;
- boost::signal<void ()> onUserJoined;
- boost::signal<void ()> onImpromptuConfigCompleted;
- boost::signal<void (const std::string&, const std::string& )> onUserNicknameChanged;
- virtual void setOnline(bool online) SWIFTEN_OVERRIDE;
- virtual void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info) SWIFTEN_OVERRIDE;
- void rejoin();
- static void appendToJoinParts(std::vector<NickJoinPart>& joinParts, const NickJoinPart& newEvent);
- static std::string generateJoinPartString(const std::vector<NickJoinPart>& joinParts, bool isImpromptu);
- static std::string concatenateListOfNames(const std::vector<NickJoinPart>& joinParts);
- static std::string generateNicknameChangeString(const std::string& oldNickname, const std::string& newNickname);
- bool isJoined();
- const std::string& getNick();
- const boost::optional<std::string> getPassword() const;
- bool isImpromptu() const;
- std::map<std::string, JID> getParticipantJIDs() const;
- void sendInvites(const std::vector<JID>& jids, const std::string& reason) const;
-
- protected:
- virtual void preSendMessageRequest(boost::shared_ptr<Message> message) SWIFTEN_OVERRIDE;
- virtual bool isIncomingMessageFromMe(boost::shared_ptr<Message> message) SWIFTEN_OVERRIDE;
- virtual std::string senderHighlightNameFromMessage(const JID& from) SWIFTEN_OVERRIDE;
- virtual std::string senderDisplayNameFromMessage(const JID& from) SWIFTEN_OVERRIDE;
- virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message> message) const SWIFTEN_OVERRIDE;
- virtual void preHandleIncomingMessage(boost::shared_ptr<MessageEvent>) SWIFTEN_OVERRIDE;
- virtual void addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
- virtual void postHandleIncomingMessage(boost::shared_ptr<MessageEvent>, const ChatWindow::ChatMessage& chatMessage) SWIFTEN_OVERRIDE;
- virtual void cancelReplaces() SWIFTEN_OVERRIDE;
- virtual void logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) SWIFTEN_OVERRIDE;
-
- private:
- void setAvailableRoomActions(const MUCOccupant::Affiliation& affiliation, const MUCOccupant::Role& role);
- void clearPresenceQueue();
- void addPresenceMessage(const std::string& message);
- void handleWindowOccupantSelectionChanged(ContactRosterItem* item);
- void handleActionRequestedOnOccupant(ChatWindow::OccupantAction, ContactRosterItem* item);
- void handleWindowClosed();
- void handleAvatarChanged(const JID& jid);
- void handleOccupantJoined(const MUCOccupant& occupant);
- void handleOccupantNicknameChanged(const std::string& oldNickname, const std::string& newNickname);
- void handleOccupantLeft(const MUCOccupant& occupant, MUC::LeavingType type, const std::string& reason);
- void handleOccupantPresenceChange(boost::shared_ptr<Presence> presence);
- void handleOccupantRoleChanged(const std::string& nick, const MUCOccupant& occupant,const MUCOccupant::Role& oldRole);
- void handleOccupantAffiliationChanged(const std::string& nick, const MUCOccupant::Affiliation& affiliation,const MUCOccupant::Affiliation& oldAffiliation);
- void handleJoinComplete(const std::string& nick);
- void handleJoinFailed(boost::shared_ptr<ErrorPayload> error);
- void handleJoinTimeoutTick();
- void handleChangeSubjectRequest(const std::string&);
- void handleBookmarkRequest();
- std::string roleToGroupName(MUCOccupant::Role role);
- std::string roleToSortName(MUCOccupant::Role role);
- JID nickToJID(const std::string& nick);
- std::string roleToFriendlyName(MUCOccupant::Role role);
- void receivedActivity();
- bool messageTargetsMe(boost::shared_ptr<Message> message);
- void updateJoinParts();
- bool shouldUpdateJoinParts();
- virtual void dayTicked() SWIFTEN_OVERRIDE { clearPresenceQueue(); }
- void processUserPart();
- virtual void handleBareJIDCapsChanged(const JID& jid) SWIFTEN_OVERRIDE;
- void handleConfigureRequest(Form::ref);
- void handleConfigurationFailed(ErrorPayload::ref);
- void handleConfigurationFormReceived(Form::ref);
- void handleDestroyRoomRequest();
- void handleInvitePersonToThisMUCRequest(const std::vector<JID>& jidsToInvite);
- void handleConfigurationCancelled();
- void handleOccupantRoleChangeFailed(ErrorPayload::ref, const JID&, MUCOccupant::Role);
- void handleGetAffiliationsRequest();
- void handleAffiliationListReceived(MUCOccupant::Affiliation affiliation, const std::vector<JID>& jids);
- void handleChangeAffiliationsRequest(const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& changes);
- void handleInviteToMUCWindowDismissed();
- void handleInviteToMUCWindowCompleted();
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void addRecentLogs();
- void checkDuplicates(boost::shared_ptr<Message> newMessage);
- void setNick(const std::string& nick);
- void setImpromptuWindowTitle();
- void handleRoomUnlocked();
- void configureAsImpromptuRoom(Form::ref form);
- Form::ref buildImpromptuRoomConfiguration(Form::ref roomConfigurationForm);
-
- void handleUnblockUserRequest();
- void handleBlockingStateChanged();
-
- void handleMUCBookmarkAdded(const MUCBookmark& bookmark);
- void handleMUCBookmarkRemoved(const MUCBookmark& bookmark);
- void updateChatWindowBookmarkStatus(const boost::optional<MUCBookmark>& bookmark);
-
- private:
- MUC::ref muc_;
- UIEventStream* events_;
- std::string nick_;
- std::string desiredNick_;
- Roster* roster_;
- TabComplete* completer_;
- bool parting_;
- bool joined_;
- bool lastWasPresence_;
- bool shouldJoinOnReconnect_;
- bool doneGettingHistory_;
- boost::bsignals::scoped_connection avatarChangedConnection_;
- boost::shared_ptr<Timer> loginCheckTimer_;
- std::set<std::string> currentOccupants_;
- std::vector<NickJoinPart> joinParts_;
- boost::posix_time::ptime lastActivity_;
- boost::optional<std::string> password_;
- XMPPRoster* xmppRoster_;
- std::vector<HistoryMessage> joinContext_;
- size_t renameCounter_;
- bool isImpromptu_;
- bool isImpromptuAlreadyConfigured_;
- RosterVCardProvider* rosterVCardProvider_;
- std::string lastJoinMessageUID_;
-
- ClientBlockListManager* clientBlockListManager_;
- boost::bsignals::scoped_connection blockingOnStateChangedConnection_;
- boost::bsignals::scoped_connection blockingOnItemAddedConnection_;
- boost::bsignals::scoped_connection blockingOnItemRemovedConnection_;
-
- boost::optional<ChatWindow::AlertID> blockedContactAlert_;
-
- MUCBookmarkManager* mucBookmarkManager_;
- boost::bsignals::scoped_connection mucBookmarkManagerBookmarkAddedConnection_;
- boost::bsignals::scoped_connection mucBookmarkManagerBookmarkRemovedConnection_;
- };
+ class StanzaChannel;
+ class IQRouter;
+ class ChatWindowFactory;
+ class Roster;
+ class AvatarManager;
+ class UIEventStream;
+ class TimerFactory;
+ class TabComplete;
+ class XMPPRoster;
+ class HighlightManager;
+ class UIEvent;
+ class VCardManager;
+ class RosterVCardProvider;
+ class ClientBlockListManager;
+ class MUCBookmarkManager;
+ class MUCBookmark;
+
+ enum JoinPart {Join, Part, JoinThenPart, PartThenJoin};
+
+ struct NickJoinPart {
+ NickJoinPart(const std::string& nick, JoinPart type) : nick(nick), type(type) {}
+ std::string nick;
+ JoinPart type;
+ };
+
+ class MUCController : public ChatControllerBase {
+ public:
+ MUCController(const JID& self, MUC::ref muc, const boost::optional<std::string>& password, const std::string &nick, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, PresenceOracle* presenceOracle, AvatarManager* avatarManager, UIEventStream* events, bool useDelayForLatency, TimerFactory* timerFactory, EventController* eventController, EntityCapsProvider* entityCapsProvider, XMPPRoster* roster, HistoryController* historyController, MUCRegistry* mucRegistry, HighlightManager* highlightManager, ClientBlockListManager* clientBlockListManager, boost::shared_ptr<ChatMessageParser> chatMessageParser, bool isImpromptu, AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider, VCardManager* vcardManager, MUCBookmarkManager* mucBookmarkManager);
+ virtual ~MUCController();
+ boost::signal<void ()> onUserLeft;
+ boost::signal<void ()> onUserJoined;
+ boost::signal<void ()> onImpromptuConfigCompleted;
+ boost::signal<void (const std::string&, const std::string& )> onUserNicknameChanged;
+ virtual void setOnline(bool online) SWIFTEN_OVERRIDE;
+ virtual void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info) SWIFTEN_OVERRIDE;
+ void rejoin();
+ static void appendToJoinParts(std::vector<NickJoinPart>& joinParts, const NickJoinPart& newEvent);
+ static std::string generateJoinPartString(const std::vector<NickJoinPart>& joinParts, bool isImpromptu);
+ static std::string concatenateListOfNames(const std::vector<NickJoinPart>& joinParts);
+ static std::string generateNicknameChangeString(const std::string& oldNickname, const std::string& newNickname);
+ bool isJoined();
+ const std::string& getNick();
+ const boost::optional<std::string> getPassword() const;
+ bool isImpromptu() const;
+ std::map<std::string, JID> getParticipantJIDs() const;
+ void sendInvites(const std::vector<JID>& jids, const std::string& reason) const;
+
+ protected:
+ virtual void preSendMessageRequest(boost::shared_ptr<Message> message) SWIFTEN_OVERRIDE;
+ virtual bool isIncomingMessageFromMe(boost::shared_ptr<Message> message) SWIFTEN_OVERRIDE;
+ virtual std::string senderHighlightNameFromMessage(const JID& from) SWIFTEN_OVERRIDE;
+ virtual std::string senderDisplayNameFromMessage(const JID& from) SWIFTEN_OVERRIDE;
+ virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message> message) const SWIFTEN_OVERRIDE;
+ virtual void preHandleIncomingMessage(boost::shared_ptr<MessageEvent>) SWIFTEN_OVERRIDE;
+ virtual void addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
+ virtual void postHandleIncomingMessage(boost::shared_ptr<MessageEvent>, const ChatWindow::ChatMessage& chatMessage) SWIFTEN_OVERRIDE;
+ virtual void cancelReplaces() SWIFTEN_OVERRIDE;
+ virtual void logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) SWIFTEN_OVERRIDE;
+
+ private:
+ void setAvailableRoomActions(const MUCOccupant::Affiliation& affiliation, const MUCOccupant::Role& role);
+ void clearPresenceQueue();
+ void addPresenceMessage(const std::string& message);
+ void handleWindowOccupantSelectionChanged(ContactRosterItem* item);
+ void handleActionRequestedOnOccupant(ChatWindow::OccupantAction, ContactRosterItem* item);
+ void handleWindowClosed();
+ void handleAvatarChanged(const JID& jid);
+ void handleOccupantJoined(const MUCOccupant& occupant);
+ void handleOccupantNicknameChanged(const std::string& oldNickname, const std::string& newNickname);
+ void handleOccupantLeft(const MUCOccupant& occupant, MUC::LeavingType type, const std::string& reason);
+ void handleOccupantPresenceChange(boost::shared_ptr<Presence> presence);
+ void handleOccupantRoleChanged(const std::string& nick, const MUCOccupant& occupant,const MUCOccupant::Role& oldRole);
+ void handleOccupantAffiliationChanged(const std::string& nick, const MUCOccupant::Affiliation& affiliation,const MUCOccupant::Affiliation& oldAffiliation);
+ void handleJoinComplete(const std::string& nick);
+ void handleJoinFailed(boost::shared_ptr<ErrorPayload> error);
+ void handleJoinTimeoutTick();
+ void handleChangeSubjectRequest(const std::string&);
+ void handleBookmarkRequest();
+ std::string roleToGroupName(MUCOccupant::Role role);
+ std::string roleToSortName(MUCOccupant::Role role);
+ JID nickToJID(const std::string& nick);
+ std::string roleToFriendlyName(MUCOccupant::Role role);
+ void receivedActivity();
+ bool messageTargetsMe(boost::shared_ptr<Message> message);
+ void updateJoinParts();
+ bool shouldUpdateJoinParts();
+ virtual void dayTicked() SWIFTEN_OVERRIDE { clearPresenceQueue(); }
+ void processUserPart();
+ virtual void handleBareJIDCapsChanged(const JID& jid) SWIFTEN_OVERRIDE;
+ void handleConfigureRequest(Form::ref);
+ void handleConfigurationFailed(ErrorPayload::ref);
+ void handleConfigurationFormReceived(Form::ref);
+ void handleDestroyRoomRequest();
+ void handleInvitePersonToThisMUCRequest(const std::vector<JID>& jidsToInvite);
+ void handleConfigurationCancelled();
+ void handleOccupantRoleChangeFailed(ErrorPayload::ref, const JID&, MUCOccupant::Role);
+ void handleGetAffiliationsRequest();
+ void handleAffiliationListReceived(MUCOccupant::Affiliation affiliation, const std::vector<JID>& jids);
+ void handleChangeAffiliationsRequest(const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& changes);
+ void handleInviteToMUCWindowDismissed();
+ void handleInviteToMUCWindowCompleted();
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void addRecentLogs();
+ void checkDuplicates(boost::shared_ptr<Message> newMessage);
+ void setNick(const std::string& nick);
+ void setImpromptuWindowTitle();
+ void handleRoomUnlocked();
+ void configureAsImpromptuRoom(Form::ref form);
+ Form::ref buildImpromptuRoomConfiguration(Form::ref roomConfigurationForm);
+
+ void handleUnblockUserRequest();
+ void handleBlockingStateChanged();
+
+ void handleMUCBookmarkAdded(const MUCBookmark& bookmark);
+ void handleMUCBookmarkRemoved(const MUCBookmark& bookmark);
+ void updateChatWindowBookmarkStatus(const boost::optional<MUCBookmark>& bookmark);
+
+ private:
+ MUC::ref muc_;
+ UIEventStream* events_;
+ std::string nick_;
+ std::string desiredNick_;
+ Roster* roster_;
+ TabComplete* completer_;
+ bool parting_;
+ bool joined_;
+ bool lastWasPresence_;
+ bool shouldJoinOnReconnect_;
+ bool doneGettingHistory_;
+ boost::bsignals::scoped_connection avatarChangedConnection_;
+ boost::shared_ptr<Timer> loginCheckTimer_;
+ std::set<std::string> currentOccupants_;
+ std::vector<NickJoinPart> joinParts_;
+ boost::posix_time::ptime lastActivity_;
+ boost::optional<std::string> password_;
+ XMPPRoster* xmppRoster_;
+ std::vector<HistoryMessage> joinContext_;
+ size_t renameCounter_;
+ bool isImpromptu_;
+ bool isImpromptuAlreadyConfigured_;
+ RosterVCardProvider* rosterVCardProvider_;
+ std::string lastJoinMessageUID_;
+
+ ClientBlockListManager* clientBlockListManager_;
+ boost::bsignals::scoped_connection blockingOnStateChangedConnection_;
+ boost::bsignals::scoped_connection blockingOnItemAddedConnection_;
+ boost::bsignals::scoped_connection blockingOnItemRemovedConnection_;
+
+ boost::optional<ChatWindow::AlertID> blockedContactAlert_;
+
+ MUCBookmarkManager* mucBookmarkManager_;
+ boost::bsignals::scoped_connection mucBookmarkManagerBookmarkAddedConnection_;
+ boost::bsignals::scoped_connection mucBookmarkManagerBookmarkRemovedConnection_;
+ };
}
diff --git a/Swift/Controllers/Chat/MUCSearchController.cpp b/Swift/Controllers/Chat/MUCSearchController.cpp
index 702a366..884978c 100644
--- a/Swift/Controllers/Chat/MUCSearchController.cpp
+++ b/Swift/Controllers/Chat/MUCSearchController.cpp
@@ -26,159 +26,159 @@ namespace Swift {
static const std::string SEARCHED_SERVICES = "searchedServices";
MUCSearchController::MUCSearchController(const JID& jid, MUCSearchWindowFactory* factory, IQRouter* iqRouter, ProfileSettingsProvider* settings) : jid_(jid), factory_(factory), iqRouter_(iqRouter), settings_(settings), window_(NULL), walker_(NULL) {
- itemsInProgress_ = 0;
- loadSavedServices();
+ itemsInProgress_ = 0;
+ loadSavedServices();
}
MUCSearchController::~MUCSearchController() {
- delete walker_;
- delete window_;
+ delete walker_;
+ delete window_;
}
void MUCSearchController::openSearchWindow() {
- if (!window_) {
- window_ = factory_->createMUCSearchWindow();
- window_->onSearchService.connect(boost::bind(&MUCSearchController::handleSearchService, this, _1));
- window_->onFinished.connect(boost::bind(&MUCSearchController::handleMUCSearchFinished, this, _1));
- window_->addSavedServices(savedServices_);
- }
- handleSearchService(JID(jid_.getDomain()));
- window_->show();
+ if (!window_) {
+ window_ = factory_->createMUCSearchWindow();
+ window_->onSearchService.connect(boost::bind(&MUCSearchController::handleSearchService, this, _1));
+ window_->onFinished.connect(boost::bind(&MUCSearchController::handleMUCSearchFinished, this, _1));
+ window_->addSavedServices(savedServices_);
+ }
+ handleSearchService(JID(jid_.getDomain()));
+ window_->show();
}
void MUCSearchController::loadSavedServices() {
- savedServices_.clear();
- foreach (std::string stringItem, String::split(settings_->getStringSetting(SEARCHED_SERVICES), '\n')) {
- savedServices_.push_back(JID(stringItem));
- }
+ savedServices_.clear();
+ foreach (std::string stringItem, String::split(settings_->getStringSetting(SEARCHED_SERVICES), '\n')) {
+ savedServices_.push_back(JID(stringItem));
+ }
}
void MUCSearchController::addToSavedServices(const JID& jid) {
- savedServices_.erase(std::remove(savedServices_.begin(), savedServices_.end(), jid), savedServices_.end());
- savedServices_.push_front(jid);
-
- std::string collapsed;
- int i = 0;
- foreach (JID jidItem, savedServices_) {
- if (i >= 15) {
- break;
- }
- if (!collapsed.empty()) {
- collapsed += "\n";
- }
- collapsed += jidItem.toString();
- ++i;
- }
- settings_->storeString(SEARCHED_SERVICES, collapsed);
- window_->addSavedServices(savedServices_);
+ savedServices_.erase(std::remove(savedServices_.begin(), savedServices_.end(), jid), savedServices_.end());
+ savedServices_.push_front(jid);
+
+ std::string collapsed;
+ int i = 0;
+ foreach (JID jidItem, savedServices_) {
+ if (i >= 15) {
+ break;
+ }
+ if (!collapsed.empty()) {
+ collapsed += "\n";
+ }
+ collapsed += jidItem.toString();
+ ++i;
+ }
+ settings_->storeString(SEARCHED_SERVICES, collapsed);
+ window_->addSavedServices(savedServices_);
}
void MUCSearchController::handleSearchService(const JID& jid) {
- if (!jid.isValid()) {
- //Set Window to say error this isn't valid
- return;
- }
- addToSavedServices(jid);
-
- services_.clear();
- serviceDetails_.clear();
-
- window_->setSearchInProgress(true);
- refreshView();
-
- if (walker_) {
- walker_->endWalk();
- walker_->onServiceFound.disconnect(boost::bind(&MUCSearchController::handleDiscoServiceFound, this, _1, _2));
- walker_->onWalkComplete.disconnect(boost::bind(&MUCSearchController::handleDiscoWalkFinished, this));
- delete walker_;
- }
-
- SWIFT_LOG(debug) << "Starting walking MUC services" << std::endl;
- itemsInProgress_ = 0;
- walker_ = new DiscoServiceWalker(jid, iqRouter_);
- walker_->onServiceFound.connect(boost::bind(&MUCSearchController::handleDiscoServiceFound, this, _1, _2));
- walker_->onWalkComplete.connect(boost::bind(&MUCSearchController::handleDiscoWalkFinished, this));
- walker_->beginWalk();
+ if (!jid.isValid()) {
+ //Set Window to say error this isn't valid
+ return;
+ }
+ addToSavedServices(jid);
+
+ services_.clear();
+ serviceDetails_.clear();
+
+ window_->setSearchInProgress(true);
+ refreshView();
+
+ if (walker_) {
+ walker_->endWalk();
+ walker_->onServiceFound.disconnect(boost::bind(&MUCSearchController::handleDiscoServiceFound, this, _1, _2));
+ walker_->onWalkComplete.disconnect(boost::bind(&MUCSearchController::handleDiscoWalkFinished, this));
+ delete walker_;
+ }
+
+ SWIFT_LOG(debug) << "Starting walking MUC services" << std::endl;
+ itemsInProgress_ = 0;
+ walker_ = new DiscoServiceWalker(jid, iqRouter_);
+ walker_->onServiceFound.connect(boost::bind(&MUCSearchController::handleDiscoServiceFound, this, _1, _2));
+ walker_->onWalkComplete.connect(boost::bind(&MUCSearchController::handleDiscoWalkFinished, this));
+ walker_->beginWalk();
}
void MUCSearchController::handleDiscoServiceFound(const JID& jid, boost::shared_ptr<DiscoInfo> info) {
- bool isMUC = false;
- std::string name;
- foreach (DiscoInfo::Identity identity, info->getIdentities()) {
- if ((identity.getCategory() == "directory"
- && identity.getType() == "chatroom")
- || (identity.getCategory() == "conference"
- && identity.getType() == "text")) {
- isMUC = true;
- name = identity.getName();
- }
- }
- if (isMUC) {
- SWIFT_LOG(debug) << "MUC Service found: " << jid << std::endl;
- services_.erase(std::remove(services_.begin(), services_.end(), jid), services_.end());
- services_.push_back(jid);
- serviceDetails_[jid].setName(name);
- serviceDetails_[jid].setJID(jid);
- serviceDetails_[jid].setComplete(false);
- itemsInProgress_++;
- SWIFT_LOG(debug) << "Requesting items of " << jid << " (" << itemsInProgress_ << " item requests in progress)" << std::endl;
- GetDiscoItemsRequest::ref discoItemsRequest = GetDiscoItemsRequest::create(jid, iqRouter_);
- discoItemsRequest->onResponse.connect(boost::bind(&MUCSearchController::handleRoomsItemsResponse, this, _1, _2, jid));
- discoItemsRequest->send();
- }
- else {
- removeService(jid);
- }
- refreshView();
+ bool isMUC = false;
+ std::string name;
+ foreach (DiscoInfo::Identity identity, info->getIdentities()) {
+ if ((identity.getCategory() == "directory"
+ && identity.getType() == "chatroom")
+ || (identity.getCategory() == "conference"
+ && identity.getType() == "text")) {
+ isMUC = true;
+ name = identity.getName();
+ }
+ }
+ if (isMUC) {
+ SWIFT_LOG(debug) << "MUC Service found: " << jid << std::endl;
+ services_.erase(std::remove(services_.begin(), services_.end(), jid), services_.end());
+ services_.push_back(jid);
+ serviceDetails_[jid].setName(name);
+ serviceDetails_[jid].setJID(jid);
+ serviceDetails_[jid].setComplete(false);
+ itemsInProgress_++;
+ SWIFT_LOG(debug) << "Requesting items of " << jid << " (" << itemsInProgress_ << " item requests in progress)" << std::endl;
+ GetDiscoItemsRequest::ref discoItemsRequest = GetDiscoItemsRequest::create(jid, iqRouter_);
+ discoItemsRequest->onResponse.connect(boost::bind(&MUCSearchController::handleRoomsItemsResponse, this, _1, _2, jid));
+ discoItemsRequest->send();
+ }
+ else {
+ removeService(jid);
+ }
+ refreshView();
}
void MUCSearchController::handleDiscoWalkFinished() {
- SWIFT_LOG(debug) << "MUC Walk finished" << std::endl;
- updateInProgressness();
+ SWIFT_LOG(debug) << "MUC Walk finished" << std::endl;
+ updateInProgressness();
}
void MUCSearchController::removeService(const JID& jid) {
- serviceDetails_.erase(jid);
- services_.erase(std::remove(services_.begin(), services_.end(), jid), services_.end());
- refreshView();
+ serviceDetails_.erase(jid);
+ services_.erase(std::remove(services_.begin(), services_.end(), jid), services_.end());
+ refreshView();
}
void MUCSearchController::handleRoomsItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error, const JID& jid) {
- itemsInProgress_--;
- SWIFT_LOG(debug) << "Items received for " << jid << " (" << itemsInProgress_ << " item requests in progress)" << std::endl;
- updateInProgressness();
- if (error) {
- handleDiscoError(jid, error);
- return;
- }
- serviceDetails_[jid].clearRooms();
- foreach (DiscoItems::Item item, items->getItems()) {
- serviceDetails_[jid].addRoom(MUCService::MUCRoom(item.getJID().getNode(), item.getName(), -1));
- }
- serviceDetails_[jid].setComplete(true);
- refreshView();
+ itemsInProgress_--;
+ SWIFT_LOG(debug) << "Items received for " << jid << " (" << itemsInProgress_ << " item requests in progress)" << std::endl;
+ updateInProgressness();
+ if (error) {
+ handleDiscoError(jid, error);
+ return;
+ }
+ serviceDetails_[jid].clearRooms();
+ foreach (DiscoItems::Item item, items->getItems()) {
+ serviceDetails_[jid].addRoom(MUCService::MUCRoom(item.getJID().getNode(), item.getName(), -1));
+ }
+ serviceDetails_[jid].setComplete(true);
+ refreshView();
}
void MUCSearchController::handleDiscoError(const JID& jid, ErrorPayload::ref error) {
- serviceDetails_[jid].setComplete(true);
- serviceDetails_[jid].setError(error->getText());
+ serviceDetails_[jid].setComplete(true);
+ serviceDetails_[jid].setError(error->getText());
}
void MUCSearchController::refreshView() {
- window_->clearList();
- foreach (JID jid, services_) {
- window_->addService(serviceDetails_[jid]);
- }
+ window_->clearList();
+ foreach (JID jid, services_) {
+ window_->addService(serviceDetails_[jid]);
+ }
}
void MUCSearchController::updateInProgressness() {
- window_->setSearchInProgress((walker_ && walker_->isActive()) || itemsInProgress_ > 0);
+ window_->setSearchInProgress((walker_ && walker_->isActive()) || itemsInProgress_ > 0);
}
void MUCSearchController::handleMUCSearchFinished(const boost::optional<JID>& result) {
- if (result) {
- onMUCSelected(*result);
- }
+ if (result) {
+ onMUCSelected(*result);
+ }
}
}
diff --git a/Swift/Controllers/Chat/MUCSearchController.h b/Swift/Controllers/Chat/MUCSearchController.h
index 01bcf74..3d2a2ca 100644
--- a/Swift/Controllers/Chat/MUCSearchController.h
+++ b/Swift/Controllers/Chat/MUCSearchController.h
@@ -22,103 +22,103 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class UIEventStream;
- class MUCSearchWindow;
- class MUCSearchWindowFactory;
- class IQRouter;
- class DiscoServiceWalker;
- class NickResolver;
-
- class MUCService {
- public:
- class MUCRoom {
- public:
- MUCRoom(const std::string& node, const std::string& name, int occupants) : node_(node), name_(name), occupants_(occupants) {}
- std::string getNode() {return node_;}
- std::string getName() {return name_;}
- int getOccupantCount() {return occupants_;}
- private:
- std::string node_;
- std::string name_;
- int occupants_;
- };
-
- MUCService() {error_ = false; complete_ = false;}
-
- void setComplete(bool complete) {
- complete_ = complete;
- }
-
- void setName(const std::string& name) {
- name_ = name;
- }
-
- void setJID(const JID& jid) {
- jid_ = jid;
- }
-
- bool getComplete() const {
- return complete_;
- }
-
- JID getJID() const {
- return jid_;
- }
-
- std::string getName() const {
- return name_;
- }
-
- void setError(const std::string& errorText) {error_ = true; errorText_ = errorText;}
-
- void clearRooms() {rooms_.clear();}
-
- void addRoom(const MUCRoom& room) {rooms_.push_back(room);}
-
- std::vector<MUCRoom> getRooms() const {return rooms_;}
- private:
- std::string name_;
- JID jid_;
- std::vector<MUCRoom> rooms_;
- bool complete_;
- bool error_;
- std::string errorText_;
- };
-
- class MUCSearchController {
- public:
- MUCSearchController(const JID& jid, MUCSearchWindowFactory* mucSearchWindowFactory, IQRouter* iqRouter, ProfileSettingsProvider* settings);
- ~MUCSearchController();
-
- void openSearchWindow();
-
- public:
- boost::signal<void (const JID&)> onMUCSelected;
-
- private:
- void handleSearchService(const JID& jid);
- void handleRoomsItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error, const JID& jid);
- void handleDiscoError(const JID& jid, ErrorPayload::ref error);
- void handleDiscoServiceFound(const JID&, boost::shared_ptr<DiscoInfo>);
- void handleDiscoWalkFinished();
- void handleMUCSearchFinished(const boost::optional<JID>& result);
- void removeService(const JID& jid);
- void refreshView();
- void loadSavedServices();
- void addToSavedServices(const JID& jid);
- void updateInProgressness();
-
- private:
- JID jid_;
- MUCSearchWindowFactory* factory_;
- IQRouter* iqRouter_;
- ProfileSettingsProvider* settings_;
- MUCSearchWindow* window_;
- DiscoServiceWalker* walker_;
- std::list<JID> services_;
- std::list<JID> savedServices_;
- std::map<JID, MUCService> serviceDetails_;
- std::vector<DiscoServiceWalker*> walksInProgress_;
- int itemsInProgress_;
- };
+ class UIEventStream;
+ class MUCSearchWindow;
+ class MUCSearchWindowFactory;
+ class IQRouter;
+ class DiscoServiceWalker;
+ class NickResolver;
+
+ class MUCService {
+ public:
+ class MUCRoom {
+ public:
+ MUCRoom(const std::string& node, const std::string& name, int occupants) : node_(node), name_(name), occupants_(occupants) {}
+ std::string getNode() {return node_;}
+ std::string getName() {return name_;}
+ int getOccupantCount() {return occupants_;}
+ private:
+ std::string node_;
+ std::string name_;
+ int occupants_;
+ };
+
+ MUCService() {error_ = false; complete_ = false;}
+
+ void setComplete(bool complete) {
+ complete_ = complete;
+ }
+
+ void setName(const std::string& name) {
+ name_ = name;
+ }
+
+ void setJID(const JID& jid) {
+ jid_ = jid;
+ }
+
+ bool getComplete() const {
+ return complete_;
+ }
+
+ JID getJID() const {
+ return jid_;
+ }
+
+ std::string getName() const {
+ return name_;
+ }
+
+ void setError(const std::string& errorText) {error_ = true; errorText_ = errorText;}
+
+ void clearRooms() {rooms_.clear();}
+
+ void addRoom(const MUCRoom& room) {rooms_.push_back(room);}
+
+ std::vector<MUCRoom> getRooms() const {return rooms_;}
+ private:
+ std::string name_;
+ JID jid_;
+ std::vector<MUCRoom> rooms_;
+ bool complete_;
+ bool error_;
+ std::string errorText_;
+ };
+
+ class MUCSearchController {
+ public:
+ MUCSearchController(const JID& jid, MUCSearchWindowFactory* mucSearchWindowFactory, IQRouter* iqRouter, ProfileSettingsProvider* settings);
+ ~MUCSearchController();
+
+ void openSearchWindow();
+
+ public:
+ boost::signal<void (const JID&)> onMUCSelected;
+
+ private:
+ void handleSearchService(const JID& jid);
+ void handleRoomsItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error, const JID& jid);
+ void handleDiscoError(const JID& jid, ErrorPayload::ref error);
+ void handleDiscoServiceFound(const JID&, boost::shared_ptr<DiscoInfo>);
+ void handleDiscoWalkFinished();
+ void handleMUCSearchFinished(const boost::optional<JID>& result);
+ void removeService(const JID& jid);
+ void refreshView();
+ void loadSavedServices();
+ void addToSavedServices(const JID& jid);
+ void updateInProgressness();
+
+ private:
+ JID jid_;
+ MUCSearchWindowFactory* factory_;
+ IQRouter* iqRouter_;
+ ProfileSettingsProvider* settings_;
+ MUCSearchWindow* window_;
+ DiscoServiceWalker* walker_;
+ std::list<JID> services_;
+ std::list<JID> savedServices_;
+ std::map<JID, MUCService> serviceDetails_;
+ std::vector<DiscoServiceWalker*> walksInProgress_;
+ int itemsInProgress_;
+ };
}
diff --git a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
index 6748b9e..9ed8bf4 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
@@ -13,269 +13,269 @@
using namespace Swift;
class ChatMessageParserTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(ChatMessageParserTest);
- CPPUNIT_TEST(testFullBody);
- CPPUNIT_TEST(testOneEmoticon);
- CPPUNIT_TEST(testBareEmoticon);
- CPPUNIT_TEST(testHiddenEmoticon);
- CPPUNIT_TEST(testEndlineEmoticon);
- CPPUNIT_TEST(testBoundedEmoticons);
- CPPUNIT_TEST(testNoColourNoHighlight);
- CPPUNIT_TEST_SUITE_END();
-
+ CPPUNIT_TEST_SUITE(ChatMessageParserTest);
+ CPPUNIT_TEST(testFullBody);
+ CPPUNIT_TEST(testOneEmoticon);
+ CPPUNIT_TEST(testBareEmoticon);
+ CPPUNIT_TEST(testHiddenEmoticon);
+ CPPUNIT_TEST(testEndlineEmoticon);
+ CPPUNIT_TEST(testBoundedEmoticons);
+ CPPUNIT_TEST(testNoColourNoHighlight);
+ CPPUNIT_TEST_SUITE_END();
+
public:
- void setUp() {
- smile1_ = ":)";
- smile1Path_ = "/blah/smile1.png";
- smile2_ = ":(";
- smile2Path_ = "/blah/smile2.jpg";
- emoticons_[smile1_] = smile1Path_;
- emoticons_[smile2_] = smile2Path_;
- }
-
- void tearDown() {
- emoticons_.clear();
- }
-
- void assertText(const ChatWindow::ChatMessage& result, size_t index, const std::string& text) {
- boost::shared_ptr<ChatWindow::ChatTextMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(result.getParts()[index]);
- CPPUNIT_ASSERT_EQUAL(text, part->text);
- }
-
- void assertEmoticon(const ChatWindow::ChatMessage& result, size_t index, const std::string& text, const std::string& path) {
- boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(result.getParts()[index]);
- CPPUNIT_ASSERT(!!part);
- CPPUNIT_ASSERT_EQUAL(text, part->alternativeText);
- CPPUNIT_ASSERT_EQUAL(path, part->imagePath);
- }
+ void setUp() {
+ smile1_ = ":)";
+ smile1Path_ = "/blah/smile1.png";
+ smile2_ = ":(";
+ smile2Path_ = "/blah/smile2.jpg";
+ emoticons_[smile1_] = smile1Path_;
+ emoticons_[smile2_] = smile2Path_;
+ }
+
+ void tearDown() {
+ emoticons_.clear();
+ }
+
+ void assertText(const ChatWindow::ChatMessage& result, size_t index, const std::string& text) {
+ boost::shared_ptr<ChatWindow::ChatTextMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(result.getParts()[index]);
+ CPPUNIT_ASSERT_EQUAL(text, part->text);
+ }
+
+ void assertEmoticon(const ChatWindow::ChatMessage& result, size_t index, const std::string& text, const std::string& path) {
+ boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(result.getParts()[index]);
+ CPPUNIT_ASSERT(!!part);
+ CPPUNIT_ASSERT_EQUAL(text, part->alternativeText);
+ CPPUNIT_ASSERT_EQUAL(path, part->imagePath);
+ }
#define assertHighlight(RESULT, INDEX, TEXT, EXPECTED_HIGHLIGHT) \
- { \
- boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(RESULT.getParts()[INDEX]); \
- CPPUNIT_ASSERT_EQUAL(std::string(TEXT), part->text); \
- CPPUNIT_ASSERT(EXPECTED_HIGHLIGHT == part->action); \
- }
-
- void assertURL(const ChatWindow::ChatMessage& result, size_t index, const std::string& text) {
- boost::shared_ptr<ChatWindow::ChatURIMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(result.getParts()[index]);
- CPPUNIT_ASSERT_EQUAL(text, part->target);
- }
-
- static HighlightRule ruleFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
- {
- HighlightRule rule;
- std::vector<std::string> keywords;
- keywords.push_back(keyword);
- rule.setKeywords(keywords);
- rule.setMatchCase(matchCase);
- rule.setMatchWholeWords(matchWholeWord);
- rule.setMatchChat(true);
- rule.getAction().setTextBackground("white");
- return rule;
- }
-
- static const HighlightRulesListPtr ruleListFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
- {
- boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
- list->addRule(ruleFromKeyword(keyword, matchCase, matchWholeWord));
- return list;
- }
-
- static const HighlightRulesListPtr ruleListFromKeywords(const HighlightRule &rule1, const HighlightRule &rule2)
- {
- boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
- list->addRule(rule1);
- list->addRule(rule2);
- return list;
- }
-
- static HighlightRulesListPtr ruleListWithNickHighlight(bool withHighlightColour = true)
- {
- HighlightRule rule;
- rule.setMatchChat(true);
- rule.setNickIsKeyword(true);
- rule.setMatchCase(true);
- rule.setMatchWholeWords(true);
- if (withHighlightColour) {
- rule.getAction().setTextBackground("white");
- }
- boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
- list->addRule(rule);
- return list;
- }
-
- void testFullBody() {
- const std::string no_special_message = "a message with no special content";
- ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
- ChatWindow::ChatMessage result = testling.parseMessageBody(no_special_message);
- assertText(result, 0, no_special_message);
-
- HighlightRulesListPtr highlightRuleList = ruleListFromKeyword("trigger", false, false);
- testling = ChatMessageParser(emoticons_, highlightRuleList);
- result = testling.parseMessageBody(":) shiny :( trigger :) http://wonderland.lit/blah http://denmark.lit boom boom");
- assertEmoticon(result, 0, smile1_, smile1Path_);
- assertText(result, 1, " shiny ");
- assertEmoticon(result, 2, smile2_, smile2Path_);
- assertText(result, 3, " ");
- assertHighlight(result, 4, "trigger", highlightRuleList->getRule(0).getAction());
- assertText(result, 5, " ");
- assertEmoticon(result, 6, smile1_, smile1Path_);
- assertText(result, 7, " ");
- assertURL(result, 8, "http://wonderland.lit/blah");
- assertText(result, 9, " ");
- assertURL(result, 10, "http://denmark.lit");
- assertText(result, 11, " boom boom");
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
- result = testling.parseMessageBody("testtriggermessage");
- assertText(result, 0, "test");
- assertHighlight(result, 1, "trigger", highlightRuleList->getRule(0).getAction());
- assertText(result, 2, "message");
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, true));
- result = testling.parseMessageBody("testtriggermessage");
- assertText(result, 0, "testtriggermessage");
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", true, false));
- result = testling.parseMessageBody("TrIgGeR");
- assertText(result, 0, "TrIgGeR");
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
- result = testling.parseMessageBody("TrIgGeR");
- assertHighlight(result, 0, "TrIgGeR", highlightRuleList->getRule(0).getAction());
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
- result = testling.parseMessageBody("partialTrIgGeRmatch");
- assertText(result, 0, "partial");
- assertHighlight(result, 1, "TrIgGeR", highlightRuleList->getRule(0).getAction());
- assertText(result, 2, "match");
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
- result = testling.parseMessageBody("zero one two three");
- assertText(result, 0, "zero ");
- assertHighlight(result, 1, "one", highlightRuleList->getRule(0).getAction());
- assertText(result, 2, " two ");
- assertHighlight(result, 3, "three", highlightRuleList->getRule(0).getAction());
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
- result = testling.parseMessageBody("zero oNe two tHrEe");
- assertText(result, 0, "zero ");
- assertHighlight(result, 1, "oNe", highlightRuleList->getRule(0).getAction());
- assertText(result, 2, " two ");
- assertHighlight(result, 3, "tHrEe", highlightRuleList->getRule(0).getAction());
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", true, false)));
- result = testling.parseMessageBody("zero oNe two tHrEe");
- assertText(result, 0, "zero ");
- assertHighlight(result, 1, "oNe", highlightRuleList->getRule(0).getAction());
- assertText(result, 2, " two tHrEe");
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", true, false), ruleFromKeyword("three", true, false)));
- result = testling.parseMessageBody("zero oNe two tHrEe");
- assertText(result, 0, "zero oNe two tHrEe");
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
- result = testling.parseMessageBody("zeroonetwothree");
- assertText(result, 0, "zero");
- assertHighlight(result, 1, "one", highlightRuleList->getRule(0).getAction());
- assertText(result, 2, "two");
- assertHighlight(result, 3, "three", highlightRuleList->getRule(0).getAction());
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", true, false), ruleFromKeyword("three", false, false)));
- result = testling.parseMessageBody("zeroOnEtwoThReE");
- assertText(result, 0, "zeroOnEtwo");
- assertHighlight(result, 1, "ThReE", highlightRuleList->getRule(0).getAction());
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, true), ruleFromKeyword("three", false, false)));
- result = testling.parseMessageBody("zeroonetwothree");
- assertText(result, 0, "zeroonetwo");
- assertHighlight(result, 1, "three", highlightRuleList->getRule(0).getAction());
-
- testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, true), ruleFromKeyword("three", false, true)));
- result = testling.parseMessageBody("zeroonetwothree");
- assertText(result, 0, "zeroonetwothree");
-
- testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
- result = testling.parseMessageBody("Alice", "Alice");
- assertHighlight(result, 0, "Alice", highlightRuleList->getRule(0).getAction());
-
- testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
- result = testling.parseMessageBody("TextAliceText", "Alice");
- assertText(result, 0, "TextAliceText");
-
- testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
- result = testling.parseMessageBody("Text Alice Text", "Alice");
- assertText(result, 0, "Text ");
- assertHighlight(result, 1, "Alice", highlightRuleList->getRule(0).getAction());
- assertText(result, 2, " Text");
-
- testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
- result = testling.parseMessageBody("Alice Text", "Alice");
- assertHighlight(result, 0, "Alice", highlightRuleList->getRule(0).getAction());
- assertText(result, 1, " Text");
-
- testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
- result = testling.parseMessageBody("Text Alice", "Alice");
- assertText(result, 0, "Text ");
- assertHighlight(result, 1, "Alice", highlightRuleList->getRule(0).getAction());
- }
-
- void testOneEmoticon() {
- ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
- ChatWindow::ChatMessage result = testling.parseMessageBody(" :) ");
- assertText(result, 0, " ");
- assertEmoticon(result, 1, smile1_, smile1Path_);
- assertText(result, 2, " ");
- }
-
-
- void testBareEmoticon() {
- ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
- ChatWindow::ChatMessage result = testling.parseMessageBody(":)");
- assertEmoticon(result, 0, smile1_, smile1Path_);
- }
-
- void testHiddenEmoticon() {
- ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
- ChatWindow::ChatMessage result = testling.parseMessageBody("b:)a");
- assertText(result, 0, "b:)a");
- }
-
- void testEndlineEmoticon() {
- ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
- ChatWindow::ChatMessage result = testling.parseMessageBody("Lazy:)");
- assertText(result, 0, "Lazy");
- assertEmoticon(result, 1, smile1_, smile1Path_);
- }
-
- void testBoundedEmoticons() {
- ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
- ChatWindow::ChatMessage result = testling.parseMessageBody(":)Lazy:(");
- assertEmoticon(result, 0, smile1_, smile1Path_);
- assertText(result, 1, "Lazy");
- assertEmoticon(result, 2, smile2_, smile2Path_);
- }
-
- void testEmoticonParenthesis() {
- ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
- ChatWindow::ChatMessage result = testling.parseMessageBody("(Like this :))");
- assertText(result, 0, "(Like this ");
- assertEmoticon(result, 1, smile1_, smile1Path_);
- assertText(result, 2, ")");
- }
-
- void testNoColourNoHighlight() {
- ChatMessageParser testling(emoticons_, ruleListWithNickHighlight(false));
- ChatWindow::ChatMessage result = testling.parseMessageBody("Alice", "Alice");
- assertText(result, 0, "Alice");
- }
+ { \
+ boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(RESULT.getParts()[INDEX]); \
+ CPPUNIT_ASSERT_EQUAL(std::string(TEXT), part->text); \
+ CPPUNIT_ASSERT(EXPECTED_HIGHLIGHT == part->action); \
+ }
+
+ void assertURL(const ChatWindow::ChatMessage& result, size_t index, const std::string& text) {
+ boost::shared_ptr<ChatWindow::ChatURIMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(result.getParts()[index]);
+ CPPUNIT_ASSERT_EQUAL(text, part->target);
+ }
+
+ static HighlightRule ruleFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
+ {
+ HighlightRule rule;
+ std::vector<std::string> keywords;
+ keywords.push_back(keyword);
+ rule.setKeywords(keywords);
+ rule.setMatchCase(matchCase);
+ rule.setMatchWholeWords(matchWholeWord);
+ rule.setMatchChat(true);
+ rule.getAction().setTextBackground("white");
+ return rule;
+ }
+
+ static const HighlightRulesListPtr ruleListFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
+ {
+ boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
+ list->addRule(ruleFromKeyword(keyword, matchCase, matchWholeWord));
+ return list;
+ }
+
+ static const HighlightRulesListPtr ruleListFromKeywords(const HighlightRule &rule1, const HighlightRule &rule2)
+ {
+ boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
+ list->addRule(rule1);
+ list->addRule(rule2);
+ return list;
+ }
+
+ static HighlightRulesListPtr ruleListWithNickHighlight(bool withHighlightColour = true)
+ {
+ HighlightRule rule;
+ rule.setMatchChat(true);
+ rule.setNickIsKeyword(true);
+ rule.setMatchCase(true);
+ rule.setMatchWholeWords(true);
+ if (withHighlightColour) {
+ rule.getAction().setTextBackground("white");
+ }
+ boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
+ list->addRule(rule);
+ return list;
+ }
+
+ void testFullBody() {
+ const std::string no_special_message = "a message with no special content";
+ ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
+ ChatWindow::ChatMessage result = testling.parseMessageBody(no_special_message);
+ assertText(result, 0, no_special_message);
+
+ HighlightRulesListPtr highlightRuleList = ruleListFromKeyword("trigger", false, false);
+ testling = ChatMessageParser(emoticons_, highlightRuleList);
+ result = testling.parseMessageBody(":) shiny :( trigger :) http://wonderland.lit/blah http://denmark.lit boom boom");
+ assertEmoticon(result, 0, smile1_, smile1Path_);
+ assertText(result, 1, " shiny ");
+ assertEmoticon(result, 2, smile2_, smile2Path_);
+ assertText(result, 3, " ");
+ assertHighlight(result, 4, "trigger", highlightRuleList->getRule(0).getAction());
+ assertText(result, 5, " ");
+ assertEmoticon(result, 6, smile1_, smile1Path_);
+ assertText(result, 7, " ");
+ assertURL(result, 8, "http://wonderland.lit/blah");
+ assertText(result, 9, " ");
+ assertURL(result, 10, "http://denmark.lit");
+ assertText(result, 11, " boom boom");
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
+ result = testling.parseMessageBody("testtriggermessage");
+ assertText(result, 0, "test");
+ assertHighlight(result, 1, "trigger", highlightRuleList->getRule(0).getAction());
+ assertText(result, 2, "message");
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, true));
+ result = testling.parseMessageBody("testtriggermessage");
+ assertText(result, 0, "testtriggermessage");
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", true, false));
+ result = testling.parseMessageBody("TrIgGeR");
+ assertText(result, 0, "TrIgGeR");
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
+ result = testling.parseMessageBody("TrIgGeR");
+ assertHighlight(result, 0, "TrIgGeR", highlightRuleList->getRule(0).getAction());
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
+ result = testling.parseMessageBody("partialTrIgGeRmatch");
+ assertText(result, 0, "partial");
+ assertHighlight(result, 1, "TrIgGeR", highlightRuleList->getRule(0).getAction());
+ assertText(result, 2, "match");
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
+ result = testling.parseMessageBody("zero one two three");
+ assertText(result, 0, "zero ");
+ assertHighlight(result, 1, "one", highlightRuleList->getRule(0).getAction());
+ assertText(result, 2, " two ");
+ assertHighlight(result, 3, "three", highlightRuleList->getRule(0).getAction());
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
+ result = testling.parseMessageBody("zero oNe two tHrEe");
+ assertText(result, 0, "zero ");
+ assertHighlight(result, 1, "oNe", highlightRuleList->getRule(0).getAction());
+ assertText(result, 2, " two ");
+ assertHighlight(result, 3, "tHrEe", highlightRuleList->getRule(0).getAction());
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", true, false)));
+ result = testling.parseMessageBody("zero oNe two tHrEe");
+ assertText(result, 0, "zero ");
+ assertHighlight(result, 1, "oNe", highlightRuleList->getRule(0).getAction());
+ assertText(result, 2, " two tHrEe");
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", true, false), ruleFromKeyword("three", true, false)));
+ result = testling.parseMessageBody("zero oNe two tHrEe");
+ assertText(result, 0, "zero oNe two tHrEe");
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
+ result = testling.parseMessageBody("zeroonetwothree");
+ assertText(result, 0, "zero");
+ assertHighlight(result, 1, "one", highlightRuleList->getRule(0).getAction());
+ assertText(result, 2, "two");
+ assertHighlight(result, 3, "three", highlightRuleList->getRule(0).getAction());
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", true, false), ruleFromKeyword("three", false, false)));
+ result = testling.parseMessageBody("zeroOnEtwoThReE");
+ assertText(result, 0, "zeroOnEtwo");
+ assertHighlight(result, 1, "ThReE", highlightRuleList->getRule(0).getAction());
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, true), ruleFromKeyword("three", false, false)));
+ result = testling.parseMessageBody("zeroonetwothree");
+ assertText(result, 0, "zeroonetwo");
+ assertHighlight(result, 1, "three", highlightRuleList->getRule(0).getAction());
+
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, true), ruleFromKeyword("three", false, true)));
+ result = testling.parseMessageBody("zeroonetwothree");
+ assertText(result, 0, "zeroonetwothree");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("Alice", "Alice");
+ assertHighlight(result, 0, "Alice", highlightRuleList->getRule(0).getAction());
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("TextAliceText", "Alice");
+ assertText(result, 0, "TextAliceText");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("Text Alice Text", "Alice");
+ assertText(result, 0, "Text ");
+ assertHighlight(result, 1, "Alice", highlightRuleList->getRule(0).getAction());
+ assertText(result, 2, " Text");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("Alice Text", "Alice");
+ assertHighlight(result, 0, "Alice", highlightRuleList->getRule(0).getAction());
+ assertText(result, 1, " Text");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("Text Alice", "Alice");
+ assertText(result, 0, "Text ");
+ assertHighlight(result, 1, "Alice", highlightRuleList->getRule(0).getAction());
+ }
+
+ void testOneEmoticon() {
+ ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
+ ChatWindow::ChatMessage result = testling.parseMessageBody(" :) ");
+ assertText(result, 0, " ");
+ assertEmoticon(result, 1, smile1_, smile1Path_);
+ assertText(result, 2, " ");
+ }
+
+
+ void testBareEmoticon() {
+ ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
+ ChatWindow::ChatMessage result = testling.parseMessageBody(":)");
+ assertEmoticon(result, 0, smile1_, smile1Path_);
+ }
+
+ void testHiddenEmoticon() {
+ ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
+ ChatWindow::ChatMessage result = testling.parseMessageBody("b:)a");
+ assertText(result, 0, "b:)a");
+ }
+
+ void testEndlineEmoticon() {
+ ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
+ ChatWindow::ChatMessage result = testling.parseMessageBody("Lazy:)");
+ assertText(result, 0, "Lazy");
+ assertEmoticon(result, 1, smile1_, smile1Path_);
+ }
+
+ void testBoundedEmoticons() {
+ ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
+ ChatWindow::ChatMessage result = testling.parseMessageBody(":)Lazy:(");
+ assertEmoticon(result, 0, smile1_, smile1Path_);
+ assertText(result, 1, "Lazy");
+ assertEmoticon(result, 2, smile2_, smile2Path_);
+ }
+
+ void testEmoticonParenthesis() {
+ ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
+ ChatWindow::ChatMessage result = testling.parseMessageBody("(Like this :))");
+ assertText(result, 0, "(Like this ");
+ assertEmoticon(result, 1, smile1_, smile1Path_);
+ assertText(result, 2, ")");
+ }
+
+ void testNoColourNoHighlight() {
+ ChatMessageParser testling(emoticons_, ruleListWithNickHighlight(false));
+ ChatWindow::ChatMessage result = testling.parseMessageBody("Alice", "Alice");
+ assertText(result, 0, "Alice");
+ }
private:
- std::map<std::string, std::string> emoticons_;
- std::string smile1_;
- std::string smile1Path_;
- std::string smile2_;
- std::string smile2Path_;
+ std::map<std::string, std::string> emoticons_;
+ std::string smile1_;
+ std::string smile1Path_;
+ std::string smile2_;
+ std::string smile2Path_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(ChatMessageParserTest);
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index d29337d..7445c4b 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -61,808 +61,808 @@
using namespace Swift;
class ChatsManagerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(ChatsManagerTest);
- CPPUNIT_TEST(testFirstOpenWindowIncoming);
- CPPUNIT_TEST(testSecondOpenWindowIncoming);
- CPPUNIT_TEST(testFirstOpenWindowOutgoing);
- CPPUNIT_TEST(testFirstOpenWindowBareToFull);
- CPPUNIT_TEST(testSecondWindow);
- CPPUNIT_TEST(testUnbindRebind);
- CPPUNIT_TEST(testNoDuplicateUnbind);
- CPPUNIT_TEST(testThreeMUCWindows);
- CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnRemoveFromRoster);
- CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnAddToRoster);
- CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToBoth);
- CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToFrom);
- CPPUNIT_TEST(testChatControllerFullJIDBindingOnMessageAndNotReceipt);
- CPPUNIT_TEST(testChatControllerFullJIDBindingOnTypingAndNotActive);
- CPPUNIT_TEST(testChatControllerPMPresenceHandling);
- CPPUNIT_TEST(testLocalMUCServiceDiscoveryResetOnDisconnect);
- CPPUNIT_TEST(testChatControllerHighlightingNotificationTesting);
- CPPUNIT_TEST(testChatControllerHighlightingNotificationDeduplicateSounds);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(ChatsManagerTest);
+ CPPUNIT_TEST(testFirstOpenWindowIncoming);
+ CPPUNIT_TEST(testSecondOpenWindowIncoming);
+ CPPUNIT_TEST(testFirstOpenWindowOutgoing);
+ CPPUNIT_TEST(testFirstOpenWindowBareToFull);
+ CPPUNIT_TEST(testSecondWindow);
+ CPPUNIT_TEST(testUnbindRebind);
+ CPPUNIT_TEST(testNoDuplicateUnbind);
+ CPPUNIT_TEST(testThreeMUCWindows);
+ CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnRemoveFromRoster);
+ CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnAddToRoster);
+ CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToBoth);
+ CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToFrom);
+ CPPUNIT_TEST(testChatControllerFullJIDBindingOnMessageAndNotReceipt);
+ CPPUNIT_TEST(testChatControllerFullJIDBindingOnTypingAndNotActive);
+ CPPUNIT_TEST(testChatControllerPMPresenceHandling);
+ CPPUNIT_TEST(testLocalMUCServiceDiscoveryResetOnDisconnect);
+ CPPUNIT_TEST(testChatControllerHighlightingNotificationTesting);
+ CPPUNIT_TEST(testChatControllerHighlightingNotificationDeduplicateSounds);
+ CPPUNIT_TEST_SUITE_END();
public:
- void setUp() {
- mocks_ = new MockRepository();
- jid_ = JID("test@test.com/resource");
- stanzaChannel_ = new DummyStanzaChannel();
- iqChannel_ = new DummyIQChannel();
- iqRouter_ = new IQRouter(iqChannel_);
-// capsProvider_ = new DummyCapsProvider();
- eventController_ = new EventController();
- chatWindowFactory_ = mocks_->InterfaceMock<ChatWindowFactory>();
- joinMUCWindowFactory_ = mocks_->InterfaceMock<JoinMUCWindowFactory>();
- xmppRoster_ = new XMPPRosterImpl();
- mucRegistry_ = new MUCRegistry();
- nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, NULL, mucRegistry_);
- presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
- serverDiscoInfo_ = boost::make_shared<DiscoInfo>();
- presenceSender_ = new StanzaChannelPresenceSender(stanzaChannel_);
- directedPresenceSender_ = new DirectedPresenceSender(presenceSender_);
- mucManager_ = new MUCManager(stanzaChannel_, iqRouter_, directedPresenceSender_, mucRegistry_);
- uiEventStream_ = new UIEventStream();
-// entityCapsManager_ = new EntityCapsManager(capsProvider_, stanzaChannel_);
- entityCapsProvider_ = new DummyEntityCapsProvider();
- chatListWindowFactory_ = mocks_->InterfaceMock<ChatListWindowFactory>();
- mucSearchWindowFactory_ = mocks_->InterfaceMock<MUCSearchWindowFactory>();
- settings_ = new DummySettingsProvider();
- profileSettings_ = new ProfileSettingsProvider("a", settings_);
- chatListWindow_ = new MockChatListWindow();
- ftManager_ = new DummyFileTransferManager();
- ftOverview_ = new FileTransferOverview(ftManager_);
- avatarManager_ = new NullAvatarManager();
- wbSessionManager_ = new WhiteboardSessionManager(iqRouter_, stanzaChannel_, presenceOracle_, entityCapsProvider_);
- wbManager_ = new WhiteboardManager(whiteboardWindowFactory_, uiEventStream_, nickResolver_, wbSessionManager_);
- highlightManager_ = new HighlightManager(settings_);
- handledHighlightActions_ = 0;
- soundsPlayed_.clear();
- highlightManager_->onHighlight.connect(boost::bind(&ChatsManagerTest::handleHighlightAction, this, _1));
-
- crypto_ = PlatformCryptoProvider::create();
- vcardStorage_ = new VCardMemoryStorage(crypto_);
- vcardManager_ = new VCardManager(jid_, iqRouter_, vcardStorage_);
- mocks_->ExpectCall(chatListWindowFactory_, ChatListWindowFactory::createChatListWindow).With(uiEventStream_).Return(chatListWindow_);
- clientBlockListManager_ = new ClientBlockListManager(iqRouter_);
- manager_ = new ChatsManager(jid_, stanzaChannel_, iqRouter_, eventController_, chatWindowFactory_, joinMUCWindowFactory_, nickResolver_, presenceOracle_, directedPresenceSender_, uiEventStream_, chatListWindowFactory_, true, NULL, mucRegistry_, entityCapsProvider_, mucManager_, mucSearchWindowFactory_, profileSettings_, ftOverview_, xmppRoster_, false, settings_, NULL, wbManager_, highlightManager_, clientBlockListManager_, emoticons_, vcardManager_);
-
- manager_->setAvatarManager(avatarManager_);
- }
-
- void tearDown() {
- delete highlightManager_;
- //delete chatListWindowFactory
- delete profileSettings_;
- delete avatarManager_;
- delete manager_;
- delete clientBlockListManager_;
- delete vcardManager_;
- delete vcardStorage_;
- delete crypto_;
- delete ftOverview_;
- delete ftManager_;
- delete wbSessionManager_;
- delete wbManager_;
- delete directedPresenceSender_;
- delete presenceSender_;
- delete presenceOracle_;
- delete nickResolver_;
- delete mucRegistry_;
- delete stanzaChannel_;
- delete eventController_;
- delete iqRouter_;
- delete iqChannel_;
- delete uiEventStream_;
- delete mucManager_;
- delete xmppRoster_;
- delete entityCapsProvider_;
- delete chatListWindow_;
- delete mocks_;
- delete settings_;
- }
-
- void testFirstOpenWindowIncoming() {
- JID messageJID("testling@test.com/resource1");
-
- MockChatWindow* window = new MockChatWindow();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
-
- boost::shared_ptr<Message> message(new Message());
- message->setFrom(messageJID);
- std::string body("This is a legible message. >HEH@)oeueu");
- message->setBody(body);
- manager_->handleIncomingMessage(message);
- CPPUNIT_ASSERT_EQUAL(body, window->lastMessageBody_);
- }
-
- void testSecondOpenWindowIncoming() {
- JID messageJID1("testling@test.com/resource1");
-
- MockChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID1, uiEventStream_).Return(window1);
-
- boost::shared_ptr<Message> message1(new Message());
- message1->setFrom(messageJID1);
- std::string body1("This is a legible message. >HEH@)oeueu");
- message1->setBody(body1);
- manager_->handleIncomingMessage(message1);
- CPPUNIT_ASSERT_EQUAL(body1, window1->lastMessageBody_);
-
- JID messageJID2("testling@test.com/resource2");
-
- //MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- //mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2, uiEventStream_).Return(window2);
-
- boost::shared_ptr<Message> message2(new Message());
- message2->setFrom(messageJID2);
- std::string body2("This is a legible message. .cmaulm.chul");
- message2->setBody(body2);
- manager_->handleIncomingMessage(message2);
- CPPUNIT_ASSERT_EQUAL(body2, window1->lastMessageBody_);
- }
-
- void testFirstOpenWindowOutgoing() {
- std::string messageJIDString("testling@test.com");
-
- ChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString), uiEventStream_).Return(window);
-
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString))));
- }
-
-
- void testFirstOpenWindowBareToFull() {
- std::string bareJIDString("testling@test.com");
- std::string fullJIDString("testling@test.com/resource1");
-
- MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(bareJIDString), uiEventStream_).Return(window);
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(bareJIDString))));
-
- boost::shared_ptr<Message> message(new Message());
- message->setFrom(JID(fullJIDString));
- std::string body("This is a legible message. mjuga3089gm8G(*>M)@*(");
- message->setBody(body);
- manager_->handleIncomingMessage(message);
- CPPUNIT_ASSERT_EQUAL(body, window->lastMessageBody_);
- }
-
- void testSecondWindow() {
- std::string messageJIDString1("testling1@test.com");
- ChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString1), uiEventStream_).Return(window1);
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString1))));
-
- std::string messageJIDString2("testling2@test.com");
- ChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString2), uiEventStream_).Return(window2);
-
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString2))));
- }
-
- /** Complete cycle.
- Create unbound window.
- Bind it.
- Unbind it.
- Rebind it.
- */
- void testUnbindRebind() {
- std::string bareJIDString("testling@test.com");
- std::string fullJIDString1("testling@test.com/resource1");
- std::string fullJIDString2("testling@test.com/resource2");
-
- MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(bareJIDString), uiEventStream_).Return(window);
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(bareJIDString))));
-
- boost::shared_ptr<Message> message1(new Message());
- message1->setFrom(JID(fullJIDString1));
- std::string messageBody1("This is a legible message.");
- message1->setBody(messageBody1);
- manager_->handleIncomingMessage(message1);
- CPPUNIT_ASSERT_EQUAL(messageBody1, window->lastMessageBody_);
-
- boost::shared_ptr<Presence> jid1Online(new Presence());
- jid1Online->setFrom(JID(fullJIDString1));
- boost::shared_ptr<Presence> jid1Offline(new Presence());
- jid1Offline->setFrom(JID(fullJIDString1));
- jid1Offline->setType(Presence::Unavailable);
- presenceOracle_->onPresenceChange(jid1Offline);
-
- boost::shared_ptr<Message> message2(new Message());
- message2->setFrom(JID(fullJIDString2));
- std::string messageBody2("This is another legible message.");
- message2->setBody(messageBody2);
- manager_->handleIncomingMessage(message2);
- CPPUNIT_ASSERT_EQUAL(messageBody2, window->lastMessageBody_);
- }
-
- /**
- * Test that MUC PMs get opened in the right windows
- */
- void testThreeMUCWindows() {
- JID muc("testling@test.com");
- ChatWindow* mucWindow = new MockChatWindow();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(muc, uiEventStream_).Return(mucWindow);
- uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(muc, std::string("nick")));
-
-
- std::string messageJIDString1("testling@test.com/1");
- ChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString1), uiEventStream_).Return(window1);
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString1))));
-
- std::string messageJIDString2("testling@test.com/2");
- ChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString2), uiEventStream_).Return(window2);
-
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString2))));
-
- std::string messageJIDString3("testling@test.com/3");
- ChatWindow* window3 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString3), uiEventStream_).Return(window3);
-
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString3))));
-
- /* Refetch an earlier window */
- /* We do not expect a new window to be created */
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString1))));
-
- }
-
- /**
- Test that a second window isn't unbound where there's already an unbound one.
- Bind 1
- Bind 2
- Unbind 1
- Unbind 2 (but it doesn't)
- Sent to bound 2
- Rebind 1
- */
- void testNoDuplicateUnbind() {
- JID messageJID1("testling@test.com/resource1");
-
- MockChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID1, uiEventStream_).Return(window1);
-
- boost::shared_ptr<Message> message1(new Message());
- message1->setFrom(messageJID1);
- message1->setBody("This is a legible message1.");
- manager_->handleIncomingMessage(message1);
-
- JID messageJID2("testling@test.com/resource2");
-
- //MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- //mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2, uiEventStream_).Return(window2);
-
- boost::shared_ptr<Message> message2(new Message());
- message2->setFrom(messageJID2);
- message2->setBody("This is a legible message2.");
- manager_->handleIncomingMessage(message2);
-
- boost::shared_ptr<Presence> jid1Online(new Presence());
- jid1Online->setFrom(JID(messageJID1));
- boost::shared_ptr<Presence> jid1Offline(new Presence());
- jid1Offline->setFrom(JID(messageJID1));
- jid1Offline->setType(Presence::Unavailable);
- presenceOracle_->onPresenceChange(jid1Offline);
-
- boost::shared_ptr<Presence> jid2Online(new Presence());
- jid2Online->setFrom(JID(messageJID2));
- boost::shared_ptr<Presence> jid2Offline(new Presence());
- jid2Offline->setFrom(JID(messageJID2));
- jid2Offline->setType(Presence::Unavailable);
- presenceOracle_->onPresenceChange(jid2Offline);
-
- JID messageJID3("testling@test.com/resource3");
-
- boost::shared_ptr<Message> message3(new Message());
- message3->setFrom(messageJID3);
- std::string body3("This is a legible message3.");
- message3->setBody(body3);
- manager_->handleIncomingMessage(message3);
- CPPUNIT_ASSERT_EQUAL(body3, window1->lastMessageBody_);
-
- boost::shared_ptr<Message> message2b(new Message());
- message2b->setFrom(messageJID2);
- std::string body2b("This is a legible message2b.");
- message2b->setBody(body2b);
- manager_->handleIncomingMessage(message2b);
- CPPUNIT_ASSERT_EQUAL(body2b, window1->lastMessageBody_);
- }
-
- /**
- * Test that ChatController doesn't send receipts anymore after removal of the contact from the roster.
- */
- void testChatControllerPresenceAccessUpdatedOnRemoveFromRoster() {
- JID messageJID("testling@test.com/resource1");
- xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), RosterItemPayload::Both);
-
- MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
- settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
-
- boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1");
- manager_->handleIncomingMessage(message);
- Stanza::ref stanzaContactOnRoster = stanzaChannel_->getStanzaAtIndex<Stanza>(0);
- CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size());
- CPPUNIT_ASSERT(stanzaContactOnRoster->getPayload<DeliveryReceipt>() != 0);
-
- xmppRoster_->removeContact(messageJID);
-
- message->setID("2");
- manager_->handleIncomingMessage(message);
- CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size());
- }
-
- /**
- * Test that ChatController sends receipts after the contact has been added to the roster.
- */
- void testChatControllerPresenceAccessUpdatedOnAddToRoster() {
- JID messageJID("testling@test.com/resource1");
-
- MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
- settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
-
- boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1");
- manager_->handleIncomingMessage(message);
-
- CPPUNIT_ASSERT_EQUAL(st(0), stanzaChannel_->sentStanzas.size());
-
- xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), RosterItemPayload::Both);
- message->setID("2");
- manager_->handleIncomingMessage(message);
-
- CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size());
- Stanza::ref stanzaContactOnRoster = stanzaChannel_->getStanzaAtIndex<Stanza>(0);
- CPPUNIT_ASSERT(stanzaContactOnRoster->getPayload<DeliveryReceipt>() != 0);
- }
-
- /**
- * Test that ChatController sends receipts if requested after change from subscription state To to subscription state Both.
- */
- void testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToBoth() {
- testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::To, RosterItemPayload::Both);
- }
-
- /**
- * Test that ChatController sends receipts if requested after change from subscription state To to subscription state From.
- */
- void testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToFrom() {
- testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::To, RosterItemPayload::From);
- }
-
- void testChatControllerFullJIDBindingOnMessageAndNotReceipt() {
- JID ownJID("test@test.com/resource");
- JID sender("foo@test.com");
- std::vector<JID> senderResource;
- senderResource.push_back(sender.withResource("resourceA"));
- senderResource.push_back(sender.withResource("resourceB"));
-
- // We support delivery receipts.
- settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
-
- // Open chat window to a sender.
- MockChatWindow* window = new MockChatWindow();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(sender, uiEventStream_).Return(window);
-
- uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(sender));
-
- foreach(const JID& senderJID, senderResource) {
- // The sender supports delivery receipts.
- DiscoInfo::ref disco = boost::make_shared<DiscoInfo>();
- disco->addFeature(DiscoInfo::MessageDeliveryReceiptsFeature);
- entityCapsProvider_->caps[senderJID] = disco;
-
- // The sender is online.
- Presence::ref senderPresence = boost::make_shared<Presence>();
- senderPresence->setFrom(senderJID);
- senderPresence->setTo(ownJID);
- stanzaChannel_->onPresenceReceived(senderPresence);
-
- entityCapsProvider_->onCapsChanged(senderJID);
- }
-
- // Send first message.
- window->onSendMessageRequest("hello there", false);
-
- // A bare message is send because no resources is bound.
- CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(0)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(0)->getPayload<DeliveryReceiptRequest>());
-
- // Two resources respond with message receipts.
- foreach(const JID& senderJID, senderResource) {
- Message::ref receiptReply = boost::make_shared<Message>();
- receiptReply->setFrom(senderJID);
- receiptReply->setTo(ownJID);
-
- boost::shared_ptr<DeliveryReceipt> receipt = boost::make_shared<DeliveryReceipt>();
- receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(0)->getID());
- receiptReply->addPayload(receipt);
- manager_->handleIncomingMessage(receiptReply);
- }
-
- // Send second message.
- window->onSendMessageRequest("how are you?", false);
-
- // A bare message is send because no resources is bound.
- CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(1)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>());
-
- // Two resources respond with message receipts.
- foreach(const JID& senderJID, senderResource) {
- Message::ref receiptReply = boost::make_shared<Message>();
- receiptReply->setFrom(senderJID);
- receiptReply->setTo(ownJID);
-
- boost::shared_ptr<DeliveryReceipt> receipt = boost::make_shared<DeliveryReceipt>();
- receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(1)->getID());
- receiptReply->addPayload(receipt);
- manager_->handleIncomingMessage(receiptReply);
- }
-
- // Reply with a message including a body text.
- Message::ref reply = boost::make_shared<Message>();
- reply->setFrom(senderResource[0]);
- reply->setTo(ownJID);
- reply->setBody("fine.");
- manager_->handleIncomingMessage(reply);
-
- // Send third message.
- window->onSendMessageRequest("great to hear.", false);
-
- // The chat session is bound to the full JID of the first resource.
- CPPUNIT_ASSERT_EQUAL(senderResource[0], stanzaChannel_->getStanzaAtIndex<Message>(2)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(2)->getPayload<DeliveryReceiptRequest>());
-
- // Receive random receipt from second sender resource.
- reply = boost::make_shared<Message>();
- reply->setFrom(senderResource[1]);
- reply->setTo(ownJID);
-
- boost::shared_ptr<DeliveryReceipt> receipt = boost::make_shared<DeliveryReceipt>();
- receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(2)->getID());
- reply->addPayload(receipt);
- manager_->handleIncomingMessage(reply);
-
- // Send forth message.
- window->onSendMessageRequest("what else is new?", false);
-
- // The chat session is bound to the full JID of the first resource.
- CPPUNIT_ASSERT_EQUAL(senderResource[0], stanzaChannel_->getStanzaAtIndex<Message>(3)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(3)->getPayload<DeliveryReceiptRequest>());
-
- // Reply with a message including a body text from second resource.
- reply = boost::make_shared<Message>();
- reply->setFrom(senderResource[1]);
- reply->setTo(ownJID);
- reply->setBody("nothing.");
- manager_->handleIncomingMessage(reply);
-
- // Send fifth message.
- window->onSendMessageRequest("okay", false);
-
- // The chat session is now bound to the full JID of the second resource.
- CPPUNIT_ASSERT_EQUAL(senderResource[1], stanzaChannel_->getStanzaAtIndex<Message>(4)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(4)->getPayload<DeliveryReceiptRequest>());
- }
-
- void testChatControllerFullJIDBindingOnTypingAndNotActive() {
- JID ownJID("test@test.com/resource");
- JID sender("foo@test.com");
- std::vector<JID> senderResource;
- senderResource.push_back(sender.withResource("resourceA"));
- senderResource.push_back(sender.withResource("resourceB"));
-
- // We support delivery receipts.
- settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
-
- // Open chat window to a sender.
- MockChatWindow* window = new MockChatWindow();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(sender, uiEventStream_).Return(window);
-
- uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(sender));
-
- foreach(const JID& senderJID, senderResource) {
- // The sender supports delivery receipts.
- DiscoInfo::ref disco = boost::make_shared<DiscoInfo>();
- disco->addFeature(DiscoInfo::MessageDeliveryReceiptsFeature);
- entityCapsProvider_->caps[senderJID] = disco;
-
- // The sender is online.
- Presence::ref senderPresence = boost::make_shared<Presence>();
- senderPresence->setFrom(senderJID);
- senderPresence->setTo(ownJID);
- stanzaChannel_->onPresenceReceived(senderPresence);
-
- entityCapsProvider_->onCapsChanged(senderJID);
- }
-
- // Send first message.
- window->onSendMessageRequest("hello there", false);
-
- // A bare message is send because no resources is bound.
- CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(0)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(0)->getPayload<DeliveryReceiptRequest>());
-
- // Two resources respond with message receipts.
- foreach(const JID& senderJID, senderResource) {
- Message::ref reply = boost::make_shared<Message>();
- reply->setFrom(senderJID);
- reply->setTo(ownJID);
-
- boost::shared_ptr<ChatState> csn = boost::make_shared<ChatState>();
- csn->setChatState(ChatState::Active);
- reply->addPayload(csn);
- manager_->handleIncomingMessage(reply);
- }
-
- // Send second message.
- window->onSendMessageRequest("how are you?", false);
-
- // A bare message is send because no resources is bound.
- CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(1)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>());
-
- // Two resources respond with message receipts.
- foreach(const JID& senderJID, senderResource) {
- Message::ref receiptReply = boost::make_shared<Message>();
- receiptReply->setFrom(senderJID);
- receiptReply->setTo(ownJID);
-
- boost::shared_ptr<DeliveryReceipt> receipt = boost::make_shared<DeliveryReceipt>();
- receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(1)->getID());
- receiptReply->addPayload(receipt);
- manager_->handleIncomingMessage(receiptReply);
- }
-
- // Reply with a message including a CSN.
- Message::ref reply = boost::make_shared<Message>();
- reply->setFrom(senderResource[0]);
- reply->setTo(ownJID);
-
- boost::shared_ptr<ChatState> csn = boost::make_shared<ChatState>();
- csn->setChatState(ChatState::Composing);
- reply->addPayload(csn);
- manager_->handleIncomingMessage(reply);
-
- // Send third message.
- window->onSendMessageRequest("great to hear.", false);
-
- // The chat session is now bound to the full JID of the first resource due to its recent composing message.
- CPPUNIT_ASSERT_EQUAL(senderResource[0], stanzaChannel_->getStanzaAtIndex<Message>(2)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(2)->getPayload<DeliveryReceiptRequest>());
-
- // Reply with a message including a CSN from the other resource.
- reply = boost::make_shared<Message>();
- reply->setFrom(senderResource[1]);
- reply->setTo(ownJID);
-
- csn = boost::make_shared<ChatState>();
- csn->setChatState(ChatState::Composing);
- reply->addPayload(csn);
- manager_->handleIncomingMessage(reply);
-
- // Send third message.
- window->onSendMessageRequest("ping.", false);
-
- // The chat session is now bound to the full JID of the second resource due to its recent composing message.
- CPPUNIT_ASSERT_EQUAL(senderResource[1], stanzaChannel_->getStanzaAtIndex<Message>(3)->getTo());
- CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(3)->getPayload<DeliveryReceiptRequest>());
- }
-
- void testChatControllerPMPresenceHandling() {
- JID participantA = JID("test@rooms.test.com/participantA");
- JID participantB = JID("test@rooms.test.com/participantB");
-
- mucRegistry_->addMUC("test@rooms.test.com");
-
- MockChatWindow* window = new MockChatWindow();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(participantA, uiEventStream_).Return(window);
-
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(participantA))));
-
- Presence::ref presence = Presence::create();
- presence->setFrom(participantA);
- presence->setShow(StatusShow::Online);
- stanzaChannel_->onPresenceReceived(presence);
- CPPUNIT_ASSERT_EQUAL(std::string("participantA has become available."), MockChatWindow::bodyFromMessage(window->lastAddedPresence_));
-
- presence = Presence::create();
- presence->setFrom(participantB);
- presence->setShow(StatusShow::Away);
- stanzaChannel_->onPresenceReceived(presence);
-
- presence = Presence::create();
- presence->setFrom(participantA);
- presence->setShow(StatusShow::None);
- presence->setType(Presence::Unavailable);
- stanzaChannel_->onPresenceReceived(presence);
- CPPUNIT_ASSERT_EQUAL(std::string("participantA has gone offline."), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
- }
-
- void testLocalMUCServiceDiscoveryResetOnDisconnect() {
- JID ownJID("test@test.com/resource");
- JID sender("foo@test.com");
-
- manager_->setOnline(true);
-
- // Open chat window to a sender.
- MockChatWindow* window = new MockChatWindow();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(sender, uiEventStream_).Return(window);
-
- uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(sender));
-
- CPPUNIT_ASSERT_EQUAL(false, window->impromptuMUCSupported_);
-
- boost::shared_ptr<IQ> infoRequest= iqChannel_->iqs_[1];
- boost::shared_ptr<IQ> infoResponse = IQ::createResult(infoRequest->getFrom(), infoRequest->getTo(), infoRequest->getID());
-
- DiscoInfo info;
- info.addIdentity(DiscoInfo::Identity("Shakespearean Chat Service", "conference", "text"));
- info.addFeature("http://jabber.org/protocol/muc");
- infoResponse->addPayload(boost::make_shared<DiscoInfo>(info));
- iqChannel_->onIQReceived(infoResponse);
-
- CPPUNIT_ASSERT_EQUAL(true, window->impromptuMUCSupported_);
- manager_->setOnline(false);
- CPPUNIT_ASSERT_EQUAL(false, window->impromptuMUCSupported_);
- }
-
- void testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::Subscription from, RosterItemPayload::Subscription to) {
- JID messageJID("testling@test.com/resource1");
- xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), from);
-
- MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
- settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
-
- boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1");
- manager_->handleIncomingMessage(message);
-
- CPPUNIT_ASSERT_EQUAL(st(0), stanzaChannel_->sentStanzas.size());
-
- xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), to);
- message->setID("2");
- manager_->handleIncomingMessage(message);
-
- CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size());
- Stanza::ref stanzaContactOnRoster = stanzaChannel_->getStanzaAtIndex<Stanza>(0);
- CPPUNIT_ASSERT(stanzaContactOnRoster->getPayload<DeliveryReceipt>() != 0);
- }
-
- void testChatControllerHighlightingNotificationTesting() {
- HighlightRule keywordRuleA;
- keywordRuleA.setMatchChat(true);
- std::vector<std::string> keywordsA;
- keywordsA.push_back("Romeo");
- keywordRuleA.setKeywords(keywordsA);
- keywordRuleA.getAction().setTextColor("yellow");
- keywordRuleA.getAction().setPlaySound(true);
- highlightManager_->insertRule(0, keywordRuleA);
-
- HighlightRule keywordRuleB;
- keywordRuleB.setMatchChat(true);
- std::vector<std::string> keywordsB;
- keywordsB.push_back("Juliet");
- keywordRuleB.setKeywords(keywordsB);
- keywordRuleB.getAction().setTextColor("green");
- keywordRuleB.getAction().setPlaySound(true);
- keywordRuleB.getAction().setSoundFile("/tmp/someotherfile.wav");
- highlightManager_->insertRule(0, keywordRuleB);
-
- JID messageJID = JID("testling@test.com");
-
- MockChatWindow* window = new MockChatWindow();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
-
- boost::shared_ptr<Message> message(new Message());
- message->setFrom(messageJID);
- std::string body("This message should cause two sounds: Juliet and Romeo.");
- message->setBody(body);
- manager_->handleIncomingMessage(message);
-
- CPPUNIT_ASSERT_EQUAL(2, handledHighlightActions_);
- CPPUNIT_ASSERT(soundsPlayed_.find(keywordRuleA.getAction().getSoundFile()) != soundsPlayed_.end());
- CPPUNIT_ASSERT(soundsPlayed_.find(keywordRuleB.getAction().getSoundFile()) != soundsPlayed_.end());
- }
-
- void testChatControllerHighlightingNotificationDeduplicateSounds() {
- HighlightRule keywordRuleA;
- keywordRuleA.setMatchChat(true);
- std::vector<std::string> keywordsA;
- keywordsA.push_back("Romeo");
- keywordRuleA.setKeywords(keywordsA);
- keywordRuleA.getAction().setTextColor("yellow");
- keywordRuleA.getAction().setPlaySound(true);
- highlightManager_->insertRule(0, keywordRuleA);
-
- HighlightRule keywordRuleB;
- keywordRuleB.setMatchChat(true);
- std::vector<std::string> keywordsB;
- keywordsB.push_back("Juliet");
- keywordRuleB.setKeywords(keywordsB);
- keywordRuleB.getAction().setTextColor("green");
- keywordRuleB.getAction().setPlaySound(true);
- highlightManager_->insertRule(0, keywordRuleB);
-
- JID messageJID = JID("testling@test.com");
-
- MockChatWindow* window = new MockChatWindow();
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
-
- boost::shared_ptr<Message> message(new Message());
- message->setFrom(messageJID);
- std::string body("This message should cause one sound, because both actions have the same sound: Juliet and Romeo.");
- message->setBody(body);
- manager_->handleIncomingMessage(message);
-
- CPPUNIT_ASSERT_EQUAL(1, handledHighlightActions_);
- CPPUNIT_ASSERT(soundsPlayed_.find(keywordRuleA.getAction().getSoundFile()) != soundsPlayed_.end());
- CPPUNIT_ASSERT(soundsPlayed_.find(keywordRuleB.getAction().getSoundFile()) != soundsPlayed_.end());
- }
+ void setUp() {
+ mocks_ = new MockRepository();
+ jid_ = JID("test@test.com/resource");
+ stanzaChannel_ = new DummyStanzaChannel();
+ iqChannel_ = new DummyIQChannel();
+ iqRouter_ = new IQRouter(iqChannel_);
+// capsProvider_ = new DummyCapsProvider();
+ eventController_ = new EventController();
+ chatWindowFactory_ = mocks_->InterfaceMock<ChatWindowFactory>();
+ joinMUCWindowFactory_ = mocks_->InterfaceMock<JoinMUCWindowFactory>();
+ xmppRoster_ = new XMPPRosterImpl();
+ mucRegistry_ = new MUCRegistry();
+ nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, NULL, mucRegistry_);
+ presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
+ serverDiscoInfo_ = boost::make_shared<DiscoInfo>();
+ presenceSender_ = new StanzaChannelPresenceSender(stanzaChannel_);
+ directedPresenceSender_ = new DirectedPresenceSender(presenceSender_);
+ mucManager_ = new MUCManager(stanzaChannel_, iqRouter_, directedPresenceSender_, mucRegistry_);
+ uiEventStream_ = new UIEventStream();
+// entityCapsManager_ = new EntityCapsManager(capsProvider_, stanzaChannel_);
+ entityCapsProvider_ = new DummyEntityCapsProvider();
+ chatListWindowFactory_ = mocks_->InterfaceMock<ChatListWindowFactory>();
+ mucSearchWindowFactory_ = mocks_->InterfaceMock<MUCSearchWindowFactory>();
+ settings_ = new DummySettingsProvider();
+ profileSettings_ = new ProfileSettingsProvider("a", settings_);
+ chatListWindow_ = new MockChatListWindow();
+ ftManager_ = new DummyFileTransferManager();
+ ftOverview_ = new FileTransferOverview(ftManager_);
+ avatarManager_ = new NullAvatarManager();
+ wbSessionManager_ = new WhiteboardSessionManager(iqRouter_, stanzaChannel_, presenceOracle_, entityCapsProvider_);
+ wbManager_ = new WhiteboardManager(whiteboardWindowFactory_, uiEventStream_, nickResolver_, wbSessionManager_);
+ highlightManager_ = new HighlightManager(settings_);
+ handledHighlightActions_ = 0;
+ soundsPlayed_.clear();
+ highlightManager_->onHighlight.connect(boost::bind(&ChatsManagerTest::handleHighlightAction, this, _1));
+
+ crypto_ = PlatformCryptoProvider::create();
+ vcardStorage_ = new VCardMemoryStorage(crypto_);
+ vcardManager_ = new VCardManager(jid_, iqRouter_, vcardStorage_);
+ mocks_->ExpectCall(chatListWindowFactory_, ChatListWindowFactory::createChatListWindow).With(uiEventStream_).Return(chatListWindow_);
+ clientBlockListManager_ = new ClientBlockListManager(iqRouter_);
+ manager_ = new ChatsManager(jid_, stanzaChannel_, iqRouter_, eventController_, chatWindowFactory_, joinMUCWindowFactory_, nickResolver_, presenceOracle_, directedPresenceSender_, uiEventStream_, chatListWindowFactory_, true, NULL, mucRegistry_, entityCapsProvider_, mucManager_, mucSearchWindowFactory_, profileSettings_, ftOverview_, xmppRoster_, false, settings_, NULL, wbManager_, highlightManager_, clientBlockListManager_, emoticons_, vcardManager_);
+
+ manager_->setAvatarManager(avatarManager_);
+ }
+
+ void tearDown() {
+ delete highlightManager_;
+ //delete chatListWindowFactory
+ delete profileSettings_;
+ delete avatarManager_;
+ delete manager_;
+ delete clientBlockListManager_;
+ delete vcardManager_;
+ delete vcardStorage_;
+ delete crypto_;
+ delete ftOverview_;
+ delete ftManager_;
+ delete wbSessionManager_;
+ delete wbManager_;
+ delete directedPresenceSender_;
+ delete presenceSender_;
+ delete presenceOracle_;
+ delete nickResolver_;
+ delete mucRegistry_;
+ delete stanzaChannel_;
+ delete eventController_;
+ delete iqRouter_;
+ delete iqChannel_;
+ delete uiEventStream_;
+ delete mucManager_;
+ delete xmppRoster_;
+ delete entityCapsProvider_;
+ delete chatListWindow_;
+ delete mocks_;
+ delete settings_;
+ }
+
+ void testFirstOpenWindowIncoming() {
+ JID messageJID("testling@test.com/resource1");
+
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+
+ boost::shared_ptr<Message> message(new Message());
+ message->setFrom(messageJID);
+ std::string body("This is a legible message. >HEH@)oeueu");
+ message->setBody(body);
+ manager_->handleIncomingMessage(message);
+ CPPUNIT_ASSERT_EQUAL(body, window->lastMessageBody_);
+ }
+
+ void testSecondOpenWindowIncoming() {
+ JID messageJID1("testling@test.com/resource1");
+
+ MockChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID1, uiEventStream_).Return(window1);
+
+ boost::shared_ptr<Message> message1(new Message());
+ message1->setFrom(messageJID1);
+ std::string body1("This is a legible message. >HEH@)oeueu");
+ message1->setBody(body1);
+ manager_->handleIncomingMessage(message1);
+ CPPUNIT_ASSERT_EQUAL(body1, window1->lastMessageBody_);
+
+ JID messageJID2("testling@test.com/resource2");
+
+ //MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ //mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2, uiEventStream_).Return(window2);
+
+ boost::shared_ptr<Message> message2(new Message());
+ message2->setFrom(messageJID2);
+ std::string body2("This is a legible message. .cmaulm.chul");
+ message2->setBody(body2);
+ manager_->handleIncomingMessage(message2);
+ CPPUNIT_ASSERT_EQUAL(body2, window1->lastMessageBody_);
+ }
+
+ void testFirstOpenWindowOutgoing() {
+ std::string messageJIDString("testling@test.com");
+
+ ChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString), uiEventStream_).Return(window);
+
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString))));
+ }
+
+
+ void testFirstOpenWindowBareToFull() {
+ std::string bareJIDString("testling@test.com");
+ std::string fullJIDString("testling@test.com/resource1");
+
+ MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(bareJIDString), uiEventStream_).Return(window);
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(bareJIDString))));
+
+ boost::shared_ptr<Message> message(new Message());
+ message->setFrom(JID(fullJIDString));
+ std::string body("This is a legible message. mjuga3089gm8G(*>M)@*(");
+ message->setBody(body);
+ manager_->handleIncomingMessage(message);
+ CPPUNIT_ASSERT_EQUAL(body, window->lastMessageBody_);
+ }
+
+ void testSecondWindow() {
+ std::string messageJIDString1("testling1@test.com");
+ ChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString1), uiEventStream_).Return(window1);
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString1))));
+
+ std::string messageJIDString2("testling2@test.com");
+ ChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString2), uiEventStream_).Return(window2);
+
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString2))));
+ }
+
+ /** Complete cycle.
+ Create unbound window.
+ Bind it.
+ Unbind it.
+ Rebind it.
+ */
+ void testUnbindRebind() {
+ std::string bareJIDString("testling@test.com");
+ std::string fullJIDString1("testling@test.com/resource1");
+ std::string fullJIDString2("testling@test.com/resource2");
+
+ MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(bareJIDString), uiEventStream_).Return(window);
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(bareJIDString))));
+
+ boost::shared_ptr<Message> message1(new Message());
+ message1->setFrom(JID(fullJIDString1));
+ std::string messageBody1("This is a legible message.");
+ message1->setBody(messageBody1);
+ manager_->handleIncomingMessage(message1);
+ CPPUNIT_ASSERT_EQUAL(messageBody1, window->lastMessageBody_);
+
+ boost::shared_ptr<Presence> jid1Online(new Presence());
+ jid1Online->setFrom(JID(fullJIDString1));
+ boost::shared_ptr<Presence> jid1Offline(new Presence());
+ jid1Offline->setFrom(JID(fullJIDString1));
+ jid1Offline->setType(Presence::Unavailable);
+ presenceOracle_->onPresenceChange(jid1Offline);
+
+ boost::shared_ptr<Message> message2(new Message());
+ message2->setFrom(JID(fullJIDString2));
+ std::string messageBody2("This is another legible message.");
+ message2->setBody(messageBody2);
+ manager_->handleIncomingMessage(message2);
+ CPPUNIT_ASSERT_EQUAL(messageBody2, window->lastMessageBody_);
+ }
+
+ /**
+ * Test that MUC PMs get opened in the right windows
+ */
+ void testThreeMUCWindows() {
+ JID muc("testling@test.com");
+ ChatWindow* mucWindow = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(muc, uiEventStream_).Return(mucWindow);
+ uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(muc, std::string("nick")));
+
+
+ std::string messageJIDString1("testling@test.com/1");
+ ChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString1), uiEventStream_).Return(window1);
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString1))));
+
+ std::string messageJIDString2("testling@test.com/2");
+ ChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString2), uiEventStream_).Return(window2);
+
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString2))));
+
+ std::string messageJIDString3("testling@test.com/3");
+ ChatWindow* window3 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString3), uiEventStream_).Return(window3);
+
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString3))));
+
+ /* Refetch an earlier window */
+ /* We do not expect a new window to be created */
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(messageJIDString1))));
+
+ }
+
+ /**
+ Test that a second window isn't unbound where there's already an unbound one.
+ Bind 1
+ Bind 2
+ Unbind 1
+ Unbind 2 (but it doesn't)
+ Sent to bound 2
+ Rebind 1
+ */
+ void testNoDuplicateUnbind() {
+ JID messageJID1("testling@test.com/resource1");
+
+ MockChatWindow* window1 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID1, uiEventStream_).Return(window1);
+
+ boost::shared_ptr<Message> message1(new Message());
+ message1->setFrom(messageJID1);
+ message1->setBody("This is a legible message1.");
+ manager_->handleIncomingMessage(message1);
+
+ JID messageJID2("testling@test.com/resource2");
+
+ //MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ //mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2, uiEventStream_).Return(window2);
+
+ boost::shared_ptr<Message> message2(new Message());
+ message2->setFrom(messageJID2);
+ message2->setBody("This is a legible message2.");
+ manager_->handleIncomingMessage(message2);
+
+ boost::shared_ptr<Presence> jid1Online(new Presence());
+ jid1Online->setFrom(JID(messageJID1));
+ boost::shared_ptr<Presence> jid1Offline(new Presence());
+ jid1Offline->setFrom(JID(messageJID1));
+ jid1Offline->setType(Presence::Unavailable);
+ presenceOracle_->onPresenceChange(jid1Offline);
+
+ boost::shared_ptr<Presence> jid2Online(new Presence());
+ jid2Online->setFrom(JID(messageJID2));
+ boost::shared_ptr<Presence> jid2Offline(new Presence());
+ jid2Offline->setFrom(JID(messageJID2));
+ jid2Offline->setType(Presence::Unavailable);
+ presenceOracle_->onPresenceChange(jid2Offline);
+
+ JID messageJID3("testling@test.com/resource3");
+
+ boost::shared_ptr<Message> message3(new Message());
+ message3->setFrom(messageJID3);
+ std::string body3("This is a legible message3.");
+ message3->setBody(body3);
+ manager_->handleIncomingMessage(message3);
+ CPPUNIT_ASSERT_EQUAL(body3, window1->lastMessageBody_);
+
+ boost::shared_ptr<Message> message2b(new Message());
+ message2b->setFrom(messageJID2);
+ std::string body2b("This is a legible message2b.");
+ message2b->setBody(body2b);
+ manager_->handleIncomingMessage(message2b);
+ CPPUNIT_ASSERT_EQUAL(body2b, window1->lastMessageBody_);
+ }
+
+ /**
+ * Test that ChatController doesn't send receipts anymore after removal of the contact from the roster.
+ */
+ void testChatControllerPresenceAccessUpdatedOnRemoveFromRoster() {
+ JID messageJID("testling@test.com/resource1");
+ xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), RosterItemPayload::Both);
+
+ MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+ settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
+
+ boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1");
+ manager_->handleIncomingMessage(message);
+ Stanza::ref stanzaContactOnRoster = stanzaChannel_->getStanzaAtIndex<Stanza>(0);
+ CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size());
+ CPPUNIT_ASSERT(stanzaContactOnRoster->getPayload<DeliveryReceipt>() != 0);
+
+ xmppRoster_->removeContact(messageJID);
+
+ message->setID("2");
+ manager_->handleIncomingMessage(message);
+ CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size());
+ }
+
+ /**
+ * Test that ChatController sends receipts after the contact has been added to the roster.
+ */
+ void testChatControllerPresenceAccessUpdatedOnAddToRoster() {
+ JID messageJID("testling@test.com/resource1");
+
+ MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+ settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
+
+ boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1");
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(st(0), stanzaChannel_->sentStanzas.size());
+
+ xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), RosterItemPayload::Both);
+ message->setID("2");
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size());
+ Stanza::ref stanzaContactOnRoster = stanzaChannel_->getStanzaAtIndex<Stanza>(0);
+ CPPUNIT_ASSERT(stanzaContactOnRoster->getPayload<DeliveryReceipt>() != 0);
+ }
+
+ /**
+ * Test that ChatController sends receipts if requested after change from subscription state To to subscription state Both.
+ */
+ void testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToBoth() {
+ testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::To, RosterItemPayload::Both);
+ }
+
+ /**
+ * Test that ChatController sends receipts if requested after change from subscription state To to subscription state From.
+ */
+ void testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToFrom() {
+ testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::To, RosterItemPayload::From);
+ }
+
+ void testChatControllerFullJIDBindingOnMessageAndNotReceipt() {
+ JID ownJID("test@test.com/resource");
+ JID sender("foo@test.com");
+ std::vector<JID> senderResource;
+ senderResource.push_back(sender.withResource("resourceA"));
+ senderResource.push_back(sender.withResource("resourceB"));
+
+ // We support delivery receipts.
+ settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
+
+ // Open chat window to a sender.
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(sender, uiEventStream_).Return(window);
+
+ uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(sender));
+
+ foreach(const JID& senderJID, senderResource) {
+ // The sender supports delivery receipts.
+ DiscoInfo::ref disco = boost::make_shared<DiscoInfo>();
+ disco->addFeature(DiscoInfo::MessageDeliveryReceiptsFeature);
+ entityCapsProvider_->caps[senderJID] = disco;
+
+ // The sender is online.
+ Presence::ref senderPresence = boost::make_shared<Presence>();
+ senderPresence->setFrom(senderJID);
+ senderPresence->setTo(ownJID);
+ stanzaChannel_->onPresenceReceived(senderPresence);
+
+ entityCapsProvider_->onCapsChanged(senderJID);
+ }
+
+ // Send first message.
+ window->onSendMessageRequest("hello there", false);
+
+ // A bare message is send because no resources is bound.
+ CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(0)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(0)->getPayload<DeliveryReceiptRequest>());
+
+ // Two resources respond with message receipts.
+ foreach(const JID& senderJID, senderResource) {
+ Message::ref receiptReply = boost::make_shared<Message>();
+ receiptReply->setFrom(senderJID);
+ receiptReply->setTo(ownJID);
+
+ boost::shared_ptr<DeliveryReceipt> receipt = boost::make_shared<DeliveryReceipt>();
+ receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(0)->getID());
+ receiptReply->addPayload(receipt);
+ manager_->handleIncomingMessage(receiptReply);
+ }
+
+ // Send second message.
+ window->onSendMessageRequest("how are you?", false);
+
+ // A bare message is send because no resources is bound.
+ CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(1)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>());
+
+ // Two resources respond with message receipts.
+ foreach(const JID& senderJID, senderResource) {
+ Message::ref receiptReply = boost::make_shared<Message>();
+ receiptReply->setFrom(senderJID);
+ receiptReply->setTo(ownJID);
+
+ boost::shared_ptr<DeliveryReceipt> receipt = boost::make_shared<DeliveryReceipt>();
+ receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(1)->getID());
+ receiptReply->addPayload(receipt);
+ manager_->handleIncomingMessage(receiptReply);
+ }
+
+ // Reply with a message including a body text.
+ Message::ref reply = boost::make_shared<Message>();
+ reply->setFrom(senderResource[0]);
+ reply->setTo(ownJID);
+ reply->setBody("fine.");
+ manager_->handleIncomingMessage(reply);
+
+ // Send third message.
+ window->onSendMessageRequest("great to hear.", false);
+
+ // The chat session is bound to the full JID of the first resource.
+ CPPUNIT_ASSERT_EQUAL(senderResource[0], stanzaChannel_->getStanzaAtIndex<Message>(2)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(2)->getPayload<DeliveryReceiptRequest>());
+
+ // Receive random receipt from second sender resource.
+ reply = boost::make_shared<Message>();
+ reply->setFrom(senderResource[1]);
+ reply->setTo(ownJID);
+
+ boost::shared_ptr<DeliveryReceipt> receipt = boost::make_shared<DeliveryReceipt>();
+ receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(2)->getID());
+ reply->addPayload(receipt);
+ manager_->handleIncomingMessage(reply);
+
+ // Send forth message.
+ window->onSendMessageRequest("what else is new?", false);
+
+ // The chat session is bound to the full JID of the first resource.
+ CPPUNIT_ASSERT_EQUAL(senderResource[0], stanzaChannel_->getStanzaAtIndex<Message>(3)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(3)->getPayload<DeliveryReceiptRequest>());
+
+ // Reply with a message including a body text from second resource.
+ reply = boost::make_shared<Message>();
+ reply->setFrom(senderResource[1]);
+ reply->setTo(ownJID);
+ reply->setBody("nothing.");
+ manager_->handleIncomingMessage(reply);
+
+ // Send fifth message.
+ window->onSendMessageRequest("okay", false);
+
+ // The chat session is now bound to the full JID of the second resource.
+ CPPUNIT_ASSERT_EQUAL(senderResource[1], stanzaChannel_->getStanzaAtIndex<Message>(4)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(4)->getPayload<DeliveryReceiptRequest>());
+ }
+
+ void testChatControllerFullJIDBindingOnTypingAndNotActive() {
+ JID ownJID("test@test.com/resource");
+ JID sender("foo@test.com");
+ std::vector<JID> senderResource;
+ senderResource.push_back(sender.withResource("resourceA"));
+ senderResource.push_back(sender.withResource("resourceB"));
+
+ // We support delivery receipts.
+ settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
+
+ // Open chat window to a sender.
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(sender, uiEventStream_).Return(window);
+
+ uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(sender));
+
+ foreach(const JID& senderJID, senderResource) {
+ // The sender supports delivery receipts.
+ DiscoInfo::ref disco = boost::make_shared<DiscoInfo>();
+ disco->addFeature(DiscoInfo::MessageDeliveryReceiptsFeature);
+ entityCapsProvider_->caps[senderJID] = disco;
+
+ // The sender is online.
+ Presence::ref senderPresence = boost::make_shared<Presence>();
+ senderPresence->setFrom(senderJID);
+ senderPresence->setTo(ownJID);
+ stanzaChannel_->onPresenceReceived(senderPresence);
+
+ entityCapsProvider_->onCapsChanged(senderJID);
+ }
+
+ // Send first message.
+ window->onSendMessageRequest("hello there", false);
+
+ // A bare message is send because no resources is bound.
+ CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(0)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(0)->getPayload<DeliveryReceiptRequest>());
+
+ // Two resources respond with message receipts.
+ foreach(const JID& senderJID, senderResource) {
+ Message::ref reply = boost::make_shared<Message>();
+ reply->setFrom(senderJID);
+ reply->setTo(ownJID);
+
+ boost::shared_ptr<ChatState> csn = boost::make_shared<ChatState>();
+ csn->setChatState(ChatState::Active);
+ reply->addPayload(csn);
+ manager_->handleIncomingMessage(reply);
+ }
+
+ // Send second message.
+ window->onSendMessageRequest("how are you?", false);
+
+ // A bare message is send because no resources is bound.
+ CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(1)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>());
+
+ // Two resources respond with message receipts.
+ foreach(const JID& senderJID, senderResource) {
+ Message::ref receiptReply = boost::make_shared<Message>();
+ receiptReply->setFrom(senderJID);
+ receiptReply->setTo(ownJID);
+
+ boost::shared_ptr<DeliveryReceipt> receipt = boost::make_shared<DeliveryReceipt>();
+ receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(1)->getID());
+ receiptReply->addPayload(receipt);
+ manager_->handleIncomingMessage(receiptReply);
+ }
+
+ // Reply with a message including a CSN.
+ Message::ref reply = boost::make_shared<Message>();
+ reply->setFrom(senderResource[0]);
+ reply->setTo(ownJID);
+
+ boost::shared_ptr<ChatState> csn = boost::make_shared<ChatState>();
+ csn->setChatState(ChatState::Composing);
+ reply->addPayload(csn);
+ manager_->handleIncomingMessage(reply);
+
+ // Send third message.
+ window->onSendMessageRequest("great to hear.", false);
+
+ // The chat session is now bound to the full JID of the first resource due to its recent composing message.
+ CPPUNIT_ASSERT_EQUAL(senderResource[0], stanzaChannel_->getStanzaAtIndex<Message>(2)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(2)->getPayload<DeliveryReceiptRequest>());
+
+ // Reply with a message including a CSN from the other resource.
+ reply = boost::make_shared<Message>();
+ reply->setFrom(senderResource[1]);
+ reply->setTo(ownJID);
+
+ csn = boost::make_shared<ChatState>();
+ csn->setChatState(ChatState::Composing);
+ reply->addPayload(csn);
+ manager_->handleIncomingMessage(reply);
+
+ // Send third message.
+ window->onSendMessageRequest("ping.", false);
+
+ // The chat session is now bound to the full JID of the second resource due to its recent composing message.
+ CPPUNIT_ASSERT_EQUAL(senderResource[1], stanzaChannel_->getStanzaAtIndex<Message>(3)->getTo());
+ CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(3)->getPayload<DeliveryReceiptRequest>());
+ }
+
+ void testChatControllerPMPresenceHandling() {
+ JID participantA = JID("test@rooms.test.com/participantA");
+ JID participantB = JID("test@rooms.test.com/participantB");
+
+ mucRegistry_->addMUC("test@rooms.test.com");
+
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(participantA, uiEventStream_).Return(window);
+
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(JID(participantA))));
+
+ Presence::ref presence = Presence::create();
+ presence->setFrom(participantA);
+ presence->setShow(StatusShow::Online);
+ stanzaChannel_->onPresenceReceived(presence);
+ CPPUNIT_ASSERT_EQUAL(std::string("participantA has become available."), MockChatWindow::bodyFromMessage(window->lastAddedPresence_));
+
+ presence = Presence::create();
+ presence->setFrom(participantB);
+ presence->setShow(StatusShow::Away);
+ stanzaChannel_->onPresenceReceived(presence);
+
+ presence = Presence::create();
+ presence->setFrom(participantA);
+ presence->setShow(StatusShow::None);
+ presence->setType(Presence::Unavailable);
+ stanzaChannel_->onPresenceReceived(presence);
+ CPPUNIT_ASSERT_EQUAL(std::string("participantA has gone offline."), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ }
+
+ void testLocalMUCServiceDiscoveryResetOnDisconnect() {
+ JID ownJID("test@test.com/resource");
+ JID sender("foo@test.com");
+
+ manager_->setOnline(true);
+
+ // Open chat window to a sender.
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(sender, uiEventStream_).Return(window);
+
+ uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(sender));
+
+ CPPUNIT_ASSERT_EQUAL(false, window->impromptuMUCSupported_);
+
+ boost::shared_ptr<IQ> infoRequest= iqChannel_->iqs_[1];
+ boost::shared_ptr<IQ> infoResponse = IQ::createResult(infoRequest->getFrom(), infoRequest->getTo(), infoRequest->getID());
+
+ DiscoInfo info;
+ info.addIdentity(DiscoInfo::Identity("Shakespearean Chat Service", "conference", "text"));
+ info.addFeature("http://jabber.org/protocol/muc");
+ infoResponse->addPayload(boost::make_shared<DiscoInfo>(info));
+ iqChannel_->onIQReceived(infoResponse);
+
+ CPPUNIT_ASSERT_EQUAL(true, window->impromptuMUCSupported_);
+ manager_->setOnline(false);
+ CPPUNIT_ASSERT_EQUAL(false, window->impromptuMUCSupported_);
+ }
+
+ void testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::Subscription from, RosterItemPayload::Subscription to) {
+ JID messageJID("testling@test.com/resource1");
+ xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), from);
+
+ MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+ settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
+
+ boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1");
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(st(0), stanzaChannel_->sentStanzas.size());
+
+ xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), to);
+ message->setID("2");
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size());
+ Stanza::ref stanzaContactOnRoster = stanzaChannel_->getStanzaAtIndex<Stanza>(0);
+ CPPUNIT_ASSERT(stanzaContactOnRoster->getPayload<DeliveryReceipt>() != 0);
+ }
+
+ void testChatControllerHighlightingNotificationTesting() {
+ HighlightRule keywordRuleA;
+ keywordRuleA.setMatchChat(true);
+ std::vector<std::string> keywordsA;
+ keywordsA.push_back("Romeo");
+ keywordRuleA.setKeywords(keywordsA);
+ keywordRuleA.getAction().setTextColor("yellow");
+ keywordRuleA.getAction().setPlaySound(true);
+ highlightManager_->insertRule(0, keywordRuleA);
+
+ HighlightRule keywordRuleB;
+ keywordRuleB.setMatchChat(true);
+ std::vector<std::string> keywordsB;
+ keywordsB.push_back("Juliet");
+ keywordRuleB.setKeywords(keywordsB);
+ keywordRuleB.getAction().setTextColor("green");
+ keywordRuleB.getAction().setPlaySound(true);
+ keywordRuleB.getAction().setSoundFile("/tmp/someotherfile.wav");
+ highlightManager_->insertRule(0, keywordRuleB);
+
+ JID messageJID = JID("testling@test.com");
+
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+
+ boost::shared_ptr<Message> message(new Message());
+ message->setFrom(messageJID);
+ std::string body("This message should cause two sounds: Juliet and Romeo.");
+ message->setBody(body);
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(2, handledHighlightActions_);
+ CPPUNIT_ASSERT(soundsPlayed_.find(keywordRuleA.getAction().getSoundFile()) != soundsPlayed_.end());
+ CPPUNIT_ASSERT(soundsPlayed_.find(keywordRuleB.getAction().getSoundFile()) != soundsPlayed_.end());
+ }
+
+ void testChatControllerHighlightingNotificationDeduplicateSounds() {
+ HighlightRule keywordRuleA;
+ keywordRuleA.setMatchChat(true);
+ std::vector<std::string> keywordsA;
+ keywordsA.push_back("Romeo");
+ keywordRuleA.setKeywords(keywordsA);
+ keywordRuleA.getAction().setTextColor("yellow");
+ keywordRuleA.getAction().setPlaySound(true);
+ highlightManager_->insertRule(0, keywordRuleA);
+
+ HighlightRule keywordRuleB;
+ keywordRuleB.setMatchChat(true);
+ std::vector<std::string> keywordsB;
+ keywordsB.push_back("Juliet");
+ keywordRuleB.setKeywords(keywordsB);
+ keywordRuleB.getAction().setTextColor("green");
+ keywordRuleB.getAction().setPlaySound(true);
+ highlightManager_->insertRule(0, keywordRuleB);
+
+ JID messageJID = JID("testling@test.com");
+
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+
+ boost::shared_ptr<Message> message(new Message());
+ message->setFrom(messageJID);
+ std::string body("This message should cause one sound, because both actions have the same sound: Juliet and Romeo.");
+ message->setBody(body);
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(1, handledHighlightActions_);
+ CPPUNIT_ASSERT(soundsPlayed_.find(keywordRuleA.getAction().getSoundFile()) != soundsPlayed_.end());
+ CPPUNIT_ASSERT(soundsPlayed_.find(keywordRuleB.getAction().getSoundFile()) != soundsPlayed_.end());
+ }
private:
- boost::shared_ptr<Message> makeDeliveryReceiptTestMessage(const JID& from, const std::string& id) {
- boost::shared_ptr<Message> message = boost::make_shared<Message>();
- message->setFrom(from);
- message->setID(id);
- message->setBody("This will cause the window to open");
- message->addPayload(boost::make_shared<DeliveryReceiptRequest>());
- return message;
- }
-
- size_t st(int i) {
- return static_cast<size_t>(i);
- }
-
- void handleHighlightAction(const HighlightAction& action) {
- handledHighlightActions_++;
- if (action.playSound()) {
- soundsPlayed_.insert(action.getSoundFile());
- }
- }
+ boost::shared_ptr<Message> makeDeliveryReceiptTestMessage(const JID& from, const std::string& id) {
+ boost::shared_ptr<Message> message = boost::make_shared<Message>();
+ message->setFrom(from);
+ message->setID(id);
+ message->setBody("This will cause the window to open");
+ message->addPayload(boost::make_shared<DeliveryReceiptRequest>());
+ return message;
+ }
+
+ size_t st(int i) {
+ return static_cast<size_t>(i);
+ }
+
+ void handleHighlightAction(const HighlightAction& action) {
+ handledHighlightActions_++;
+ if (action.playSound()) {
+ soundsPlayed_.insert(action.getSoundFile());
+ }
+ }
private:
- JID jid_;
- ChatsManager* manager_;
- DummyStanzaChannel* stanzaChannel_;
- DummyIQChannel* iqChannel_;
- IQRouter* iqRouter_;
- EventController* eventController_;
- ChatWindowFactory* chatWindowFactory_;
- JoinMUCWindowFactory* joinMUCWindowFactory_;
- NickResolver* nickResolver_;
- PresenceOracle* presenceOracle_;
- AvatarManager* avatarManager_;
- boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
- XMPPRosterImpl* xmppRoster_;
- PresenceSender* presenceSender_;
- MockRepository* mocks_;
- UIEventStream* uiEventStream_;
- ChatListWindowFactory* chatListWindowFactory_;
- WhiteboardWindowFactory* whiteboardWindowFactory_;
- MUCSearchWindowFactory* mucSearchWindowFactory_;
- MUCRegistry* mucRegistry_;
- DirectedPresenceSender* directedPresenceSender_;
- DummyEntityCapsProvider* entityCapsProvider_;
- MUCManager* mucManager_;
- DummySettingsProvider* settings_;
- ProfileSettingsProvider* profileSettings_;
- ChatListWindow* chatListWindow_;
- FileTransferOverview* ftOverview_;
- FileTransferManager* ftManager_;
- WhiteboardSessionManager* wbSessionManager_;
- WhiteboardManager* wbManager_;
- HighlightManager* highlightManager_;
- ClientBlockListManager* clientBlockListManager_;
- VCardManager* vcardManager_;
- CryptoProvider* crypto_;
- VCardStorage* vcardStorage_;
- std::map<std::string, std::string> emoticons_;
- int handledHighlightActions_;
- std::set<std::string> soundsPlayed_;
+ JID jid_;
+ ChatsManager* manager_;
+ DummyStanzaChannel* stanzaChannel_;
+ DummyIQChannel* iqChannel_;
+ IQRouter* iqRouter_;
+ EventController* eventController_;
+ ChatWindowFactory* chatWindowFactory_;
+ JoinMUCWindowFactory* joinMUCWindowFactory_;
+ NickResolver* nickResolver_;
+ PresenceOracle* presenceOracle_;
+ AvatarManager* avatarManager_;
+ boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
+ XMPPRosterImpl* xmppRoster_;
+ PresenceSender* presenceSender_;
+ MockRepository* mocks_;
+ UIEventStream* uiEventStream_;
+ ChatListWindowFactory* chatListWindowFactory_;
+ WhiteboardWindowFactory* whiteboardWindowFactory_;
+ MUCSearchWindowFactory* mucSearchWindowFactory_;
+ MUCRegistry* mucRegistry_;
+ DirectedPresenceSender* directedPresenceSender_;
+ DummyEntityCapsProvider* entityCapsProvider_;
+ MUCManager* mucManager_;
+ DummySettingsProvider* settings_;
+ ProfileSettingsProvider* profileSettings_;
+ ChatListWindow* chatListWindow_;
+ FileTransferOverview* ftOverview_;
+ FileTransferManager* ftManager_;
+ WhiteboardSessionManager* wbSessionManager_;
+ WhiteboardManager* wbManager_;
+ HighlightManager* highlightManager_;
+ ClientBlockListManager* clientBlockListManager_;
+ VCardManager* vcardManager_;
+ CryptoProvider* crypto_;
+ VCardStorage* vcardStorage_;
+ std::map<std::string, std::string> emoticons_;
+ int handledHighlightActions_;
+ std::set<std::string> soundsPlayed_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest);
diff --git a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
index e8fc41d..db9bcdc 100644
--- a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
@@ -48,509 +48,509 @@
using namespace Swift;
class MUCControllerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(MUCControllerTest);
- CPPUNIT_TEST(testJoinPartStringContructionSimple);
- CPPUNIT_TEST(testJoinPartStringContructionMixed);
- CPPUNIT_TEST(testAppendToJoinParts);
- CPPUNIT_TEST(testAddressedToSelf);
- CPPUNIT_TEST(testNotAddressedToSelf);
- CPPUNIT_TEST(testAddressedToSelfBySelf);
- CPPUNIT_TEST(testMessageWithEmptyLabelItem);
- CPPUNIT_TEST(testMessageWithLabelItem);
- CPPUNIT_TEST(testCorrectMessageWithLabelItem);
- CPPUNIT_TEST(testRoleAffiliationStates);
- CPPUNIT_TEST(testSubjectChangeCorrect);
- CPPUNIT_TEST(testSubjectChangeIncorrectA);
- CPPUNIT_TEST(testSubjectChangeIncorrectB);
- CPPUNIT_TEST(testSubjectChangeIncorrectC);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(MUCControllerTest);
+ CPPUNIT_TEST(testJoinPartStringContructionSimple);
+ CPPUNIT_TEST(testJoinPartStringContructionMixed);
+ CPPUNIT_TEST(testAppendToJoinParts);
+ CPPUNIT_TEST(testAddressedToSelf);
+ CPPUNIT_TEST(testNotAddressedToSelf);
+ CPPUNIT_TEST(testAddressedToSelfBySelf);
+ CPPUNIT_TEST(testMessageWithEmptyLabelItem);
+ CPPUNIT_TEST(testMessageWithLabelItem);
+ CPPUNIT_TEST(testCorrectMessageWithLabelItem);
+ CPPUNIT_TEST(testRoleAffiliationStates);
+ CPPUNIT_TEST(testSubjectChangeCorrect);
+ CPPUNIT_TEST(testSubjectChangeIncorrectA);
+ CPPUNIT_TEST(testSubjectChangeIncorrectB);
+ CPPUNIT_TEST(testSubjectChangeIncorrectC);
+ CPPUNIT_TEST_SUITE_END();
public:
- void setUp() {
- crypto_ = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
- self_ = JID("girl@wonderland.lit/rabbithole");
- nick_ = "aLiCe";
- mucJID_ = JID("teaparty@rooms.wonderland.lit");
- mocks_ = new MockRepository();
- stanzaChannel_ = new DummyStanzaChannel();
- iqChannel_ = new DummyIQChannel();
- iqRouter_ = new IQRouter(iqChannel_);
- eventController_ = new EventController();
- chatWindowFactory_ = mocks_->InterfaceMock<ChatWindowFactory>();
- userSearchWindowFactory_ = mocks_->InterfaceMock<UserSearchWindowFactory>();
- xmppRoster_ = new XMPPRosterImpl();
- presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
- presenceSender_ = new StanzaChannelPresenceSender(stanzaChannel_);
- directedPresenceSender_ = new DirectedPresenceSender(presenceSender_);
- uiEventStream_ = new UIEventStream();
- avatarManager_ = new NullAvatarManager();
- TimerFactory* timerFactory = NULL;
- window_ = new MockChatWindow();
- mucRegistry_ = new MUCRegistry();
- entityCapsProvider_ = new DummyEntityCapsProvider();
- settings_ = new DummySettingsProvider();
- highlightManager_ = new HighlightManager(settings_);
- muc_ = boost::make_shared<MockMUC>(mucJID_);
- mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(muc_->getJID(), uiEventStream_).Return(window_);
- chatMessageParser_ = boost::make_shared<ChatMessageParser>(std::map<std::string, std::string>(), highlightManager_->getRules(), true);
- vcardStorage_ = new VCardMemoryStorage(crypto_.get());
- vcardManager_ = new VCardManager(self_, iqRouter_, vcardStorage_);
- clientBlockListManager_ = new ClientBlockListManager(iqRouter_);
- mucBookmarkManager_ = new MUCBookmarkManager(iqRouter_);
- controller_ = new MUCController (self_, muc_, boost::optional<std::string>(), nick_, stanzaChannel_, iqRouter_, chatWindowFactory_, presenceOracle_, avatarManager_, uiEventStream_, false, timerFactory, eventController_, entityCapsProvider_, NULL, NULL, mucRegistry_, highlightManager_, clientBlockListManager_, chatMessageParser_, false, NULL, vcardManager_, mucBookmarkManager_);
- }
-
- void tearDown() {
- delete controller_;
- delete mucBookmarkManager_;
- delete clientBlockListManager_;
- delete vcardManager_;
- delete vcardStorage_;
- delete highlightManager_;
- delete settings_;
- delete entityCapsProvider_;
- delete eventController_;
- delete presenceOracle_;
- delete xmppRoster_;
- delete mocks_;
- delete uiEventStream_;
- delete stanzaChannel_;
- delete presenceSender_;
- delete directedPresenceSender_;
- delete iqRouter_;
- delete iqChannel_;
- delete mucRegistry_;
- delete avatarManager_;
- }
-
- void finishJoin() {
- Presence::ref presence(new Presence());
- presence->setFrom(JID(muc_->getJID().toString() + "/" + nick_));
- MUCUserPayload::ref status(new MUCUserPayload());
- MUCUserPayload::StatusCode code;
- code.code = 110;
- status->addStatusCode(code);
- presence->addPayload(status);
- stanzaChannel_->onPresenceReceived(presence);
- }
-
- void testAddressedToSelf() {
- finishJoin();
- Message::ref message(new Message());
-
- message = Message::ref(new Message());
- message->setFrom(JID(muc_->getJID().toString() + "/otherperson"));
- message->setBody("basic " + nick_ + " test.");
- message->setType(Message::Groupchat);
- controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
- CPPUNIT_ASSERT_EQUAL((size_t)1, eventController_->getEvents().size());
-
- message = Message::ref(new Message());
- message->setFrom(JID(muc_->getJID().toString() + "/otherperson"));
- message->setBody(nick_ + ": hi there");
- message->setType(Message::Groupchat);
- controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
- CPPUNIT_ASSERT_EQUAL((size_t)2, eventController_->getEvents().size());
-
- message->setFrom(JID(muc_->getJID().toString() + "/other"));
- message->setBody("Hi there " + nick_);
- message->setType(Message::Groupchat);
- controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
- CPPUNIT_ASSERT_EQUAL((size_t)3, eventController_->getEvents().size());
-
- message = Message::ref(new Message());
- message->setFrom(JID(muc_->getJID().toString() + "/other2"));
- message->setBody("Hi " + boost::to_lower_copy(nick_) + ".");
- message->setType(Message::Groupchat);
- controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
- CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
-
- message = Message::ref(new Message());
- message->setFrom(JID(muc_->getJID().toString() + "/other3"));
- message->setBody("Hi bert.");
- message->setType(Message::Groupchat);
- controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
- CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
-
- message = Message::ref(new Message());
- message->setFrom(JID(muc_->getJID().toString() + "/other2"));
- message->setBody("Hi " + boost::to_lower_copy(nick_) + "ie.");
- message->setType(Message::Groupchat);
- controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
- CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
- }
-
- void testNotAddressedToSelf() {
- finishJoin();
- Message::ref message(new Message());
- message->setFrom(JID(muc_->getJID().toString() + "/other3"));
- message->setBody("Hi there Hatter");
- message->setType(Message::Groupchat);
- controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
- CPPUNIT_ASSERT_EQUAL((size_t)0, eventController_->getEvents().size());
- }
-
- void testAddressedToSelfBySelf() {
- finishJoin();
- Message::ref message(new Message());
- message->setFrom(JID(muc_->getJID().toString() + "/" + nick_));
- message->setBody("Hi there " + nick_);
- message->setType(Message::Groupchat);
- controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
- CPPUNIT_ASSERT_EQUAL((size_t)0, eventController_->getEvents().size());
- }
-
- void testMessageWithEmptyLabelItem() {
- SecurityLabelsCatalog::Item label;
- label.setSelector("Bob");
- window_->label_ = label;
- boost::shared_ptr<DiscoInfo> features = boost::make_shared<DiscoInfo>();
- features->addFeature(DiscoInfo::SecurityLabelsCatalogFeature);
- controller_->setAvailableServerFeatures(features);
- IQ::ref iq = iqChannel_->iqs_[iqChannel_->iqs_.size() - 1];
- SecurityLabelsCatalog::ref labelPayload = boost::make_shared<SecurityLabelsCatalog>();
- labelPayload->addItem(label);
- IQ::ref result = IQ::createResult(self_, iq->getID(), labelPayload);
- iqChannel_->onIQReceived(result);
- std::string messageBody("agamemnon");
- window_->onSendMessageRequest(messageBody, false);
- boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
- Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
- CPPUNIT_ASSERT_EQUAL(iq->getTo(), result->getFrom());
- CPPUNIT_ASSERT(window_->labelsEnabled_);
- CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
- CPPUNIT_ASSERT(message);
- CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get());
- CPPUNIT_ASSERT(!message->getPayload<SecurityLabel>());
- }
-
- void testMessageWithLabelItem() {
- boost::shared_ptr<SecurityLabel> label = boost::make_shared<SecurityLabel>();
- label->setLabel("a");
- SecurityLabelsCatalog::Item labelItem;
- labelItem.setSelector("Bob");
- labelItem.setLabel(label);
- window_->label_ = labelItem;
- boost::shared_ptr<DiscoInfo> features = boost::make_shared<DiscoInfo>();
- features->addFeature(DiscoInfo::SecurityLabelsCatalogFeature);
- controller_->setAvailableServerFeatures(features);
- IQ::ref iq = iqChannel_->iqs_[iqChannel_->iqs_.size() - 1];
- SecurityLabelsCatalog::ref labelPayload = boost::make_shared<SecurityLabelsCatalog>();
- labelPayload->addItem(labelItem);
- IQ::ref result = IQ::createResult(self_, iq->getID(), labelPayload);
- iqChannel_->onIQReceived(result);
- std::string messageBody("agamemnon");
- window_->onSendMessageRequest(messageBody, false);
- boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
- Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
- CPPUNIT_ASSERT_EQUAL(iq->getTo(), result->getFrom());
- CPPUNIT_ASSERT(window_->labelsEnabled_);
- CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
- CPPUNIT_ASSERT(message);
- CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get());
- CPPUNIT_ASSERT_EQUAL(label, message->getPayload<SecurityLabel>());
- }
-
- void testCorrectMessageWithLabelItem() {
- boost::shared_ptr<SecurityLabel> label = boost::make_shared<SecurityLabel>();
- label->setLabel("a");
- SecurityLabelsCatalog::Item labelItem;
- labelItem.setSelector("Bob");
- labelItem.setLabel(label);
- boost::shared_ptr<SecurityLabel> label2 = boost::make_shared<SecurityLabel>();
- label->setLabel("b");
- SecurityLabelsCatalog::Item labelItem2;
- labelItem2.setSelector("Charlie");
- labelItem2.setLabel(label2);
- window_->label_ = labelItem;
- boost::shared_ptr<DiscoInfo> features = boost::make_shared<DiscoInfo>();
- features->addFeature(DiscoInfo::SecurityLabelsCatalogFeature);
- controller_->setAvailableServerFeatures(features);
- IQ::ref iq = iqChannel_->iqs_[iqChannel_->iqs_.size() - 1];
- SecurityLabelsCatalog::ref labelPayload = boost::make_shared<SecurityLabelsCatalog>();
- labelPayload->addItem(labelItem);
- IQ::ref result = IQ::createResult(self_, iq->getID(), labelPayload);
- iqChannel_->onIQReceived(result);
- std::string messageBody("agamemnon");
- window_->onSendMessageRequest(messageBody, false);
- boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
- Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
- CPPUNIT_ASSERT_EQUAL(iq->getTo(), result->getFrom());
- CPPUNIT_ASSERT(window_->labelsEnabled_);
- CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
- CPPUNIT_ASSERT(message);
- CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get());
- CPPUNIT_ASSERT_EQUAL(label, message->getPayload<SecurityLabel>());
- window_->label_ = labelItem2;
- window_->onSendMessageRequest(messageBody, true);
- rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
- message = boost::dynamic_pointer_cast<Message>(rawStanza);
- CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get());
- CPPUNIT_ASSERT_EQUAL(label, message->getPayload<SecurityLabel>());
- }
-
- void checkEqual(const std::vector<NickJoinPart>& expected, const std::vector<NickJoinPart>& actual) {
- CPPUNIT_ASSERT_EQUAL(expected.size(), actual.size());
- for (size_t i = 0; i < expected.size(); i++) {
- CPPUNIT_ASSERT_EQUAL(expected[i].nick, actual[i].nick);
- CPPUNIT_ASSERT_EQUAL(expected[i].type, actual[i].type);
- }
- }
-
- void testAppendToJoinParts() {
- std::vector<NickJoinPart> list;
- std::vector<NickJoinPart> gold;
- MUCController::appendToJoinParts(list, NickJoinPart("Kev", Join));
- gold.push_back(NickJoinPart("Kev", Join));
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Remko", Join));
- gold.push_back(NickJoinPart("Remko", Join));
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Bert", Join));
- gold.push_back(NickJoinPart("Bert", Join));
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Bert", Part));
- gold[2].type = JoinThenPart;
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Kev", Part));
- gold[0].type = JoinThenPart;
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Remko", Part));
- gold[1].type = JoinThenPart;
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Ernie", Part));
- gold.push_back(NickJoinPart("Ernie", Part));
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Ernie", Join));
- gold[3].type = PartThenJoin;
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Kev", Join));
- gold[0].type = Join;
- checkEqual(gold, list);
- MUCController::appendToJoinParts(list, NickJoinPart("Ernie", Part));
- gold[3].type = Part;
- checkEqual(gold, list);
-
- }
-
- void testJoinPartStringContructionSimple() {
- std::vector<NickJoinPart> list;
- list.push_back(NickJoinPart("Kev", Join));
- CPPUNIT_ASSERT_EQUAL(std::string("Kev has entered the room"), MUCController::generateJoinPartString(list, false));
- list.push_back(NickJoinPart("Remko", Part));
- CPPUNIT_ASSERT_EQUAL(std::string("Kev has entered the room and Remko has left the room"), MUCController::generateJoinPartString(list, false));
- list.push_back(NickJoinPart("Bert", Join));
- CPPUNIT_ASSERT_EQUAL(std::string("Kev and Bert have entered the room and Remko has left the room"), MUCController::generateJoinPartString(list, false));
- list.push_back(NickJoinPart("Ernie", Join));
- CPPUNIT_ASSERT_EQUAL(std::string("Kev, Bert and Ernie have entered the room and Remko has left the room"), MUCController::generateJoinPartString(list, false));
- }
-
- void testJoinPartStringContructionMixed() {
- std::vector<NickJoinPart> list;
- list.push_back(NickJoinPart("Kev", JoinThenPart));
- CPPUNIT_ASSERT_EQUAL(std::string("Kev has entered then left the room"), MUCController::generateJoinPartString(list, false));
- list.push_back(NickJoinPart("Remko", Part));
- CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room and Kev has entered then left the room"), MUCController::generateJoinPartString(list, false));
- list.push_back(NickJoinPart("Bert", PartThenJoin));
- CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room, Kev has entered then left the room and Bert has left then returned to the room"), MUCController::generateJoinPartString(list, false));
- list.push_back(NickJoinPart("Ernie", JoinThenPart));
- CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room, Kev and Ernie have entered then left the room and Bert has left then returned to the room"), MUCController::generateJoinPartString(list, false));
- }
-
- JID jidFromOccupant(const MUCOccupant& occupant) {
- return JID(mucJID_.toString()+"/"+occupant.getNick());
- }
-
- void testRoleAffiliationStates() {
-
- typedef std::map<std::string, MUCOccupant> occupant_map;
- occupant_map occupants;
- occupants.insert(occupant_map::value_type("Kev", MUCOccupant("Kev", MUCOccupant::Participant, MUCOccupant::Owner)));
- occupants.insert(occupant_map::value_type("Remko", MUCOccupant("Remko", MUCOccupant::Participant, MUCOccupant::Owner)));
- occupants.insert(occupant_map::value_type("Bert", MUCOccupant("Bert", MUCOccupant::Participant, MUCOccupant::Owner)));
- occupants.insert(occupant_map::value_type("Ernie", MUCOccupant("Ernie", MUCOccupant::Participant, MUCOccupant::Owner)));
-
- /* populate the MUC with fake users */
- typedef const std::pair<std::string,MUCOccupant> occupantIterator;
- foreach(occupantIterator &occupant, occupants) {
- muc_->insertOccupant(occupant.second);
- }
-
- std::vector<MUCOccupant> alterations;
- alterations.push_back(MUCOccupant("Kev", MUCOccupant::Visitor, MUCOccupant::Admin));
- alterations.push_back(MUCOccupant("Remko", MUCOccupant::Moderator, MUCOccupant::Member));
- alterations.push_back(MUCOccupant("Bert", MUCOccupant::Visitor, MUCOccupant::Outcast));
- alterations.push_back(MUCOccupant("Ernie", MUCOccupant::NoRole, MUCOccupant::Member));
- alterations.push_back(MUCOccupant("Bert", MUCOccupant::Moderator, MUCOccupant::Owner));
- alterations.push_back(MUCOccupant("Kev", MUCOccupant::Participant, MUCOccupant::Outcast));
- alterations.push_back(MUCOccupant("Bert", MUCOccupant::Visitor, MUCOccupant::NoAffiliation));
- alterations.push_back(MUCOccupant("Remko", MUCOccupant::NoRole, MUCOccupant::NoAffiliation));
- alterations.push_back(MUCOccupant("Ernie", MUCOccupant::Visitor, MUCOccupant::Outcast));
-
- foreach(const MUCOccupant& alteration, alterations) {
- /* perform an alteration to a user's role and affiliation */
- occupant_map::iterator occupant = occupants.find(alteration.getNick());
- CPPUNIT_ASSERT(occupant != occupants.end());
- const JID jid = jidFromOccupant(occupant->second);
- /* change the affiliation, leave the role in place */
- muc_->changeAffiliation(jid, alteration.getAffiliation());
- occupant->second = MUCOccupant(occupant->first, occupant->second.getRole(), alteration.getAffiliation());
- testRoleAffiliationStatesVerify(occupants);
- /* change the role, leave the affiliation in place */
- muc_->changeOccupantRole(jid, alteration.getRole());
- occupant->second = MUCOccupant(occupant->first, alteration.getRole(), occupant->second.getAffiliation());
- testRoleAffiliationStatesVerify(occupants);
- }
- }
-
- void testSubjectChangeCorrect() {
- std::string messageBody("test message");
- window_->onSendMessageRequest(messageBody, false);
- boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
- Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
- CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
- CPPUNIT_ASSERT(message);
- CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
-
- {
- Message::ref message = boost::make_shared<Message>();
- message->setType(Message::Groupchat);
- message->setTo(self_);
- message->setFrom(mucJID_.withResource("SomeNickname"));
- message->setID(iqChannel_->getNewIQID());
- message->setSubject("New Room Subject");
-
- controller_->handleIncomingMessage(boost::make_shared<MessageEvent>(message));
- CPPUNIT_ASSERT_EQUAL(std::string("The room subject is now: New Room Subject"), boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
- }
- }
-
- /*
- * Test that message stanzas with subject element and non-empty body element do not cause a subject change.
- */
- void testSubjectChangeIncorrectA() {
- std::string messageBody("test message");
- window_->onSendMessageRequest(messageBody, false);
- boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
- Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
- CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
- CPPUNIT_ASSERT(message);
- CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
-
- {
- Message::ref message = boost::make_shared<Message>();
- message->setType(Message::Groupchat);
- message->setTo(self_);
- message->setFrom(mucJID_.withResource("SomeNickname"));
- message->setID(iqChannel_->getNewIQID());
- message->setSubject("New Room Subject");
- message->setBody("Some body text that prevents this stanza from being a subject change.");
-
- controller_->handleIncomingMessage(boost::make_shared<MessageEvent>(message));
- CPPUNIT_ASSERT_EQUAL(std::string("Trying to enter room teaparty@rooms.wonderland.lit"), boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
- }
- }
-
- /*
- * Test that message stanzas with subject element and thread element do not cause a subject change.
- */
- void testSubjectChangeIncorrectB() {
- std::string messageBody("test message");
- window_->onSendMessageRequest(messageBody, false);
- boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
- Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
- CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
- CPPUNIT_ASSERT(message);
- CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
-
- {
- Message::ref message = boost::make_shared<Message>();
- message->setType(Message::Groupchat);
- message->setTo(self_);
- message->setFrom(mucJID_.withResource("SomeNickname"));
- message->setID(iqChannel_->getNewIQID());
- message->setSubject("New Room Subject");
- message->addPayload(boost::make_shared<Thread>("Thread that prevents the subject change."));
-
- controller_->handleIncomingMessage(boost::make_shared<MessageEvent>(message));
- CPPUNIT_ASSERT_EQUAL(std::string("Trying to enter room teaparty@rooms.wonderland.lit"), boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
- }
- }
-
- /*
- * Test that message stanzas with subject element and empty body element do not cause a subject change.
- */
- void testSubjectChangeIncorrectC() {
- std::string messageBody("test message");
- window_->onSendMessageRequest(messageBody, false);
- boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
- Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
- CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
- CPPUNIT_ASSERT(message);
- CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
-
- {
- Message::ref message = boost::make_shared<Message>();
- message->setType(Message::Groupchat);
- message->setTo(self_);
- message->setFrom(mucJID_.withResource("SomeNickname"));
- message->setID(iqChannel_->getNewIQID());
- message->setSubject("New Room Subject");
- message->setBody("");
-
- controller_->handleIncomingMessage(boost::make_shared<MessageEvent>(message));
- CPPUNIT_ASSERT_EQUAL(std::string("Trying to enter room teaparty@rooms.wonderland.lit"), boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
- }
- }
-
- void testRoleAffiliationStatesVerify(const std::map<std::string, MUCOccupant> &occupants) {
- /* verify that the roster is in sync */
- GroupRosterItem* group = window_->getRosterModel()->getRoot();
- foreach(RosterItem* rosterItem, group->getChildren()) {
- GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(rosterItem);
- CPPUNIT_ASSERT(child);
- foreach(RosterItem* childItem, child->getChildren()) {
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(childItem);
- CPPUNIT_ASSERT(item);
- std::map<std::string, MUCOccupant>::const_iterator occupant = occupants.find(item->getJID().getResource());
- CPPUNIT_ASSERT(occupant != occupants.end());
- CPPUNIT_ASSERT(item->getMUCRole() == occupant->second.getRole());
- CPPUNIT_ASSERT(item->getMUCAffiliation() == occupant->second.getAffiliation());
- }
- }
- }
+ void setUp() {
+ crypto_ = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
+ self_ = JID("girl@wonderland.lit/rabbithole");
+ nick_ = "aLiCe";
+ mucJID_ = JID("teaparty@rooms.wonderland.lit");
+ mocks_ = new MockRepository();
+ stanzaChannel_ = new DummyStanzaChannel();
+ iqChannel_ = new DummyIQChannel();
+ iqRouter_ = new IQRouter(iqChannel_);
+ eventController_ = new EventController();
+ chatWindowFactory_ = mocks_->InterfaceMock<ChatWindowFactory>();
+ userSearchWindowFactory_ = mocks_->InterfaceMock<UserSearchWindowFactory>();
+ xmppRoster_ = new XMPPRosterImpl();
+ presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
+ presenceSender_ = new StanzaChannelPresenceSender(stanzaChannel_);
+ directedPresenceSender_ = new DirectedPresenceSender(presenceSender_);
+ uiEventStream_ = new UIEventStream();
+ avatarManager_ = new NullAvatarManager();
+ TimerFactory* timerFactory = NULL;
+ window_ = new MockChatWindow();
+ mucRegistry_ = new MUCRegistry();
+ entityCapsProvider_ = new DummyEntityCapsProvider();
+ settings_ = new DummySettingsProvider();
+ highlightManager_ = new HighlightManager(settings_);
+ muc_ = boost::make_shared<MockMUC>(mucJID_);
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(muc_->getJID(), uiEventStream_).Return(window_);
+ chatMessageParser_ = boost::make_shared<ChatMessageParser>(std::map<std::string, std::string>(), highlightManager_->getRules(), true);
+ vcardStorage_ = new VCardMemoryStorage(crypto_.get());
+ vcardManager_ = new VCardManager(self_, iqRouter_, vcardStorage_);
+ clientBlockListManager_ = new ClientBlockListManager(iqRouter_);
+ mucBookmarkManager_ = new MUCBookmarkManager(iqRouter_);
+ controller_ = new MUCController (self_, muc_, boost::optional<std::string>(), nick_, stanzaChannel_, iqRouter_, chatWindowFactory_, presenceOracle_, avatarManager_, uiEventStream_, false, timerFactory, eventController_, entityCapsProvider_, NULL, NULL, mucRegistry_, highlightManager_, clientBlockListManager_, chatMessageParser_, false, NULL, vcardManager_, mucBookmarkManager_);
+ }
+
+ void tearDown() {
+ delete controller_;
+ delete mucBookmarkManager_;
+ delete clientBlockListManager_;
+ delete vcardManager_;
+ delete vcardStorage_;
+ delete highlightManager_;
+ delete settings_;
+ delete entityCapsProvider_;
+ delete eventController_;
+ delete presenceOracle_;
+ delete xmppRoster_;
+ delete mocks_;
+ delete uiEventStream_;
+ delete stanzaChannel_;
+ delete presenceSender_;
+ delete directedPresenceSender_;
+ delete iqRouter_;
+ delete iqChannel_;
+ delete mucRegistry_;
+ delete avatarManager_;
+ }
+
+ void finishJoin() {
+ Presence::ref presence(new Presence());
+ presence->setFrom(JID(muc_->getJID().toString() + "/" + nick_));
+ MUCUserPayload::ref status(new MUCUserPayload());
+ MUCUserPayload::StatusCode code;
+ code.code = 110;
+ status->addStatusCode(code);
+ presence->addPayload(status);
+ stanzaChannel_->onPresenceReceived(presence);
+ }
+
+ void testAddressedToSelf() {
+ finishJoin();
+ Message::ref message(new Message());
+
+ message = Message::ref(new Message());
+ message->setFrom(JID(muc_->getJID().toString() + "/otherperson"));
+ message->setBody("basic " + nick_ + " test.");
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)1, eventController_->getEvents().size());
+
+ message = Message::ref(new Message());
+ message->setFrom(JID(muc_->getJID().toString() + "/otherperson"));
+ message->setBody(nick_ + ": hi there");
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)2, eventController_->getEvents().size());
+
+ message->setFrom(JID(muc_->getJID().toString() + "/other"));
+ message->setBody("Hi there " + nick_);
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)3, eventController_->getEvents().size());
+
+ message = Message::ref(new Message());
+ message->setFrom(JID(muc_->getJID().toString() + "/other2"));
+ message->setBody("Hi " + boost::to_lower_copy(nick_) + ".");
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
+
+ message = Message::ref(new Message());
+ message->setFrom(JID(muc_->getJID().toString() + "/other3"));
+ message->setBody("Hi bert.");
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
+
+ message = Message::ref(new Message());
+ message->setFrom(JID(muc_->getJID().toString() + "/other2"));
+ message->setBody("Hi " + boost::to_lower_copy(nick_) + "ie.");
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
+ }
+
+ void testNotAddressedToSelf() {
+ finishJoin();
+ Message::ref message(new Message());
+ message->setFrom(JID(muc_->getJID().toString() + "/other3"));
+ message->setBody("Hi there Hatter");
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)0, eventController_->getEvents().size());
+ }
+
+ void testAddressedToSelfBySelf() {
+ finishJoin();
+ Message::ref message(new Message());
+ message->setFrom(JID(muc_->getJID().toString() + "/" + nick_));
+ message->setBody("Hi there " + nick_);
+ message->setType(Message::Groupchat);
+ controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+ CPPUNIT_ASSERT_EQUAL((size_t)0, eventController_->getEvents().size());
+ }
+
+ void testMessageWithEmptyLabelItem() {
+ SecurityLabelsCatalog::Item label;
+ label.setSelector("Bob");
+ window_->label_ = label;
+ boost::shared_ptr<DiscoInfo> features = boost::make_shared<DiscoInfo>();
+ features->addFeature(DiscoInfo::SecurityLabelsCatalogFeature);
+ controller_->setAvailableServerFeatures(features);
+ IQ::ref iq = iqChannel_->iqs_[iqChannel_->iqs_.size() - 1];
+ SecurityLabelsCatalog::ref labelPayload = boost::make_shared<SecurityLabelsCatalog>();
+ labelPayload->addItem(label);
+ IQ::ref result = IQ::createResult(self_, iq->getID(), labelPayload);
+ iqChannel_->onIQReceived(result);
+ std::string messageBody("agamemnon");
+ window_->onSendMessageRequest(messageBody, false);
+ boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
+ Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
+ CPPUNIT_ASSERT_EQUAL(iq->getTo(), result->getFrom());
+ CPPUNIT_ASSERT(window_->labelsEnabled_);
+ CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
+ CPPUNIT_ASSERT(message);
+ CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get());
+ CPPUNIT_ASSERT(!message->getPayload<SecurityLabel>());
+ }
+
+ void testMessageWithLabelItem() {
+ boost::shared_ptr<SecurityLabel> label = boost::make_shared<SecurityLabel>();
+ label->setLabel("a");
+ SecurityLabelsCatalog::Item labelItem;
+ labelItem.setSelector("Bob");
+ labelItem.setLabel(label);
+ window_->label_ = labelItem;
+ boost::shared_ptr<DiscoInfo> features = boost::make_shared<DiscoInfo>();
+ features->addFeature(DiscoInfo::SecurityLabelsCatalogFeature);
+ controller_->setAvailableServerFeatures(features);
+ IQ::ref iq = iqChannel_->iqs_[iqChannel_->iqs_.size() - 1];
+ SecurityLabelsCatalog::ref labelPayload = boost::make_shared<SecurityLabelsCatalog>();
+ labelPayload->addItem(labelItem);
+ IQ::ref result = IQ::createResult(self_, iq->getID(), labelPayload);
+ iqChannel_->onIQReceived(result);
+ std::string messageBody("agamemnon");
+ window_->onSendMessageRequest(messageBody, false);
+ boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
+ Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
+ CPPUNIT_ASSERT_EQUAL(iq->getTo(), result->getFrom());
+ CPPUNIT_ASSERT(window_->labelsEnabled_);
+ CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
+ CPPUNIT_ASSERT(message);
+ CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get());
+ CPPUNIT_ASSERT_EQUAL(label, message->getPayload<SecurityLabel>());
+ }
+
+ void testCorrectMessageWithLabelItem() {
+ boost::shared_ptr<SecurityLabel> label = boost::make_shared<SecurityLabel>();
+ label->setLabel("a");
+ SecurityLabelsCatalog::Item labelItem;
+ labelItem.setSelector("Bob");
+ labelItem.setLabel(label);
+ boost::shared_ptr<SecurityLabel> label2 = boost::make_shared<SecurityLabel>();
+ label->setLabel("b");
+ SecurityLabelsCatalog::Item labelItem2;
+ labelItem2.setSelector("Charlie");
+ labelItem2.setLabel(label2);
+ window_->label_ = labelItem;
+ boost::shared_ptr<DiscoInfo> features = boost::make_shared<DiscoInfo>();
+ features->addFeature(DiscoInfo::SecurityLabelsCatalogFeature);
+ controller_->setAvailableServerFeatures(features);
+ IQ::ref iq = iqChannel_->iqs_[iqChannel_->iqs_.size() - 1];
+ SecurityLabelsCatalog::ref labelPayload = boost::make_shared<SecurityLabelsCatalog>();
+ labelPayload->addItem(labelItem);
+ IQ::ref result = IQ::createResult(self_, iq->getID(), labelPayload);
+ iqChannel_->onIQReceived(result);
+ std::string messageBody("agamemnon");
+ window_->onSendMessageRequest(messageBody, false);
+ boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
+ Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
+ CPPUNIT_ASSERT_EQUAL(iq->getTo(), result->getFrom());
+ CPPUNIT_ASSERT(window_->labelsEnabled_);
+ CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
+ CPPUNIT_ASSERT(message);
+ CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get());
+ CPPUNIT_ASSERT_EQUAL(label, message->getPayload<SecurityLabel>());
+ window_->label_ = labelItem2;
+ window_->onSendMessageRequest(messageBody, true);
+ rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
+ message = boost::dynamic_pointer_cast<Message>(rawStanza);
+ CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get());
+ CPPUNIT_ASSERT_EQUAL(label, message->getPayload<SecurityLabel>());
+ }
+
+ void checkEqual(const std::vector<NickJoinPart>& expected, const std::vector<NickJoinPart>& actual) {
+ CPPUNIT_ASSERT_EQUAL(expected.size(), actual.size());
+ for (size_t i = 0; i < expected.size(); i++) {
+ CPPUNIT_ASSERT_EQUAL(expected[i].nick, actual[i].nick);
+ CPPUNIT_ASSERT_EQUAL(expected[i].type, actual[i].type);
+ }
+ }
+
+ void testAppendToJoinParts() {
+ std::vector<NickJoinPart> list;
+ std::vector<NickJoinPart> gold;
+ MUCController::appendToJoinParts(list, NickJoinPart("Kev", Join));
+ gold.push_back(NickJoinPart("Kev", Join));
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Remko", Join));
+ gold.push_back(NickJoinPart("Remko", Join));
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Bert", Join));
+ gold.push_back(NickJoinPart("Bert", Join));
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Bert", Part));
+ gold[2].type = JoinThenPart;
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Kev", Part));
+ gold[0].type = JoinThenPart;
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Remko", Part));
+ gold[1].type = JoinThenPart;
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Ernie", Part));
+ gold.push_back(NickJoinPart("Ernie", Part));
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Ernie", Join));
+ gold[3].type = PartThenJoin;
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Kev", Join));
+ gold[0].type = Join;
+ checkEqual(gold, list);
+ MUCController::appendToJoinParts(list, NickJoinPart("Ernie", Part));
+ gold[3].type = Part;
+ checkEqual(gold, list);
+
+ }
+
+ void testJoinPartStringContructionSimple() {
+ std::vector<NickJoinPart> list;
+ list.push_back(NickJoinPart("Kev", Join));
+ CPPUNIT_ASSERT_EQUAL(std::string("Kev has entered the room"), MUCController::generateJoinPartString(list, false));
+ list.push_back(NickJoinPart("Remko", Part));
+ CPPUNIT_ASSERT_EQUAL(std::string("Kev has entered the room and Remko has left the room"), MUCController::generateJoinPartString(list, false));
+ list.push_back(NickJoinPart("Bert", Join));
+ CPPUNIT_ASSERT_EQUAL(std::string("Kev and Bert have entered the room and Remko has left the room"), MUCController::generateJoinPartString(list, false));
+ list.push_back(NickJoinPart("Ernie", Join));
+ CPPUNIT_ASSERT_EQUAL(std::string("Kev, Bert and Ernie have entered the room and Remko has left the room"), MUCController::generateJoinPartString(list, false));
+ }
+
+ void testJoinPartStringContructionMixed() {
+ std::vector<NickJoinPart> list;
+ list.push_back(NickJoinPart("Kev", JoinThenPart));
+ CPPUNIT_ASSERT_EQUAL(std::string("Kev has entered then left the room"), MUCController::generateJoinPartString(list, false));
+ list.push_back(NickJoinPart("Remko", Part));
+ CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room and Kev has entered then left the room"), MUCController::generateJoinPartString(list, false));
+ list.push_back(NickJoinPart("Bert", PartThenJoin));
+ CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room, Kev has entered then left the room and Bert has left then returned to the room"), MUCController::generateJoinPartString(list, false));
+ list.push_back(NickJoinPart("Ernie", JoinThenPart));
+ CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room, Kev and Ernie have entered then left the room and Bert has left then returned to the room"), MUCController::generateJoinPartString(list, false));
+ }
+
+ JID jidFromOccupant(const MUCOccupant& occupant) {
+ return JID(mucJID_.toString()+"/"+occupant.getNick());
+ }
+
+ void testRoleAffiliationStates() {
+
+ typedef std::map<std::string, MUCOccupant> occupant_map;
+ occupant_map occupants;
+ occupants.insert(occupant_map::value_type("Kev", MUCOccupant("Kev", MUCOccupant::Participant, MUCOccupant::Owner)));
+ occupants.insert(occupant_map::value_type("Remko", MUCOccupant("Remko", MUCOccupant::Participant, MUCOccupant::Owner)));
+ occupants.insert(occupant_map::value_type("Bert", MUCOccupant("Bert", MUCOccupant::Participant, MUCOccupant::Owner)));
+ occupants.insert(occupant_map::value_type("Ernie", MUCOccupant("Ernie", MUCOccupant::Participant, MUCOccupant::Owner)));
+
+ /* populate the MUC with fake users */
+ typedef const std::pair<std::string,MUCOccupant> occupantIterator;
+ foreach(occupantIterator &occupant, occupants) {
+ muc_->insertOccupant(occupant.second);
+ }
+
+ std::vector<MUCOccupant> alterations;
+ alterations.push_back(MUCOccupant("Kev", MUCOccupant::Visitor, MUCOccupant::Admin));
+ alterations.push_back(MUCOccupant("Remko", MUCOccupant::Moderator, MUCOccupant::Member));
+ alterations.push_back(MUCOccupant("Bert", MUCOccupant::Visitor, MUCOccupant::Outcast));
+ alterations.push_back(MUCOccupant("Ernie", MUCOccupant::NoRole, MUCOccupant::Member));
+ alterations.push_back(MUCOccupant("Bert", MUCOccupant::Moderator, MUCOccupant::Owner));
+ alterations.push_back(MUCOccupant("Kev", MUCOccupant::Participant, MUCOccupant::Outcast));
+ alterations.push_back(MUCOccupant("Bert", MUCOccupant::Visitor, MUCOccupant::NoAffiliation));
+ alterations.push_back(MUCOccupant("Remko", MUCOccupant::NoRole, MUCOccupant::NoAffiliation));
+ alterations.push_back(MUCOccupant("Ernie", MUCOccupant::Visitor, MUCOccupant::Outcast));
+
+ foreach(const MUCOccupant& alteration, alterations) {
+ /* perform an alteration to a user's role and affiliation */
+ occupant_map::iterator occupant = occupants.find(alteration.getNick());
+ CPPUNIT_ASSERT(occupant != occupants.end());
+ const JID jid = jidFromOccupant(occupant->second);
+ /* change the affiliation, leave the role in place */
+ muc_->changeAffiliation(jid, alteration.getAffiliation());
+ occupant->second = MUCOccupant(occupant->first, occupant->second.getRole(), alteration.getAffiliation());
+ testRoleAffiliationStatesVerify(occupants);
+ /* change the role, leave the affiliation in place */
+ muc_->changeOccupantRole(jid, alteration.getRole());
+ occupant->second = MUCOccupant(occupant->first, alteration.getRole(), occupant->second.getAffiliation());
+ testRoleAffiliationStatesVerify(occupants);
+ }
+ }
+
+ void testSubjectChangeCorrect() {
+ std::string messageBody("test message");
+ window_->onSendMessageRequest(messageBody, false);
+ boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
+ Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
+ CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
+ CPPUNIT_ASSERT(message);
+ CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
+
+ {
+ Message::ref message = boost::make_shared<Message>();
+ message->setType(Message::Groupchat);
+ message->setTo(self_);
+ message->setFrom(mucJID_.withResource("SomeNickname"));
+ message->setID(iqChannel_->getNewIQID());
+ message->setSubject("New Room Subject");
+
+ controller_->handleIncomingMessage(boost::make_shared<MessageEvent>(message));
+ CPPUNIT_ASSERT_EQUAL(std::string("The room subject is now: New Room Subject"), boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
+ }
+ }
+
+ /*
+ * Test that message stanzas with subject element and non-empty body element do not cause a subject change.
+ */
+ void testSubjectChangeIncorrectA() {
+ std::string messageBody("test message");
+ window_->onSendMessageRequest(messageBody, false);
+ boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
+ Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
+ CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
+ CPPUNIT_ASSERT(message);
+ CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
+
+ {
+ Message::ref message = boost::make_shared<Message>();
+ message->setType(Message::Groupchat);
+ message->setTo(self_);
+ message->setFrom(mucJID_.withResource("SomeNickname"));
+ message->setID(iqChannel_->getNewIQID());
+ message->setSubject("New Room Subject");
+ message->setBody("Some body text that prevents this stanza from being a subject change.");
+
+ controller_->handleIncomingMessage(boost::make_shared<MessageEvent>(message));
+ CPPUNIT_ASSERT_EQUAL(std::string("Trying to enter room teaparty@rooms.wonderland.lit"), boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
+ }
+ }
+
+ /*
+ * Test that message stanzas with subject element and thread element do not cause a subject change.
+ */
+ void testSubjectChangeIncorrectB() {
+ std::string messageBody("test message");
+ window_->onSendMessageRequest(messageBody, false);
+ boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
+ Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
+ CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
+ CPPUNIT_ASSERT(message);
+ CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
+
+ {
+ Message::ref message = boost::make_shared<Message>();
+ message->setType(Message::Groupchat);
+ message->setTo(self_);
+ message->setFrom(mucJID_.withResource("SomeNickname"));
+ message->setID(iqChannel_->getNewIQID());
+ message->setSubject("New Room Subject");
+ message->addPayload(boost::make_shared<Thread>("Thread that prevents the subject change."));
+
+ controller_->handleIncomingMessage(boost::make_shared<MessageEvent>(message));
+ CPPUNIT_ASSERT_EQUAL(std::string("Trying to enter room teaparty@rooms.wonderland.lit"), boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
+ }
+ }
+
+ /*
+ * Test that message stanzas with subject element and empty body element do not cause a subject change.
+ */
+ void testSubjectChangeIncorrectC() {
+ std::string messageBody("test message");
+ window_->onSendMessageRequest(messageBody, false);
+ boost::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
+ Message::ref message = boost::dynamic_pointer_cast<Message>(rawStanza);
+ CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
+ CPPUNIT_ASSERT(message);
+ CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
+
+ {
+ Message::ref message = boost::make_shared<Message>();
+ message->setType(Message::Groupchat);
+ message->setTo(self_);
+ message->setFrom(mucJID_.withResource("SomeNickname"));
+ message->setID(iqChannel_->getNewIQID());
+ message->setSubject("New Room Subject");
+ message->setBody("");
+
+ controller_->handleIncomingMessage(boost::make_shared<MessageEvent>(message));
+ CPPUNIT_ASSERT_EQUAL(std::string("Trying to enter room teaparty@rooms.wonderland.lit"), boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
+ }
+ }
+
+ void testRoleAffiliationStatesVerify(const std::map<std::string, MUCOccupant> &occupants) {
+ /* verify that the roster is in sync */
+ GroupRosterItem* group = window_->getRosterModel()->getRoot();
+ foreach(RosterItem* rosterItem, group->getChildren()) {
+ GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(rosterItem);
+ CPPUNIT_ASSERT(child);
+ foreach(RosterItem* childItem, child->getChildren()) {
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(childItem);
+ CPPUNIT_ASSERT(item);
+ std::map<std::string, MUCOccupant>::const_iterator occupant = occupants.find(item->getJID().getResource());
+ CPPUNIT_ASSERT(occupant != occupants.end());
+ CPPUNIT_ASSERT(item->getMUCRole() == occupant->second.getRole());
+ CPPUNIT_ASSERT(item->getMUCAffiliation() == occupant->second.getAffiliation());
+ }
+ }
+ }
private:
- JID self_;
- JID mucJID_;
- MockMUC::ref muc_;
- std::string nick_;
- DummyStanzaChannel* stanzaChannel_;
- DummyIQChannel* iqChannel_;
- IQRouter* iqRouter_;
- EventController* eventController_;
- ChatWindowFactory* chatWindowFactory_;
- UserSearchWindowFactory* userSearchWindowFactory_;
- MUCController* controller_;
-// NickResolver* nickResolver_;
- PresenceOracle* presenceOracle_;
- AvatarManager* avatarManager_;
- StanzaChannelPresenceSender* presenceSender_;
- DirectedPresenceSender* directedPresenceSender_;
- MockRepository* mocks_;
- UIEventStream* uiEventStream_;
- MockChatWindow* window_;
- MUCRegistry* mucRegistry_;
- DummyEntityCapsProvider* entityCapsProvider_;
- DummySettingsProvider* settings_;
- HighlightManager* highlightManager_;
- boost::shared_ptr<ChatMessageParser> chatMessageParser_;
- boost::shared_ptr<CryptoProvider> crypto_;
- VCardManager* vcardManager_;
- VCardMemoryStorage* vcardStorage_;
- ClientBlockListManager* clientBlockListManager_;
- MUCBookmarkManager* mucBookmarkManager_;
- XMPPRoster* xmppRoster_;
+ JID self_;
+ JID mucJID_;
+ MockMUC::ref muc_;
+ std::string nick_;
+ DummyStanzaChannel* stanzaChannel_;
+ DummyIQChannel* iqChannel_;
+ IQRouter* iqRouter_;
+ EventController* eventController_;
+ ChatWindowFactory* chatWindowFactory_;
+ UserSearchWindowFactory* userSearchWindowFactory_;
+ MUCController* controller_;
+// NickResolver* nickResolver_;
+ PresenceOracle* presenceOracle_;
+ AvatarManager* avatarManager_;
+ StanzaChannelPresenceSender* presenceSender_;
+ DirectedPresenceSender* directedPresenceSender_;
+ MockRepository* mocks_;
+ UIEventStream* uiEventStream_;
+ MockChatWindow* window_;
+ MUCRegistry* mucRegistry_;
+ DummyEntityCapsProvider* entityCapsProvider_;
+ DummySettingsProvider* settings_;
+ HighlightManager* highlightManager_;
+ boost::shared_ptr<ChatMessageParser> chatMessageParser_;
+ boost::shared_ptr<CryptoProvider> crypto_;
+ VCardManager* vcardManager_;
+ VCardMemoryStorage* vcardStorage_;
+ ClientBlockListManager* clientBlockListManager_;
+ MUCBookmarkManager* mucBookmarkManager_;
+ XMPPRoster* xmppRoster_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(MUCControllerTest);
diff --git a/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h b/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
index 0754749..395b050 100644
--- a/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
+++ b/Swift/Controllers/Chat/UnitTest/MockChatListWindow.h
@@ -10,19 +10,19 @@
namespace Swift {
- class MockChatListWindow : public ChatListWindow {
- public:
- MockChatListWindow() {}
- virtual ~MockChatListWindow() {}
- void addMUCBookmark(const MUCBookmark& /*bookmark*/) {}
- void removeMUCBookmark(const MUCBookmark& /*bookmark*/) {}
- void addWhiteboardSession(const ChatListWindow::Chat& /*chat*/) {}
- void removeWhiteboardSession(const JID& /*jid*/) {}
- void setBookmarksEnabled(bool /*enabled*/) {}
- void setRecents(const std::list<ChatListWindow::Chat>& /*recents*/) {}
- void setUnreadCount(int /*unread*/) {}
- void clearBookmarks() {}
- void setOnline(bool /*isOnline*/) {}
- };
+ class MockChatListWindow : public ChatListWindow {
+ public:
+ MockChatListWindow() {}
+ virtual ~MockChatListWindow() {}
+ void addMUCBookmark(const MUCBookmark& /*bookmark*/) {}
+ void removeMUCBookmark(const MUCBookmark& /*bookmark*/) {}
+ void addWhiteboardSession(const ChatListWindow::Chat& /*chat*/) {}
+ void removeWhiteboardSession(const JID& /*jid*/) {}
+ void setBookmarksEnabled(bool /*enabled*/) {}
+ void setRecents(const std::list<ChatListWindow::Chat>& /*recents*/) {}
+ void setUnreadCount(int /*unread*/) {}
+ void clearBookmarks() {}
+ void setOnline(bool /*isOnline*/) {}
+ };
}
diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp
index e08912a..216488a 100644
--- a/Swift/Controllers/Chat/UserSearchController.cpp
+++ b/Swift/Controllers/Chat/UserSearchController.cpp
@@ -36,357 +36,357 @@ namespace Swift {
static const std::string SEARCHED_DIRECTORIES = "searchedDirectories";
UserSearchController::UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* factory, IQRouter* iqRouter, RosterController* rosterController, ContactSuggester* contactSuggester, AvatarManager* avatarManager, PresenceOracle* presenceOracle, ProfileSettingsProvider* settings) : type_(type), jid_(jid), uiEventStream_(uiEventStream), vcardManager_(vcardManager), factory_(factory), iqRouter_(iqRouter), rosterController_(rosterController), contactSuggester_(contactSuggester), avatarManager_(avatarManager), presenceOracle_(presenceOracle), settings_(settings) {
- uiEventStream_->onUIEvent.connect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
- vcardManager_->onVCardChanged.connect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
- avatarManager_->onAvatarChanged.connect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1));
- presenceOracle_->onPresenceChange.connect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1));
- window_ = NULL;
- discoWalker_ = NULL;
- loadSavedDirectories();
+ uiEventStream_->onUIEvent.connect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
+ vcardManager_->onVCardChanged.connect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
+ avatarManager_->onAvatarChanged.connect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1));
+ presenceOracle_->onPresenceChange.connect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1));
+ window_ = NULL;
+ discoWalker_ = NULL;
+ loadSavedDirectories();
}
UserSearchController::~UserSearchController() {
- endDiscoWalker();
- delete discoWalker_;
- if (window_) {
- window_->onNameSuggestionRequested.disconnect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1));
- window_->onFormRequested.disconnect(boost::bind(&UserSearchController::handleFormRequested, this, _1));
- window_->onSearchRequested.disconnect(boost::bind(&UserSearchController::handleSearch, this, _1, _2));
- window_->onContactSuggestionsRequested.disconnect(boost::bind(&UserSearchController::handleContactSuggestionsRequested, this, _1));
- window_->onJIDUpdateRequested.disconnect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1));
- window_->onJIDAddRequested.disconnect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1));
- window_->onJIDEditFieldChanged.disconnect(boost::bind(&UserSearchController::handleJIDEditingFinished, this, _1));
- delete window_;
- }
- presenceOracle_->onPresenceChange.disconnect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1));
- avatarManager_->onAvatarChanged.disconnect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1));
- vcardManager_->onVCardChanged.disconnect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
- uiEventStream_->onUIEvent.disconnect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
+ endDiscoWalker();
+ delete discoWalker_;
+ if (window_) {
+ window_->onNameSuggestionRequested.disconnect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1));
+ window_->onFormRequested.disconnect(boost::bind(&UserSearchController::handleFormRequested, this, _1));
+ window_->onSearchRequested.disconnect(boost::bind(&UserSearchController::handleSearch, this, _1, _2));
+ window_->onContactSuggestionsRequested.disconnect(boost::bind(&UserSearchController::handleContactSuggestionsRequested, this, _1));
+ window_->onJIDUpdateRequested.disconnect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1));
+ window_->onJIDAddRequested.disconnect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1));
+ window_->onJIDEditFieldChanged.disconnect(boost::bind(&UserSearchController::handleJIDEditingFinished, this, _1));
+ delete window_;
+ }
+ presenceOracle_->onPresenceChange.disconnect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1));
+ avatarManager_->onAvatarChanged.disconnect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1));
+ vcardManager_->onVCardChanged.disconnect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
+ uiEventStream_->onUIEvent.disconnect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
}
UserSearchWindow* UserSearchController::getUserSearchWindow() {
- initializeUserWindow();
- assert(window_);
- return window_;
+ initializeUserWindow();
+ assert(window_);
+ return window_;
}
void UserSearchController::setCanInitiateImpromptuMUC(bool supportsImpromptu) {
- if (!window_) {
- initializeUserWindow();
- }
- if (window_) {
- window_->setCanStartImpromptuChats(supportsImpromptu);
- } // Else doesn't support search
+ if (!window_) {
+ initializeUserWindow();
+ }
+ if (window_) {
+ window_->setCanStartImpromptuChats(supportsImpromptu);
+ } // Else doesn't support search
}
void UserSearchController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
- bool handle = false;
- boost::shared_ptr<RequestAddUserDialogUIEvent> addUserRequest = boost::shared_ptr<RequestAddUserDialogUIEvent>();
- RequestInviteToMUCUIEvent::ref inviteToMUCRequest = RequestInviteToMUCUIEvent::ref();
- switch (type_) {
- case AddContact:
- if ((addUserRequest = boost::dynamic_pointer_cast<RequestAddUserDialogUIEvent>(event))) {
- handle = true;
- }
- break;
- case StartChat:
- if (boost::dynamic_pointer_cast<RequestChatWithUserDialogUIEvent>(event)) {
- handle = true;
- }
- break;
- case InviteToChat:
- if ((inviteToMUCRequest = boost::dynamic_pointer_cast<RequestInviteToMUCUIEvent>(event))) {
- handle = true;
- }
- break;
- }
- if (handle) {
- initializeUserWindow();
- window_->show();
- window_->addSavedServices(savedDirectories_);
- if (addUserRequest) {
- const std::string& name = addUserRequest->getPredefinedName();
- const JID& jid = addUserRequest->getPredefinedJID();
- if (!name.empty() && jid.isValid()) {
- window_->prepopulateJIDAndName(jid, name);
- }
- } else if (inviteToMUCRequest) {
- window_->setCanSupplyDescription(!inviteToMUCRequest->isImpromptu());
- window_->setJIDs(inviteToMUCRequest->getInvites());
- window_->setRoomJID(inviteToMUCRequest->getRoom());
- }
- return;
- }
+ bool handle = false;
+ boost::shared_ptr<RequestAddUserDialogUIEvent> addUserRequest = boost::shared_ptr<RequestAddUserDialogUIEvent>();
+ RequestInviteToMUCUIEvent::ref inviteToMUCRequest = RequestInviteToMUCUIEvent::ref();
+ switch (type_) {
+ case AddContact:
+ if ((addUserRequest = boost::dynamic_pointer_cast<RequestAddUserDialogUIEvent>(event))) {
+ handle = true;
+ }
+ break;
+ case StartChat:
+ if (boost::dynamic_pointer_cast<RequestChatWithUserDialogUIEvent>(event)) {
+ handle = true;
+ }
+ break;
+ case InviteToChat:
+ if ((inviteToMUCRequest = boost::dynamic_pointer_cast<RequestInviteToMUCUIEvent>(event))) {
+ handle = true;
+ }
+ break;
+ }
+ if (handle) {
+ initializeUserWindow();
+ window_->show();
+ window_->addSavedServices(savedDirectories_);
+ if (addUserRequest) {
+ const std::string& name = addUserRequest->getPredefinedName();
+ const JID& jid = addUserRequest->getPredefinedJID();
+ if (!name.empty() && jid.isValid()) {
+ window_->prepopulateJIDAndName(jid, name);
+ }
+ } else if (inviteToMUCRequest) {
+ window_->setCanSupplyDescription(!inviteToMUCRequest->isImpromptu());
+ window_->setJIDs(inviteToMUCRequest->getInvites());
+ window_->setRoomJID(inviteToMUCRequest->getRoom());
+ }
+ return;
+ }
}
void UserSearchController::handleFormRequested(const JID& service) {
- window_->setSearchError(false);
- window_->setServerSupportsSearch(true);
-
- //Abort a previous search if is active
- endDiscoWalker();
- delete discoWalker_;
- discoWalker_ = new DiscoServiceWalker(service, iqRouter_);
- discoWalker_->onServiceFound.connect(boost::bind(&UserSearchController::handleDiscoServiceFound, this, _1, _2));
- discoWalker_->onWalkComplete.connect(boost::bind(&UserSearchController::handleDiscoWalkFinished, this));
- discoWalker_->beginWalk();
+ window_->setSearchError(false);
+ window_->setServerSupportsSearch(true);
+
+ //Abort a previous search if is active
+ endDiscoWalker();
+ delete discoWalker_;
+ discoWalker_ = new DiscoServiceWalker(service, iqRouter_);
+ discoWalker_->onServiceFound.connect(boost::bind(&UserSearchController::handleDiscoServiceFound, this, _1, _2));
+ discoWalker_->onWalkComplete.connect(boost::bind(&UserSearchController::handleDiscoWalkFinished, this));
+ discoWalker_->beginWalk();
}
void UserSearchController::endDiscoWalker() {
- if (discoWalker_) {
- discoWalker_->endWalk();
- discoWalker_->onServiceFound.disconnect(boost::bind(&UserSearchController::handleDiscoServiceFound, this, _1, _2));
- discoWalker_->onWalkComplete.disconnect(boost::bind(&UserSearchController::handleDiscoWalkFinished, this));
- }
+ if (discoWalker_) {
+ discoWalker_->endWalk();
+ discoWalker_->onServiceFound.disconnect(boost::bind(&UserSearchController::handleDiscoServiceFound, this, _1, _2));
+ discoWalker_->onWalkComplete.disconnect(boost::bind(&UserSearchController::handleDiscoWalkFinished, this));
+ }
}
void UserSearchController::handleDiscoServiceFound(const JID& jid, boost::shared_ptr<DiscoInfo> info) {
- //bool isUserDirectory = false;
- bool supports55 = false;
- foreach (DiscoInfo::Identity identity, info->getIdentities()) {
- if ((identity.getCategory() == "directory"
- && identity.getType() == "user")) {
- //isUserDirectory = true;
- }
- }
- std::vector<std::string> features = info->getFeatures();
- supports55 = std::find(features.begin(), features.end(), DiscoInfo::JabberSearchFeature) != features.end();
- if (/*isUserDirectory && */supports55) { //FIXME: once M-Link correctly advertises directoryness.
- /* Abort further searches.*/
- endDiscoWalker();
- boost::shared_ptr<GenericRequest<SearchPayload> > searchRequest(new GenericRequest<SearchPayload>(IQ::Get, jid, boost::make_shared<SearchPayload>(), iqRouter_));
- searchRequest->onResponse.connect(boost::bind(&UserSearchController::handleFormResponse, this, _1, _2));
- searchRequest->send();
- }
+ //bool isUserDirectory = false;
+ bool supports55 = false;
+ foreach (DiscoInfo::Identity identity, info->getIdentities()) {
+ if ((identity.getCategory() == "directory"
+ && identity.getType() == "user")) {
+ //isUserDirectory = true;
+ }
+ }
+ std::vector<std::string> features = info->getFeatures();
+ supports55 = std::find(features.begin(), features.end(), DiscoInfo::JabberSearchFeature) != features.end();
+ if (/*isUserDirectory && */supports55) { //FIXME: once M-Link correctly advertises directoryness.
+ /* Abort further searches.*/
+ endDiscoWalker();
+ boost::shared_ptr<GenericRequest<SearchPayload> > searchRequest(new GenericRequest<SearchPayload>(IQ::Get, jid, boost::make_shared<SearchPayload>(), iqRouter_));
+ searchRequest->onResponse.connect(boost::bind(&UserSearchController::handleFormResponse, this, _1, _2));
+ searchRequest->send();
+ }
}
void UserSearchController::handleFormResponse(boost::shared_ptr<SearchPayload> fields, ErrorPayload::ref error) {
- if (error || !fields) {
- window_->setServerSupportsSearch(false);
- return;
- }
- window_->setSearchFields(fields);
+ if (error || !fields) {
+ window_->setServerSupportsSearch(false);
+ return;
+ }
+ window_->setSearchFields(fields);
}
void UserSearchController::handleSearch(boost::shared_ptr<SearchPayload> fields, const JID& jid) {
- addToSavedDirectories(jid);
- boost::shared_ptr<GenericRequest<SearchPayload> > searchRequest(new GenericRequest<SearchPayload>(IQ::Set, jid, fields, iqRouter_));
- searchRequest->onResponse.connect(boost::bind(&UserSearchController::handleSearchResponse, this, _1, _2));
- searchRequest->send();
+ addToSavedDirectories(jid);
+ boost::shared_ptr<GenericRequest<SearchPayload> > searchRequest(new GenericRequest<SearchPayload>(IQ::Set, jid, fields, iqRouter_));
+ searchRequest->onResponse.connect(boost::bind(&UserSearchController::handleSearchResponse, this, _1, _2));
+ searchRequest->send();
}
void UserSearchController::handleSearchResponse(boost::shared_ptr<SearchPayload> resultsPayload, ErrorPayload::ref error) {
- if (error || !resultsPayload) {
- window_->setSearchError(true);
- return;
- }
-
- std::vector<UserSearchResult> results;
-
- if (resultsPayload->getForm()) {
- window_->setResultsForm(resultsPayload->getForm());
- } else {
- foreach (SearchPayload::Item item, resultsPayload->getItems()) {
- JID jid(item.jid);
- std::map<std::string, std::string> fields;
- fields["first"] = item.first;
- fields["last"] = item.last;
- fields["nick"] = item.nick;
- fields["email"] = item.email;
- UserSearchResult result(jid, fields);
- results.push_back(result);
- }
- window_->setResults(results);
- }
+ if (error || !resultsPayload) {
+ window_->setSearchError(true);
+ return;
+ }
+
+ std::vector<UserSearchResult> results;
+
+ if (resultsPayload->getForm()) {
+ window_->setResultsForm(resultsPayload->getForm());
+ } else {
+ foreach (SearchPayload::Item item, resultsPayload->getItems()) {
+ JID jid(item.jid);
+ std::map<std::string, std::string> fields;
+ fields["first"] = item.first;
+ fields["last"] = item.last;
+ fields["nick"] = item.nick;
+ fields["email"] = item.email;
+ UserSearchResult result(jid, fields);
+ results.push_back(result);
+ }
+ window_->setResults(results);
+ }
}
void UserSearchController::handleNameSuggestionRequest(const JID &jid) {
- suggestionsJID_= jid;
- VCard::ref vcard = vcardManager_->getVCardAndRequestWhenNeeded(jid);
- if (vcard) {
- handleVCardChanged(jid, vcard);
- }
+ suggestionsJID_= jid;
+ VCard::ref vcard = vcardManager_->getVCardAndRequestWhenNeeded(jid);
+ if (vcard) {
+ handleVCardChanged(jid, vcard);
+ }
}
void UserSearchController::handleJIDEditingFinished(const JID& jid) {
- if (jid.isValid()) {
- if (rosterController_->getItem(jid)) {
- window_->setWarning(QT_TRANSLATE_NOOP("", "This contact is already on your contact list."));
- }
- else if (jid.getNode().empty()) {
- window_->setWarning(QT_TRANSLATE_NOOP("", "Part of the address you have entered is missing. An address has a structure of 'user@example.com'."));
- }
- else {
- window_->setWarning(boost::optional<std::string>());
- }
- }
- else {
- window_->setWarning(QT_TRANSLATE_NOOP("", "The address you have entered is invalid."));
- }
+ if (jid.isValid()) {
+ if (rosterController_->getItem(jid)) {
+ window_->setWarning(QT_TRANSLATE_NOOP("", "This contact is already on your contact list."));
+ }
+ else if (jid.getNode().empty()) {
+ window_->setWarning(QT_TRANSLATE_NOOP("", "Part of the address you have entered is missing. An address has a structure of 'user@example.com'."));
+ }
+ else {
+ window_->setWarning(boost::optional<std::string>());
+ }
+ }
+ else {
+ window_->setWarning(QT_TRANSLATE_NOOP("", "The address you have entered is invalid."));
+ }
}
void UserSearchController::handleContactSuggestionsRequested(std::string text) {
- const std::vector<JID> existingJIDs = window_->getJIDs();
- std::vector<Contact::ref> suggestions = contactSuggester_->getSuggestions(text, false);
- /* do not suggest contacts that have already been added to the chat list */
- std::vector<Contact::ref>::iterator i = suggestions.begin();
- while (i != suggestions.end()) {
- bool found = false;
- foreach (const JID& jid, existingJIDs) {
- if ((*i)->jid == jid) {
- found = true;
- break;
- }
- }
-
- // remove contact suggestions which are already on the contact list in add-contact-mode
- if (type_ == AddContact) {
- if (!found && !!rosterController_->getItem((*i)->jid)) {
- found = true;
- }
- }
-
- if (found) {
- i = suggestions.erase(i);
- } else {
- i++;
- }
- }
- window_->setContactSuggestions(suggestions);
+ const std::vector<JID> existingJIDs = window_->getJIDs();
+ std::vector<Contact::ref> suggestions = contactSuggester_->getSuggestions(text, false);
+ /* do not suggest contacts that have already been added to the chat list */
+ std::vector<Contact::ref>::iterator i = suggestions.begin();
+ while (i != suggestions.end()) {
+ bool found = false;
+ foreach (const JID& jid, existingJIDs) {
+ if ((*i)->jid == jid) {
+ found = true;
+ break;
+ }
+ }
+
+ // remove contact suggestions which are already on the contact list in add-contact-mode
+ if (type_ == AddContact) {
+ if (!found && !!rosterController_->getItem((*i)->jid)) {
+ found = true;
+ }
+ }
+
+ if (found) {
+ i = suggestions.erase(i);
+ } else {
+ i++;
+ }
+ }
+ window_->setContactSuggestions(suggestions);
}
void UserSearchController::handleVCardChanged(const JID& jid, VCard::ref vcard) {
- if (jid == suggestionsJID_) {
- window_->setNameSuggestions(ContactEditController::nameSuggestionsFromVCard(vcard));
- suggestionsJID_ = JID();
- }
- handleJIDUpdateRequested(std::vector<JID>(1, jid));
+ if (jid == suggestionsJID_) {
+ window_->setNameSuggestions(ContactEditController::nameSuggestionsFromVCard(vcard));
+ suggestionsJID_ = JID();
+ }
+ handleJIDUpdateRequested(std::vector<JID>(1, jid));
}
void UserSearchController::handleAvatarChanged(const JID& jid) {
- handleJIDUpdateRequested(std::vector<JID>(1, jid));
+ handleJIDUpdateRequested(std::vector<JID>(1, jid));
}
void UserSearchController::handlePresenceChanged(Presence::ref presence) {
- handleJIDUpdateRequested(std::vector<JID>(1, presence->getFrom().toBare()));
+ handleJIDUpdateRequested(std::vector<JID>(1, presence->getFrom().toBare()));
}
void UserSearchController::handleJIDUpdateRequested(const std::vector<JID>& jids) {
- if (window_) {
- std::vector<Contact::ref> updates;
- foreach(const JID& jid, jids) {
- updates.push_back(convertJIDtoContact(jid));
- }
- window_->updateContacts(updates);
- }
+ if (window_) {
+ std::vector<Contact::ref> updates;
+ foreach(const JID& jid, jids) {
+ updates.push_back(convertJIDtoContact(jid));
+ }
+ window_->updateContacts(updates);
+ }
}
void UserSearchController::handleJIDAddRequested(const std::vector<JID>& jids) {
- std::vector<Contact::ref> contacts;
- foreach(const JID& jid, jids) {
- contacts.push_back(convertJIDtoContact(jid));
- }
- window_->addContacts(contacts);
+ std::vector<Contact::ref> contacts;
+ foreach(const JID& jid, jids) {
+ contacts.push_back(convertJIDtoContact(jid));
+ }
+ window_->addContacts(contacts);
}
Contact::ref UserSearchController::convertJIDtoContact(const JID& jid) {
- Contact::ref contact = boost::make_shared<Contact>();
- contact->jid = jid;
-
- // name lookup
- boost::optional<XMPPRosterItem> rosterItem = rosterController_->getItem(jid);
- if (rosterItem && !rosterItem->getName().empty()) {
- contact->name = rosterItem->getName();
- } else {
- VCard::ref vcard = vcardManager_->getVCard(jid);
- if (vcard && !vcard->getFullName().empty()) {
- contact->name = vcard->getFullName();
- } else {
- contact->name = jid.toString();
- }
- }
-
- // presence lookup
- Presence::ref presence = presenceOracle_->getAccountPresence(jid);
- if (presence) {
- contact->statusType = presence->getShow();
- } else {
- contact->statusType = StatusShow::None;
- }
-
- // avatar lookup
- contact->avatarPath = avatarManager_->getAvatarPath(jid);
- return contact;
+ Contact::ref contact = boost::make_shared<Contact>();
+ contact->jid = jid;
+
+ // name lookup
+ boost::optional<XMPPRosterItem> rosterItem = rosterController_->getItem(jid);
+ if (rosterItem && !rosterItem->getName().empty()) {
+ contact->name = rosterItem->getName();
+ } else {
+ VCard::ref vcard = vcardManager_->getVCard(jid);
+ if (vcard && !vcard->getFullName().empty()) {
+ contact->name = vcard->getFullName();
+ } else {
+ contact->name = jid.toString();
+ }
+ }
+
+ // presence lookup
+ Presence::ref presence = presenceOracle_->getAccountPresence(jid);
+ if (presence) {
+ contact->statusType = presence->getShow();
+ } else {
+ contact->statusType = StatusShow::None;
+ }
+
+ // avatar lookup
+ contact->avatarPath = avatarManager_->getAvatarPath(jid);
+ return contact;
}
void UserSearchController::handleDiscoWalkFinished() {
- window_->setServerSupportsSearch(false);
- endDiscoWalker();
+ window_->setServerSupportsSearch(false);
+ endDiscoWalker();
}
void UserSearchController::initializeUserWindow() {
- if (!window_) {
- UserSearchWindow::Type windowType = UserSearchWindow::AddContact;
- switch(type_) {
- case AddContact:
- windowType = UserSearchWindow::AddContact;
- break;
- case StartChat:
- windowType = UserSearchWindow::ChatToContact;
- break;
- case InviteToChat:
- windowType = UserSearchWindow::InviteToChat;
- break;
- }
-
- window_ = factory_->createUserSearchWindow(windowType, uiEventStream_, rosterController_->getGroups());
- if (!window_) {
- // UI Doesn't support user search
- return;
- }
- window_->onNameSuggestionRequested.connect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1));
- window_->onFormRequested.connect(boost::bind(&UserSearchController::handleFormRequested, this, _1));
- window_->onSearchRequested.connect(boost::bind(&UserSearchController::handleSearch, this, _1, _2));
- window_->onContactSuggestionsRequested.connect(boost::bind(&UserSearchController::handleContactSuggestionsRequested, this, _1));
- window_->onJIDUpdateRequested.connect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1));
- window_->onJIDAddRequested.connect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1));
- window_->onJIDEditFieldChanged.connect(boost::bind(&UserSearchController::handleJIDEditingFinished, this, _1));
- window_->setSelectedService(JID(jid_.getDomain()));
- window_->clear();
- }
+ if (!window_) {
+ UserSearchWindow::Type windowType = UserSearchWindow::AddContact;
+ switch(type_) {
+ case AddContact:
+ windowType = UserSearchWindow::AddContact;
+ break;
+ case StartChat:
+ windowType = UserSearchWindow::ChatToContact;
+ break;
+ case InviteToChat:
+ windowType = UserSearchWindow::InviteToChat;
+ break;
+ }
+
+ window_ = factory_->createUserSearchWindow(windowType, uiEventStream_, rosterController_->getGroups());
+ if (!window_) {
+ // UI Doesn't support user search
+ return;
+ }
+ window_->onNameSuggestionRequested.connect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1));
+ window_->onFormRequested.connect(boost::bind(&UserSearchController::handleFormRequested, this, _1));
+ window_->onSearchRequested.connect(boost::bind(&UserSearchController::handleSearch, this, _1, _2));
+ window_->onContactSuggestionsRequested.connect(boost::bind(&UserSearchController::handleContactSuggestionsRequested, this, _1));
+ window_->onJIDUpdateRequested.connect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1));
+ window_->onJIDAddRequested.connect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1));
+ window_->onJIDEditFieldChanged.connect(boost::bind(&UserSearchController::handleJIDEditingFinished, this, _1));
+ window_->setSelectedService(JID(jid_.getDomain()));
+ window_->clear();
+ }
}
void UserSearchController::loadSavedDirectories() {
- savedDirectories_.clear();
- foreach (std::string stringItem, String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) {
- if(!stringItem.empty()) {
- savedDirectories_.push_back(JID(stringItem));
- }
- }
+ savedDirectories_.clear();
+ foreach (std::string stringItem, String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) {
+ if(!stringItem.empty()) {
+ savedDirectories_.push_back(JID(stringItem));
+ }
+ }
}
void UserSearchController::addToSavedDirectories(const JID& jid) {
- if (!jid.isValid()) {
- return;
- }
-
- savedDirectories_.erase(std::remove(savedDirectories_.begin(), savedDirectories_.end(), jid), savedDirectories_.end());
- savedDirectories_.insert(savedDirectories_.begin(), jid);
-
- std::string collapsed;
- int i = 0;
- foreach (JID jidItem, savedDirectories_) {
- if (i >= 15) {
- break;
- }
- if (!collapsed.empty()) {
- collapsed += "\n";
- }
- collapsed += jidItem.toString();
- ++i;
- }
- settings_->storeString(SEARCHED_DIRECTORIES, collapsed);
- window_->addSavedServices(savedDirectories_);
+ if (!jid.isValid()) {
+ return;
+ }
+
+ savedDirectories_.erase(std::remove(savedDirectories_.begin(), savedDirectories_.end(), jid), savedDirectories_.end());
+ savedDirectories_.insert(savedDirectories_.begin(), jid);
+
+ std::string collapsed;
+ int i = 0;
+ foreach (JID jidItem, savedDirectories_) {
+ if (i >= 15) {
+ break;
+ }
+ if (!collapsed.empty()) {
+ collapsed += "\n";
+ }
+ collapsed += jidItem.toString();
+ ++i;
+ }
+ settings_->storeString(SEARCHED_DIRECTORIES, collapsed);
+ window_->addSavedServices(savedDirectories_);
}
}
diff --git a/Swift/Controllers/Chat/UserSearchController.h b/Swift/Controllers/Chat/UserSearchController.h
index 0423a65..71b8331 100644
--- a/Swift/Controllers/Chat/UserSearchController.h
+++ b/Swift/Controllers/Chat/UserSearchController.h
@@ -24,76 +24,76 @@
#include <Swift/Controllers/Contact.h>
namespace Swift {
- class UIEventStream;
- class UIEvent;
- class UserSearchWindow;
- class UserSearchWindowFactory;
- class IQRouter;
- class DiscoServiceWalker;
- class RosterController;
- class VCardManager;
- class ContactSuggester;
- class AvatarManager;
- class PresenceOracle;
- class ProfileSettingsProvider;
+ class UIEventStream;
+ class UIEvent;
+ class UserSearchWindow;
+ class UserSearchWindowFactory;
+ class IQRouter;
+ class DiscoServiceWalker;
+ class RosterController;
+ class VCardManager;
+ class ContactSuggester;
+ class AvatarManager;
+ class PresenceOracle;
+ class ProfileSettingsProvider;
- class UserSearchResult {
- public:
- UserSearchResult(const JID& jid, const std::map<std::string, std::string>& fields) : jid_(jid), fields_(fields) {}
- const JID& getJID() const {return jid_;}
- const std::map<std::string, std::string>& getFields() const {return fields_;}
- private:
- JID jid_;
- std::map<std::string, std::string> fields_;
- };
+ class UserSearchResult {
+ public:
+ UserSearchResult(const JID& jid, const std::map<std::string, std::string>& fields) : jid_(jid), fields_(fields) {}
+ const JID& getJID() const {return jid_;}
+ const std::map<std::string, std::string>& getFields() const {return fields_;}
+ private:
+ JID jid_;
+ std::map<std::string, std::string> fields_;
+ };
- class UserSearchController {
- public:
- enum Type {AddContact, StartChat, InviteToChat};
- UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* userSearchWindowFactory, IQRouter* iqRouter, RosterController* rosterController, ContactSuggester* contactSuggester, AvatarManager* avatarManager, PresenceOracle* presenceOracle, ProfileSettingsProvider* settings);
- ~UserSearchController();
+ class UserSearchController {
+ public:
+ enum Type {AddContact, StartChat, InviteToChat};
+ UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* userSearchWindowFactory, IQRouter* iqRouter, RosterController* rosterController, ContactSuggester* contactSuggester, AvatarManager* avatarManager, PresenceOracle* presenceOracle, ProfileSettingsProvider* settings);
+ ~UserSearchController();
- UserSearchWindow* getUserSearchWindow();
- void setCanInitiateImpromptuMUC(bool supportsImpromptu);
+ UserSearchWindow* getUserSearchWindow();
+ void setCanInitiateImpromptuMUC(bool supportsImpromptu);
- private:
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void handleFormRequested(const JID& service);
- void handleDiscoServiceFound(const JID& jid, boost::shared_ptr<DiscoInfo> info);
- void handleDiscoWalkFinished();
- void handleFormResponse(boost::shared_ptr<SearchPayload> items, ErrorPayload::ref error);
- void handleSearch(boost::shared_ptr<SearchPayload> fields, const JID& jid);
- void handleSearchResponse(boost::shared_ptr<SearchPayload> results, ErrorPayload::ref error);
- void handleNameSuggestionRequest(const JID& jid);
- void handleContactSuggestionsRequested(std::string text);
- void handleVCardChanged(const JID& jid, VCard::ref vcard);
- void handleAvatarChanged(const JID& jid);
- void handlePresenceChanged(Presence::ref presence);
- void handleJIDUpdateRequested(const std::vector<JID>& jids);
- void handleJIDAddRequested(const std::vector<JID>& jids);
- void handleJIDEditingFinished(const JID& jid);
- Contact::ref convertJIDtoContact(const JID& jid);
- void endDiscoWalker();
- void initializeUserWindow();
+ private:
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleFormRequested(const JID& service);
+ void handleDiscoServiceFound(const JID& jid, boost::shared_ptr<DiscoInfo> info);
+ void handleDiscoWalkFinished();
+ void handleFormResponse(boost::shared_ptr<SearchPayload> items, ErrorPayload::ref error);
+ void handleSearch(boost::shared_ptr<SearchPayload> fields, const JID& jid);
+ void handleSearchResponse(boost::shared_ptr<SearchPayload> results, ErrorPayload::ref error);
+ void handleNameSuggestionRequest(const JID& jid);
+ void handleContactSuggestionsRequested(std::string text);
+ void handleVCardChanged(const JID& jid, VCard::ref vcard);
+ void handleAvatarChanged(const JID& jid);
+ void handlePresenceChanged(Presence::ref presence);
+ void handleJIDUpdateRequested(const std::vector<JID>& jids);
+ void handleJIDAddRequested(const std::vector<JID>& jids);
+ void handleJIDEditingFinished(const JID& jid);
+ Contact::ref convertJIDtoContact(const JID& jid);
+ void endDiscoWalker();
+ void initializeUserWindow();
- void loadSavedDirectories();
- void addToSavedDirectories(const JID& jid);
+ void loadSavedDirectories();
+ void addToSavedDirectories(const JID& jid);
- private:
- Type type_;
- JID jid_;
- JID suggestionsJID_;
- UIEventStream* uiEventStream_;
- VCardManager* vcardManager_;
- UserSearchWindowFactory* factory_;
- IQRouter* iqRouter_;
- RosterController* rosterController_;
- UserSearchWindow* window_;
- DiscoServiceWalker* discoWalker_;
- ContactSuggester* contactSuggester_;
- AvatarManager* avatarManager_;
- PresenceOracle* presenceOracle_;
- std::vector<JID> savedDirectories_;
- ProfileSettingsProvider* settings_;
- };
+ private:
+ Type type_;
+ JID jid_;
+ JID suggestionsJID_;
+ UIEventStream* uiEventStream_;
+ VCardManager* vcardManager_;
+ UserSearchWindowFactory* factory_;
+ IQRouter* iqRouter_;
+ RosterController* rosterController_;
+ UserSearchWindow* window_;
+ DiscoServiceWalker* discoWalker_;
+ ContactSuggester* contactSuggester_;
+ AvatarManager* avatarManager_;
+ PresenceOracle* presenceOracle_;
+ std::vector<JID> savedDirectories_;
+ ProfileSettingsProvider* settings_;
+ };
}
diff --git a/Swift/Controllers/ChatMessageSummarizer.cpp b/Swift/Controllers/ChatMessageSummarizer.cpp
index a0ae6d1..6b630e7 100644
--- a/Swift/Controllers/ChatMessageSummarizer.cpp
+++ b/Swift/Controllers/ChatMessageSummarizer.cpp
@@ -15,32 +15,32 @@ using namespace Swift;
using namespace std;
string ChatMessageSummarizer::getSummary(const string& current, const vector<UnreadPair>& unreads) {
- vector<UnreadPair> others;
- int currentUnread = 0;
- int otherCount = 0;
- foreach (UnreadPair unread, unreads) {
- if (unread.first == current) {
- currentUnread += unread.second;
- } else {
- if (unread.second > 0) {
- otherCount += unread.second;
- others.push_back(unread);
- }
- }
- }
- string myString(current);
+ vector<UnreadPair> others;
+ int currentUnread = 0;
+ int otherCount = 0;
+ foreach (UnreadPair unread, unreads) {
+ if (unread.first == current) {
+ currentUnread += unread.second;
+ } else {
+ if (unread.second > 0) {
+ otherCount += unread.second;
+ others.push_back(unread);
+ }
+ }
+ }
+ string myString(current);
- if (currentUnread > 0) {
- string result(QT_TRANSLATE_NOOP("", "%1% (%2%)"));
- myString = str(format(result) % current % currentUnread);
- }
+ if (currentUnread > 0) {
+ string result(QT_TRANSLATE_NOOP("", "%1% (%2%)"));
+ myString = str(format(result) % current % currentUnread);
+ }
- if (others.size() > 1) {
- string result(QT_TRANSLATE_NOOP("", "%1% and %2% others (%3%)"));
- myString = str(format(result) % myString % others.size() % otherCount);
- } else if (!others.empty()) {
- string result(QT_TRANSLATE_NOOP("", "%1%; %2% (%3%)"));
- myString = str(format(result) % myString % others[0].first % otherCount);
- }
- return myString;
+ if (others.size() > 1) {
+ string result(QT_TRANSLATE_NOOP("", "%1% and %2% others (%3%)"));
+ myString = str(format(result) % myString % others.size() % otherCount);
+ } else if (!others.empty()) {
+ string result(QT_TRANSLATE_NOOP("", "%1%; %2% (%3%)"));
+ myString = str(format(result) % myString % others[0].first % otherCount);
+ }
+ return myString;
}
diff --git a/Swift/Controllers/ChatMessageSummarizer.h b/Swift/Controllers/ChatMessageSummarizer.h
index 9ed867d..0b4df21 100644
--- a/Swift/Controllers/ChatMessageSummarizer.h
+++ b/Swift/Controllers/ChatMessageSummarizer.h
@@ -13,8 +13,8 @@
namespace Swift {
typedef std::pair<std::string, int> UnreadPair;
- class ChatMessageSummarizer {
- public:
- std::string getSummary(const std::string& current, const std::vector<UnreadPair>& unreads);
- };
+ class ChatMessageSummarizer {
+ public:
+ std::string getSummary(const std::string& current, const std::vector<UnreadPair>& unreads);
+ };
}
diff --git a/Swift/Controllers/ConnectionSettings.h b/Swift/Controllers/ConnectionSettings.h
index 6a2fded..7ce45cd 100644
--- a/Swift/Controllers/ConnectionSettings.h
+++ b/Swift/Controllers/ConnectionSettings.h
@@ -9,32 +9,32 @@
#include <string>
struct ConnectionSettings {
- enum Method {
- Automatic,
- Manual,
- BOSH
- };
- enum ProxyType {
- None,
- System,
- SOCKS5,
- HTTPConnect
- };
+ enum Method {
+ Automatic,
+ Manual,
+ BOSH
+ };
+ enum ProxyType {
+ None,
+ System,
+ SOCKS5,
+ HTTPConnect
+ };
- Method method;
- struct {
- bool useManualServer;
- std::string manualServerHostname;
- int manualServerPort;
- ProxyType proxyType;
- bool useManualProxy;
- std::string manualProxyHostname;
- int manualProxyPort;
- } manualSettings;
- struct {
- std::string boshURI;
- bool useManualProxy;
- std::string manualProxyHostname;
- int manualProxyPort;
- } boshSettings;
+ Method method;
+ struct {
+ bool useManualServer;
+ std::string manualServerHostname;
+ int manualServerPort;
+ ProxyType proxyType;
+ bool useManualProxy;
+ std::string manualProxyHostname;
+ int manualProxyPort;
+ } manualSettings;
+ struct {
+ std::string boshURI;
+ bool useManualProxy;
+ std::string manualProxyHostname;
+ int manualProxyPort;
+ } boshSettings;
};
diff --git a/Swift/Controllers/Contact.cpp b/Swift/Controllers/Contact.cpp
index bda1239..b9b98c3 100644
--- a/Swift/Controllers/Contact.cpp
+++ b/Swift/Controllers/Contact.cpp
@@ -24,54 +24,54 @@ Contact::Contact(const std::string& name, const JID& jid, StatusShow::Type statu
}
bool Contact::lexicographicalSortPredicate(const Contact::ref& a, const Contact::ref& b) {
- if (a->jid.isValid() && b->jid.isValid()) {
- return a->jid < b->jid;
- } else {
- return a->name < b->name;
- }
+ if (a->jid.isValid() && b->jid.isValid()) {
+ return a->jid < b->jid;
+ } else {
+ return a->name < b->name;
+ }
}
bool Contact::equalityPredicate(const Contact::ref& a, const Contact::ref& b) {
- if (a->jid.isValid() && b->jid.isValid()) {
- return a->jid == b->jid;
- } else {
- return a->name == b->name;
- }
+ if (a->jid.isValid() && b->jid.isValid()) {
+ return a->jid == b->jid;
+ } else {
+ return a->name == b->name;
+ }
}
bool Contact::sortPredicate(const Contact::ref& a, const Contact::ref& b, const std::string& search) {
- /* perform case insensitive comparisons */
- std::string aLower = a->name;
- boost::to_lower(aLower);
- std::string bLower = b->name;
- boost::to_lower(bLower);
- std::string searchLower = search;
- boost::to_lower(searchLower);
+ /* perform case insensitive comparisons */
+ std::string aLower = a->name;
+ boost::to_lower(aLower);
+ std::string bLower = b->name;
+ boost::to_lower(bLower);
+ std::string searchLower = search;
+ boost::to_lower(searchLower);
- /* name starts with the search term */
- if (aLower.find(searchLower) == 0 && bLower.find(searchLower) != 0) {
- return true;
- } else if (bLower.find(searchLower) == 0 && aLower.find(searchLower) != 0) {
- return false;
- }
+ /* name starts with the search term */
+ if (aLower.find(searchLower) == 0 && bLower.find(searchLower) != 0) {
+ return true;
+ } else if (bLower.find(searchLower) == 0 && aLower.find(searchLower) != 0) {
+ return false;
+ }
- /* name contains search term */
- if (aLower.find(searchLower) != std::string::npos && bLower.find(searchLower) == std::string::npos) {
- return true;
- } else if (bLower.find(searchLower) != std::string::npos && aLower.find(searchLower) == std::string::npos) {
- return false;
- }
+ /* name contains search term */
+ if (aLower.find(searchLower) != std::string::npos && bLower.find(searchLower) == std::string::npos) {
+ return true;
+ } else if (bLower.find(searchLower) != std::string::npos && aLower.find(searchLower) == std::string::npos) {
+ return false;
+ }
- /* Levenshtein should be done here */
- /* if edit distances are equal, fall through to the tests below */
+ /* Levenshtein should be done here */
+ /* if edit distances are equal, fall through to the tests below */
- /* lexicographical sort */
- if (a->statusType == b->statusType) {
- return aLower.compare(bLower) < 0;
- }
+ /* lexicographical sort */
+ if (a->statusType == b->statusType) {
+ return aLower.compare(bLower) < 0;
+ }
- /* online status */
- return a->statusType < b->statusType;
+ /* online status */
+ return a->statusType < b->statusType;
}
}
diff --git a/Swift/Controllers/Contact.h b/Swift/Controllers/Contact.h
index b03a118..4aa6999 100644
--- a/Swift/Controllers/Contact.h
+++ b/Swift/Controllers/Contact.h
@@ -21,21 +21,21 @@
namespace Swift {
class Contact : public boost::enable_shared_from_this<Contact> {
- public:
- typedef boost::shared_ptr<Contact> ref;
+ public:
+ typedef boost::shared_ptr<Contact> ref;
- Contact();
- Contact(const std::string& name, const JID& jid, StatusShow::Type statusType, const boost::filesystem::path& path);
+ Contact();
+ Contact(const std::string& name, const JID& jid, StatusShow::Type statusType, const boost::filesystem::path& path);
- static bool lexicographicalSortPredicate(const Contact::ref& a, const Contact::ref& b);
- static bool equalityPredicate(const Contact::ref& a, const Contact::ref& b);
- static bool sortPredicate(const Contact::ref& a, const Contact::ref& b, const std::string& search);
+ static bool lexicographicalSortPredicate(const Contact::ref& a, const Contact::ref& b);
+ static bool equalityPredicate(const Contact::ref& a, const Contact::ref& b);
+ static bool sortPredicate(const Contact::ref& a, const Contact::ref& b, const std::string& search);
- public:
- std::string name;
- JID jid;
- StatusShow::Type statusType;
- boost::filesystem::path avatarPath;
+ public:
+ std::string name;
+ JID jid;
+ StatusShow::Type statusType;
+ boost::filesystem::path avatarPath;
};
}
diff --git a/Swift/Controllers/ContactEditController.cpp b/Swift/Controllers/ContactEditController.cpp
index 704e3bc..734ef79 100644
--- a/Swift/Controllers/ContactEditController.cpp
+++ b/Swift/Controllers/ContactEditController.cpp
@@ -21,89 +21,89 @@
namespace Swift {
ContactEditController::ContactEditController(RosterController* rosterController, VCardManager* vcardManager, ContactEditWindowFactory* contactEditWindowFactory, UIEventStream* uiEventStream) : rosterController(rosterController), vcardManager(vcardManager), contactEditWindowFactory(contactEditWindowFactory), uiEventStream(uiEventStream), contactEditWindow(NULL) {
- uiEventStream->onUIEvent.connect(boost::bind(&ContactEditController::handleUIEvent, this, _1));
- vcardManager->onVCardChanged.connect(boost::bind(&ContactEditController::handleVCardChanged, this, _1, _2));
+ uiEventStream->onUIEvent.connect(boost::bind(&ContactEditController::handleUIEvent, this, _1));
+ vcardManager->onVCardChanged.connect(boost::bind(&ContactEditController::handleVCardChanged, this, _1, _2));
}
ContactEditController::~ContactEditController() {
- if (contactEditWindow) {
- contactEditWindow->onChangeContactRequest.disconnect(boost::bind(&ContactEditController::handleChangeContactRequest, this, _1, _2));
- contactEditWindow->onRemoveContactRequest.disconnect(boost::bind(&ContactEditController::handleRemoveContactRequest, this));
- delete contactEditWindow;
- }
- uiEventStream->onUIEvent.disconnect(boost::bind(&ContactEditController::handleUIEvent, this, _1));
+ if (contactEditWindow) {
+ contactEditWindow->onChangeContactRequest.disconnect(boost::bind(&ContactEditController::handleChangeContactRequest, this, _1, _2));
+ contactEditWindow->onRemoveContactRequest.disconnect(boost::bind(&ContactEditController::handleRemoveContactRequest, this));
+ delete contactEditWindow;
+ }
+ uiEventStream->onUIEvent.disconnect(boost::bind(&ContactEditController::handleUIEvent, this, _1));
}
void ContactEditController::handleUIEvent(UIEvent::ref event) {
- RequestContactEditorUIEvent::ref editEvent = boost::dynamic_pointer_cast<RequestContactEditorUIEvent>(event);
- if (!editEvent) {
- return;
- }
-
- if (!contactEditWindow) {
- contactEditWindow = contactEditWindowFactory->createContactEditWindow();
- contactEditWindow->onRemoveContactRequest.connect(boost::bind(&ContactEditController::handleRemoveContactRequest, this));
- contactEditWindow->onChangeContactRequest.connect(boost::bind(&ContactEditController::handleChangeContactRequest, this, _1, _2));
- }
- currentContact = rosterController->getItem(editEvent->getJID());
- assert(currentContact);
- jid = rosterController->getItem(editEvent->getJID())->getJID();
- contactEditWindow->setContact(jid, currentContact->getName(), currentContact->getGroups(), rosterController->getGroups());
- contactEditWindow->show();
-
- if (vcardManager) {
- VCard::ref vcard = vcardManager->getVCardAndRequestWhenNeeded(jid);
- if (vcard) {
- handleVCardChanged(jid, vcard);
- }
- }
+ RequestContactEditorUIEvent::ref editEvent = boost::dynamic_pointer_cast<RequestContactEditorUIEvent>(event);
+ if (!editEvent) {
+ return;
+ }
+
+ if (!contactEditWindow) {
+ contactEditWindow = contactEditWindowFactory->createContactEditWindow();
+ contactEditWindow->onRemoveContactRequest.connect(boost::bind(&ContactEditController::handleRemoveContactRequest, this));
+ contactEditWindow->onChangeContactRequest.connect(boost::bind(&ContactEditController::handleChangeContactRequest, this, _1, _2));
+ }
+ currentContact = rosterController->getItem(editEvent->getJID());
+ assert(currentContact);
+ jid = rosterController->getItem(editEvent->getJID())->getJID();
+ contactEditWindow->setContact(jid, currentContact->getName(), currentContact->getGroups(), rosterController->getGroups());
+ contactEditWindow->show();
+
+ if (vcardManager) {
+ VCard::ref vcard = vcardManager->getVCardAndRequestWhenNeeded(jid);
+ if (vcard) {
+ handleVCardChanged(jid, vcard);
+ }
+ }
}
void ContactEditController::handleVCardChanged(const JID &jid, VCard::ref vcard) {
- if (jid == this->jid) {
- contactEditWindow->setNameSuggestions(nameSuggestionsFromVCard(vcard));
- }
+ if (jid == this->jid) {
+ contactEditWindow->setNameSuggestions(nameSuggestionsFromVCard(vcard));
+ }
}
void ContactEditController::setAvailable(bool b) {
- if (contactEditWindow) {
- contactEditWindow->setEnabled(b);
- }
+ if (contactEditWindow) {
+ contactEditWindow->setEnabled(b);
+ }
}
std::vector<std::string> ContactEditController::nameSuggestionsFromVCard(VCard::ref vcard) {
- std::vector<std::string> suggestions;
- if (!vcard->getNickname().empty()) {
- suggestions.push_back(vcard->getNickname());
- }
- if (!vcard->getFullName().empty()) {
- suggestions.push_back(vcard->getFullName());
- }
- if (!vcard->getGivenName().empty()) {
- std::string suggestedName;
- suggestedName = vcard->getGivenName();
- boost::algorithm::trim(suggestedName);
- suggestions.push_back(suggestedName);
- }
- return suggestions;
+ std::vector<std::string> suggestions;
+ if (!vcard->getNickname().empty()) {
+ suggestions.push_back(vcard->getNickname());
+ }
+ if (!vcard->getFullName().empty()) {
+ suggestions.push_back(vcard->getFullName());
+ }
+ if (!vcard->getGivenName().empty()) {
+ std::string suggestedName;
+ suggestedName = vcard->getGivenName();
+ boost::algorithm::trim(suggestedName);
+ suggestions.push_back(suggestedName);
+ }
+ return suggestions;
}
void ContactEditController::handleRemoveContactRequest() {
- assert(currentContact);
- uiEventStream->send(boost::make_shared<RemoveRosterItemUIEvent>(currentContact->getJID()));
- contactEditWindow->hide();
+ assert(currentContact);
+ uiEventStream->send(boost::make_shared<RemoveRosterItemUIEvent>(currentContact->getJID()));
+ contactEditWindow->hide();
}
void ContactEditController::handleChangeContactRequest(const std::string& name, const std::set<std::string>& newGroups) {
- std::vector<std::string> oldGroupsVector = currentContact->getGroups();
- std::set<std::string> oldGroups(oldGroupsVector.begin(), oldGroupsVector.end());
- if (oldGroups != newGroups || currentContact->getName() != name) {
- XMPPRosterItem newContact(*currentContact);
- newContact.setName(name);
- newContact.setGroups(std::vector<std::string>(newGroups.begin(), newGroups.end()));
- rosterController->updateItem(newContact);
- }
- contactEditWindow->hide();
+ std::vector<std::string> oldGroupsVector = currentContact->getGroups();
+ std::set<std::string> oldGroups(oldGroupsVector.begin(), oldGroupsVector.end());
+ if (oldGroups != newGroups || currentContact->getName() != name) {
+ XMPPRosterItem newContact(*currentContact);
+ newContact.setName(name);
+ newContact.setGroups(std::vector<std::string>(newGroups.begin(), newGroups.end()));
+ rosterController->updateItem(newContact);
+ }
+ contactEditWindow->hide();
}
}
diff --git a/Swift/Controllers/ContactEditController.h b/Swift/Controllers/ContactEditController.h
index 671fe38..ab2b52e 100644
--- a/Swift/Controllers/ContactEditController.h
+++ b/Swift/Controllers/ContactEditController.h
@@ -19,38 +19,38 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class UIEventStream;
- class ContactEditWindowFactory;
- class ContactEditWindow;
- class RosterController;
- class VCardManager;
-
- class ContactEditController {
- public:
- ContactEditController(RosterController* rosterController, VCardManager* vcardManager, ContactEditWindowFactory* contactEditWindowFactory, UIEventStream* uiEventStream);
- ~ContactEditController();
-
- void setAvailable(bool b);
-
- public:
- static std::vector<std::string> nameSuggestionsFromVCard(VCard::ref vcard);
-
- private:
- void handleRemoveContactRequest();
- void handleChangeContactRequest(const std::string& name, const std::set<std::string>& groups);
-
- private:
- void handleUIEvent(UIEvent::ref event);
- void handleVCardChanged(const JID& jid, VCard::ref vcard);
-
- private:
- boost::optional<XMPPRosterItem> currentContact;
- RosterController* rosterController;
- VCardManager* vcardManager;
- ContactEditWindowFactory* contactEditWindowFactory;
- UIEventStream* uiEventStream;
- JID jid;
- ContactEditWindow* contactEditWindow;
- };
+ class UIEventStream;
+ class ContactEditWindowFactory;
+ class ContactEditWindow;
+ class RosterController;
+ class VCardManager;
+
+ class ContactEditController {
+ public:
+ ContactEditController(RosterController* rosterController, VCardManager* vcardManager, ContactEditWindowFactory* contactEditWindowFactory, UIEventStream* uiEventStream);
+ ~ContactEditController();
+
+ void setAvailable(bool b);
+
+ public:
+ static std::vector<std::string> nameSuggestionsFromVCard(VCard::ref vcard);
+
+ private:
+ void handleRemoveContactRequest();
+ void handleChangeContactRequest(const std::string& name, const std::set<std::string>& groups);
+
+ private:
+ void handleUIEvent(UIEvent::ref event);
+ void handleVCardChanged(const JID& jid, VCard::ref vcard);
+
+ private:
+ boost::optional<XMPPRosterItem> currentContact;
+ RosterController* rosterController;
+ VCardManager* vcardManager;
+ ContactEditWindowFactory* contactEditWindowFactory;
+ UIEventStream* uiEventStream;
+ JID jid;
+ ContactEditWindow* contactEditWindow;
+ };
}
diff --git a/Swift/Controllers/ContactProvider.h b/Swift/Controllers/ContactProvider.h
index 08812d5..423f8a3 100644
--- a/Swift/Controllers/ContactProvider.h
+++ b/Swift/Controllers/ContactProvider.h
@@ -19,9 +19,9 @@
namespace Swift {
class ContactProvider {
- public:
- virtual ~ContactProvider();
- virtual std::vector<Contact::ref> getContacts(bool withMUCNicks) = 0;
+ public:
+ virtual ~ContactProvider();
+ virtual std::vector<Contact::ref> getContacts(bool withMUCNicks) = 0;
};
}
diff --git a/Swift/Controllers/ContactSuggester.cpp b/Swift/Controllers/ContactSuggester.cpp
index a2b605a..04e9dc4 100644
--- a/Swift/Controllers/ContactSuggester.cpp
+++ b/Swift/Controllers/ContactSuggester.cpp
@@ -39,49 +39,49 @@ ContactSuggester::~ContactSuggester() {
}
void ContactSuggester::addContactProvider(ContactProvider* provider) {
- contactProviders_.push_back(provider);
+ contactProviders_.push_back(provider);
}
bool ContactSuggester::matchContact(const std::string& search, const Contact::ref& c) {
- if (fuzzyMatch(c->name, search)) {
- return true;
- }
- else if (c->jid.isValid()) {
- return fuzzyMatch(c->jid.toString(), search);
- }
- return false;
+ if (fuzzyMatch(c->name, search)) {
+ return true;
+ }
+ else if (c->jid.isValid()) {
+ return fuzzyMatch(c->jid.toString(), search);
+ }
+ return false;
}
std::vector<Contact::ref> ContactSuggester::getSuggestions(const std::string& search, bool withMUCNicks) const {
- std::vector<Contact::ref> results;
+ std::vector<Contact::ref> results;
- foreach(ContactProvider* provider, contactProviders_) {
- append(results, provider->getContacts(withMUCNicks));
- }
+ foreach(ContactProvider* provider, contactProviders_) {
+ append(results, provider->getContacts(withMUCNicks));
+ }
- std::sort(results.begin(), results.end(), Contact::lexicographicalSortPredicate);
- results.erase(std::unique(results.begin(), results.end(), Contact::equalityPredicate), results.end());
- results.erase(std::remove_if(results.begin(), results.end(), !lambda::bind(&matchContact, search, lambda::_1)),
- results.end());
- std::sort(results.begin(), results.end(), boost::bind(&Contact::sortPredicate, _1, _2, search));
+ std::sort(results.begin(), results.end(), Contact::lexicographicalSortPredicate);
+ results.erase(std::unique(results.begin(), results.end(), Contact::equalityPredicate), results.end());
+ results.erase(std::remove_if(results.begin(), results.end(), !lambda::bind(&matchContact, search, lambda::_1)),
+ results.end());
+ std::sort(results.begin(), results.end(), boost::bind(&Contact::sortPredicate, _1, _2, search));
- return results;
+ return results;
}
bool ContactSuggester::fuzzyMatch(std::string text, std::string match) {
- std::string lowerText = text;
- boost::algorithm::to_lower(lowerText);
- std::string lowerMatch = match;
- boost::algorithm::to_lower(lowerMatch);
- size_t lastMatch = 0;
- for (size_t i = 0; i < lowerMatch.length(); ++i) {
- size_t where = lowerText.find_first_of(lowerMatch[i], lastMatch);
- if (where == std::string::npos) {
- return false;
- }
- lastMatch = where + 1;
- }
- return true;
+ std::string lowerText = text;
+ boost::algorithm::to_lower(lowerText);
+ std::string lowerMatch = match;
+ boost::algorithm::to_lower(lowerMatch);
+ size_t lastMatch = 0;
+ for (size_t i = 0; i < lowerMatch.length(); ++i) {
+ size_t where = lowerText.find_first_of(lowerMatch[i], lastMatch);
+ if (where == std::string::npos) {
+ return false;
+ }
+ lastMatch = where + 1;
+ }
+ return true;
}
}
diff --git a/Swift/Controllers/ContactSuggester.h b/Swift/Controllers/ContactSuggester.h
index a57f638..f91879d 100644
--- a/Swift/Controllers/ContactSuggester.h
+++ b/Swift/Controllers/ContactSuggester.h
@@ -20,24 +20,24 @@
class ContactSuggesterTest;
namespace Swift {
- class ContactProvider;
-
- class ContactSuggester {
- public:
- ContactSuggester();
- ~ContactSuggester();
-
- void addContactProvider(ContactProvider* provider);
-
- std::vector<Contact::ref> getSuggestions(const std::string& search, bool withMUCNicks) const;
- public:
- static bool matchContact(const std::string& search, const Contact::ref& c);
- /**
- * Performs fuzzy matching on the string text. Matches when each character of match string is present in sequence in text string.
- */
- static bool fuzzyMatch(std::string text, std::string match);
-
- private:
- std::vector<ContactProvider*> contactProviders_;
- };
+ class ContactProvider;
+
+ class ContactSuggester {
+ public:
+ ContactSuggester();
+ ~ContactSuggester();
+
+ void addContactProvider(ContactProvider* provider);
+
+ std::vector<Contact::ref> getSuggestions(const std::string& search, bool withMUCNicks) const;
+ public:
+ static bool matchContact(const std::string& search, const Contact::ref& c);
+ /**
+ * Performs fuzzy matching on the string text. Matches when each character of match string is present in sequence in text string.
+ */
+ static bool fuzzyMatch(std::string text, std::string match);
+
+ private:
+ std::vector<ContactProvider*> contactProviders_;
+ };
}
diff --git a/Swift/Controllers/ContactsFromXMPPRoster.cpp b/Swift/Controllers/ContactsFromXMPPRoster.cpp
index 1cab9b1..1aa4424 100644
--- a/Swift/Controllers/ContactsFromXMPPRoster.cpp
+++ b/Swift/Controllers/ContactsFromXMPPRoster.cpp
@@ -27,15 +27,15 @@ ContactsFromXMPPRoster::~ContactsFromXMPPRoster() {
}
std::vector<Contact::ref> ContactsFromXMPPRoster::getContacts(bool /*withMUCNicks*/) {
- std::vector<Contact::ref> results;
- std::vector<XMPPRosterItem> rosterItems = roster_->getItems();
- foreach(const XMPPRosterItem& rosterItem, rosterItems) {
- Contact::ref contact = boost::make_shared<Contact>(rosterItem.getName().empty() ? rosterItem.getJID().toString() : rosterItem.getName(), rosterItem.getJID(), StatusShow::None,"");
- contact->statusType = presenceOracle_->getAccountPresence(contact->jid) ? presenceOracle_->getAccountPresence(contact->jid)->getShow() : StatusShow::None;
- contact->avatarPath = avatarManager_->getAvatarPath(contact->jid);
- results.push_back(contact);
- }
- return results;
+ std::vector<Contact::ref> results;
+ std::vector<XMPPRosterItem> rosterItems = roster_->getItems();
+ foreach(const XMPPRosterItem& rosterItem, rosterItems) {
+ Contact::ref contact = boost::make_shared<Contact>(rosterItem.getName().empty() ? rosterItem.getJID().toString() : rosterItem.getName(), rosterItem.getJID(), StatusShow::None,"");
+ contact->statusType = presenceOracle_->getAccountPresence(contact->jid) ? presenceOracle_->getAccountPresence(contact->jid)->getShow() : StatusShow::None;
+ contact->avatarPath = avatarManager_->getAvatarPath(contact->jid);
+ results.push_back(contact);
+ }
+ return results;
}
}
diff --git a/Swift/Controllers/ContactsFromXMPPRoster.h b/Swift/Controllers/ContactsFromXMPPRoster.h
index 43d4985..2782dcc 100644
--- a/Swift/Controllers/ContactsFromXMPPRoster.h
+++ b/Swift/Controllers/ContactsFromXMPPRoster.h
@@ -21,15 +21,15 @@ class AvatarManager;
class XMPPRoster;
class ContactsFromXMPPRoster : public ContactProvider {
- public:
- ContactsFromXMPPRoster(XMPPRoster* roster, AvatarManager* avatarManager, PresenceOracle* presenceOracle);
- virtual ~ContactsFromXMPPRoster();
-
- virtual std::vector<Contact::ref> getContacts(bool withMUCNicks);
- private:
- XMPPRoster* roster_;
- AvatarManager* avatarManager_;
- PresenceOracle* presenceOracle_;
+ public:
+ ContactsFromXMPPRoster(XMPPRoster* roster, AvatarManager* avatarManager, PresenceOracle* presenceOracle);
+ virtual ~ContactsFromXMPPRoster();
+
+ virtual std::vector<Contact::ref> getContacts(bool withMUCNicks);
+ private:
+ XMPPRoster* roster_;
+ AvatarManager* avatarManager_;
+ PresenceOracle* presenceOracle_;
};
}
diff --git a/Swift/Controllers/DummySoundPlayer.h b/Swift/Controllers/DummySoundPlayer.h
index 2d99fb9..e297cae 100644
--- a/Swift/Controllers/DummySoundPlayer.h
+++ b/Swift/Controllers/DummySoundPlayer.h
@@ -9,8 +9,8 @@
#include <Swift/Controllers/SoundPlayer.h>
namespace Swift {
- class DummySoundPlayer : public SoundPlayer {
- public:
- void playSound(SoundEffect /*sound*/, const std::string& /*soundResource*/) {}
- };
+ class DummySoundPlayer : public SoundPlayer {
+ public:
+ void playSound(SoundEffect /*sound*/, const std::string& /*soundResource*/) {}
+ };
}
diff --git a/Swift/Controllers/DummySystemTray.h b/Swift/Controllers/DummySystemTray.h
index b413737..b36ed28 100644
--- a/Swift/Controllers/DummySystemTray.h
+++ b/Swift/Controllers/DummySystemTray.h
@@ -9,10 +9,10 @@
#include <Swift/Controllers/SystemTray.h>
namespace Swift {
- class DummySystemTray : public SystemTray {
- public:
- void setUnreadMessages(bool /*some*/) {}
- void setStatusType(StatusShow::Type /*type*/) {}
- void setConnecting() {}
- };
+ class DummySystemTray : public SystemTray {
+ public:
+ void setUnreadMessages(bool /*some*/) {}
+ void setStatusType(StatusShow::Type /*type*/) {}
+ void setConnecting() {}
+ };
}
diff --git a/Swift/Controllers/EventNotifier.cpp b/Swift/Controllers/EventNotifier.cpp
index 6615448..f4a9c2f 100644
--- a/Swift/Controllers/EventNotifier.cpp
+++ b/Swift/Controllers/EventNotifier.cpp
@@ -28,53 +28,53 @@
namespace Swift {
EventNotifier::EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver) : eventController(eventController), notifier(notifier), avatarManager(avatarManager), nickResolver(nickResolver) {
- eventController->onEventQueueEventAdded.connect(boost::bind(&EventNotifier::handleEventAdded, this, _1));
+ eventController->onEventQueueEventAdded.connect(boost::bind(&EventNotifier::handleEventAdded, this, _1));
}
EventNotifier::~EventNotifier() {
- notifier->purgeCallbacks();
- eventController->onEventQueueEventAdded.disconnect(boost::bind(&EventNotifier::handleEventAdded, this, _1));
+ notifier->purgeCallbacks();
+ eventController->onEventQueueEventAdded.disconnect(boost::bind(&EventNotifier::handleEventAdded, this, _1));
}
void EventNotifier::handleEventAdded(boost::shared_ptr<StanzaEvent> event) {
- if (event->getConcluded()) {
- return;
- }
- if (boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event)) {
- JID jid = messageEvent->getStanza()->getFrom();
- std::string title = nickResolver->jidToNick(jid);
- if (!messageEvent->getStanza()->isError() && !messageEvent->getStanza()->getBody().get_value_or("").empty()) {
- JID activationJID = jid;
- if (messageEvent->getStanza()->getType() == Message::Groupchat) {
- activationJID = jid.toBare();
- }
- std::string messageText = messageEvent->getStanza()->getBody().get_value_or("");
- if (boost::starts_with(messageText, "/me ")) {
- messageText = "*" + String::getSplittedAtFirst(messageText, ' ').second + "*";
- }
- notifier->showMessage(Notifier::IncomingMessage, title, messageText, avatarManager->getAvatarPath(jid), boost::bind(&EventNotifier::handleNotificationActivated, this, activationJID));
- }
- }
- else if(boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event)) {
- JID jid = subscriptionEvent->getJID();
- std::string title = jid;
- std::string message = str(format(QT_TRANSLATE_NOOP("", "%1% wants to add you to his/her contact list")) % nickResolver->jidToNick(jid));
- notifier->showMessage(Notifier::SystemMessage, title, message, boost::filesystem::path(), boost::function<void()>());
- }
- else if(boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event)) {
- notifier->showMessage(Notifier::SystemMessage, QT_TRANSLATE_NOOP("", "Error"), errorEvent->getText(), boost::filesystem::path(), boost::function<void()>());
- }
- else if (boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event)) {
- std::string title = mucInviteEvent->getInviter();
- std::string message = str(format(QT_TRANSLATE_NOOP("", "%1% has invited you to enter the %2% room")) % nickResolver->jidToNick(mucInviteEvent->getInviter()) % mucInviteEvent->getRoomJID());
- // FIXME: not show avatar or greyed out avatar for mediated invites
- notifier->showMessage(Notifier::SystemMessage, title, message, avatarManager->getAvatarPath(mucInviteEvent->getInviter()), boost::bind(&EventNotifier::handleNotificationActivated, this, mucInviteEvent->getInviter()));
- }
+ if (event->getConcluded()) {
+ return;
+ }
+ if (boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event)) {
+ JID jid = messageEvent->getStanza()->getFrom();
+ std::string title = nickResolver->jidToNick(jid);
+ if (!messageEvent->getStanza()->isError() && !messageEvent->getStanza()->getBody().get_value_or("").empty()) {
+ JID activationJID = jid;
+ if (messageEvent->getStanza()->getType() == Message::Groupchat) {
+ activationJID = jid.toBare();
+ }
+ std::string messageText = messageEvent->getStanza()->getBody().get_value_or("");
+ if (boost::starts_with(messageText, "/me ")) {
+ messageText = "*" + String::getSplittedAtFirst(messageText, ' ').second + "*";
+ }
+ notifier->showMessage(Notifier::IncomingMessage, title, messageText, avatarManager->getAvatarPath(jid), boost::bind(&EventNotifier::handleNotificationActivated, this, activationJID));
+ }
+ }
+ else if(boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event)) {
+ JID jid = subscriptionEvent->getJID();
+ std::string title = jid;
+ std::string message = str(format(QT_TRANSLATE_NOOP("", "%1% wants to add you to his/her contact list")) % nickResolver->jidToNick(jid));
+ notifier->showMessage(Notifier::SystemMessage, title, message, boost::filesystem::path(), boost::function<void()>());
+ }
+ else if(boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event)) {
+ notifier->showMessage(Notifier::SystemMessage, QT_TRANSLATE_NOOP("", "Error"), errorEvent->getText(), boost::filesystem::path(), boost::function<void()>());
+ }
+ else if (boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event)) {
+ std::string title = mucInviteEvent->getInviter();
+ std::string message = str(format(QT_TRANSLATE_NOOP("", "%1% has invited you to enter the %2% room")) % nickResolver->jidToNick(mucInviteEvent->getInviter()) % mucInviteEvent->getRoomJID());
+ // FIXME: not show avatar or greyed out avatar for mediated invites
+ notifier->showMessage(Notifier::SystemMessage, title, message, avatarManager->getAvatarPath(mucInviteEvent->getInviter()), boost::bind(&EventNotifier::handleNotificationActivated, this, mucInviteEvent->getInviter()));
+ }
}
void EventNotifier::handleNotificationActivated(JID jid) {
- onNotificationActivated(jid);
+ onNotificationActivated(jid);
}
}
diff --git a/Swift/Controllers/EventNotifier.h b/Swift/Controllers/EventNotifier.h
index 2ecff6a..4661c46 100644
--- a/Swift/Controllers/EventNotifier.h
+++ b/Swift/Controllers/EventNotifier.h
@@ -16,29 +16,29 @@
#include <SwifTools/Notifier/Notifier.h>
namespace Swift {
- class EventController;
- class Notifier;
- class AvatarManager;
- class NickResolver;
- class JID;
- class UIEventStream;
- class SettingsProvider;
-
- class EventNotifier {
- public:
- EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver);
- ~EventNotifier();
-
- boost::signal<void (const JID&)> onNotificationActivated;
-
- private:
- void handleEventAdded(boost::shared_ptr<StanzaEvent>);
- void handleNotificationActivated(JID jid);
-
- private:
- EventController* eventController;
- Notifier* notifier;
- AvatarManager* avatarManager;
- NickResolver* nickResolver;
- };
+ class EventController;
+ class Notifier;
+ class AvatarManager;
+ class NickResolver;
+ class JID;
+ class UIEventStream;
+ class SettingsProvider;
+
+ class EventNotifier {
+ public:
+ EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver);
+ ~EventNotifier();
+
+ boost::signal<void (const JID&)> onNotificationActivated;
+
+ private:
+ void handleEventAdded(boost::shared_ptr<StanzaEvent>);
+ void handleNotificationActivated(JID jid);
+
+ private:
+ EventController* eventController;
+ Notifier* notifier;
+ AvatarManager* avatarManager;
+ NickResolver* nickResolver;
+ };
}
diff --git a/Swift/Controllers/EventWindowController.cpp b/Swift/Controllers/EventWindowController.cpp
index 91fedd2..2739a87 100644
--- a/Swift/Controllers/EventWindowController.cpp
+++ b/Swift/Controllers/EventWindowController.cpp
@@ -14,41 +14,41 @@
namespace Swift {
EventWindowController::EventWindowController(EventController* eventController, EventWindowFactory* windowFactory) {
- eventController_ = eventController;
- windowFactory_ = windowFactory;
- window_ = windowFactory_->createEventWindow();
- eventAddedConnection_ = eventController_->onEventQueueEventAdded.connect(boost::bind(&EventWindowController::handleEventQueueEventAdded, this, _1));
+ eventController_ = eventController;
+ windowFactory_ = windowFactory;
+ window_ = windowFactory_->createEventWindow();
+ eventAddedConnection_ = eventController_->onEventQueueEventAdded.connect(boost::bind(&EventWindowController::handleEventQueueEventAdded, this, _1));
}
EventWindowController::~EventWindowController() {
- if (window_->canDelete()) {
- delete window_;
- }
+ if (window_->canDelete()) {
+ delete window_;
+ }
}
void EventWindowController::handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent> event) {
- if (event->getConcluded()) {
- handleEventConcluded(event);
- } else {
- boost::shared_ptr<MessageEvent> message = boost::dynamic_pointer_cast<MessageEvent>(event);
- if (!(message && message->isReadable())) {
- event->onConclusion.connect(boost::bind(&EventWindowController::handleEventConcluded, this, event));
- window_->addEvent(event, true);
- }
- }
+ if (event->getConcluded()) {
+ handleEventConcluded(event);
+ } else {
+ boost::shared_ptr<MessageEvent> message = boost::dynamic_pointer_cast<MessageEvent>(event);
+ if (!(message && message->isReadable())) {
+ event->onConclusion.connect(boost::bind(&EventWindowController::handleEventConcluded, this, event));
+ window_->addEvent(event, true);
+ }
+ }
}
void EventWindowController::handleEventConcluded(boost::shared_ptr<StanzaEvent> event) {
- window_->removeEvent(event);
- bool includeAsCompleted = true;
- /* Because subscription requests get duplicated, don't add them back */
- if (boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event) || boost::dynamic_pointer_cast<MessageEvent>(event)) {
- includeAsCompleted = false;
- }
- if (includeAsCompleted) {
- window_->addEvent(event, false);
- }
- event->onConclusion.disconnect(boost::bind(&EventWindowController::handleEventConcluded, this, event));
+ window_->removeEvent(event);
+ bool includeAsCompleted = true;
+ /* Because subscription requests get duplicated, don't add them back */
+ if (boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event) || boost::dynamic_pointer_cast<MessageEvent>(event)) {
+ includeAsCompleted = false;
+ }
+ if (includeAsCompleted) {
+ window_->addEvent(event, false);
+ }
+ event->onConclusion.disconnect(boost::bind(&EventWindowController::handleEventConcluded, this, event));
}
}
diff --git a/Swift/Controllers/EventWindowController.h b/Swift/Controllers/EventWindowController.h
index 1c50830..eba07ca 100644
--- a/Swift/Controllers/EventWindowController.h
+++ b/Swift/Controllers/EventWindowController.h
@@ -12,18 +12,18 @@
namespace Swift {
- class EventWindowController {
- public:
- EventWindowController(EventController* eventController, EventWindowFactory* windowFactory);
- ~EventWindowController();
- private:
- void handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent> event);
- void handleEventConcluded(boost::shared_ptr<StanzaEvent> event);
+ class EventWindowController {
+ public:
+ EventWindowController(EventController* eventController, EventWindowFactory* windowFactory);
+ ~EventWindowController();
+ private:
+ void handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent> event);
+ void handleEventConcluded(boost::shared_ptr<StanzaEvent> event);
- EventController* eventController_;
- EventWindowFactory* windowFactory_;
- EventWindow* window_;
- boost::bsignals::scoped_connection eventAddedConnection_;
- };
+ EventController* eventController_;
+ EventWindowFactory* windowFactory_;
+ EventWindow* window_;
+ boost::bsignals::scoped_connection eventAddedConnection_;
+ };
}
diff --git a/Swift/Controllers/FileTransfer/FileTransferController.cpp b/Swift/Controllers/FileTransfer/FileTransferController.cpp
index 89e9a91..fd13d99 100644
--- a/Swift/Controllers/FileTransfer/FileTransferController.cpp
+++ b/Swift/Controllers/FileTransfer/FileTransferController.cpp
@@ -28,135 +28,135 @@
namespace Swift {
FileTransferController::FileTransferController(const JID& receipient, const std::string& filename, FileTransferManager* fileTransferManager) :
- sending(true), otherParty(receipient), filename(filename), ftManager(fileTransferManager), ftProgressInfo(0), chatWindow(0), currentState(FileTransfer::State::WaitingForStart) {
-
+ sending(true), otherParty(receipient), filename(filename), ftManager(fileTransferManager), ftProgressInfo(0), chatWindow(0), currentState(FileTransfer::State::WaitingForStart) {
+
}
FileTransferController::FileTransferController(IncomingFileTransfer::ref transfer) :
- sending(false), otherParty(transfer->getSender()), filename(transfer->getFileName()), transfer(transfer), ftManager(0), ftProgressInfo(0), chatWindow(0), currentState(FileTransfer::State::WaitingForStart) {
- transfer->onStateChanged.connect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
+ sending(false), otherParty(transfer->getSender()), filename(transfer->getFileName()), transfer(transfer), ftManager(0), ftProgressInfo(0), chatWindow(0), currentState(FileTransfer::State::WaitingForStart) {
+ transfer->onStateChanged.connect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
}
FileTransferController::~FileTransferController() {
- delete ftProgressInfo;
- transfer->onStateChanged.disconnect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
+ delete ftProgressInfo;
+ transfer->onStateChanged.disconnect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
}
const JID &FileTransferController::getOtherParty() const {
- return otherParty;
+ return otherParty;
}
std::string FileTransferController::setChatWindow(ChatWindow* wnd, std::string nickname) {
- chatWindow = wnd;
- if (sending) {
- uiID = wnd->addFileTransfer(QT_TRANSLATE_NOOP("", "me"), true, filename, boost::filesystem::file_size(boost::filesystem::path(filename)), "");
- } else {
- uiID = wnd->addFileTransfer(nickname, false, filename, transfer->getFileSizeInBytes(), transfer->getDescription());
- }
- return uiID;
+ chatWindow = wnd;
+ if (sending) {
+ uiID = wnd->addFileTransfer(QT_TRANSLATE_NOOP("", "me"), true, filename, boost::filesystem::file_size(boost::filesystem::path(filename)), "");
+ } else {
+ uiID = wnd->addFileTransfer(nickname, false, filename, transfer->getFileSizeInBytes(), transfer->getDescription());
+ }
+ return uiID;
}
void FileTransferController::setReceipient(const JID& receipient) {
- this->otherParty = receipient;
+ this->otherParty = receipient;
}
bool FileTransferController::isIncoming() const {
- return !sending;
+ return !sending;
}
FileTransfer::State FileTransferController::getState() const {
- return currentState;
+ return currentState;
}
int FileTransferController::getProgress() const {
- return ftProgressInfo ? ftProgressInfo->getPercentage() : 0;
+ return ftProgressInfo ? ftProgressInfo->getPercentage() : 0;
}
boost::uintmax_t FileTransferController::getSize() const {
- if (transfer) {
- return transfer->getFileSizeInBytes();
- } else {
- return 0;
- }
+ if (transfer) {
+ return transfer->getFileSizeInBytes();
+ } else {
+ return 0;
+ }
}
void FileTransferController::start(std::string& description) {
- SWIFT_LOG(debug) << "FileTransferController::start" << std::endl;
- fileReadStream = boost::make_shared<FileReadBytestream>(boost::filesystem::path(filename));
- OutgoingFileTransfer::ref outgoingTransfer = ftManager->createOutgoingFileTransfer(otherParty, boost::filesystem::path(filename), description, fileReadStream);
- if (outgoingTransfer) {
- ftProgressInfo = new FileTransferProgressInfo(outgoingTransfer->getFileSizeInBytes());
- ftProgressInfo->onProgressPercentage.connect(boost::bind(&FileTransferController::handleProgressPercentageChange, this, _1));
- outgoingTransfer->onStateChanged.connect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
- outgoingTransfer->onProcessedBytes.connect(boost::bind(&FileTransferProgressInfo::setBytesProcessed, ftProgressInfo, _1));
- outgoingTransfer->start();
- transfer = outgoingTransfer;
- } else {
- std::cerr << "File transfer not supported!" << std::endl;
- }
+ SWIFT_LOG(debug) << "FileTransferController::start" << std::endl;
+ fileReadStream = boost::make_shared<FileReadBytestream>(boost::filesystem::path(filename));
+ OutgoingFileTransfer::ref outgoingTransfer = ftManager->createOutgoingFileTransfer(otherParty, boost::filesystem::path(filename), description, fileReadStream);
+ if (outgoingTransfer) {
+ ftProgressInfo = new FileTransferProgressInfo(outgoingTransfer->getFileSizeInBytes());
+ ftProgressInfo->onProgressPercentage.connect(boost::bind(&FileTransferController::handleProgressPercentageChange, this, _1));
+ outgoingTransfer->onStateChanged.connect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
+ outgoingTransfer->onProcessedBytes.connect(boost::bind(&FileTransferProgressInfo::setBytesProcessed, ftProgressInfo, _1));
+ outgoingTransfer->start();
+ transfer = outgoingTransfer;
+ } else {
+ std::cerr << "File transfer not supported!" << std::endl;
+ }
}
void FileTransferController::accept(std::string& file) {
- SWIFT_LOG(debug) << "FileTransferController::accept" << std::endl;
- IncomingFileTransfer::ref incomingTransfer = boost::dynamic_pointer_cast<IncomingFileTransfer>(transfer);
- if (incomingTransfer) {
- fileWriteStream = boost::make_shared<FileWriteBytestream>(boost::filesystem::path(file));
+ SWIFT_LOG(debug) << "FileTransferController::accept" << std::endl;
+ IncomingFileTransfer::ref incomingTransfer = boost::dynamic_pointer_cast<IncomingFileTransfer>(transfer);
+ if (incomingTransfer) {
+ fileWriteStream = boost::make_shared<FileWriteBytestream>(boost::filesystem::path(file));
- ftProgressInfo = new FileTransferProgressInfo(transfer->getFileSizeInBytes());
- ftProgressInfo->onProgressPercentage.connect(boost::bind(&FileTransferController::handleProgressPercentageChange, this, _1));
- transfer->onProcessedBytes.connect(boost::bind(&FileTransferProgressInfo::setBytesProcessed, ftProgressInfo, _1));
- incomingTransfer->accept(fileWriteStream);
- } else {
- std::cerr << "Expected an incoming transfer in this situation!" << std::endl;
- }
+ ftProgressInfo = new FileTransferProgressInfo(transfer->getFileSizeInBytes());
+ ftProgressInfo->onProgressPercentage.connect(boost::bind(&FileTransferController::handleProgressPercentageChange, this, _1));
+ transfer->onProcessedBytes.connect(boost::bind(&FileTransferProgressInfo::setBytesProcessed, ftProgressInfo, _1));
+ incomingTransfer->accept(fileWriteStream);
+ } else {
+ std::cerr << "Expected an incoming transfer in this situation!" << std::endl;
+ }
}
void FileTransferController::cancel() {
- if (transfer) {
- transfer->cancel();
- } else {
- chatWindow->setFileTransferStatus(uiID, ChatWindow::Canceled);
- }
+ if (transfer) {
+ transfer->cancel();
+ } else {
+ chatWindow->setFileTransferStatus(uiID, ChatWindow::Canceled);
+ }
}
void FileTransferController::handleFileTransferStateChange(FileTransfer::State state) {
- currentState = state;
- onStateChanged();
- switch(state.type) {
- case FileTransfer::State::Initial:
- assert(false);
- return;
- case FileTransfer::State::Negotiating:
- chatWindow->setFileTransferStatus(uiID, ChatWindow::Negotiating);
- return;
- case FileTransfer::State::Transferring:
- chatWindow->setFileTransferStatus(uiID, ChatWindow::Transferring);
- return;
- case FileTransfer::State::Canceled:
- chatWindow->setFileTransferStatus(uiID, ChatWindow::Canceled);
- return;
- case FileTransfer::State::Finished:
- chatWindow->setFileTransferStatus(uiID, ChatWindow::Finished);
- if (fileWriteStream) {
- fileWriteStream->close();
- }
- return;
- case FileTransfer::State::Failed:
- chatWindow->setFileTransferStatus(uiID, ChatWindow::FTFailed);
- return;
- case FileTransfer::State::WaitingForAccept:
- chatWindow->setFileTransferStatus(uiID, ChatWindow::WaitingForAccept);
- return;
- case FileTransfer::State::WaitingForStart:
- chatWindow->setFileTransferStatus(uiID, ChatWindow::Initialisation);
- return;
- }
- assert(false);
+ currentState = state;
+ onStateChanged();
+ switch(state.type) {
+ case FileTransfer::State::Initial:
+ assert(false);
+ return;
+ case FileTransfer::State::Negotiating:
+ chatWindow->setFileTransferStatus(uiID, ChatWindow::Negotiating);
+ return;
+ case FileTransfer::State::Transferring:
+ chatWindow->setFileTransferStatus(uiID, ChatWindow::Transferring);
+ return;
+ case FileTransfer::State::Canceled:
+ chatWindow->setFileTransferStatus(uiID, ChatWindow::Canceled);
+ return;
+ case FileTransfer::State::Finished:
+ chatWindow->setFileTransferStatus(uiID, ChatWindow::Finished);
+ if (fileWriteStream) {
+ fileWriteStream->close();
+ }
+ return;
+ case FileTransfer::State::Failed:
+ chatWindow->setFileTransferStatus(uiID, ChatWindow::FTFailed);
+ return;
+ case FileTransfer::State::WaitingForAccept:
+ chatWindow->setFileTransferStatus(uiID, ChatWindow::WaitingForAccept);
+ return;
+ case FileTransfer::State::WaitingForStart:
+ chatWindow->setFileTransferStatus(uiID, ChatWindow::Initialisation);
+ return;
+ }
+ assert(false);
}
void FileTransferController::handleProgressPercentageChange(int percentage) {
- onProgressChange();
- chatWindow->setFileTransferProgress(uiID, percentage);
+ onProgressChange();
+ chatWindow->setFileTransferProgress(uiID, percentage);
}
}
diff --git a/Swift/Controllers/FileTransfer/FileTransferController.h b/Swift/Controllers/FileTransfer/FileTransferController.h
index 490773d..a25abee 100644
--- a/Swift/Controllers/FileTransfer/FileTransferController.h
+++ b/Swift/Controllers/FileTransfer/FileTransferController.h
@@ -32,49 +32,49 @@ class ChatWindow;
class FileTransferController {
public:
- /**
- * For outgoing file transfers. It'll create a file transfer via FileTransferManager as soon as the descriptive information is available.
- */
- FileTransferController(const JID&, const std::string&, FileTransferManager*);
+ /**
+ * For outgoing file transfers. It'll create a file transfer via FileTransferManager as soon as the descriptive information is available.
+ */
+ FileTransferController(const JID&, const std::string&, FileTransferManager*);
- /**
- * For incoming file transfers.
- */
- FileTransferController(IncomingFileTransfer::ref transfer);
- ~FileTransferController();
+ /**
+ * For incoming file transfers.
+ */
+ FileTransferController(IncomingFileTransfer::ref transfer);
+ ~FileTransferController();
- std::string setChatWindow(ChatWindow*, std::string nickname);
- void setReceipient(const JID& otherParty);
+ std::string setChatWindow(ChatWindow*, std::string nickname);
+ void setReceipient(const JID& otherParty);
- void start(std::string& description);
- void accept(std::string& file);
- void cancel();
+ void start(std::string& description);
+ void accept(std::string& file);
+ void cancel();
- const JID &getOtherParty() const;
- bool isIncoming() const;
- FileTransfer::State getState() const;
- int getProgress() const;
- boost::uintmax_t getSize() const;
+ const JID &getOtherParty() const;
+ bool isIncoming() const;
+ FileTransfer::State getState() const;
+ int getProgress() const;
+ boost::uintmax_t getSize() const;
- boost::signal<void ()> onStateChanged;
- boost::signal<void ()> onProgressChange;
+ boost::signal<void ()> onStateChanged;
+ boost::signal<void ()> onProgressChange;
private:
- void handleFileTransferStateChange(FileTransfer::State);
- void handleProgressPercentageChange(int percentage);
+ void handleFileTransferStateChange(FileTransfer::State);
+ void handleProgressPercentageChange(int percentage);
private:
- bool sending;
- JID otherParty;
- std::string filename;
- FileTransfer::ref transfer;
- boost::shared_ptr<FileReadBytestream> fileReadStream;
- boost::shared_ptr<FileWriteBytestream> fileWriteStream;
- FileTransferManager* ftManager;
- FileTransferProgressInfo* ftProgressInfo;
- ChatWindow* chatWindow;
- std::string uiID;
- FileTransfer::State currentState;
+ bool sending;
+ JID otherParty;
+ std::string filename;
+ FileTransfer::ref transfer;
+ boost::shared_ptr<FileReadBytestream> fileReadStream;
+ boost::shared_ptr<FileWriteBytestream> fileWriteStream;
+ FileTransferManager* ftManager;
+ FileTransferProgressInfo* ftProgressInfo;
+ ChatWindow* chatWindow;
+ std::string uiID;
+ FileTransfer::State currentState;
};
}
diff --git a/Swift/Controllers/FileTransfer/FileTransferOverview.cpp b/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
index 8616c1e..a53b000 100644
--- a/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
+++ b/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
@@ -23,70 +23,70 @@
namespace Swift {
FileTransferOverview::FileTransferOverview(FileTransferManager* ftm) : fileTransferManager(ftm) {
- fileTransferManager->onIncomingFileTransfer.connect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1));
- onNewFileTransferController.connect(boost::bind(&FileTransferOverview::handleNewFileTransferController, this, _1));
+ fileTransferManager->onIncomingFileTransfer.connect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1));
+ onNewFileTransferController.connect(boost::bind(&FileTransferOverview::handleNewFileTransferController, this, _1));
}
FileTransferOverview::~FileTransferOverview() {
- onNewFileTransferController.disconnect(boost::bind(&FileTransferOverview::handleNewFileTransferController, this, _1));
- fileTransferManager->onIncomingFileTransfer.disconnect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1));
- foreach(FileTransferController* controller, fileTransfers) {
- controller->onStateChanged.disconnect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
- }
+ onNewFileTransferController.disconnect(boost::bind(&FileTransferOverview::handleNewFileTransferController, this, _1));
+ fileTransferManager->onIncomingFileTransfer.disconnect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1));
+ foreach(FileTransferController* controller, fileTransfers) {
+ controller->onStateChanged.disconnect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
+ }
}
-
+
void FileTransferOverview::sendFile(const JID& jid, const std::string& filename) {
- if (boost::filesystem::exists(filename) && boost::filesystem::file_size(filename) > 0) {
- FileTransferController* controller = new FileTransferController(jid, filename, fileTransferManager);
- onNewFileTransferController(controller);
- }
+ if (boost::filesystem::exists(filename) && boost::filesystem::file_size(filename) > 0) {
+ FileTransferController* controller = new FileTransferController(jid, filename, fileTransferManager);
+ onNewFileTransferController(controller);
+ }
}
void FileTransferOverview::handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) {
- FileTransferController* controller = new FileTransferController(transfer);
- onNewFileTransferController(controller);
+ FileTransferController* controller = new FileTransferController(transfer);
+ onNewFileTransferController(controller);
}
void FileTransferOverview::handleNewFileTransferController(FileTransferController* controller) {
- fileTransfers.push_back(controller);
- controller->onStateChanged.connect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
+ fileTransfers.push_back(controller);
+ controller->onStateChanged.connect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
}
void FileTransferOverview::handleFileTransferStateChanged() {
- onFileTransferListChanged();
+ onFileTransferListChanged();
}
const std::vector<FileTransferController*>& FileTransferOverview::getFileTransfers() const {
- return fileTransfers;
+ return fileTransfers;
}
void FileTransferOverview::clearFinished() {
- for (std::vector<FileTransferController*>::iterator it = fileTransfers.begin(); it != fileTransfers.end(); ) {
- if((*it)->getState().type == FileTransfer::State::Finished
- || (*it)->getState().type == FileTransfer::State::Failed
- || (*it)->getState().type == FileTransfer::State::Canceled) {
- FileTransferController* controller = *it;
- it = fileTransfers.erase(it);
- controller->onStateChanged.disconnect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
- delete controller;
- } else {
- ++it;
- }
- }
- onFileTransferListChanged();
+ for (std::vector<FileTransferController*>::iterator it = fileTransfers.begin(); it != fileTransfers.end(); ) {
+ if((*it)->getState().type == FileTransfer::State::Finished
+ || (*it)->getState().type == FileTransfer::State::Failed
+ || (*it)->getState().type == FileTransfer::State::Canceled) {
+ FileTransferController* controller = *it;
+ it = fileTransfers.erase(it);
+ controller->onStateChanged.disconnect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
+ delete controller;
+ } else {
+ ++it;
+ }
+ }
+ onFileTransferListChanged();
}
bool FileTransferOverview::isClearable() const {
- bool isClearable = false;
- foreach (FileTransferController* controller, fileTransfers) {
- if(controller->getState().type == FileTransfer::State::Finished
- || controller->getState().type == FileTransfer::State::Failed
- || controller->getState().type == FileTransfer::State::Canceled) {
- isClearable = true;
- break;
- }
- }
- return isClearable;
+ bool isClearable = false;
+ foreach (FileTransferController* controller, fileTransfers) {
+ if(controller->getState().type == FileTransfer::State::Finished
+ || controller->getState().type == FileTransfer::State::Failed
+ || controller->getState().type == FileTransfer::State::Canceled) {
+ isClearable = true;
+ break;
+ }
+ }
+ return isClearable;
}
}
diff --git a/Swift/Controllers/FileTransfer/FileTransferOverview.h b/Swift/Controllers/FileTransfer/FileTransferOverview.h
index e3cbf81..a55727c 100644
--- a/Swift/Controllers/FileTransfer/FileTransferOverview.h
+++ b/Swift/Controllers/FileTransfer/FileTransferOverview.h
@@ -25,25 +25,25 @@ class FileTransferManager;
class FileTransferOverview {
public:
- FileTransferOverview(FileTransferManager*);
- ~FileTransferOverview();
-
- void sendFile(const JID&, const std::string&);
- const std::vector<FileTransferController*>& getFileTransfers() const;
- void clearFinished();
- bool isClearable() const;
+ FileTransferOverview(FileTransferManager*);
+ ~FileTransferOverview();
- boost::signal<void (FileTransferController*)> onNewFileTransferController;
- boost::signal<void ()> onFileTransferListChanged;
+ void sendFile(const JID&, const std::string&);
+ const std::vector<FileTransferController*>& getFileTransfers() const;
+ void clearFinished();
+ bool isClearable() const;
+
+ boost::signal<void (FileTransferController*)> onNewFileTransferController;
+ boost::signal<void ()> onFileTransferListChanged;
private:
- void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer);
- void handleNewFileTransferController(FileTransferController* controller);
- void handleFileTransferStateChanged();
+ void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer);
+ void handleNewFileTransferController(FileTransferController* controller);
+ void handleFileTransferStateChanged();
private:
- std::vector<FileTransferController*> fileTransfers;
- FileTransferManager *fileTransferManager;
+ std::vector<FileTransferController*> fileTransfers;
+ FileTransferManager *fileTransferManager;
};
}
diff --git a/Swift/Controllers/FileTransfer/FileTransferProgressInfo.cpp b/Swift/Controllers/FileTransfer/FileTransferProgressInfo.cpp
index a2fff03..b073017 100644
--- a/Swift/Controllers/FileTransfer/FileTransferProgressInfo.cpp
+++ b/Swift/Controllers/FileTransfer/FileTransferProgressInfo.cpp
@@ -19,21 +19,21 @@
namespace Swift {
FileTransferProgressInfo::FileTransferProgressInfo(boost::uintmax_t completeBytes) : completeBytes(completeBytes), completedBytes(0), percentage(0) {
- onProgressPercentage(0);
+ onProgressPercentage(0);
}
void FileTransferProgressInfo::setBytesProcessed(int processedBytes) {
- int oldPercentage = int(double(completedBytes) / double(completeBytes) * 100.0);
- completedBytes += boost::numeric_cast<boost::uintmax_t>(processedBytes);
- int newPercentage = int(double(completedBytes) / double(completeBytes) * 100.0);
- if (oldPercentage != newPercentage) {
- onProgressPercentage(newPercentage);
- }
- percentage = newPercentage;
+ int oldPercentage = int(double(completedBytes) / double(completeBytes) * 100.0);
+ completedBytes += boost::numeric_cast<boost::uintmax_t>(processedBytes);
+ int newPercentage = int(double(completedBytes) / double(completeBytes) * 100.0);
+ if (oldPercentage != newPercentage) {
+ onProgressPercentage(newPercentage);
+ }
+ percentage = newPercentage;
}
int FileTransferProgressInfo::getPercentage() const {
- return percentage;
+ return percentage;
}
}
diff --git a/Swift/Controllers/FileTransfer/FileTransferProgressInfo.h b/Swift/Controllers/FileTransfer/FileTransferProgressInfo.h
index ea88657..783874a 100644
--- a/Swift/Controllers/FileTransfer/FileTransferProgressInfo.h
+++ b/Swift/Controllers/FileTransfer/FileTransferProgressInfo.h
@@ -20,18 +20,18 @@ namespace Swift {
class FileTransferProgressInfo {
public:
- FileTransferProgressInfo(boost::uintmax_t completeBytes);
+ FileTransferProgressInfo(boost::uintmax_t completeBytes);
public:
- void setBytesProcessed(int processedBytes);
+ void setBytesProcessed(int processedBytes);
- int getPercentage() const;
- boost::signal<void (int)> onProgressPercentage;
+ int getPercentage() const;
+ boost::signal<void (int)> onProgressPercentage;
private:
- boost::uintmax_t completeBytes;
- boost::uintmax_t completedBytes;
- int percentage;
+ boost::uintmax_t completeBytes;
+ boost::uintmax_t completedBytes;
+ int percentage;
};
}
diff --git a/Swift/Controllers/FileTransferListController.cpp b/Swift/Controllers/FileTransferListController.cpp
index 6e84435..a383ae5 100644
--- a/Swift/Controllers/FileTransferListController.cpp
+++ b/Swift/Controllers/FileTransferListController.cpp
@@ -20,32 +20,32 @@
namespace Swift {
FileTransferListController::FileTransferListController(UIEventStream* uiEventStream, FileTransferListWidgetFactory* fileTransferListWidgetFactory) : fileTransferListWidgetFactory(fileTransferListWidgetFactory), fileTransferListWidget(NULL), fileTransferOverview(0) {
- uiEventStream->onUIEvent.connect(boost::bind(&FileTransferListController::handleUIEvent, this, _1));
+ uiEventStream->onUIEvent.connect(boost::bind(&FileTransferListController::handleUIEvent, this, _1));
}
FileTransferListController::~FileTransferListController() {
- delete fileTransferListWidget;
+ delete fileTransferListWidget;
}
void FileTransferListController::setFileTransferOverview(FileTransferOverview *overview) {
- fileTransferOverview = overview;
- if (fileTransferListWidget) {
- fileTransferListWidget->setFileTransferOverview(fileTransferOverview);
- }
+ fileTransferOverview = overview;
+ if (fileTransferListWidget) {
+ fileTransferListWidget->setFileTransferOverview(fileTransferOverview);
+ }
}
void FileTransferListController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
- boost::shared_ptr<RequestFileTransferListUIEvent> event = boost::dynamic_pointer_cast<RequestFileTransferListUIEvent>(rawEvent);
- if (event != NULL) {
- if (fileTransferListWidget == NULL) {
- fileTransferListWidget = fileTransferListWidgetFactory->createFileTransferListWidget();
- if (fileTransferOverview) {
- fileTransferListWidget->setFileTransferOverview(fileTransferOverview);
- }
- }
- fileTransferListWidget->show();
- fileTransferListWidget->activate();
- }
+ boost::shared_ptr<RequestFileTransferListUIEvent> event = boost::dynamic_pointer_cast<RequestFileTransferListUIEvent>(rawEvent);
+ if (event != NULL) {
+ if (fileTransferListWidget == NULL) {
+ fileTransferListWidget = fileTransferListWidgetFactory->createFileTransferListWidget();
+ if (fileTransferOverview) {
+ fileTransferListWidget->setFileTransferOverview(fileTransferOverview);
+ }
+ }
+ fileTransferListWidget->show();
+ fileTransferListWidget->activate();
+ }
}
}
diff --git a/Swift/Controllers/FileTransferListController.h b/Swift/Controllers/FileTransferListController.h
index 079cd35..df79d1f 100644
--- a/Swift/Controllers/FileTransferListController.h
+++ b/Swift/Controllers/FileTransferListController.h
@@ -24,18 +24,18 @@ class FileTransferOverview;
class FileTransferListController {
public:
- FileTransferListController(UIEventStream* uiEventStream, FileTransferListWidgetFactory* fileTransferListWidgetFactory);
- ~FileTransferListController();
+ FileTransferListController(UIEventStream* uiEventStream, FileTransferListWidgetFactory* fileTransferListWidgetFactory);
+ ~FileTransferListController();
- void setFileTransferOverview(FileTransferOverview* overview);
+ void setFileTransferOverview(FileTransferOverview* overview);
private:
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
private:
- FileTransferListWidgetFactory* fileTransferListWidgetFactory;
- FileTransferListWidget* fileTransferListWidget;
- FileTransferOverview* fileTransferOverview;
+ FileTransferListWidgetFactory* fileTransferListWidgetFactory;
+ FileTransferListWidget* fileTransferListWidget;
+ FileTransferOverview* fileTransferOverview;
};
}
diff --git a/Swift/Controllers/HighlightAction.cpp b/Swift/Controllers/HighlightAction.cpp
index 4603408..3ea2c86 100644
--- a/Swift/Controllers/HighlightAction.cpp
+++ b/Swift/Controllers/HighlightAction.cpp
@@ -16,47 +16,47 @@ namespace Swift {
void HighlightAction::setHighlightWholeMessage(bool highlightText)
{
- highlightWholeMessage_ = highlightText;
- if (!highlightWholeMessage_) {
- textColor_.clear();
- textBackground_.clear();
- }
+ highlightWholeMessage_ = highlightText;
+ if (!highlightWholeMessage_) {
+ textColor_.clear();
+ textBackground_.clear();
+ }
}
void HighlightAction::setPlaySound(bool playSound)
{
- playSound_ = playSound;
- if (!playSound_) {
- soundFile_.clear();
- }
+ playSound_ = playSound;
+ if (!playSound_) {
+ soundFile_.clear();
+ }
}
bool operator ==(HighlightAction const& a, HighlightAction const& b) {
- if (a.highlightWholeMessage() != b.highlightWholeMessage()) {
- return false;
- }
+ if (a.highlightWholeMessage() != b.highlightWholeMessage()) {
+ return false;
+ }
- if (a.getTextColor() != b.getTextColor()) {
- return false;
- }
+ if (a.getTextColor() != b.getTextColor()) {
+ return false;
+ }
- if (a.getTextBackground() != b.getTextBackground()) {
- return false;
- }
+ if (a.getTextBackground() != b.getTextBackground()) {
+ return false;
+ }
- if (a.playSound() != b.playSound()) {
- return false;
- }
+ if (a.playSound() != b.playSound()) {
+ return false;
+ }
- if (a.getSoundFile() != b.getSoundFile()) {
- return false;
- }
+ if (a.getSoundFile() != b.getSoundFile()) {
+ return false;
+ }
- return true;
+ return true;
}
bool operator !=(HighlightAction const& a, HighlightAction const& b) {
- return !(a == b);
+ return !(a == b);
}
}
diff --git a/Swift/Controllers/HighlightAction.h b/Swift/Controllers/HighlightAction.h
index 3930eee..b9d4539 100644
--- a/Swift/Controllers/HighlightAction.h
+++ b/Swift/Controllers/HighlightAction.h
@@ -19,64 +19,64 @@
namespace Swift {
- class HighlightRule;
-
- class HighlightAction {
- public:
- HighlightAction() : highlightWholeMessage_(false), playSound_(false) {}
-
- /**
- * Gets the flag that indicates the entire message should be highlighted.
- */
- bool highlightWholeMessage() const { return highlightWholeMessage_; }
- void setHighlightWholeMessage(bool highlightText);
-
- /**
- * Gets the foreground highlight color.
- */
- const std::string& getTextColor() const { return textColor_; }
- void setTextColor(const std::string& textColor) { textColor_ = textColor; }
-
- /**
- * Gets the background highlight color.
- */
- const std::string& getTextBackground() const { return textBackground_; }
- void setTextBackground(const std::string& textBackground) { textBackground_ = textBackground; }
-
- bool playSound() const { return playSound_; }
- void setPlaySound(bool playSound);
-
- /**
- * Gets the sound filename. If the string is empty, assume a default sound file.
- */
- const std::string& getSoundFile() const { return soundFile_; }
- void setSoundFile(const std::string& soundFile) { soundFile_ = soundFile; }
-
- bool isEmpty() const { return !highlightWholeMessage_ && !playSound_; }
-
- private:
- friend class boost::serialization::access;
- template<class Archive> void serialize(Archive & ar, const unsigned int version);
-
- bool highlightWholeMessage_;
- std::string textColor_;
- std::string textBackground_;
-
- bool playSound_;
- std::string soundFile_;
- };
-
- bool operator ==(HighlightAction const& a, HighlightAction const& b);
- bool operator !=(HighlightAction const& a, HighlightAction const& b);
-
- template<class Archive>
- void HighlightAction::serialize(Archive& ar, const unsigned int /*version*/)
- {
- ar & highlightWholeMessage_;
- ar & textColor_;
- ar & textBackground_;
- ar & playSound_;
- ar & soundFile_;
- }
+ class HighlightRule;
+
+ class HighlightAction {
+ public:
+ HighlightAction() : highlightWholeMessage_(false), playSound_(false) {}
+
+ /**
+ * Gets the flag that indicates the entire message should be highlighted.
+ */
+ bool highlightWholeMessage() const { return highlightWholeMessage_; }
+ void setHighlightWholeMessage(bool highlightText);
+
+ /**
+ * Gets the foreground highlight color.
+ */
+ const std::string& getTextColor() const { return textColor_; }
+ void setTextColor(const std::string& textColor) { textColor_ = textColor; }
+
+ /**
+ * Gets the background highlight color.
+ */
+ const std::string& getTextBackground() const { return textBackground_; }
+ void setTextBackground(const std::string& textBackground) { textBackground_ = textBackground; }
+
+ bool playSound() const { return playSound_; }
+ void setPlaySound(bool playSound);
+
+ /**
+ * Gets the sound filename. If the string is empty, assume a default sound file.
+ */
+ const std::string& getSoundFile() const { return soundFile_; }
+ void setSoundFile(const std::string& soundFile) { soundFile_ = soundFile; }
+
+ bool isEmpty() const { return !highlightWholeMessage_ && !playSound_; }
+
+ private:
+ friend class boost::serialization::access;
+ template<class Archive> void serialize(Archive & ar, const unsigned int version);
+
+ bool highlightWholeMessage_;
+ std::string textColor_;
+ std::string textBackground_;
+
+ bool playSound_;
+ std::string soundFile_;
+ };
+
+ bool operator ==(HighlightAction const& a, HighlightAction const& b);
+ bool operator !=(HighlightAction const& a, HighlightAction const& b);
+
+ template<class Archive>
+ void HighlightAction::serialize(Archive& ar, const unsigned int /*version*/)
+ {
+ ar & highlightWholeMessage_;
+ ar & textColor_;
+ ar & textBackground_;
+ ar & playSound_;
+ ar & soundFile_;
+ }
}
diff --git a/Swift/Controllers/HighlightEditorController.cpp b/Swift/Controllers/HighlightEditorController.cpp
index ebda81c..bf5dbc4 100644
--- a/Swift/Controllers/HighlightEditorController.cpp
+++ b/Swift/Controllers/HighlightEditorController.cpp
@@ -25,33 +25,33 @@ namespace Swift {
HighlightEditorController::HighlightEditorController(UIEventStream* uiEventStream, HighlightEditorWindowFactory* highlightEditorWindowFactory, HighlightManager* highlightManager)
: highlightEditorWindowFactory_(highlightEditorWindowFactory), highlightEditorWindow_(NULL), highlightManager_(highlightManager), contactSuggester_(0)
{
- uiEventStream->onUIEvent.connect(boost::bind(&HighlightEditorController::handleUIEvent, this, _1));
+ uiEventStream->onUIEvent.connect(boost::bind(&HighlightEditorController::handleUIEvent, this, _1));
}
HighlightEditorController::~HighlightEditorController()
{
- delete highlightEditorWindow_;
- highlightEditorWindow_ = NULL;
+ delete highlightEditorWindow_;
+ highlightEditorWindow_ = NULL;
}
void HighlightEditorController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent)
{
- boost::shared_ptr<RequestHighlightEditorUIEvent> event = boost::dynamic_pointer_cast<RequestHighlightEditorUIEvent>(rawEvent);
- if (event) {
- if (!highlightEditorWindow_) {
- highlightEditorWindow_ = highlightEditorWindowFactory_->createHighlightEditorWindow();
- highlightEditorWindow_->setHighlightManager(highlightManager_);
- highlightEditorWindow_->onContactSuggestionsRequested.connect(boost::bind(&HighlightEditorController::handleContactSuggestionsRequested, this, _1));
- }
- highlightEditorWindow_->show();
- }
+ boost::shared_ptr<RequestHighlightEditorUIEvent> event = boost::dynamic_pointer_cast<RequestHighlightEditorUIEvent>(rawEvent);
+ if (event) {
+ if (!highlightEditorWindow_) {
+ highlightEditorWindow_ = highlightEditorWindowFactory_->createHighlightEditorWindow();
+ highlightEditorWindow_->setHighlightManager(highlightManager_);
+ highlightEditorWindow_->onContactSuggestionsRequested.connect(boost::bind(&HighlightEditorController::handleContactSuggestionsRequested, this, _1));
+ }
+ highlightEditorWindow_->show();
+ }
}
void HighlightEditorController::handleContactSuggestionsRequested(const std::string& text)
{
- if (contactSuggester_) {
- highlightEditorWindow_->setContactSuggestions(contactSuggester_->getSuggestions(text, true));
- }
+ if (contactSuggester_) {
+ highlightEditorWindow_->setContactSuggestions(contactSuggester_->getSuggestions(text, true));
+ }
}
}
diff --git a/Swift/Controllers/HighlightEditorController.h b/Swift/Controllers/HighlightEditorController.h
index 52587c2..24ad9c2 100644
--- a/Swift/Controllers/HighlightEditorController.h
+++ b/Swift/Controllers/HighlightEditorController.h
@@ -18,31 +18,31 @@
namespace Swift {
- class UIEventStream;
+ class UIEventStream;
- class HighlightEditorWindowFactory;
- class HighlightEditorWindow;
+ class HighlightEditorWindowFactory;
+ class HighlightEditorWindow;
- class HighlightManager;
- class ContactSuggester;
+ class HighlightManager;
+ class ContactSuggester;
- class HighlightEditorController {
- public:
- HighlightEditorController(UIEventStream* uiEventStream, HighlightEditorWindowFactory* highlightEditorWindowFactory, HighlightManager* highlightManager);
- ~HighlightEditorController();
+ class HighlightEditorController {
+ public:
+ HighlightEditorController(UIEventStream* uiEventStream, HighlightEditorWindowFactory* highlightEditorWindowFactory, HighlightManager* highlightManager);
+ ~HighlightEditorController();
- HighlightManager* getHighlightManager() const { return highlightManager_; }
- void setContactSuggester(ContactSuggester *suggester) { contactSuggester_ = suggester; }
+ HighlightManager* getHighlightManager() const { return highlightManager_; }
+ void setContactSuggester(ContactSuggester *suggester) { contactSuggester_ = suggester; }
- private:
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void handleContactSuggestionsRequested(const std::string& text);
+ private:
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleContactSuggestionsRequested(const std::string& text);
- private:
- HighlightEditorWindowFactory* highlightEditorWindowFactory_;
- HighlightEditorWindow* highlightEditorWindow_;
- HighlightManager* highlightManager_;
- ContactSuggester* contactSuggester_;
- };
+ private:
+ HighlightEditorWindowFactory* highlightEditorWindowFactory_;
+ HighlightEditorWindow* highlightEditorWindow_;
+ HighlightManager* highlightManager_;
+ ContactSuggester* contactSuggester_;
+ };
}
diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp
index 07f8e54..45b800a 100644
--- a/Swift/Controllers/HighlightManager.cpp
+++ b/Swift/Controllers/HighlightManager.cpp
@@ -48,102 +48,102 @@
namespace Swift {
HighlightManager::HighlightManager(SettingsProvider* settings)
- : settings_(settings)
- , storingSettings_(false) {
- rules_ = boost::make_shared<HighlightRulesList>();
- loadSettings();
- handleSettingChangedConnection_ = settings_->onSettingChanged.connect(boost::bind(&HighlightManager::handleSettingChanged, this, _1));
+ : settings_(settings)
+ , storingSettings_(false) {
+ rules_ = boost::make_shared<HighlightRulesList>();
+ loadSettings();
+ handleSettingChangedConnection_ = settings_->onSettingChanged.connect(boost::bind(&HighlightManager::handleSettingChanged, this, _1));
}
void HighlightManager::handleSettingChanged(const std::string& settingPath) {
- if (!storingSettings_ && SettingConstants::HIGHLIGHT_RULES.getKey() == settingPath) {
- loadSettings();
- }
+ if (!storingSettings_ && SettingConstants::HIGHLIGHT_RULES.getKey() == settingPath) {
+ loadSettings();
+ }
}
std::string HighlightManager::rulesToString() const {
- std::stringstream stream;
- boost::archive::text_oarchive archive(stream);
- archive << rules_->list_;
- return stream.str();
+ std::stringstream stream;
+ boost::archive::text_oarchive archive(stream);
+ archive << rules_->list_;
+ return stream.str();
}
std::vector<HighlightRule> HighlightManager::getDefaultRules() {
- std::vector<HighlightRule> rules;
-
- HighlightRule chatNotificationRule;
- chatNotificationRule.setMatchChat(true);
- chatNotificationRule.getAction().setPlaySound(true);
- chatNotificationRule.setMatchWholeWords(true);
- rules.push_back(chatNotificationRule);
-
- HighlightRule selfMentionMUCRule;
- selfMentionMUCRule.setMatchMUC(true);
- selfMentionMUCRule.getAction().setPlaySound(true);
- selfMentionMUCRule.setNickIsKeyword(true);
- selfMentionMUCRule.setMatchCase(true);
- selfMentionMUCRule.setMatchWholeWords(true);
- rules.push_back(selfMentionMUCRule);
-
- return rules;
+ std::vector<HighlightRule> rules;
+
+ HighlightRule chatNotificationRule;
+ chatNotificationRule.setMatchChat(true);
+ chatNotificationRule.getAction().setPlaySound(true);
+ chatNotificationRule.setMatchWholeWords(true);
+ rules.push_back(chatNotificationRule);
+
+ HighlightRule selfMentionMUCRule;
+ selfMentionMUCRule.setMatchMUC(true);
+ selfMentionMUCRule.getAction().setPlaySound(true);
+ selfMentionMUCRule.setNickIsKeyword(true);
+ selfMentionMUCRule.setMatchCase(true);
+ selfMentionMUCRule.setMatchWholeWords(true);
+ rules.push_back(selfMentionMUCRule);
+
+ return rules;
}
HighlightRule HighlightManager::getRule(int index) const {
- assert(index >= 0 && static_cast<size_t>(index) < rules_->getSize());
- return rules_->getRule(static_cast<size_t>(index));
+ assert(index >= 0 && static_cast<size_t>(index) < rules_->getSize());
+ return rules_->getRule(static_cast<size_t>(index));
}
void HighlightManager::setRule(int index, const HighlightRule& rule) {
- assert(index >= 0 && static_cast<size_t>(index) < rules_->getSize());
- rules_->list_[static_cast<size_t>(index)] = rule;
+ assert(index >= 0 && static_cast<size_t>(index) < rules_->getSize());
+ rules_->list_[static_cast<size_t>(index)] = rule;
}
void HighlightManager::insertRule(int index, const HighlightRule& rule) {
- assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) <= rules_->getSize());
- rules_->list_.insert(rules_->list_.begin() + index, rule);
+ assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) <= rules_->getSize());
+ rules_->list_.insert(rules_->list_.begin() + index, rule);
}
void HighlightManager::removeRule(int index) {
- assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) < rules_->getSize());
- rules_->list_.erase(rules_->list_.begin() + index);
+ assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) < rules_->getSize());
+ rules_->list_.erase(rules_->list_.begin() + index);
}
void HighlightManager::swapRules(const size_t first, const size_t second) {
- assert(first < rules_->getSize());
- assert(second < rules_->getSize());
- const HighlightRule swap = rules_->getRule(first);
- rules_->setRule(first, rules_->getRule(second));
- rules_->setRule(second, swap);
+ assert(first < rules_->getSize());
+ assert(second < rules_->getSize());
+ const HighlightRule swap = rules_->getRule(first);
+ rules_->setRule(first, rules_->getRule(second));
+ rules_->setRule(second, swap);
}
void HighlightManager::storeSettings() {
- storingSettings_ = true; // don't reload settings while saving
- settings_->storeSetting(SettingConstants::HIGHLIGHT_RULES, rulesToString());
- storingSettings_ = false;
+ storingSettings_ = true; // don't reload settings while saving
+ settings_->storeSetting(SettingConstants::HIGHLIGHT_RULES, rulesToString());
+ storingSettings_ = false;
}
void HighlightManager::loadSettings() {
- std::string rulesString = settings_->getSetting(SettingConstants::HIGHLIGHT_RULES);
- std::stringstream stream;
- stream << rulesString;
- try {
- boost::archive::text_iarchive archive(stream);
- archive >> rules_->list_;
- } catch (boost::archive::archive_exception&) {
- rules_->list_ = getDefaultRules();
- }
+ std::string rulesString = settings_->getSetting(SettingConstants::HIGHLIGHT_RULES);
+ std::stringstream stream;
+ stream << rulesString;
+ try {
+ boost::archive::text_iarchive archive(stream);
+ archive >> rules_->list_;
+ } catch (boost::archive::archive_exception&) {
+ rules_->list_ = getDefaultRules();
+ }
}
Highlighter* HighlightManager::createHighlighter() {
- return new Highlighter(this);
+ return new Highlighter(this);
}
bool HighlightManager::isDefaultRulesList() const {
- return getDefaultRules() == rules_->list_;
+ return getDefaultRules() == rules_->list_;
}
void HighlightManager::resetToDefaultRulesList() {
- rules_->list_ = getDefaultRules();
+ rules_->list_ = getDefaultRules();
}
}
diff --git a/Swift/Controllers/HighlightManager.h b/Swift/Controllers/HighlightManager.h
index 180f7a3..1d2eb8a 100644
--- a/Swift/Controllers/HighlightManager.h
+++ b/Swift/Controllers/HighlightManager.h
@@ -21,61 +21,61 @@
namespace Swift {
- class SettingsProvider;
- class Highlighter;
-
- class HighlightManager {
- public:
-
- class HighlightRulesList {
- public:
- friend class HighlightManager;
- size_t getSize() const { return list_.size(); }
- const HighlightRule& getRule(const size_t index) const { return list_[index]; }
- void addRule(const HighlightRule& rule) { list_.push_back(rule); }
- void combineRules(const HighlightRulesList& rhs) {
- list_.insert(list_.end(), rhs.list_.begin(), rhs.list_.end());
- }
- void setRule(const size_t index, const HighlightRule& rule) {
- list_[index] = rule;
- }
- private:
- std::vector<HighlightRule> list_;
- };
-
- HighlightManager(SettingsProvider* settings);
-
- Highlighter* createHighlighter();
-
- boost::shared_ptr<const HighlightManager::HighlightRulesList> getRules() const { return rules_; }
-
- bool isDefaultRulesList() const;
- void resetToDefaultRulesList();
-
- HighlightRule getRule(int index) const;
- void setRule(int index, const HighlightRule& rule);
- void insertRule(int index, const HighlightRule& rule);
- void removeRule(int index);
- void swapRules(const size_t first, const size_t second);
- void storeSettings();
- void loadSettings();
-
- boost::signal<void (const HighlightAction&)> onHighlight;
-
- private:
- void handleSettingChanged(const std::string& settingPath);
-
- std::string rulesToString() const;
- static std::vector<HighlightRule> getDefaultRules();
-
- private:
- SettingsProvider* settings_;
- bool storingSettings_;
-
- boost::shared_ptr<HighlightManager::HighlightRulesList> rules_;
- boost::bsignals::scoped_connection handleSettingChangedConnection_;
- };
-
- typedef boost::shared_ptr<const HighlightManager::HighlightRulesList> HighlightRulesListPtr;
+ class SettingsProvider;
+ class Highlighter;
+
+ class HighlightManager {
+ public:
+
+ class HighlightRulesList {
+ public:
+ friend class HighlightManager;
+ size_t getSize() const { return list_.size(); }
+ const HighlightRule& getRule(const size_t index) const { return list_[index]; }
+ void addRule(const HighlightRule& rule) { list_.push_back(rule); }
+ void combineRules(const HighlightRulesList& rhs) {
+ list_.insert(list_.end(), rhs.list_.begin(), rhs.list_.end());
+ }
+ void setRule(const size_t index, const HighlightRule& rule) {
+ list_[index] = rule;
+ }
+ private:
+ std::vector<HighlightRule> list_;
+ };
+
+ HighlightManager(SettingsProvider* settings);
+
+ Highlighter* createHighlighter();
+
+ boost::shared_ptr<const HighlightManager::HighlightRulesList> getRules() const { return rules_; }
+
+ bool isDefaultRulesList() const;
+ void resetToDefaultRulesList();
+
+ HighlightRule getRule(int index) const;
+ void setRule(int index, const HighlightRule& rule);
+ void insertRule(int index, const HighlightRule& rule);
+ void removeRule(int index);
+ void swapRules(const size_t first, const size_t second);
+ void storeSettings();
+ void loadSettings();
+
+ boost::signal<void (const HighlightAction&)> onHighlight;
+
+ private:
+ void handleSettingChanged(const std::string& settingPath);
+
+ std::string rulesToString() const;
+ static std::vector<HighlightRule> getDefaultRules();
+
+ private:
+ SettingsProvider* settings_;
+ bool storingSettings_;
+
+ boost::shared_ptr<HighlightManager::HighlightRulesList> rules_;
+ boost::bsignals::scoped_connection handleSettingChangedConnection_;
+ };
+
+ typedef boost::shared_ptr<const HighlightManager::HighlightRulesList> HighlightRulesListPtr;
}
diff --git a/Swift/Controllers/HighlightRule.cpp b/Swift/Controllers/HighlightRule.cpp
index 021e15d..86ac5f7 100644
--- a/Swift/Controllers/HighlightRule.cpp
+++ b/Swift/Controllers/HighlightRule.cpp
@@ -23,179 +23,179 @@
namespace Swift {
HighlightRule::HighlightRule()
- : nickIsKeyword_(false)
- , matchCase_(false)
- , matchWholeWords_(false)
- , matchChat_(false)
- , matchMUC_(false)
+ : nickIsKeyword_(false)
+ , matchCase_(false)
+ , matchWholeWords_(false)
+ , matchChat_(false)
+ , matchMUC_(false)
{
}
boost::regex HighlightRule::regexFromString(const std::string & s) const
{
- std::string escaped = Regex::escape(s);
- std::string word = matchWholeWords_ ? "\\b" : "";
- boost::regex::flag_type flags = boost::regex::normal;
- if (!matchCase_) {
- flags |= boost::regex::icase;
- }
- return boost::regex(word + escaped + word, flags);
+ std::string escaped = Regex::escape(s);
+ std::string word = matchWholeWords_ ? "\\b" : "";
+ boost::regex::flag_type flags = boost::regex::normal;
+ if (!matchCase_) {
+ flags |= boost::regex::icase;
+ }
+ return boost::regex(word + escaped + word, flags);
}
void HighlightRule::updateRegex() const
{
- keywordRegex_.clear();
- foreach (const std::string & k, keywords_) {
- keywordRegex_.push_back(regexFromString(k));
- }
- senderRegex_.clear();
- foreach (const std::string & s, senders_) {
- senderRegex_.push_back(regexFromString(s));
- }
+ keywordRegex_.clear();
+ foreach (const std::string & k, keywords_) {
+ keywordRegex_.push_back(regexFromString(k));
+ }
+ senderRegex_.clear();
+ foreach (const std::string & s, senders_) {
+ senderRegex_.push_back(regexFromString(s));
+ }
}
std::string HighlightRule::boolToString(bool b)
{
- return b ? "1" : "0";
+ return b ? "1" : "0";
}
bool HighlightRule::boolFromString(const std::string& s)
{
- return s == "1";
+ return s == "1";
}
bool HighlightRule::isMatch(const std::string& body, const std::string& sender, const std::string& nick, MessageType messageType) const
{
- if ((messageType == HighlightRule::ChatMessage && matchChat_) || (messageType == HighlightRule::MUCMessage && matchMUC_)) {
-
- bool matchesKeyword = keywords_.empty() && (nick.empty() || !nickIsKeyword_);
- bool matchesSender = senders_.empty();
-
- if (!matchesKeyword) {
- // check if the nickname matches
- if (nickIsKeyword_ && !nick.empty() && boost::regex_search(body, regexFromString(nick))) {
- matchesKeyword = true;
- }
-
- // check if a keyword matches
- if (!matchesKeyword && !keywords_.empty()) {
- foreach (const boost::regex &keyword, keywordRegex_) {
- if (boost::regex_search(body, keyword)) {
- matchesKeyword = true;
- break;
- }
- }
- }
- }
-
- foreach (const boost::regex & rx, senderRegex_) {
- if (boost::regex_search(sender, rx)) {
- matchesSender = true;
- break;
- }
- }
-
- if (matchesKeyword && matchesSender) {
- return true;
- }
- }
-
- return false;
+ if ((messageType == HighlightRule::ChatMessage && matchChat_) || (messageType == HighlightRule::MUCMessage && matchMUC_)) {
+
+ bool matchesKeyword = keywords_.empty() && (nick.empty() || !nickIsKeyword_);
+ bool matchesSender = senders_.empty();
+
+ if (!matchesKeyword) {
+ // check if the nickname matches
+ if (nickIsKeyword_ && !nick.empty() && boost::regex_search(body, regexFromString(nick))) {
+ matchesKeyword = true;
+ }
+
+ // check if a keyword matches
+ if (!matchesKeyword && !keywords_.empty()) {
+ foreach (const boost::regex &keyword, keywordRegex_) {
+ if (boost::regex_search(body, keyword)) {
+ matchesKeyword = true;
+ break;
+ }
+ }
+ }
+ }
+
+ foreach (const boost::regex & rx, senderRegex_) {
+ if (boost::regex_search(sender, rx)) {
+ matchesSender = true;
+ break;
+ }
+ }
+
+ if (matchesKeyword && matchesSender) {
+ return true;
+ }
+ }
+
+ return false;
}
void HighlightRule::setSenders(const std::vector<std::string>& senders)
{
- senders_ = senders;
- updateRegex();
+ senders_ = senders;
+ updateRegex();
}
void HighlightRule::setKeywords(const std::vector<std::string>& keywords)
{
- keywords_ = keywords;
- updateRegex();
+ keywords_ = keywords;
+ updateRegex();
}
std::vector<boost::regex> HighlightRule::getKeywordRegex(const std::string& nick) const {
- if (nickIsKeyword_) {
- std::vector<boost::regex> regex;
- if (!nick.empty()) {
- regex.push_back(regexFromString(nick));
- }
- return regex;
- } else {
- return keywordRegex_;
- }
+ if (nickIsKeyword_) {
+ std::vector<boost::regex> regex;
+ if (!nick.empty()) {
+ regex.push_back(regexFromString(nick));
+ }
+ return regex;
+ } else {
+ return keywordRegex_;
+ }
}
void HighlightRule::setNickIsKeyword(bool nickIsKeyword)
{
- nickIsKeyword_ = nickIsKeyword;
- updateRegex();
+ nickIsKeyword_ = nickIsKeyword;
+ updateRegex();
}
void HighlightRule::setMatchCase(bool matchCase)
{
- matchCase_ = matchCase;
- updateRegex();
+ matchCase_ = matchCase;
+ updateRegex();
}
void HighlightRule::setMatchWholeWords(bool matchWholeWords)
{
- matchWholeWords_ = matchWholeWords;
- updateRegex();
+ matchWholeWords_ = matchWholeWords;
+ updateRegex();
}
void HighlightRule::setMatchChat(bool matchChat)
{
- matchChat_ = matchChat;
- updateRegex();
+ matchChat_ = matchChat;
+ updateRegex();
}
void HighlightRule::setMatchMUC(bool matchMUC)
{
- matchMUC_ = matchMUC;
- updateRegex();
+ matchMUC_ = matchMUC;
+ updateRegex();
}
bool HighlightRule::isEmpty() const
{
- return senders_.empty() && keywords_.empty() && !nickIsKeyword_ && !matchChat_ && !matchMUC_ && action_.isEmpty();
+ return senders_.empty() && keywords_.empty() && !nickIsKeyword_ && !matchChat_ && !matchMUC_ && action_.isEmpty();
}
bool operator ==(HighlightRule const& a, HighlightRule const& b) {
- if (a.getSenders() != b.getSenders()) {
- return false;
- }
+ if (a.getSenders() != b.getSenders()) {
+ return false;
+ }
- if (a.getKeywords() != b.getKeywords()) {
- return false;
- }
+ if (a.getKeywords() != b.getKeywords()) {
+ return false;
+ }
- if (a.getNickIsKeyword() != b.getNickIsKeyword()) {
- return false;
- }
+ if (a.getNickIsKeyword() != b.getNickIsKeyword()) {
+ return false;
+ }
- if (a.getMatchChat() != b.getMatchChat()) {
- return false;
- }
+ if (a.getMatchChat() != b.getMatchChat()) {
+ return false;
+ }
- if (a.getMatchMUC() != b.getMatchMUC()) {
- return false;
- }
+ if (a.getMatchMUC() != b.getMatchMUC()) {
+ return false;
+ }
- if (a.getMatchCase() != b.getMatchCase()) {
- return false;
- }
+ if (a.getMatchCase() != b.getMatchCase()) {
+ return false;
+ }
- if (a.getMatchWholeWords() != b.getMatchWholeWords()) {
- return false;
- }
+ if (a.getMatchWholeWords() != b.getMatchWholeWords()) {
+ return false;
+ }
- if (a.getAction() != b.getAction()) {
- return false;
- }
+ if (a.getAction() != b.getAction()) {
+ return false;
+ }
- return true;
+ return true;
}
}
diff --git a/Swift/Controllers/HighlightRule.h b/Swift/Controllers/HighlightRule.h
index caacaee..bffdc41 100644
--- a/Swift/Controllers/HighlightRule.h
+++ b/Swift/Controllers/HighlightRule.h
@@ -23,81 +23,81 @@
namespace Swift {
- class HighlightRule {
- public:
- HighlightRule();
+ class HighlightRule {
+ public:
+ HighlightRule();
- enum MessageType { ChatMessage, MUCMessage };
+ enum MessageType { ChatMessage, MUCMessage };
- bool isMatch(const std::string& body, const std::string& sender, const std::string& nick, MessageType) const;
+ bool isMatch(const std::string& body, const std::string& sender, const std::string& nick, MessageType) const;
- const HighlightAction& getAction() const { return action_; }
- HighlightAction& getAction() { return action_; }
+ const HighlightAction& getAction() const { return action_; }
+ HighlightAction& getAction() { return action_; }
- const std::vector<std::string>& getSenders() const { return senders_; }
- void setSenders(const std::vector<std::string>&);
- const std::vector<boost::regex>& getSenderRegex() const { return senderRegex_; }
+ const std::vector<std::string>& getSenders() const { return senders_; }
+ void setSenders(const std::vector<std::string>&);
+ const std::vector<boost::regex>& getSenderRegex() const { return senderRegex_; }
- const std::vector<std::string>& getKeywords() const { return keywords_; }
- void setKeywords(const std::vector<std::string>&);
- std::vector<boost::regex> getKeywordRegex(const std::string& nick) const;
+ const std::vector<std::string>& getKeywords() const { return keywords_; }
+ void setKeywords(const std::vector<std::string>&);
+ std::vector<boost::regex> getKeywordRegex(const std::string& nick) const;
- bool getNickIsKeyword() const { return nickIsKeyword_; }
- void setNickIsKeyword(bool);
+ bool getNickIsKeyword() const { return nickIsKeyword_; }
+ void setNickIsKeyword(bool);
- bool getMatchCase() const { return matchCase_; }
- void setMatchCase(bool);
+ bool getMatchCase() const { return matchCase_; }
+ void setMatchCase(bool);
- bool getMatchWholeWords() const { return matchWholeWords_; }
- void setMatchWholeWords(bool);
+ bool getMatchWholeWords() const { return matchWholeWords_; }
+ void setMatchWholeWords(bool);
- bool getMatchChat() const { return matchChat_; }
- void setMatchChat(bool);
+ bool getMatchChat() const { return matchChat_; }
+ void setMatchChat(bool);
- bool getMatchMUC() const { return matchMUC_; }
- void setMatchMUC(bool);
+ bool getMatchMUC() const { return matchMUC_; }
+ void setMatchMUC(bool);
- bool isEmpty() const;
+ bool isEmpty() const;
- private:
- friend class boost::serialization::access;
- template<class Archive> void serialize(Archive & ar, const unsigned int version);
+ private:
+ friend class boost::serialization::access;
+ template<class Archive> void serialize(Archive & ar, const unsigned int version);
- static std::string boolToString(bool);
- static bool boolFromString(const std::string&);
+ static std::string boolToString(bool);
+ static bool boolFromString(const std::string&);
- std::vector<std::string> senders_;
- std::vector<std::string> keywords_;
- bool nickIsKeyword_;
+ std::vector<std::string> senders_;
+ std::vector<std::string> keywords_;
+ bool nickIsKeyword_;
- mutable std::vector<boost::regex> senderRegex_;
- mutable std::vector<boost::regex> keywordRegex_;
- void updateRegex() const;
- boost::regex regexFromString(const std::string&) const;
+ mutable std::vector<boost::regex> senderRegex_;
+ mutable std::vector<boost::regex> keywordRegex_;
+ void updateRegex() const;
+ boost::regex regexFromString(const std::string&) const;
- bool matchCase_;
- bool matchWholeWords_;
+ bool matchCase_;
+ bool matchWholeWords_;
- bool matchChat_;
- bool matchMUC_;
+ bool matchChat_;
+ bool matchMUC_;
- HighlightAction action_;
- };
+ HighlightAction action_;
+ };
- bool operator ==(HighlightRule const& a, HighlightRule const& b);
+ bool operator ==(HighlightRule const& a, HighlightRule const& b);
- template<class Archive>
- void HighlightRule::serialize(Archive& ar, const unsigned int /*version*/)
- {
- ar & senders_;
- ar & keywords_;
- ar & nickIsKeyword_;
- ar & matchChat_;
- ar & matchMUC_;
- ar & matchCase_;
- ar & matchWholeWords_;
- ar & action_;
- updateRegex();
- }
+ template<class Archive>
+ void HighlightRule::serialize(Archive& ar, const unsigned int /*version*/)
+ {
+ ar & senders_;
+ ar & keywords_;
+ ar & nickIsKeyword_;
+ ar & matchChat_;
+ ar & matchMUC_;
+ ar & matchCase_;
+ ar & matchWholeWords_;
+ ar & action_;
+ updateRegex();
+ }
}
diff --git a/Swift/Controllers/Highlighter.cpp b/Swift/Controllers/Highlighter.cpp
index 40f92ba..3499217 100644
--- a/Swift/Controllers/Highlighter.cpp
+++ b/Swift/Controllers/Highlighter.cpp
@@ -19,35 +19,35 @@
namespace Swift {
Highlighter::Highlighter(HighlightManager* manager)
- : manager_(manager)
+ : manager_(manager)
{
- setMode(ChatMode);
+ setMode(ChatMode);
}
void Highlighter::setMode(Mode mode)
{
- mode_ = mode;
- messageType_ = mode_ == ChatMode ? HighlightRule::ChatMessage : HighlightRule::MUCMessage;
+ mode_ = mode;
+ messageType_ = mode_ == ChatMode ? HighlightRule::ChatMessage : HighlightRule::MUCMessage;
}
HighlightAction Highlighter::findFirstFullMessageMatchAction(const std::string& body, const std::string& sender) const
{
- HighlightAction match;
- HighlightRulesListPtr rules = manager_->getRules();
- for (size_t i = 0; i < rules->getSize(); ++i) {
- const HighlightRule& rule = rules->getRule(i);
- if (rule.isMatch(body, sender, nick_, messageType_) && rule.getAction().highlightWholeMessage()) {
- match = rule.getAction();
- break;
- }
- }
-
- return match;
+ HighlightAction match;
+ HighlightRulesListPtr rules = manager_->getRules();
+ for (size_t i = 0; i < rules->getSize(); ++i) {
+ const HighlightRule& rule = rules->getRule(i);
+ if (rule.isMatch(body, sender, nick_, messageType_) && rule.getAction().highlightWholeMessage()) {
+ match = rule.getAction();
+ break;
+ }
+ }
+
+ return match;
}
void Highlighter::handleHighlightAction(const HighlightAction& action)
{
- manager_->onHighlight(action);
+ manager_->onHighlight(action);
}
}
diff --git a/Swift/Controllers/Highlighter.h b/Swift/Controllers/Highlighter.h
index 5d5f531..9ad3339 100644
--- a/Swift/Controllers/Highlighter.h
+++ b/Swift/Controllers/Highlighter.h
@@ -19,27 +19,27 @@
namespace Swift {
- class HighlightManager;
+ class HighlightManager;
- class Highlighter {
- public:
- Highlighter(HighlightManager* manager);
+ class Highlighter {
+ public:
+ Highlighter(HighlightManager* manager);
- enum Mode { ChatMode, MUCMode };
- void setMode(Mode mode);
+ enum Mode { ChatMode, MUCMode };
+ void setMode(Mode mode);
- void setNick(const std::string& nick) { nick_ = nick; }
- std::string getNick() const { return nick_; }
+ void setNick(const std::string& nick) { nick_ = nick; }
+ std::string getNick() const { return nick_; }
- HighlightAction findFirstFullMessageMatchAction(const std::string& body, const std::string& sender) const;
+ HighlightAction findFirstFullMessageMatchAction(const std::string& body, const std::string& sender) const;
- void handleHighlightAction(const HighlightAction& action);
+ void handleHighlightAction(const HighlightAction& action);
- private:
- HighlightManager* manager_;
- Mode mode_;
- HighlightRule::MessageType messageType_;
- std::string nick_;
- };
+ private:
+ HighlightManager* manager_;
+ Mode mode_;
+ HighlightRule::MessageType messageType_;
+ std::string nick_;
+ };
}
diff --git a/Swift/Controllers/HistoryController.cpp b/Swift/Controllers/HistoryController.cpp
index f439429..1e5830c 100644
--- a/Swift/Controllers/HistoryController.cpp
+++ b/Swift/Controllers/HistoryController.cpp
@@ -28,39 +28,39 @@ HistoryController::~HistoryController() {
}
void HistoryController::addMessage(const std::string& message, const JID& fromJID, const JID& toJID, HistoryMessage::Type type, const boost::posix_time::ptime& timeStamp) {
- // note: using localtime timestamps
- boost::posix_time::ptime localTime = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(timeStamp);
- int offset = (localTime - timeStamp).hours();
+ // note: using localtime timestamps
+ boost::posix_time::ptime localTime = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(timeStamp);
+ int offset = (localTime - timeStamp).hours();
- HistoryMessage historyMessage(message, fromJID, toJID, type, localTime, offset);
+ HistoryMessage historyMessage(message, fromJID, toJID, type, localTime, offset);
- localHistory_->addMessage(historyMessage);
- onNewMessage(historyMessage);
+ localHistory_->addMessage(historyMessage);
+ onNewMessage(historyMessage);
}
std::vector<HistoryMessage> HistoryController::getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
- return localHistory_->getMessagesFromDate(selfJID, contactJID, type, date);
+ return localHistory_->getMessagesFromDate(selfJID, contactJID, type, date);
}
std::vector<HistoryMessage> HistoryController::getMUCContext(const JID& selfJID, const JID& mucJID, const boost::posix_time::ptime& timeStamp) const {
- boost::posix_time::ptime localTime = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(timeStamp);
- return getMessagesFromDate(selfJID, mucJID, HistoryMessage::Groupchat, localTime.date());
+ boost::posix_time::ptime localTime = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(timeStamp);
+ return getMessagesFromDate(selfJID, mucJID, HistoryMessage::Groupchat, localTime.date());
}
std::vector<HistoryMessage> HistoryController::getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
- return localHistory_->getMessagesFromPreviousDate(selfJID, contactJID, type, date);
+ return localHistory_->getMessagesFromPreviousDate(selfJID, contactJID, type, date);
}
std::vector<HistoryMessage> HistoryController::getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
- return localHistory_->getMessagesFromNextDate(selfJID, contactJID, type, date);
+ return localHistory_->getMessagesFromNextDate(selfJID, contactJID, type, date);
}
ContactsMap HistoryController::getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword) const {
- return localHistory_->getContacts(selfJID, type, keyword);
+ return localHistory_->getContacts(selfJID, type, keyword);
}
boost::posix_time::ptime HistoryController::getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) {
- return localHistory_->getLastTimeStampFromMUC(selfJID, mucJID);
+ return localHistory_->getLastTimeStampFromMUC(selfJID, mucJID);
}
}
diff --git a/Swift/Controllers/HistoryController.h b/Swift/Controllers/HistoryController.h
index 0bdbb35..f1f613f 100644
--- a/Swift/Controllers/HistoryController.h
+++ b/Swift/Controllers/HistoryController.h
@@ -21,25 +21,25 @@
#include <Swiften/History/HistoryStorage.h>
namespace Swift {
- class JID;
+ class JID;
- class HistoryController {
- public:
- HistoryController(HistoryStorage* localHistoryStorage);
- ~HistoryController();
+ class HistoryController {
+ public:
+ HistoryController(HistoryStorage* localHistoryStorage);
+ ~HistoryController();
- void addMessage(const std::string& message, const JID& fromJID, const JID& toJID, HistoryMessage::Type type, const boost::posix_time::ptime& timeStamp);
- std::vector<HistoryMessage> getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const;
- std::vector<HistoryMessage> getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const;
- std::vector<HistoryMessage> getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const;
- ContactsMap getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword = std::string()) const;
- std::vector<HistoryMessage> getMUCContext(const JID& selfJID, const JID& mucJID, const boost::posix_time::ptime& timeStamp) const;
+ void addMessage(const std::string& message, const JID& fromJID, const JID& toJID, HistoryMessage::Type type, const boost::posix_time::ptime& timeStamp);
+ std::vector<HistoryMessage> getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const;
+ std::vector<HistoryMessage> getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const;
+ std::vector<HistoryMessage> getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const;
+ ContactsMap getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword = std::string()) const;
+ std::vector<HistoryMessage> getMUCContext(const JID& selfJID, const JID& mucJID, const boost::posix_time::ptime& timeStamp) const;
- boost::posix_time::ptime getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID);
+ boost::posix_time::ptime getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID);
- boost::signal<void (const HistoryMessage&)> onNewMessage;
+ boost::signal<void (const HistoryMessage&)> onNewMessage;
- private:
- HistoryStorage* localHistory_;
- };
+ private:
+ HistoryStorage* localHistory_;
+ };
}
diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp
index 2d56b9e..d0ccc66 100644
--- a/Swift/Controllers/HistoryViewController.cpp
+++ b/Swift/Controllers/HistoryViewController.cpp
@@ -25,335 +25,335 @@
#include <Swift/Controllers/UIInterfaces/HistoryWindowFactory.h>
namespace Swift {
- static const std::string category[] = { "Contacts", "MUC", "Contacts" };
+ static const std::string category[] = { "Contacts", "MUC", "Contacts" };
HistoryViewController::HistoryViewController(
- const JID& selfJID,
- UIEventStream* uiEventStream,
- HistoryController* historyController,
- NickResolver* nickResolver,
- AvatarManager* avatarManager,
- PresenceOracle* presenceOracle,
- HistoryWindowFactory* historyWindowFactory) :
- selfJID_(selfJID),
- uiEventStream_(uiEventStream),
- historyController_(historyController),
- nickResolver_(nickResolver),
- avatarManager_(avatarManager),
- presenceOracle_(presenceOracle),
- historyWindowFactory_(historyWindowFactory),
- historyWindow_(NULL),
- selectedItem_(NULL),
- currentResultDate_(boost::gregorian::not_a_date_time) {
- uiEventStream_->onUIEvent.connect(boost::bind(&HistoryViewController::handleUIEvent, this, _1));
-
- roster_ = new Roster(false, true);
+ const JID& selfJID,
+ UIEventStream* uiEventStream,
+ HistoryController* historyController,
+ NickResolver* nickResolver,
+ AvatarManager* avatarManager,
+ PresenceOracle* presenceOracle,
+ HistoryWindowFactory* historyWindowFactory) :
+ selfJID_(selfJID),
+ uiEventStream_(uiEventStream),
+ historyController_(historyController),
+ nickResolver_(nickResolver),
+ avatarManager_(avatarManager),
+ presenceOracle_(presenceOracle),
+ historyWindowFactory_(historyWindowFactory),
+ historyWindow_(NULL),
+ selectedItem_(NULL),
+ currentResultDate_(boost::gregorian::not_a_date_time) {
+ uiEventStream_->onUIEvent.connect(boost::bind(&HistoryViewController::handleUIEvent, this, _1));
+
+ roster_ = new Roster(false, true);
}
HistoryViewController::~HistoryViewController() {
- uiEventStream_->onUIEvent.disconnect(boost::bind(&HistoryViewController::handleUIEvent, this, _1));
- if (historyWindow_) {
- historyWindow_->onSelectedContactChanged.disconnect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1));
- historyWindow_->onReturnPressed.disconnect(boost::bind(&HistoryViewController::handleReturnPressed, this, _1));
- historyWindow_->onScrollReachedTop.disconnect(boost::bind(&HistoryViewController::handleScrollReachedTop, this, _1));
- historyWindow_->onScrollReachedBottom.disconnect(boost::bind(&HistoryViewController::handleScrollReachedBottom, this, _1));
- historyWindow_->onPreviousButtonClicked.disconnect(boost::bind(&HistoryViewController::handlePreviousButtonClicked, this));
- historyWindow_->onNextButtonClicked.disconnect(boost::bind(&HistoryViewController::handleNextButtonClicked, this));
- historyWindow_->onCalendarClicked.disconnect(boost::bind(&HistoryViewController::handleCalendarClicked, this, _1));
- historyController_->onNewMessage.disconnect(boost::bind(&HistoryViewController::handleNewMessage, this, _1));
-
- presenceOracle_->onPresenceChange.disconnect(boost::bind(&HistoryViewController::handlePresenceChanged, this, _1));
- avatarManager_->onAvatarChanged.disconnect(boost::bind(&HistoryViewController::handleAvatarChanged, this, _1));
-
- delete historyWindow_;
- }
- delete roster_;
+ uiEventStream_->onUIEvent.disconnect(boost::bind(&HistoryViewController::handleUIEvent, this, _1));
+ if (historyWindow_) {
+ historyWindow_->onSelectedContactChanged.disconnect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1));
+ historyWindow_->onReturnPressed.disconnect(boost::bind(&HistoryViewController::handleReturnPressed, this, _1));
+ historyWindow_->onScrollReachedTop.disconnect(boost::bind(&HistoryViewController::handleScrollReachedTop, this, _1));
+ historyWindow_->onScrollReachedBottom.disconnect(boost::bind(&HistoryViewController::handleScrollReachedBottom, this, _1));
+ historyWindow_->onPreviousButtonClicked.disconnect(boost::bind(&HistoryViewController::handlePreviousButtonClicked, this));
+ historyWindow_->onNextButtonClicked.disconnect(boost::bind(&HistoryViewController::handleNextButtonClicked, this));
+ historyWindow_->onCalendarClicked.disconnect(boost::bind(&HistoryViewController::handleCalendarClicked, this, _1));
+ historyController_->onNewMessage.disconnect(boost::bind(&HistoryViewController::handleNewMessage, this, _1));
+
+ presenceOracle_->onPresenceChange.disconnect(boost::bind(&HistoryViewController::handlePresenceChanged, this, _1));
+ avatarManager_->onAvatarChanged.disconnect(boost::bind(&HistoryViewController::handleAvatarChanged, this, _1));
+
+ delete historyWindow_;
+ }
+ delete roster_;
}
void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
- boost::shared_ptr<RequestHistoryUIEvent> event = boost::dynamic_pointer_cast<RequestHistoryUIEvent>(rawEvent);
- if (event != NULL) {
- if (historyWindow_ == NULL) {
- historyWindow_ = historyWindowFactory_->createHistoryWindow(uiEventStream_);
- historyWindow_->onSelectedContactChanged.connect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1));
- historyWindow_->onReturnPressed.connect(boost::bind(&HistoryViewController::handleReturnPressed, this, _1));
- historyWindow_->onScrollReachedTop.connect(boost::bind(&HistoryViewController::handleScrollReachedTop, this, _1));
- historyWindow_->onScrollReachedBottom.connect(boost::bind(&HistoryViewController::handleScrollReachedBottom, this, _1));
- historyWindow_->onPreviousButtonClicked.connect(boost::bind(&HistoryViewController::handlePreviousButtonClicked, this));
- historyWindow_->onNextButtonClicked.connect(boost::bind(&HistoryViewController::handleNextButtonClicked, this));
- historyWindow_->onCalendarClicked.connect(boost::bind(&HistoryViewController::handleCalendarClicked, this, _1));
- historyController_->onNewMessage.connect(boost::bind(&HistoryViewController::handleNewMessage, this, _1));
-
- presenceOracle_->onPresenceChange.connect(boost::bind(&HistoryViewController::handlePresenceChanged, this, _1));
- avatarManager_->onAvatarChanged.connect(boost::bind(&HistoryViewController::handleAvatarChanged, this, _1));
-
- historyWindow_->setRosterModel(roster_);
- }
-
- // populate roster by doing an empty search
- handleReturnPressed(std::string());
-
- historyWindow_->activate();
- }
+ boost::shared_ptr<RequestHistoryUIEvent> event = boost::dynamic_pointer_cast<RequestHistoryUIEvent>(rawEvent);
+ if (event != NULL) {
+ if (historyWindow_ == NULL) {
+ historyWindow_ = historyWindowFactory_->createHistoryWindow(uiEventStream_);
+ historyWindow_->onSelectedContactChanged.connect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1));
+ historyWindow_->onReturnPressed.connect(boost::bind(&HistoryViewController::handleReturnPressed, this, _1));
+ historyWindow_->onScrollReachedTop.connect(boost::bind(&HistoryViewController::handleScrollReachedTop, this, _1));
+ historyWindow_->onScrollReachedBottom.connect(boost::bind(&HistoryViewController::handleScrollReachedBottom, this, _1));
+ historyWindow_->onPreviousButtonClicked.connect(boost::bind(&HistoryViewController::handlePreviousButtonClicked, this));
+ historyWindow_->onNextButtonClicked.connect(boost::bind(&HistoryViewController::handleNextButtonClicked, this));
+ historyWindow_->onCalendarClicked.connect(boost::bind(&HistoryViewController::handleCalendarClicked, this, _1));
+ historyController_->onNewMessage.connect(boost::bind(&HistoryViewController::handleNewMessage, this, _1));
+
+ presenceOracle_->onPresenceChange.connect(boost::bind(&HistoryViewController::handlePresenceChanged, this, _1));
+ avatarManager_->onAvatarChanged.connect(boost::bind(&HistoryViewController::handleAvatarChanged, this, _1));
+
+ historyWindow_->setRosterModel(roster_);
+ }
+
+ // populate roster by doing an empty search
+ handleReturnPressed(std::string());
+
+ historyWindow_->activate();
+ }
}
void HistoryViewController::handleSelectedContactChanged(RosterItem* newContact) {
- // FIXME: signal is triggerd twice.
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(newContact);
-
- if (contact && selectedItem_ != contact) {
- selectedItem_ = contact;
- historyWindow_->resetConversationView();
- }
- else {
- return;
- }
-
- JID contactJID = contact->getJID();
-
- std::vector<HistoryMessage> messages;
- for (int it = HistoryMessage::Chat; it <= HistoryMessage::PrivateMessage; it++) {
- HistoryMessage::Type type = static_cast<HistoryMessage::Type>(it);
-
- if (contacts_[type].count(contactJID)) {
- currentResultDate_ = *contacts_[type][contactJID].rbegin();
- selectedItemType_ = type;
- messages = historyController_->getMessagesFromDate(selfJID_, contactJID, type, currentResultDate_);
- }
- }
-
- historyWindow_->setDate(currentResultDate_);
-
- foreach (const HistoryMessage& message, messages) {
- addNewMessage(message, false);
- }
+ // FIXME: signal is triggerd twice.
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(newContact);
+
+ if (contact && selectedItem_ != contact) {
+ selectedItem_ = contact;
+ historyWindow_->resetConversationView();
+ }
+ else {
+ return;
+ }
+
+ JID contactJID = contact->getJID();
+
+ std::vector<HistoryMessage> messages;
+ for (int it = HistoryMessage::Chat; it <= HistoryMessage::PrivateMessage; it++) {
+ HistoryMessage::Type type = static_cast<HistoryMessage::Type>(it);
+
+ if (contacts_[type].count(contactJID)) {
+ currentResultDate_ = *contacts_[type][contactJID].rbegin();
+ selectedItemType_ = type;
+ messages = historyController_->getMessagesFromDate(selfJID_, contactJID, type, currentResultDate_);
+ }
+ }
+
+ historyWindow_->setDate(currentResultDate_);
+
+ foreach (const HistoryMessage& message, messages) {
+ addNewMessage(message, false);
+ }
}
void HistoryViewController::handleNewMessage(const HistoryMessage& message) {
- JID contactJID = message.getFromJID().toBare() == selfJID_ ? message.getToJID() : message.getFromJID();
-
- JID displayJID;
- if (message.getType() == HistoryMessage::PrivateMessage) {
- displayJID = contactJID;
- }
- else {
- displayJID = contactJID.toBare();
- }
-
- // check current conversation
- if (selectedItem_ && selectedItem_->getJID() == displayJID) {
- if (historyWindow_->getLastVisibleDate() == message.getTime().date()) {
- addNewMessage(message, false);
- }
- }
-
- // check if the new message matches the query
- if (message.getMessage().find(historyWindow_->getSearchBoxText()) == std::string::npos) {
- return;
- }
-
- // update contacts
- if (!contacts_[message.getType()].count(displayJID)) {
- roster_->addContact(displayJID, displayJID, nickResolver_->jidToNick(displayJID), category[message.getType()], avatarManager_->getAvatarPath(displayJID));
- }
-
- contacts_[message.getType()][displayJID].insert(message.getTime().date());
+ JID contactJID = message.getFromJID().toBare() == selfJID_ ? message.getToJID() : message.getFromJID();
+
+ JID displayJID;
+ if (message.getType() == HistoryMessage::PrivateMessage) {
+ displayJID = contactJID;
+ }
+ else {
+ displayJID = contactJID.toBare();
+ }
+
+ // check current conversation
+ if (selectedItem_ && selectedItem_->getJID() == displayJID) {
+ if (historyWindow_->getLastVisibleDate() == message.getTime().date()) {
+ addNewMessage(message, false);
+ }
+ }
+
+ // check if the new message matches the query
+ if (message.getMessage().find(historyWindow_->getSearchBoxText()) == std::string::npos) {
+ return;
+ }
+
+ // update contacts
+ if (!contacts_[message.getType()].count(displayJID)) {
+ roster_->addContact(displayJID, displayJID, nickResolver_->jidToNick(displayJID), category[message.getType()], avatarManager_->getAvatarPath(displayJID));
+ }
+
+ contacts_[message.getType()][displayJID].insert(message.getTime().date());
}
void HistoryViewController::addNewMessage(const HistoryMessage& message, bool addAtTheTop) {
- bool senderIsSelf = message.getFromJID().toBare() == selfJID_;
- std::string avatarPath = pathToString(avatarManager_->getAvatarPath(message.getFromJID()));
+ bool senderIsSelf = message.getFromJID().toBare() == selfJID_;
+ std::string avatarPath = pathToString(avatarManager_->getAvatarPath(message.getFromJID()));
- std::string nick = message.getType() != HistoryMessage::Groupchat ? nickResolver_->jidToNick(message.getFromJID()) : message.getFromJID().getResource();
- historyWindow_->addMessage(message.getMessage(), nick, senderIsSelf, avatarPath, message.getTime(), addAtTheTop);
+ std::string nick = message.getType() != HistoryMessage::Groupchat ? nickResolver_->jidToNick(message.getFromJID()) : message.getFromJID().getResource();
+ historyWindow_->addMessage(message.getMessage(), nick, senderIsSelf, avatarPath, message.getTime(), addAtTheTop);
}
void HistoryViewController::handleReturnPressed(const std::string& keyword) {
- reset();
-
- for (int it = HistoryMessage::Chat; it <= HistoryMessage::PrivateMessage; it++) {
- HistoryMessage::Type type = static_cast<HistoryMessage::Type>(it);
-
- contacts_[type] = historyController_->getContacts(selfJID_, type, keyword);
-
- for (ContactsMap::const_iterator contact = contacts_[type].begin(); contact != contacts_[type].end(); contact++) {
- const JID& jid = contact->first;
- std::string nick;
- if (type == HistoryMessage::PrivateMessage) {
- nick = jid.toString();
- }
- else {
- nick = nickResolver_->jidToNick(jid);
- }
- roster_->addContact(jid, jid, nick, category[type], avatarManager_->getAvatarPath(jid));
-
- Presence::ref presence = getPresence(jid, type == HistoryMessage::Groupchat);
-
- if (presence.get()) {
- roster_->applyOnItem(SetPresence(presence, JID::WithoutResource), jid);
- }
- }
- }
+ reset();
+
+ for (int it = HistoryMessage::Chat; it <= HistoryMessage::PrivateMessage; it++) {
+ HistoryMessage::Type type = static_cast<HistoryMessage::Type>(it);
+
+ contacts_[type] = historyController_->getContacts(selfJID_, type, keyword);
+
+ for (ContactsMap::const_iterator contact = contacts_[type].begin(); contact != contacts_[type].end(); contact++) {
+ const JID& jid = contact->first;
+ std::string nick;
+ if (type == HistoryMessage::PrivateMessage) {
+ nick = jid.toString();
+ }
+ else {
+ nick = nickResolver_->jidToNick(jid);
+ }
+ roster_->addContact(jid, jid, nick, category[type], avatarManager_->getAvatarPath(jid));
+
+ Presence::ref presence = getPresence(jid, type == HistoryMessage::Groupchat);
+
+ if (presence.get()) {
+ roster_->applyOnItem(SetPresence(presence, JID::WithoutResource), jid);
+ }
+ }
+ }
}
void HistoryViewController::handleScrollReachedTop(const boost::gregorian::date& date) {
- if (!selectedItem_) {
- return;
- }
+ if (!selectedItem_) {
+ return;
+ }
- std::vector<HistoryMessage> messages = historyController_->getMessagesFromPreviousDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromPreviousDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
- foreach (const HistoryMessage& message, messages) {
- addNewMessage(message, true);
- }
- historyWindow_->resetConversationViewTopInsertPoint();
+ foreach (const HistoryMessage& message, messages) {
+ addNewMessage(message, true);
+ }
+ historyWindow_->resetConversationViewTopInsertPoint();
}
void HistoryViewController::handleScrollReachedBottom(const boost::gregorian::date& date) {
- if (!selectedItem_) {
- return;
- }
+ if (!selectedItem_) {
+ return;
+ }
- std::vector<HistoryMessage> messages = historyController_->getMessagesFromNextDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromNextDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
- foreach (const HistoryMessage& message, messages) {
- addNewMessage(message, false);
- }
+ foreach (const HistoryMessage& message, messages) {
+ addNewMessage(message, false);
+ }
}
void HistoryViewController::handleNextButtonClicked() {
- if (!selectedItem_) {
- return;
- }
+ if (!selectedItem_) {
+ return;
+ }
- std::set<boost::gregorian::date>::iterator date = contacts_[selectedItemType_][selectedItem_->getJID()].find(currentResultDate_);
+ std::set<boost::gregorian::date>::iterator date = contacts_[selectedItemType_][selectedItem_->getJID()].find(currentResultDate_);
- if (*date == *contacts_[selectedItemType_][selectedItem_->getJID()].rbegin()) {
- return;
- }
+ if (*date == *contacts_[selectedItemType_][selectedItem_->getJID()].rbegin()) {
+ return;
+ }
- historyWindow_->resetConversationView();
- currentResultDate_ = *(++date);
- std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
- historyWindow_->setDate(currentResultDate_);
+ historyWindow_->resetConversationView();
+ currentResultDate_ = *(++date);
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
+ historyWindow_->setDate(currentResultDate_);
- foreach (const HistoryMessage& message, messages) {
- addNewMessage(message, false);
- }
+ foreach (const HistoryMessage& message, messages) {
+ addNewMessage(message, false);
+ }
}
void HistoryViewController::handlePreviousButtonClicked() {
- if (!selectedItem_) {
- return;
- }
+ if (!selectedItem_) {
+ return;
+ }
- std::set<boost::gregorian::date>::iterator date = contacts_[selectedItemType_][selectedItem_->getJID()].find(currentResultDate_);
+ std::set<boost::gregorian::date>::iterator date = contacts_[selectedItemType_][selectedItem_->getJID()].find(currentResultDate_);
- if (date == contacts_[selectedItemType_][selectedItem_->getJID()].begin()) {
- return;
- }
+ if (date == contacts_[selectedItemType_][selectedItem_->getJID()].begin()) {
+ return;
+ }
- historyWindow_->resetConversationView();
- currentResultDate_ = *(--date);
- std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
- historyWindow_->setDate(currentResultDate_);
+ historyWindow_->resetConversationView();
+ currentResultDate_ = *(--date);
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
+ historyWindow_->setDate(currentResultDate_);
- foreach (const HistoryMessage& message, messages) {
- addNewMessage(message, false);
- }
+ foreach (const HistoryMessage& message, messages) {
+ addNewMessage(message, false);
+ }
}
void HistoryViewController::reset() {
- roster_->removeAll();
- contacts_.clear();
- selectedItem_ = NULL;
- historyWindow_->resetConversationView();
+ roster_->removeAll();
+ contacts_.clear();
+ selectedItem_ = NULL;
+ historyWindow_->resetConversationView();
}
void HistoryViewController::handleCalendarClicked(const boost::gregorian::date& date) {
- if (!selectedItem_) {
- return;
- }
-
- boost::gregorian::date newDate;
- if (contacts_[selectedItemType_][selectedItem_->getJID()].count(date)) {
- newDate = date;
- }
- else if (date < currentResultDate_) {
- foreach(const boost::gregorian::date& current, contacts_[selectedItemType_][selectedItem_->getJID()]) {
- if (current > date) {
- newDate = current;
- break;
- }
- }
- }
- else {
- reverse_foreach(const boost::gregorian::date& current, contacts_[selectedItemType_][selectedItem_->getJID()]) {
- if (current < date) {
- newDate = current;
- break;
- }
- }
- }
-
- historyWindow_->setDate(newDate);
- if (newDate == currentResultDate_) {
- return;
- }
- currentResultDate_ = newDate;
- historyWindow_->resetConversationView();
-
- std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
- historyWindow_->setDate(currentResultDate_);
-
- foreach (const HistoryMessage& message, messages) {
- addNewMessage(message, false);
- }
+ if (!selectedItem_) {
+ return;
+ }
+
+ boost::gregorian::date newDate;
+ if (contacts_[selectedItemType_][selectedItem_->getJID()].count(date)) {
+ newDate = date;
+ }
+ else if (date < currentResultDate_) {
+ foreach(const boost::gregorian::date& current, contacts_[selectedItemType_][selectedItem_->getJID()]) {
+ if (current > date) {
+ newDate = current;
+ break;
+ }
+ }
+ }
+ else {
+ reverse_foreach(const boost::gregorian::date& current, contacts_[selectedItemType_][selectedItem_->getJID()]) {
+ if (current < date) {
+ newDate = current;
+ break;
+ }
+ }
+ }
+
+ historyWindow_->setDate(newDate);
+ if (newDate == currentResultDate_) {
+ return;
+ }
+ currentResultDate_ = newDate;
+ historyWindow_->resetConversationView();
+
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
+ historyWindow_->setDate(currentResultDate_);
+
+ foreach (const HistoryMessage& message, messages) {
+ addNewMessage(message, false);
+ }
}
void HistoryViewController::handlePresenceChanged(Presence::ref presence) {
- JID jid = presence->getFrom();
-
- if (contacts_[HistoryMessage::Chat].count(jid.toBare())) {
- roster_->applyOnItems(SetPresence(presence, JID::WithoutResource));
- return;
- }
-
- if (contacts_[HistoryMessage::Groupchat].count(jid.toBare())) {
- Presence::ref availablePresence = boost::make_shared<Presence>(Presence());
- availablePresence->setFrom(jid.toBare());
- roster_->applyOnItems(SetPresence(availablePresence, JID::WithResource));
- }
-
- if (contacts_[HistoryMessage::PrivateMessage].count(jid)) {
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- }
+ JID jid = presence->getFrom();
+
+ if (contacts_[HistoryMessage::Chat].count(jid.toBare())) {
+ roster_->applyOnItems(SetPresence(presence, JID::WithoutResource));
+ return;
+ }
+
+ if (contacts_[HistoryMessage::Groupchat].count(jid.toBare())) {
+ Presence::ref availablePresence = boost::make_shared<Presence>(Presence());
+ availablePresence->setFrom(jid.toBare());
+ roster_->applyOnItems(SetPresence(availablePresence, JID::WithResource));
+ }
+
+ if (contacts_[HistoryMessage::PrivateMessage].count(jid)) {
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+ }
}
void HistoryViewController::handleAvatarChanged(const JID& jid) {
- roster_->applyOnItems(SetAvatar(jid, avatarManager_->getAvatarPath(jid)));
+ roster_->applyOnItems(SetAvatar(jid, avatarManager_->getAvatarPath(jid)));
}
Presence::ref HistoryViewController::getPresence(const JID& jid, bool isMUC) {
- if (jid.isBare() && !isMUC) {
- return presenceOracle_->getHighestPriorityPresence(jid);
- }
+ if (jid.isBare() && !isMUC) {
+ return presenceOracle_->getHighestPriorityPresence(jid);
+ }
- std::vector<Presence::ref> mucPresence = presenceOracle_->getAllPresence(jid.toBare());
+ std::vector<Presence::ref> mucPresence = presenceOracle_->getAllPresence(jid.toBare());
- if (isMUC && !mucPresence.empty()) {
- Presence::ref presence = boost::make_shared<Presence>(Presence());
- presence->setFrom(jid);
- return presence;
- }
+ if (isMUC && !mucPresence.empty()) {
+ Presence::ref presence = boost::make_shared<Presence>(Presence());
+ presence->setFrom(jid);
+ return presence;
+ }
- foreach (Presence::ref presence, mucPresence) {
- if (presence.get() && presence->getFrom() == jid) {
- return presence;
- }
- }
+ foreach (Presence::ref presence, mucPresence) {
+ if (presence.get() && presence->getFrom() == jid) {
+ return presence;
+ }
+ }
- return Presence::create();
+ return Presence::create();
}
}
diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h
index b388160..463ee06 100644
--- a/Swift/Controllers/HistoryViewController.h
+++ b/Swift/Controllers/HistoryViewController.h
@@ -25,51 +25,51 @@
#include <Swift/Controllers/UIEvents/UIEventStream.h>
namespace Swift {
- class HistoryWindowFactory;
- class HistoryWindow;
- class Roster;
- class RosterItem;
- class ContactRosterItem;
- class HistoryController;
- class NickResolver;
- class AvatarManager;
+ class HistoryWindowFactory;
+ class HistoryWindow;
+ class Roster;
+ class RosterItem;
+ class ContactRosterItem;
+ class HistoryController;
+ class NickResolver;
+ class AvatarManager;
- class HistoryViewController {
- public:
- HistoryViewController(const JID& selfJID, UIEventStream* uiEventStream, HistoryController* historyController, NickResolver* nickResolver, AvatarManager* avatarManager, PresenceOracle* presenceOracle, HistoryWindowFactory* historyWindowFactory);
- ~HistoryViewController();
+ class HistoryViewController {
+ public:
+ HistoryViewController(const JID& selfJID, UIEventStream* uiEventStream, HistoryController* historyController, NickResolver* nickResolver, AvatarManager* avatarManager, PresenceOracle* presenceOracle, HistoryWindowFactory* historyWindowFactory);
+ ~HistoryViewController();
- private:
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void handleSelectedContactChanged(RosterItem* item);
- void handleNewMessage(const HistoryMessage& message);
- void handleReturnPressed(const std::string& keyword);
- void handleScrollReachedTop(const boost::gregorian::date& date);
- void handleScrollReachedBottom(const boost::gregorian::date& date);
- void handlePreviousButtonClicked();
- void handleNextButtonClicked();
- void handleCalendarClicked(const boost::gregorian::date& date);
- void handlePresenceChanged(Presence::ref presence);
- void handleAvatarChanged(const JID& jid);
+ private:
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleSelectedContactChanged(RosterItem* item);
+ void handleNewMessage(const HistoryMessage& message);
+ void handleReturnPressed(const std::string& keyword);
+ void handleScrollReachedTop(const boost::gregorian::date& date);
+ void handleScrollReachedBottom(const boost::gregorian::date& date);
+ void handlePreviousButtonClicked();
+ void handleNextButtonClicked();
+ void handleCalendarClicked(const boost::gregorian::date& date);
+ void handlePresenceChanged(Presence::ref presence);
+ void handleAvatarChanged(const JID& jid);
- void addNewMessage(const HistoryMessage& message, bool addAtTheTop);
- void reset();
- Presence::ref getPresence(const JID& jid, bool isMUC);
+ void addNewMessage(const HistoryMessage& message, bool addAtTheTop);
+ void reset();
+ Presence::ref getPresence(const JID& jid, bool isMUC);
- private:
- JID selfJID_;
- UIEventStream* uiEventStream_;
- HistoryController* historyController_;
- NickResolver* nickResolver_;
- AvatarManager* avatarManager_;
- PresenceOracle* presenceOracle_;
- HistoryWindowFactory* historyWindowFactory_;
- HistoryWindow* historyWindow_;
- Roster* roster_;
+ private:
+ JID selfJID_;
+ UIEventStream* uiEventStream_;
+ HistoryController* historyController_;
+ NickResolver* nickResolver_;
+ AvatarManager* avatarManager_;
+ PresenceOracle* presenceOracle_;
+ HistoryWindowFactory* historyWindowFactory_;
+ HistoryWindow* historyWindow_;
+ Roster* roster_;
- std::map<HistoryMessage::Type, ContactsMap> contacts_;
- ContactRosterItem* selectedItem_;
- HistoryMessage::Type selectedItemType_;
- boost::gregorian::date currentResultDate_;
- };
+ std::map<HistoryMessage::Type, ContactsMap> contacts_;
+ ContactRosterItem* selectedItem_;
+ HistoryMessage::Type selectedItemType_;
+ boost::gregorian::date currentResultDate_;
+ };
}
diff --git a/Swift/Controllers/Intl.h b/Swift/Controllers/Intl.h
index 386696a..c599493 100644
--- a/Swift/Controllers/Intl.h
+++ b/Swift/Controllers/Intl.h
@@ -8,4 +8,4 @@
#include <Swift/Controllers/Translator.h>
#define QT_TRANSLATE_NOOP(context, text) \
- Swift::Translator::getInstance()->translate(text, context)
+ Swift::Translator::getInstance()->translate(text, context)
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 9f61b2b..b48059c 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -99,749 +99,749 @@ static const std::string CLIENT_NODE = "http://swift.im";
MainController::MainController(
- EventLoop* eventLoop,
- NetworkFactories* networkFactories,
- UIFactory* uiFactories,
- SettingsProvider* settings,
- SystemTray* systemTray,
- SoundPlayer* soundPlayer,
- StoragesFactory* storagesFactory,
- CertificateStorageFactory* certificateStorageFactory,
- Dock* dock,
- Notifier* notifier,
- URIHandler* uriHandler,
- IdleDetector* idleDetector,
- const std::map<std::string, std::string>& emoticons,
- bool useDelayForLatency) :
- eventLoop_(eventLoop),
- networkFactories_(networkFactories),
- uiFactory_(uiFactories),
- storagesFactory_(storagesFactory),
- certificateStorageFactory_(certificateStorageFactory),
- settings_(settings),
- uriHandler_(uriHandler),
- idleDetector_(idleDetector),
- loginWindow_(NULL) ,
- useDelayForLatency_(useDelayForLatency),
- ftOverview_(NULL),
- emoticons_(emoticons) {
- storages_ = NULL;
- certificateStorage_ = NULL;
- certificateTrustChecker_ = NULL;
- statusTracker_ = NULL;
- presenceNotifier_ = NULL;
- eventNotifier_ = NULL;
- rosterController_ = NULL;
- chatsManager_ = NULL;
- historyController_ = NULL;
- historyViewController_ = NULL;
- eventWindowController_ = NULL;
- profileController_ = NULL;
- blockListController_ = NULL;
- showProfileController_ = NULL;
- contactEditController_ = NULL;
- userSearchControllerChat_ = NULL;
- userSearchControllerAdd_ = NULL;
- userSearchControllerInvite_ = NULL;
- contactsFromRosterProvider_ = NULL;
- contactSuggesterWithoutRoster_ = NULL;
- contactSuggesterWithRoster_ = NULL;
- whiteboardManager_ = NULL;
- adHocManager_ = NULL;
- quitRequested_ = false;
- clientInitialized_ = false;
- offlineRequested_ = false;
-
- timeBeforeNextReconnect_ = -1;
- dock_ = dock;
- uiEventStream_ = new UIEventStream();
-
- notifier_ = new TogglableNotifier(notifier);
- notifier_->setPersistentEnabled(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
- eventController_ = new EventController();
- eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1));
-
- systemTrayController_ = new SystemTrayController(eventController_, systemTray);
- loginWindow_ = uiFactory_->createLoginWindow(uiEventStream_);
- loginWindow_->setShowNotificationToggle(!notifier->isExternallyConfigured());
-
- highlightManager_ = new HighlightManager(settings_);
- highlightEditorController_ = new HighlightEditorController(uiEventStream_, uiFactory_, highlightManager_);
-
- soundEventController_ = new SoundEventController(eventController_, soundPlayer, settings, highlightManager_);
-
- xmppURIController_ = new XMPPURIController(uriHandler_, uiEventStream_);
-
- std::string selectedLoginJID = settings_->getSetting(SettingConstants::LAST_LOGIN_JID);
- bool loginAutomatically = settings_->getSetting(SettingConstants::LOGIN_AUTOMATICALLY);
- std::string cachedPassword;
- std::string cachedCertificate;
- ClientOptions cachedOptions;
- bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);
- if (!eagle) {
- foreach (std::string profile, settings->getAvailableProfiles()) {
- ProfileSettingsProvider profileSettings(profile, settings);
- std::string password = profileSettings.getStringSetting("pass");
- std::string certificate = profileSettings.getStringSetting("certificate");
- std::string jid = profileSettings.getStringSetting("jid");
- ClientOptions clientOptions = parseClientOptions(profileSettings.getStringSetting("options"));
+ EventLoop* eventLoop,
+ NetworkFactories* networkFactories,
+ UIFactory* uiFactories,
+ SettingsProvider* settings,
+ SystemTray* systemTray,
+ SoundPlayer* soundPlayer,
+ StoragesFactory* storagesFactory,
+ CertificateStorageFactory* certificateStorageFactory,
+ Dock* dock,
+ Notifier* notifier,
+ URIHandler* uriHandler,
+ IdleDetector* idleDetector,
+ const std::map<std::string, std::string>& emoticons,
+ bool useDelayForLatency) :
+ eventLoop_(eventLoop),
+ networkFactories_(networkFactories),
+ uiFactory_(uiFactories),
+ storagesFactory_(storagesFactory),
+ certificateStorageFactory_(certificateStorageFactory),
+ settings_(settings),
+ uriHandler_(uriHandler),
+ idleDetector_(idleDetector),
+ loginWindow_(NULL) ,
+ useDelayForLatency_(useDelayForLatency),
+ ftOverview_(NULL),
+ emoticons_(emoticons) {
+ storages_ = NULL;
+ certificateStorage_ = NULL;
+ certificateTrustChecker_ = NULL;
+ statusTracker_ = NULL;
+ presenceNotifier_ = NULL;
+ eventNotifier_ = NULL;
+ rosterController_ = NULL;
+ chatsManager_ = NULL;
+ historyController_ = NULL;
+ historyViewController_ = NULL;
+ eventWindowController_ = NULL;
+ profileController_ = NULL;
+ blockListController_ = NULL;
+ showProfileController_ = NULL;
+ contactEditController_ = NULL;
+ userSearchControllerChat_ = NULL;
+ userSearchControllerAdd_ = NULL;
+ userSearchControllerInvite_ = NULL;
+ contactsFromRosterProvider_ = NULL;
+ contactSuggesterWithoutRoster_ = NULL;
+ contactSuggesterWithRoster_ = NULL;
+ whiteboardManager_ = NULL;
+ adHocManager_ = NULL;
+ quitRequested_ = false;
+ clientInitialized_ = false;
+ offlineRequested_ = false;
+
+ timeBeforeNextReconnect_ = -1;
+ dock_ = dock;
+ uiEventStream_ = new UIEventStream();
+
+ notifier_ = new TogglableNotifier(notifier);
+ notifier_->setPersistentEnabled(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
+ eventController_ = new EventController();
+ eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1));
+
+ systemTrayController_ = new SystemTrayController(eventController_, systemTray);
+ loginWindow_ = uiFactory_->createLoginWindow(uiEventStream_);
+ loginWindow_->setShowNotificationToggle(!notifier->isExternallyConfigured());
+
+ highlightManager_ = new HighlightManager(settings_);
+ highlightEditorController_ = new HighlightEditorController(uiEventStream_, uiFactory_, highlightManager_);
+
+ soundEventController_ = new SoundEventController(eventController_, soundPlayer, settings, highlightManager_);
+
+ xmppURIController_ = new XMPPURIController(uriHandler_, uiEventStream_);
+
+ std::string selectedLoginJID = settings_->getSetting(SettingConstants::LAST_LOGIN_JID);
+ bool loginAutomatically = settings_->getSetting(SettingConstants::LOGIN_AUTOMATICALLY);
+ std::string cachedPassword;
+ std::string cachedCertificate;
+ ClientOptions cachedOptions;
+ bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);
+ if (!eagle) {
+ foreach (std::string profile, settings->getAvailableProfiles()) {
+ ProfileSettingsProvider profileSettings(profile, settings);
+ std::string password = profileSettings.getStringSetting("pass");
+ std::string certificate = profileSettings.getStringSetting("certificate");
+ std::string jid = profileSettings.getStringSetting("jid");
+ ClientOptions clientOptions = parseClientOptions(profileSettings.getStringSetting("options"));
#ifdef SWIFTEN_PLATFORM_WIN32
- clientOptions.singleSignOn = settings_->getSetting(SettingConstants::SINGLE_SIGN_ON);
+ clientOptions.singleSignOn = settings_->getSetting(SettingConstants::SINGLE_SIGN_ON);
#endif
- loginWindow_->addAvailableAccount(jid, password, certificate, clientOptions);
- if (jid == selectedLoginJID) {
- cachedPassword = password;
- cachedCertificate = certificate;
- cachedOptions = clientOptions;
- }
- }
- loginWindow_->selectUser(selectedLoginJID);
- loginWindow_->setLoginAutomatically(loginAutomatically);
- }
+ loginWindow_->addAvailableAccount(jid, password, certificate, clientOptions);
+ if (jid == selectedLoginJID) {
+ cachedPassword = password;
+ cachedCertificate = certificate;
+ cachedOptions = clientOptions;
+ }
+ }
+ loginWindow_->selectUser(selectedLoginJID);
+ loginWindow_->setLoginAutomatically(loginAutomatically);
+ }
- loginWindow_->onLoginRequest.connect(boost::bind(&MainController::handleLoginRequest, this, _1, _2, _3, _4, _5, _6, _7));
- loginWindow_->onPurgeSavedLoginRequest.connect(boost::bind(&MainController::handlePurgeSavedLoginRequest, this, _1));
- loginWindow_->onCancelLoginRequest.connect(boost::bind(&MainController::handleCancelLoginRequest, this));
- loginWindow_->onQuitRequest.connect(boost::bind(&MainController::handleQuitRequest, this));
+ loginWindow_->onLoginRequest.connect(boost::bind(&MainController::handleLoginRequest, this, _1, _2, _3, _4, _5, _6, _7));
+ loginWindow_->onPurgeSavedLoginRequest.connect(boost::bind(&MainController::handlePurgeSavedLoginRequest, this, _1));
+ loginWindow_->onCancelLoginRequest.connect(boost::bind(&MainController::handleCancelLoginRequest, this));
+ loginWindow_->onQuitRequest.connect(boost::bind(&MainController::handleQuitRequest, this));
- idleDetector_->setIdleTimeSeconds(settings->getSetting(SettingConstants::IDLE_TIMEOUT));
- idleDetector_->onIdleChanged.connect(boost::bind(&MainController::handleInputIdleChanged, this, _1));
+ idleDetector_->setIdleTimeSeconds(settings->getSetting(SettingConstants::IDLE_TIMEOUT));
+ idleDetector_->onIdleChanged.connect(boost::bind(&MainController::handleInputIdleChanged, this, _1));
- xmlConsoleController_ = new XMLConsoleController(uiEventStream_, uiFactory_);
+ xmlConsoleController_ = new XMLConsoleController(uiEventStream_, uiFactory_);
- fileTransferListController_ = new FileTransferListController(uiEventStream_, uiFactory_);
+ fileTransferListController_ = new FileTransferListController(uiEventStream_, uiFactory_);
- settings_->onSettingChanged.connect(boost::bind(&MainController::handleSettingChanged, this, _1));
+ settings_->onSettingChanged.connect(boost::bind(&MainController::handleSettingChanged, this, _1));
- if (loginAutomatically) {
- profileSettings_ = new ProfileSettingsProvider(selectedLoginJID, settings_);
- /* FIXME: deal with autologin with a cert*/
- handleLoginRequest(selectedLoginJID, cachedPassword, cachedCertificate, CertificateWithKey::ref(), cachedOptions, true, true);
- } else {
- profileSettings_ = NULL;
- }
+ if (loginAutomatically) {
+ profileSettings_ = new ProfileSettingsProvider(selectedLoginJID, settings_);
+ /* FIXME: deal with autologin with a cert*/
+ handleLoginRequest(selectedLoginJID, cachedPassword, cachedCertificate, CertificateWithKey::ref(), cachedOptions, true, true);
+ } else {
+ profileSettings_ = NULL;
+ }
}
MainController::~MainController() {
- idleDetector_->onIdleChanged.disconnect(boost::bind(&MainController::handleInputIdleChanged, this, _1));
-
- purgeCachedCredentials();
- //setManagersOffline();
- eventController_->disconnectAll();
-
- resetClient();
- delete highlightEditorController_;
- delete highlightManager_;
- delete fileTransferListController_;
- delete xmlConsoleController_;
- delete xmppURIController_;
- delete soundEventController_;
- delete systemTrayController_;
- delete eventController_;
- delete notifier_;
- delete uiEventStream_;
+ idleDetector_->onIdleChanged.disconnect(boost::bind(&MainController::handleInputIdleChanged, this, _1));
+
+ purgeCachedCredentials();
+ //setManagersOffline();
+ eventController_->disconnectAll();
+
+ resetClient();
+ delete highlightEditorController_;
+ delete highlightManager_;
+ delete fileTransferListController_;
+ delete xmlConsoleController_;
+ delete xmppURIController_;
+ delete soundEventController_;
+ delete systemTrayController_;
+ delete eventController_;
+ delete notifier_;
+ delete uiEventStream_;
}
void MainController::purgeCachedCredentials() {
- safeClear(password_);
+ safeClear(password_);
}
void MainController::resetClient() {
- purgeCachedCredentials();
- resetCurrentError();
- resetPendingReconnects();
- vCardPhotoHash_.clear();
- delete contactEditController_;
- contactEditController_ = NULL;
- delete profileController_;
- profileController_ = NULL;
- delete showProfileController_;
- showProfileController_ = NULL;
- delete eventWindowController_;
- eventWindowController_ = NULL;
- delete chatsManager_;
- chatsManager_ = NULL;
+ purgeCachedCredentials();
+ resetCurrentError();
+ resetPendingReconnects();
+ vCardPhotoHash_.clear();
+ delete contactEditController_;
+ contactEditController_ = NULL;
+ delete profileController_;
+ profileController_ = NULL;
+ delete showProfileController_;
+ showProfileController_ = NULL;
+ delete eventWindowController_;
+ eventWindowController_ = NULL;
+ delete chatsManager_;
+ chatsManager_ = NULL;
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- delete historyViewController_;
- historyViewController_ = NULL;
- delete historyController_;
- historyController_ = NULL;
+ delete historyViewController_;
+ historyViewController_ = NULL;
+ delete historyController_;
+ historyController_ = NULL;
#endif
- fileTransferListController_->setFileTransferOverview(NULL);
- delete ftOverview_;
- ftOverview_ = NULL;
- delete blockListController_;
- blockListController_ = NULL;
- delete rosterController_;
- rosterController_ = NULL;
- delete eventNotifier_;
- eventNotifier_ = NULL;
- delete presenceNotifier_;
- presenceNotifier_ = NULL;
- delete certificateTrustChecker_;
- certificateTrustChecker_ = NULL;
- delete certificateStorage_;
- certificateStorage_ = NULL;
- delete storages_;
- storages_ = NULL;
- delete statusTracker_;
- statusTracker_ = NULL;
- delete profileSettings_;
- profileSettings_ = NULL;
- delete userSearchControllerChat_;
- userSearchControllerChat_ = NULL;
- delete userSearchControllerAdd_;
- userSearchControllerAdd_ = NULL;
- delete userSearchControllerInvite_;
- userSearchControllerInvite_ = NULL;
- delete contactSuggesterWithoutRoster_;
- contactSuggesterWithoutRoster_ = NULL;
- delete contactSuggesterWithRoster_;
- contactSuggesterWithRoster_ = NULL;
- delete contactsFromRosterProvider_;
- contactsFromRosterProvider_ = NULL;
- delete adHocManager_;
- adHocManager_ = NULL;
- delete whiteboardManager_;
- whiteboardManager_ = NULL;
- clientInitialized_ = false;
+ fileTransferListController_->setFileTransferOverview(NULL);
+ delete ftOverview_;
+ ftOverview_ = NULL;
+ delete blockListController_;
+ blockListController_ = NULL;
+ delete rosterController_;
+ rosterController_ = NULL;
+ delete eventNotifier_;
+ eventNotifier_ = NULL;
+ delete presenceNotifier_;
+ presenceNotifier_ = NULL;
+ delete certificateTrustChecker_;
+ certificateTrustChecker_ = NULL;
+ delete certificateStorage_;
+ certificateStorage_ = NULL;
+ delete storages_;
+ storages_ = NULL;
+ delete statusTracker_;
+ statusTracker_ = NULL;
+ delete profileSettings_;
+ profileSettings_ = NULL;
+ delete userSearchControllerChat_;
+ userSearchControllerChat_ = NULL;
+ delete userSearchControllerAdd_;
+ userSearchControllerAdd_ = NULL;
+ delete userSearchControllerInvite_;
+ userSearchControllerInvite_ = NULL;
+ delete contactSuggesterWithoutRoster_;
+ contactSuggesterWithoutRoster_ = NULL;
+ delete contactSuggesterWithRoster_;
+ contactSuggesterWithRoster_ = NULL;
+ delete contactsFromRosterProvider_;
+ contactsFromRosterProvider_ = NULL;
+ delete adHocManager_;
+ adHocManager_ = NULL;
+ delete whiteboardManager_;
+ whiteboardManager_ = NULL;
+ clientInitialized_ = false;
}
void MainController::handleSettingChanged(const std::string& settingPath) {
- if (settingPath == SettingConstants::SHOW_NOTIFICATIONS.getKey()) {
- notifier_->setPersistentEnabled(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
- }
+ if (settingPath == SettingConstants::SHOW_NOTIFICATIONS.getKey()) {
+ notifier_->setPersistentEnabled(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
+ }
}
void MainController::resetPendingReconnects() {
- timeBeforeNextReconnect_ = -1;
- if (reconnectTimer_) {
- reconnectTimer_->stop();
- reconnectTimer_.reset();
- }
- resetCurrentError();
+ timeBeforeNextReconnect_ = -1;
+ if (reconnectTimer_) {
+ reconnectTimer_->stop();
+ reconnectTimer_.reset();
+ }
+ resetCurrentError();
}
void MainController::resetCurrentError() {
- if (lastDisconnectError_) {
- lastDisconnectError_->conclude();
- lastDisconnectError_ = boost::shared_ptr<ErrorEvent>();
- }
+ if (lastDisconnectError_) {
+ lastDisconnectError_->conclude();
+ lastDisconnectError_ = boost::shared_ptr<ErrorEvent>();
+ }
}
void MainController::handleConnected() {
- boundJID_ = client_->getJID();
- resetCurrentError();
- resetPendingReconnects();
-
- if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
- purgeCachedCredentials();
- }
-
- bool freshLogin = rosterController_ == NULL;
- myStatusLooksOnline_ = true;
- if (freshLogin) {
- profileController_ = new ProfileController(client_->getVCardManager(), uiFactory_, uiEventStream_);
- showProfileController_ = new ShowProfileController(client_->getVCardManager(), uiFactory_, uiEventStream_);
- ftOverview_ = new FileTransferOverview(client_->getFileTransferManager());
- fileTransferListController_->setFileTransferOverview(ftOverview_);
- rosterController_ = new RosterController(boundJID_, client_->getRoster(), client_->getAvatarManager(), uiFactory_, client_->getNickManager(), client_->getNickResolver(), client_->getPresenceOracle(), client_->getSubscriptionManager(), eventController_, uiEventStream_, client_->getIQRouter(), settings_, client_->getEntityCapsProvider(), ftOverview_, client_->getClientBlockListManager(), client_->getVCardManager());
- rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2));
- rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this));
- rosterController_->getWindow()->onShowCertificateRequest.connect(boost::bind(&MainController::handleShowCertificateRequest, this));
-
- blockListController_ = new BlockListController(client_->getClientBlockListManager(), uiEventStream_, uiFactory_, eventController_);
-
- contactEditController_ = new ContactEditController(rosterController_, client_->getVCardManager(), uiFactory_, uiEventStream_);
- whiteboardManager_ = new WhiteboardManager(uiFactory_, uiEventStream_, client_->getNickResolver(), client_->getWhiteboardSessionManager());
-
- /* Doing this early as an ordering fix. Various things later will
- * want to have the user's nick available and this means it will
- * be before they receive stanzas that need it (e.g. bookmarks).*/
- client_->getVCardManager()->requestOwnVCard();
-
- contactSuggesterWithoutRoster_ = new ContactSuggester();
- contactSuggesterWithRoster_ = new ContactSuggester();
-
- userSearchControllerInvite_ = new UserSearchController(UserSearchController::InviteToChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
+ boundJID_ = client_->getJID();
+ resetCurrentError();
+ resetPendingReconnects();
+
+ if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
+ purgeCachedCredentials();
+ }
+
+ bool freshLogin = rosterController_ == NULL;
+ myStatusLooksOnline_ = true;
+ if (freshLogin) {
+ profileController_ = new ProfileController(client_->getVCardManager(), uiFactory_, uiEventStream_);
+ showProfileController_ = new ShowProfileController(client_->getVCardManager(), uiFactory_, uiEventStream_);
+ ftOverview_ = new FileTransferOverview(client_->getFileTransferManager());
+ fileTransferListController_->setFileTransferOverview(ftOverview_);
+ rosterController_ = new RosterController(boundJID_, client_->getRoster(), client_->getAvatarManager(), uiFactory_, client_->getNickManager(), client_->getNickResolver(), client_->getPresenceOracle(), client_->getSubscriptionManager(), eventController_, uiEventStream_, client_->getIQRouter(), settings_, client_->getEntityCapsProvider(), ftOverview_, client_->getClientBlockListManager(), client_->getVCardManager());
+ rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2));
+ rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this));
+ rosterController_->getWindow()->onShowCertificateRequest.connect(boost::bind(&MainController::handleShowCertificateRequest, this));
+
+ blockListController_ = new BlockListController(client_->getClientBlockListManager(), uiEventStream_, uiFactory_, eventController_);
+
+ contactEditController_ = new ContactEditController(rosterController_, client_->getVCardManager(), uiFactory_, uiEventStream_);
+ whiteboardManager_ = new WhiteboardManager(uiFactory_, uiEventStream_, client_->getNickResolver(), client_->getWhiteboardSessionManager());
+
+ /* Doing this early as an ordering fix. Various things later will
+ * want to have the user's nick available and this means it will
+ * be before they receive stanzas that need it (e.g. bookmarks).*/
+ client_->getVCardManager()->requestOwnVCard();
+
+ contactSuggesterWithoutRoster_ = new ContactSuggester();
+ contactSuggesterWithRoster_ = new ContactSuggester();
+
+ userSearchControllerInvite_ = new UserSearchController(UserSearchController::InviteToChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- historyController_ = new HistoryController(storages_->getHistoryStorage());
- historyViewController_ = new HistoryViewController(jid_, uiEventStream_, historyController_, client_->getNickResolver(), client_->getAvatarManager(), client_->getPresenceOracle(), uiFactory_);
- chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, historyController_, whiteboardManager_, highlightManager_, client_->getClientBlockListManager(), emoticons_, client_->getVCardManager());
+ historyController_ = new HistoryController(storages_->getHistoryStorage());
+ historyViewController_ = new HistoryViewController(jid_, uiEventStream_, historyController_, client_->getNickResolver(), client_->getAvatarManager(), client_->getPresenceOracle(), uiFactory_);
+ chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, historyController_, whiteboardManager_, highlightManager_, client_->getClientBlockListManager(), emoticons_, client_->getVCardManager());
#else
- chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, NULL, whiteboardManager_, highlightManager_, client_->getClientBlockListManager(), emoticons_, client_->getVCardManager());
+ chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, NULL, whiteboardManager_, highlightManager_, client_->getClientBlockListManager(), emoticons_, client_->getVCardManager());
#endif
- contactsFromRosterProvider_ = new ContactsFromXMPPRoster(client_->getRoster(), client_->getAvatarManager(), client_->getPresenceOracle());
- contactSuggesterWithoutRoster_->addContactProvider(chatsManager_);
- contactSuggesterWithRoster_->addContactProvider(chatsManager_);
- contactSuggesterWithRoster_->addContactProvider(contactsFromRosterProvider_);
- highlightEditorController_->setContactSuggester(contactSuggesterWithoutRoster_);
+ contactsFromRosterProvider_ = new ContactsFromXMPPRoster(client_->getRoster(), client_->getAvatarManager(), client_->getPresenceOracle());
+ contactSuggesterWithoutRoster_->addContactProvider(chatsManager_);
+ contactSuggesterWithRoster_->addContactProvider(chatsManager_);
+ contactSuggesterWithRoster_->addContactProvider(contactsFromRosterProvider_);
+ highlightEditorController_->setContactSuggester(contactSuggesterWithoutRoster_);
- client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1));
- chatsManager_->setAvatarManager(client_->getAvatarManager());
+ client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1));
+ chatsManager_->setAvatarManager(client_->getAvatarManager());
- eventWindowController_ = new EventWindowController(eventController_, uiFactory_);
+ eventWindowController_ = new EventWindowController(eventController_, uiFactory_);
- loginWindow_->morphInto(rosterController_->getWindow());
+ loginWindow_->morphInto(rosterController_->getWindow());
- DiscoInfo discoInfo;
- discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc"));
- discoInfo.addFeature(DiscoInfo::ChatStatesFeature);
- discoInfo.addFeature(DiscoInfo::SecurityLabelsFeature);
- discoInfo.addFeature(DiscoInfo::MessageCorrectionFeature);
+ DiscoInfo discoInfo;
+ discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc"));
+ discoInfo.addFeature(DiscoInfo::ChatStatesFeature);
+ discoInfo.addFeature(DiscoInfo::SecurityLabelsFeature);
+ discoInfo.addFeature(DiscoInfo::MessageCorrectionFeature);
#ifdef SWIFT_EXPERIMENTAL_FT
- discoInfo.addFeature(DiscoInfo::JingleFeature);
- discoInfo.addFeature(DiscoInfo::JingleFTFeature);
- discoInfo.addFeature(DiscoInfo::JingleTransportsIBBFeature);
- discoInfo.addFeature(DiscoInfo::JingleTransportsS5BFeature);
+ discoInfo.addFeature(DiscoInfo::JingleFeature);
+ discoInfo.addFeature(DiscoInfo::JingleFTFeature);
+ discoInfo.addFeature(DiscoInfo::JingleTransportsIBBFeature);
+ discoInfo.addFeature(DiscoInfo::JingleTransportsS5BFeature);
#endif
#ifdef SWIFT_EXPERIMENTAL_WB
- discoInfo.addFeature(DiscoInfo::WhiteboardFeature);
+ discoInfo.addFeature(DiscoInfo::WhiteboardFeature);
#endif
- discoInfo.addFeature(DiscoInfo::MessageDeliveryReceiptsFeature);
- client_->getDiscoManager()->setCapsNode(CLIENT_NODE);
- client_->getDiscoManager()->setDiscoInfo(discoInfo);
-
- userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
- userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithoutRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
- adHocManager_ = new AdHocManager(JID(boundJID_.getDomain()), uiFactory_, client_->getIQRouter(), uiEventStream_, rosterController_->getWindow());
-
- chatsManager_->onImpromptuMUCServiceDiscovered.connect(boost::bind(&UserSearchController::setCanInitiateImpromptuMUC, userSearchControllerChat_, _1));
- }
- loginWindow_->setIsLoggingIn(false);
-
- client_->requestRoster();
-
- GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(JID(boundJID_.getDomain()), client_->getIQRouter());
- discoInfoRequest->onResponse.connect(boost::bind(&MainController::handleServerDiscoInfoResponse, this, _1, _2));
- discoInfoRequest->send();
-
- client_->getVCardManager()->requestOwnVCard();
-
- rosterController_->setJID(boundJID_);
- rosterController_->setEnabled(true);
- rosterController_->getWindow()->setStreamEncryptionStatus(client_->isStreamEncrypted());
- profileController_->setAvailable(true);
- contactEditController_->setAvailable(true);
- /* Send presence later to catch all the incoming presences. */
- sendPresence(statusTracker_->getNextPresence());
-
- /* Enable chats last of all, so rejoining MUCs has the right sent presence */
- assert(chatsManager_);
- chatsManager_->setOnline(true);
- adHocManager_->setOnline(true);
+ discoInfo.addFeature(DiscoInfo::MessageDeliveryReceiptsFeature);
+ client_->getDiscoManager()->setCapsNode(CLIENT_NODE);
+ client_->getDiscoManager()->setDiscoInfo(discoInfo);
+
+ userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
+ userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithoutRoster_, client_->getAvatarManager(), client_->getPresenceOracle(), profileSettings_);
+ adHocManager_ = new AdHocManager(JID(boundJID_.getDomain()), uiFactory_, client_->getIQRouter(), uiEventStream_, rosterController_->getWindow());
+
+ chatsManager_->onImpromptuMUCServiceDiscovered.connect(boost::bind(&UserSearchController::setCanInitiateImpromptuMUC, userSearchControllerChat_, _1));
+ }
+ loginWindow_->setIsLoggingIn(false);
+
+ client_->requestRoster();
+
+ GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(JID(boundJID_.getDomain()), client_->getIQRouter());
+ discoInfoRequest->onResponse.connect(boost::bind(&MainController::handleServerDiscoInfoResponse, this, _1, _2));
+ discoInfoRequest->send();
+
+ client_->getVCardManager()->requestOwnVCard();
+
+ rosterController_->setJID(boundJID_);
+ rosterController_->setEnabled(true);
+ rosterController_->getWindow()->setStreamEncryptionStatus(client_->isStreamEncrypted());
+ profileController_->setAvailable(true);
+ contactEditController_->setAvailable(true);
+ /* Send presence later to catch all the incoming presences. */
+ sendPresence(statusTracker_->getNextPresence());
+
+ /* Enable chats last of all, so rejoining MUCs has the right sent presence */
+ assert(chatsManager_);
+ chatsManager_->setOnline(true);
+ adHocManager_->setOnline(true);
}
void MainController::handleEventQueueLengthChange(int count) {
- dock_->setNumberOfPendingMessages(count);
+ dock_->setNumberOfPendingMessages(count);
}
void MainController::reconnectAfterError() {
- if (reconnectTimer_) {
- reconnectTimer_->stop();
- }
- performLoginFromCachedCredentials();
+ if (reconnectTimer_) {
+ reconnectTimer_->stop();
+ }
+ performLoginFromCachedCredentials();
}
void MainController::handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText) {
- boost::shared_ptr<Presence> presence(new Presence());
- if (show == StatusShow::None) {
- // Note: this is misleading, None doesn't mean unavailable on the wire.
- presence->setType(Presence::Unavailable);
- resetPendingReconnects();
- myStatusLooksOnline_ = false;
- offlineRequested_ = true;
- }
- else {
- offlineRequested_ = false;
- presence->setShow(show);
- }
- presence->setStatus(statusText);
- statusTracker_->setRequestedPresence(presence);
- if (presence->getType() != Presence::Unavailable) {
- profileSettings_->storeInt("lastShow", presence->getShow());
- profileSettings_->storeString("lastStatus", presence->getStatus());
- }
- if (presence->getType() != Presence::Unavailable && !client_->isAvailable()) {
- performLoginFromCachedCredentials();
- } else {
- sendPresence(presence);
- }
+ boost::shared_ptr<Presence> presence(new Presence());
+ if (show == StatusShow::None) {
+ // Note: this is misleading, None doesn't mean unavailable on the wire.
+ presence->setType(Presence::Unavailable);
+ resetPendingReconnects();
+ myStatusLooksOnline_ = false;
+ offlineRequested_ = true;
+ }
+ else {
+ offlineRequested_ = false;
+ presence->setShow(show);
+ }
+ presence->setStatus(statusText);
+ statusTracker_->setRequestedPresence(presence);
+ if (presence->getType() != Presence::Unavailable) {
+ profileSettings_->storeInt("lastShow", presence->getShow());
+ profileSettings_->storeString("lastStatus", presence->getStatus());
+ }
+ if (presence->getType() != Presence::Unavailable && !client_->isAvailable()) {
+ performLoginFromCachedCredentials();
+ } else {
+ sendPresence(presence);
+ }
}
void MainController::sendPresence(boost::shared_ptr<Presence> presence) {
- rosterController_->getWindow()->setMyStatusType(presence->getShow());
- rosterController_->getWindow()->setMyStatusText(presence->getStatus());
- systemTrayController_->setMyStatusType(presence->getShow());
- notifier_->setTemporarilyDisabled(presence->getShow() == StatusShow::DND);
-
- // Add information and send
- presence->updatePayload(boost::make_shared<VCardUpdate>(vCardPhotoHash_));
- client_->getPresenceSender()->sendPresence(presence);
- if (presence->getType() == Presence::Unavailable) {
- logout();
- }
+ rosterController_->getWindow()->setMyStatusType(presence->getShow());
+ rosterController_->getWindow()->setMyStatusText(presence->getStatus());
+ systemTrayController_->setMyStatusType(presence->getShow());
+ notifier_->setTemporarilyDisabled(presence->getShow() == StatusShow::DND);
+
+ // Add information and send
+ presence->updatePayload(boost::make_shared<VCardUpdate>(vCardPhotoHash_));
+ client_->getPresenceSender()->sendPresence(presence);
+ if (presence->getType() == Presence::Unavailable) {
+ logout();
+ }
}
void MainController::handleInputIdleChanged(bool idle) {
- if (!statusTracker_) {
- //Haven't logged in yet.
- return;
- }
-
- if (settings_->getSetting(SettingConstants::IDLE_GOES_OFFLINE)) {
- if (idle) {
- logout();
- }
- }
- else {
- if (idle) {
- if (statusTracker_->goAutoAway(idleDetector_->getIdleTimeSeconds())) {
- if (client_ && client_->isAvailable()) {
- sendPresence(statusTracker_->getNextPresence());
- }
- }
- } else {
- if (statusTracker_->goAutoUnAway()) {
- if (client_ && client_->isAvailable()) {
- sendPresence(statusTracker_->getNextPresence());
- }
- }
- }
- }
+ if (!statusTracker_) {
+ //Haven't logged in yet.
+ return;
+ }
+
+ if (settings_->getSetting(SettingConstants::IDLE_GOES_OFFLINE)) {
+ if (idle) {
+ logout();
+ }
+ }
+ else {
+ if (idle) {
+ if (statusTracker_->goAutoAway(idleDetector_->getIdleTimeSeconds())) {
+ if (client_ && client_->isAvailable()) {
+ sendPresence(statusTracker_->getNextPresence());
+ }
+ }
+ } else {
+ if (statusTracker_->goAutoUnAway()) {
+ if (client_ && client_->isAvailable()) {
+ sendPresence(statusTracker_->getNextPresence());
+ }
+ }
+ }
+ }
}
void MainController::handleShowCertificateRequest() {
- std::vector<Certificate::ref> chain = client_->getStanzaChannel()->getPeerCertificateChain();
- rosterController_->getWindow()->openCertificateDialog(chain);
+ std::vector<Certificate::ref> chain = client_->getStanzaChannel()->getPeerCertificateChain();
+ rosterController_->getWindow()->openCertificateDialog(chain);
}
void MainController::handleLoginRequest(const std::string &username, const std::string &password, const std::string& certificatePath, CertificateWithKey::ref certificate, const ClientOptions& options, bool remember, bool loginAutomatically) {
- jid_ = JID(username);
- if (options.singleSignOn && (!jid_.isValid() || !jid_.getNode().empty())) {
- loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form 'wonderland.lit'"));
- loginWindow_->setIsLoggingIn(false);
- } else if (!options.singleSignOn && (!jid_.isValid() || jid_.getNode().empty())) {
- loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form 'alice@wonderland.lit'"));
- loginWindow_->setIsLoggingIn(false);
- } else {
+ jid_ = JID(username);
+ if (options.singleSignOn && (!jid_.isValid() || !jid_.getNode().empty())) {
+ loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form 'wonderland.lit'"));
+ loginWindow_->setIsLoggingIn(false);
+ } else if (!options.singleSignOn && (!jid_.isValid() || jid_.getNode().empty())) {
+ loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form 'alice@wonderland.lit'"));
+ loginWindow_->setIsLoggingIn(false);
+ } else {
#ifdef SWIFTEN_PLATFORM_WIN32
- if (options.singleSignOn) {
- std::string userName;
- std::string clientName;
- std::string serverName;
- boost::shared_ptr<boost::system::error_code> errorCode = getUserNameEx(userName, clientName, serverName);
-
- if (!errorCode) {
- /* Create JID using the Windows logon name and user provided domain name */
- jid_ = JID(clientName, username);
- }
- else {
- loginWindow_->setMessage(str(format(QT_TRANSLATE_NOOP("", "Error obtaining Windows user name (%1%)")) % errorCode->message()));
- loginWindow_->setIsLoggingIn(false);
- return;
- }
- }
+ if (options.singleSignOn) {
+ std::string userName;
+ std::string clientName;
+ std::string serverName;
+ boost::shared_ptr<boost::system::error_code> errorCode = getUserNameEx(userName, clientName, serverName);
+
+ if (!errorCode) {
+ /* Create JID using the Windows logon name and user provided domain name */
+ jid_ = JID(clientName, username);
+ }
+ else {
+ loginWindow_->setMessage(str(format(QT_TRANSLATE_NOOP("", "Error obtaining Windows user name (%1%)")) % errorCode->message()));
+ loginWindow_->setIsLoggingIn(false);
+ return;
+ }
+ }
#endif
- loginWindow_->setMessage("");
- loginWindow_->setIsLoggingIn(true);
- profileSettings_ = new ProfileSettingsProvider(username, settings_);
- if (!settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
- profileSettings_->storeString("jid", username);
- profileSettings_->storeString("certificate", certificatePath);
- profileSettings_->storeString("pass", (remember || loginAutomatically) ? password : "");
- std::string optionString = serializeClientOptions(options);
- profileSettings_->storeString("options", optionString);
- settings_->storeSetting(SettingConstants::LAST_LOGIN_JID, username);
- settings_->storeSetting(SettingConstants::LOGIN_AUTOMATICALLY, loginAutomatically);
- loginWindow_->addAvailableAccount(profileSettings_->getStringSetting("jid"), profileSettings_->getStringSetting("pass"), profileSettings_->getStringSetting("certificate"), options);
- }
-
- password_ = password;
- certificate_ = certificate;
- clientOptions_ = options;
- performLoginFromCachedCredentials();
- }
+ loginWindow_->setMessage("");
+ loginWindow_->setIsLoggingIn(true);
+ profileSettings_ = new ProfileSettingsProvider(username, settings_);
+ if (!settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
+ profileSettings_->storeString("jid", username);
+ profileSettings_->storeString("certificate", certificatePath);
+ profileSettings_->storeString("pass", (remember || loginAutomatically) ? password : "");
+ std::string optionString = serializeClientOptions(options);
+ profileSettings_->storeString("options", optionString);
+ settings_->storeSetting(SettingConstants::LAST_LOGIN_JID, username);
+ settings_->storeSetting(SettingConstants::LOGIN_AUTOMATICALLY, loginAutomatically);
+ loginWindow_->addAvailableAccount(profileSettings_->getStringSetting("jid"), profileSettings_->getStringSetting("pass"), profileSettings_->getStringSetting("certificate"), options);
+ }
+
+ password_ = password;
+ certificate_ = certificate;
+ clientOptions_ = options;
+ performLoginFromCachedCredentials();
+ }
}
void MainController::handlePurgeSavedLoginRequest(const std::string& username) {
- settings_->removeProfile(username);
- loginWindow_->removeAvailableAccount(username);
+ settings_->removeProfile(username);
+ loginWindow_->removeAvailableAccount(username);
}
void MainController::performLoginFromCachedCredentials() {
- if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS) && password_.empty()) {
- /* Then we can't try to login again. */
- return;
- }
- /* If we logged in with a bare JID, and we have a full bound JID, re-login with the
- * bound JID to try and keep dynamically assigned resources */
- JID clientJID = jid_;
- if (boundJID_.isValid() && jid_.isBare() && boundJID_.toBare() == jid_) {
- clientJID = boundJID_;
- }
-
- if (!statusTracker_) {
- statusTracker_ = new StatusTracker();
- }
- if (!clientInitialized_) {
- storages_ = storagesFactory_->createStorages(jid_.toBare());
- certificateStorage_ = certificateStorageFactory_->createCertificateStorage(jid_.toBare());
- certificateTrustChecker_ = new CertificateStorageTrustChecker(certificateStorage_);
-
- client_ = boost::make_shared<Swift::Client>(clientJID, createSafeByteArray(password_.c_str()), networkFactories_, storages_);
- clientInitialized_ = true;
- client_->setCertificateTrustChecker(certificateTrustChecker_);
- client_->onDataRead.connect(boost::bind(&XMLConsoleController::handleDataRead, xmlConsoleController_, _1));
- client_->onDataWritten.connect(boost::bind(&XMLConsoleController::handleDataWritten, xmlConsoleController_, _1));
- client_->onDisconnected.connect(boost::bind(&MainController::handleDisconnected, this, _1));
- client_->onConnected.connect(boost::bind(&MainController::handleConnected, this));
-
- client_->setSoftwareVersion(CLIENT_NAME, buildVersion);
-
- client_->getVCardManager()->onVCardChanged.connect(boost::bind(&MainController::handleVCardReceived, this, _1, _2));
- presenceNotifier_ = new PresenceNotifier(client_->getStanzaChannel(), notifier_, client_->getMUCRegistry(), client_->getAvatarManager(), client_->getNickResolver(), client_->getPresenceOracle(), networkFactories_->getTimerFactory());
- presenceNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1));
- eventNotifier_ = new EventNotifier(eventController_, notifier_, client_->getAvatarManager(), client_->getNickResolver());
- eventNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1));
- if (certificate_) {
- client_->setCertificate(certificate_);
- }
- boost::shared_ptr<Presence> presence(new Presence());
- presence->setShow(static_cast<StatusShow::Type>(profileSettings_->getIntSetting("lastShow", StatusShow::Online)));
- presence->setStatus(profileSettings_->getStringSetting("lastStatus"));
- statusTracker_->setRequestedPresence(presence);
- } else {
- /* In case we're in the middle of another login, make sure they don't overlap */
- client_->disconnect();
- }
- systemTrayController_->setConnecting();
- if (rosterController_) {
- rosterController_->getWindow()->setConnecting();
- }
- ClientOptions clientOptions = clientOptions_;
- bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);
- clientOptions.forgetPassword = eagle;
- clientOptions.useTLS = eagle ? ClientOptions::RequireTLS : clientOptions_.useTLS;
- client_->connect(clientOptions);
+ if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS) && password_.empty()) {
+ /* Then we can't try to login again. */
+ return;
+ }
+ /* If we logged in with a bare JID, and we have a full bound JID, re-login with the
+ * bound JID to try and keep dynamically assigned resources */
+ JID clientJID = jid_;
+ if (boundJID_.isValid() && jid_.isBare() && boundJID_.toBare() == jid_) {
+ clientJID = boundJID_;
+ }
+
+ if (!statusTracker_) {
+ statusTracker_ = new StatusTracker();
+ }
+ if (!clientInitialized_) {
+ storages_ = storagesFactory_->createStorages(jid_.toBare());
+ certificateStorage_ = certificateStorageFactory_->createCertificateStorage(jid_.toBare());
+ certificateTrustChecker_ = new CertificateStorageTrustChecker(certificateStorage_);
+
+ client_ = boost::make_shared<Swift::Client>(clientJID, createSafeByteArray(password_.c_str()), networkFactories_, storages_);
+ clientInitialized_ = true;
+ client_->setCertificateTrustChecker(certificateTrustChecker_);
+ client_->onDataRead.connect(boost::bind(&XMLConsoleController::handleDataRead, xmlConsoleController_, _1));
+ client_->onDataWritten.connect(boost::bind(&XMLConsoleController::handleDataWritten, xmlConsoleController_, _1));
+ client_->onDisconnected.connect(boost::bind(&MainController::handleDisconnected, this, _1));
+ client_->onConnected.connect(boost::bind(&MainController::handleConnected, this));
+
+ client_->setSoftwareVersion(CLIENT_NAME, buildVersion);
+
+ client_->getVCardManager()->onVCardChanged.connect(boost::bind(&MainController::handleVCardReceived, this, _1, _2));
+ presenceNotifier_ = new PresenceNotifier(client_->getStanzaChannel(), notifier_, client_->getMUCRegistry(), client_->getAvatarManager(), client_->getNickResolver(), client_->getPresenceOracle(), networkFactories_->getTimerFactory());
+ presenceNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1));
+ eventNotifier_ = new EventNotifier(eventController_, notifier_, client_->getAvatarManager(), client_->getNickResolver());
+ eventNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1));
+ if (certificate_) {
+ client_->setCertificate(certificate_);
+ }
+ boost::shared_ptr<Presence> presence(new Presence());
+ presence->setShow(static_cast<StatusShow::Type>(profileSettings_->getIntSetting("lastShow", StatusShow::Online)));
+ presence->setStatus(profileSettings_->getStringSetting("lastStatus"));
+ statusTracker_->setRequestedPresence(presence);
+ } else {
+ /* In case we're in the middle of another login, make sure they don't overlap */
+ client_->disconnect();
+ }
+ systemTrayController_->setConnecting();
+ if (rosterController_) {
+ rosterController_->getWindow()->setConnecting();
+ }
+ ClientOptions clientOptions = clientOptions_;
+ bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);
+ clientOptions.forgetPassword = eagle;
+ clientOptions.useTLS = eagle ? ClientOptions::RequireTLS : clientOptions_.useTLS;
+ client_->connect(clientOptions);
}
void MainController::handleDisconnected(const boost::optional<ClientError>& error) {
- if (rosterController_) {
- rosterController_->getWindow()->setStreamEncryptionStatus(false);
- }
- if (adHocManager_) {
- adHocManager_->setOnline(false);
- }
- if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
- purgeCachedCredentials();
- }
- if (quitRequested_) {
- resetClient();
- loginWindow_->quit();
- }
- else if (error) {
- std::string message;
- std::string certificateErrorMessage;
- bool forceSignout = false;
- switch(error->getType()) {
- case ClientError::UnknownError: message = QT_TRANSLATE_NOOP("", "Unknown Error"); break;
- case ClientError::DomainNameResolveError: message = QT_TRANSLATE_NOOP("", "Unable to find server"); break;
- case ClientError::ConnectionError: message = QT_TRANSLATE_NOOP("", "Error connecting to server"); break;
- case ClientError::ConnectionReadError: message = QT_TRANSLATE_NOOP("", "Error while receiving server data"); break;
- case ClientError::ConnectionWriteError: message = QT_TRANSLATE_NOOP("", "Error while sending data to the server"); break;
- case ClientError::XMLError: message = QT_TRANSLATE_NOOP("", "Error parsing server data"); break;
- case ClientError::AuthenticationFailedError: message = QT_TRANSLATE_NOOP("", "Login/password invalid"); break;
- case ClientError::CompressionFailedError: message = QT_TRANSLATE_NOOP("", "Error while compressing stream"); break;
- case ClientError::ServerVerificationFailedError: message = QT_TRANSLATE_NOOP("", "Server verification failed"); break;
- case ClientError::NoSupportedAuthMechanismsError: message = QT_TRANSLATE_NOOP("", "Authentication mechanisms not supported"); break;
- case ClientError::UnexpectedElementError: message = QT_TRANSLATE_NOOP("", "Unexpected response"); break;
- case ClientError::ResourceBindError: message = QT_TRANSLATE_NOOP("", "Error binding resource"); break;
- case ClientError::SessionStartError: message = QT_TRANSLATE_NOOP("", "Error starting session"); break;
- case ClientError::StreamError: message = QT_TRANSLATE_NOOP("", "Stream error"); break;
- case ClientError::TLSError: message = QT_TRANSLATE_NOOP("", "Encryption error"); break;
- case ClientError::ClientCertificateLoadError: message = QT_TRANSLATE_NOOP("", "Error loading certificate (Invalid file or password?)"); break;
- case ClientError::ClientCertificateError: message = QT_TRANSLATE_NOOP("", "Certificate not authorized"); break;
- case ClientError::CertificateCardRemoved: message = QT_TRANSLATE_NOOP("", "Certificate card removed"); forceSignout = true; break;
-
- case ClientError::UnknownCertificateError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unknown certificate"); break;
- case ClientError::CertificateExpiredError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has expired"); break;
- case ClientError::CertificateNotYetValidError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not yet valid"); break;
- case ClientError::CertificateSelfSignedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is self-signed"); break;
- case ClientError::CertificateRejectedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been rejected"); break;
- case ClientError::CertificateUntrustedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not trusted"); break;
- case ClientError::InvalidCertificatePurposeError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate cannot be used for encrypting your connection"); break;
- case ClientError::CertificatePathLengthExceededError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate path length constraint exceeded"); break;
- case ClientError::InvalidCertificateSignatureError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid certificate signature"); break;
- case ClientError::InvalidCAError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid Certificate Authority"); break;
- case ClientError::InvalidServerIdentityError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate does not match the host identity"); break;
- case ClientError::RevokedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been revoked"); break;
- case ClientError::RevocationCheckFailedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unable to determine certificate revocation state"); break;
- }
- bool forceReconnectAfterCertificateTrust = false;
- if (!certificateErrorMessage.empty()) {
- std::vector<Certificate::ref> certificates = certificateTrustChecker_->getLastCertificateChain();
- if (!certificates.empty() && loginWindow_->askUserToTrustCertificatePermanently(certificateErrorMessage, certificates)) {
- certificateStorage_->addCertificate(certificates[0]);
- forceReconnectAfterCertificateTrust = true;
- }
- else {
- message = QT_TRANSLATE_NOOP("", "Certificate error");
- }
- }
-
- if (!message.empty() && error->getErrorCode()) {
- message = str(format(QT_TRANSLATE_NOOP("", "%1% (%2%)")) % message % error->getErrorCode()->message());
- }
-
- if (forceReconnectAfterCertificateTrust && settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
- forceReconnectAfterCertificateTrust = false;
- forceSignout = true;
- message = QT_TRANSLATE_NOOP("", "Re-enter credentials and retry");
- }
-
- if (forceReconnectAfterCertificateTrust) {
- performLoginFromCachedCredentials();
- }
- else if (forceSignout || !rosterController_) { //hasn't been logged in yet or permanent error
- signOut();
- loginWindow_->setMessage(message);
- loginWindow_->setIsLoggingIn(false);
- } else {
- logout();
- if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
- message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%. To reconnect, Sign Out and provide your password again.")) % jid_.getDomain() % message);
- } else {
- if (!offlineRequested_) {
- setReconnectTimer();
- }
- if (lastDisconnectError_) {
- message = str(format(QT_TRANSLATE_NOOP("", "Reconnect to %1% failed: %2%. Will retry in %3% seconds.")) % jid_.getDomain() % message % boost::lexical_cast<std::string>(timeBeforeNextReconnect_));
- lastDisconnectError_->conclude();
- } else {
- message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%.")) % jid_.getDomain() % message);
- }
- lastDisconnectError_ = boost::make_shared<ErrorEvent>(JID(jid_.getDomain()), message);
- eventController_->handleIncomingEvent(lastDisconnectError_);
- }
- }
- }
- else if (!rosterController_) { //hasn't been logged in yet
- loginWindow_->setIsLoggingIn(false);
- }
+ if (rosterController_) {
+ rosterController_->getWindow()->setStreamEncryptionStatus(false);
+ }
+ if (adHocManager_) {
+ adHocManager_->setOnline(false);
+ }
+ if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
+ purgeCachedCredentials();
+ }
+ if (quitRequested_) {
+ resetClient();
+ loginWindow_->quit();
+ }
+ else if (error) {
+ std::string message;
+ std::string certificateErrorMessage;
+ bool forceSignout = false;
+ switch(error->getType()) {
+ case ClientError::UnknownError: message = QT_TRANSLATE_NOOP("", "Unknown Error"); break;
+ case ClientError::DomainNameResolveError: message = QT_TRANSLATE_NOOP("", "Unable to find server"); break;
+ case ClientError::ConnectionError: message = QT_TRANSLATE_NOOP("", "Error connecting to server"); break;
+ case ClientError::ConnectionReadError: message = QT_TRANSLATE_NOOP("", "Error while receiving server data"); break;
+ case ClientError::ConnectionWriteError: message = QT_TRANSLATE_NOOP("", "Error while sending data to the server"); break;
+ case ClientError::XMLError: message = QT_TRANSLATE_NOOP("", "Error parsing server data"); break;
+ case ClientError::AuthenticationFailedError: message = QT_TRANSLATE_NOOP("", "Login/password invalid"); break;
+ case ClientError::CompressionFailedError: message = QT_TRANSLATE_NOOP("", "Error while compressing stream"); break;
+ case ClientError::ServerVerificationFailedError: message = QT_TRANSLATE_NOOP("", "Server verification failed"); break;
+ case ClientError::NoSupportedAuthMechanismsError: message = QT_TRANSLATE_NOOP("", "Authentication mechanisms not supported"); break;
+ case ClientError::UnexpectedElementError: message = QT_TRANSLATE_NOOP("", "Unexpected response"); break;
+ case ClientError::ResourceBindError: message = QT_TRANSLATE_NOOP("", "Error binding resource"); break;
+ case ClientError::SessionStartError: message = QT_TRANSLATE_NOOP("", "Error starting session"); break;
+ case ClientError::StreamError: message = QT_TRANSLATE_NOOP("", "Stream error"); break;
+ case ClientError::TLSError: message = QT_TRANSLATE_NOOP("", "Encryption error"); break;
+ case ClientError::ClientCertificateLoadError: message = QT_TRANSLATE_NOOP("", "Error loading certificate (Invalid file or password?)"); break;
+ case ClientError::ClientCertificateError: message = QT_TRANSLATE_NOOP("", "Certificate not authorized"); break;
+ case ClientError::CertificateCardRemoved: message = QT_TRANSLATE_NOOP("", "Certificate card removed"); forceSignout = true; break;
+
+ case ClientError::UnknownCertificateError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unknown certificate"); break;
+ case ClientError::CertificateExpiredError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has expired"); break;
+ case ClientError::CertificateNotYetValidError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not yet valid"); break;
+ case ClientError::CertificateSelfSignedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is self-signed"); break;
+ case ClientError::CertificateRejectedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been rejected"); break;
+ case ClientError::CertificateUntrustedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not trusted"); break;
+ case ClientError::InvalidCertificatePurposeError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate cannot be used for encrypting your connection"); break;
+ case ClientError::CertificatePathLengthExceededError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate path length constraint exceeded"); break;
+ case ClientError::InvalidCertificateSignatureError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid certificate signature"); break;
+ case ClientError::InvalidCAError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid Certificate Authority"); break;
+ case ClientError::InvalidServerIdentityError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate does not match the host identity"); break;
+ case ClientError::RevokedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been revoked"); break;
+ case ClientError::RevocationCheckFailedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unable to determine certificate revocation state"); break;
+ }
+ bool forceReconnectAfterCertificateTrust = false;
+ if (!certificateErrorMessage.empty()) {
+ std::vector<Certificate::ref> certificates = certificateTrustChecker_->getLastCertificateChain();
+ if (!certificates.empty() && loginWindow_->askUserToTrustCertificatePermanently(certificateErrorMessage, certificates)) {
+ certificateStorage_->addCertificate(certificates[0]);
+ forceReconnectAfterCertificateTrust = true;
+ }
+ else {
+ message = QT_TRANSLATE_NOOP("", "Certificate error");
+ }
+ }
+
+ if (!message.empty() && error->getErrorCode()) {
+ message = str(format(QT_TRANSLATE_NOOP("", "%1% (%2%)")) % message % error->getErrorCode()->message());
+ }
+
+ if (forceReconnectAfterCertificateTrust && settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
+ forceReconnectAfterCertificateTrust = false;
+ forceSignout = true;
+ message = QT_TRANSLATE_NOOP("", "Re-enter credentials and retry");
+ }
+
+ if (forceReconnectAfterCertificateTrust) {
+ performLoginFromCachedCredentials();
+ }
+ else if (forceSignout || !rosterController_) { //hasn't been logged in yet or permanent error
+ signOut();
+ loginWindow_->setMessage(message);
+ loginWindow_->setIsLoggingIn(false);
+ } else {
+ logout();
+ if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
+ message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%. To reconnect, Sign Out and provide your password again.")) % jid_.getDomain() % message);
+ } else {
+ if (!offlineRequested_) {
+ setReconnectTimer();
+ }
+ if (lastDisconnectError_) {
+ message = str(format(QT_TRANSLATE_NOOP("", "Reconnect to %1% failed: %2%. Will retry in %3% seconds.")) % jid_.getDomain() % message % boost::lexical_cast<std::string>(timeBeforeNextReconnect_));
+ lastDisconnectError_->conclude();
+ } else {
+ message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%.")) % jid_.getDomain() % message);
+ }
+ lastDisconnectError_ = boost::make_shared<ErrorEvent>(JID(jid_.getDomain()), message);
+ eventController_->handleIncomingEvent(lastDisconnectError_);
+ }
+ }
+ }
+ else if (!rosterController_) { //hasn't been logged in yet
+ loginWindow_->setIsLoggingIn(false);
+ }
}
void MainController::setReconnectTimer() {
- if (timeBeforeNextReconnect_ < 0) {
- timeBeforeNextReconnect_ = 1;
- } else {
- timeBeforeNextReconnect_ = timeBeforeNextReconnect_ >= 150 ? 300 : timeBeforeNextReconnect_ * 2; // Randomly selected by roll of a die, as required by 3920bis
- }
- if (reconnectTimer_) {
- reconnectTimer_->stop();
- }
- reconnectTimer_ = networkFactories_->getTimerFactory()->createTimer(timeBeforeNextReconnect_ * 1000);
- reconnectTimer_->onTick.connect(boost::bind(&MainController::reconnectAfterError, this));
- reconnectTimer_->start();
+ if (timeBeforeNextReconnect_ < 0) {
+ timeBeforeNextReconnect_ = 1;
+ } else {
+ timeBeforeNextReconnect_ = timeBeforeNextReconnect_ >= 150 ? 300 : timeBeforeNextReconnect_ * 2; // Randomly selected by roll of a die, as required by 3920bis
+ }
+ if (reconnectTimer_) {
+ reconnectTimer_->stop();
+ }
+ reconnectTimer_ = networkFactories_->getTimerFactory()->createTimer(timeBeforeNextReconnect_ * 1000);
+ reconnectTimer_->onTick.connect(boost::bind(&MainController::reconnectAfterError, this));
+ reconnectTimer_->start();
}
void MainController::handleCancelLoginRequest() {
- signOut();
+ signOut();
}
void MainController::signOut() {
- if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
- purgeCachedCredentials();
- }
- eventController_->clear();
- logout();
- loginWindow_->loggedOut();
- resetClient();
+ if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
+ purgeCachedCredentials();
+ }
+ eventController_->clear();
+ logout();
+ loginWindow_->loggedOut();
+ resetClient();
}
void MainController::logout() {
- if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
- purgeCachedCredentials();
- }
- systemTrayController_->setMyStatusType(StatusShow::None);
- if (clientInitialized_ /*&& client_->isAvailable()*/) {
- client_->disconnect();
- }
- if (rosterController_ && myStatusLooksOnline_) {
- rosterController_->getWindow()->setMyStatusType(StatusShow::None);
- rosterController_->getWindow()->setMyStatusText("");
- myStatusLooksOnline_ = false;
- }
- setManagersOffline();
+ if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
+ purgeCachedCredentials();
+ }
+ systemTrayController_->setMyStatusType(StatusShow::None);
+ if (clientInitialized_ /*&& client_->isAvailable()*/) {
+ client_->disconnect();
+ }
+ if (rosterController_ && myStatusLooksOnline_) {
+ rosterController_->getWindow()->setMyStatusType(StatusShow::None);
+ rosterController_->getWindow()->setMyStatusText("");
+ myStatusLooksOnline_ = false;
+ }
+ setManagersOffline();
}
void MainController::setManagersOffline() {
- if (chatsManager_) {
- chatsManager_->setOnline(false);
- }
- if (rosterController_) {
- rosterController_->setEnabled(false);
- }
- if (profileController_) {
- profileController_->setAvailable(false);
- }
- if (contactEditController_) {
- contactEditController_->setAvailable(false);
- }
+ if (chatsManager_) {
+ chatsManager_->setOnline(false);
+ }
+ if (rosterController_) {
+ rosterController_->setEnabled(false);
+ }
+ if (profileController_) {
+ profileController_->setAvailable(false);
+ }
+ if (contactEditController_) {
+ contactEditController_->setAvailable(false);
+ }
}
void MainController::handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo> info, ErrorPayload::ref error) {
- if (!error) {
- chatsManager_->setServerDiscoInfo(info);
- adHocManager_->setServerDiscoInfo(info);
- if (info->hasFeature(DiscoInfo::BlockingCommandFeature)) {
- rosterController_->getWindow()->setBlockingCommandAvailable(true);
- rosterController_->initBlockingCommand();
- }
- }
+ if (!error) {
+ chatsManager_->setServerDiscoInfo(info);
+ adHocManager_->setServerDiscoInfo(info);
+ if (info->hasFeature(DiscoInfo::BlockingCommandFeature)) {
+ rosterController_->getWindow()->setBlockingCommandAvailable(true);
+ rosterController_->initBlockingCommand();
+ }
+ }
}
void MainController::handleVCardReceived(const JID& jid, VCard::ref vCard) {
- if (!jid.equals(jid_, JID::WithoutResource) || !vCard) {
- return;
- }
- std::string hash;
- if (!vCard->getPhoto().empty()) {
- hash = Hexify::hexify(networkFactories_->getCryptoProvider()->getSHA1Hash(vCard->getPhoto()));
- }
- if (hash != vCardPhotoHash_) {
- vCardPhotoHash_ = hash;
- if (client_ && client_->isAvailable()) {
- sendPresence(statusTracker_->getNextPresence());
- }
- }
+ if (!jid.equals(jid_, JID::WithoutResource) || !vCard) {
+ return;
+ }
+ std::string hash;
+ if (!vCard->getPhoto().empty()) {
+ hash = Hexify::hexify(networkFactories_->getCryptoProvider()->getSHA1Hash(vCard->getPhoto()));
+ }
+ if (hash != vCardPhotoHash_) {
+ vCardPhotoHash_ = hash;
+ if (client_ && client_->isAvailable()) {
+ sendPresence(statusTracker_->getNextPresence());
+ }
+ }
}
void MainController::handleNotificationClicked(const JID& jid) {
- assert(chatsManager_);
- if (clientInitialized_) {
- if (client_->getMUCRegistry()->isMUC(jid)) {
- uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(jid));
- }
- else {
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(jid)));
- }
- }
+ assert(chatsManager_);
+ if (clientInitialized_) {
+ if (client_->getMUCRegistry()->isMUC(jid)) {
+ uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(jid));
+ }
+ else {
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(jid)));
+ }
+ }
}
void MainController::handleQuitRequest() {
- if (client_ && client_->isActive()) {
- quitRequested_ = true;
- client_->disconnect();
- }
- else {
- resetClient();
- loginWindow_->quit();
- }
+ if (client_ && client_->isActive()) {
+ quitRequested_ = true;
+ client_->disconnect();
+ }
+ else {
+ resetClient();
+ loginWindow_->quit();
+ }
}
#define SERIALIZE_BOOL(option) result += options.option ? "1" : "0"; result += ",";
@@ -851,34 +851,34 @@ void MainController::handleQuitRequest() {
#define SERIALIZE_URL(option) SERIALIZE_STRING(option.toString())
std::string MainController::serializeClientOptions(const ClientOptions& options) {
- std::string result;
- SERIALIZE_BOOL(useStreamCompression);
- switch (options.useTLS) {
- case ClientOptions::NeverUseTLS: result += "1";break;
- case ClientOptions::UseTLSWhenAvailable: result += "2";break;
- case ClientOptions::RequireTLS: result += "3";break;
- }
- result += ",";
- SERIALIZE_BOOL(allowPLAINWithoutTLS);
- SERIALIZE_BOOL(useStreamResumption);
- SERIALIZE_BOOL(useAcks);
- SERIALIZE_STRING(manualHostname);
- SERIALIZE_INT(manualPort);
- switch (options.proxyType) {
- case ClientOptions::NoProxy: result += "1";break;
- case ClientOptions::SystemConfiguredProxy: result += "2";break;
- case ClientOptions::SOCKS5Proxy: result += "3";break;
- case ClientOptions::HTTPConnectProxy: result += "4";break;
- }
- result += ",";
- SERIALIZE_STRING(manualProxyHostname);
- SERIALIZE_INT(manualProxyPort);
- SERIALIZE_URL(boshURL);
- SERIALIZE_URL(boshHTTPConnectProxyURL);
- SERIALIZE_SAFE_STRING(boshHTTPConnectProxyAuthID);
- SERIALIZE_SAFE_STRING(boshHTTPConnectProxyAuthPassword);
- SERIALIZE_BOOL(tlsOptions.schannelTLS1_0Workaround);
- return result;
+ std::string result;
+ SERIALIZE_BOOL(useStreamCompression);
+ switch (options.useTLS) {
+ case ClientOptions::NeverUseTLS: result += "1";break;
+ case ClientOptions::UseTLSWhenAvailable: result += "2";break;
+ case ClientOptions::RequireTLS: result += "3";break;
+ }
+ result += ",";
+ SERIALIZE_BOOL(allowPLAINWithoutTLS);
+ SERIALIZE_BOOL(useStreamResumption);
+ SERIALIZE_BOOL(useAcks);
+ SERIALIZE_STRING(manualHostname);
+ SERIALIZE_INT(manualPort);
+ switch (options.proxyType) {
+ case ClientOptions::NoProxy: result += "1";break;
+ case ClientOptions::SystemConfiguredProxy: result += "2";break;
+ case ClientOptions::SOCKS5Proxy: result += "3";break;
+ case ClientOptions::HTTPConnectProxy: result += "4";break;
+ }
+ result += ",";
+ SERIALIZE_STRING(manualProxyHostname);
+ SERIALIZE_INT(manualProxyPort);
+ SERIALIZE_URL(boshURL);
+ SERIALIZE_URL(boshHTTPConnectProxyURL);
+ SERIALIZE_SAFE_STRING(boshHTTPConnectProxyAuthID);
+ SERIALIZE_SAFE_STRING(boshHTTPConnectProxyAuthPassword);
+ SERIALIZE_BOOL(tlsOptions.schannelTLS1_0Workaround);
+ return result;
}
#define CHECK_PARSE_LENGTH if (i >= segments.size()) {return result;}
@@ -893,41 +893,41 @@ std::string MainController::serializeClientOptions(const ClientOptions& options)
ClientOptions MainController::parseClientOptions(const std::string& optionString) {
- ClientOptions result;
- size_t i = 0;
- int intVal = 0;
- std::string stringVal;
- std::vector<std::string> segments = String::split(optionString, ',');
-
- PARSE_BOOL(useStreamCompression, 1);
- PARSE_INT_RAW(-1);
- switch (intVal) {
- case 1: result.useTLS = ClientOptions::NeverUseTLS;break;
- case 2: result.useTLS = ClientOptions::UseTLSWhenAvailable;break;
- case 3: result.useTLS = ClientOptions::RequireTLS;break;
- default:;
- }
- PARSE_BOOL(allowPLAINWithoutTLS, 0);
- PARSE_BOOL(useStreamResumption, 0);
- PARSE_BOOL(useAcks, 1);
- PARSE_STRING(manualHostname);
- PARSE_INT(manualPort, -1);
- PARSE_INT_RAW(-1);
- switch (intVal) {
- case 1: result.proxyType = ClientOptions::NoProxy;break;
- case 2: result.proxyType = ClientOptions::SystemConfiguredProxy;break;
- case 3: result.proxyType = ClientOptions::SOCKS5Proxy;break;
- case 4: result.proxyType = ClientOptions::HTTPConnectProxy;break;
- }
- PARSE_STRING(manualProxyHostname);
- PARSE_INT(manualProxyPort, -1);
- PARSE_URL(boshURL);
- PARSE_URL(boshHTTPConnectProxyURL);
- PARSE_SAFE_STRING(boshHTTPConnectProxyAuthID);
- PARSE_SAFE_STRING(boshHTTPConnectProxyAuthPassword);
- PARSE_BOOL(tlsOptions.schannelTLS1_0Workaround, false);
-
- return result;
+ ClientOptions result;
+ size_t i = 0;
+ int intVal = 0;
+ std::string stringVal;
+ std::vector<std::string> segments = String::split(optionString, ',');
+
+ PARSE_BOOL(useStreamCompression, 1);
+ PARSE_INT_RAW(-1);
+ switch (intVal) {
+ case 1: result.useTLS = ClientOptions::NeverUseTLS;break;
+ case 2: result.useTLS = ClientOptions::UseTLSWhenAvailable;break;
+ case 3: result.useTLS = ClientOptions::RequireTLS;break;
+ default:;
+ }
+ PARSE_BOOL(allowPLAINWithoutTLS, 0);
+ PARSE_BOOL(useStreamResumption, 0);
+ PARSE_BOOL(useAcks, 1);
+ PARSE_STRING(manualHostname);
+ PARSE_INT(manualPort, -1);
+ PARSE_INT_RAW(-1);
+ switch (intVal) {
+ case 1: result.proxyType = ClientOptions::NoProxy;break;
+ case 2: result.proxyType = ClientOptions::SystemConfiguredProxy;break;
+ case 3: result.proxyType = ClientOptions::SOCKS5Proxy;break;
+ case 4: result.proxyType = ClientOptions::HTTPConnectProxy;break;
+ }
+ PARSE_STRING(manualProxyHostname);
+ PARSE_INT(manualProxyPort, -1);
+ PARSE_URL(boshURL);
+ PARSE_URL(boshHTTPConnectProxyURL);
+ PARSE_SAFE_STRING(boshHTTPConnectProxyAuthID);
+ PARSE_SAFE_STRING(boshHTTPConnectProxyAuthPassword);
+ PARSE_BOOL(tlsOptions.schannelTLS1_0Workaround, false);
+
+ return result;
}
}
diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h
index e8a915e..ed7765a 100644
--- a/Swift/Controllers/MainController.h
+++ b/Swift/Controllers/MainController.h
@@ -29,171 +29,171 @@
#include <Swift/Controllers/XMPPEvents/ErrorEvent.h>
namespace Swift {
- class IdleDetector;
- class UIFactory;
- class EventLoop;
- class Client;
- class ChatController;
- class ChatsManager;
- class CertificateStorageFactory;
- class CertificateStorage;
- class CertificateStorageTrustChecker;
- class EventController;
- class MainWindow;
- class RosterController;
- class LoginWindow;
- class EventLoop;
- class MUCController;
- class Notifier;
- class ProfileController;
- class ShowProfileController;
- class ContactEditController;
- class TogglableNotifier;
- class PresenceNotifier;
- class EventNotifier;
- class SystemTray;
- class SystemTrayController;
- class SoundEventController;
- class SoundPlayer;
- class XMLConsoleController;
- class HistoryViewController;
- class HistoryController;
- class FileTransferListController;
- class UIEventStream;
- class EventWindowFactory;
- class EventWindowController;
- class MUCSearchController;
- class UserSearchController;
- class StatusTracker;
- class Dock;
- class Storages;
- class StoragesFactory;
- class NetworkFactories;
- class URIHandler;
- class XMPPURIController;
- class AdHocManager;
- class AdHocCommandWindowFactory;
- class FileTransferOverview;
- class WhiteboardManager;
- class HighlightManager;
- class HighlightEditorController;
- class BlockListController;
- class ContactSuggester;
- class ContactsFromXMPPRoster;
+ class IdleDetector;
+ class UIFactory;
+ class EventLoop;
+ class Client;
+ class ChatController;
+ class ChatsManager;
+ class CertificateStorageFactory;
+ class CertificateStorage;
+ class CertificateStorageTrustChecker;
+ class EventController;
+ class MainWindow;
+ class RosterController;
+ class LoginWindow;
+ class EventLoop;
+ class MUCController;
+ class Notifier;
+ class ProfileController;
+ class ShowProfileController;
+ class ContactEditController;
+ class TogglableNotifier;
+ class PresenceNotifier;
+ class EventNotifier;
+ class SystemTray;
+ class SystemTrayController;
+ class SoundEventController;
+ class SoundPlayer;
+ class XMLConsoleController;
+ class HistoryViewController;
+ class HistoryController;
+ class FileTransferListController;
+ class UIEventStream;
+ class EventWindowFactory;
+ class EventWindowController;
+ class MUCSearchController;
+ class UserSearchController;
+ class StatusTracker;
+ class Dock;
+ class Storages;
+ class StoragesFactory;
+ class NetworkFactories;
+ class URIHandler;
+ class XMPPURIController;
+ class AdHocManager;
+ class AdHocCommandWindowFactory;
+ class FileTransferOverview;
+ class WhiteboardManager;
+ class HighlightManager;
+ class HighlightEditorController;
+ class BlockListController;
+ class ContactSuggester;
+ class ContactsFromXMPPRoster;
- class MainController {
- public:
- MainController(
- EventLoop* eventLoop,
- NetworkFactories* networkFactories,
- UIFactory* uiFactories,
- SettingsProvider *settings,
- SystemTray* systemTray,
- SoundPlayer* soundPlayer,
- StoragesFactory* storagesFactory,
- CertificateStorageFactory* certificateStorageFactory,
- Dock* dock,
- Notifier* notifier,
- URIHandler* uriHandler,
- IdleDetector* idleDetector,
- const std::map<std::string, std::string>& emoticons,
- bool useDelayForLatency);
- ~MainController();
+ class MainController {
+ public:
+ MainController(
+ EventLoop* eventLoop,
+ NetworkFactories* networkFactories,
+ UIFactory* uiFactories,
+ SettingsProvider *settings,
+ SystemTray* systemTray,
+ SoundPlayer* soundPlayer,
+ StoragesFactory* storagesFactory,
+ CertificateStorageFactory* certificateStorageFactory,
+ Dock* dock,
+ Notifier* notifier,
+ URIHandler* uriHandler,
+ IdleDetector* idleDetector,
+ const std::map<std::string, std::string>& emoticons,
+ bool useDelayForLatency);
+ ~MainController();
- private:
- void resetClient();
- void handleConnected();
- void handleLoginRequest(const std::string& username, const std::string& password, const std::string& certificatePath, CertificateWithKey::ref certificate, const ClientOptions& options, bool remember, bool loginAutomatically);
- void handleCancelLoginRequest();
- void handleQuitRequest();
- void handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText);
- void handleDisconnected(const boost::optional<ClientError>& error);
- void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo>, ErrorPayload::ref);
- void handleEventQueueLengthChange(int count);
- void handleVCardReceived(const JID& j, VCard::ref vCard);
- void handleSettingChanged(const std::string& settingPath);
- void handlePurgeSavedLoginRequest(const std::string& username);
- void sendPresence(boost::shared_ptr<Presence> presence);
- void handleInputIdleChanged(bool);
- void handleShowCertificateRequest();
- void logout();
- void signOut();
- void setReconnectTimer();
- void resetPendingReconnects();
- void resetCurrentError();
-
- void performLoginFromCachedCredentials();
- void reconnectAfterError();
- void setManagersOffline();
- void handleNotificationClicked(const JID& jid);
- void handleForceQuit();
- void purgeCachedCredentials();
- std::string serializeClientOptions(const ClientOptions& options);
- ClientOptions parseClientOptions(const std::string& optionString);
+ private:
+ void resetClient();
+ void handleConnected();
+ void handleLoginRequest(const std::string& username, const std::string& password, const std::string& certificatePath, CertificateWithKey::ref certificate, const ClientOptions& options, bool remember, bool loginAutomatically);
+ void handleCancelLoginRequest();
+ void handleQuitRequest();
+ void handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText);
+ void handleDisconnected(const boost::optional<ClientError>& error);
+ void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo>, ErrorPayload::ref);
+ void handleEventQueueLengthChange(int count);
+ void handleVCardReceived(const JID& j, VCard::ref vCard);
+ void handleSettingChanged(const std::string& settingPath);
+ void handlePurgeSavedLoginRequest(const std::string& username);
+ void sendPresence(boost::shared_ptr<Presence> presence);
+ void handleInputIdleChanged(bool);
+ void handleShowCertificateRequest();
+ void logout();
+ void signOut();
+ void setReconnectTimer();
+ void resetPendingReconnects();
+ void resetCurrentError();
- private:
- EventLoop* eventLoop_;
- NetworkFactories* networkFactories_;
- UIFactory* uiFactory_;
- StoragesFactory* storagesFactory_;
- Storages* storages_;
- CertificateStorageFactory* certificateStorageFactory_;
- CertificateStorage* certificateStorage_;
- CertificateStorageTrustChecker* certificateTrustChecker_;
- bool clientInitialized_;
- boost::shared_ptr<Client> client_;
- SettingsProvider *settings_;
- ProfileSettingsProvider* profileSettings_;
- Dock* dock_;
- URIHandler* uriHandler_;
- IdleDetector* idleDetector_;
- TogglableNotifier* notifier_;
- PresenceNotifier* presenceNotifier_;
- EventNotifier* eventNotifier_;
- RosterController* rosterController_;
- EventController* eventController_;
- EventWindowController* eventWindowController_;
- AdHocManager* adHocManager_;
- LoginWindow* loginWindow_;
- UIEventStream* uiEventStream_;
- XMLConsoleController* xmlConsoleController_;
- HistoryViewController* historyViewController_;
- HistoryController* historyController_;
- FileTransferListController* fileTransferListController_;
- BlockListController* blockListController_;
- ChatsManager* chatsManager_;
- ProfileController* profileController_;
- ShowProfileController* showProfileController_;
- ContactEditController* contactEditController_;
- ContactsFromXMPPRoster* contactsFromRosterProvider_;
- ContactSuggester* contactSuggesterWithoutRoster_;
- ContactSuggester* contactSuggesterWithRoster_;
- JID jid_;
- JID boundJID_;
- SystemTrayController* systemTrayController_;
- SoundEventController* soundEventController_;
- XMPPURIController* xmppURIController_;
- std::string vCardPhotoHash_;
- std::string password_;
- CertificateWithKey::ref certificate_;
- ClientOptions clientOptions_;
- boost::shared_ptr<ErrorEvent> lastDisconnectError_;
- bool useDelayForLatency_;
- UserSearchController* userSearchControllerChat_;
- UserSearchController* userSearchControllerAdd_;
- UserSearchController* userSearchControllerInvite_;
- int timeBeforeNextReconnect_;
- Timer::ref reconnectTimer_;
- StatusTracker* statusTracker_;
- bool myStatusLooksOnline_;
- bool quitRequested_;
- bool offlineRequested_;
- static const int SecondsToWaitBeforeForceQuitting;
- FileTransferOverview* ftOverview_;
- WhiteboardManager* whiteboardManager_;
- HighlightManager* highlightManager_;
- HighlightEditorController* highlightEditorController_;
- std::map<std::string, std::string> emoticons_;
- };
+ void performLoginFromCachedCredentials();
+ void reconnectAfterError();
+ void setManagersOffline();
+ void handleNotificationClicked(const JID& jid);
+ void handleForceQuit();
+ void purgeCachedCredentials();
+ std::string serializeClientOptions(const ClientOptions& options);
+ ClientOptions parseClientOptions(const std::string& optionString);
+
+ private:
+ EventLoop* eventLoop_;
+ NetworkFactories* networkFactories_;
+ UIFactory* uiFactory_;
+ StoragesFactory* storagesFactory_;
+ Storages* storages_;
+ CertificateStorageFactory* certificateStorageFactory_;
+ CertificateStorage* certificateStorage_;
+ CertificateStorageTrustChecker* certificateTrustChecker_;
+ bool clientInitialized_;
+ boost::shared_ptr<Client> client_;
+ SettingsProvider *settings_;
+ ProfileSettingsProvider* profileSettings_;
+ Dock* dock_;
+ URIHandler* uriHandler_;
+ IdleDetector* idleDetector_;
+ TogglableNotifier* notifier_;
+ PresenceNotifier* presenceNotifier_;
+ EventNotifier* eventNotifier_;
+ RosterController* rosterController_;
+ EventController* eventController_;
+ EventWindowController* eventWindowController_;
+ AdHocManager* adHocManager_;
+ LoginWindow* loginWindow_;
+ UIEventStream* uiEventStream_;
+ XMLConsoleController* xmlConsoleController_;
+ HistoryViewController* historyViewController_;
+ HistoryController* historyController_;
+ FileTransferListController* fileTransferListController_;
+ BlockListController* blockListController_;
+ ChatsManager* chatsManager_;
+ ProfileController* profileController_;
+ ShowProfileController* showProfileController_;
+ ContactEditController* contactEditController_;
+ ContactsFromXMPPRoster* contactsFromRosterProvider_;
+ ContactSuggester* contactSuggesterWithoutRoster_;
+ ContactSuggester* contactSuggesterWithRoster_;
+ JID jid_;
+ JID boundJID_;
+ SystemTrayController* systemTrayController_;
+ SoundEventController* soundEventController_;
+ XMPPURIController* xmppURIController_;
+ std::string vCardPhotoHash_;
+ std::string password_;
+ CertificateWithKey::ref certificate_;
+ ClientOptions clientOptions_;
+ boost::shared_ptr<ErrorEvent> lastDisconnectError_;
+ bool useDelayForLatency_;
+ UserSearchController* userSearchControllerChat_;
+ UserSearchController* userSearchControllerAdd_;
+ UserSearchController* userSearchControllerInvite_;
+ int timeBeforeNextReconnect_;
+ Timer::ref reconnectTimer_;
+ StatusTracker* statusTracker_;
+ bool myStatusLooksOnline_;
+ bool quitRequested_;
+ bool offlineRequested_;
+ static const int SecondsToWaitBeforeForceQuitting;
+ FileTransferOverview* ftOverview_;
+ WhiteboardManager* whiteboardManager_;
+ HighlightManager* highlightManager_;
+ HighlightEditorController* highlightEditorController_;
+ std::map<std::string, std::string> emoticons_;
+ };
}
diff --git a/Swift/Controllers/PresenceNotifier.cpp b/Swift/Controllers/PresenceNotifier.cpp
index b579187..c000107 100644
--- a/Swift/Controllers/PresenceNotifier.cpp
+++ b/Swift/Controllers/PresenceNotifier.cpp
@@ -21,117 +21,117 @@
namespace Swift {
PresenceNotifier::PresenceNotifier(StanzaChannel* stanzaChannel, Notifier* notifier, const MUCRegistry* mucRegistry, AvatarManager* avatarManager, NickResolver* nickResolver, const PresenceOracle* presenceOracle, TimerFactory* timerFactory) : stanzaChannel(stanzaChannel), notifier(notifier), mucRegistry(mucRegistry), avatarManager(avatarManager), nickResolver(nickResolver), presenceOracle(presenceOracle), timerFactory(timerFactory) {
- justInitialized = true;
- inQuietPeriod = false;
- stanzaChannel->onPresenceReceived.connect(boost::bind(&PresenceNotifier::handlePresenceReceived, this, _1));
- stanzaChannel->onAvailableChanged.connect(boost::bind(&PresenceNotifier::handleStanzaChannelAvailableChanged, this, _1));
- setInitialQuietPeriodMS(3000);
+ justInitialized = true;
+ inQuietPeriod = false;
+ stanzaChannel->onPresenceReceived.connect(boost::bind(&PresenceNotifier::handlePresenceReceived, this, _1));
+ stanzaChannel->onAvailableChanged.connect(boost::bind(&PresenceNotifier::handleStanzaChannelAvailableChanged, this, _1));
+ setInitialQuietPeriodMS(3000);
}
PresenceNotifier::~PresenceNotifier() {
- if (timer) {
- timer->stop();
- timer->onTick.disconnect(boost::bind(&PresenceNotifier::handleTimerTick, this));
- timer.reset();
- }
- stanzaChannel->onAvailableChanged.disconnect(boost::bind(&PresenceNotifier::handleStanzaChannelAvailableChanged, this, _1));
- stanzaChannel->onPresenceReceived.disconnect(boost::bind(&PresenceNotifier::handlePresenceReceived, this, _1));
+ if (timer) {
+ timer->stop();
+ timer->onTick.disconnect(boost::bind(&PresenceNotifier::handleTimerTick, this));
+ timer.reset();
+ }
+ stanzaChannel->onAvailableChanged.disconnect(boost::bind(&PresenceNotifier::handleStanzaChannelAvailableChanged, this, _1));
+ stanzaChannel->onPresenceReceived.disconnect(boost::bind(&PresenceNotifier::handlePresenceReceived, this, _1));
}
void PresenceNotifier::handlePresenceReceived(boost::shared_ptr<Presence> presence) {
- JID from = presence->getFrom();
-
- if (mucRegistry->isMUC(from.toBare())) {
- return;
- }
-
- if (justInitialized) {
- justInitialized = false;
- if (timer) {
- inQuietPeriod = true;
- }
- }
-
- if (inQuietPeriod) {
- timer->stop();
- timer->start();
- return;
- }
-
- std::set<JID>::iterator i = availableUsers.find(from);
- if (presence->isAvailable()) {
- if (i != availableUsers.end()) {
- showNotification(from, Notifier::ContactStatusChange);
- }
- else {
- showNotification(from, Notifier::ContactAvailable);
- availableUsers.insert(from);
- }
- }
- else {
- if (i != availableUsers.end()) {
- showNotification(from, Notifier::ContactUnavailable);
- availableUsers.erase(i);
- }
- }
+ JID from = presence->getFrom();
+
+ if (mucRegistry->isMUC(from.toBare())) {
+ return;
+ }
+
+ if (justInitialized) {
+ justInitialized = false;
+ if (timer) {
+ inQuietPeriod = true;
+ }
+ }
+
+ if (inQuietPeriod) {
+ timer->stop();
+ timer->start();
+ return;
+ }
+
+ std::set<JID>::iterator i = availableUsers.find(from);
+ if (presence->isAvailable()) {
+ if (i != availableUsers.end()) {
+ showNotification(from, Notifier::ContactStatusChange);
+ }
+ else {
+ showNotification(from, Notifier::ContactAvailable);
+ availableUsers.insert(from);
+ }
+ }
+ else {
+ if (i != availableUsers.end()) {
+ showNotification(from, Notifier::ContactUnavailable);
+ availableUsers.erase(i);
+ }
+ }
}
void PresenceNotifier::handleStanzaChannelAvailableChanged(bool available) {
- if (available) {
- availableUsers.clear();
- justInitialized = true;
- if (timer) {
- timer->stop();
- }
- }
+ if (available) {
+ availableUsers.clear();
+ justInitialized = true;
+ if (timer) {
+ timer->stop();
+ }
+ }
}
void PresenceNotifier::showNotification(const JID& jid, Notifier::Type type) {
- std::string name = nickResolver->jidToNick(jid);
- std::string title = name + " (" + getStatusType(jid) + ")";
- std::string message = getStatusMessage(jid);
- notifier->showMessage(type, title, message, avatarManager->getAvatarPath(jid), boost::bind(&PresenceNotifier::handleNotificationActivated, this, jid));
+ std::string name = nickResolver->jidToNick(jid);
+ std::string title = name + " (" + getStatusType(jid) + ")";
+ std::string message = getStatusMessage(jid);
+ notifier->showMessage(type, title, message, avatarManager->getAvatarPath(jid), boost::bind(&PresenceNotifier::handleNotificationActivated, this, jid));
}
void PresenceNotifier::handleNotificationActivated(JID jid) {
- onNotificationActivated(jid);
+ onNotificationActivated(jid);
}
std::string PresenceNotifier::getStatusType(const JID& jid) const {
- Presence::ref presence = presenceOracle->getLastPresence(jid);
- if (presence) {
- return statusShowTypeToFriendlyName(presence->getShow());
- }
- else {
- return "Unavailable";
- }
+ Presence::ref presence = presenceOracle->getLastPresence(jid);
+ if (presence) {
+ return statusShowTypeToFriendlyName(presence->getShow());
+ }
+ else {
+ return "Unavailable";
+ }
}
std::string PresenceNotifier::getStatusMessage(const JID& jid) const {
- Presence::ref presence = presenceOracle->getLastPresence(jid);
- if (presence) {
- return presence->getStatus();
- }
- else {
- return std::string();
- }
+ Presence::ref presence = presenceOracle->getLastPresence(jid);
+ if (presence) {
+ return presence->getStatus();
+ }
+ else {
+ return std::string();
+ }
}
void PresenceNotifier::setInitialQuietPeriodMS(int ms) {
- if (timer) {
- timer->stop();
- timer->onTick.disconnect(boost::bind(&PresenceNotifier::handleTimerTick, this));
- timer.reset();
- }
- if (ms > 0) {
- timer = timerFactory->createTimer(ms);
- timer->onTick.connect(boost::bind(&PresenceNotifier::handleTimerTick, this));
- }
+ if (timer) {
+ timer->stop();
+ timer->onTick.disconnect(boost::bind(&PresenceNotifier::handleTimerTick, this));
+ timer.reset();
+ }
+ if (ms > 0) {
+ timer = timerFactory->createTimer(ms);
+ timer->onTick.connect(boost::bind(&PresenceNotifier::handleTimerTick, this));
+ }
}
void PresenceNotifier::handleTimerTick() {
- inQuietPeriod = false;
- timer->stop();
+ inQuietPeriod = false;
+ timer->stop();
}
diff --git a/Swift/Controllers/PresenceNotifier.h b/Swift/Controllers/PresenceNotifier.h
index b02f8a2..3d498bd 100644
--- a/Swift/Controllers/PresenceNotifier.h
+++ b/Swift/Controllers/PresenceNotifier.h
@@ -19,44 +19,44 @@
#include <SwifTools/Notifier/Notifier.h>
namespace Swift {
- class TimerFactory;
- class StanzaChannel;
- class MUCRegistry;
- class NickResolver;
- class PresenceOracle;
-
- class PresenceNotifier {
- public:
- PresenceNotifier(StanzaChannel* stanzaChannel, Notifier* notifier, const MUCRegistry* mucRegistry, AvatarManager* avatarManager, NickResolver* nickResolver, const PresenceOracle* presenceOracle, TimerFactory* timerFactory);
- ~PresenceNotifier();
-
- void setInitialQuietPeriodMS(int ms);
-
- boost::signal<void (const JID&)> onNotificationActivated;
-
- private:
- void handlePresenceReceived(boost::shared_ptr<Presence>);
- void handleStanzaChannelAvailableChanged(bool);
- void handleNotificationActivated(JID jid);
- void handleTimerTick();
- std::string getStatusType(const JID&) const;
- std::string getStatusMessage(const JID&) const;
-
- private:
- void showNotification(const JID& jid, Notifier::Type type);
-
- private:
- StanzaChannel* stanzaChannel;
- Notifier* notifier;
- const MUCRegistry* mucRegistry;
- AvatarManager* avatarManager;
- NickResolver* nickResolver;
- const PresenceOracle* presenceOracle;
- TimerFactory* timerFactory;
- boost::shared_ptr<Timer> timer;
- bool justInitialized;
- bool inQuietPeriod;
- std::set<JID> availableUsers;
- };
+ class TimerFactory;
+ class StanzaChannel;
+ class MUCRegistry;
+ class NickResolver;
+ class PresenceOracle;
+
+ class PresenceNotifier {
+ public:
+ PresenceNotifier(StanzaChannel* stanzaChannel, Notifier* notifier, const MUCRegistry* mucRegistry, AvatarManager* avatarManager, NickResolver* nickResolver, const PresenceOracle* presenceOracle, TimerFactory* timerFactory);
+ ~PresenceNotifier();
+
+ void setInitialQuietPeriodMS(int ms);
+
+ boost::signal<void (const JID&)> onNotificationActivated;
+
+ private:
+ void handlePresenceReceived(boost::shared_ptr<Presence>);
+ void handleStanzaChannelAvailableChanged(bool);
+ void handleNotificationActivated(JID jid);
+ void handleTimerTick();
+ std::string getStatusType(const JID&) const;
+ std::string getStatusMessage(const JID&) const;
+
+ private:
+ void showNotification(const JID& jid, Notifier::Type type);
+
+ private:
+ StanzaChannel* stanzaChannel;
+ Notifier* notifier;
+ const MUCRegistry* mucRegistry;
+ AvatarManager* avatarManager;
+ NickResolver* nickResolver;
+ const PresenceOracle* presenceOracle;
+ TimerFactory* timerFactory;
+ boost::shared_ptr<Timer> timer;
+ bool justInitialized;
+ bool inQuietPeriod;
+ std::set<JID> availableUsers;
+ };
}
diff --git a/Swift/Controllers/PreviousStatusStore.cpp b/Swift/Controllers/PreviousStatusStore.cpp
index 6564ab5..4806f9c 100644
--- a/Swift/Controllers/PreviousStatusStore.cpp
+++ b/Swift/Controllers/PreviousStatusStore.cpp
@@ -19,35 +19,35 @@ PreviousStatusStore::~PreviousStatusStore() {
}
void PreviousStatusStore::addStatus(StatusShow::Type status, const std::string& message) {
- //FIXME: remove old entries
- store_.push_back(TypeStringPair(status, message));
+ //FIXME: remove old entries
+ store_.push_back(TypeStringPair(status, message));
}
std::vector<TypeStringPair> PreviousStatusStore::exactMatchSuggestions(StatusShow::Type status, const std::string& message) {
- std::vector<TypeStringPair> suggestions;
- suggestions.push_back(TypeStringPair(status, message));
- return suggestions;
+ std::vector<TypeStringPair> suggestions;
+ suggestions.push_back(TypeStringPair(status, message));
+ return suggestions;
}
std::vector<TypeStringPair> PreviousStatusStore::getSuggestions(const std::string& message) {
- std::vector<TypeStringPair> suggestions;
- foreach (TypeStringPair status, store_) {
- if (status.second == message) {
- suggestions.clear();
- suggestions.push_back(status);
- break;
- } else if (status.second.find(message) != std::string::npos) {
- suggestions.push_back(status);
- }
- }
- if (suggestions.empty()) {
- TypeStringPair suggestion(StatusShow::Online, message);
- suggestions.push_back(suggestion);
- }
- if (suggestions.size() == 1) {
- suggestions = exactMatchSuggestions(suggestions[0].first, suggestions[0].second);
- }
- return suggestions;
+ std::vector<TypeStringPair> suggestions;
+ foreach (TypeStringPair status, store_) {
+ if (status.second == message) {
+ suggestions.clear();
+ suggestions.push_back(status);
+ break;
+ } else if (status.second.find(message) != std::string::npos) {
+ suggestions.push_back(status);
+ }
+ }
+ if (suggestions.empty()) {
+ TypeStringPair suggestion(StatusShow::Online, message);
+ suggestions.push_back(suggestion);
+ }
+ if (suggestions.size() == 1) {
+ suggestions = exactMatchSuggestions(suggestions[0].first, suggestions[0].second);
+ }
+ return suggestions;
}
}
diff --git a/Swift/Controllers/PreviousStatusStore.h b/Swift/Controllers/PreviousStatusStore.h
index 51c2dd9..eb1fb59 100644
--- a/Swift/Controllers/PreviousStatusStore.h
+++ b/Swift/Controllers/PreviousStatusStore.h
@@ -13,16 +13,16 @@
#include <Swiften/Elements/StatusShow.h>
namespace Swift {
- typedef std::pair<StatusShow::Type, std::string> TypeStringPair;
- class PreviousStatusStore {
- public:
- PreviousStatusStore();
- ~PreviousStatusStore();
- void addStatus(StatusShow::Type status, const std::string& message);
- std::vector<TypeStringPair> getSuggestions(const std::string& message);
+ typedef std::pair<StatusShow::Type, std::string> TypeStringPair;
+ class PreviousStatusStore {
+ public:
+ PreviousStatusStore();
+ ~PreviousStatusStore();
+ void addStatus(StatusShow::Type status, const std::string& message);
+ std::vector<TypeStringPair> getSuggestions(const std::string& message);
- private:
- std::vector<TypeStringPair> exactMatchSuggestions(StatusShow::Type status, const std::string& message);
- std::vector<TypeStringPair> store_;
- };
+ private:
+ std::vector<TypeStringPair> exactMatchSuggestions(StatusShow::Type status, const std::string& message);
+ std::vector<TypeStringPair> store_;
+ };
}
diff --git a/Swift/Controllers/ProfileController.cpp b/Swift/Controllers/ProfileController.cpp
index a1aa5f9..756aaff 100644
--- a/Swift/Controllers/ProfileController.cpp
+++ b/Swift/Controllers/ProfileController.cpp
@@ -18,97 +18,97 @@
namespace Swift {
ProfileController::ProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream) : vcardManager(vcardManager), profileWindowFactory(profileWindowFactory), uiEventStream(uiEventStream), available(true), profileWindow(NULL), gettingVCard(false) {
- uiEventStream->onUIEvent.connect(boost::bind(&ProfileController::handleUIEvent, this, _1));
+ uiEventStream->onUIEvent.connect(boost::bind(&ProfileController::handleUIEvent, this, _1));
}
ProfileController::~ProfileController() {
- if (profileWindow) {
- vcardManager->onOwnVCardChanged.disconnect(boost::bind(&ProfileController::handleOwnVCardChanged, this, _1));
- vcardManager->onVCardRetrievalError.disconnect(boost::bind(&ProfileController::handleVCardRetrievalError, this, _1, _2));
- profileWindow->onVCardChangeRequest.disconnect(boost::bind(&ProfileController::handleVCardChangeRequest, this, _1));
- profileWindow->onWindowAboutToBeClosed.disconnect(boost::bind(&ProfileController::handleProfileWindowAboutToBeClosed, this, _1));
- }
- uiEventStream->onUIEvent.disconnect(boost::bind(&ProfileController::handleUIEvent, this, _1));
- delete profileWindow;
+ if (profileWindow) {
+ vcardManager->onOwnVCardChanged.disconnect(boost::bind(&ProfileController::handleOwnVCardChanged, this, _1));
+ vcardManager->onVCardRetrievalError.disconnect(boost::bind(&ProfileController::handleVCardRetrievalError, this, _1, _2));
+ profileWindow->onVCardChangeRequest.disconnect(boost::bind(&ProfileController::handleVCardChangeRequest, this, _1));
+ profileWindow->onWindowAboutToBeClosed.disconnect(boost::bind(&ProfileController::handleProfileWindowAboutToBeClosed, this, _1));
+ }
+ uiEventStream->onUIEvent.disconnect(boost::bind(&ProfileController::handleUIEvent, this, _1));
+ delete profileWindow;
}
void ProfileController::handleUIEvent(UIEvent::ref event) {
- if (!boost::dynamic_pointer_cast<RequestProfileEditorUIEvent>(event)) {
- return;
- }
-
- if (!profileWindow) {
- profileWindow = profileWindowFactory->createProfileWindow();
- profileWindow->setEditable(true);
- profileWindow->onVCardChangeRequest.connect(boost::bind(&ProfileController::handleVCardChangeRequest, this, _1));
- profileWindow->onWindowAboutToBeClosed.connect(boost::bind(&ProfileController::handleProfileWindowAboutToBeClosed, this, _1));
- vcardManager->onOwnVCardChanged.connect(boost::bind(&ProfileController::handleOwnVCardChanged, this, _1));
- vcardManager->onVCardRetrievalError.connect(boost::bind(&ProfileController::handleVCardRetrievalError, this, _1, _2));
- }
- gettingVCard = true;
- updateDialogStatus();
- vcardManager->requestOwnVCard();
- profileWindow->show();
+ if (!boost::dynamic_pointer_cast<RequestProfileEditorUIEvent>(event)) {
+ return;
+ }
+
+ if (!profileWindow) {
+ profileWindow = profileWindowFactory->createProfileWindow();
+ profileWindow->setEditable(true);
+ profileWindow->onVCardChangeRequest.connect(boost::bind(&ProfileController::handleVCardChangeRequest, this, _1));
+ profileWindow->onWindowAboutToBeClosed.connect(boost::bind(&ProfileController::handleProfileWindowAboutToBeClosed, this, _1));
+ vcardManager->onOwnVCardChanged.connect(boost::bind(&ProfileController::handleOwnVCardChanged, this, _1));
+ vcardManager->onVCardRetrievalError.connect(boost::bind(&ProfileController::handleVCardRetrievalError, this, _1, _2));
+ }
+ gettingVCard = true;
+ updateDialogStatus();
+ vcardManager->requestOwnVCard();
+ profileWindow->show();
}
void ProfileController::handleVCardChangeRequest(VCard::ref vcard) {
- assert(!pendingSetVCardRequest);
- profileWindow->setError("");
- pendingSetVCardRequest = vcardManager->createSetVCardRequest(vcard);
- pendingSetVCardRequest->onResponse.connect(boost::bind(&ProfileController::handleSetVCardResponse, this, _2));
- pendingSetVCardRequest->send();
- updateDialogStatus();
+ assert(!pendingSetVCardRequest);
+ profileWindow->setError("");
+ pendingSetVCardRequest = vcardManager->createSetVCardRequest(vcard);
+ pendingSetVCardRequest->onResponse.connect(boost::bind(&ProfileController::handleSetVCardResponse, this, _2));
+ pendingSetVCardRequest->send();
+ updateDialogStatus();
}
void ProfileController::handleSetVCardResponse(ErrorPayload::ref error) {
- pendingSetVCardRequest.reset();
- updateDialogStatus();
- if (error) {
- profileWindow->setVCard(vcardBeforeEdit);
- profileWindow->setError(QT_TRANSLATE_NOOP("", "There was an error publishing your profile data"));
- }
- else {
- profileWindow->setError("");
- profileWindow->hide();
- }
+ pendingSetVCardRequest.reset();
+ updateDialogStatus();
+ if (error) {
+ profileWindow->setVCard(vcardBeforeEdit);
+ profileWindow->setError(QT_TRANSLATE_NOOP("", "There was an error publishing your profile data"));
+ }
+ else {
+ profileWindow->setError("");
+ profileWindow->hide();
+ }
}
void ProfileController::handleVCardRetrievalError(const JID& jid, ErrorPayload::ref /* error */) {
- if ((jid == JID()) && profileWindow) {
- profileWindow->setProcessing(false);
- profileWindow->setEnabled(false);
- profileWindow->setVCard(boost::make_shared<VCard>());
- profileWindow->setError(QT_TRANSLATE_NOOP("", "There was an error fetching your current profile data"));
- }
+ if ((jid == JID()) && profileWindow) {
+ profileWindow->setProcessing(false);
+ profileWindow->setEnabled(false);
+ profileWindow->setVCard(boost::make_shared<VCard>());
+ profileWindow->setError(QT_TRANSLATE_NOOP("", "There was an error fetching your current profile data"));
+ }
}
void ProfileController::handleOwnVCardChanged(VCard::ref vcard) {
- if (profileWindow) {
- profileWindow->setVCard(vcard);
- vcardBeforeEdit = vcard;
- gettingVCard = false;
- updateDialogStatus();
- }
+ if (profileWindow) {
+ profileWindow->setVCard(vcard);
+ vcardBeforeEdit = vcard;
+ gettingVCard = false;
+ updateDialogStatus();
+ }
}
void ProfileController::handleProfileWindowAboutToBeClosed(const JID&) {
- profileWindow = NULL;
+ profileWindow = NULL;
}
void ProfileController::setAvailable(bool b) {
- available = b;
- if (!available) {
- pendingSetVCardRequest.reset();
- }
- updateDialogStatus();
+ available = b;
+ if (!available) {
+ pendingSetVCardRequest.reset();
+ }
+ updateDialogStatus();
}
void ProfileController::updateDialogStatus() {
- if (profileWindow) {
- profileWindow->setEnabled(available && !gettingVCard && !pendingSetVCardRequest);
- profileWindow->setProcessing(gettingVCard || pendingSetVCardRequest);
- }
+ if (profileWindow) {
+ profileWindow->setEnabled(available && !gettingVCard && !pendingSetVCardRequest);
+ profileWindow->setProcessing(gettingVCard || pendingSetVCardRequest);
+ }
}
}
diff --git a/Swift/Controllers/ProfileController.h b/Swift/Controllers/ProfileController.h
index ebb569d..3bb1fce 100644
--- a/Swift/Controllers/ProfileController.h
+++ b/Swift/Controllers/ProfileController.h
@@ -13,36 +13,36 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class ProfileWindow;
- class ProfileWindowFactory;
- class UIEventStream;
- class VCardManager;
-
- class ProfileController {
- public:
- ProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream);
- ~ProfileController();
-
- void setAvailable(bool b);
-
- private:
- void handleUIEvent(UIEvent::ref event);
- void handleVCardChangeRequest(VCard::ref vcard);
- void handleSetVCardResponse(ErrorPayload::ref);
- void handleOwnVCardChanged(VCard::ref vcard);
- void handleVCardRetrievalError(const JID& jid, ErrorPayload::ref error);
- void handleProfileWindowAboutToBeClosed(const JID&);
- void updateDialogStatus();
-
- private:
- VCardManager* vcardManager;
- ProfileWindowFactory* profileWindowFactory;
- UIEventStream* uiEventStream;
- bool available;
- SetVCardRequest::ref pendingSetVCardRequest;
- ProfileWindow* profileWindow;
- bool gettingVCard;
- VCard::ref vcardBeforeEdit;
- };
+ class ProfileWindow;
+ class ProfileWindowFactory;
+ class UIEventStream;
+ class VCardManager;
+
+ class ProfileController {
+ public:
+ ProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream);
+ ~ProfileController();
+
+ void setAvailable(bool b);
+
+ private:
+ void handleUIEvent(UIEvent::ref event);
+ void handleVCardChangeRequest(VCard::ref vcard);
+ void handleSetVCardResponse(ErrorPayload::ref);
+ void handleOwnVCardChanged(VCard::ref vcard);
+ void handleVCardRetrievalError(const JID& jid, ErrorPayload::ref error);
+ void handleProfileWindowAboutToBeClosed(const JID&);
+ void updateDialogStatus();
+
+ private:
+ VCardManager* vcardManager;
+ ProfileWindowFactory* profileWindowFactory;
+ UIEventStream* uiEventStream;
+ bool available;
+ SetVCardRequest::ref pendingSetVCardRequest;
+ ProfileWindow* profileWindow;
+ bool gettingVCard;
+ VCard::ref vcardBeforeEdit;
+ };
}
diff --git a/Swift/Controllers/ProfileSettingsProvider.cpp b/Swift/Controllers/ProfileSettingsProvider.cpp
index 86f4c99..bb186fc 100644
--- a/Swift/Controllers/ProfileSettingsProvider.cpp
+++ b/Swift/Controllers/ProfileSettingsProvider.cpp
@@ -9,58 +9,58 @@
namespace Swift {
ProfileSettingsProvider::ProfileSettingsProvider(const std::string& profile, SettingsProvider* provider) :
- profile_(profile) {
- provider_ = provider;
- bool found = false;
- foreach (std::string existingProfile, provider->getAvailableProfiles()) {
- if (existingProfile == profile) {
- found = true;
- }
- }
- if (!found) {
- provider_->createProfile(profile);
- }
+ profile_(profile) {
+ provider_ = provider;
+ bool found = false;
+ foreach (std::string existingProfile, provider->getAvailableProfiles()) {
+ if (existingProfile == profile) {
+ found = true;
+ }
+ }
+ if (!found) {
+ provider_->createProfile(profile);
+ }
}
ProfileSettingsProvider::~ProfileSettingsProvider() {
}
std::string ProfileSettingsProvider::getStringSetting(const std::string &settingPath) {
- //FIXME: Remove shim
- SettingsProvider::Setting<std::string> setting(profileSettingPath(settingPath), "");
- return provider_->getSetting(setting);
+ //FIXME: Remove shim
+ SettingsProvider::Setting<std::string> setting(profileSettingPath(settingPath), "");
+ return provider_->getSetting(setting);
}
void ProfileSettingsProvider::storeString(const std::string &settingPath, const std::string &settingValue) {
- //FIXME: Remove shim
- if (!getIsSettingFinal(settingPath)) {
- SettingsProvider::Setting<std::string> setting(profileSettingPath(settingPath), "");
- provider_->storeSetting(setting, settingValue);
- }
+ //FIXME: Remove shim
+ if (!getIsSettingFinal(settingPath)) {
+ SettingsProvider::Setting<std::string> setting(profileSettingPath(settingPath), "");
+ provider_->storeSetting(setting, settingValue);
+ }
}
int ProfileSettingsProvider::getIntSetting(const std::string& settingPath, int defaultValue) {
- //FIXME: Remove shim
- SettingsProvider::Setting<int> setting(profileSettingPath(settingPath), defaultValue);
- return provider_->getSetting(setting);
+ //FIXME: Remove shim
+ SettingsProvider::Setting<int> setting(profileSettingPath(settingPath), defaultValue);
+ return provider_->getSetting(setting);
}
void ProfileSettingsProvider::storeInt(const std::string& settingPath, int settingValue) {
- //FIXME: Remove shim
- if (!getIsSettingFinal(settingPath)) {
- SettingsProvider::Setting<int> setting(profileSettingPath(settingPath), 0);
- provider_->storeSetting(setting, settingValue);
- }
+ //FIXME: Remove shim
+ if (!getIsSettingFinal(settingPath)) {
+ SettingsProvider::Setting<int> setting(profileSettingPath(settingPath), 0);
+ provider_->storeSetting(setting, settingValue);
+ }
}
bool ProfileSettingsProvider::getIsSettingFinal(const std::string& settingPath) {
- //FIXME: Remove shim
- SettingsProvider::Setting<int> setting(settingPath, 0);
- return provider_->getIsSettingFinal(setting);
+ //FIXME: Remove shim
+ SettingsProvider::Setting<int> setting(settingPath, 0);
+ return provider_->getIsSettingFinal(setting);
}
std::string ProfileSettingsProvider::profileSettingPath(const std::string &settingPath) {
- return profile_ + ":" + settingPath;
+ return profile_ + ":" + settingPath;
}
diff --git a/Swift/Controllers/ProfileSettingsProvider.h b/Swift/Controllers/ProfileSettingsProvider.h
index 02e1e81..f3c3156 100644
--- a/Swift/Controllers/ProfileSettingsProvider.h
+++ b/Swift/Controllers/ProfileSettingsProvider.h
@@ -13,20 +13,20 @@
namespace Swift {
class ProfileSettingsProvider {
- public:
- ProfileSettingsProvider(const std::string& profile, SettingsProvider* provider);
- virtual ~ProfileSettingsProvider();
- virtual std::string getStringSetting(const std::string &settingPath);
- virtual void storeString(const std::string &settingPath, const std::string &settingValue);
- virtual int getIntSetting(const std::string& settingPath, int defaultValue);
- virtual void storeInt(const std::string& settingPath, int settingValue);
- /** See \ref SettingsProvider::getIsSettingFinal for discussion of what this means.*/
- virtual bool getIsSettingFinal(const std::string& settingPath);
-
- private:
- std::string profileSettingPath(const std::string &settingPath);
- SettingsProvider* provider_;
- std::string profile_;
+ public:
+ ProfileSettingsProvider(const std::string& profile, SettingsProvider* provider);
+ virtual ~ProfileSettingsProvider();
+ virtual std::string getStringSetting(const std::string &settingPath);
+ virtual void storeString(const std::string &settingPath, const std::string &settingValue);
+ virtual int getIntSetting(const std::string& settingPath, int defaultValue);
+ virtual void storeInt(const std::string& settingPath, int settingValue);
+ /** See \ref SettingsProvider::getIsSettingFinal for discussion of what this means.*/
+ virtual bool getIsSettingFinal(const std::string& settingPath);
+
+ private:
+ std::string profileSettingPath(const std::string &settingPath);
+ SettingsProvider* provider_;
+ std::string profile_;
};
}
diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp
index 3258fb5..89053e6 100644
--- a/Swift/Controllers/Roster/ContactRosterItem.cpp
+++ b/Swift/Controllers/Roster/ContactRosterItem.cpp
@@ -27,149 +27,149 @@ ContactRosterItem::~ContactRosterItem() {
}
StatusShow::Type ContactRosterItem::getStatusShow() const {
- return presence_ ? presence_->getShow() : StatusShow::None;
+ return presence_ ? presence_->getShow() : StatusShow::None;
}
StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const {
- switch (presence_ ? presence_->getShow() : StatusShow::None) {
- case StatusShow::Online: return StatusShow::Online;
- case StatusShow::Away: return StatusShow::Away;
- case StatusShow::XA: return StatusShow::Away;
- case StatusShow::FFC: return StatusShow::Online;
- case StatusShow::DND: return StatusShow::DND;
- case StatusShow::None: return StatusShow::None;
- }
- assert(false);
- return StatusShow::None;
+ switch (presence_ ? presence_->getShow() : StatusShow::None) {
+ case StatusShow::Online: return StatusShow::Online;
+ case StatusShow::Away: return StatusShow::Away;
+ case StatusShow::XA: return StatusShow::Away;
+ case StatusShow::FFC: return StatusShow::Online;
+ case StatusShow::DND: return StatusShow::DND;
+ case StatusShow::None: return StatusShow::None;
+ }
+ assert(false);
+ return StatusShow::None;
}
std::string ContactRosterItem::getStatusText() const {
- return presence_ ? presence_->getStatus() : "";
+ return presence_ ? presence_->getStatus() : "";
}
std::string ContactRosterItem::getIdleText() const {
- Idle::ref idle = presence_ ? presence_->getPayload<Idle>() : Idle::ref();
- if (!idle || idle->getSince().is_not_a_date_time()) {
- return "";
- } else {
- return dateTimeToLocalString(idle->getSince());
- }
+ Idle::ref idle = presence_ ? presence_->getPayload<Idle>() : Idle::ref();
+ if (!idle || idle->getSince().is_not_a_date_time()) {
+ return "";
+ } else {
+ return dateTimeToLocalString(idle->getSince());
+ }
}
std::string ContactRosterItem::getOfflineSinceText() const {
- if (presence_ && presence_->getType() == Presence::Unavailable) {
- boost::optional<boost::posix_time::ptime> delay = presence_->getTimestamp();
- if (delay) {
- return dateTimeToLocalString(*delay);
- }
- }
- return "";
+ if (presence_ && presence_->getType() == Presence::Unavailable) {
+ boost::optional<boost::posix_time::ptime> delay = presence_->getTimestamp();
+ if (delay) {
+ return dateTimeToLocalString(*delay);
+ }
+ }
+ return "";
}
void ContactRosterItem::setAvatarPath(const boost::filesystem::path& path) {
- avatarPath_ = path;
- onDataChanged();
+ avatarPath_ = path;
+ onDataChanged();
}
const boost::filesystem::path& ContactRosterItem::getAvatarPath() const {
- return avatarPath_;
+ return avatarPath_;
}
const JID& ContactRosterItem::getJID() const {
- return jid_;
+ return jid_;
}
void ContactRosterItem::setDisplayJID(const JID& jid) {
- displayJID_ = jid;
+ displayJID_ = jid;
}
const JID& ContactRosterItem::getDisplayJID() const {
- return displayJID_;
+ return displayJID_;
}
typedef std::pair<std::string, boost::shared_ptr<Presence> > StringPresencePair;
void ContactRosterItem::clearPresence() {
- presence_.reset();
- onDataChanged();
+ presence_.reset();
+ onDataChanged();
}
void ContactRosterItem::applyPresence(boost::shared_ptr<Presence> presence) {
- presence_ = presence;
- onDataChanged();
+ presence_ = presence;
+ onDataChanged();
}
const std::vector<std::string>& ContactRosterItem::getGroups() const {
- return groups_;
+ return groups_;
}
/** Only used so a contact can know about the groups it's in*/
void ContactRosterItem::addGroup(const std::string& group) {
- groups_.push_back(group);
+ groups_.push_back(group);
}
void ContactRosterItem::removeGroup(const std::string& group) {
- groups_.erase(std::remove(groups_.begin(), groups_.end(), group), groups_.end());
+ groups_.erase(std::remove(groups_.begin(), groups_.end(), group), groups_.end());
}
MUCOccupant::Role ContactRosterItem::getMUCRole() const
{
- return mucRole_;
+ return mucRole_;
}
void ContactRosterItem::setMUCRole(const MUCOccupant::Role& role)
{
- mucRole_ = role;
+ mucRole_ = role;
}
MUCOccupant::Affiliation ContactRosterItem::getMUCAffiliation() const
{
- return mucAffiliation_;
+ return mucAffiliation_;
}
void ContactRosterItem::setMUCAffiliation(const MUCOccupant::Affiliation& affiliation)
{
- mucAffiliation_ = affiliation;
+ mucAffiliation_ = affiliation;
}
std::string ContactRosterItem::getMUCAffiliationText() const
{
- std::string affiliationString;
- switch (mucAffiliation_) {
- case MUCOccupant::Owner: affiliationString = QT_TRANSLATE_NOOP("", "Owner"); break;
- case MUCOccupant::Admin: affiliationString = QT_TRANSLATE_NOOP("", "Admin"); break;
- case MUCOccupant::Member: affiliationString = QT_TRANSLATE_NOOP("", "Member"); break;
- case MUCOccupant::Outcast: affiliationString = QT_TRANSLATE_NOOP("", "Outcast"); break;
- case MUCOccupant::NoAffiliation: affiliationString = ""; break;
- }
+ std::string affiliationString;
+ switch (mucAffiliation_) {
+ case MUCOccupant::Owner: affiliationString = QT_TRANSLATE_NOOP("", "Owner"); break;
+ case MUCOccupant::Admin: affiliationString = QT_TRANSLATE_NOOP("", "Admin"); break;
+ case MUCOccupant::Member: affiliationString = QT_TRANSLATE_NOOP("", "Member"); break;
+ case MUCOccupant::Outcast: affiliationString = QT_TRANSLATE_NOOP("", "Outcast"); break;
+ case MUCOccupant::NoAffiliation: affiliationString = ""; break;
+ }
- return affiliationString;
+ return affiliationString;
}
void ContactRosterItem::setSupportedFeatures(const std::set<Feature>& features) {
- features_ = features;
- onDataChanged();
+ features_ = features;
+ onDataChanged();
}
bool ContactRosterItem::supportsFeature(const Feature feature) const {
- return features_.find(feature) != features_.end();
+ return features_.find(feature) != features_.end();
}
void ContactRosterItem::setBlockState(BlockState state) {
- blockState_ = state;
- onDataChanged();
+ blockState_ = state;
+ onDataChanged();
}
ContactRosterItem::BlockState ContactRosterItem::blockState() const {
- return blockState_;
+ return blockState_;
}
VCard::ref ContactRosterItem::getVCard() const {
- return vcard_;
+ return vcard_;
}
void ContactRosterItem::setVCard(VCard::ref vcard) {
- vcard_ = vcard;
- onDataChanged();
+ vcard_ = vcard;
+ onDataChanged();
}
}
diff --git a/Swift/Controllers/Roster/ContactRosterItem.h b/Swift/Controllers/Roster/ContactRosterItem.h
index d21935c..d77ba2d 100644
--- a/Swift/Controllers/Roster/ContactRosterItem.h
+++ b/Swift/Controllers/Roster/ContactRosterItem.h
@@ -28,69 +28,69 @@ namespace Swift {
class GroupRosterItem;
class ContactRosterItem : public RosterItem {
- public:
- enum Feature {
- FileTransferFeature,
- WhiteboardFeature
- };
-
- enum BlockState {
- BlockingNotSupported,
- IsBlocked,
- IsUnblocked,
- IsDomainBlocked
- };
-
- public:
- ContactRosterItem(const JID& jid, const JID& displayJID, const std::string& name, GroupRosterItem* parent);
- virtual ~ContactRosterItem();
-
- StatusShow::Type getStatusShow() const;
- StatusShow::Type getSimplifiedStatusShow() const;
- std::string getStatusText() const;
- std::string getIdleText() const;
- std::string getOfflineSinceText() const;
- void setAvatarPath(const boost::filesystem::path& path);
- const boost::filesystem::path& getAvatarPath() const;
- const JID& getJID() const;
- void setDisplayJID(const JID& jid);
- const JID& getDisplayJID() const;
- void applyPresence(boost::shared_ptr<Presence> presence);
- const std::vector<std::string>& getGroups() const;
- /** Only used so a contact can know about the groups it's in*/
- void addGroup(const std::string& group);
- void removeGroup(const std::string& group);
- void clearPresence();
-
- MUCOccupant::Role getMUCRole() const;
- void setMUCRole(const MUCOccupant::Role& role);
- MUCOccupant::Affiliation getMUCAffiliation() const;
- void setMUCAffiliation(const MUCOccupant::Affiliation& affiliation);
- std::string getMUCAffiliationText() const;
-
- void setSupportedFeatures(const std::set<Feature>& features);
- bool supportsFeature(Feature feature) const;
-
- void setBlockState(BlockState state);
- BlockState blockState() const;
-
- VCard::ref getVCard() const;
- void setVCard(VCard::ref vcard);
-
- boost::signal<void ()> onVCardRequested;
-
- private:
- JID jid_;
- JID displayJID_;
- boost::posix_time::ptime lastAvailableTime_;
- boost::filesystem::path avatarPath_;
- boost::shared_ptr<Presence> presence_;
- std::vector<std::string> groups_;
- MUCOccupant::Role mucRole_;
- MUCOccupant::Affiliation mucAffiliation_;
- std::set<Feature> features_;
- BlockState blockState_;
- VCard::ref vcard_;
+ public:
+ enum Feature {
+ FileTransferFeature,
+ WhiteboardFeature
+ };
+
+ enum BlockState {
+ BlockingNotSupported,
+ IsBlocked,
+ IsUnblocked,
+ IsDomainBlocked
+ };
+
+ public:
+ ContactRosterItem(const JID& jid, const JID& displayJID, const std::string& name, GroupRosterItem* parent);
+ virtual ~ContactRosterItem();
+
+ StatusShow::Type getStatusShow() const;
+ StatusShow::Type getSimplifiedStatusShow() const;
+ std::string getStatusText() const;
+ std::string getIdleText() const;
+ std::string getOfflineSinceText() const;
+ void setAvatarPath(const boost::filesystem::path& path);
+ const boost::filesystem::path& getAvatarPath() const;
+ const JID& getJID() const;
+ void setDisplayJID(const JID& jid);
+ const JID& getDisplayJID() const;
+ void applyPresence(boost::shared_ptr<Presence> presence);
+ const std::vector<std::string>& getGroups() const;
+ /** Only used so a contact can know about the groups it's in*/
+ void addGroup(const std::string& group);
+ void removeGroup(const std::string& group);
+ void clearPresence();
+
+ MUCOccupant::Role getMUCRole() const;
+ void setMUCRole(const MUCOccupant::Role& role);
+ MUCOccupant::Affiliation getMUCAffiliation() const;
+ void setMUCAffiliation(const MUCOccupant::Affiliation& affiliation);
+ std::string getMUCAffiliationText() const;
+
+ void setSupportedFeatures(const std::set<Feature>& features);
+ bool supportsFeature(Feature feature) const;
+
+ void setBlockState(BlockState state);
+ BlockState blockState() const;
+
+ VCard::ref getVCard() const;
+ void setVCard(VCard::ref vcard);
+
+ boost::signal<void ()> onVCardRequested;
+
+ private:
+ JID jid_;
+ JID displayJID_;
+ boost::posix_time::ptime lastAvailableTime_;
+ boost::filesystem::path avatarPath_;
+ boost::shared_ptr<Presence> presence_;
+ std::vector<std::string> groups_;
+ MUCOccupant::Role mucRole_;
+ MUCOccupant::Affiliation mucAffiliation_;
+ std::set<Feature> features_;
+ BlockState blockState_;
+ VCard::ref vcard_;
};
}
diff --git a/Swift/Controllers/Roster/FuzzyRosterFilter.h b/Swift/Controllers/Roster/FuzzyRosterFilter.h
index 14e0f62..8c45935 100644
--- a/Swift/Controllers/Roster/FuzzyRosterFilter.h
+++ b/Swift/Controllers/Roster/FuzzyRosterFilter.h
@@ -22,21 +22,21 @@
namespace Swift {
class FuzzyRosterFilter : public RosterFilter {
- public:
- FuzzyRosterFilter(const std::string& query) : query_(query) { }
- virtual ~FuzzyRosterFilter() {}
- virtual bool operator() (RosterItem* item) const {
- ContactRosterItem *contactItem = dynamic_cast<ContactRosterItem*>(item);
- if (contactItem) {
- const bool itemMatched = ContactSuggester::fuzzyMatch(contactItem->getDisplayName(), query_) || ContactSuggester::fuzzyMatch(contactItem->getDisplayJID(), query_);
- return !itemMatched;
- } else {
- return false;
- }
- }
-
- private:
- std::string query_;
+ public:
+ FuzzyRosterFilter(const std::string& query) : query_(query) { }
+ virtual ~FuzzyRosterFilter() {}
+ virtual bool operator() (RosterItem* item) const {
+ ContactRosterItem *contactItem = dynamic_cast<ContactRosterItem*>(item);
+ if (contactItem) {
+ const bool itemMatched = ContactSuggester::fuzzyMatch(contactItem->getDisplayName(), query_) || ContactSuggester::fuzzyMatch(contactItem->getDisplayJID(), query_);
+ return !itemMatched;
+ } else {
+ return false;
+ }
+ }
+
+ private:
+ std::string query_;
};
}
diff --git a/Swift/Controllers/Roster/GroupRosterItem.cpp b/Swift/Controllers/Roster/GroupRosterItem.cpp
index 6c68851..82e43df 100644
--- a/Swift/Controllers/Roster/GroupRosterItem.cpp
+++ b/Swift/Controllers/Roster/GroupRosterItem.cpp
@@ -12,7 +12,7 @@
namespace Swift {
GroupRosterItem::GroupRosterItem(const std::string& name, GroupRosterItem* parent, bool sortByStatus) : RosterItem(name, parent), sortByStatus_(sortByStatus), manualSort_(false) {
- expanded_ = true;
+ expanded_ = true;
}
GroupRosterItem::~GroupRosterItem() {
@@ -20,77 +20,77 @@ GroupRosterItem::~GroupRosterItem() {
}
void GroupRosterItem::setManualSort(const std::string& manualSortValue) {
- manualSort_ = true;
- bool changed = manualSortValue_ != manualSortValue;
- manualSortValue_ = manualSortValue;
- if (changed) {
- onChildrenChanged();
- onDataChanged();
- }
+ manualSort_ = true;
+ bool changed = manualSortValue_ != manualSortValue;
+ manualSortValue_ = manualSortValue;
+ if (changed) {
+ onChildrenChanged();
+ onDataChanged();
+ }
}
const std::string& GroupRosterItem::getSortableDisplayName() const {
- return manualSort_ ? manualSortValue_ : RosterItem::getSortableDisplayName();
+ return manualSort_ ? manualSortValue_ : RosterItem::getSortableDisplayName();
}
bool GroupRosterItem::isExpanded() const {
- return expanded_;
+ return expanded_;
}
/**
- This has no effect, and is only used by the UI.
- If reTransmit is specified, dataChanged will be emitted on a change -
- This may be undesireable if called from the UI, so you can use reTransmit=false
- to avoid a loop in this case.
+ This has no effect, and is only used by the UI.
+ If reTransmit is specified, dataChanged will be emitted on a change -
+ This may be undesireable if called from the UI, so you can use reTransmit=false
+ to avoid a loop in this case.
*/
void GroupRosterItem::setExpanded(bool expanded) {
- bool old = expanded_;
- expanded_ = expanded;
- if (expanded != old) {
- onExpandedChanged(expanded);
- }
+ bool old = expanded_;
+ expanded_ = expanded;
+ if (expanded != old) {
+ onExpandedChanged(expanded);
+ }
}
const std::vector<RosterItem*>& GroupRosterItem::getChildren() const {
- return children_;
+ return children_;
}
const std::vector<RosterItem*>& GroupRosterItem::getDisplayedChildren() const {
- return displayedChildren_;
+ return displayedChildren_;
}
void GroupRosterItem::addChild(RosterItem* item) {
- children_.push_back(item);
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- group->onChildrenChanged.connect(boost::bind(&GroupRosterItem::handleChildrenChanged, this, group));
- } else {
- item->onDataChanged.connect(boost::bind(&GroupRosterItem::handleDataChanged, this, item));
- }
- onChildrenChanged();
- onDataChanged();
+ children_.push_back(item);
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
+ if (group) {
+ group->onChildrenChanged.connect(boost::bind(&GroupRosterItem::handleChildrenChanged, this, group));
+ } else {
+ item->onDataChanged.connect(boost::bind(&GroupRosterItem::handleDataChanged, this, item));
+ }
+ onChildrenChanged();
+ onDataChanged();
}
/**
* Does not emit a changed signal.
*/
void GroupRosterItem::removeAll() {
- std::vector<RosterItem*>::iterator it = children_.begin();
- displayedChildren_.clear();
- while (it != children_.end()) {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(*it);
- if (contact) {
- delete contact;
- } else {
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
- if (group) {
- group->removeAll();
- delete group;
- }
- }
- ++it;
- }
- children_.clear();
+ std::vector<RosterItem*>::iterator it = children_.begin();
+ displayedChildren_.clear();
+ while (it != children_.end()) {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(*it);
+ if (contact) {
+ delete contact;
+ } else {
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
+ if (group) {
+ group->removeAll();
+ delete group;
+ }
+ }
+ ++it;
+ }
+ children_.clear();
}
/**
@@ -98,136 +98,136 @@ void GroupRosterItem::removeAll() {
* the return result is undefined.
*/
ContactRosterItem* GroupRosterItem::removeChild(const JID& jid) {
- std::vector<RosterItem*>::iterator it = children_.begin();
- ContactRosterItem* removed = NULL;
- while (it != children_.end()) {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(*it);
- if (contact && contact->getJID() == jid) {
- displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), contact), displayedChildren_.end());
- removed = contact;
- delete contact;
- it = children_.erase(it);
- continue;
- }
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
- if (group) {
- ContactRosterItem* groupRemoved = group->removeChild(jid);
- if (groupRemoved) {
- removed = groupRemoved;
- }
- }
- ++it;
- }
- onChildrenChanged();
- onDataChanged();
- return removed;
+ std::vector<RosterItem*>::iterator it = children_.begin();
+ ContactRosterItem* removed = NULL;
+ while (it != children_.end()) {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(*it);
+ if (contact && contact->getJID() == jid) {
+ displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), contact), displayedChildren_.end());
+ removed = contact;
+ delete contact;
+ it = children_.erase(it);
+ continue;
+ }
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
+ if (group) {
+ ContactRosterItem* groupRemoved = group->removeChild(jid);
+ if (groupRemoved) {
+ removed = groupRemoved;
+ }
+ }
+ ++it;
+ }
+ onChildrenChanged();
+ onDataChanged();
+ return removed;
}
GroupRosterItem* GroupRosterItem::removeGroupChild(const std::string& groupName) {
- std::vector<RosterItem*>::iterator it = children_.begin();
- GroupRosterItem* removed = NULL;
- while (it != children_.end()) {
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
- if (group && group->getDisplayName() == groupName) {
- displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), group), displayedChildren_.end());
- removed = group;
- delete group;
- it = children_.erase(it);
- continue;
- }
- ++it;
- }
- onChildrenChanged();
- onDataChanged();
- return removed;
+ std::vector<RosterItem*>::iterator it = children_.begin();
+ GroupRosterItem* removed = NULL;
+ while (it != children_.end()) {
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
+ if (group && group->getDisplayName() == groupName) {
+ displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), group), displayedChildren_.end());
+ removed = group;
+ delete group;
+ it = children_.erase(it);
+ continue;
+ }
+ ++it;
+ }
+ onChildrenChanged();
+ onDataChanged();
+ return removed;
}
/**
* Returns false if the list didn't need a resort
*/
bool GroupRosterItem::sortDisplayed() {
- /* Not doing this until we import boost::algorithm*/
-// if (boost::is_sorted(displayedChildren_begin(), displayedChildren_.end(), itemLessThan)) {
-// return false;
-// }
- //Sholudn't need stable_sort here
- std::sort(displayedChildren_.begin(), displayedChildren_.end(), sortByStatus_? itemLessThanWithStatus : itemLessThanWithoutStatus);
- return true;
+ /* Not doing this until we import boost::algorithm*/
+// if (boost::is_sorted(displayedChildren_begin(), displayedChildren_.end(), itemLessThan)) {
+// return false;
+// }
+ //Sholudn't need stable_sort here
+ std::sort(displayedChildren_.begin(), displayedChildren_.end(), sortByStatus_? itemLessThanWithStatus : itemLessThanWithoutStatus);
+ return true;
}
bool GroupRosterItem::itemLessThanWithoutStatus(const RosterItem* left, const RosterItem* right) {
- return left->getSortableDisplayName() < right->getSortableDisplayName();
+ return left->getSortableDisplayName() < right->getSortableDisplayName();
}
bool GroupRosterItem::itemLessThanWithStatus(const RosterItem* left, const RosterItem* right) {
- const ContactRosterItem* leftContact = dynamic_cast<const ContactRosterItem*>(left);
- const ContactRosterItem* rightContact = dynamic_cast<const ContactRosterItem*>(right);
- if (leftContact) {
- if (!rightContact) {
- return false;
- }
- StatusShow::Type leftType = leftContact->getSimplifiedStatusShow();
- StatusShow::Type rightType = rightContact->getSimplifiedStatusShow();
- if (leftType == rightType) {
- return left->getSortableDisplayName() < right->getSortableDisplayName();
- } else {
- return leftType < rightType;
- }
- } else {
- if (rightContact) {
- return true;
- }
- return left->getSortableDisplayName() < right->getSortableDisplayName();
- }
+ const ContactRosterItem* leftContact = dynamic_cast<const ContactRosterItem*>(left);
+ const ContactRosterItem* rightContact = dynamic_cast<const ContactRosterItem*>(right);
+ if (leftContact) {
+ if (!rightContact) {
+ return false;
+ }
+ StatusShow::Type leftType = leftContact->getSimplifiedStatusShow();
+ StatusShow::Type rightType = rightContact->getSimplifiedStatusShow();
+ if (leftType == rightType) {
+ return left->getSortableDisplayName() < right->getSortableDisplayName();
+ } else {
+ return leftType < rightType;
+ }
+ } else {
+ if (rightContact) {
+ return true;
+ }
+ return left->getSortableDisplayName() < right->getSortableDisplayName();
+ }
}
void GroupRosterItem::setDisplayed(RosterItem* item, bool displayed) {
- bool found = false;
- for (size_t i = 0; i < displayedChildren_.size(); i++) {
- if (displayedChildren_[i] == item) {
- found = true;
- }
- }
- if (found == displayed) {
- return;
- }
- if (displayed) {
- displayedChildren_.push_back(item);
- sortDisplayed();
- } else {
- displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), item), displayedChildren_.end());
- }
- onChildrenChanged();
- onDataChanged();
+ bool found = false;
+ for (size_t i = 0; i < displayedChildren_.size(); i++) {
+ if (displayedChildren_[i] == item) {
+ found = true;
+ }
+ }
+ if (found == displayed) {
+ return;
+ }
+ if (displayed) {
+ displayedChildren_.push_back(item);
+ sortDisplayed();
+ } else {
+ displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), item), displayedChildren_.end());
+ }
+ onChildrenChanged();
+ onDataChanged();
}
void GroupRosterItem::handleDataChanged(RosterItem* /*item*/) {
- if (sortDisplayed()) {
- onChildrenChanged();
- }
+ if (sortDisplayed()) {
+ onChildrenChanged();
+ }
}
void GroupRosterItem::handleChildrenChanged(GroupRosterItem* group) {
- size_t oldSize = getDisplayedChildren().size();
- if (group->getDisplayedChildren().size() > 0) {
- bool found = false;
- for (size_t i = 0; i < displayedChildren_.size(); i++) {
- if (displayedChildren_[i] == group) {
- found = true;
- }
- }
- if (!found) {
- displayedChildren_.push_back(group);
- sortDisplayed();
- }
- } else {
- displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), group), displayedChildren_.end());
- }
-
- if (oldSize != getDisplayedChildren().size() || sortDisplayed()) {
- onChildrenChanged();
- onDataChanged();
- }
+ size_t oldSize = getDisplayedChildren().size();
+ if (group->getDisplayedChildren().size() > 0) {
+ bool found = false;
+ for (size_t i = 0; i < displayedChildren_.size(); i++) {
+ if (displayedChildren_[i] == group) {
+ found = true;
+ }
+ }
+ if (!found) {
+ displayedChildren_.push_back(group);
+ sortDisplayed();
+ }
+ } else {
+ displayedChildren_.erase(std::remove(displayedChildren_.begin(), displayedChildren_.end(), group), displayedChildren_.end());
+ }
+
+ if (oldSize != getDisplayedChildren().size() || sortDisplayed()) {
+ onChildrenChanged();
+ onDataChanged();
+ }
}
diff --git a/Swift/Controllers/Roster/GroupRosterItem.h b/Swift/Controllers/Roster/GroupRosterItem.h
index 9b4024f..760b008 100644
--- a/Swift/Controllers/Roster/GroupRosterItem.h
+++ b/Swift/Controllers/Roster/GroupRosterItem.h
@@ -15,35 +15,35 @@
namespace Swift {
class GroupRosterItem : public RosterItem {
- public:
- GroupRosterItem(const std::string& name, GroupRosterItem* parent, bool sortByStatus);
- virtual ~GroupRosterItem();
- const std::vector<RosterItem*>& getChildren() const;
- const std::vector<RosterItem*>& getDisplayedChildren() const;
- void addChild(RosterItem* item);
- ContactRosterItem* removeChild(const JID& jid);
- GroupRosterItem* removeGroupChild(const std::string& group);
- void removeAll();
- void setDisplayed(RosterItem* item, bool displayed);
- boost::signal<void ()> onChildrenChanged;
- static bool itemLessThanWithStatus(const RosterItem* left, const RosterItem* right);
- static bool itemLessThanWithoutStatus(const RosterItem* left, const RosterItem* right);
- void setExpanded(bool expanded);
- bool isExpanded() const;
- boost::signal<void (bool)> onExpandedChanged;
- void setManualSort(const std::string& manualSortValue);
- virtual const std::string& getSortableDisplayName() const;
- private:
- void handleChildrenChanged(GroupRosterItem* group);
- void handleDataChanged(RosterItem* item);
- bool sortDisplayed();
- std::string name_;
- bool expanded_;
- std::vector<RosterItem*> children_;
- std::vector<RosterItem*> displayedChildren_;
- bool sortByStatus_;
- bool manualSort_;
- std::string manualSortValue_;
+ public:
+ GroupRosterItem(const std::string& name, GroupRosterItem* parent, bool sortByStatus);
+ virtual ~GroupRosterItem();
+ const std::vector<RosterItem*>& getChildren() const;
+ const std::vector<RosterItem*>& getDisplayedChildren() const;
+ void addChild(RosterItem* item);
+ ContactRosterItem* removeChild(const JID& jid);
+ GroupRosterItem* removeGroupChild(const std::string& group);
+ void removeAll();
+ void setDisplayed(RosterItem* item, bool displayed);
+ boost::signal<void ()> onChildrenChanged;
+ static bool itemLessThanWithStatus(const RosterItem* left, const RosterItem* right);
+ static bool itemLessThanWithoutStatus(const RosterItem* left, const RosterItem* right);
+ void setExpanded(bool expanded);
+ bool isExpanded() const;
+ boost::signal<void (bool)> onExpandedChanged;
+ void setManualSort(const std::string& manualSortValue);
+ virtual const std::string& getSortableDisplayName() const;
+ private:
+ void handleChildrenChanged(GroupRosterItem* group);
+ void handleDataChanged(RosterItem* item);
+ bool sortDisplayed();
+ std::string name_;
+ bool expanded_;
+ std::vector<RosterItem*> children_;
+ std::vector<RosterItem*> displayedChildren_;
+ bool sortByStatus_;
+ bool manualSort_;
+ std::string manualSortValue_;
};
}
diff --git a/Swift/Controllers/Roster/ItemOperations/AppearOffline.h b/Swift/Controllers/Roster/ItemOperations/AppearOffline.h
index e59e01b..c57974b 100644
--- a/Swift/Controllers/Roster/ItemOperations/AppearOffline.h
+++ b/Swift/Controllers/Roster/ItemOperations/AppearOffline.h
@@ -14,16 +14,16 @@ namespace Swift {
class RosterItem;
class AppearOffline : public RosterItemOperation {
- public:
- AppearOffline() {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact) {
- contact->clearPresence();
- }
- }
+ public:
+ AppearOffline() {
+ }
+
+ virtual void operator() (RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact) {
+ contact->clearPresence();
+ }
+ }
};
diff --git a/Swift/Controllers/Roster/ItemOperations/RosterItemOperation.h b/Swift/Controllers/Roster/ItemOperations/RosterItemOperation.h
index 833c863..76227c0 100644
--- a/Swift/Controllers/Roster/ItemOperations/RosterItemOperation.h
+++ b/Swift/Controllers/Roster/ItemOperations/RosterItemOperation.h
@@ -11,20 +11,20 @@
namespace Swift {
class RosterItemOperation {
- public:
- RosterItemOperation(bool requiresLookup = false, const JID& lookupJID = JID()) : requiresLookup_(requiresLookup), lookupJID_(lookupJID) {}
- virtual ~RosterItemOperation() {}
- bool requiresLookup() const {return requiresLookup_;}
- const JID& lookupJID() const {return lookupJID_;}
- /**
- * This is called when iterating over possible subjects, so must check it's
- * applying to the right items - even if requiresLookup() is true an item
- * with the same bare JID but different full JID may be passed.
- */
- virtual void operator() (RosterItem*) const = 0;
- private:
- bool requiresLookup_;
- JID lookupJID_;
+ public:
+ RosterItemOperation(bool requiresLookup = false, const JID& lookupJID = JID()) : requiresLookup_(requiresLookup), lookupJID_(lookupJID) {}
+ virtual ~RosterItemOperation() {}
+ bool requiresLookup() const {return requiresLookup_;}
+ const JID& lookupJID() const {return lookupJID_;}
+ /**
+ * This is called when iterating over possible subjects, so must check it's
+ * applying to the right items - even if requiresLookup() is true an item
+ * with the same bare JID but different full JID may be passed.
+ */
+ virtual void operator() (RosterItem*) const = 0;
+ private:
+ bool requiresLookup_;
+ JID lookupJID_;
};
}
diff --git a/Swift/Controllers/Roster/ItemOperations/SetAvailableFeatures.h b/Swift/Controllers/Roster/ItemOperations/SetAvailableFeatures.h
index b19b95a..29f9722 100644
--- a/Swift/Controllers/Roster/ItemOperations/SetAvailableFeatures.h
+++ b/Swift/Controllers/Roster/ItemOperations/SetAvailableFeatures.h
@@ -22,21 +22,21 @@ namespace Swift {
class RosterItem;
class SetAvailableFeatures : public RosterItemOperation {
- public:
- SetAvailableFeatures(const JID& jid, const std::set<ContactRosterItem::Feature>& availableFeatures, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), availableFeatures_(availableFeatures), compareType_(compareType) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(jid_, compareType_)) {
- contact->setSupportedFeatures(availableFeatures_);
- }
- }
-
- private:
- JID jid_;
- std::set<ContactRosterItem::Feature> availableFeatures_;
- JID::CompareType compareType_;
+ public:
+ SetAvailableFeatures(const JID& jid, const std::set<ContactRosterItem::Feature>& availableFeatures, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), availableFeatures_(availableFeatures), compareType_(compareType) {
+ }
+
+ virtual void operator() (RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact && contact->getJID().equals(jid_, compareType_)) {
+ contact->setSupportedFeatures(availableFeatures_);
+ }
+ }
+
+ private:
+ JID jid_;
+ std::set<ContactRosterItem::Feature> availableFeatures_;
+ JID::CompareType compareType_;
};
}
diff --git a/Swift/Controllers/Roster/ItemOperations/SetAvatar.h b/Swift/Controllers/Roster/ItemOperations/SetAvatar.h
index 211321e..d47c921 100644
--- a/Swift/Controllers/Roster/ItemOperations/SetAvatar.h
+++ b/Swift/Controllers/Roster/ItemOperations/SetAvatar.h
@@ -19,21 +19,21 @@ namespace Swift {
class RosterItem;
class SetAvatar : public RosterItemOperation {
- public:
- SetAvatar(const JID& jid, const boost::filesystem::path& path, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), path_(path), compareType_(compareType) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(jid_, compareType_)) {
- contact->setAvatarPath(path_);
- }
- }
-
- private:
- JID jid_;
- boost::filesystem::path path_;
- JID::CompareType compareType_;
+ public:
+ SetAvatar(const JID& jid, const boost::filesystem::path& path, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), path_(path), compareType_(compareType) {
+ }
+
+ virtual void operator() (RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact && contact->getJID().equals(jid_, compareType_)) {
+ contact->setAvatarPath(path_);
+ }
+ }
+
+ private:
+ JID jid_;
+ boost::filesystem::path path_;
+ JID::CompareType compareType_;
};
}
diff --git a/Swift/Controllers/Roster/ItemOperations/SetBlockingState.h b/Swift/Controllers/Roster/ItemOperations/SetBlockingState.h
index 098eeb5..818d9b4 100644
--- a/Swift/Controllers/Roster/ItemOperations/SetBlockingState.h
+++ b/Swift/Controllers/Roster/ItemOperations/SetBlockingState.h
@@ -22,30 +22,30 @@ namespace Swift {
class RosterItem;
class SetBlockingState : public RosterItemOperation {
- public:
- SetBlockingState(const JID& jid, ContactRosterItem::BlockState state, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(!jid.getNode().empty(), jid), jid_(jid), state_(state), compareType_(compareType) {
- if (state_ == ContactRosterItem::IsBlocked && jid.getNode().empty()) {
- state_ = ContactRosterItem::IsDomainBlocked;
- }
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (jid_.getNode().empty()) {
- if (contact && contact->getJID().getDomain() == jid_.getDomain()) {
- contact->setBlockState(state_);
- }
- } else {
- if (contact && contact->getJID().equals(jid_, compareType_)) {
- contact->setBlockState(state_);
- }
- }
- }
-
- private:
- JID jid_;
- ContactRosterItem::BlockState state_;
- JID::CompareType compareType_;
+ public:
+ SetBlockingState(const JID& jid, ContactRosterItem::BlockState state, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(!jid.getNode().empty(), jid), jid_(jid), state_(state), compareType_(compareType) {
+ if (state_ == ContactRosterItem::IsBlocked && jid.getNode().empty()) {
+ state_ = ContactRosterItem::IsDomainBlocked;
+ }
+ }
+
+ virtual void operator() (RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (jid_.getNode().empty()) {
+ if (contact && contact->getJID().getDomain() == jid_.getDomain()) {
+ contact->setBlockState(state_);
+ }
+ } else {
+ if (contact && contact->getJID().equals(jid_, compareType_)) {
+ contact->setBlockState(state_);
+ }
+ }
+ }
+
+ private:
+ JID jid_;
+ ContactRosterItem::BlockState state_;
+ JID::CompareType compareType_;
};
}
diff --git a/Swift/Controllers/Roster/ItemOperations/SetMUC.h b/Swift/Controllers/Roster/ItemOperations/SetMUC.h
index 8a4a0c6..7640c24 100644
--- a/Swift/Controllers/Roster/ItemOperations/SetMUC.h
+++ b/Swift/Controllers/Roster/ItemOperations/SetMUC.h
@@ -16,23 +16,23 @@ namespace Swift {
class RosterItem;
class SetMUC : public RosterItemOperation {
- public:
- SetMUC(const JID& jid, const MUCOccupant::Role& role, const MUCOccupant::Affiliation& affiliation)
- : RosterItemOperation(true, jid), jid_(jid), mucRole_(role), mucAffiliation_(affiliation) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(jid_, JID::WithResource)) {
- contact->setMUCRole(mucRole_);
- contact->setMUCAffiliation(mucAffiliation_);
- }
- }
-
- private:
- JID jid_;
- MUCOccupant::Role mucRole_;
- MUCOccupant::Affiliation mucAffiliation_;
+ public:
+ SetMUC(const JID& jid, const MUCOccupant::Role& role, const MUCOccupant::Affiliation& affiliation)
+ : RosterItemOperation(true, jid), jid_(jid), mucRole_(role), mucAffiliation_(affiliation) {
+ }
+
+ virtual void operator() (RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact && contact->getJID().equals(jid_, JID::WithResource)) {
+ contact->setMUCRole(mucRole_);
+ contact->setMUCAffiliation(mucAffiliation_);
+ }
+ }
+
+ private:
+ JID jid_;
+ MUCOccupant::Role mucRole_;
+ MUCOccupant::Affiliation mucAffiliation_;
};
}
diff --git a/Swift/Controllers/Roster/ItemOperations/SetName.h b/Swift/Controllers/Roster/ItemOperations/SetName.h
index 9f8a0b9..fa0694d 100644
--- a/Swift/Controllers/Roster/ItemOperations/SetName.h
+++ b/Swift/Controllers/Roster/ItemOperations/SetName.h
@@ -16,21 +16,21 @@ namespace Swift {
class RosterItem;
class SetName : public RosterItemOperation {
- public:
- SetName(const std::string& name, const JID& jid, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), name_(name), jid_(jid), compareType_(compareType) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(jid_, compareType_)) {
- contact->setDisplayName(name_);
- }
- }
-
- private:
- std::string name_;
- JID jid_;
- JID::CompareType compareType_;
+ public:
+ SetName(const std::string& name, const JID& jid, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), name_(name), jid_(jid), compareType_(compareType) {
+ }
+
+ virtual void operator() (RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact && contact->getJID().equals(jid_, compareType_)) {
+ contact->setDisplayName(name_);
+ }
+ }
+
+ private:
+ std::string name_;
+ JID jid_;
+ JID::CompareType compareType_;
};
}
diff --git a/Swift/Controllers/Roster/ItemOperations/SetPresence.h b/Swift/Controllers/Roster/ItemOperations/SetPresence.h
index 2b5bbbe..fc39e5c 100644
--- a/Swift/Controllers/Roster/ItemOperations/SetPresence.h
+++ b/Swift/Controllers/Roster/ItemOperations/SetPresence.h
@@ -17,20 +17,20 @@ namespace Swift {
class RosterItem;
class SetPresence : public RosterItemOperation {
- public:
- SetPresence(Presence::ref presence, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, compareType == JID::WithoutResource ? presence->getFrom().toBare() : presence->getFrom()), presence_(presence), compareType_(compareType) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(presence_->getFrom(), compareType_)) {
- contact->applyPresence(presence_);
- }
- }
-
- private:
- Presence::ref presence_;
- JID::CompareType compareType_;
+ public:
+ SetPresence(Presence::ref presence, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, compareType == JID::WithoutResource ? presence->getFrom().toBare() : presence->getFrom()), presence_(presence), compareType_(compareType) {
+ }
+
+ virtual void operator() (RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact && contact->getJID().equals(presence_->getFrom(), compareType_)) {
+ contact->applyPresence(presence_);
+ }
+ }
+
+ private:
+ Presence::ref presence_;
+ JID::CompareType compareType_;
};
}
diff --git a/Swift/Controllers/Roster/ItemOperations/SetVCard.h b/Swift/Controllers/Roster/ItemOperations/SetVCard.h
index e1744b9..278ae56 100644
--- a/Swift/Controllers/Roster/ItemOperations/SetVCard.h
+++ b/Swift/Controllers/Roster/ItemOperations/SetVCard.h
@@ -23,21 +23,21 @@ namespace Swift {
class RosterItem;
class SetVCard : public RosterItemOperation {
- public:
- SetVCard(const JID& jid, VCard::ref vcard, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), vcard_(vcard), compareType_(compareType) {
- }
-
- virtual void operator() (RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && contact->getJID().equals(jid_, compareType_)) {
- contact->setVCard(vcard_);
- }
- }
-
- private:
- JID jid_;
- VCard::ref vcard_;
- JID::CompareType compareType_;
+ public:
+ SetVCard(const JID& jid, VCard::ref vcard, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), vcard_(vcard), compareType_(compareType) {
+ }
+
+ virtual void operator() (RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact && contact->getJID().equals(jid_, compareType_)) {
+ contact->setVCard(vcard_);
+ }
+ }
+
+ private:
+ JID jid_;
+ VCard::ref vcard_;
+ JID::CompareType compareType_;
};
}
diff --git a/Swift/Controllers/Roster/LeastCommonSubsequence.h b/Swift/Controllers/Roster/LeastCommonSubsequence.h
index e7b9370..8daa20c 100644
--- a/Swift/Controllers/Roster/LeastCommonSubsequence.h
+++ b/Swift/Controllers/Roster/LeastCommonSubsequence.h
@@ -11,98 +11,98 @@
#include <boost/numeric/conversion/cast.hpp>
namespace Swift {
- using std::equal_to;
+ using std::equal_to;
- namespace Detail {
- template<typename XIt, typename YIt, typename Length, typename Predicate>
- void computeLeastCommonSubsequenceMatrix(XIt xBegin, XIt xEnd, YIt yBegin, YIt yEnd, std::vector<Length>& result) {
- size_t width = static_cast<size_t>(std::distance(xBegin, xEnd) + 1);
- size_t height = static_cast<size_t>(std::distance(yBegin, yEnd) + 1);
- result.resize(width * height);
+ namespace Detail {
+ template<typename XIt, typename YIt, typename Length, typename Predicate>
+ void computeLeastCommonSubsequenceMatrix(XIt xBegin, XIt xEnd, YIt yBegin, YIt yEnd, std::vector<Length>& result) {
+ size_t width = static_cast<size_t>(std::distance(xBegin, xEnd) + 1);
+ size_t height = static_cast<size_t>(std::distance(yBegin, yEnd) + 1);
+ result.resize(width * height);
- // Initialize first row & column
- for (size_t i = 0; i < width; ++i) {
- result[i] = 0;
- }
- for (size_t j = 0; j < height; ++j) {
- result[j*width] = 0;
- }
+ // Initialize first row & column
+ for (size_t i = 0; i < width; ++i) {
+ result[i] = 0;
+ }
+ for (size_t j = 0; j < height; ++j) {
+ result[j*width] = 0;
+ }
- // Compute the LCS lengths for subsets
- Predicate predicate;
- for (size_t i = 1; i < width; ++i) {
- for (size_t j = 1; j < height; ++j) {
- result[i + j*width] = predicate(*(xBegin + boost::numeric_cast<long long>(i)-1), *(yBegin + boost::numeric_cast<long long >(j)-1)) ? result[(i-1) + (j-1)*width] + 1 : std::max(result[i + (j-1)*width], result[i-1 + (j*width)]);
- }
- }
- }
- }
+ // Compute the LCS lengths for subsets
+ Predicate predicate;
+ for (size_t i = 1; i < width; ++i) {
+ for (size_t j = 1; j < height; ++j) {
+ result[i + j*width] = predicate(*(xBegin + boost::numeric_cast<long long>(i)-1), *(yBegin + boost::numeric_cast<long long >(j)-1)) ? result[(i-1) + (j-1)*width] + 1 : std::max(result[i + (j-1)*width], result[i-1 + (j*width)]);
+ }
+ }
+ }
+ }
- template<typename X, typename InsertRemovePredicate, typename UpdatePredicate>
- void computeIndexDiff(const std::vector<X>& x, const std::vector<X>& y, std::vector<size_t>& updates, std::vector<size_t>& postUpdates, std::vector<size_t>& removes, std::vector<size_t>& inserts) {
- InsertRemovePredicate insertRemovePredicate;
- UpdatePredicate updatePredicate;
+ template<typename X, typename InsertRemovePredicate, typename UpdatePredicate>
+ void computeIndexDiff(const std::vector<X>& x, const std::vector<X>& y, std::vector<size_t>& updates, std::vector<size_t>& postUpdates, std::vector<size_t>& removes, std::vector<size_t>& inserts) {
+ InsertRemovePredicate insertRemovePredicate;
+ UpdatePredicate updatePredicate;
- // Find & handle common prefix (Optimization to reduce LCS matrix size)
- typename std::vector<X>::const_iterator xBegin = x.begin();
- typename std::vector<X>::const_iterator yBegin = y.begin();
- while (xBegin < x.end() && yBegin < y.end() && insertRemovePredicate(*xBegin, *yBegin)) {
- if (updatePredicate(*xBegin, *yBegin)) {
- updates.push_back(static_cast<size_t>(std::distance(x.begin(), xBegin)));
- postUpdates.push_back(static_cast<size_t>(std::distance(y.begin(), yBegin)));
- }
- ++xBegin;
- ++yBegin;
- }
- size_t prefixLength = static_cast<size_t>(std::distance(x.begin(), xBegin));
+ // Find & handle common prefix (Optimization to reduce LCS matrix size)
+ typename std::vector<X>::const_iterator xBegin = x.begin();
+ typename std::vector<X>::const_iterator yBegin = y.begin();
+ while (xBegin < x.end() && yBegin < y.end() && insertRemovePredicate(*xBegin, *yBegin)) {
+ if (updatePredicate(*xBegin, *yBegin)) {
+ updates.push_back(static_cast<size_t>(std::distance(x.begin(), xBegin)));
+ postUpdates.push_back(static_cast<size_t>(std::distance(y.begin(), yBegin)));
+ }
+ ++xBegin;
+ ++yBegin;
+ }
+ size_t prefixLength = static_cast<size_t>(std::distance(x.begin(), xBegin));
- // Find & handle common suffix (Optimization to reduce LCS matrix size)
- typename std::vector<X>::const_reverse_iterator xEnd = x.rbegin();
- typename std::vector<X>::const_reverse_iterator yEnd = y.rbegin();
- while (xEnd.base() > xBegin && yEnd.base() > yBegin && insertRemovePredicate(*xEnd, *yEnd)) {
- if (updatePredicate(*xEnd, *yEnd)) {
- updates.push_back(static_cast<size_t>(std::distance(x.begin(), xEnd.base()) - 1));
- postUpdates.push_back(static_cast<size_t>(std::distance(y.begin(), yEnd.base()) - 1));
- }
- ++xEnd;
- ++yEnd;
- }
+ // Find & handle common suffix (Optimization to reduce LCS matrix size)
+ typename std::vector<X>::const_reverse_iterator xEnd = x.rbegin();
+ typename std::vector<X>::const_reverse_iterator yEnd = y.rbegin();
+ while (xEnd.base() > xBegin && yEnd.base() > yBegin && insertRemovePredicate(*xEnd, *yEnd)) {
+ if (updatePredicate(*xEnd, *yEnd)) {
+ updates.push_back(static_cast<size_t>(std::distance(x.begin(), xEnd.base()) - 1));
+ postUpdates.push_back(static_cast<size_t>(std::distance(y.begin(), yEnd.base()) - 1));
+ }
+ ++xEnd;
+ ++yEnd;
+ }
- // Compute lengths
- size_t xLength = static_cast<size_t>(std::distance(xBegin, xEnd.base()));
- size_t yLength = static_cast<size_t>(std::distance(yBegin, yEnd.base()));
+ // Compute lengths
+ size_t xLength = static_cast<size_t>(std::distance(xBegin, xEnd.base()));
+ size_t yLength = static_cast<size_t>(std::distance(yBegin, yEnd.base()));
- // Compute LCS matrix
- std::vector<unsigned int> lcs;
- Detail::computeLeastCommonSubsequenceMatrix<typename std::vector<X>::const_iterator, typename std::vector<X>::const_iterator, unsigned int, InsertRemovePredicate>(xBegin, xEnd.base(), yBegin, yEnd.base(), lcs);
+ // Compute LCS matrix
+ std::vector<unsigned int> lcs;
+ Detail::computeLeastCommonSubsequenceMatrix<typename std::vector<X>::const_iterator, typename std::vector<X>::const_iterator, unsigned int, InsertRemovePredicate>(xBegin, xEnd.base(), yBegin, yEnd.base(), lcs);
- // Process LCS matrix
- size_t i = xLength;
- size_t j = yLength;
- size_t width = xLength + 1;
- while (true) {
- if (i > 0 && j > 0 && insertRemovePredicate(x[prefixLength + i-1], y[prefixLength + j-1])) {
- // x[i-1] same
- if (updatePredicate(x[prefixLength + i - 1], y[prefixLength + j - 1])) {
- updates.push_back(prefixLength + i-1);
- postUpdates.push_back(prefixLength + j-1);
- }
- i -= 1;
- j -= 1;
- }
- else if (j > 0 && (i == 0 || lcs[i + (j-1)*width] >= lcs[i-1 + j*width])) {
- // y[j-1] added
- inserts.push_back(prefixLength + j-1);
- j -= 1;
- }
- else if (i > 0 && (j == 0 || lcs[i + (j-1)*width] < lcs[i-1 + j*width])) {
- // x[i-1] removed
- removes.push_back(prefixLength + i-1);
- i -= 1;
- }
- else {
- break;
- }
- }
- }
+ // Process LCS matrix
+ size_t i = xLength;
+ size_t j = yLength;
+ size_t width = xLength + 1;
+ while (true) {
+ if (i > 0 && j > 0 && insertRemovePredicate(x[prefixLength + i-1], y[prefixLength + j-1])) {
+ // x[i-1] same
+ if (updatePredicate(x[prefixLength + i - 1], y[prefixLength + j - 1])) {
+ updates.push_back(prefixLength + i-1);
+ postUpdates.push_back(prefixLength + j-1);
+ }
+ i -= 1;
+ j -= 1;
+ }
+ else if (j > 0 && (i == 0 || lcs[i + (j-1)*width] >= lcs[i-1 + j*width])) {
+ // y[j-1] added
+ inserts.push_back(prefixLength + j-1);
+ j -= 1;
+ }
+ else if (i > 0 && (j == 0 || lcs[i + (j-1)*width] < lcs[i-1 + j*width])) {
+ // x[i-1] removed
+ removes.push_back(prefixLength + i-1);
+ i -= 1;
+ }
+ else {
+ break;
+ }
+ }
+ }
}
diff --git a/Swift/Controllers/Roster/OfflineRosterFilter.h b/Swift/Controllers/Roster/OfflineRosterFilter.h
index d25d073..033eecb 100644
--- a/Swift/Controllers/Roster/OfflineRosterFilter.h
+++ b/Swift/Controllers/Roster/OfflineRosterFilter.h
@@ -15,12 +15,12 @@
namespace Swift {
class OfflineRosterFilter : public RosterFilter {
- public:
- virtual ~OfflineRosterFilter() {}
- virtual bool operator() (RosterItem *item) const {
- ContactRosterItem *contactItem = dynamic_cast<ContactRosterItem*>(item);
- return contactItem && contactItem->getStatusShow() == StatusShow::None;
- }
+ public:
+ virtual ~OfflineRosterFilter() {}
+ virtual bool operator() (RosterItem *item) const {
+ ContactRosterItem *contactItem = dynamic_cast<ContactRosterItem*>(item);
+ return contactItem && contactItem->getStatusShow() == StatusShow::None;
+ }
};
}
diff --git a/Swift/Controllers/Roster/Roster.cpp b/Swift/Controllers/Roster/Roster.cpp
index 77d6b78..2e68fd4 100644
--- a/Swift/Controllers/Roster/Roster.cpp
+++ b/Swift/Controllers/Roster/Roster.cpp
@@ -23,252 +23,252 @@
namespace Swift {
Roster::Roster(bool sortByStatus, bool fullJIDMapping) : blockingSupported_(false) {
- sortByStatus_ = sortByStatus;
- fullJIDMapping_ = fullJIDMapping;
- root_ = new GroupRosterItem("Dummy-Root", NULL, sortByStatus_);
- root_->onChildrenChanged.connect(boost::bind(&Roster::handleChildrenChanged, this, root_));
+ sortByStatus_ = sortByStatus;
+ fullJIDMapping_ = fullJIDMapping;
+ root_ = new GroupRosterItem("Dummy-Root", NULL, sortByStatus_);
+ root_->onChildrenChanged.connect(boost::bind(&Roster::handleChildrenChanged, this, root_));
}
Roster::~Roster() {
- std::deque<RosterItem*> queue;
- queue.push_back(root_);
- while (!queue.empty()) {
- RosterItem* item = *queue.begin();
- queue.pop_front();
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
- }
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact) {
- contact->onVCardRequested.disconnect(boost::bind(boost::ref(onVCardUpdateRequested), contact->getJID()));
- }
- delete item;
- }
+ std::deque<RosterItem*> queue;
+ queue.push_back(root_);
+ while (!queue.empty()) {
+ RosterItem* item = *queue.begin();
+ queue.pop_front();
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
+ if (group) {
+ queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
+ }
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact) {
+ contact->onVCardRequested.disconnect(boost::bind(boost::ref(onVCardUpdateRequested), contact->getJID()));
+ }
+ delete item;
+ }
}
GroupRosterItem* Roster::getRoot() const {
- return root_;
+ return root_;
}
std::set<JID> Roster::getJIDs() const {
- std::set<JID> jids;
-
- std::deque<RosterItem*> queue;
- queue.push_back(root_);
- while (!queue.empty()) {
- RosterItem* item = *queue.begin();
- queue.pop_front();
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- ContactRosterItem *contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact) {
- jids.insert(contact->getJID());
- jids.insert(contact->getDisplayJID());
- }
- else if (group) {
- queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
- }
- }
-
- return jids;
+ std::set<JID> jids;
+
+ std::deque<RosterItem*> queue;
+ queue.push_back(root_);
+ while (!queue.empty()) {
+ RosterItem* item = *queue.begin();
+ queue.pop_front();
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
+ ContactRosterItem *contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact) {
+ jids.insert(contact->getJID());
+ jids.insert(contact->getDisplayJID());
+ }
+ else if (group) {
+ queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
+ }
+ }
+
+ return jids;
}
GroupRosterItem* Roster::getGroup(const std::string& groupName) {
- foreach (RosterItem *item, root_->getChildren()) {
- GroupRosterItem *group = dynamic_cast<GroupRosterItem*>(item);
- if (group && group->getDisplayName() == groupName) {
- return group;
- }
- }
- GroupRosterItem* group = new GroupRosterItem(groupName, root_, sortByStatus_);
- root_->addChild(group);
- group->onChildrenChanged.connect(boost::bind(&Roster::handleChildrenChanged, this, group));
- group->onDataChanged.connect(boost::bind(&Roster::handleDataChanged, this, group));
- return group;
+ foreach (RosterItem *item, root_->getChildren()) {
+ GroupRosterItem *group = dynamic_cast<GroupRosterItem*>(item);
+ if (group && group->getDisplayName() == groupName) {
+ return group;
+ }
+ }
+ GroupRosterItem* group = new GroupRosterItem(groupName, root_, sortByStatus_);
+ root_->addChild(group);
+ group->onChildrenChanged.connect(boost::bind(&Roster::handleChildrenChanged, this, group));
+ group->onDataChanged.connect(boost::bind(&Roster::handleDataChanged, this, group));
+ return group;
}
void Roster::setBlockingSupported(bool isSupported) {
- if (!blockingSupported_) {
- foreach(ItemMap::value_type i, itemMap_) {
- foreach(ContactRosterItem* item, i.second) {
- item->setBlockState(ContactRosterItem::IsUnblocked);
- }
- }
- }
- blockingSupported_ = isSupported;
+ if (!blockingSupported_) {
+ foreach(ItemMap::value_type i, itemMap_) {
+ foreach(ContactRosterItem* item, i.second) {
+ item->setBlockState(ContactRosterItem::IsUnblocked);
+ }
+ }
+ }
+ blockingSupported_ = isSupported;
}
void Roster::removeGroup(const std::string& group) {
- root_->removeGroupChild(group);
+ root_->removeGroupChild(group);
}
void Roster::handleDataChanged(RosterItem* item) {
- onDataChanged(item);
+ onDataChanged(item);
}
void Roster::handleChildrenChanged(GroupRosterItem* item) {
- onChildrenChanged(item);
+ onChildrenChanged(item);
}
void Roster::addContact(const JID& jid, const JID& displayJID, const std::string& name, const std::string& groupName, const boost::filesystem::path& avatarPath) {
- GroupRosterItem* group(getGroup(groupName));
- ContactRosterItem *item = new ContactRosterItem(jid, displayJID, name, group);
- item->onVCardRequested.connect(boost::bind(boost::ref(onVCardUpdateRequested), jid));
- item->setAvatarPath(avatarPath);
- if (blockingSupported_) {
- item->setBlockState(ContactRosterItem::IsUnblocked);
- }
- group->addChild(item);
- ItemMap::iterator i = itemMap_.insert(std::make_pair(fullJIDMapping_ ? jid : jid.toBare(), std::vector<ContactRosterItem*>())).first;
- if (!i->second.empty()) {
- foreach (const std::string& existingGroup, i->second[0]->getGroups()) {
- item->addGroup(existingGroup);
- }
- }
- i->second.push_back(item);
- item->onDataChanged.connect(boost::bind(&Roster::handleDataChanged, this, item));
- filterContact(item, group);
-
- foreach (ContactRosterItem* item, i->second) {
- item->addGroup(groupName);
- }
+ GroupRosterItem* group(getGroup(groupName));
+ ContactRosterItem *item = new ContactRosterItem(jid, displayJID, name, group);
+ item->onVCardRequested.connect(boost::bind(boost::ref(onVCardUpdateRequested), jid));
+ item->setAvatarPath(avatarPath);
+ if (blockingSupported_) {
+ item->setBlockState(ContactRosterItem::IsUnblocked);
+ }
+ group->addChild(item);
+ ItemMap::iterator i = itemMap_.insert(std::make_pair(fullJIDMapping_ ? jid : jid.toBare(), std::vector<ContactRosterItem*>())).first;
+ if (!i->second.empty()) {
+ foreach (const std::string& existingGroup, i->second[0]->getGroups()) {
+ item->addGroup(existingGroup);
+ }
+ }
+ i->second.push_back(item);
+ item->onDataChanged.connect(boost::bind(&Roster::handleDataChanged, this, item));
+ filterContact(item, group);
+
+ foreach (ContactRosterItem* item, i->second) {
+ item->addGroup(groupName);
+ }
}
struct JIDEqualsTo {
- JIDEqualsTo(const JID& jid) : jid(jid) {}
- bool operator()(ContactRosterItem* i) const { return jid == i->getJID(); }
- JID jid;
+ JIDEqualsTo(const JID& jid) : jid(jid) {}
+ bool operator()(ContactRosterItem* i) const { return jid == i->getJID(); }
+ JID jid;
};
void Roster::removeAll() {
- root_->removeAll();
- itemMap_.clear();
- onChildrenChanged(root_);
- onDataChanged(root_);
+ root_->removeAll();
+ itemMap_.clear();
+ onChildrenChanged(root_);
+ onDataChanged(root_);
}
void Roster::removeContact(const JID& jid) {
- ItemMap::iterator item = itemMap_.find(fullJIDMapping_ ? jid : jid.toBare());
- if (item != itemMap_.end()) {
- std::vector<ContactRosterItem*>& items = item->second;
- items.erase(std::remove_if(items.begin(), items.end(), JIDEqualsTo(jid)), items.end());
- if (items.empty()) {
- itemMap_.erase(item);
- }
- }
- //Causes the delete
- root_->removeChild(jid);
+ ItemMap::iterator item = itemMap_.find(fullJIDMapping_ ? jid : jid.toBare());
+ if (item != itemMap_.end()) {
+ std::vector<ContactRosterItem*>& items = item->second;
+ items.erase(std::remove_if(items.begin(), items.end(), JIDEqualsTo(jid)), items.end());
+ if (items.empty()) {
+ itemMap_.erase(item);
+ }
+ }
+ //Causes the delete
+ root_->removeChild(jid);
}
void Roster::removeContactFromGroup(const JID& jid, const std::string& groupName) {
- std::vector<RosterItem*> children = root_->getChildren();
- std::vector<RosterItem*>::iterator it = children.begin();
- ItemMap::iterator itemIt = itemMap_.find(fullJIDMapping_ ? jid : jid.toBare());
- while (it != children.end()) {
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
- if (group && group->getDisplayName() == groupName) {
- ContactRosterItem* deleted = group->removeChild(jid);
- if (itemIt != itemMap_.end()) {
- std::vector<ContactRosterItem*>& items = itemIt->second;
- items.erase(std::remove(items.begin(), items.end(), deleted), items.end());
- }
- }
- ++it;
- }
-
- if (itemIt != itemMap_.end()) {
- foreach (ContactRosterItem* item, itemIt->second) {
- item->removeGroup(groupName);
- }
- }
+ std::vector<RosterItem*> children = root_->getChildren();
+ std::vector<RosterItem*>::iterator it = children.begin();
+ ItemMap::iterator itemIt = itemMap_.find(fullJIDMapping_ ? jid : jid.toBare());
+ while (it != children.end()) {
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(*it);
+ if (group && group->getDisplayName() == groupName) {
+ ContactRosterItem* deleted = group->removeChild(jid);
+ if (itemIt != itemMap_.end()) {
+ std::vector<ContactRosterItem*>& items = itemIt->second;
+ items.erase(std::remove(items.begin(), items.end(), deleted), items.end());
+ }
+ }
+ ++it;
+ }
+
+ if (itemIt != itemMap_.end()) {
+ foreach (ContactRosterItem* item, itemIt->second) {
+ item->removeGroup(groupName);
+ }
+ }
}
void Roster::applyOnItems(const RosterItemOperation& operation) {
- if (operation.requiresLookup()) {
- applyOnItem(operation, operation.lookupJID());
- } else {
- applyOnAllItems(operation);
- }
+ if (operation.requiresLookup()) {
+ applyOnItem(operation, operation.lookupJID());
+ } else {
+ applyOnAllItems(operation);
+ }
}
void Roster::applyOnItem(const RosterItemOperation& operation, const JID& jid) {
- ItemMap::iterator i = itemMap_.find(fullJIDMapping_ ? jid : jid.toBare());
- if (i == itemMap_.end()) {
- return;
- }
- foreach (ContactRosterItem* item, i->second) {
- operation(item);
- filterContact(item, item->getParent());
- }
+ ItemMap::iterator i = itemMap_.find(fullJIDMapping_ ? jid : jid.toBare());
+ if (i == itemMap_.end()) {
+ return;
+ }
+ foreach (ContactRosterItem* item, i->second) {
+ operation(item);
+ filterContact(item, item->getParent());
+ }
}
void Roster::applyOnAllItems(const RosterItemOperation& operation) {
- std::deque<RosterItem*> queue;
- queue.push_back(root_);
- while (!queue.empty()) {
- RosterItem* item = *queue.begin();
- queue.pop_front();
- operation(item);
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
- }
- }
- filterAll();
+ std::deque<RosterItem*> queue;
+ queue.push_back(root_);
+ while (!queue.empty()) {
+ RosterItem* item = *queue.begin();
+ queue.pop_front();
+ operation(item);
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
+ if (group) {
+ queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
+ }
+ }
+ filterAll();
}
void Roster::addFilter(RosterFilter* filter) {
- filters_.push_back(filter);
- filterAll();
- onFilterAdded(filter);
+ filters_.push_back(filter);
+ filterAll();
+ onFilterAdded(filter);
}
void Roster::removeFilter(RosterFilter* filter) {
- for (unsigned int i = 0; i < filters_.size(); i++) {
- if (filters_[i] == filter) {
- filters_.erase(filters_.begin() + i);
- break;
- }
- }
- filterAll();
- onFilterRemoved(filter);
+ for (unsigned int i = 0; i < filters_.size(); i++) {
+ if (filters_[i] == filter) {
+ filters_.erase(filters_.begin() + i);
+ break;
+ }
+ }
+ filterAll();
+ onFilterRemoved(filter);
}
void Roster::filterContact(ContactRosterItem* contact, GroupRosterItem* group) {
- size_t oldDisplayedSize = group->getDisplayedChildren().size();
- bool hide = true;
- foreach (RosterFilter *filter, filters_) {
- hide &= (*filter)(contact);
- }
- group->setDisplayed(contact, filters_.empty() || !hide);
- size_t newDisplayedSize = group->getDisplayedChildren().size();
- if (oldDisplayedSize == 0 && newDisplayedSize > 0) {
- onGroupAdded(group);
- }
+ size_t oldDisplayedSize = group->getDisplayedChildren().size();
+ bool hide = true;
+ foreach (RosterFilter *filter, filters_) {
+ hide &= (*filter)(contact);
+ }
+ group->setDisplayed(contact, filters_.empty() || !hide);
+ size_t newDisplayedSize = group->getDisplayedChildren().size();
+ if (oldDisplayedSize == 0 && newDisplayedSize > 0) {
+ onGroupAdded(group);
+ }
}
void Roster::filterGroup(GroupRosterItem* group) {
- foreach (RosterItem* child, group->getChildren()) {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(child);
- if (contact) {
- filterContact(contact, group);
- }
- }
+ foreach (RosterItem* child, group->getChildren()) {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(child);
+ if (contact) {
+ filterContact(contact, group);
+ }
+ }
}
void Roster::filterAll() {
- std::deque<RosterItem*> queue;
- queue.push_back(root_);
- while (!queue.empty()) {
- RosterItem *item = *queue.begin();
- queue.pop_front();
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- if (group) {
- queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
- filterGroup(group);
- }
- }
+ std::deque<RosterItem*> queue;
+ queue.push_back(root_);
+ while (!queue.empty()) {
+ RosterItem *item = *queue.begin();
+ queue.pop_front();
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
+ if (group) {
+ queue.insert(queue.begin(), group->getChildren().begin(), group->getChildren().end());
+ filterGroup(group);
+ }
+ }
}
}
diff --git a/Swift/Controllers/Roster/Roster.h b/Swift/Controllers/Roster/Roster.h
index 269ec4d..70e5bab 100644
--- a/Swift/Controllers/Roster/Roster.h
+++ b/Swift/Controllers/Roster/Roster.h
@@ -27,46 +27,46 @@ class GroupRosterItem;
class ContactRosterItem;
class Roster {
- public:
- Roster(bool sortByStatus = true, bool fullJIDMapping = false);
- ~Roster();
+ public:
+ Roster(bool sortByStatus = true, bool fullJIDMapping = false);
+ ~Roster();
- void addContact(const JID& jid, const JID& displayJID, const std::string& name, const std::string& group, const boost::filesystem::path& avatarPath);
- void removeContact(const JID& jid);
- void removeContactFromGroup(const JID& jid, const std::string& group);
- void removeGroup(const std::string& group);
- void removeAll();
- void applyOnItems(const RosterItemOperation& operation);
- void applyOnAllItems(const RosterItemOperation& operation);
- void applyOnItem(const RosterItemOperation& operation, const JID& jid);
- void addFilter(RosterFilter* filter);
- void removeFilter(RosterFilter* filter);
- GroupRosterItem* getRoot() const;
- std::set<JID> getJIDs() const;
+ void addContact(const JID& jid, const JID& displayJID, const std::string& name, const std::string& group, const boost::filesystem::path& avatarPath);
+ void removeContact(const JID& jid);
+ void removeContactFromGroup(const JID& jid, const std::string& group);
+ void removeGroup(const std::string& group);
+ void removeAll();
+ void applyOnItems(const RosterItemOperation& operation);
+ void applyOnAllItems(const RosterItemOperation& operation);
+ void applyOnItem(const RosterItemOperation& operation, const JID& jid);
+ void addFilter(RosterFilter* filter);
+ void removeFilter(RosterFilter* filter);
+ GroupRosterItem* getRoot() const;
+ std::set<JID> getJIDs() const;
- std::vector<RosterFilter*> getFilters() {return filters_;}
- boost::signal<void (GroupRosterItem*)> onChildrenChanged;
- boost::signal<void (GroupRosterItem*)> onGroupAdded;
- boost::signal<void (RosterItem*)> onDataChanged;
- boost::signal<void (JID&)> onVCardUpdateRequested;
- boost::signal<void (RosterFilter* filter)> onFilterAdded;
- boost::signal<void (RosterFilter* filter)> onFilterRemoved;
- GroupRosterItem* getGroup(const std::string& groupName);
- void setBlockingSupported(bool isSupported);
+ std::vector<RosterFilter*> getFilters() {return filters_;}
+ boost::signal<void (GroupRosterItem*)> onChildrenChanged;
+ boost::signal<void (GroupRosterItem*)> onGroupAdded;
+ boost::signal<void (RosterItem*)> onDataChanged;
+ boost::signal<void (JID&)> onVCardUpdateRequested;
+ boost::signal<void (RosterFilter* filter)> onFilterAdded;
+ boost::signal<void (RosterFilter* filter)> onFilterRemoved;
+ GroupRosterItem* getGroup(const std::string& groupName);
+ void setBlockingSupported(bool isSupported);
- private:
- void handleDataChanged(RosterItem* item);
- void handleChildrenChanged(GroupRosterItem* item);
- void filterGroup(GroupRosterItem* item);
- void filterContact(ContactRosterItem* contact, GroupRosterItem* group);
- void filterAll();
- GroupRosterItem* root_;
- std::vector<RosterFilter*> filters_;
- typedef std::map<JID, std::vector<ContactRosterItem*> > ItemMap;
- ItemMap itemMap_;
- bool fullJIDMapping_;
- bool sortByStatus_;
- bool blockingSupported_;
+ private:
+ void handleDataChanged(RosterItem* item);
+ void handleChildrenChanged(GroupRosterItem* item);
+ void filterGroup(GroupRosterItem* item);
+ void filterContact(ContactRosterItem* contact, GroupRosterItem* group);
+ void filterAll();
+ GroupRosterItem* root_;
+ std::vector<RosterFilter*> filters_;
+ typedef std::map<JID, std::vector<ContactRosterItem*> > ItemMap;
+ ItemMap itemMap_;
+ bool fullJIDMapping_;
+ bool sortByStatus_;
+ bool blockingSupported_;
};
}
diff --git a/Swift/Controllers/Roster/RosterController.cpp b/Swift/Controllers/Roster/RosterController.cpp
index 4fbdea4..e391f41 100644
--- a/Swift/Controllers/Roster/RosterController.cpp
+++ b/Swift/Controllers/Roster/RosterController.cpp
@@ -62,354 +62,354 @@ namespace Swift {
* The controller does not gain ownership of these parameters.
*/
RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickManager* nickManager, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter, SettingsProvider* settings, EntityCapsProvider* entityCapsManager, FileTransferOverview* fileTransferOverview, ClientBlockListManager* clientBlockListManager, VCardManager* vcardManager)
- : myJID_(jid), xmppRoster_(xmppRoster), mainWindowFactory_(mainWindowFactory), mainWindow_(mainWindowFactory_->createMainWindow(uiEventStream)), roster_(new Roster()), offlineFilter_(new OfflineRosterFilter()), vcardManager_(vcardManager), avatarManager_(avatarManager), nickManager_(nickManager), nickResolver_(nickResolver), presenceOracle_(presenceOracle), uiEventStream_(uiEventStream), entityCapsManager_(entityCapsManager), ftOverview_(fileTransferOverview), clientBlockListManager_(clientBlockListManager) {
- assert(fileTransferOverview);
- iqRouter_ = iqRouter;
- subscriptionManager_ = subscriptionManager;
- eventController_ = eventController;
- settings_ = settings;
- expandiness_ = new RosterGroupExpandinessPersister(roster_, settings);
- mainWindow_->setRosterModel(roster_);
- rosterVCardProvider_ = new RosterVCardProvider(roster_, vcardManager, JID::WithoutResource);
-
- changeStatusConnection_ = mainWindow_->onChangeStatusRequest.connect(boost::bind(&RosterController::handleChangeStatusRequest, this, _1, _2));
- signOutConnection_ = mainWindow_->onSignOutRequest.connect(boost::bind(boost::ref(onSignOutRequest)));
- xmppRoster_->onJIDAdded.connect(boost::bind(&RosterController::handleOnJIDAdded, this, _1));
- xmppRoster_->onJIDUpdated.connect(boost::bind(&RosterController::handleOnJIDUpdated, this, _1, _2, _3));
- xmppRoster_->onJIDRemoved.connect(boost::bind(&RosterController::handleOnJIDRemoved, this, _1));
- xmppRoster_->onRosterCleared.connect(boost::bind(&RosterController::handleRosterCleared, this));
- subscriptionManager_->onPresenceSubscriptionRequest.connect(boost::bind(&RosterController::handleSubscriptionRequest, this, _1, _2));
- uiEventConnection_ = uiEventStream->onUIEvent.connect(boost::bind(&RosterController::handleUIEvent, this, _1));
-
- vcardManager_->onOwnVCardChanged.connect(boost::bind(&RosterController::handleOwnVCardChanged, this, _1));
- avatarManager_->onAvatarChanged.connect(boost::bind(&RosterController::handleAvatarChanged, this, _1));
- presenceOracle_->onPresenceChange.connect(boost::bind(&RosterController::handlePresenceChanged, this, _1));
- mainWindow_->setMyAvatarPath(pathToString(avatarManager_->getAvatarPath(myJID_.toBare())));
-
- nickManager_->onOwnNickChanged.connect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1));
- mainWindow_->setMyJID(jid);
- mainWindow_->setMyNick(nickManager_->getOwnNick());
-
- entityCapsManager_->onCapsChanged.connect(boost::bind(&RosterController::handleOnCapsChanged, this, _1));
-
- settings_->onSettingChanged.connect(boost::bind(&RosterController::handleSettingChanged, this, _1));
-
- handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
-
- ownContact_ = boost::make_shared<ContactRosterItem>(myJID_.toBare(), myJID_.toBare(), nickManager_->getOwnNick(), static_cast<GroupRosterItem*>(0));
- ownContact_->setVCard(vcardManager_->getVCard(myJID_.toBare()));
- ownContact_->setAvatarPath(pathToString(avatarManager_->getAvatarPath(myJID_.toBare())));
- mainWindow_->setMyContactRosterItem(ownContact_);
+ : myJID_(jid), xmppRoster_(xmppRoster), mainWindowFactory_(mainWindowFactory), mainWindow_(mainWindowFactory_->createMainWindow(uiEventStream)), roster_(new Roster()), offlineFilter_(new OfflineRosterFilter()), vcardManager_(vcardManager), avatarManager_(avatarManager), nickManager_(nickManager), nickResolver_(nickResolver), presenceOracle_(presenceOracle), uiEventStream_(uiEventStream), entityCapsManager_(entityCapsManager), ftOverview_(fileTransferOverview), clientBlockListManager_(clientBlockListManager) {
+ assert(fileTransferOverview);
+ iqRouter_ = iqRouter;
+ subscriptionManager_ = subscriptionManager;
+ eventController_ = eventController;
+ settings_ = settings;
+ expandiness_ = new RosterGroupExpandinessPersister(roster_, settings);
+ mainWindow_->setRosterModel(roster_);
+ rosterVCardProvider_ = new RosterVCardProvider(roster_, vcardManager, JID::WithoutResource);
+
+ changeStatusConnection_ = mainWindow_->onChangeStatusRequest.connect(boost::bind(&RosterController::handleChangeStatusRequest, this, _1, _2));
+ signOutConnection_ = mainWindow_->onSignOutRequest.connect(boost::bind(boost::ref(onSignOutRequest)));
+ xmppRoster_->onJIDAdded.connect(boost::bind(&RosterController::handleOnJIDAdded, this, _1));
+ xmppRoster_->onJIDUpdated.connect(boost::bind(&RosterController::handleOnJIDUpdated, this, _1, _2, _3));
+ xmppRoster_->onJIDRemoved.connect(boost::bind(&RosterController::handleOnJIDRemoved, this, _1));
+ xmppRoster_->onRosterCleared.connect(boost::bind(&RosterController::handleRosterCleared, this));
+ subscriptionManager_->onPresenceSubscriptionRequest.connect(boost::bind(&RosterController::handleSubscriptionRequest, this, _1, _2));
+ uiEventConnection_ = uiEventStream->onUIEvent.connect(boost::bind(&RosterController::handleUIEvent, this, _1));
+
+ vcardManager_->onOwnVCardChanged.connect(boost::bind(&RosterController::handleOwnVCardChanged, this, _1));
+ avatarManager_->onAvatarChanged.connect(boost::bind(&RosterController::handleAvatarChanged, this, _1));
+ presenceOracle_->onPresenceChange.connect(boost::bind(&RosterController::handlePresenceChanged, this, _1));
+ mainWindow_->setMyAvatarPath(pathToString(avatarManager_->getAvatarPath(myJID_.toBare())));
+
+ nickManager_->onOwnNickChanged.connect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1));
+ mainWindow_->setMyJID(jid);
+ mainWindow_->setMyNick(nickManager_->getOwnNick());
+
+ entityCapsManager_->onCapsChanged.connect(boost::bind(&RosterController::handleOnCapsChanged, this, _1));
+
+ settings_->onSettingChanged.connect(boost::bind(&RosterController::handleSettingChanged, this, _1));
+
+ handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
+
+ ownContact_ = boost::make_shared<ContactRosterItem>(myJID_.toBare(), myJID_.toBare(), nickManager_->getOwnNick(), static_cast<GroupRosterItem*>(0));
+ ownContact_->setVCard(vcardManager_->getVCard(myJID_.toBare()));
+ ownContact_->setAvatarPath(pathToString(avatarManager_->getAvatarPath(myJID_.toBare())));
+ mainWindow_->setMyContactRosterItem(ownContact_);
}
-RosterController::~RosterController() {
- settings_->onSettingChanged.disconnect(boost::bind(&RosterController::handleSettingChanged, this, _1));
- nickManager_->onOwnNickChanged.disconnect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1));
-
- delete offlineFilter_;
- delete expandiness_;
+RosterController::~RosterController() {
+ settings_->onSettingChanged.disconnect(boost::bind(&RosterController::handleSettingChanged, this, _1));
+ nickManager_->onOwnNickChanged.disconnect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1));
- mainWindow_->setRosterModel(NULL);
- if (mainWindow_->canDelete()) {
- delete mainWindow_;
- }
- delete rosterVCardProvider_;
- delete roster_;
+ delete offlineFilter_;
+ delete expandiness_;
+
+ mainWindow_->setRosterModel(NULL);
+ if (mainWindow_->canDelete()) {
+ delete mainWindow_;
+ }
+ delete rosterVCardProvider_;
+ delete roster_;
}
void RosterController::setEnabled(bool enabled) {
- if (!enabled) {
- roster_->applyOnItems(AppearOffline());
- }
+ if (!enabled) {
+ roster_->applyOnItems(AppearOffline());
+ }
}
void RosterController::handleShowOfflineToggled(bool state) {
- if (state) {
- roster_->removeFilter(offlineFilter_);
- } else {
- roster_->addFilter(offlineFilter_);
- }
+ if (state) {
+ roster_->removeFilter(offlineFilter_);
+ } else {
+ roster_->addFilter(offlineFilter_);
+ }
}
void RosterController::handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText) {
- onChangeStatusRequest(show, statusText);
+ onChangeStatusRequest(show, statusText);
}
void RosterController::handleOnJIDAdded(const JID& jid) {
- std::vector<std::string> groups = xmppRoster_->getGroupsForJID(jid);
- std::string name = nickResolver_->jidToNick(jid);
- if (!groups.empty()) {
- foreach(const std::string& group, groups) {
- roster_->addContact(jid, jid, name, group, avatarManager_->getAvatarPath(jid));
- }
- }
- else {
- roster_->addContact(jid, jid, name, QT_TRANSLATE_NOOP("", "Contacts"), avatarManager_->getAvatarPath(jid));
- }
- applyAllPresenceTo(jid);
+ std::vector<std::string> groups = xmppRoster_->getGroupsForJID(jid);
+ std::string name = nickResolver_->jidToNick(jid);
+ if (!groups.empty()) {
+ foreach(const std::string& group, groups) {
+ roster_->addContact(jid, jid, name, group, avatarManager_->getAvatarPath(jid));
+ }
+ }
+ else {
+ roster_->addContact(jid, jid, name, QT_TRANSLATE_NOOP("", "Contacts"), avatarManager_->getAvatarPath(jid));
+ }
+ applyAllPresenceTo(jid);
}
void RosterController::applyAllPresenceTo(const JID& jid) {
- foreach (Presence::ref presence, presenceOracle_->getAllPresence(jid)) {
- roster_->applyOnItems(SetPresence(presence));
- }
+ foreach (Presence::ref presence, presenceOracle_->getAllPresence(jid)) {
+ roster_->applyOnItems(SetPresence(presence));
+ }
}
void RosterController::handleRosterCleared() {
- roster_->removeAll();
+ roster_->removeAll();
}
void RosterController::handleOnJIDRemoved(const JID& jid) {
- roster_->removeContact(jid);
+ roster_->removeContact(jid);
}
void RosterController::handleOnJIDUpdated(const JID& jid, const std::string& oldName, const std::vector<std::string>& passedOldGroups) {
- if (oldName != xmppRoster_->getNameForJID(jid)) {
- roster_->applyOnItems(SetName(nickResolver_->jidToNick(jid), jid));
- }
- std::vector<std::string> groups = xmppRoster_->getGroupsForJID(jid);
- std::vector<std::string> oldGroups = passedOldGroups;
- std::string name = nickResolver_->jidToNick(jid);
- std::string contactsGroup = QT_TRANSLATE_NOOP("", "Contacts");
- if (oldGroups.empty()) {
- oldGroups.push_back(contactsGroup);
- }
- if (groups.empty()) {
- groups.push_back(contactsGroup);
- }
- foreach(const std::string& group, groups) {
- if (std::find(oldGroups.begin(), oldGroups.end(), group) == oldGroups.end()) {
- roster_->addContact(jid, jid, name, group, avatarManager_->getAvatarPath(jid));
- }
- }
- foreach(const std::string& group, oldGroups) {
- if (std::find(groups.begin(), groups.end(), group) == groups.end()) {
- roster_->removeContactFromGroup(jid, group);
- if (roster_->getGroup(group)->getChildren().size() == 0) {
- roster_->removeGroup(group);
- }
- }
- }
- applyAllPresenceTo(jid);
+ if (oldName != xmppRoster_->getNameForJID(jid)) {
+ roster_->applyOnItems(SetName(nickResolver_->jidToNick(jid), jid));
+ }
+ std::vector<std::string> groups = xmppRoster_->getGroupsForJID(jid);
+ std::vector<std::string> oldGroups = passedOldGroups;
+ std::string name = nickResolver_->jidToNick(jid);
+ std::string contactsGroup = QT_TRANSLATE_NOOP("", "Contacts");
+ if (oldGroups.empty()) {
+ oldGroups.push_back(contactsGroup);
+ }
+ if (groups.empty()) {
+ groups.push_back(contactsGroup);
+ }
+ foreach(const std::string& group, groups) {
+ if (std::find(oldGroups.begin(), oldGroups.end(), group) == oldGroups.end()) {
+ roster_->addContact(jid, jid, name, group, avatarManager_->getAvatarPath(jid));
+ }
+ }
+ foreach(const std::string& group, oldGroups) {
+ if (std::find(groups.begin(), groups.end(), group) == groups.end()) {
+ roster_->removeContactFromGroup(jid, group);
+ if (roster_->getGroup(group)->getChildren().size() == 0) {
+ roster_->removeGroup(group);
+ }
+ }
+ }
+ applyAllPresenceTo(jid);
}
void RosterController::handleSettingChanged(const std::string& settingPath) {
- if (settingPath == SettingConstants::SHOW_OFFLINE.getKey()) {
- handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
- }
+ if (settingPath == SettingConstants::SHOW_OFFLINE.getKey()) {
+ handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
+ }
}
void RosterController::handleBlockingStateChanged() {
- if (clientBlockListManager_->getBlockList()->getState() == BlockList::Available) {
- foreach(const JID& jid, clientBlockListManager_->getBlockList()->getItems()) {
- roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsBlocked));
- }
- }
+ if (clientBlockListManager_->getBlockList()->getState() == BlockList::Available) {
+ foreach(const JID& jid, clientBlockListManager_->getBlockList()->getItems()) {
+ roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsBlocked));
+ }
+ }
}
void RosterController::handleBlockingItemAdded(const JID& jid) {
- roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsBlocked));
+ roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsBlocked));
}
void RosterController::handleBlockingItemRemoved(const JID& jid) {
- roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsUnblocked));
+ roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsUnblocked));
}
void RosterController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
- if (boost::shared_ptr<AddContactUIEvent> addContactEvent = boost::dynamic_pointer_cast<AddContactUIEvent>(event)) {
- RosterItemPayload item;
- item.setName(addContactEvent->getName());
- item.setJID(addContactEvent->getJID());
- item.setGroups(std::vector<std::string>(addContactEvent->getGroups().begin(), addContactEvent->getGroups().end()));
- boost::shared_ptr<RosterPayload> roster(new RosterPayload());
- roster->addItem(item);
- SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_);
- request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster));
- request->send();
- subscriptionManager_->requestSubscription(addContactEvent->getJID());
- }
- else if (boost::shared_ptr<RemoveRosterItemUIEvent> removeEvent = boost::dynamic_pointer_cast<RemoveRosterItemUIEvent>(event)) {
- RosterItemPayload item(removeEvent->getJID(), "", RosterItemPayload::Remove);
- boost::shared_ptr<RosterPayload> roster(new RosterPayload());
- roster->addItem(item);
- SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_);
- request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster));
- request->send();
-
- }
- else if (boost::shared_ptr<RenameRosterItemUIEvent> renameEvent = boost::dynamic_pointer_cast<RenameRosterItemUIEvent>(event)) {
- JID contact(renameEvent->getJID());
- RosterItemPayload item(contact, renameEvent->getNewName(), xmppRoster_->getSubscriptionStateForJID(contact));
- item.setGroups(xmppRoster_->getGroupsForJID(contact));
- boost::shared_ptr<RosterPayload> roster(new RosterPayload());
- roster->addItem(item);
- SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_);
- request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster));
- request->send();
- }
- else if (boost::shared_ptr<RenameGroupUIEvent> renameGroupEvent = boost::dynamic_pointer_cast<RenameGroupUIEvent>(event)) {
- std::vector<XMPPRosterItem> items = xmppRoster_->getItems();
- std::string group = renameGroupEvent->getGroup();
- // FIXME: We should handle contacts groups specially to avoid clashes
- if (group == QT_TRANSLATE_NOOP("", "Contacts")) {
- group = "";
- }
- foreach(XMPPRosterItem& item, items) {
- std::vector<std::string> groups = item.getGroups();
- if ( (group.empty() && groups.empty()) || std::find(groups.begin(), groups.end(), group) != groups.end()) {
- groups.erase(std::remove(groups.begin(), groups.end(), group), groups.end());
- if (std::find(groups.begin(), groups.end(), renameGroupEvent->getNewName()) == groups.end()) {
- groups.push_back(renameGroupEvent->getNewName());
- }
- item.setGroups(groups);
- updateItem(item);
- }
- }
- }
- else if (boost::shared_ptr<SendFileUIEvent> sendFileEvent = boost::dynamic_pointer_cast<SendFileUIEvent>(event)) {
- //TODO add send file dialog to ChatView of receipient jid
- ftOverview_->sendFile(sendFileEvent->getJID(), sendFileEvent->getFilename());
- }
+ if (boost::shared_ptr<AddContactUIEvent> addContactEvent = boost::dynamic_pointer_cast<AddContactUIEvent>(event)) {
+ RosterItemPayload item;
+ item.setName(addContactEvent->getName());
+ item.setJID(addContactEvent->getJID());
+ item.setGroups(std::vector<std::string>(addContactEvent->getGroups().begin(), addContactEvent->getGroups().end()));
+ boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+ roster->addItem(item);
+ SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_);
+ request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster));
+ request->send();
+ subscriptionManager_->requestSubscription(addContactEvent->getJID());
+ }
+ else if (boost::shared_ptr<RemoveRosterItemUIEvent> removeEvent = boost::dynamic_pointer_cast<RemoveRosterItemUIEvent>(event)) {
+ RosterItemPayload item(removeEvent->getJID(), "", RosterItemPayload::Remove);
+ boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+ roster->addItem(item);
+ SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_);
+ request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster));
+ request->send();
+
+ }
+ else if (boost::shared_ptr<RenameRosterItemUIEvent> renameEvent = boost::dynamic_pointer_cast<RenameRosterItemUIEvent>(event)) {
+ JID contact(renameEvent->getJID());
+ RosterItemPayload item(contact, renameEvent->getNewName(), xmppRoster_->getSubscriptionStateForJID(contact));
+ item.setGroups(xmppRoster_->getGroupsForJID(contact));
+ boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+ roster->addItem(item);
+ SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_);
+ request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster));
+ request->send();
+ }
+ else if (boost::shared_ptr<RenameGroupUIEvent> renameGroupEvent = boost::dynamic_pointer_cast<RenameGroupUIEvent>(event)) {
+ std::vector<XMPPRosterItem> items = xmppRoster_->getItems();
+ std::string group = renameGroupEvent->getGroup();
+ // FIXME: We should handle contacts groups specially to avoid clashes
+ if (group == QT_TRANSLATE_NOOP("", "Contacts")) {
+ group = "";
+ }
+ foreach(XMPPRosterItem& item, items) {
+ std::vector<std::string> groups = item.getGroups();
+ if ( (group.empty() && groups.empty()) || std::find(groups.begin(), groups.end(), group) != groups.end()) {
+ groups.erase(std::remove(groups.begin(), groups.end(), group), groups.end());
+ if (std::find(groups.begin(), groups.end(), renameGroupEvent->getNewName()) == groups.end()) {
+ groups.push_back(renameGroupEvent->getNewName());
+ }
+ item.setGroups(groups);
+ updateItem(item);
+ }
+ }
+ }
+ else if (boost::shared_ptr<SendFileUIEvent> sendFileEvent = boost::dynamic_pointer_cast<SendFileUIEvent>(event)) {
+ //TODO add send file dialog to ChatView of receipient jid
+ ftOverview_->sendFile(sendFileEvent->getJID(), sendFileEvent->getFilename());
+ }
}
void RosterController::setContactGroups(const JID& jid, const std::vector<std::string>& groups) {
- updateItem(XMPPRosterItem(jid, xmppRoster_->getNameForJID(jid), groups, xmppRoster_->getSubscriptionStateForJID(jid)));
+ updateItem(XMPPRosterItem(jid, xmppRoster_->getNameForJID(jid), groups, xmppRoster_->getSubscriptionStateForJID(jid)));
}
void RosterController::updateItem(const XMPPRosterItem& item) {
- RosterItemPayload itemPayload(item.getJID(), item.getName(), item.getSubscription());
- itemPayload.setGroups(item.getGroups());
+ RosterItemPayload itemPayload(item.getJID(), item.getName(), item.getSubscription());
+ itemPayload.setGroups(item.getGroups());
- RosterPayload::ref roster = boost::make_shared<RosterPayload>();
- roster->addItem(itemPayload);
+ RosterPayload::ref roster = boost::make_shared<RosterPayload>();
+ roster->addItem(itemPayload);
- SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_);
- request->onResponse.connect(boost::bind(&RosterController::handleRosterItemUpdated, this, _1, roster));
- request->send();
+ SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_);
+ request->onResponse.connect(boost::bind(&RosterController::handleRosterItemUpdated, this, _1, roster));
+ request->send();
}
void RosterController::initBlockingCommand() {
- boost::shared_ptr<BlockList> blockList = clientBlockListManager_->requestBlockList();
-
- blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&RosterController::handleBlockingStateChanged, this));
- blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&RosterController::handleBlockingItemAdded, this, _1));
- blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&RosterController::handleBlockingItemRemoved, this, _1));
- roster_->setBlockingSupported(true);
- if (blockList->getState() == BlockList::Available) {
- foreach(const JID& jid, blockList->getItems()) {
- roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsBlocked));
- }
- }
+ boost::shared_ptr<BlockList> blockList = clientBlockListManager_->requestBlockList();
+
+ blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&RosterController::handleBlockingStateChanged, this));
+ blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&RosterController::handleBlockingItemAdded, this, _1));
+ blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&RosterController::handleBlockingItemRemoved, this, _1));
+ roster_->setBlockingSupported(true);
+ if (blockList->getState() == BlockList::Available) {
+ foreach(const JID& jid, blockList->getItems()) {
+ roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsBlocked));
+ }
+ }
}
void RosterController::handleRosterItemUpdated(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload) {
- if (!!error) {
- handleRosterSetError(error, rosterPayload);
- }
- boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
- std::vector<RosterItemPayload> items = rosterPayload->getItems();
- if (blockList->getState() == BlockList::Available && items.size() > 0) {
- std::vector<JID> jids = blockList->getItems();
- if (std::find(jids.begin(), jids.end(), items[0].getJID()) != jids.end()) {
- roster_->applyOnItems(SetBlockingState(items[0].getJID(), ContactRosterItem::IsBlocked));
- }
- }
+ if (!!error) {
+ handleRosterSetError(error, rosterPayload);
+ }
+ boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
+ std::vector<RosterItemPayload> items = rosterPayload->getItems();
+ if (blockList->getState() == BlockList::Available && items.size() > 0) {
+ std::vector<JID> jids = blockList->getItems();
+ if (std::find(jids.begin(), jids.end(), items[0].getJID()) != jids.end()) {
+ roster_->applyOnItems(SetBlockingState(items[0].getJID(), ContactRosterItem::IsBlocked));
+ }
+ }
}
void RosterController::handleRosterSetError(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload) {
- if (!error) {
- return;
- }
- std::string text = str(format(QT_TRANSLATE_NOOP("", "Server %1% rejected contact list change to item '%2%'")) % myJID_.getDomain() % rosterPayload->getItems()[0].getJID().toString());
- if (!error->getText().empty()) {
- text += ": " + error->getText();
- }
- boost::shared_ptr<ErrorEvent> errorEvent(new ErrorEvent(JID(myJID_.getDomain()), text));
- eventController_->handleIncomingEvent(errorEvent);
+ if (!error) {
+ return;
+ }
+ std::string text = str(format(QT_TRANSLATE_NOOP("", "Server %1% rejected contact list change to item '%2%'")) % myJID_.getDomain() % rosterPayload->getItems()[0].getJID().toString());
+ if (!error->getText().empty()) {
+ text += ": " + error->getText();
+ }
+ boost::shared_ptr<ErrorEvent> errorEvent(new ErrorEvent(JID(myJID_.getDomain()), text));
+ eventController_->handleIncomingEvent(errorEvent);
}
void RosterController::handleIncomingPresence(Presence::ref newPresence) {
- if (newPresence->getType() == Presence::Error) {
- return;
- }
- Presence::ref accountPresence = presenceOracle_->getAccountPresence(newPresence->getFrom().toBare());
- if (!accountPresence) {
- accountPresence = Presence::create();
- accountPresence->setFrom(newPresence->getFrom());
- accountPresence->setType(Presence::Unavailable);
- }
- roster_->applyOnItems(SetPresence(accountPresence));
+ if (newPresence->getType() == Presence::Error) {
+ return;
+ }
+ Presence::ref accountPresence = presenceOracle_->getAccountPresence(newPresence->getFrom().toBare());
+ if (!accountPresence) {
+ accountPresence = Presence::create();
+ accountPresence->setFrom(newPresence->getFrom());
+ accountPresence->setType(Presence::Unavailable);
+ }
+ roster_->applyOnItems(SetPresence(accountPresence));
}
void RosterController::handleSubscriptionRequest(const JID& jid, const std::string& message) {
- if (xmppRoster_->containsJID(jid) && (xmppRoster_->getSubscriptionStateForJID(jid) == RosterItemPayload::To || xmppRoster_->getSubscriptionStateForJID(jid) == RosterItemPayload::Both)) {
- subscriptionManager_->confirmSubscription(jid);
- return;
- }
- SubscriptionRequestEvent* eventPointer = new SubscriptionRequestEvent(jid, message);
- eventPointer->onAccept.connect(boost::bind(&RosterController::handleSubscriptionRequestAccepted, this, eventPointer));
- eventPointer->onDecline.connect(boost::bind(&RosterController::handleSubscriptionRequestDeclined, this, eventPointer));
- boost::shared_ptr<StanzaEvent> event(eventPointer);
- eventController_->handleIncomingEvent(event);
+ if (xmppRoster_->containsJID(jid) && (xmppRoster_->getSubscriptionStateForJID(jid) == RosterItemPayload::To || xmppRoster_->getSubscriptionStateForJID(jid) == RosterItemPayload::Both)) {
+ subscriptionManager_->confirmSubscription(jid);
+ return;
+ }
+ SubscriptionRequestEvent* eventPointer = new SubscriptionRequestEvent(jid, message);
+ eventPointer->onAccept.connect(boost::bind(&RosterController::handleSubscriptionRequestAccepted, this, eventPointer));
+ eventPointer->onDecline.connect(boost::bind(&RosterController::handleSubscriptionRequestDeclined, this, eventPointer));
+ boost::shared_ptr<StanzaEvent> event(eventPointer);
+ eventController_->handleIncomingEvent(event);
}
void RosterController::handleSubscriptionRequestAccepted(SubscriptionRequestEvent* event) {
- subscriptionManager_->confirmSubscription(event->getJID());
- if (!xmppRoster_->containsJID(event->getJID()) || xmppRoster_->getSubscriptionStateForJID(event->getJID()) == RosterItemPayload::None || xmppRoster_->getSubscriptionStateForJID(event->getJID()) == RosterItemPayload::From) {
- subscriptionManager_->requestSubscription(event->getJID());
- }
+ subscriptionManager_->confirmSubscription(event->getJID());
+ if (!xmppRoster_->containsJID(event->getJID()) || xmppRoster_->getSubscriptionStateForJID(event->getJID()) == RosterItemPayload::None || xmppRoster_->getSubscriptionStateForJID(event->getJID()) == RosterItemPayload::From) {
+ subscriptionManager_->requestSubscription(event->getJID());
+ }
}
void RosterController::handleSubscriptionRequestDeclined(SubscriptionRequestEvent* event) {
- subscriptionManager_->cancelSubscription(event->getJID());
+ subscriptionManager_->cancelSubscription(event->getJID());
}
void RosterController::handleOwnVCardChanged(VCard::ref vcard) {
- ownContact_->setVCard(vcard);
- mainWindow_->setMyContactRosterItem(ownContact_);
+ ownContact_->setVCard(vcard);
+ mainWindow_->setMyContactRosterItem(ownContact_);
}
void RosterController::handleAvatarChanged(const JID& jid) {
- boost::filesystem::path path = avatarManager_->getAvatarPath(jid);
- roster_->applyOnItems(SetAvatar(jid, path));
- if (jid.equals(myJID_, JID::WithoutResource)) {
- mainWindow_->setMyAvatarPath(pathToString(path));
- ownContact_->setAvatarPath(pathToString(path));
- mainWindow_->setMyContactRosterItem(ownContact_);
- }
+ boost::filesystem::path path = avatarManager_->getAvatarPath(jid);
+ roster_->applyOnItems(SetAvatar(jid, path));
+ if (jid.equals(myJID_, JID::WithoutResource)) {
+ mainWindow_->setMyAvatarPath(pathToString(path));
+ ownContact_->setAvatarPath(pathToString(path));
+ mainWindow_->setMyContactRosterItem(ownContact_);
+ }
}
void RosterController::handlePresenceChanged(Presence::ref presence) {
- if (presence->getFrom().equals(myJID_, JID::WithResource)) {
- ownContact_->applyPresence(presence);
- mainWindow_->setMyContactRosterItem(ownContact_);
- }
- else {
- handleIncomingPresence(presence);
- }
+ if (presence->getFrom().equals(myJID_, JID::WithResource)) {
+ ownContact_->applyPresence(presence);
+ mainWindow_->setMyContactRosterItem(ownContact_);
+ }
+ else {
+ handleIncomingPresence(presence);
+ }
}
boost::optional<XMPPRosterItem> RosterController::getItem(const JID& jid) const {
- return xmppRoster_->getItem(jid);
+ return xmppRoster_->getItem(jid);
}
std::set<std::string> RosterController::getGroups() const {
- return xmppRoster_->getGroups();
+ return xmppRoster_->getGroups();
}
void RosterController::handleOnCapsChanged(const JID& jid) {
- DiscoInfo::ref info = entityCapsManager_->getCaps(jid);
- if (info) {
- std::set<ContactRosterItem::Feature> features;
- if (FileTransferManager::isSupportedBy(info)) {
- features.insert(ContactRosterItem::FileTransferFeature);
- }
- if (info->hasFeature(DiscoInfo::WhiteboardFeature)) {
- features.insert(ContactRosterItem::WhiteboardFeature);
- }
- roster_->applyOnItems(SetAvailableFeatures(jid, features));
- }
+ DiscoInfo::ref info = entityCapsManager_->getCaps(jid);
+ if (info) {
+ std::set<ContactRosterItem::Feature> features;
+ if (FileTransferManager::isSupportedBy(info)) {
+ features.insert(ContactRosterItem::FileTransferFeature);
+ }
+ if (info->hasFeature(DiscoInfo::WhiteboardFeature)) {
+ features.insert(ContactRosterItem::WhiteboardFeature);
+ }
+ roster_->applyOnItems(SetAvailableFeatures(jid, features));
+ }
}
}
diff --git a/Swift/Controllers/Roster/RosterController.h b/Swift/Controllers/Roster/RosterController.h
index 545abfc..f1660a8 100644
--- a/Swift/Controllers/Roster/RosterController.h
+++ b/Swift/Controllers/Roster/RosterController.h
@@ -23,104 +23,104 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class AvatarManager;
- class ClientBlockListManager;
- class EntityCapsProvider;
- class EventController;
- class FileTransferManager;
- class FileTransferOverview;
- class IQRouter;
- class MainWindow;
- class MainWindowFactory;
- class NickManager;
- class NickResolver;
- class OfflineRosterFilter;
- class PresenceOracle;
- class Roster;
- class RosterGroupExpandinessPersister;
- class RosterVCardProvider;
- class SettingsProvider;
- class SubscriptionManager;
- class SubscriptionRequestEvent;
- class UIEventStream;
- class VCardManager;
- class XMPPRoster;
- class XMPPRosterItem;
+ class AvatarManager;
+ class ClientBlockListManager;
+ class EntityCapsProvider;
+ class EventController;
+ class FileTransferManager;
+ class FileTransferOverview;
+ class IQRouter;
+ class MainWindow;
+ class MainWindowFactory;
+ class NickManager;
+ class NickResolver;
+ class OfflineRosterFilter;
+ class PresenceOracle;
+ class Roster;
+ class RosterGroupExpandinessPersister;
+ class RosterVCardProvider;
+ class SettingsProvider;
+ class SubscriptionManager;
+ class SubscriptionRequestEvent;
+ class UIEventStream;
+ class VCardManager;
+ class XMPPRoster;
+ class XMPPRosterItem;
- class RosterController {
- public:
- RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickManager* nickManager, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter, SettingsProvider* settings, EntityCapsProvider* entityCapsProvider, FileTransferOverview* fileTransferOverview, ClientBlockListManager* clientBlockListManager, VCardManager* vcardManager);
- ~RosterController();
- void showRosterWindow();
- void setJID(const JID& jid) { myJID_ = jid; }
- MainWindow* getWindow() {return mainWindow_;}
- boost::signal<void (StatusShow::Type, const std::string&)> onChangeStatusRequest;
- boost::signal<void ()> onSignOutRequest;
- void handleOwnVCardChanged(VCard::ref vcard);
- void handleAvatarChanged(const JID& jid);
- void handlePresenceChanged(Presence::ref presence);
- void setEnabled(bool enabled);
+ class RosterController {
+ public:
+ RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickManager* nickManager, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter, SettingsProvider* settings, EntityCapsProvider* entityCapsProvider, FileTransferOverview* fileTransferOverview, ClientBlockListManager* clientBlockListManager, VCardManager* vcardManager);
+ ~RosterController();
+ void showRosterWindow();
+ void setJID(const JID& jid) { myJID_ = jid; }
+ MainWindow* getWindow() {return mainWindow_;}
+ boost::signal<void (StatusShow::Type, const std::string&)> onChangeStatusRequest;
+ boost::signal<void ()> onSignOutRequest;
+ void handleOwnVCardChanged(VCard::ref vcard);
+ void handleAvatarChanged(const JID& jid);
+ void handlePresenceChanged(Presence::ref presence);
+ void setEnabled(bool enabled);
- boost::optional<XMPPRosterItem> getItem(const JID&) const;
- std::set<std::string> getGroups() const;
+ boost::optional<XMPPRosterItem> getItem(const JID&) const;
+ std::set<std::string> getGroups() const;
- void setContactGroups(const JID& jid, const std::vector<std::string>& groups);
- void updateItem(const XMPPRosterItem&);
+ void setContactGroups(const JID& jid, const std::vector<std::string>& groups);
+ void updateItem(const XMPPRosterItem&);
- void initBlockingCommand();
+ void initBlockingCommand();
- private:
- void handleOnJIDAdded(const JID &jid);
- void handleRosterCleared();
- void handleOnJIDRemoved(const JID &jid);
- void handleOnJIDUpdated(const JID &jid, const std::string& oldName, const std::vector<std::string>& oldGroups);
- void handleStartChatRequest(const JID& contact);
- void handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText);
- void handleShowOfflineToggled(bool state);
- void handleIncomingPresence(boost::shared_ptr<Presence> newPresence);
- void handleSubscriptionRequest(const JID& jid, const std::string& message);
- void handleSubscriptionRequestAccepted(SubscriptionRequestEvent* event);
- void handleSubscriptionRequestDeclined(SubscriptionRequestEvent* event);
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void handleRosterItemUpdated(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload);
- void handleRosterSetError(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload);
- void applyAllPresenceTo(const JID& jid);
- void handleEditProfileRequest();
- void handleOnCapsChanged(const JID& jid);
- void handleSettingChanged(const std::string& settingPath);
+ private:
+ void handleOnJIDAdded(const JID &jid);
+ void handleRosterCleared();
+ void handleOnJIDRemoved(const JID &jid);
+ void handleOnJIDUpdated(const JID &jid, const std::string& oldName, const std::vector<std::string>& oldGroups);
+ void handleStartChatRequest(const JID& contact);
+ void handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText);
+ void handleShowOfflineToggled(bool state);
+ void handleIncomingPresence(boost::shared_ptr<Presence> newPresence);
+ void handleSubscriptionRequest(const JID& jid, const std::string& message);
+ void handleSubscriptionRequestAccepted(SubscriptionRequestEvent* event);
+ void handleSubscriptionRequestDeclined(SubscriptionRequestEvent* event);
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleRosterItemUpdated(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload);
+ void handleRosterSetError(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload);
+ void applyAllPresenceTo(const JID& jid);
+ void handleEditProfileRequest();
+ void handleOnCapsChanged(const JID& jid);
+ void handleSettingChanged(const std::string& settingPath);
- void handleBlockingStateChanged();
- void handleBlockingItemAdded(const JID& jid);
- void handleBlockingItemRemoved(const JID& jid);
+ void handleBlockingStateChanged();
+ void handleBlockingItemAdded(const JID& jid);
+ void handleBlockingItemRemoved(const JID& jid);
- JID myJID_;
- XMPPRoster* xmppRoster_;
- MainWindowFactory* mainWindowFactory_;
- MainWindow* mainWindow_;
- Roster* roster_;
- OfflineRosterFilter* offlineFilter_;
- VCardManager* vcardManager_;
- AvatarManager* avatarManager_;
- NickManager* nickManager_;
- NickResolver* nickResolver_;
- PresenceOracle* presenceOracle_;
- SubscriptionManager* subscriptionManager_;
- EventController* eventController_;
- RosterGroupExpandinessPersister* expandiness_;
- IQRouter* iqRouter_;
- SettingsProvider* settings_;
- UIEventStream* uiEventStream_;
- EntityCapsProvider* entityCapsManager_;
- FileTransferOverview* ftOverview_;
- ClientBlockListManager* clientBlockListManager_;
- RosterVCardProvider* rosterVCardProvider_;
- boost::shared_ptr<ContactRosterItem> ownContact_;
-
- boost::bsignals::scoped_connection blockingOnStateChangedConnection_;
- boost::bsignals::scoped_connection blockingOnItemAddedConnection_;
- boost::bsignals::scoped_connection blockingOnItemRemovedConnection_;
- boost::bsignals::scoped_connection changeStatusConnection_;
- boost::bsignals::scoped_connection signOutConnection_;
- boost::bsignals::scoped_connection uiEventConnection_;
- };
+ JID myJID_;
+ XMPPRoster* xmppRoster_;
+ MainWindowFactory* mainWindowFactory_;
+ MainWindow* mainWindow_;
+ Roster* roster_;
+ OfflineRosterFilter* offlineFilter_;
+ VCardManager* vcardManager_;
+ AvatarManager* avatarManager_;
+ NickManager* nickManager_;
+ NickResolver* nickResolver_;
+ PresenceOracle* presenceOracle_;
+ SubscriptionManager* subscriptionManager_;
+ EventController* eventController_;
+ RosterGroupExpandinessPersister* expandiness_;
+ IQRouter* iqRouter_;
+ SettingsProvider* settings_;
+ UIEventStream* uiEventStream_;
+ EntityCapsProvider* entityCapsManager_;
+ FileTransferOverview* ftOverview_;
+ ClientBlockListManager* clientBlockListManager_;
+ RosterVCardProvider* rosterVCardProvider_;
+ boost::shared_ptr<ContactRosterItem> ownContact_;
+
+ boost::bsignals::scoped_connection blockingOnStateChangedConnection_;
+ boost::bsignals::scoped_connection blockingOnItemAddedConnection_;
+ boost::bsignals::scoped_connection blockingOnItemRemovedConnection_;
+ boost::bsignals::scoped_connection changeStatusConnection_;
+ boost::bsignals::scoped_connection signOutConnection_;
+ boost::bsignals::scoped_connection uiEventConnection_;
+ };
}
diff --git a/Swift/Controllers/Roster/RosterFilter.h b/Swift/Controllers/Roster/RosterFilter.h
index e68ab57..6075c66 100644
--- a/Swift/Controllers/Roster/RosterFilter.h
+++ b/Swift/Controllers/Roster/RosterFilter.h
@@ -11,9 +11,9 @@
namespace Swift {
class RosterFilter {
- public:
- virtual ~RosterFilter() {}
- virtual bool operator() (RosterItem* item) const = 0;
+ public:
+ virtual ~RosterFilter() {}
+ virtual bool operator() (RosterItem* item) const = 0;
};
}
diff --git a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp
index a39667c..af89b54 100644
--- a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp
+++ b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp
@@ -19,45 +19,45 @@
namespace Swift {
RosterGroupExpandinessPersister::RosterGroupExpandinessPersister(Roster* roster, SettingsProvider* settings) : roster_(roster), settings_(settings) {
- load();
- roster_->onGroupAdded.connect(boost::bind(&RosterGroupExpandinessPersister::handleGroupAdded, this, _1));
+ load();
+ roster_->onGroupAdded.connect(boost::bind(&RosterGroupExpandinessPersister::handleGroupAdded, this, _1));
}
void RosterGroupExpandinessPersister::handleGroupAdded(GroupRosterItem* group) {
- if (collapsed_.find(group->getDisplayName()) != collapsed_.end()) {
- group->setExpanded(false);
- } else {
- group->setExpanded(true);
- }
- group->onExpandedChanged.connect(boost::bind(&RosterGroupExpandinessPersister::handleExpandedChanged, this, group, _1));
+ if (collapsed_.find(group->getDisplayName()) != collapsed_.end()) {
+ group->setExpanded(false);
+ } else {
+ group->setExpanded(true);
+ }
+ group->onExpandedChanged.connect(boost::bind(&RosterGroupExpandinessPersister::handleExpandedChanged, this, group, _1));
}
void RosterGroupExpandinessPersister::handleExpandedChanged(GroupRosterItem* group, bool expanded) {
- if (expanded) {
- std::string displayName = group->getDisplayName();
- //collapsed_.erase(std::remove(collapsed_.begin(), collapsed_.end(), displayName), collapsed_.end());
- collapsed_.erase(displayName);
- } else {
- collapsed_.insert(group->getDisplayName());
- }
- save();
+ if (expanded) {
+ std::string displayName = group->getDisplayName();
+ //collapsed_.erase(std::remove(collapsed_.begin(), collapsed_.end(), displayName), collapsed_.end());
+ collapsed_.erase(displayName);
+ } else {
+ collapsed_.insert(group->getDisplayName());
+ }
+ save();
}
void RosterGroupExpandinessPersister::save() {
- std::string setting;
- foreach (const std::string& group, collapsed_) {
- if (!setting.empty()) {
- setting += "\n";
- }
- setting += group;
- }
- settings_->storeSetting(SettingConstants::EXPANDED_ROSTER_GROUPS, setting);
+ std::string setting;
+ foreach (const std::string& group, collapsed_) {
+ if (!setting.empty()) {
+ setting += "\n";
+ }
+ setting += group;
+ }
+ settings_->storeSetting(SettingConstants::EXPANDED_ROSTER_GROUPS, setting);
}
void RosterGroupExpandinessPersister::load() {
- std::string saved = settings_->getSetting(SettingConstants::EXPANDED_ROSTER_GROUPS);
- std::vector<std::string> collapsed = String::split(saved, '\n');
- collapsed_.insert(collapsed.begin(), collapsed.end());
+ std::string saved = settings_->getSetting(SettingConstants::EXPANDED_ROSTER_GROUPS);
+ std::vector<std::string> collapsed = String::split(saved, '\n');
+ collapsed_.insert(collapsed.begin(), collapsed.end());
}
diff --git a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.h b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.h
index c3d5c12..4cc08a7 100644
--- a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.h
+++ b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.h
@@ -12,16 +12,16 @@
#include <Swift/Controllers/Settings/SettingsProvider.h>
namespace Swift {
- class RosterGroupExpandinessPersister {
- public:
- RosterGroupExpandinessPersister(Roster* roster, SettingsProvider* settings);
- private:
- void handleExpandedChanged(GroupRosterItem* group, bool expanded);
- void handleGroupAdded(GroupRosterItem* group);
- void load();
- void save();
- std::set<std::string> collapsed_;
- Roster* roster_;
- SettingsProvider* settings_;
- };
+ class RosterGroupExpandinessPersister {
+ public:
+ RosterGroupExpandinessPersister(Roster* roster, SettingsProvider* settings);
+ private:
+ void handleExpandedChanged(GroupRosterItem* group, bool expanded);
+ void handleGroupAdded(GroupRosterItem* group);
+ void load();
+ void save();
+ std::set<std::string> collapsed_;
+ Roster* roster_;
+ SettingsProvider* settings_;
+ };
}
diff --git a/Swift/Controllers/Roster/RosterItem.cpp b/Swift/Controllers/Roster/RosterItem.cpp
index 51478c3..685613f 100644
--- a/Swift/Controllers/Roster/RosterItem.cpp
+++ b/Swift/Controllers/Roster/RosterItem.cpp
@@ -13,10 +13,10 @@
namespace Swift {
RosterItem::RosterItem(const std::string& name, GroupRosterItem* parent) : name_(name), sortableDisplayName_(boost::to_lower_copy(name_)), parent_(parent) {
- /* The following would be good, but because of C++'s inheritance not working in constructors, it's not going to work. */
- //if (parent) {
- // parent_->addChild(this);
- //}
+ /* The following would be good, but because of C++'s inheritance not working in constructors, it's not going to work. */
+ //if (parent) {
+ // parent_->addChild(this);
+ //}
}
RosterItem::~RosterItem() {
@@ -24,21 +24,21 @@ RosterItem::~RosterItem() {
}
GroupRosterItem* RosterItem::getParent() const {
- return parent_;
+ return parent_;
}
void RosterItem::setDisplayName(const std::string& name) {
- name_ = name;
- sortableDisplayName_ = boost::to_lower_copy(name_);
- onDataChanged();
+ name_ = name;
+ sortableDisplayName_ = boost::to_lower_copy(name_);
+ onDataChanged();
}
const std::string& RosterItem::getDisplayName() const {
- return name_;
+ return name_;
}
const std::string& RosterItem::getSortableDisplayName() const {
- return sortableDisplayName_;
+ return sortableDisplayName_;
}
diff --git a/Swift/Controllers/Roster/RosterItem.h b/Swift/Controllers/Roster/RosterItem.h
index 736c6af..e7a3e20 100644
--- a/Swift/Controllers/Roster/RosterItem.h
+++ b/Swift/Controllers/Roster/RosterItem.h
@@ -15,18 +15,18 @@
namespace Swift {
class GroupRosterItem;
class RosterItem {
- public:
- RosterItem(const std::string& name, GroupRosterItem* parent);
- virtual ~RosterItem();
- boost::signal<void ()> onDataChanged;
- GroupRosterItem* getParent() const;
- void setDisplayName(const std::string& name);
- const std::string& getDisplayName() const;
- virtual const std::string& getSortableDisplayName() const;
- private:
- std::string name_;
- std::string sortableDisplayName_;
- GroupRosterItem* parent_;
+ public:
+ RosterItem(const std::string& name, GroupRosterItem* parent);
+ virtual ~RosterItem();
+ boost::signal<void ()> onDataChanged;
+ GroupRosterItem* getParent() const;
+ void setDisplayName(const std::string& name);
+ const std::string& getDisplayName() const;
+ virtual const std::string& getSortableDisplayName() const;
+ private:
+ std::string name_;
+ std::string sortableDisplayName_;
+ GroupRosterItem* parent_;
};
}
diff --git a/Swift/Controllers/Roster/RosterVCardProvider.cpp b/Swift/Controllers/Roster/RosterVCardProvider.cpp
index d00d318..2aa82a9 100644
--- a/Swift/Controllers/Roster/RosterVCardProvider.cpp
+++ b/Swift/Controllers/Roster/RosterVCardProvider.cpp
@@ -20,22 +20,22 @@
namespace Swift {
RosterVCardProvider::RosterVCardProvider(Roster* roster, VCardManager* vcardManager, JID::CompareType compareType) : roster_(roster), vcardManager_(vcardManager), compareType_(compareType) {
- vcardUpdateRequestedConnection = roster_->onVCardUpdateRequested.connect(boost::bind(&RosterVCardProvider::handleVCardUpdateRequested, this, _1));
- vcardChangedConnection = vcardManager_->onVCardChanged.connect(boost::bind(&RosterVCardProvider::handleVCardChanged, this, _1, _2));
+ vcardUpdateRequestedConnection = roster_->onVCardUpdateRequested.connect(boost::bind(&RosterVCardProvider::handleVCardUpdateRequested, this, _1));
+ vcardChangedConnection = vcardManager_->onVCardChanged.connect(boost::bind(&RosterVCardProvider::handleVCardChanged, this, _1, _2));
}
RosterVCardProvider::~RosterVCardProvider() {
}
void RosterVCardProvider::handleVCardUpdateRequested(const JID& jid) {
- VCard::ref vcard = vcardManager_->getVCardAndRequestWhenNeeded(jid);
- if (vcard) {
- handleVCardChanged(jid, vcard);
- }
+ VCard::ref vcard = vcardManager_->getVCardAndRequestWhenNeeded(jid);
+ if (vcard) {
+ handleVCardChanged(jid, vcard);
+ }
}
void RosterVCardProvider::handleVCardChanged(const JID& jid, VCard::ref vcard) {
- roster_->applyOnItem(SetVCard(jid, vcard, compareType_), jid);
+ roster_->applyOnItem(SetVCard(jid, vcard, compareType_), jid);
}
diff --git a/Swift/Controllers/Roster/RosterVCardProvider.h b/Swift/Controllers/Roster/RosterVCardProvider.h
index da41298..a697dae 100644
--- a/Swift/Controllers/Roster/RosterVCardProvider.h
+++ b/Swift/Controllers/Roster/RosterVCardProvider.h
@@ -18,20 +18,20 @@ class Roster;
class VCardManager;
class RosterVCardProvider {
- public:
- RosterVCardProvider(Roster* roster, VCardManager* vcardManager, JID::CompareType compareType);
- ~RosterVCardProvider();
-
- private:
- void handleVCardUpdateRequested(const JID& jid);
- void handleVCardChanged(const JID& jid, VCard::ref vcard);
-
- private:
- Roster* roster_;
- VCardManager* vcardManager_;
- JID::CompareType compareType_;
- boost::bsignals::scoped_connection vcardUpdateRequestedConnection;
- boost::bsignals::scoped_connection vcardChangedConnection;
+ public:
+ RosterVCardProvider(Roster* roster, VCardManager* vcardManager, JID::CompareType compareType);
+ ~RosterVCardProvider();
+
+ private:
+ void handleVCardUpdateRequested(const JID& jid);
+ void handleVCardChanged(const JID& jid, VCard::ref vcard);
+
+ private:
+ Roster* roster_;
+ VCardManager* vcardManager_;
+ JID::CompareType compareType_;
+ boost::bsignals::scoped_connection vcardUpdateRequestedConnection;
+ boost::bsignals::scoped_connection vcardChangedConnection;
};
}
diff --git a/Swift/Controllers/Roster/TableRoster.cpp b/Swift/Controllers/Roster/TableRoster.cpp
index fde3304..f164a4d 100644
--- a/Swift/Controllers/Roster/TableRoster.cpp
+++ b/Swift/Controllers/Roster/TableRoster.cpp
@@ -21,167 +21,167 @@
#include <Swift/Controllers/Roster/Roster.h>
namespace Swift {
- struct SectionNameEquals {
- bool operator()(const TableRoster::Section& s1, const TableRoster::Section& s2) const {
- return s1.name == s2.name;
- }
- };
-
- template<typename T>
- struct True {
- bool operator()(const T&, const T&) const {
- return true;
- }
- };
-
- struct ItemEquals {
- bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const {
- return i1.jid == i2.jid;
- }
- };
-
-
- struct ItemNeedsUpdate {
- bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const {
- return i1.status != i2.status || i1.description != i2.description || i1.name != i2.name || i1.avatarPath.empty() != i2.avatarPath.empty();
- }
- };
-
- struct CreateIndexForSection {
- CreateIndexForSection(size_t section) : section(section) {
- }
-
- TableRoster::Index operator()(size_t row) const {
- return TableRoster::Index(section, row);
- }
-
- size_t section;
- };
+ struct SectionNameEquals {
+ bool operator()(const TableRoster::Section& s1, const TableRoster::Section& s2) const {
+ return s1.name == s2.name;
+ }
+ };
+
+ template<typename T>
+ struct True {
+ bool operator()(const T&, const T&) const {
+ return true;
+ }
+ };
+
+ struct ItemEquals {
+ bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const {
+ return i1.jid == i2.jid;
+ }
+ };
+
+
+ struct ItemNeedsUpdate {
+ bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const {
+ return i1.status != i2.status || i1.description != i2.description || i1.name != i2.name || i1.avatarPath.empty() != i2.avatarPath.empty();
+ }
+ };
+
+ struct CreateIndexForSection {
+ CreateIndexForSection(size_t section) : section(section) {
+ }
+
+ TableRoster::Index operator()(size_t row) const {
+ return TableRoster::Index(section, row);
+ }
+
+ size_t section;
+ };
}
using namespace Swift;
TableRoster::TableRoster(Roster* model, TimerFactory* timerFactory, int updateDelay) : model(model), updatePending(false) {
- updateTimer = timerFactory->createTimer(updateDelay);
- updateTimer->onTick.connect(boost::bind(&TableRoster::handleUpdateTimerTick, this));
- if (model) {
- model->onChildrenChanged.connect(boost::bind(&TableRoster::scheduleUpdate, this));
- model->onGroupAdded.connect(boost::bind(&TableRoster::scheduleUpdate, this));
- model->onDataChanged.connect(boost::bind(&TableRoster::scheduleUpdate, this));
- }
+ updateTimer = timerFactory->createTimer(updateDelay);
+ updateTimer->onTick.connect(boost::bind(&TableRoster::handleUpdateTimerTick, this));
+ if (model) {
+ model->onChildrenChanged.connect(boost::bind(&TableRoster::scheduleUpdate, this));
+ model->onGroupAdded.connect(boost::bind(&TableRoster::scheduleUpdate, this));
+ model->onDataChanged.connect(boost::bind(&TableRoster::scheduleUpdate, this));
+ }
}
TableRoster::~TableRoster() {
- updateTimer->stop();
- updateTimer->onTick.disconnect(boost::bind(&TableRoster::handleUpdateTimerTick, this));
- if (model) {
- model->onDataChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
- model->onGroupAdded.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
- model->onChildrenChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
- }
+ updateTimer->stop();
+ updateTimer->onTick.disconnect(boost::bind(&TableRoster::handleUpdateTimerTick, this));
+ if (model) {
+ model->onDataChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
+ model->onGroupAdded.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
+ model->onChildrenChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
+ }
}
-
+
size_t TableRoster::getNumberOfSections() const {
- return sections.size();
+ return sections.size();
}
const std::string& TableRoster::getSectionTitle(size_t section) {
- return sections[section].name;
+ return sections[section].name;
}
size_t TableRoster::getNumberOfRowsInSection(size_t section) const {
- return sections[section].items.size();
+ return sections[section].items.size();
}
const TableRoster::Item& TableRoster::getItem(const Index& index) const {
- return sections[index.section].items[index.row];
+ return sections[index.section].items[index.row];
}
-
+
void TableRoster::handleUpdateTimerTick() {
- updateTimer->stop();
- updatePending = false;
-
- // Get a model for the new roster
- std::vector<Section> newSections;
- if (model) {
- foreach(RosterItem* item, model->getRoot()->getDisplayedChildren()) {
- if (GroupRosterItem* groupItem = boost::polymorphic_downcast<GroupRosterItem*>(item)) {
- //std::cerr << "* " << groupItem->getDisplayName() << std::endl;
- Section section(groupItem->getDisplayName());
- foreach(RosterItem* groupChildItem, groupItem->getDisplayedChildren()) {
- if (ContactRosterItem* contact = boost::polymorphic_downcast<ContactRosterItem*>(groupChildItem)) {
- //std::cerr << " - " << contact->getDisplayJID() << std::endl;
- section.items.push_back(Item(contact->getDisplayName(), contact->getStatusText(), contact->getDisplayJID(), contact->getStatusShow(), contact->getAvatarPath()));
- }
- }
- newSections.push_back(section);
- }
- }
- }
-
- // Do a diff with the previous roster
- Update update;
- std::vector<size_t> sectionUpdates;
- std::vector<size_t> sectionPostUpdates;
- computeIndexDiff<Section,SectionNameEquals,True<Section> >(sections, newSections, sectionUpdates, sectionPostUpdates, update.deletedSections, update.insertedSections);
- assert(sectionUpdates.size() == sectionPostUpdates.size());
- for (size_t i = 0; i < sectionUpdates.size(); ++i) {
- assert(sectionUpdates[i] < sections.size());
- assert(sectionPostUpdates[i] < newSections.size());
- std::vector<size_t> itemUpdates;
- std::vector<size_t> itemPostUpdates;
- std::vector<size_t> itemRemoves;
- std::vector<size_t> itemInserts;
- computeIndexDiff<Item, ItemEquals, ItemNeedsUpdate >(sections[sectionUpdates[i]].items, newSections[sectionPostUpdates[i]].items, itemUpdates, itemPostUpdates, itemRemoves, itemInserts);
- size_t end = update.insertedRows.size();
- update.insertedRows.resize(update.insertedRows.size() + itemInserts.size());
- std::transform(itemInserts.begin(), itemInserts.end(), update.insertedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionPostUpdates[i]));
- end = update.deletedRows.size();
- update.deletedRows.resize(update.deletedRows.size() + itemRemoves.size());
- std::transform(itemRemoves.begin(), itemRemoves.end(), update.deletedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionUpdates[i]));
- end = update.updatedRows.size();
- update.updatedRows.resize(update.updatedRows.size() + itemUpdates.size());
- std::transform(itemUpdates.begin(), itemUpdates.end(), update.updatedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionPostUpdates[i]));
- }
-
- // Switch the old model with the new
- sections.swap(newSections);
-
- /*
- std::cerr << "-S: ";
- for (size_t i = 0; i < update.deletedSections.size(); ++i) {
- std::cerr << update.deletedSections[i] << " ";
- }
- std::cerr << std::endl;
- std::cerr << "+S: ";
- for (size_t i = 0; i < update.insertedSections.size(); ++i) {
- std::cerr << update.insertedSections[i] << " ";
- }
- std::cerr << std::endl;
- std::cerr << "-R: ";
- for (size_t i = 0; i < update.deletedRows.size(); ++i) {
- std::cerr << update.deletedRows[i].section << "," << update.deletedRows[i].row << " ";
- }
- std::cerr << std::endl;
- std::cerr << "*R: ";
- for (size_t i = 0; i < update.updatedRows.size(); ++i) {
- std::cerr << update.updatedRows[i].section << "," << update.updatedRows[i].row << " ";
- }
- std::cerr << std::endl;
- std::cerr << "+R: ";
- for (size_t i = 0; i < update.insertedRows.size(); ++i) {
- std::cerr << update.insertedRows[i].section << "," << update.insertedRows[i].row << " ";
- }
- std::cerr << std::endl;
- */
-
- // Emit the update
- onUpdate(update);
+ updateTimer->stop();
+ updatePending = false;
+
+ // Get a model for the new roster
+ std::vector<Section> newSections;
+ if (model) {
+ foreach(RosterItem* item, model->getRoot()->getDisplayedChildren()) {
+ if (GroupRosterItem* groupItem = boost::polymorphic_downcast<GroupRosterItem*>(item)) {
+ //std::cerr << "* " << groupItem->getDisplayName() << std::endl;
+ Section section(groupItem->getDisplayName());
+ foreach(RosterItem* groupChildItem, groupItem->getDisplayedChildren()) {
+ if (ContactRosterItem* contact = boost::polymorphic_downcast<ContactRosterItem*>(groupChildItem)) {
+ //std::cerr << " - " << contact->getDisplayJID() << std::endl;
+ section.items.push_back(Item(contact->getDisplayName(), contact->getStatusText(), contact->getDisplayJID(), contact->getStatusShow(), contact->getAvatarPath()));
+ }
+ }
+ newSections.push_back(section);
+ }
+ }
+ }
+
+ // Do a diff with the previous roster
+ Update update;
+ std::vector<size_t> sectionUpdates;
+ std::vector<size_t> sectionPostUpdates;
+ computeIndexDiff<Section,SectionNameEquals,True<Section> >(sections, newSections, sectionUpdates, sectionPostUpdates, update.deletedSections, update.insertedSections);
+ assert(sectionUpdates.size() == sectionPostUpdates.size());
+ for (size_t i = 0; i < sectionUpdates.size(); ++i) {
+ assert(sectionUpdates[i] < sections.size());
+ assert(sectionPostUpdates[i] < newSections.size());
+ std::vector<size_t> itemUpdates;
+ std::vector<size_t> itemPostUpdates;
+ std::vector<size_t> itemRemoves;
+ std::vector<size_t> itemInserts;
+ computeIndexDiff<Item, ItemEquals, ItemNeedsUpdate >(sections[sectionUpdates[i]].items, newSections[sectionPostUpdates[i]].items, itemUpdates, itemPostUpdates, itemRemoves, itemInserts);
+ size_t end = update.insertedRows.size();
+ update.insertedRows.resize(update.insertedRows.size() + itemInserts.size());
+ std::transform(itemInserts.begin(), itemInserts.end(), update.insertedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionPostUpdates[i]));
+ end = update.deletedRows.size();
+ update.deletedRows.resize(update.deletedRows.size() + itemRemoves.size());
+ std::transform(itemRemoves.begin(), itemRemoves.end(), update.deletedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionUpdates[i]));
+ end = update.updatedRows.size();
+ update.updatedRows.resize(update.updatedRows.size() + itemUpdates.size());
+ std::transform(itemUpdates.begin(), itemUpdates.end(), update.updatedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionPostUpdates[i]));
+ }
+
+ // Switch the old model with the new
+ sections.swap(newSections);
+
+ /*
+ std::cerr << "-S: ";
+ for (size_t i = 0; i < update.deletedSections.size(); ++i) {
+ std::cerr << update.deletedSections[i] << " ";
+ }
+ std::cerr << std::endl;
+ std::cerr << "+S: ";
+ for (size_t i = 0; i < update.insertedSections.size(); ++i) {
+ std::cerr << update.insertedSections[i] << " ";
+ }
+ std::cerr << std::endl;
+ std::cerr << "-R: ";
+ for (size_t i = 0; i < update.deletedRows.size(); ++i) {
+ std::cerr << update.deletedRows[i].section << "," << update.deletedRows[i].row << " ";
+ }
+ std::cerr << std::endl;
+ std::cerr << "*R: ";
+ for (size_t i = 0; i < update.updatedRows.size(); ++i) {
+ std::cerr << update.updatedRows[i].section << "," << update.updatedRows[i].row << " ";
+ }
+ std::cerr << std::endl;
+ std::cerr << "+R: ";
+ for (size_t i = 0; i < update.insertedRows.size(); ++i) {
+ std::cerr << update.insertedRows[i].section << "," << update.insertedRows[i].row << " ";
+ }
+ std::cerr << std::endl;
+ */
+
+ // Emit the update
+ onUpdate(update);
}
void TableRoster::scheduleUpdate() {
- if (!updatePending) {
- updatePending = true;
- updateTimer->start();
- }
+ if (!updatePending) {
+ updatePending = true;
+ updateTimer->start();
+ }
}
diff --git a/Swift/Controllers/Roster/TableRoster.h b/Swift/Controllers/Roster/TableRoster.h
index 87f9e75..3d336ef 100644
--- a/Swift/Controllers/Roster/TableRoster.h
+++ b/Swift/Controllers/Roster/TableRoster.h
@@ -16,70 +16,70 @@
#include <Swiften/JID/JID.h>
namespace Swift {
- class Roster;
- class TimerFactory;
- class Timer;
-
- class TableRoster {
- public:
- struct Item {
- Item(const std::string& name, const std::string& description, const JID& jid, StatusShow::Type status, const boost::filesystem::path& avatarPath) : name(name), description(description), jid(jid), status(status), avatarPath(avatarPath) {
- }
- std::string name;
- std::string description;
- JID jid;
- StatusShow::Type status;
- boost::filesystem::path avatarPath;
- };
-
- struct Index {
- Index(size_t section = 0, size_t row = 0) : section(section), row(row) {
- }
- size_t section;
- size_t row;
-
- bool operator==(const Index& o) const {
- return o.section == section && o.row == row;
- }
- };
-
- struct Update {
- std::vector<Index> updatedRows;
- std::vector<Index> insertedRows;
- std::vector<Index> deletedRows;
- std::vector<size_t> insertedSections;
- std::vector<size_t> deletedSections;
- };
-
- TableRoster(Roster* model, TimerFactory* timerFactory, int updateDelay);
- ~TableRoster();
-
- size_t getNumberOfSections() const;
- size_t getNumberOfRowsInSection(size_t section) const;
-
- const std::string& getSectionTitle(size_t);
-
- const Item& getItem(const Index&) const;
-
- boost::signal<void (const Update&)> onUpdate;
-
- private:
- void handleUpdateTimerTick();
- void scheduleUpdate();
-
- private:
- friend struct SectionNameEquals;
- struct Section {
- Section(const std::string& name) : name(name) {
- }
-
- std::string name;
- std::vector<Item> items;
- };
-
- Roster* model;
- std::vector<Section> sections;
- bool updatePending;
- boost::shared_ptr<Timer> updateTimer;
- };
+ class Roster;
+ class TimerFactory;
+ class Timer;
+
+ class TableRoster {
+ public:
+ struct Item {
+ Item(const std::string& name, const std::string& description, const JID& jid, StatusShow::Type status, const boost::filesystem::path& avatarPath) : name(name), description(description), jid(jid), status(status), avatarPath(avatarPath) {
+ }
+ std::string name;
+ std::string description;
+ JID jid;
+ StatusShow::Type status;
+ boost::filesystem::path avatarPath;
+ };
+
+ struct Index {
+ Index(size_t section = 0, size_t row = 0) : section(section), row(row) {
+ }
+ size_t section;
+ size_t row;
+
+ bool operator==(const Index& o) const {
+ return o.section == section && o.row == row;
+ }
+ };
+
+ struct Update {
+ std::vector<Index> updatedRows;
+ std::vector<Index> insertedRows;
+ std::vector<Index> deletedRows;
+ std::vector<size_t> insertedSections;
+ std::vector<size_t> deletedSections;
+ };
+
+ TableRoster(Roster* model, TimerFactory* timerFactory, int updateDelay);
+ ~TableRoster();
+
+ size_t getNumberOfSections() const;
+ size_t getNumberOfRowsInSection(size_t section) const;
+
+ const std::string& getSectionTitle(size_t);
+
+ const Item& getItem(const Index&) const;
+
+ boost::signal<void (const Update&)> onUpdate;
+
+ private:
+ void handleUpdateTimerTick();
+ void scheduleUpdate();
+
+ private:
+ friend struct SectionNameEquals;
+ struct Section {
+ Section(const std::string& name) : name(name) {
+ }
+
+ std::string name;
+ std::vector<Item> items;
+ };
+
+ Roster* model;
+ std::vector<Section> sections;
+ bool updatePending;
+ boost::shared_ptr<Timer> updateTimer;
+ };
}
diff --git a/Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp b/Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp
index 144de77..5844ebe 100644
--- a/Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp
@@ -18,294 +18,294 @@
using namespace Swift;
struct IsBOrC {
- bool operator()(char c, char c2) const {
- CPPUNIT_ASSERT_EQUAL(c, c2);
- return c == 'b' || c == 'c';
- }
+ bool operator()(char c, char c2) const {
+ CPPUNIT_ASSERT_EQUAL(c, c2);
+ return c == 'b' || c == 'c';
+ }
};
struct IsXOrY {
- bool operator()(char c, char c2) const {
- CPPUNIT_ASSERT_EQUAL(c, c2);
- return c == 'x' || c == 'y';
- }
+ bool operator()(char c, char c2) const {
+ CPPUNIT_ASSERT_EQUAL(c, c2);
+ return c == 'x' || c == 'y';
+ }
};
struct IsArizonaOrNewJersey {
- bool operator()(const std::string& s, const std::string& s2) const {
- CPPUNIT_ASSERT_EQUAL(s, s2);
- return s == "Arizona" || s == "New Jersey";
- }
+ bool operator()(const std::string& s, const std::string& s2) const {
+ CPPUNIT_ASSERT_EQUAL(s, s2);
+ return s == "Arizona" || s == "New Jersey";
+ }
};
class LeastCommonSubsequenceTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(LeastCommonSubsequenceTest);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_1);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_2);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_Sequence1Empty);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_Sequence2Empty);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_BothSequencesEmpty);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_NoCommonSequence);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_SameSequences);
- CPPUNIT_TEST(testComputeIndexDiff_1);
- CPPUNIT_TEST(testComputeIndexDiff_2);
- CPPUNIT_TEST(testComputeIndexDiff_Sequence1Empty);
- CPPUNIT_TEST(testComputeIndexDiff_Sequence2Empty);
- CPPUNIT_TEST(testComputeIndexDiff_BothSequencesEmpty);
- CPPUNIT_TEST(testComputeIndexDiff_NoCommonSequence);
- CPPUNIT_TEST(testComputeIndexDiff_SameSequences);
- CPPUNIT_TEST(testComputeIndexDiff_CommonPrefixAndSuffix);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void testComputeLeastCommonSubsequenceMatrix_1() {
- std::vector<char> x = boost::assign::list_of('x')('m')('j')('y')('a')('u')('z');
- std::vector<char> y = boost::assign::list_of('m')('z')('j')('a')('w')('x')('u');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0)(0)(0)(0)(0)
- (0)(0)(1)(1)(1)(1)(1)(1)
- (0)(0)(1)(1)(1)(1)(1)(2)
- (0)(0)(1)(2)(2)(2)(2)(2)
- (0)(0)(1)(2)(2)(3)(3)(3)
- (0)(0)(1)(2)(2)(3)(3)(3)
- (0)(1)(1)(2)(2)(3)(3)(3)
- (0)(1)(1)(2)(2)(3)(4)(4);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_2() {
- std::vector<char> x = boost::assign::list_of('x')('x')('x')('m')('j')('y')('a')('u')('z');
- std::vector<char> y = boost::assign::list_of('m')('z')('j')('a')('w')('x')('u');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0)(0)(0)(0)(0)(0)(0)
- (0)(0)(0)(0)(1)(1)(1)(1)(1)(1)
- (0)(0)(0)(0)(1)(1)(1)(1)(1)(2)
- (0)(0)(0)(0)(1)(2)(2)(2)(2)(2)
- (0)(0)(0)(0)(1)(2)(2)(3)(3)(3)
- (0)(0)(0)(0)(1)(2)(2)(3)(3)(3)
- (0)(1)(1)(1)(1)(2)(2)(3)(3)(3)
- (0)(1)(1)(1)(1)(2)(2)(3)(4)(4);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_Sequence1Empty() {
- std::vector<char> x;
- std::vector<char> y = boost::assign::list_of('a')('b')('c');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)
- (0)
- (0)
- (0);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_Sequence2Empty() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y;
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_BothSequencesEmpty() {
- std::vector<char> x;
- std::vector<char> y;
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of(0);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_NoCommonSequence() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y = boost::assign::list_of('d')('e')('f')('g');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0)
- (0)(0)(0)(0)
- (0)(0)(0)(0)
- (0)(0)(0)(0)
- (0)(0)(0)(0);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_SameSequences() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y = boost::assign::list_of('a')('b')('c');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0)
- (0)(1)(1)(1)
- (0)(1)(2)(2)
- (0)(1)(2)(3);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeIndexDiff_1() {
- std::vector<std::string> x = boost::assign::list_of("Arizona")("California")("Delaware")("New Jersey")("Washington");
- std::vector<std::string> y = boost::assign::list_of("Alaska")("Arizona")("California")("Georgia")("New Jersey")("Virginia");
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<std::string, std::equal_to<std::string>, IsArizonaOrNewJersey >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedUpdates = boost::assign::list_of(3)(0);
- std::vector<size_t> expectedPostUpdates = boost::assign::list_of(4)(1);
- std::vector<size_t> expectedRemoves = boost::assign::list_of(4)(2);
- std::vector<size_t> expectedInserts = boost::assign::list_of(5)(3)(0);
- CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
- CPPUNIT_ASSERT_EQUAL(expectedPostUpdates, postUpdates);
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
- }
-
- void testComputeIndexDiff_2() {
- std::vector<char> x = boost::assign::list_of('x')('y');
- std::vector<char> y = boost::assign::list_of('x');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedRemoves = boost::assign::list_of(1);
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT(inserts.empty());
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- }
-
- void testComputeIndexDiff_Sequence1Empty() {
- std::vector<char> x;
- std::vector<char> y = boost::assign::list_of('a')('b')('c');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedInserts = boost::assign::list_of(2)(1)(0);
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT(removes.empty());
- CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
- }
-
- void testComputeIndexDiff_Sequence2Empty() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y;
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedRemoves = boost::assign::list_of(2)(1)(0);
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- CPPUNIT_ASSERT(inserts.empty());
- }
-
- void testComputeIndexDiff_BothSequencesEmpty() {
- std::vector<char> x;
- std::vector<char> y;
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT(removes.empty());
- CPPUNIT_ASSERT(inserts.empty());
- }
-
- void testComputeIndexDiff_NoCommonSequence() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y = boost::assign::list_of('d')('e')('f')('g');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedRemoves = boost::assign::list_of(2)(1)(0);
- std::vector<size_t> expectedInserts = boost::assign::list_of(3)(2)(1)(0);
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
- }
-
- void testComputeIndexDiff_SameSequences() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y = boost::assign::list_of('a')('b')('c');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedUpdates = boost::assign::list_of(1)(2);
- CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
- CPPUNIT_ASSERT_EQUAL(expectedUpdates, postUpdates);
- CPPUNIT_ASSERT(removes.empty());
- CPPUNIT_ASSERT(inserts.empty());
- }
-
- void testComputeIndexDiff_CommonPrefixAndSuffix() {
- std::vector<char> x = boost::assign::list_of('x')('x')('x')('x')('a')('b')('c')('d')('e')('y')('y')('y');
- std::vector<char> y = boost::assign::list_of('x')('x')('x')('x')('e')('a')('b')('f')('d')('g')('y')('y')('y');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsXOrY >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedUpdates = boost::assign::list_of(0)(1)(2)(3)(11)(10)(9);
- std::vector<size_t> expectedPostUpdates = boost::assign::list_of(0)(1)(2)(3)(12)(11)(10);
- std::vector<size_t> expectedRemoves = boost::assign::list_of(8)(6);
- std::vector<size_t> expectedInserts = boost::assign::list_of(9)(7)(4);
- CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
- CPPUNIT_ASSERT_EQUAL(expectedPostUpdates, postUpdates);
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
- }
+ CPPUNIT_TEST_SUITE(LeastCommonSubsequenceTest);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_1);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_2);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_Sequence1Empty);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_Sequence2Empty);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_BothSequencesEmpty);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_NoCommonSequence);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_SameSequences);
+ CPPUNIT_TEST(testComputeIndexDiff_1);
+ CPPUNIT_TEST(testComputeIndexDiff_2);
+ CPPUNIT_TEST(testComputeIndexDiff_Sequence1Empty);
+ CPPUNIT_TEST(testComputeIndexDiff_Sequence2Empty);
+ CPPUNIT_TEST(testComputeIndexDiff_BothSequencesEmpty);
+ CPPUNIT_TEST(testComputeIndexDiff_NoCommonSequence);
+ CPPUNIT_TEST(testComputeIndexDiff_SameSequences);
+ CPPUNIT_TEST(testComputeIndexDiff_CommonPrefixAndSuffix);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testComputeLeastCommonSubsequenceMatrix_1() {
+ std::vector<char> x = boost::assign::list_of('x')('m')('j')('y')('a')('u')('z');
+ std::vector<char> y = boost::assign::list_of('m')('z')('j')('a')('w')('x')('u');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0)(0)(0)(0)(0)
+ (0)(0)(1)(1)(1)(1)(1)(1)
+ (0)(0)(1)(1)(1)(1)(1)(2)
+ (0)(0)(1)(2)(2)(2)(2)(2)
+ (0)(0)(1)(2)(2)(3)(3)(3)
+ (0)(0)(1)(2)(2)(3)(3)(3)
+ (0)(1)(1)(2)(2)(3)(3)(3)
+ (0)(1)(1)(2)(2)(3)(4)(4);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_2() {
+ std::vector<char> x = boost::assign::list_of('x')('x')('x')('m')('j')('y')('a')('u')('z');
+ std::vector<char> y = boost::assign::list_of('m')('z')('j')('a')('w')('x')('u');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0)(0)(0)(0)(0)(0)(0)
+ (0)(0)(0)(0)(1)(1)(1)(1)(1)(1)
+ (0)(0)(0)(0)(1)(1)(1)(1)(1)(2)
+ (0)(0)(0)(0)(1)(2)(2)(2)(2)(2)
+ (0)(0)(0)(0)(1)(2)(2)(3)(3)(3)
+ (0)(0)(0)(0)(1)(2)(2)(3)(3)(3)
+ (0)(1)(1)(1)(1)(2)(2)(3)(3)(3)
+ (0)(1)(1)(1)(1)(2)(2)(3)(4)(4);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_Sequence1Empty() {
+ std::vector<char> x;
+ std::vector<char> y = boost::assign::list_of('a')('b')('c');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)
+ (0)
+ (0)
+ (0);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_Sequence2Empty() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y;
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_BothSequencesEmpty() {
+ std::vector<char> x;
+ std::vector<char> y;
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of(0);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_NoCommonSequence() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y = boost::assign::list_of('d')('e')('f')('g');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0)
+ (0)(0)(0)(0)
+ (0)(0)(0)(0)
+ (0)(0)(0)(0)
+ (0)(0)(0)(0);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_SameSequences() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y = boost::assign::list_of('a')('b')('c');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0)
+ (0)(1)(1)(1)
+ (0)(1)(2)(2)
+ (0)(1)(2)(3);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeIndexDiff_1() {
+ std::vector<std::string> x = boost::assign::list_of("Arizona")("California")("Delaware")("New Jersey")("Washington");
+ std::vector<std::string> y = boost::assign::list_of("Alaska")("Arizona")("California")("Georgia")("New Jersey")("Virginia");
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<std::string, std::equal_to<std::string>, IsArizonaOrNewJersey >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedUpdates = boost::assign::list_of(3)(0);
+ std::vector<size_t> expectedPostUpdates = boost::assign::list_of(4)(1);
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(4)(2);
+ std::vector<size_t> expectedInserts = boost::assign::list_of(5)(3)(0);
+ CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
+ CPPUNIT_ASSERT_EQUAL(expectedPostUpdates, postUpdates);
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
+ }
+
+ void testComputeIndexDiff_2() {
+ std::vector<char> x = boost::assign::list_of('x')('y');
+ std::vector<char> y = boost::assign::list_of('x');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(1);
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT(inserts.empty());
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ }
+
+ void testComputeIndexDiff_Sequence1Empty() {
+ std::vector<char> x;
+ std::vector<char> y = boost::assign::list_of('a')('b')('c');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedInserts = boost::assign::list_of(2)(1)(0);
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT(removes.empty());
+ CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
+ }
+
+ void testComputeIndexDiff_Sequence2Empty() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y;
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(2)(1)(0);
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ CPPUNIT_ASSERT(inserts.empty());
+ }
+
+ void testComputeIndexDiff_BothSequencesEmpty() {
+ std::vector<char> x;
+ std::vector<char> y;
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT(removes.empty());
+ CPPUNIT_ASSERT(inserts.empty());
+ }
+
+ void testComputeIndexDiff_NoCommonSequence() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y = boost::assign::list_of('d')('e')('f')('g');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(2)(1)(0);
+ std::vector<size_t> expectedInserts = boost::assign::list_of(3)(2)(1)(0);
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
+ }
+
+ void testComputeIndexDiff_SameSequences() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y = boost::assign::list_of('a')('b')('c');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedUpdates = boost::assign::list_of(1)(2);
+ CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
+ CPPUNIT_ASSERT_EQUAL(expectedUpdates, postUpdates);
+ CPPUNIT_ASSERT(removes.empty());
+ CPPUNIT_ASSERT(inserts.empty());
+ }
+
+ void testComputeIndexDiff_CommonPrefixAndSuffix() {
+ std::vector<char> x = boost::assign::list_of('x')('x')('x')('x')('a')('b')('c')('d')('e')('y')('y')('y');
+ std::vector<char> y = boost::assign::list_of('x')('x')('x')('x')('e')('a')('b')('f')('d')('g')('y')('y')('y');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsXOrY >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedUpdates = boost::assign::list_of(0)(1)(2)(3)(11)(10)(9);
+ std::vector<size_t> expectedPostUpdates = boost::assign::list_of(0)(1)(2)(3)(12)(11)(10);
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(8)(6);
+ std::vector<size_t> expectedInserts = boost::assign::list_of(9)(7)(4);
+ CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
+ CPPUNIT_ASSERT_EQUAL(expectedPostUpdates, postUpdates);
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(LeastCommonSubsequenceTest);
diff --git a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp
index d774e6d..551bd6b 100644
--- a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp
@@ -46,351 +46,351 @@ using namespace Swift;
#define CHILDREN mainWindow_->roster->getRoot()->getChildren()
class DummyCapsProvider : public CapsProvider {
- DiscoInfo::ref getCaps(const std::string&) const {return DiscoInfo::ref(new DiscoInfo());}
+ DiscoInfo::ref getCaps(const std::string&) const {return DiscoInfo::ref(new DiscoInfo());}
};
class RosterControllerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(RosterControllerTest);
- CPPUNIT_TEST(testAdd);
- CPPUNIT_TEST(testAddSubscription);
- CPPUNIT_TEST(testReceiveRename);
- CPPUNIT_TEST(testReceiveRegroup);
- CPPUNIT_TEST(testSendRename);
- CPPUNIT_TEST(testPresence);
- CPPUNIT_TEST(testHighestPresence);
- CPPUNIT_TEST(testNotHighestPresence);
- CPPUNIT_TEST(testUnavailablePresence);
- CPPUNIT_TEST(testRemoveResultsInUnavailablePresence);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- jid_ = JID("testjid@swift.im/swift");
- xmppRoster_ = new XMPPRosterImpl();
- avatarManager_ = new NullAvatarManager();
- mainWindowFactory_ = new MockMainWindowFactory();
- mucRegistry_ = new MUCRegistry();
- nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, NULL, mucRegistry_);
- channel_ = new DummyIQChannel();
- router_ = new IQRouter(channel_);
- stanzaChannel_ = new DummyStanzaChannel();
- presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
- subscriptionManager_ = new SubscriptionManager(stanzaChannel_);
- eventController_ = new EventController();
- uiEventStream_ = new UIEventStream();
- settings_ = new DummySettingsProvider();
- nickManager_ = new DummyNickManager();
- capsProvider_ = new DummyCapsProvider();
- entityCapsManager_ = new EntityCapsManager(capsProvider_, stanzaChannel_);
- jingleSessionManager_ = new JingleSessionManager(router_);
-
- ftManager_ = new DummyFileTransferManager();
- ftOverview_ = new FileTransferOverview(ftManager_);
- clientBlockListManager_ = new ClientBlockListManager(router_);
- crypto_ = PlatformCryptoProvider::create();
- vcardStorage_ = new VCardMemoryStorage(crypto_);
- vcardManager_ = new VCardManager(jid_, router_, vcardStorage_);
- rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickManager_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_, entityCapsManager_, ftOverview_, clientBlockListManager_, vcardManager_);
- mainWindow_ = mainWindowFactory_->last;
- }
-
- void tearDown() {
- delete rosterController_;
- delete vcardManager_;
- delete vcardStorage_;
- delete crypto_;
- delete clientBlockListManager_;
- delete ftOverview_;
- delete ftManager_;
- delete jingleSessionManager_;
- delete entityCapsManager_;
- delete capsProvider_;
- delete nickManager_;
- delete nickResolver_;
- delete mucRegistry_;
- delete mainWindowFactory_;
- delete avatarManager_;
- delete router_;
- delete channel_;
- delete eventController_;
- delete subscriptionManager_;
- delete presenceOracle_;
- delete stanzaChannel_;
- delete uiEventStream_;
- delete settings_;
- delete xmppRoster_;
- }
-
- GroupRosterItem* groupChild(size_t i) {
- return dynamic_cast<GroupRosterItem*>(CHILDREN[i]);
- }
-
- JID withResource(const JID& jid, const std::string& resource) {
- return JID(jid.toBare().toString() + "/" + resource);
- }
-
- void testPresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- groups.push_back("testGroup2");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
- Presence::ref presence(new Presence());
- presence->setFrom(withResource(from, "bob"));
- presence->setPriority(2);
- presence->setStatus("So totally here");
- stanzaChannel_->onPresenceReceived(presence);
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item->getStatusText());
- ContactRosterItem* item2 = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[1])->getChildren()[0]);
- CPPUNIT_ASSERT(item2);
- CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item2->getStatusText());
-
- }
-
- void testHighestPresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
- Presence::ref lowPresence(new Presence());
- lowPresence->setFrom(withResource(from, "bob"));
- lowPresence->setPriority(2);
- lowPresence->setStatus("Not here");
- Presence::ref highPresence(new Presence());
- highPresence->setFrom(withResource(from, "bert"));
- highPresence->setPriority(10);
- highPresence->setStatus("So totally here");
- stanzaChannel_->onPresenceReceived(lowPresence);
- stanzaChannel_->onPresenceReceived(highPresence);
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
- }
-
- void testNotHighestPresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
- Presence::ref lowPresence(new Presence());
- lowPresence->setFrom(withResource(from, "bob"));
- lowPresence->setPriority(2);
- lowPresence->setStatus("Not here");
- Presence::ref highPresence(new Presence());
- highPresence->setFrom(withResource(from, "bert"));
- highPresence->setPriority(10);
- highPresence->setStatus("So totally here");
- stanzaChannel_->onPresenceReceived(highPresence);
- stanzaChannel_->onPresenceReceived(lowPresence);
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
- }
-
- void testUnavailablePresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
-
- Presence::ref lowPresence(new Presence());
- lowPresence->setFrom(withResource(from, "bob"));
- lowPresence->setPriority(2);
- lowPresence->setShow(StatusShow::Away);
- lowPresence->setStatus("Not here");
- Presence::ref lowPresenceOffline(new Presence());
- lowPresenceOffline->setFrom(withResource(from, "bob"));
- lowPresenceOffline->setStatus("Signing out");
- lowPresenceOffline->setType(Presence::Unavailable);
-
- Presence::ref highPresence(new Presence());
- highPresence->setFrom(withResource(from, "bert"));
- highPresence->setPriority(10);
- highPresence->setStatus("So totally here");
- Presence::ref highPresenceOffline(new Presence());
- highPresenceOffline->setFrom(withResource(from, "bert"));
- highPresenceOffline->setType(Presence::Unavailable);
-
- stanzaChannel_->onPresenceReceived(lowPresence);
- Presence::ref accountPresence = presenceOracle_->getAccountPresence(from);
- CPPUNIT_ASSERT_EQUAL(StatusShow::Away, accountPresence->getShow());
-
- stanzaChannel_->onPresenceReceived(highPresence);
- accountPresence = presenceOracle_->getAccountPresence(from);
- CPPUNIT_ASSERT_EQUAL(StatusShow::Online, accountPresence->getShow());
-
- stanzaChannel_->onPresenceReceived(highPresenceOffline);
-
- // After this, the roster should show the low presence.
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
-
- Presence::ref low = presenceOracle_->getAccountPresence(from);
-
- CPPUNIT_ASSERT_EQUAL(Presence::Available, low->getType());
- CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), low->getStatus());
- CPPUNIT_ASSERT_EQUAL(lowPresence->getShow(), item->getStatusShow());
- CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), item->getStatusText());
- stanzaChannel_->onPresenceReceived(lowPresenceOffline);
- item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
- /* A verification that if the test fails, it's the RosterController, not the PresenceOracle. */
- low = presenceOracle_->getHighestPriorityPresence(from);
- CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, low->getType());
- CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), low->getStatus());
- CPPUNIT_ASSERT_EQUAL(StatusShow::None, item->getStatusShow());
- CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), item->getStatusText());
- }
-
- void testAdd() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- groups.push_back("testGroup2");
- xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups, RosterItemPayload::Both);
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(CHILDREN.size()));
- //CPPUNIT_ASSERT_EQUAL(std::string("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com")));
- }
-
- void testAddSubscription() {
- std::vector<std::string> groups;
- JID jid("test@testdomain.com");
- xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::None);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::To);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
-
- xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
-
- }
-
- void testReceiveRename() {
- std::vector<std::string> groups;
- JID jid("test@testdomain.com");
- xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("name"), groupChild(0)->getChildren()[0]->getDisplayName());
- xmppRoster_->addContact(jid, "NewName", groups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("NewName"), groupChild(0)->getChildren()[0]->getDisplayName());
- }
-
- void testReceiveRegroup() {
- std::vector<std::string> oldGroups;
- std::vector<std::string> newGroups;
- newGroups.push_back("A Group");
- std::vector<std::string> newestGroups;
- newestGroups.push_back("Best Group");
- JID jid("test@testdomain.com");
- xmppRoster_->addContact(jid, "", oldGroups, RosterItemPayload::Both);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(jid.toString(), groupChild(0)->getChildren()[0]->getDisplayName());
-
- xmppRoster_->addContact(jid, "new name", newGroups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("A Group"), groupChild(0)->getDisplayName());
-
- xmppRoster_->addContact(jid, "new name", newestGroups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Best Group"), groupChild(0)->getDisplayName());
- }
-
- void testSendRename() {
- JID jid("testling@wonderland.lit");
- std::vector<std::string> groups;
- groups.push_back("Friends");
- groups.push_back("Enemies");
- xmppRoster_->addContact(jid, "Bob", groups, RosterItemPayload::From);
- CPPUNIT_ASSERT_EQUAL(groups.size(), xmppRoster_->getGroupsForJID(jid).size());
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RenameRosterItemUIEvent(jid, "Robert")));
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), channel_->iqs_.size());
- CPPUNIT_ASSERT_EQUAL(IQ::Set, channel_->iqs_[0]->getType());
- boost::shared_ptr<RosterPayload> payload = channel_->iqs_[0]->getPayload<RosterPayload>();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getItems().size());
- RosterItemPayload item = payload->getItems()[0];
- CPPUNIT_ASSERT_EQUAL(jid, item.getJID());
- CPPUNIT_ASSERT_EQUAL(std::string("Robert"), item.getName());
-
- CPPUNIT_ASSERT_EQUAL(groups.size(), item.getGroups().size());
- assertVectorsEqual(groups, item.getGroups(), __LINE__);
- }
-
- void testRemoveResultsInUnavailablePresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
- Presence::ref lowPresence(new Presence());
- lowPresence->setFrom(withResource(from, "bob"));
- lowPresence->setPriority(2);
- lowPresence->setStatus("Not here");
- Presence::ref highPresence(new Presence());
- highPresence->setFrom(withResource(from, "bert"));
- highPresence->setPriority(10);
- highPresence->setStatus("So totally here");
- stanzaChannel_->onPresenceReceived(highPresence);
- stanzaChannel_->onPresenceReceived(lowPresence);
-
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), presenceOracle_->getAllPresence("test@testdomain.com").size());
-
- xmppRoster_->onJIDRemoved(JID("test@testdomain.com"));
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), presenceOracle_->getAllPresence("test@testdomain.com").size());
- CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presenceOracle_->getAllPresence("test@testdomain.com")[0]->getType());
- }
-
- void assertVectorsEqual(const std::vector<std::string>& v1, const std::vector<std::string>& v2, int line) {
- foreach (const std::string& entry, v1) {
- if (std::find(v2.begin(), v2.end(), entry) == v2.end()) {
- std::stringstream stream;
- stream << "Couldn't find " << entry << " in v2 (line " << line << ")";
- CPPUNIT_FAIL(stream.str());
- }
- }
- }
-
- private:
- JID jid_;
- XMPPRosterImpl* xmppRoster_;
- MUCRegistry* mucRegistry_;
- AvatarManager* avatarManager_;
- MockMainWindowFactory* mainWindowFactory_;
- NickManager* nickManager_;
- NickResolver* nickResolver_;
- RosterController* rosterController_;
- DummyIQChannel* channel_;
- DummyStanzaChannel* stanzaChannel_;
- IQRouter* router_;
- PresenceOracle* presenceOracle_;
- SubscriptionManager* subscriptionManager_;
- EventController* eventController_;
- UIEventStream* uiEventStream_;
- MockMainWindow* mainWindow_;
- DummySettingsProvider* settings_;
- DummyCapsProvider* capsProvider_;
- EntityCapsManager* entityCapsManager_;
- JingleSessionManager* jingleSessionManager_;
- FileTransferManager* ftManager_;
- FileTransferOverview* ftOverview_;
- ClientBlockListManager* clientBlockListManager_;
- CryptoProvider* crypto_;
- VCardStorage* vcardStorage_;
- VCardManager* vcardManager_;
+ CPPUNIT_TEST_SUITE(RosterControllerTest);
+ CPPUNIT_TEST(testAdd);
+ CPPUNIT_TEST(testAddSubscription);
+ CPPUNIT_TEST(testReceiveRename);
+ CPPUNIT_TEST(testReceiveRegroup);
+ CPPUNIT_TEST(testSendRename);
+ CPPUNIT_TEST(testPresence);
+ CPPUNIT_TEST(testHighestPresence);
+ CPPUNIT_TEST(testNotHighestPresence);
+ CPPUNIT_TEST(testUnavailablePresence);
+ CPPUNIT_TEST(testRemoveResultsInUnavailablePresence);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ jid_ = JID("testjid@swift.im/swift");
+ xmppRoster_ = new XMPPRosterImpl();
+ avatarManager_ = new NullAvatarManager();
+ mainWindowFactory_ = new MockMainWindowFactory();
+ mucRegistry_ = new MUCRegistry();
+ nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, NULL, mucRegistry_);
+ channel_ = new DummyIQChannel();
+ router_ = new IQRouter(channel_);
+ stanzaChannel_ = new DummyStanzaChannel();
+ presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
+ subscriptionManager_ = new SubscriptionManager(stanzaChannel_);
+ eventController_ = new EventController();
+ uiEventStream_ = new UIEventStream();
+ settings_ = new DummySettingsProvider();
+ nickManager_ = new DummyNickManager();
+ capsProvider_ = new DummyCapsProvider();
+ entityCapsManager_ = new EntityCapsManager(capsProvider_, stanzaChannel_);
+ jingleSessionManager_ = new JingleSessionManager(router_);
+
+ ftManager_ = new DummyFileTransferManager();
+ ftOverview_ = new FileTransferOverview(ftManager_);
+ clientBlockListManager_ = new ClientBlockListManager(router_);
+ crypto_ = PlatformCryptoProvider::create();
+ vcardStorage_ = new VCardMemoryStorage(crypto_);
+ vcardManager_ = new VCardManager(jid_, router_, vcardStorage_);
+ rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickManager_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_, entityCapsManager_, ftOverview_, clientBlockListManager_, vcardManager_);
+ mainWindow_ = mainWindowFactory_->last;
+ }
+
+ void tearDown() {
+ delete rosterController_;
+ delete vcardManager_;
+ delete vcardStorage_;
+ delete crypto_;
+ delete clientBlockListManager_;
+ delete ftOverview_;
+ delete ftManager_;
+ delete jingleSessionManager_;
+ delete entityCapsManager_;
+ delete capsProvider_;
+ delete nickManager_;
+ delete nickResolver_;
+ delete mucRegistry_;
+ delete mainWindowFactory_;
+ delete avatarManager_;
+ delete router_;
+ delete channel_;
+ delete eventController_;
+ delete subscriptionManager_;
+ delete presenceOracle_;
+ delete stanzaChannel_;
+ delete uiEventStream_;
+ delete settings_;
+ delete xmppRoster_;
+ }
+
+ GroupRosterItem* groupChild(size_t i) {
+ return dynamic_cast<GroupRosterItem*>(CHILDREN[i]);
+ }
+
+ JID withResource(const JID& jid, const std::string& resource) {
+ return JID(jid.toBare().toString() + "/" + resource);
+ }
+
+ void testPresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ groups.push_back("testGroup2");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+ Presence::ref presence(new Presence());
+ presence->setFrom(withResource(from, "bob"));
+ presence->setPriority(2);
+ presence->setStatus("So totally here");
+ stanzaChannel_->onPresenceReceived(presence);
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item->getStatusText());
+ ContactRosterItem* item2 = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[1])->getChildren()[0]);
+ CPPUNIT_ASSERT(item2);
+ CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item2->getStatusText());
+
+ }
+
+ void testHighestPresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+ Presence::ref lowPresence(new Presence());
+ lowPresence->setFrom(withResource(from, "bob"));
+ lowPresence->setPriority(2);
+ lowPresence->setStatus("Not here");
+ Presence::ref highPresence(new Presence());
+ highPresence->setFrom(withResource(from, "bert"));
+ highPresence->setPriority(10);
+ highPresence->setStatus("So totally here");
+ stanzaChannel_->onPresenceReceived(lowPresence);
+ stanzaChannel_->onPresenceReceived(highPresence);
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
+ }
+
+ void testNotHighestPresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+ Presence::ref lowPresence(new Presence());
+ lowPresence->setFrom(withResource(from, "bob"));
+ lowPresence->setPriority(2);
+ lowPresence->setStatus("Not here");
+ Presence::ref highPresence(new Presence());
+ highPresence->setFrom(withResource(from, "bert"));
+ highPresence->setPriority(10);
+ highPresence->setStatus("So totally here");
+ stanzaChannel_->onPresenceReceived(highPresence);
+ stanzaChannel_->onPresenceReceived(lowPresence);
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
+ }
+
+ void testUnavailablePresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+
+ Presence::ref lowPresence(new Presence());
+ lowPresence->setFrom(withResource(from, "bob"));
+ lowPresence->setPriority(2);
+ lowPresence->setShow(StatusShow::Away);
+ lowPresence->setStatus("Not here");
+ Presence::ref lowPresenceOffline(new Presence());
+ lowPresenceOffline->setFrom(withResource(from, "bob"));
+ lowPresenceOffline->setStatus("Signing out");
+ lowPresenceOffline->setType(Presence::Unavailable);
+
+ Presence::ref highPresence(new Presence());
+ highPresence->setFrom(withResource(from, "bert"));
+ highPresence->setPriority(10);
+ highPresence->setStatus("So totally here");
+ Presence::ref highPresenceOffline(new Presence());
+ highPresenceOffline->setFrom(withResource(from, "bert"));
+ highPresenceOffline->setType(Presence::Unavailable);
+
+ stanzaChannel_->onPresenceReceived(lowPresence);
+ Presence::ref accountPresence = presenceOracle_->getAccountPresence(from);
+ CPPUNIT_ASSERT_EQUAL(StatusShow::Away, accountPresence->getShow());
+
+ stanzaChannel_->onPresenceReceived(highPresence);
+ accountPresence = presenceOracle_->getAccountPresence(from);
+ CPPUNIT_ASSERT_EQUAL(StatusShow::Online, accountPresence->getShow());
+
+ stanzaChannel_->onPresenceReceived(highPresenceOffline);
+
+ // After this, the roster should show the low presence.
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+
+ Presence::ref low = presenceOracle_->getAccountPresence(from);
+
+ CPPUNIT_ASSERT_EQUAL(Presence::Available, low->getType());
+ CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), low->getStatus());
+ CPPUNIT_ASSERT_EQUAL(lowPresence->getShow(), item->getStatusShow());
+ CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), item->getStatusText());
+ stanzaChannel_->onPresenceReceived(lowPresenceOffline);
+ item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+ /* A verification that if the test fails, it's the RosterController, not the PresenceOracle. */
+ low = presenceOracle_->getHighestPriorityPresence(from);
+ CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, low->getType());
+ CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), low->getStatus());
+ CPPUNIT_ASSERT_EQUAL(StatusShow::None, item->getStatusShow());
+ CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), item->getStatusText());
+ }
+
+ void testAdd() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ groups.push_back("testGroup2");
+ xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups, RosterItemPayload::Both);
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(CHILDREN.size()));
+ //CPPUNIT_ASSERT_EQUAL(std::string("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com")));
+ }
+
+ void testAddSubscription() {
+ std::vector<std::string> groups;
+ JID jid("test@testdomain.com");
+ xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::None);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::To);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+
+ xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+
+ }
+
+ void testReceiveRename() {
+ std::vector<std::string> groups;
+ JID jid("test@testdomain.com");
+ xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("name"), groupChild(0)->getChildren()[0]->getDisplayName());
+ xmppRoster_->addContact(jid, "NewName", groups, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("NewName"), groupChild(0)->getChildren()[0]->getDisplayName());
+ }
+
+ void testReceiveRegroup() {
+ std::vector<std::string> oldGroups;
+ std::vector<std::string> newGroups;
+ newGroups.push_back("A Group");
+ std::vector<std::string> newestGroups;
+ newestGroups.push_back("Best Group");
+ JID jid("test@testdomain.com");
+ xmppRoster_->addContact(jid, "", oldGroups, RosterItemPayload::Both);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(jid.toString(), groupChild(0)->getChildren()[0]->getDisplayName());
+
+ xmppRoster_->addContact(jid, "new name", newGroups, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("A Group"), groupChild(0)->getDisplayName());
+
+ xmppRoster_->addContact(jid, "new name", newestGroups, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Best Group"), groupChild(0)->getDisplayName());
+ }
+
+ void testSendRename() {
+ JID jid("testling@wonderland.lit");
+ std::vector<std::string> groups;
+ groups.push_back("Friends");
+ groups.push_back("Enemies");
+ xmppRoster_->addContact(jid, "Bob", groups, RosterItemPayload::From);
+ CPPUNIT_ASSERT_EQUAL(groups.size(), xmppRoster_->getGroupsForJID(jid).size());
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RenameRosterItemUIEvent(jid, "Robert")));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), channel_->iqs_.size());
+ CPPUNIT_ASSERT_EQUAL(IQ::Set, channel_->iqs_[0]->getType());
+ boost::shared_ptr<RosterPayload> payload = channel_->iqs_[0]->getPayload<RosterPayload>();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getItems().size());
+ RosterItemPayload item = payload->getItems()[0];
+ CPPUNIT_ASSERT_EQUAL(jid, item.getJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("Robert"), item.getName());
+
+ CPPUNIT_ASSERT_EQUAL(groups.size(), item.getGroups().size());
+ assertVectorsEqual(groups, item.getGroups(), __LINE__);
+ }
+
+ void testRemoveResultsInUnavailablePresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+ Presence::ref lowPresence(new Presence());
+ lowPresence->setFrom(withResource(from, "bob"));
+ lowPresence->setPriority(2);
+ lowPresence->setStatus("Not here");
+ Presence::ref highPresence(new Presence());
+ highPresence->setFrom(withResource(from, "bert"));
+ highPresence->setPriority(10);
+ highPresence->setStatus("So totally here");
+ stanzaChannel_->onPresenceReceived(highPresence);
+ stanzaChannel_->onPresenceReceived(lowPresence);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), presenceOracle_->getAllPresence("test@testdomain.com").size());
+
+ xmppRoster_->onJIDRemoved(JID("test@testdomain.com"));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), presenceOracle_->getAllPresence("test@testdomain.com").size());
+ CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presenceOracle_->getAllPresence("test@testdomain.com")[0]->getType());
+ }
+
+ void assertVectorsEqual(const std::vector<std::string>& v1, const std::vector<std::string>& v2, int line) {
+ foreach (const std::string& entry, v1) {
+ if (std::find(v2.begin(), v2.end(), entry) == v2.end()) {
+ std::stringstream stream;
+ stream << "Couldn't find " << entry << " in v2 (line " << line << ")";
+ CPPUNIT_FAIL(stream.str());
+ }
+ }
+ }
+
+ private:
+ JID jid_;
+ XMPPRosterImpl* xmppRoster_;
+ MUCRegistry* mucRegistry_;
+ AvatarManager* avatarManager_;
+ MockMainWindowFactory* mainWindowFactory_;
+ NickManager* nickManager_;
+ NickResolver* nickResolver_;
+ RosterController* rosterController_;
+ DummyIQChannel* channel_;
+ DummyStanzaChannel* stanzaChannel_;
+ IQRouter* router_;
+ PresenceOracle* presenceOracle_;
+ SubscriptionManager* subscriptionManager_;
+ EventController* eventController_;
+ UIEventStream* uiEventStream_;
+ MockMainWindow* mainWindow_;
+ DummySettingsProvider* settings_;
+ DummyCapsProvider* capsProvider_;
+ EntityCapsManager* entityCapsManager_;
+ JingleSessionManager* jingleSessionManager_;
+ FileTransferManager* ftManager_;
+ FileTransferOverview* ftOverview_;
+ ClientBlockListManager* clientBlockListManager_;
+ CryptoProvider* crypto_;
+ VCardStorage* vcardStorage_;
+ VCardManager* vcardManager_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(RosterControllerTest);
diff --git a/Swift/Controllers/Roster/UnitTest/RosterTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterTest.cpp
index 314b5c6..dd22cb7 100644
--- a/Swift/Controllers/Roster/UnitTest/RosterTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/RosterTest.cpp
@@ -16,130 +16,130 @@
using namespace Swift;
class RosterTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(RosterTest);
- CPPUNIT_TEST(testGetGroup);
- CPPUNIT_TEST(testRemoveContact);
- CPPUNIT_TEST(testRemoveSecondContact);
- CPPUNIT_TEST(testRemoveSecondContactSameBare);
- CPPUNIT_TEST(testApplyPresenceLikeMUC);
- CPPUNIT_TEST(testReSortLikeMUC);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- jid1_ = JID("a@b.c");
- jid2_ = JID("b@c.d");
- jid3_ = JID("c@d.e");
- roster_ = new Roster();
- }
-
- void tearDown() {
- delete roster_;
- }
-
- void testGetGroup() {
- roster_->addContact(jid1_, JID(), "Bert", "group1", "");
- roster_->addContact(jid2_, JID(), "Ernie", "group2", "");
- roster_->addContact(jid3_, JID(), "Cookie", "group1", "");
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster_->getRoot()->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("group1"), roster_->getRoot()->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("group2"), roster_->getRoot()->getChildren()[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Ernie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[1])->getChildren()[0]->getDisplayName());
-
- }
-
- void testRemoveContact() {
- roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
-
- roster_->removeContact(jid1_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- }
-
- void testRemoveSecondContact() {
- roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
- roster_->addContact(jid2_, jid2_, "Cookie", "group1", "");
- CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
-
- roster_->removeContact(jid2_);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- }
-
- void testRemoveSecondContactSameBare() {
- JID jid4a("a@b/c");
- JID jid4b("a@b/d");
- roster_->addContact(jid4a, JID(), "Bert", "group1", "");
- roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
- CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
-
- roster_->removeContact(jid4b);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- }
-
- void testApplyPresenceLikeMUC() {
- JID jid4a("a@b/c");
- JID jid4b("a@b/d");
- JID jid4c("a@b/e");
- roster_->addContact(jid4a, JID(), "Bird", "group1", "");
- roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
- roster_->removeContact(jid4b);
- roster_->addContact(jid4c, JID(), "Bert", "group1", "");
- roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
- boost::shared_ptr<Presence> presence(new Presence());
- presence->setShow(StatusShow::DND);
- presence->setFrom(jid4a);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- presence->setFrom(jid4b);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- presence->setFrom(jid4c);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
-
- presence = boost::make_shared<Presence>();
- presence->setFrom(jid4b);
- presence->setShow(StatusShow::Online);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- std::vector<RosterItem*> children = static_cast<GroupRosterItem*>(roster_->getRoot()->getDisplayedChildren()[0])->getDisplayedChildren();
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(children.size()));
-
- /* Check order */
- CPPUNIT_ASSERT_EQUAL(std::string("Ernie"), children[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), children[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Bird"), children[2]->getDisplayName());
-
- presence = boost::make_shared<Presence>();
- presence->setFrom(jid4c);
- presence->setType(Presence::Unavailable);
- roster_->removeContact(jid4c);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
-
- }
-
- void testReSortLikeMUC() {
- JID jid4a("a@b/c");
- JID jid4b("a@b/d");
- JID jid4c("a@b/e");
- roster_->addContact(jid4a, JID(), "Bird", "group1", "");
- roster_->addContact(jid4b, JID(), "Cookie", "group2", "");
- roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
- roster_->getGroup("group1")->setManualSort("2");
- roster_->getGroup("group2")->setManualSort("1");
- GroupRosterItem* root = roster_->getRoot();
- const std::vector<RosterItem*> kids = root->getDisplayedChildren();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), kids.size());
- CPPUNIT_ASSERT_EQUAL(std::string("group2"), kids[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("group1"), kids[1]->getDisplayName());
- }
-
- private:
- Roster *roster_;
- JID jid1_;
- JID jid2_;
- JID jid3_;
+ CPPUNIT_TEST_SUITE(RosterTest);
+ CPPUNIT_TEST(testGetGroup);
+ CPPUNIT_TEST(testRemoveContact);
+ CPPUNIT_TEST(testRemoveSecondContact);
+ CPPUNIT_TEST(testRemoveSecondContactSameBare);
+ CPPUNIT_TEST(testApplyPresenceLikeMUC);
+ CPPUNIT_TEST(testReSortLikeMUC);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ jid1_ = JID("a@b.c");
+ jid2_ = JID("b@c.d");
+ jid3_ = JID("c@d.e");
+ roster_ = new Roster();
+ }
+
+ void tearDown() {
+ delete roster_;
+ }
+
+ void testGetGroup() {
+ roster_->addContact(jid1_, JID(), "Bert", "group1", "");
+ roster_->addContact(jid2_, JID(), "Ernie", "group2", "");
+ roster_->addContact(jid3_, JID(), "Cookie", "group1", "");
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster_->getRoot()->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("group1"), roster_->getRoot()->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("group2"), roster_->getRoot()->getChildren()[1]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Ernie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[1])->getChildren()[0]->getDisplayName());
+
+ }
+
+ void testRemoveContact() {
+ roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+
+ roster_->removeContact(jid1_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
+ }
+
+ void testRemoveSecondContact() {
+ roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
+ roster_->addContact(jid2_, jid2_, "Cookie", "group1", "");
+ CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
+
+ roster_->removeContact(jid2_);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+ }
+
+ void testRemoveSecondContactSameBare() {
+ JID jid4a("a@b/c");
+ JID jid4b("a@b/d");
+ roster_->addContact(jid4a, JID(), "Bert", "group1", "");
+ roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
+ CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
+
+ roster_->removeContact(jid4b);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+ }
+
+ void testApplyPresenceLikeMUC() {
+ JID jid4a("a@b/c");
+ JID jid4b("a@b/d");
+ JID jid4c("a@b/e");
+ roster_->addContact(jid4a, JID(), "Bird", "group1", "");
+ roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
+ roster_->removeContact(jid4b);
+ roster_->addContact(jid4c, JID(), "Bert", "group1", "");
+ roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
+ boost::shared_ptr<Presence> presence(new Presence());
+ presence->setShow(StatusShow::DND);
+ presence->setFrom(jid4a);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+ presence->setFrom(jid4b);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+ presence->setFrom(jid4c);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+
+ presence = boost::make_shared<Presence>();
+ presence->setFrom(jid4b);
+ presence->setShow(StatusShow::Online);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+ std::vector<RosterItem*> children = static_cast<GroupRosterItem*>(roster_->getRoot()->getDisplayedChildren()[0])->getDisplayedChildren();
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(children.size()));
+
+ /* Check order */
+ CPPUNIT_ASSERT_EQUAL(std::string("Ernie"), children[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), children[1]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Bird"), children[2]->getDisplayName());
+
+ presence = boost::make_shared<Presence>();
+ presence->setFrom(jid4c);
+ presence->setType(Presence::Unavailable);
+ roster_->removeContact(jid4c);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+
+ }
+
+ void testReSortLikeMUC() {
+ JID jid4a("a@b/c");
+ JID jid4b("a@b/d");
+ JID jid4c("a@b/e");
+ roster_->addContact(jid4a, JID(), "Bird", "group1", "");
+ roster_->addContact(jid4b, JID(), "Cookie", "group2", "");
+ roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
+ roster_->getGroup("group1")->setManualSort("2");
+ roster_->getGroup("group2")->setManualSort("1");
+ GroupRosterItem* root = roster_->getRoot();
+ const std::vector<RosterItem*> kids = root->getDisplayedChildren();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), kids.size());
+ CPPUNIT_ASSERT_EQUAL(std::string("group2"), kids[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("group1"), kids[1]->getDisplayName());
+ }
+
+ private:
+ Roster *roster_;
+ JID jid1_;
+ JID jid2_;
+ JID jid3_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(RosterTest);
diff --git a/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp b/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
index 10030ef..086bd6f 100644
--- a/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
@@ -9,8 +9,8 @@
std::ostream& operator<<(std::ostream& os, const Swift::TableRoster::Index& i);
std::ostream& operator<<(std::ostream& os, const Swift::TableRoster::Index& i) {
- os << "(" << i.section << ", " << i.row << ")";
- return os;
+ os << "(" << i.section << ", " << i.row << ")";
+ return os;
}
#include <cppunit/extensions/HelperMacros.h>
@@ -27,67 +27,67 @@ std::ostream& operator<<(std::ostream& os, const Swift::TableRoster::Index& i) {
using namespace Swift;
class TableRosterTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(TableRosterTest);
- CPPUNIT_TEST(testAddContact_EmptyRoster);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- timerFactory = new DummyTimerFactory();
- roster = new Roster();
- jid1 = JID("jid1@example.com");
- jid2 = JID("jid2@example.com");
- }
-
- void tearDown() {
- delete roster;
- delete timerFactory;
- }
-
- void testAddContact_EmptyRoster() {
- /*
- boost::shared_ptr<TableRoster> tableRoster(createTestling());
-
- addContact(jid1, "1", "group1");
-
- CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(events.size()));
- CPPUNIT_ASSERT(boost::get<BeginUpdatesEvent>(&events[0]));
- CPPUNIT_ASSERT(boost::get<SectionsInsertedEvent>(&events[1]));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(boost::get<SectionsInsertedEvent>(events[1]).sections.size()));
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(boost::get<SectionsInsertedEvent>(events[1]).sections[0]));
- CPPUNIT_ASSERT(boost::get<RowsInsertedEvent>(&events[2]));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(boost::get<RowsInsertedEvent>(events[2]).rows.size()));
- CPPUNIT_ASSERT_EQUAL(TableRoster::Index(0, 0), boost::get<RowsInsertedEvent>(events[2]).rows[0]);
- CPPUNIT_ASSERT(boost::get<EndUpdatesEvent>(&events[3]));
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(tableRoster->getNumberOfSections()));
- CPPUNIT_ASSERT_EQUAL(std::string("group1"), tableRoster->getSectionTitle(0));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(tableRoster->getNumberOfRowsInSection(0)));
- CPPUNIT_ASSERT_EQUAL(jid1, tableRoster->getItem(TableRoster::Index(0, 0)).jid);
- */
- }
-
- private:
- void addContact(const JID& jid, const std::string& name, const std::string& group) {
- roster->addContact(jid, JID(), name, group, "");
- }
-
- TableRoster* createTestling() {
- TableRoster* result = new TableRoster(roster, timerFactory, 10);
- result->onUpdate.connect(boost::bind(&TableRosterTest::handleUpdate, this, _1));
- return result;
- }
-
- void handleUpdate(const TableRoster::Update& update) {
- updates.push_back(update);
- }
-
- private:
- DummyTimerFactory* timerFactory;
- Roster* roster;
- JID jid1;
- JID jid2;
- std::vector<TableRoster::Update> updates;
+ CPPUNIT_TEST_SUITE(TableRosterTest);
+ CPPUNIT_TEST(testAddContact_EmptyRoster);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ timerFactory = new DummyTimerFactory();
+ roster = new Roster();
+ jid1 = JID("jid1@example.com");
+ jid2 = JID("jid2@example.com");
+ }
+
+ void tearDown() {
+ delete roster;
+ delete timerFactory;
+ }
+
+ void testAddContact_EmptyRoster() {
+ /*
+ boost::shared_ptr<TableRoster> tableRoster(createTestling());
+
+ addContact(jid1, "1", "group1");
+
+ CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(events.size()));
+ CPPUNIT_ASSERT(boost::get<BeginUpdatesEvent>(&events[0]));
+ CPPUNIT_ASSERT(boost::get<SectionsInsertedEvent>(&events[1]));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(boost::get<SectionsInsertedEvent>(events[1]).sections.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(boost::get<SectionsInsertedEvent>(events[1]).sections[0]));
+ CPPUNIT_ASSERT(boost::get<RowsInsertedEvent>(&events[2]));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(boost::get<RowsInsertedEvent>(events[2]).rows.size()));
+ CPPUNIT_ASSERT_EQUAL(TableRoster::Index(0, 0), boost::get<RowsInsertedEvent>(events[2]).rows[0]);
+ CPPUNIT_ASSERT(boost::get<EndUpdatesEvent>(&events[3]));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(tableRoster->getNumberOfSections()));
+ CPPUNIT_ASSERT_EQUAL(std::string("group1"), tableRoster->getSectionTitle(0));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(tableRoster->getNumberOfRowsInSection(0)));
+ CPPUNIT_ASSERT_EQUAL(jid1, tableRoster->getItem(TableRoster::Index(0, 0)).jid);
+ */
+ }
+
+ private:
+ void addContact(const JID& jid, const std::string& name, const std::string& group) {
+ roster->addContact(jid, JID(), name, group, "");
+ }
+
+ TableRoster* createTestling() {
+ TableRoster* result = new TableRoster(roster, timerFactory, 10);
+ result->onUpdate.connect(boost::bind(&TableRosterTest::handleUpdate, this, _1));
+ return result;
+ }
+
+ void handleUpdate(const TableRoster::Update& update) {
+ updates.push_back(update);
+ }
+
+ private:
+ DummyTimerFactory* timerFactory;
+ Roster* roster;
+ JID jid1;
+ JID jid2;
+ std::vector<TableRoster::Update> updates;
};
CPPUNIT_TEST_SUITE_REGISTRATION(TableRosterTest);
diff --git a/Swift/Controllers/SettingConstants.h b/Swift/Controllers/SettingConstants.h
index c4ac4ad..9343b7b 100644
--- a/Swift/Controllers/SettingConstants.h
+++ b/Swift/Controllers/SettingConstants.h
@@ -9,100 +9,100 @@
#include <Swift/Controllers/Settings/SettingsProvider.h>
namespace Swift {
- /**
- * This class contains the major setting keys for Swift.
- */
- class SettingConstants {
- public:
- /**
- * The #IDLE_GOES_OFFLINE setting specifies whether to close the XMPP connection when
- * the user went idle.
- *
- * True for automatic close of the XMPP connection and false for only changing the presence on idle.
- */
- static const SettingsProvider::Setting<bool> IDLE_GOES_OFFLINE;
- /**
- * The #IDLE_TIMEOUT setting specifieds the seconds the user has to be inactive at the
- * desktop so the user is regarded as idle.
- */
- static const SettingsProvider::Setting<int> IDLE_TIMEOUT;
- static const SettingsProvider::Setting<bool> SHOW_NOTIFICATIONS;
- /**
- * The #REQUEST_DELIVERYRECEIPTS settings specifies whether to request delivery receipts
- * for messages to contacts that support message receipts.
- */
- static const SettingsProvider::Setting<bool> REQUEST_DELIVERYRECEIPTS;
- static const SettingsProvider::Setting<bool> FORGET_PASSWORDS;
- static const SettingsProvider::Setting<bool> REMEMBER_RECENT_CHATS;
- static const SettingsProvider::Setting<std::string> LAST_LOGIN_JID;
- static const SettingsProvider::Setting<bool> LOGIN_AUTOMATICALLY;
- /**
- * The #SHOW_OFFLINE setting specifies whether or not to show offline contacts in the
- * roster.
- *
- * If set true Swift will show offline contacts; else not.
- */
- static const SettingsProvider::Setting<bool> SHOW_OFFLINE;
- /**
- * The #EXPANDED_ROSTER_GROUPS setting specifies the list of groups that are expanded
- * in the roster UI.
- *
- * Its value is a string with group names seperated by newlines.
- */
- static const SettingsProvider::Setting<std::string> EXPANDED_ROSTER_GROUPS;
- static const SettingsProvider::Setting<bool> PLAY_SOUNDS;
- /**
- * The #HIGHLIGHT_RULES setting specifies the highlight rules and the associated actions.
- *
- * Its value is a Boost serialized representation.
- */
- static const SettingsProvider::Setting<std::string> HIGHLIGHT_RULES;
- static const SettingsProvider::Setting<bool> SPELL_CHECKER;
- static const SettingsProvider::Setting<std::string> DICT_PATH;
- static const SettingsProvider::Setting<std::string> PERSONAL_DICT_PATH;
- static const SettingsProvider::Setting<std::string> DICT_FILE;
- /**
- * The #INVITE_AUTO_ACCEPT_MODE setting specifies how to handle invites to chat rooms.
- *
- * Supported values are:
- * - "no" : It is up to the user whether to accept the invitation and enter a room or not.
- * - "presence" : The invitation is automatically accepted if it is from a contact that is
- * already allowed to see the user's presence status.
- * - "domain" : The invitation is automatically accepted if it is from a contact that is
- * already allowed to see the user's presence status or from a contact of user's domain.
- */
- static const SettingsProvider::Setting<std::string> INVITE_AUTO_ACCEPT_MODE;
- /**
- * The #TRELLIS_GRID_SIZE setting specifies the dimensions of the grid used for the trellis
- * layout.
- *
- * Its value is a Qt serialized representation.
- */
- static const SettingsProvider::Setting<std::string> TRELLIS_GRID_SIZE;
- /**
- * The #TRELLIS_GRID_POSITIONS setting specifies where conversations to contacts or rooms go
- * in the trellis grid.
- *
- * Its value is a Qt serialized representation.
- */
- static const SettingsProvider::Setting<std::string> TRELLIS_GRID_POSITIONS;
- /**
- * The #DISCONNECT_ON_CARD_REMOVAL setting
- * specifies whether or not to sign out the user when
- * the smartcard is removed.
- *
- * If set true Swift will sign out the user when the
- * smart card is removed; else not.
- */
- static const SettingsProvider::Setting<bool> DISCONNECT_ON_CARD_REMOVAL;
- /**
- * The #SINGLE_SIGN_ON setting
- * specifies whether to log in using Single Sign On.
- * This is currently supported on Windows.
- *
- * If set true Swift will use GSSAPI authentication to
- * log in the user; else not.
- */
- static const SettingsProvider::Setting<bool> SINGLE_SIGN_ON;
- };
+ /**
+ * This class contains the major setting keys for Swift.
+ */
+ class SettingConstants {
+ public:
+ /**
+ * The #IDLE_GOES_OFFLINE setting specifies whether to close the XMPP connection when
+ * the user went idle.
+ *
+ * True for automatic close of the XMPP connection and false for only changing the presence on idle.
+ */
+ static const SettingsProvider::Setting<bool> IDLE_GOES_OFFLINE;
+ /**
+ * The #IDLE_TIMEOUT setting specifieds the seconds the user has to be inactive at the
+ * desktop so the user is regarded as idle.
+ */
+ static const SettingsProvider::Setting<int> IDLE_TIMEOUT;
+ static const SettingsProvider::Setting<bool> SHOW_NOTIFICATIONS;
+ /**
+ * The #REQUEST_DELIVERYRECEIPTS settings specifies whether to request delivery receipts
+ * for messages to contacts that support message receipts.
+ */
+ static const SettingsProvider::Setting<bool> REQUEST_DELIVERYRECEIPTS;
+ static const SettingsProvider::Setting<bool> FORGET_PASSWORDS;
+ static const SettingsProvider::Setting<bool> REMEMBER_RECENT_CHATS;
+ static const SettingsProvider::Setting<std::string> LAST_LOGIN_JID;
+ static const SettingsProvider::Setting<bool> LOGIN_AUTOMATICALLY;
+ /**
+ * The #SHOW_OFFLINE setting specifies whether or not to show offline contacts in the
+ * roster.
+ *
+ * If set true Swift will show offline contacts; else not.
+ */
+ static const SettingsProvider::Setting<bool> SHOW_OFFLINE;
+ /**
+ * The #EXPANDED_ROSTER_GROUPS setting specifies the list of groups that are expanded
+ * in the roster UI.
+ *
+ * Its value is a string with group names seperated by newlines.
+ */
+ static const SettingsProvider::Setting<std::string> EXPANDED_ROSTER_GROUPS;
+ static const SettingsProvider::Setting<bool> PLAY_SOUNDS;
+ /**
+ * The #HIGHLIGHT_RULES setting specifies the highlight rules and the associated actions.
+ *
+ * Its value is a Boost serialized representation.
+ */
+ static const SettingsProvider::Setting<std::string> HIGHLIGHT_RULES;
+ static const SettingsProvider::Setting<bool> SPELL_CHECKER;
+ static const SettingsProvider::Setting<std::string> DICT_PATH;
+ static const SettingsProvider::Setting<std::string> PERSONAL_DICT_PATH;
+ static const SettingsProvider::Setting<std::string> DICT_FILE;
+ /**
+ * The #INVITE_AUTO_ACCEPT_MODE setting specifies how to handle invites to chat rooms.
+ *
+ * Supported values are:
+ * - "no" : It is up to the user whether to accept the invitation and enter a room or not.
+ * - "presence" : The invitation is automatically accepted if it is from a contact that is
+ * already allowed to see the user's presence status.
+ * - "domain" : The invitation is automatically accepted if it is from a contact that is
+ * already allowed to see the user's presence status or from a contact of user's domain.
+ */
+ static const SettingsProvider::Setting<std::string> INVITE_AUTO_ACCEPT_MODE;
+ /**
+ * The #TRELLIS_GRID_SIZE setting specifies the dimensions of the grid used for the trellis
+ * layout.
+ *
+ * Its value is a Qt serialized representation.
+ */
+ static const SettingsProvider::Setting<std::string> TRELLIS_GRID_SIZE;
+ /**
+ * The #TRELLIS_GRID_POSITIONS setting specifies where conversations to contacts or rooms go
+ * in the trellis grid.
+ *
+ * Its value is a Qt serialized representation.
+ */
+ static const SettingsProvider::Setting<std::string> TRELLIS_GRID_POSITIONS;
+ /**
+ * The #DISCONNECT_ON_CARD_REMOVAL setting
+ * specifies whether or not to sign out the user when
+ * the smartcard is removed.
+ *
+ * If set true Swift will sign out the user when the
+ * smart card is removed; else not.
+ */
+ static const SettingsProvider::Setting<bool> DISCONNECT_ON_CARD_REMOVAL;
+ /**
+ * The #SINGLE_SIGN_ON setting
+ * specifies whether to log in using Single Sign On.
+ * This is currently supported on Windows.
+ *
+ * If set true Swift will use GSSAPI authentication to
+ * log in the user; else not.
+ */
+ static const SettingsProvider::Setting<bool> SINGLE_SIGN_ON;
+ };
}
diff --git a/Swift/Controllers/Settings/DummySettingsProvider.h b/Swift/Controllers/Settings/DummySettingsProvider.h
index 605153e..63c0767 100644
--- a/Swift/Controllers/Settings/DummySettingsProvider.h
+++ b/Swift/Controllers/Settings/DummySettingsProvider.h
@@ -13,44 +13,44 @@
namespace Swift {
class DummySettingsProvider : public SettingsProvider {
- public:
- virtual ~DummySettingsProvider() {}
- virtual std::string getSetting(const Setting<std::string>& setting) {
- return stringValues.find(setting.getKey()) != stringValues.end() ? stringValues[setting.getKey()] : setting.getDefaultValue();
- }
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) {
- stringValues[setting.getKey()] = value;
- onSettingChanged(setting.getKey());
- }
- virtual bool getSetting(const Setting<bool>& setting) {
- return boolValues.find(setting.getKey()) != boolValues.end() ? boolValues[setting.getKey()] : setting.getDefaultValue();
- }
- virtual void storeSetting(const Setting<bool>& setting, const bool& value) {
- boolValues[setting.getKey()] = value;
- onSettingChanged(setting.getKey());
- }
- virtual int getSetting(const Setting<int>& setting) {
- return intValues.find(setting.getKey()) != intValues.end() ? intValues[setting.getKey()] : setting.getDefaultValue();
- }
- virtual void storeSetting(const Setting<int>& setting, const int& value) {
- intValues[setting.getKey()] = value;
- onSettingChanged(setting.getKey());
- }
- virtual std::vector<std::string> getAvailableProfiles() {return std::vector<std::string>();}
- virtual void createProfile(const std::string& ) {}
- virtual void removeProfile(const std::string& ) {}
- virtual bool getIsSettingFinal(const std::string& settingPath) {return finals.count(settingPath);}
- void setFinal(const std::string& settingPath) {
- finals.insert(settingPath);
- }
- virtual bool hasSetting(const std::string& key) {
- return stringValues.find(key) != stringValues.end() || intValues.find(key) != intValues.end() || boolValues.find(key) != boolValues.end();
- }
- private:
- std::map<std::string, std::string> stringValues;
- std::map<std::string, int> intValues;
- std::map<std::string, bool> boolValues;
- std::set<std::string> finals;
+ public:
+ virtual ~DummySettingsProvider() {}
+ virtual std::string getSetting(const Setting<std::string>& setting) {
+ return stringValues.find(setting.getKey()) != stringValues.end() ? stringValues[setting.getKey()] : setting.getDefaultValue();
+ }
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) {
+ stringValues[setting.getKey()] = value;
+ onSettingChanged(setting.getKey());
+ }
+ virtual bool getSetting(const Setting<bool>& setting) {
+ return boolValues.find(setting.getKey()) != boolValues.end() ? boolValues[setting.getKey()] : setting.getDefaultValue();
+ }
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value) {
+ boolValues[setting.getKey()] = value;
+ onSettingChanged(setting.getKey());
+ }
+ virtual int getSetting(const Setting<int>& setting) {
+ return intValues.find(setting.getKey()) != intValues.end() ? intValues[setting.getKey()] : setting.getDefaultValue();
+ }
+ virtual void storeSetting(const Setting<int>& setting, const int& value) {
+ intValues[setting.getKey()] = value;
+ onSettingChanged(setting.getKey());
+ }
+ virtual std::vector<std::string> getAvailableProfiles() {return std::vector<std::string>();}
+ virtual void createProfile(const std::string& ) {}
+ virtual void removeProfile(const std::string& ) {}
+ virtual bool getIsSettingFinal(const std::string& settingPath) {return finals.count(settingPath);}
+ void setFinal(const std::string& settingPath) {
+ finals.insert(settingPath);
+ }
+ virtual bool hasSetting(const std::string& key) {
+ return stringValues.find(key) != stringValues.end() || intValues.find(key) != intValues.end() || boolValues.find(key) != boolValues.end();
+ }
+ private:
+ std::map<std::string, std::string> stringValues;
+ std::map<std::string, int> intValues;
+ std::map<std::string, bool> boolValues;
+ std::set<std::string> finals;
};
}
diff --git a/Swift/Controllers/Settings/SettingsProvider.h b/Swift/Controllers/Settings/SettingsProvider.h
index 29e26b5..a804235 100644
--- a/Swift/Controllers/Settings/SettingsProvider.h
+++ b/Swift/Controllers/Settings/SettingsProvider.h
@@ -15,57 +15,57 @@ namespace Swift {
class SettingsProvider {
- public:
- template <typename T>
- class Setting {
- public:
- Setting(const std::string& key, const T& defaultValue) : key(key), defaultValue(defaultValue) {
-
- }
-
- const std::string& getKey() const {
- return key;
- }
-
- const T& getDefaultValue() const {
- return defaultValue;
- }
-
- private:
- std::string key;
- T defaultValue;
- };
-
- public:
- virtual ~SettingsProvider() {}
- virtual std::string getSetting(const Setting<std::string>& setting) = 0;
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) = 0;
- virtual bool getSetting(const Setting<bool>& setting) = 0;
- virtual void storeSetting(const Setting<bool>& setting, const bool& value) = 0;
- virtual int getSetting(const Setting<int>& setting) = 0;
- virtual void storeSetting(const Setting<int>& setting, const int& value) = 0;
-
- virtual std::vector<std::string> getAvailableProfiles() = 0;
- virtual void createProfile(const std::string& profile) = 0;
- virtual void removeProfile(const std::string& profile) = 0;
- /** A final setting is one that this settings provider says may not be overriden by lower priority profiles.
- * e.g. An Administrator-set configuration to disallow saving user passwords could not be overridden by the user.
- */
- template<typename T>
- bool getIsSettingFinal(const Setting<T>& setting) {
- return getIsSettingFinal(setting.getKey());
- }
- virtual bool hasSetting(const std::string& key) = 0;
-
- friend class SettingsProviderHierachy;
- protected:
- virtual bool getIsSettingFinal(const std::string& settingPath) = 0;
-
- public:
- /**
- * Emitted when a setting is changed.
- */
- boost::signal<void (const std::string& /*Setting's Path*/)> onSettingChanged;
+ public:
+ template <typename T>
+ class Setting {
+ public:
+ Setting(const std::string& key, const T& defaultValue) : key(key), defaultValue(defaultValue) {
+
+ }
+
+ const std::string& getKey() const {
+ return key;
+ }
+
+ const T& getDefaultValue() const {
+ return defaultValue;
+ }
+
+ private:
+ std::string key;
+ T defaultValue;
+ };
+
+ public:
+ virtual ~SettingsProvider() {}
+ virtual std::string getSetting(const Setting<std::string>& setting) = 0;
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) = 0;
+ virtual bool getSetting(const Setting<bool>& setting) = 0;
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value) = 0;
+ virtual int getSetting(const Setting<int>& setting) = 0;
+ virtual void storeSetting(const Setting<int>& setting, const int& value) = 0;
+
+ virtual std::vector<std::string> getAvailableProfiles() = 0;
+ virtual void createProfile(const std::string& profile) = 0;
+ virtual void removeProfile(const std::string& profile) = 0;
+ /** A final setting is one that this settings provider says may not be overriden by lower priority profiles.
+ * e.g. An Administrator-set configuration to disallow saving user passwords could not be overridden by the user.
+ */
+ template<typename T>
+ bool getIsSettingFinal(const Setting<T>& setting) {
+ return getIsSettingFinal(setting.getKey());
+ }
+ virtual bool hasSetting(const std::string& key) = 0;
+
+ friend class SettingsProviderHierachy;
+ protected:
+ virtual bool getIsSettingFinal(const std::string& settingPath) = 0;
+
+ public:
+ /**
+ * Emitted when a setting is changed.
+ */
+ boost::signal<void (const std::string& /*Setting's Path*/)> onSettingChanged;
};
}
diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
index a349417..5156d14 100644
--- a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
+++ b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
@@ -14,102 +14,102 @@ SettingsProviderHierachy::~SettingsProviderHierachy() {
}
bool SettingsProviderHierachy::hasSetting(const std::string& key) {
- foreach (SettingsProvider* provider, providers_) {
- if (provider->hasSetting(key)) {
- return true;
- }
- }
- return false;
+ foreach (SettingsProvider* provider, providers_) {
+ if (provider->hasSetting(key)) {
+ return true;
+ }
+ }
+ return false;
}
std::string SettingsProviderHierachy::getSetting(const Setting<std::string>& setting) {
- std::string value = setting.getDefaultValue();
- foreach (SettingsProvider* provider, providers_) {
- std::string providerSetting = provider->getSetting(setting);
- if (provider->hasSetting(setting.getKey())) {
- value = providerSetting;
- }
- if (provider->getIsSettingFinal(setting.getKey())) {
- return value;
- }
- }
- return value;
+ std::string value = setting.getDefaultValue();
+ foreach (SettingsProvider* provider, providers_) {
+ std::string providerSetting = provider->getSetting(setting);
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ }
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return value;
+ }
+ }
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<std::string>& setting, const std::string& settingValue) {
- if (!getIsSettingFinal(setting.getKey())) {
- getWritableProvider()->storeSetting(setting, settingValue);
- }
+ if (!getIsSettingFinal(setting.getKey())) {
+ getWritableProvider()->storeSetting(setting, settingValue);
+ }
}
bool SettingsProviderHierachy::getSetting(const Setting<bool>& setting) {
- bool value = setting.getDefaultValue();
- foreach (SettingsProvider* provider, providers_) {
- bool providerSetting = provider->getSetting(setting);
- if (provider->hasSetting(setting.getKey())) {
- value = providerSetting;
- if (provider->getIsSettingFinal(setting.getKey())) {
- return providerSetting;
- }
- }
- }
- return value;
+ bool value = setting.getDefaultValue();
+ foreach (SettingsProvider* provider, providers_) {
+ bool providerSetting = provider->getSetting(setting);
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return providerSetting;
+ }
+ }
+ }
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<bool>& setting, const bool& settingValue) {
- if (!getIsSettingFinal(setting.getKey())) {
- getWritableProvider()->storeSetting(setting, settingValue);
- }
+ if (!getIsSettingFinal(setting.getKey())) {
+ getWritableProvider()->storeSetting(setting, settingValue);
+ }
}
int SettingsProviderHierachy::getSetting(const Setting<int>& setting) {
- int value = setting.getDefaultValue();
- foreach (SettingsProvider* provider, providers_) {
- int providerSetting = provider->getSetting(setting);
- if (provider->hasSetting(setting.getKey())) {
- value = providerSetting;
- if (provider->getIsSettingFinal(setting.getKey())) {
- return providerSetting;
- }
- }
- }
- return value;
+ int value = setting.getDefaultValue();
+ foreach (SettingsProvider* provider, providers_) {
+ int providerSetting = provider->getSetting(setting);
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return providerSetting;
+ }
+ }
+ }
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<int>& setting, const int& settingValue) {
- if (!getIsSettingFinal(setting.getKey())) {
- getWritableProvider()->storeSetting(setting, settingValue);
- }
+ if (!getIsSettingFinal(setting.getKey())) {
+ getWritableProvider()->storeSetting(setting, settingValue);
+ }
}
std::vector<std::string> SettingsProviderHierachy::getAvailableProfiles() {
- /* Always pull profiles from the topmost */
- return getWritableProvider()->getAvailableProfiles();
+ /* Always pull profiles from the topmost */
+ return getWritableProvider()->getAvailableProfiles();
}
void SettingsProviderHierachy::createProfile(const std::string& profile) {
- return getWritableProvider()->createProfile(profile);
+ return getWritableProvider()->createProfile(profile);
}
void SettingsProviderHierachy::removeProfile(const std::string& profile) {
- return getWritableProvider()->removeProfile(profile);
+ return getWritableProvider()->removeProfile(profile);
}
bool SettingsProviderHierachy::getIsSettingFinal(const std::string& settingPath) {
- bool isFinal = false;
- foreach (SettingsProvider* provider, providers_) {
- isFinal |= provider->getIsSettingFinal(settingPath);
- }
- return isFinal;
+ bool isFinal = false;
+ foreach (SettingsProvider* provider, providers_) {
+ isFinal |= provider->getIsSettingFinal(settingPath);
+ }
+ return isFinal;
}
SettingsProvider* SettingsProviderHierachy::getWritableProvider() {
- return providers_.back();
+ return providers_.back();
}
void SettingsProviderHierachy::addProviderToTopOfStack(SettingsProvider* provider) {
- providers_.push_back(provider);
- provider->onSettingChanged.connect(onSettingChanged);
+ providers_.push_back(provider);
+ provider->onSettingChanged.connect(onSettingChanged);
}
}
diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.h b/Swift/Controllers/Settings/SettingsProviderHierachy.h
index 9efbdcb..a68ff36 100644
--- a/Swift/Controllers/Settings/SettingsProviderHierachy.h
+++ b/Swift/Controllers/Settings/SettingsProviderHierachy.h
@@ -11,34 +11,34 @@
namespace Swift {
class SettingsProviderHierachy : public SettingsProvider {
- public:
- virtual ~SettingsProviderHierachy();
- virtual std::string getSetting(const Setting<std::string>& setting);
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
- virtual bool getSetting(const Setting<bool>& setting);
- virtual void storeSetting(const Setting<bool>& setting, const bool& value);
- virtual int getSetting(const Setting<int>& setting);
- virtual void storeSetting(const Setting<int>& setting, const int& value);
- virtual std::vector<std::string> getAvailableProfiles();
- virtual void createProfile(const std::string& profile);
- virtual void removeProfile(const std::string& profile);
- virtual bool hasSetting(const std::string& key);
- protected:
- virtual bool getIsSettingFinal(const std::string& settingPath);
-
- public:
- /**
- * Adds a provider less significant than any already added.
- * This means that if an existing provider has a setting, this provider won't be asked.
- * Any settings will be pushed into the topmost (least significant) provider.
- * Does not take ownership of provider.
- */
- void addProviderToTopOfStack(SettingsProvider* provider);
- private:
- SettingsProvider* getWritableProvider();
- private:
- /* Start/Left is most significant (lowest), left overrides right.*/
- std::vector<SettingsProvider*> providers_;
+ public:
+ virtual ~SettingsProviderHierachy();
+ virtual std::string getSetting(const Setting<std::string>& setting);
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
+ virtual bool getSetting(const Setting<bool>& setting);
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value);
+ virtual int getSetting(const Setting<int>& setting);
+ virtual void storeSetting(const Setting<int>& setting, const int& value);
+ virtual std::vector<std::string> getAvailableProfiles();
+ virtual void createProfile(const std::string& profile);
+ virtual void removeProfile(const std::string& profile);
+ virtual bool hasSetting(const std::string& key);
+ protected:
+ virtual bool getIsSettingFinal(const std::string& settingPath);
+
+ public:
+ /**
+ * Adds a provider less significant than any already added.
+ * This means that if an existing provider has a setting, this provider won't be asked.
+ * Any settings will be pushed into the topmost (least significant) provider.
+ * Does not take ownership of provider.
+ */
+ void addProviderToTopOfStack(SettingsProvider* provider);
+ private:
+ SettingsProvider* getWritableProvider();
+ private:
+ /* Start/Left is most significant (lowest), left overrides right.*/
+ std::vector<SettingsProvider*> providers_;
};
}
diff --git a/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp b/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp
index 11d5c11..5822add 100644
--- a/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp
+++ b/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp
@@ -15,77 +15,77 @@ using namespace Swift;
using namespace std;
class SettingsProviderHierachyTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(SettingsProviderHierachyTest);
- CPPUNIT_TEST(testEmpty);
- CPPUNIT_TEST(testTop);
- CPPUNIT_TEST(testBottom);
- CPPUNIT_TEST(testBoth);
- CPPUNIT_TEST(testTopDefault);
- CPPUNIT_TEST(testBottomOverrides);
- CPPUNIT_TEST(testFinal);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(SettingsProviderHierachyTest);
+ CPPUNIT_TEST(testEmpty);
+ CPPUNIT_TEST(testTop);
+ CPPUNIT_TEST(testBottom);
+ CPPUNIT_TEST(testBoth);
+ CPPUNIT_TEST(testTopDefault);
+ CPPUNIT_TEST(testBottomOverrides);
+ CPPUNIT_TEST(testFinal);
+ CPPUNIT_TEST_SUITE_END();
public:
- SettingsProviderHierachyTest() : setting1("somekey", 42) {}
+ SettingsProviderHierachyTest() : setting1("somekey", 42) {}
- void setUp() {
- bottom = new DummySettingsProvider();
- top = new DummySettingsProvider();
- testling = new SettingsProviderHierachy();
- testling->addProviderToTopOfStack(bottom);
- testling->addProviderToTopOfStack(top);
- }
+ void setUp() {
+ bottom = new DummySettingsProvider();
+ top = new DummySettingsProvider();
+ testling = new SettingsProviderHierachy();
+ testling->addProviderToTopOfStack(bottom);
+ testling->addProviderToTopOfStack(top);
+ }
- void tearDown() {
- delete testling;
- delete top;
- delete bottom;
- }
+ void tearDown() {
+ delete testling;
+ delete top;
+ delete bottom;
+ }
- void testEmpty() {
- CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
- }
+ void testEmpty() {
+ CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
+ }
- void testTop() {
- top->storeSetting(setting1, 37);
- CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
- }
+ void testTop() {
+ top->storeSetting(setting1, 37);
+ CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
+ }
- void testBottom() {
- bottom->storeSetting(setting1, 17);
- CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
- }
+ void testBottom() {
+ bottom->storeSetting(setting1, 17);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
- void testBoth() {
- bottom->storeSetting(setting1, 17);
- top->storeSetting(setting1, 37);
- CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
- }
+ void testBoth() {
+ bottom->storeSetting(setting1, 17);
+ top->storeSetting(setting1, 37);
+ CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
+ }
- void testTopDefault() {
- bottom->storeSetting(setting1, 17);
- top->storeSetting(setting1, 42);
- CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
- }
+ void testTopDefault() {
+ bottom->storeSetting(setting1, 17);
+ top->storeSetting(setting1, 42);
+ CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
+ }
- void testBottomOverrides() {
- bottom->storeSetting(setting1, 17);
- bottom->setFinal(setting1.getKey());
- top->storeSetting(setting1, 5);
- CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
- }
+ void testBottomOverrides() {
+ bottom->storeSetting(setting1, 17);
+ bottom->setFinal(setting1.getKey());
+ top->storeSetting(setting1, 5);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
- void testFinal() {
- bottom->storeSetting(setting1, 17);
- bottom->setFinal(setting1.getKey());
- testling->storeSetting(setting1, 5);
- CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
- }
+ void testFinal() {
+ bottom->storeSetting(setting1, 17);
+ bottom->setFinal(setting1.getKey());
+ testling->storeSetting(setting1, 5);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
private:
- SettingsProviderHierachy* testling;
- DummySettingsProvider* bottom;
- DummySettingsProvider* top;
- SettingsProvider::Setting<int> setting1;
+ SettingsProviderHierachy* testling;
+ DummySettingsProvider* bottom;
+ DummySettingsProvider* top;
+ SettingsProvider::Setting<int> setting1;
};
CPPUNIT_TEST_SUITE_REGISTRATION(SettingsProviderHierachyTest);
diff --git a/Swift/Controllers/Settings/XMLSettingsProvider.cpp b/Swift/Controllers/Settings/XMLSettingsProvider.cpp
index 548f36f..4dfb8bd 100644
--- a/Swift/Controllers/Settings/XMLSettingsProvider.cpp
+++ b/Swift/Controllers/Settings/XMLSettingsProvider.cpp
@@ -16,20 +16,20 @@
namespace Swift {
XMLSettingsProvider::XMLSettingsProvider(const std::string& xmlConfig) : level_(0) {
- if (!xmlConfig.empty()) {
- PlatformXMLParserFactory factory;
- XMLParser* parser = factory.createXMLParser(this);
- if (parser->parse(xmlConfig)) {
- SWIFT_LOG(debug) << "Found and parsed system config" << std::endl;
- }
- else {
- SWIFT_LOG(debug) << "Found invalid system config" << std::endl;
- }
- delete parser;
- }
- else {
- SWIFT_LOG(debug) << "No system config found" << std::endl;
- }
+ if (!xmlConfig.empty()) {
+ PlatformXMLParserFactory factory;
+ XMLParser* parser = factory.createXMLParser(this);
+ if (parser->parse(xmlConfig)) {
+ SWIFT_LOG(debug) << "Found and parsed system config" << std::endl;
+ }
+ else {
+ SWIFT_LOG(debug) << "Found invalid system config" << std::endl;
+ }
+ delete parser;
+ }
+ else {
+ SWIFT_LOG(debug) << "No system config found" << std::endl;
+ }
}
XMLSettingsProvider::~XMLSettingsProvider() {
@@ -37,89 +37,89 @@ XMLSettingsProvider::~XMLSettingsProvider() {
}
bool XMLSettingsProvider::hasSetting(const std::string& key) {
- return (values_.find(key) != values_.end());
+ return (values_.find(key) != values_.end());
}
std::string XMLSettingsProvider::getSetting(const Setting<std::string>& setting) {
- if (values_.find(setting.getKey()) != values_.end()) {
- std::string value = values_[setting.getKey()];
- return value;
- }
- return setting.getDefaultValue();
+ if (values_.find(setting.getKey()) != values_.end()) {
+ std::string value = values_[setting.getKey()];
+ return value;
+ }
+ return setting.getDefaultValue();
}
void XMLSettingsProvider::storeSetting(const Setting<std::string>& /*settingPath*/, const std::string& /*settingValue*/) {
- assert(false);
+ assert(false);
}
bool XMLSettingsProvider::getSetting(const Setting<bool>& setting) {
- if (values_.find(setting.getKey()) != values_.end()) {
- std::string value = values_[setting.getKey()];
- return boost::iequals(value, "true") || value == "1";
- }
- return setting.getDefaultValue();
+ if (values_.find(setting.getKey()) != values_.end()) {
+ std::string value = values_[setting.getKey()];
+ return boost::iequals(value, "true") || value == "1";
+ }
+ return setting.getDefaultValue();
}
void XMLSettingsProvider::storeSetting(const Setting<bool>& /*settingPath*/, const bool& /*settingValue*/) {
- assert(false);
+ assert(false);
}
int XMLSettingsProvider::getSetting(const Setting<int>& setting) {
- if (values_.find(setting.getKey()) != values_.end()) {
- std::string value = values_[setting.getKey()];
- try {
- return value.empty() ? setting.getDefaultValue() : boost::lexical_cast<int>(value);;
- }
- catch(boost::bad_lexical_cast &) {}
- }
- return setting.getDefaultValue();
+ if (values_.find(setting.getKey()) != values_.end()) {
+ std::string value = values_[setting.getKey()];
+ try {
+ return value.empty() ? setting.getDefaultValue() : boost::lexical_cast<int>(value);;
+ }
+ catch(boost::bad_lexical_cast &) {}
+ }
+ return setting.getDefaultValue();
}
void XMLSettingsProvider::storeSetting(const Setting<int>& /*settingPath*/, const int& /*settingValue*/) {
- assert(false);
+ assert(false);
}
std::vector<std::string> XMLSettingsProvider::getAvailableProfiles() {
- assert(false);
- return std::vector<std::string>();
+ assert(false);
+ return std::vector<std::string>();
}
void XMLSettingsProvider::createProfile(const std::string& /*profile*/) {
- assert(false);
+ assert(false);
}
void XMLSettingsProvider::removeProfile(const std::string& /*profile*/) {
- assert(false);
+ assert(false);
}
bool XMLSettingsProvider::getIsSettingFinal(const std::string& settingPath) {
- return finals_.count(settingPath);
+ return finals_.count(settingPath);
}
void XMLSettingsProvider::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) {
- level_++;
- if (level_ == SettingLevel) {
- if (attributes.getBoolAttribute("final", false)) {
- finals_.insert(element);
- }
- currentElement_ = element;
- currentText_ = "";
- }
+ level_++;
+ if (level_ == SettingLevel) {
+ if (attributes.getBoolAttribute("final", false)) {
+ finals_.insert(element);
+ }
+ currentElement_ = element;
+ currentText_ = "";
+ }
}
void XMLSettingsProvider::handleEndElement(const std::string& /*element*/, const std::string& /*ns*/) {
- if (level_ == SettingLevel) {
- values_[currentElement_] = currentText_;
- SWIFT_LOG(debug) << "Setting value of " << currentElement_ << " to " << currentText_ << std::endl;
- }
- level_--;
+ if (level_ == SettingLevel) {
+ values_[currentElement_] = currentText_;
+ SWIFT_LOG(debug) << "Setting value of " << currentElement_ << " to " << currentText_ << std::endl;
+ }
+ level_--;
}
void XMLSettingsProvider::handleCharacterData(const std::string& data) {
- if (level_ >= SettingLevel) {
- currentText_ += data;
- }
+ if (level_ >= SettingLevel) {
+ currentText_ += data;
+ }
}
diff --git a/Swift/Controllers/Settings/XMLSettingsProvider.h b/Swift/Controllers/Settings/XMLSettingsProvider.h
index 2dbb23c..5fd82cf 100644
--- a/Swift/Controllers/Settings/XMLSettingsProvider.h
+++ b/Swift/Controllers/Settings/XMLSettingsProvider.h
@@ -16,40 +16,40 @@
namespace Swift {
class XMLSettingsProvider : public SettingsProvider, public XMLParserClient {
- public:
- XMLSettingsProvider(const std::string& xmlConfig);
- virtual ~XMLSettingsProvider();
- virtual std::string getSetting(const Setting<std::string>& setting);
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
- virtual bool getSetting(const Setting<bool>& setting);
- virtual void storeSetting(const Setting<bool>& setting, const bool& value);
- virtual int getSetting(const Setting<int>& setting);
- virtual void storeSetting(const Setting<int>& setting, const int& value);
- virtual std::vector<std::string> getAvailableProfiles();
- virtual void createProfile(const std::string& profile);
- virtual void removeProfile(const std::string& profile);
- virtual bool hasSetting(const std::string& key);
-
-
- virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes);
- virtual void handleEndElement(const std::string& element, const std::string& ns);
- virtual void handleCharacterData(const std::string& data);
-
- protected:
- virtual bool getIsSettingFinal(const std::string& settingPath);
- private:
- std::map<std::string /*settingPath*/, std::string /*settingValue*/> values_;
- /* Settings that are final*/
- std::set<std::string /*settingPath*/> finals_;
-
- enum Level {
- TopLevel = 0,
- SettingLevel = 2
- };
-
- int level_;
- std::string currentElement_;
- std::string currentText_;
+ public:
+ XMLSettingsProvider(const std::string& xmlConfig);
+ virtual ~XMLSettingsProvider();
+ virtual std::string getSetting(const Setting<std::string>& setting);
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
+ virtual bool getSetting(const Setting<bool>& setting);
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value);
+ virtual int getSetting(const Setting<int>& setting);
+ virtual void storeSetting(const Setting<int>& setting, const int& value);
+ virtual std::vector<std::string> getAvailableProfiles();
+ virtual void createProfile(const std::string& profile);
+ virtual void removeProfile(const std::string& profile);
+ virtual bool hasSetting(const std::string& key);
+
+
+ virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes);
+ virtual void handleEndElement(const std::string& element, const std::string& ns);
+ virtual void handleCharacterData(const std::string& data);
+
+ protected:
+ virtual bool getIsSettingFinal(const std::string& settingPath);
+ private:
+ std::map<std::string /*settingPath*/, std::string /*settingValue*/> values_;
+ /* Settings that are final*/
+ std::set<std::string /*settingPath*/> finals_;
+
+ enum Level {
+ TopLevel = 0,
+ SettingLevel = 2
+ };
+
+ int level_;
+ std::string currentElement_;
+ std::string currentText_;
};
}
diff --git a/Swift/Controllers/ShowProfileController.cpp b/Swift/Controllers/ShowProfileController.cpp
index 9e94392..bf5eb1e 100644
--- a/Swift/Controllers/ShowProfileController.cpp
+++ b/Swift/Controllers/ShowProfileController.cpp
@@ -25,57 +25,57 @@
namespace Swift {
ShowProfileController::ShowProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream) : vcardManager(vcardManager), profileWindowFactory(profileWindowFactory), uiEventStream(uiEventStream) {
- uiEventStream->onUIEvent.connect(boost::bind(&ShowProfileController::handleUIEvent, this, _1));
- vcardManager->onVCardChanged.connect(boost::bind(&ShowProfileController::handleVCardChanged, this, _1, _2));
+ uiEventStream->onUIEvent.connect(boost::bind(&ShowProfileController::handleUIEvent, this, _1));
+ vcardManager->onVCardChanged.connect(boost::bind(&ShowProfileController::handleVCardChanged, this, _1, _2));
}
ShowProfileController::~ShowProfileController() {
- typedef std::pair<JID, ProfileWindow*> JIDProfileWindowPair;
- foreach(const JIDProfileWindowPair& jidWndPair, openedProfileWindows) {
- jidWndPair.second->onWindowAboutToBeClosed.disconnect(boost::bind(&ShowProfileController::handleProfileWindowAboutToBeClosed, this, _1));
- delete jidWndPair.second;
- }
+ typedef std::pair<JID, ProfileWindow*> JIDProfileWindowPair;
+ foreach(const JIDProfileWindowPair& jidWndPair, openedProfileWindows) {
+ jidWndPair.second->onWindowAboutToBeClosed.disconnect(boost::bind(&ShowProfileController::handleProfileWindowAboutToBeClosed, this, _1));
+ delete jidWndPair.second;
+ }
- vcardManager->onVCardChanged.disconnect(boost::bind(&ShowProfileController::handleVCardChanged, this, _1, _2));
- uiEventStream->onUIEvent.disconnect(boost::bind(&ShowProfileController::handleUIEvent, this, _1));
+ vcardManager->onVCardChanged.disconnect(boost::bind(&ShowProfileController::handleVCardChanged, this, _1, _2));
+ uiEventStream->onUIEvent.disconnect(boost::bind(&ShowProfileController::handleUIEvent, this, _1));
}
void ShowProfileController::handleUIEvent(UIEvent::ref event) {
- ShowProfileForRosterItemUIEvent::ref showProfileEvent = boost::dynamic_pointer_cast<ShowProfileForRosterItemUIEvent>(event);
- if (!showProfileEvent) {
- return;
- }
+ ShowProfileForRosterItemUIEvent::ref showProfileEvent = boost::dynamic_pointer_cast<ShowProfileForRosterItemUIEvent>(event);
+ if (!showProfileEvent) {
+ return;
+ }
- if (openedProfileWindows.find(showProfileEvent->getJID()) == openedProfileWindows.end()) {
- ProfileWindow* newProfileWindow = profileWindowFactory->createProfileWindow();
- newProfileWindow->setJID(showProfileEvent->getJID());
- newProfileWindow->onWindowAboutToBeClosed.connect(boost::bind(&ShowProfileController::handleProfileWindowAboutToBeClosed, this, _1));
- openedProfileWindows[showProfileEvent->getJID()] = newProfileWindow;
- VCard::ref vcard = vcardManager->getVCardAndRequestWhenNeeded(showProfileEvent->getJID(), boost::posix_time::minutes(5));
- if (vcard) {
- newProfileWindow->setVCard(vcard);
- } else {
- newProfileWindow->setProcessing(true);
- }
- newProfileWindow->show();
- } else {
- openedProfileWindows[showProfileEvent->getJID()]->show();
- }
+ if (openedProfileWindows.find(showProfileEvent->getJID()) == openedProfileWindows.end()) {
+ ProfileWindow* newProfileWindow = profileWindowFactory->createProfileWindow();
+ newProfileWindow->setJID(showProfileEvent->getJID());
+ newProfileWindow->onWindowAboutToBeClosed.connect(boost::bind(&ShowProfileController::handleProfileWindowAboutToBeClosed, this, _1));
+ openedProfileWindows[showProfileEvent->getJID()] = newProfileWindow;
+ VCard::ref vcard = vcardManager->getVCardAndRequestWhenNeeded(showProfileEvent->getJID(), boost::posix_time::minutes(5));
+ if (vcard) {
+ newProfileWindow->setVCard(vcard);
+ } else {
+ newProfileWindow->setProcessing(true);
+ }
+ newProfileWindow->show();
+ } else {
+ openedProfileWindows[showProfileEvent->getJID()]->show();
+ }
}
void ShowProfileController::handleVCardChanged(const JID& jid, VCard::ref vcard) {
- if (openedProfileWindows.find(jid) == openedProfileWindows.end()) {
- return;
- }
+ if (openedProfileWindows.find(jid) == openedProfileWindows.end()) {
+ return;
+ }
- ProfileWindow* profileWindow = openedProfileWindows[jid];
- profileWindow->setVCard(vcard);
- profileWindow->setProcessing(false);
- profileWindow->show();
+ ProfileWindow* profileWindow = openedProfileWindows[jid];
+ profileWindow->setVCard(vcard);
+ profileWindow->setProcessing(false);
+ profileWindow->show();
}
void ShowProfileController::handleProfileWindowAboutToBeClosed(const JID& profileJid) {
- openedProfileWindows.erase(profileJid);
+ openedProfileWindows.erase(profileJid);
}
}
diff --git a/Swift/Controllers/ShowProfileController.h b/Swift/Controllers/ShowProfileController.h
index 37fb615..4f23c19 100644
--- a/Swift/Controllers/ShowProfileController.h
+++ b/Swift/Controllers/ShowProfileController.h
@@ -18,25 +18,25 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class VCardManager;
- class ProfileWindow;
- class ProfileWindowFactory;
- class UIEventStream;
-
- class ShowProfileController {
- public:
- ShowProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream);
- ~ShowProfileController();
-
- private:
- void handleUIEvent(UIEvent::ref event);
- void handleVCardChanged(const JID&, VCard::ref);
- void handleProfileWindowAboutToBeClosed(const JID& profileJid);
-
- private:
- VCardManager* vcardManager;
- ProfileWindowFactory* profileWindowFactory;
- UIEventStream* uiEventStream;
- std::map<JID, ProfileWindow*> openedProfileWindows;
- };
+ class VCardManager;
+ class ProfileWindow;
+ class ProfileWindowFactory;
+ class UIEventStream;
+
+ class ShowProfileController {
+ public:
+ ShowProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream);
+ ~ShowProfileController();
+
+ private:
+ void handleUIEvent(UIEvent::ref event);
+ void handleVCardChanged(const JID&, VCard::ref);
+ void handleProfileWindowAboutToBeClosed(const JID& profileJid);
+
+ private:
+ VCardManager* vcardManager;
+ ProfileWindowFactory* profileWindowFactory;
+ UIEventStream* uiEventStream;
+ std::map<JID, ProfileWindow*> openedProfileWindows;
+ };
}
diff --git a/Swift/Controllers/SoundEventController.cpp b/Swift/Controllers/SoundEventController.cpp
index 43c8ed0..433937b 100644
--- a/Swift/Controllers/SoundEventController.cpp
+++ b/Swift/Controllers/SoundEventController.cpp
@@ -18,39 +18,39 @@
namespace Swift {
SoundEventController::SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, SettingsProvider* settings, HighlightManager* highlightManager) {
- settings_ = settings;
- eventController_ = eventController;
- soundPlayer_ = soundPlayer;
- eventController_->onEventQueueEventAdded.connect(boost::bind(&SoundEventController::handleEventQueueEventAdded, this, _1));
- highlightManager_ = highlightManager;
- highlightManager_->onHighlight.connect(boost::bind(&SoundEventController::handleHighlight, this, _1));
+ settings_ = settings;
+ eventController_ = eventController;
+ soundPlayer_ = soundPlayer;
+ eventController_->onEventQueueEventAdded.connect(boost::bind(&SoundEventController::handleEventQueueEventAdded, this, _1));
+ highlightManager_ = highlightManager;
+ highlightManager_->onHighlight.connect(boost::bind(&SoundEventController::handleHighlight, this, _1));
- settings_->onSettingChanged.connect(boost::bind(&SoundEventController::handleSettingChanged, this, _1));
+ settings_->onSettingChanged.connect(boost::bind(&SoundEventController::handleSettingChanged, this, _1));
- playSounds_ = settings->getSetting(SettingConstants::PLAY_SOUNDS);
+ playSounds_ = settings->getSetting(SettingConstants::PLAY_SOUNDS);
}
void SoundEventController::handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent> event) {
- if (playSounds_ && boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event)) {
- soundPlayer_->playSound(SoundPlayer::MessageReceived, "");
- }
+ if (playSounds_ && boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event)) {
+ soundPlayer_->playSound(SoundPlayer::MessageReceived, "");
+ }
}
void SoundEventController::handleHighlight(const HighlightAction& action) {
- if (playSounds_ && action.playSound()) {
- soundPlayer_->playSound(SoundPlayer::MessageReceived, action.getSoundFile());
- }
+ if (playSounds_ && action.playSound()) {
+ soundPlayer_->playSound(SoundPlayer::MessageReceived, action.getSoundFile());
+ }
}
void SoundEventController::setPlaySounds(bool playSounds) {
- playSounds_ = playSounds;
- settings_->storeSetting(SettingConstants::PLAY_SOUNDS, playSounds);
+ playSounds_ = playSounds;
+ settings_->storeSetting(SettingConstants::PLAY_SOUNDS, playSounds);
}
void SoundEventController::handleSettingChanged(const std::string& settingPath) {
- if (SettingConstants::PLAY_SOUNDS.getKey() == settingPath) {
- playSounds_ = settings_->getSetting(SettingConstants::PLAY_SOUNDS);
- }
+ if (SettingConstants::PLAY_SOUNDS.getKey() == settingPath) {
+ playSounds_ = settings_->getSetting(SettingConstants::PLAY_SOUNDS);
+ }
}
}
diff --git a/Swift/Controllers/SoundEventController.h b/Swift/Controllers/SoundEventController.h
index 88c7b00..3ea682a 100644
--- a/Swift/Controllers/SoundEventController.h
+++ b/Swift/Controllers/SoundEventController.h
@@ -13,22 +13,22 @@
#include <Swift/Controllers/XMPPEvents/StanzaEvent.h>
namespace Swift {
- class EventController;
- class SoundPlayer;
- class HighlightManager;
- class SoundEventController {
- public:
- SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, SettingsProvider* settings, HighlightManager* highlightManager);
- void setPlaySounds(bool playSounds);
- bool getSoundEnabled() {return playSounds_;}
- private:
- void handleSettingChanged(const std::string& settingPath);
- void handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent> event);
- void handleHighlight(const HighlightAction& action);
- EventController* eventController_;
- SoundPlayer* soundPlayer_;
- bool playSounds_;
- SettingsProvider* settings_;
- HighlightManager* highlightManager_;
- };
+ class EventController;
+ class SoundPlayer;
+ class HighlightManager;
+ class SoundEventController {
+ public:
+ SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, SettingsProvider* settings, HighlightManager* highlightManager);
+ void setPlaySounds(bool playSounds);
+ bool getSoundEnabled() {return playSounds_;}
+ private:
+ void handleSettingChanged(const std::string& settingPath);
+ void handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent> event);
+ void handleHighlight(const HighlightAction& action);
+ EventController* eventController_;
+ SoundPlayer* soundPlayer_;
+ bool playSounds_;
+ SettingsProvider* settings_;
+ HighlightManager* highlightManager_;
+ };
}
diff --git a/Swift/Controllers/SoundPlayer.h b/Swift/Controllers/SoundPlayer.h
index e38cd7c..8525c6c 100644
--- a/Swift/Controllers/SoundPlayer.h
+++ b/Swift/Controllers/SoundPlayer.h
@@ -9,10 +9,10 @@
#include <string>
namespace Swift {
- class SoundPlayer {
- public:
- virtual ~SoundPlayer() {}
- enum SoundEffect{MessageReceived};
- virtual void playSound(SoundEffect sound, const std::string& soundResource) = 0;
- };
+ class SoundPlayer {
+ public:
+ virtual ~SoundPlayer() {}
+ enum SoundEffect{MessageReceived};
+ virtual void playSound(SoundEffect sound, const std::string& soundResource) = 0;
+ };
}
diff --git a/Swift/Controllers/StatusCache.cpp b/Swift/Controllers/StatusCache.cpp
index d00d7f6..ce4391d 100644
--- a/Swift/Controllers/StatusCache.cpp
+++ b/Swift/Controllers/StatusCache.cpp
@@ -24,9 +24,9 @@ namespace Swift {
static const size_t MAX_ENTRIES = 200;
StatusCache::StatusCache(ApplicationPathProvider* paths) {
- paths_ = paths;
- path_ = paths_->getDataDir() / "StatusCache";
- loadRecents();
+ paths_ = paths;
+ path_ = paths_->getDataDir() / "StatusCache";
+ loadRecents();
}
StatusCache::~StatusCache() {
@@ -34,71 +34,71 @@ StatusCache::~StatusCache() {
}
std::vector<StatusCache::PreviousStatus> StatusCache::getMatches(const std::string& substring, size_t maxCount) const {
- std::vector<PreviousStatus> matches;
- foreach (const PreviousStatus& status, previousStatuses_) {
- if (substring.empty() || (boost::algorithm::ifind_first(status.first, substring) && substring != status.first)) {
- matches.push_back(status);
- if (matches.size() == maxCount) {
- break;
- }
- }
- }
- return matches;
+ std::vector<PreviousStatus> matches;
+ foreach (const PreviousStatus& status, previousStatuses_) {
+ if (substring.empty() || (boost::algorithm::ifind_first(status.first, substring) && substring != status.first)) {
+ matches.push_back(status);
+ if (matches.size() == maxCount) {
+ break;
+ }
+ }
+ }
+ return matches;
}
void StatusCache::addRecent(const std::string& text, StatusShow::Type type) {
- if (text.empty()) {
- return;
- }
- previousStatuses_.remove_if(lambda::bind(&PreviousStatus::first, lambda::_1) == text && lambda::bind(&PreviousStatus::second, lambda::_1) == type);
- previousStatuses_.push_front(PreviousStatus(text, type));
- for (size_t i = previousStatuses_.size(); i > MAX_ENTRIES; i--) {
- previousStatuses_.pop_back();
- }
- saveRecents();
+ if (text.empty()) {
+ return;
+ }
+ previousStatuses_.remove_if(lambda::bind(&PreviousStatus::first, lambda::_1) == text && lambda::bind(&PreviousStatus::second, lambda::_1) == type);
+ previousStatuses_.push_front(PreviousStatus(text, type));
+ for (size_t i = previousStatuses_.size(); i > MAX_ENTRIES; i--) {
+ previousStatuses_.pop_back();
+ }
+ saveRecents();
}
void StatusCache::loadRecents() {
- try {
- if (boost::filesystem::exists(path_)) {
- ByteArray data;
- readByteArrayFromFile(data, path_);
- std::string stringData = byteArrayToString(data);
- std::vector<std::string> lines;
- boost::split(lines, stringData, boost::is_any_of("\n"));
- foreach (const std::string& line, lines) {
- std::vector<std::string> bits;
- boost::split(bits, line, boost::is_any_of("\t"));
- if (bits.size() < 2) {
- continue;
- }
- StatusShow::Type type;
- type = static_cast<StatusShow::Type>(boost::lexical_cast<size_t>(bits[0]));
- previousStatuses_.push_back(PreviousStatus(boost::trim_copy(bits[1]), type));
- }
- }
- }
- catch (const boost::filesystem::filesystem_error& e) {
- std::cerr << "ERROR: " << e.what() << std::endl;
- }
+ try {
+ if (boost::filesystem::exists(path_)) {
+ ByteArray data;
+ readByteArrayFromFile(data, path_);
+ std::string stringData = byteArrayToString(data);
+ std::vector<std::string> lines;
+ boost::split(lines, stringData, boost::is_any_of("\n"));
+ foreach (const std::string& line, lines) {
+ std::vector<std::string> bits;
+ boost::split(bits, line, boost::is_any_of("\t"));
+ if (bits.size() < 2) {
+ continue;
+ }
+ StatusShow::Type type;
+ type = static_cast<StatusShow::Type>(boost::lexical_cast<size_t>(bits[0]));
+ previousStatuses_.push_back(PreviousStatus(boost::trim_copy(bits[1]), type));
+ }
+ }
+ }
+ catch (const boost::filesystem::filesystem_error& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ }
}
void StatusCache::saveRecents() {
- try {
- if (!boost::filesystem::exists(path_.parent_path())) {
- boost::filesystem::create_directories(path_.parent_path());
- }
- boost::filesystem::ofstream file(path_);
- foreach (const PreviousStatus& recent, previousStatuses_) {
- std::string message = recent.first;
- boost::replace_all(message, "\t", " ");
- file << recent.second << "\t" << message << std::endl;
- }
- file.close();
- }
- catch (const boost::filesystem::filesystem_error& e) {
- std::cerr << "ERROR: " << e.what() << std::endl;
- }
+ try {
+ if (!boost::filesystem::exists(path_.parent_path())) {
+ boost::filesystem::create_directories(path_.parent_path());
+ }
+ boost::filesystem::ofstream file(path_);
+ foreach (const PreviousStatus& recent, previousStatuses_) {
+ std::string message = recent.first;
+ boost::replace_all(message, "\t", " ");
+ file << recent.second << "\t" << message << std::endl;
+ }
+ file.close();
+ }
+ catch (const boost::filesystem::filesystem_error& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ }
}
}
diff --git a/Swift/Controllers/StatusCache.h b/Swift/Controllers/StatusCache.h
index 0ed85d6..033cde0 100644
--- a/Swift/Controllers/StatusCache.h
+++ b/Swift/Controllers/StatusCache.h
@@ -17,24 +17,24 @@
#include <Swiften/Elements/StatusShow.h>
namespace Swift {
- class ApplicationPathProvider;
- class StatusCache {
- public:
- typedef std::pair<std::string, StatusShow::Type> PreviousStatus;
- public:
- StatusCache(ApplicationPathProvider* paths);
- ~StatusCache();
-
- std::vector<PreviousStatus> getMatches(const std::string& substring, size_t maxCount) const;
- void addRecent(const std::string& text, StatusShow::Type type);
- private:
- void saveRecents();
- void loadRecents();
- private:
- boost::filesystem::path path_;
- std::list<PreviousStatus> previousStatuses_;
- ApplicationPathProvider* paths_;
- };
+ class ApplicationPathProvider;
+ class StatusCache {
+ public:
+ typedef std::pair<std::string, StatusShow::Type> PreviousStatus;
+ public:
+ StatusCache(ApplicationPathProvider* paths);
+ ~StatusCache();
+
+ std::vector<PreviousStatus> getMatches(const std::string& substring, size_t maxCount) const;
+ void addRecent(const std::string& text, StatusShow::Type type);
+ private:
+ void saveRecents();
+ void loadRecents();
+ private:
+ boost::filesystem::path path_;
+ std::list<PreviousStatus> previousStatuses_;
+ ApplicationPathProvider* paths_;
+ };
}
diff --git a/Swift/Controllers/StatusTracker.cpp b/Swift/Controllers/StatusTracker.cpp
index e42b99e..51db328 100644
--- a/Swift/Controllers/StatusTracker.cpp
+++ b/Swift/Controllers/StatusTracker.cpp
@@ -13,46 +13,46 @@
namespace Swift {
StatusTracker::StatusTracker() {
- isAutoAway_ = false;
- queuedPresence_ = boost::make_shared<Presence>();
+ isAutoAway_ = false;
+ queuedPresence_ = boost::make_shared<Presence>();
}
boost::shared_ptr<Presence> StatusTracker::getNextPresence() {
- boost::shared_ptr<Presence> presence;
- if (isAutoAway_) {
- presence = boost::make_shared<Presence>();
- presence->setShow(StatusShow::Away);
- presence->setStatus(queuedPresence_->getStatus());
- presence->addPayload(boost::make_shared<Idle>(isAutoAwaySince_));
- } else {
- presence = queuedPresence_;
- }
- return presence;
+ boost::shared_ptr<Presence> presence;
+ if (isAutoAway_) {
+ presence = boost::make_shared<Presence>();
+ presence->setShow(StatusShow::Away);
+ presence->setStatus(queuedPresence_->getStatus());
+ presence->addPayload(boost::make_shared<Idle>(isAutoAwaySince_));
+ } else {
+ presence = queuedPresence_;
+ }
+ return presence;
}
void StatusTracker::setRequestedPresence(boost::shared_ptr<Presence> presence) {
- isAutoAway_ = false;
- queuedPresence_ = presence;
-// if (presence->getType() == Presence::Unavailable) {
-// queuedPresence_ = boost::make_shared<Presence>();
-// }
+ isAutoAway_ = false;
+ queuedPresence_ = presence;
+// if (presence->getType() == Presence::Unavailable) {
+// queuedPresence_ = boost::make_shared<Presence>();
+// }
}
bool StatusTracker::goAutoAway(const int& seconds) {
- if (queuedPresence_->getShow() != StatusShow::Online) {
- return false;
- }
- isAutoAway_ = true;
- isAutoAwaySince_ = boost::posix_time::second_clock::universal_time() - boost::posix_time::seconds(seconds);
- return true;
+ if (queuedPresence_->getShow() != StatusShow::Online) {
+ return false;
+ }
+ isAutoAway_ = true;
+ isAutoAwaySince_ = boost::posix_time::second_clock::universal_time() - boost::posix_time::seconds(seconds);
+ return true;
}
bool StatusTracker::goAutoUnAway() {
- if (!isAutoAway_) {
- return false;
- }
- isAutoAway_ = false;
- return true;
+ if (!isAutoAway_) {
+ return false;
+ }
+ isAutoAway_ = false;
+ return true;
}
}
diff --git a/Swift/Controllers/StatusTracker.h b/Swift/Controllers/StatusTracker.h
index 092ce43..cf92781 100644
--- a/Swift/Controllers/StatusTracker.h
+++ b/Swift/Controllers/StatusTracker.h
@@ -13,16 +13,16 @@
namespace Swift {
- class StatusTracker {
- public:
- StatusTracker();
- boost::shared_ptr<Presence> getNextPresence();
- void setRequestedPresence(boost::shared_ptr<Presence> presence);
- bool goAutoAway(const int& seconds);
- bool goAutoUnAway();
- private:
- boost::shared_ptr<Presence> queuedPresence_;
- bool isAutoAway_;
- boost::posix_time::ptime isAutoAwaySince_;
- };
+ class StatusTracker {
+ public:
+ StatusTracker();
+ boost::shared_ptr<Presence> getNextPresence();
+ void setRequestedPresence(boost::shared_ptr<Presence> presence);
+ bool goAutoAway(const int& seconds);
+ bool goAutoUnAway();
+ private:
+ boost::shared_ptr<Presence> queuedPresence_;
+ bool isAutoAway_;
+ boost::posix_time::ptime isAutoAwaySince_;
+ };
}
diff --git a/Swift/Controllers/StatusUtil.cpp b/Swift/Controllers/StatusUtil.cpp
index 0c5bc21..1034863 100644
--- a/Swift/Controllers/StatusUtil.cpp
+++ b/Swift/Controllers/StatusUtil.cpp
@@ -13,16 +13,16 @@
namespace Swift {
std::string statusShowTypeToFriendlyName(StatusShow::Type type) {
- switch (type) {
- case StatusShow::Online: return QT_TRANSLATE_NOOP("", "Available");
- case StatusShow::FFC: return QT_TRANSLATE_NOOP("", "Available");
- case StatusShow::Away: return QT_TRANSLATE_NOOP("", "Away");
- case StatusShow::XA: return QT_TRANSLATE_NOOP("", "Away");
- case StatusShow::DND: return QT_TRANSLATE_NOOP("", "Busy");
- case StatusShow::None: return QT_TRANSLATE_NOOP("", "Offline");
- }
- assert(false);
- return "";
+ switch (type) {
+ case StatusShow::Online: return QT_TRANSLATE_NOOP("", "Available");
+ case StatusShow::FFC: return QT_TRANSLATE_NOOP("", "Available");
+ case StatusShow::Away: return QT_TRANSLATE_NOOP("", "Away");
+ case StatusShow::XA: return QT_TRANSLATE_NOOP("", "Away");
+ case StatusShow::DND: return QT_TRANSLATE_NOOP("", "Busy");
+ case StatusShow::None: return QT_TRANSLATE_NOOP("", "Offline");
+ }
+ assert(false);
+ return "";
}
}
diff --git a/Swift/Controllers/StatusUtil.h b/Swift/Controllers/StatusUtil.h
index 871ca0a..6872bf7 100644
--- a/Swift/Controllers/StatusUtil.h
+++ b/Swift/Controllers/StatusUtil.h
@@ -11,6 +11,6 @@
#include <Swiften/Elements/StatusShow.h>
namespace Swift {
- std::string statusShowTypeToFriendlyName(StatusShow::Type type);
+ std::string statusShowTypeToFriendlyName(StatusShow::Type type);
}
diff --git a/Swift/Controllers/Storages/AvatarFileStorage.cpp b/Swift/Controllers/Storages/AvatarFileStorage.cpp
index 56e27e1..cded945 100644
--- a/Swift/Controllers/Storages/AvatarFileStorage.cpp
+++ b/Swift/Controllers/Storages/AvatarFileStorage.cpp
@@ -19,88 +19,88 @@
namespace Swift {
AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto) : avatarsDir(avatarsDir), avatarsFile(avatarsFile), crypto(crypto) {
- if (boost::filesystem::exists(avatarsFile)) {
- try {
- boost::filesystem::ifstream file(avatarsFile);
- std::string line;
- if (file.is_open()) {
- while (!file.eof()) {
- getline(file, line);
- std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' ');
- JID jid(r.second);
- if (jid.isValid()) {
- jidAvatars.insert(std::make_pair(jid, r.first));
- }
- else if (!r.first.empty() || !r.second.empty()) {
- std::cerr << "Invalid entry in avatars file: " << r.second << std::endl;
- }
- }
- }
- }
- catch (...) {
- std::cerr << "Error reading avatars file" << std::endl;
- }
- }
+ if (boost::filesystem::exists(avatarsFile)) {
+ try {
+ boost::filesystem::ifstream file(avatarsFile);
+ std::string line;
+ if (file.is_open()) {
+ while (!file.eof()) {
+ getline(file, line);
+ std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' ');
+ JID jid(r.second);
+ if (jid.isValid()) {
+ jidAvatars.insert(std::make_pair(jid, r.first));
+ }
+ else if (!r.first.empty() || !r.second.empty()) {
+ std::cerr << "Invalid entry in avatars file: " << r.second << std::endl;
+ }
+ }
+ }
+ }
+ catch (...) {
+ std::cerr << "Error reading avatars file" << std::endl;
+ }
+ }
}
-bool AvatarFileStorage::hasAvatar(const std::string& hash) const {
- return boost::filesystem::exists(getAvatarPath(hash));
+bool AvatarFileStorage::hasAvatar(const std::string& hash) const {
+ return boost::filesystem::exists(getAvatarPath(hash));
}
void AvatarFileStorage::addAvatar(const std::string& hash, const ByteArray& avatar) {
- assert(Hexify::hexify(crypto->getSHA1Hash(avatar)) == hash);
+ assert(Hexify::hexify(crypto->getSHA1Hash(avatar)) == hash);
- boost::filesystem::path avatarPath = getAvatarPath(hash);
- if (!boost::filesystem::exists(avatarPath.parent_path())) {
- try {
- boost::filesystem::create_directories(avatarPath.parent_path());
- }
- catch (const boost::filesystem::filesystem_error& e) {
- std::cerr << "ERROR: " << e.what() << std::endl;
- }
- }
- boost::filesystem::ofstream file(avatarPath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out);
- file.write(reinterpret_cast<const char*>(vecptr(avatar)), static_cast<std::streamsize>(avatar.size()));
- file.close();
+ boost::filesystem::path avatarPath = getAvatarPath(hash);
+ if (!boost::filesystem::exists(avatarPath.parent_path())) {
+ try {
+ boost::filesystem::create_directories(avatarPath.parent_path());
+ }
+ catch (const boost::filesystem::filesystem_error& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ }
+ }
+ boost::filesystem::ofstream file(avatarPath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out);
+ file.write(reinterpret_cast<const char*>(vecptr(avatar)), static_cast<std::streamsize>(avatar.size()));
+ file.close();
}
boost::filesystem::path AvatarFileStorage::getAvatarPath(const std::string& hash) const {
- return avatarsDir / hash;
+ return avatarsDir / hash;
}
ByteArray AvatarFileStorage::getAvatar(const std::string& hash) const {
- ByteArray data;
- readByteArrayFromFile(data, getAvatarPath(hash));
- return data;
+ ByteArray data;
+ readByteArrayFromFile(data, getAvatarPath(hash));
+ return data;
}
void AvatarFileStorage::setAvatarForJID(const JID& jid, const std::string& hash) {
- std::pair<JIDAvatarMap::iterator, bool> r = jidAvatars.insert(std::make_pair(jid, hash));
- if (r.second) {
- saveJIDAvatars();
- }
- else if (r.first->second != hash) {
- r.first->second = hash;
- saveJIDAvatars();
- }
+ std::pair<JIDAvatarMap::iterator, bool> r = jidAvatars.insert(std::make_pair(jid, hash));
+ if (r.second) {
+ saveJIDAvatars();
+ }
+ else if (r.first->second != hash) {
+ r.first->second = hash;
+ saveJIDAvatars();
+ }
}
std::string AvatarFileStorage::getAvatarForJID(const JID& jid) const {
- JIDAvatarMap::const_iterator i = jidAvatars.find(jid);
- return i == jidAvatars.end() ? "" : i->second;
+ JIDAvatarMap::const_iterator i = jidAvatars.find(jid);
+ return i == jidAvatars.end() ? "" : i->second;
}
void AvatarFileStorage::saveJIDAvatars() {
- try {
- boost::filesystem::ofstream file(avatarsFile);
- for (JIDAvatarMap::const_iterator i = jidAvatars.begin(); i != jidAvatars.end(); ++i) {
- file << i->second << " " << i->first.toString() << std::endl;
- }
- file.close();
- }
- catch (...) {
- std::cerr << "Error writing avatars file" << std::endl;
- }
+ try {
+ boost::filesystem::ofstream file(avatarsFile);
+ for (JIDAvatarMap::const_iterator i = jidAvatars.begin(); i != jidAvatars.end(); ++i) {
+ file << i->second << " " << i->first.toString() << std::endl;
+ }
+ file.close();
+ }
+ catch (...) {
+ std::cerr << "Error writing avatars file" << std::endl;
+ }
}
}
diff --git a/Swift/Controllers/Storages/AvatarFileStorage.h b/Swift/Controllers/Storages/AvatarFileStorage.h
index 9c6f617..41c7106 100644
--- a/Swift/Controllers/Storages/AvatarFileStorage.h
+++ b/Swift/Controllers/Storages/AvatarFileStorage.h
@@ -16,30 +16,30 @@
#include <Swiften/JID/JID.h>
namespace Swift {
- class CryptoProvider;
+ class CryptoProvider;
- class AvatarFileStorage : public AvatarStorage {
- public:
- AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto);
+ class AvatarFileStorage : public AvatarStorage {
+ public:
+ AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto);
- virtual bool hasAvatar(const std::string& hash) const;
- virtual void addAvatar(const std::string& hash, const ByteArray& avatar);
- virtual ByteArray getAvatar(const std::string& hash) const;
+ virtual bool hasAvatar(const std::string& hash) const;
+ virtual void addAvatar(const std::string& hash, const ByteArray& avatar);
+ virtual ByteArray getAvatar(const std::string& hash) const;
- virtual boost::filesystem::path getAvatarPath(const std::string& hash) const;
+ virtual boost::filesystem::path getAvatarPath(const std::string& hash) const;
- virtual void setAvatarForJID(const JID& jid, const std::string& hash);
- virtual std::string getAvatarForJID(const JID& jid) const;
+ virtual void setAvatarForJID(const JID& jid, const std::string& hash);
+ virtual std::string getAvatarForJID(const JID& jid) const;
- private:
- void saveJIDAvatars();
+ private:
+ void saveJIDAvatars();
- private:
- boost::filesystem::path avatarsDir;
- boost::filesystem::path avatarsFile;
- CryptoProvider* crypto;
- typedef std::map<JID, std::string> JIDAvatarMap;
- JIDAvatarMap jidAvatars;
- };
+ private:
+ boost::filesystem::path avatarsDir;
+ boost::filesystem::path avatarsFile;
+ CryptoProvider* crypto;
+ typedef std::map<JID, std::string> JIDAvatarMap;
+ JIDAvatarMap jidAvatars;
+ };
}
diff --git a/Swift/Controllers/Storages/CapsFileStorage.cpp b/Swift/Controllers/Storages/CapsFileStorage.cpp
index 7b99fe0..21a99bc 100644
--- a/Swift/Controllers/Storages/CapsFileStorage.cpp
+++ b/Swift/Controllers/Storages/CapsFileStorage.cpp
@@ -20,15 +20,15 @@ CapsFileStorage::CapsFileStorage(const boost::filesystem::path& path) : path(pat
}
DiscoInfo::ref CapsFileStorage::getDiscoInfo(const std::string& hash) const {
- return DiscoInfoPersister().loadPayloadGeneric(getCapsPath(hash));
+ return DiscoInfoPersister().loadPayloadGeneric(getCapsPath(hash));
}
void CapsFileStorage::setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo) {
- DiscoInfo::ref bareDiscoInfo(new DiscoInfo(*discoInfo.get()));
- bareDiscoInfo->setNode("");
- DiscoInfoPersister().savePayload(bareDiscoInfo, getCapsPath(hash));
+ DiscoInfo::ref bareDiscoInfo(new DiscoInfo(*discoInfo.get()));
+ bareDiscoInfo->setNode("");
+ DiscoInfoPersister().savePayload(bareDiscoInfo, getCapsPath(hash));
}
boost::filesystem::path CapsFileStorage::getCapsPath(const std::string& hash) const {
- return path / (Hexify::hexify(Base64::decode(hash)) + ".xml");
+ return path / (Hexify::hexify(Base64::decode(hash)) + ".xml");
}
diff --git a/Swift/Controllers/Storages/CapsFileStorage.h b/Swift/Controllers/Storages/CapsFileStorage.h
index 06dfd91..7df23f1 100644
--- a/Swift/Controllers/Storages/CapsFileStorage.h
+++ b/Swift/Controllers/Storages/CapsFileStorage.h
@@ -13,17 +13,17 @@
#include <Swiften/Disco/CapsStorage.h>
namespace Swift {
- class CapsFileStorage : public CapsStorage {
- public:
- CapsFileStorage(const boost::filesystem::path& path);
+ class CapsFileStorage : public CapsStorage {
+ public:
+ CapsFileStorage(const boost::filesystem::path& path);
- virtual DiscoInfo::ref getDiscoInfo(const std::string& hash) const;
- virtual void setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo);
+ virtual DiscoInfo::ref getDiscoInfo(const std::string& hash) const;
+ virtual void setDiscoInfo(const std::string& hash, DiscoInfo::ref discoInfo);
- private:
- boost::filesystem::path getCapsPath(const std::string& hash) const;
+ private:
+ boost::filesystem::path getCapsPath(const std::string& hash) const;
- private:
- boost::filesystem::path path;
- };
+ private:
+ boost::filesystem::path path;
+ };
}
diff --git a/Swift/Controllers/Storages/CertificateFileStorage.cpp b/Swift/Controllers/Storages/CertificateFileStorage.cpp
index a549165..3fe6d54 100644
--- a/Swift/Controllers/Storages/CertificateFileStorage.cpp
+++ b/Swift/Controllers/Storages/CertificateFileStorage.cpp
@@ -22,42 +22,42 @@ CertificateFileStorage::CertificateFileStorage(const boost::filesystem::path& pa
}
bool CertificateFileStorage::hasCertificate(Certificate::ref certificate) const {
- boost::filesystem::path certificatePath = getCertificatePath(certificate);
- if (boost::filesystem::exists(certificatePath)) {
- ByteArray data;
- readByteArrayFromFile(data, certificatePath);
- Certificate::ref storedCertificate(certificateFactory->createCertificateFromDER(data));
- if (storedCertificate && storedCertificate->toDER() == certificate->toDER()) {
- return true;
- }
- else {
- SWIFT_LOG(warning) << "Stored certificate does not match received certificate" << std::endl;
- return false;
- }
- }
- else {
- return false;
- }
+ boost::filesystem::path certificatePath = getCertificatePath(certificate);
+ if (boost::filesystem::exists(certificatePath)) {
+ ByteArray data;
+ readByteArrayFromFile(data, certificatePath);
+ Certificate::ref storedCertificate(certificateFactory->createCertificateFromDER(data));
+ if (storedCertificate && storedCertificate->toDER() == certificate->toDER()) {
+ return true;
+ }
+ else {
+ SWIFT_LOG(warning) << "Stored certificate does not match received certificate" << std::endl;
+ return false;
+ }
+ }
+ else {
+ return false;
+ }
}
void CertificateFileStorage::addCertificate(Certificate::ref certificate) {
- boost::filesystem::path certificatePath = getCertificatePath(certificate);
- if (!boost::filesystem::exists(certificatePath.parent_path())) {
- try {
- boost::filesystem::create_directories(certificatePath.parent_path());
- }
- catch (const boost::filesystem::filesystem_error& e) {
- std::cerr << "ERROR: " << e.what() << std::endl;
- }
- }
- boost::filesystem::ofstream file(certificatePath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out);
- ByteArray data = certificate->toDER();
- file.write(reinterpret_cast<const char*>(vecptr(data)), boost::numeric_cast<std::streamsize>(data.size()));
- file.close();
+ boost::filesystem::path certificatePath = getCertificatePath(certificate);
+ if (!boost::filesystem::exists(certificatePath.parent_path())) {
+ try {
+ boost::filesystem::create_directories(certificatePath.parent_path());
+ }
+ catch (const boost::filesystem::filesystem_error& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ }
+ }
+ boost::filesystem::ofstream file(certificatePath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out);
+ ByteArray data = certificate->toDER();
+ file.write(reinterpret_cast<const char*>(vecptr(data)), boost::numeric_cast<std::streamsize>(data.size()));
+ file.close();
}
boost::filesystem::path CertificateFileStorage::getCertificatePath(Certificate::ref certificate) const {
- return path / Hexify::hexify(crypto->getSHA1Hash(certificate->toDER()));
+ return path / Hexify::hexify(crypto->getSHA1Hash(certificate->toDER()));
}
}
diff --git a/Swift/Controllers/Storages/CertificateFileStorage.h b/Swift/Controllers/Storages/CertificateFileStorage.h
index f7d3cb3..d2c228d 100644
--- a/Swift/Controllers/Storages/CertificateFileStorage.h
+++ b/Swift/Controllers/Storages/CertificateFileStorage.h
@@ -11,23 +11,23 @@
#include <Swift/Controllers/Storages/CertificateStorage.h>
namespace Swift {
- class CertificateFactory;
- class CryptoProvider;
+ class CertificateFactory;
+ class CryptoProvider;
- class CertificateFileStorage : public CertificateStorage {
- public:
- CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory, CryptoProvider* crypto);
+ class CertificateFileStorage : public CertificateStorage {
+ public:
+ CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory, CryptoProvider* crypto);
- virtual bool hasCertificate(Certificate::ref certificate) const;
- virtual void addCertificate(Certificate::ref certificate);
+ virtual bool hasCertificate(Certificate::ref certificate) const;
+ virtual void addCertificate(Certificate::ref certificate);
- private:
- boost::filesystem::path getCertificatePath(Certificate::ref certificate) const;
+ private:
+ boost::filesystem::path getCertificatePath(Certificate::ref certificate) const;
- private:
- boost::filesystem::path path;
- CertificateFactory* certificateFactory;
- CryptoProvider* crypto;
- };
+ private:
+ boost::filesystem::path path;
+ CertificateFactory* certificateFactory;
+ CryptoProvider* crypto;
+ };
}
diff --git a/Swift/Controllers/Storages/CertificateFileStorageFactory.h b/Swift/Controllers/Storages/CertificateFileStorageFactory.h
index da8e66e..8ab99f4 100644
--- a/Swift/Controllers/Storages/CertificateFileStorageFactory.h
+++ b/Swift/Controllers/Storages/CertificateFileStorageFactory.h
@@ -10,21 +10,21 @@
#include <Swift/Controllers/Storages/CertificateStorageFactory.h>
namespace Swift {
- class CertificateFactory;
- class CryptoProvider;
+ class CertificateFactory;
+ class CryptoProvider;
- class CertificateFileStorageFactory : public CertificateStorageFactory {
- public:
- CertificateFileStorageFactory(const boost::filesystem::path& basePath, CertificateFactory* certificateFactory, CryptoProvider* crypto) : basePath(basePath), certificateFactory(certificateFactory), crypto(crypto) {}
+ class CertificateFileStorageFactory : public CertificateStorageFactory {
+ public:
+ CertificateFileStorageFactory(const boost::filesystem::path& basePath, CertificateFactory* certificateFactory, CryptoProvider* crypto) : basePath(basePath), certificateFactory(certificateFactory), crypto(crypto) {}
- virtual CertificateStorage* createCertificateStorage(const JID& profile) const {
- boost::filesystem::path profilePath = basePath / profile.toString();
- return new CertificateFileStorage(profilePath / "certificates", certificateFactory, crypto);
- }
+ virtual CertificateStorage* createCertificateStorage(const JID& profile) const {
+ boost::filesystem::path profilePath = basePath / profile.toString();
+ return new CertificateFileStorage(profilePath / "certificates", certificateFactory, crypto);
+ }
- private:
- boost::filesystem::path basePath;
- CertificateFactory* certificateFactory;
- CryptoProvider* crypto;
- };
+ private:
+ boost::filesystem::path basePath;
+ CertificateFactory* certificateFactory;
+ CryptoProvider* crypto;
+ };
}
diff --git a/Swift/Controllers/Storages/CertificateMemoryStorage.cpp b/Swift/Controllers/Storages/CertificateMemoryStorage.cpp
index cd3c8fa..08c6ee7 100644
--- a/Swift/Controllers/Storages/CertificateMemoryStorage.cpp
+++ b/Swift/Controllers/Storages/CertificateMemoryStorage.cpp
@@ -14,14 +14,14 @@ CertificateMemoryStorage::CertificateMemoryStorage() {
}
bool CertificateMemoryStorage::hasCertificate(Certificate::ref certificate) const {
- foreach(Certificate::ref storedCert, certificates) {
- if (storedCert->toDER() == certificate->toDER()) {
- return true;
- }
- }
- return false;
+ foreach(Certificate::ref storedCert, certificates) {
+ if (storedCert->toDER() == certificate->toDER()) {
+ return true;
+ }
+ }
+ return false;
}
void CertificateMemoryStorage::addCertificate(Certificate::ref certificate) {
- certificates.push_back(certificate);
+ certificates.push_back(certificate);
}
diff --git a/Swift/Controllers/Storages/CertificateMemoryStorage.h b/Swift/Controllers/Storages/CertificateMemoryStorage.h
index 8bf7986..4870385 100644
--- a/Swift/Controllers/Storages/CertificateMemoryStorage.h
+++ b/Swift/Controllers/Storages/CertificateMemoryStorage.h
@@ -11,15 +11,15 @@
#include <Swift/Controllers/Storages/CertificateStorage.h>
namespace Swift {
- class CertificateMemoryStorage : public CertificateStorage {
- public:
- CertificateMemoryStorage();
+ class CertificateMemoryStorage : public CertificateStorage {
+ public:
+ CertificateMemoryStorage();
- virtual bool hasCertificate(Certificate::ref certificate) const;
- virtual void addCertificate(Certificate::ref certificate);
+ virtual bool hasCertificate(Certificate::ref certificate) const;
+ virtual void addCertificate(Certificate::ref certificate);
- private:
- std::vector<Certificate::ref> certificates;
- };
+ private:
+ std::vector<Certificate::ref> certificates;
+ };
}
diff --git a/Swift/Controllers/Storages/CertificateStorage.h b/Swift/Controllers/Storages/CertificateStorage.h
index 470b420..87a566b 100644
--- a/Swift/Controllers/Storages/CertificateStorage.h
+++ b/Swift/Controllers/Storages/CertificateStorage.h
@@ -11,12 +11,12 @@
#include <Swiften/TLS/Certificate.h>
namespace Swift {
- class CertificateStorage {
- public:
- virtual ~CertificateStorage();
+ class CertificateStorage {
+ public:
+ virtual ~CertificateStorage();
- virtual bool hasCertificate(Certificate::ref certificate) const = 0;
- virtual void addCertificate(Certificate::ref certificate) = 0;
- };
+ virtual bool hasCertificate(Certificate::ref certificate) const = 0;
+ virtual void addCertificate(Certificate::ref certificate) = 0;
+ };
}
diff --git a/Swift/Controllers/Storages/CertificateStorageFactory.h b/Swift/Controllers/Storages/CertificateStorageFactory.h
index 44605df..25fa232 100644
--- a/Swift/Controllers/Storages/CertificateStorageFactory.h
+++ b/Swift/Controllers/Storages/CertificateStorageFactory.h
@@ -7,13 +7,13 @@
#pragma once
namespace Swift {
- class CertificateStorage;
- class JID;
+ class CertificateStorage;
+ class JID;
- class CertificateStorageFactory {
- public:
- virtual ~CertificateStorageFactory();
+ class CertificateStorageFactory {
+ public:
+ virtual ~CertificateStorageFactory();
- virtual CertificateStorage* createCertificateStorage(const JID& profile) const = 0;
- };
+ virtual CertificateStorage* createCertificateStorage(const JID& profile) const = 0;
+ };
}
diff --git a/Swift/Controllers/Storages/CertificateStorageTrustChecker.h b/Swift/Controllers/Storages/CertificateStorageTrustChecker.h
index 7f2f43e..3c708a3 100644
--- a/Swift/Controllers/Storages/CertificateStorageTrustChecker.h
+++ b/Swift/Controllers/Storages/CertificateStorageTrustChecker.h
@@ -11,25 +11,25 @@
#include <Swift/Controllers/Storages/CertificateStorage.h>
namespace Swift {
- /**
- * A certificate trust checker that trusts certificates in a certificate storage.
- */
- class CertificateStorageTrustChecker : public CertificateTrustChecker {
- public:
- CertificateStorageTrustChecker(CertificateStorage* storage) : storage(storage) {
- }
+ /**
+ * A certificate trust checker that trusts certificates in a certificate storage.
+ */
+ class CertificateStorageTrustChecker : public CertificateTrustChecker {
+ public:
+ CertificateStorageTrustChecker(CertificateStorage* storage) : storage(storage) {
+ }
- virtual bool isCertificateTrusted(const std::vector<Certificate::ref>& certificateChain) {
- lastCertificateChain = std::vector<Certificate::ref>(certificateChain.begin(), certificateChain.end());
- return certificateChain.empty() ? false : storage->hasCertificate(certificateChain[0]);
- }
+ virtual bool isCertificateTrusted(const std::vector<Certificate::ref>& certificateChain) {
+ lastCertificateChain = std::vector<Certificate::ref>(certificateChain.begin(), certificateChain.end());
+ return certificateChain.empty() ? false : storage->hasCertificate(certificateChain[0]);
+ }
- const std::vector<Certificate::ref>& getLastCertificateChain() const {
- return lastCertificateChain;
- }
+ const std::vector<Certificate::ref>& getLastCertificateChain() const {
+ return lastCertificateChain;
+ }
- private:
- CertificateStorage* storage;
- std::vector<Certificate::ref> lastCertificateChain;
- };
+ private:
+ CertificateStorage* storage;
+ std::vector<Certificate::ref> lastCertificateChain;
+ };
}
diff --git a/Swift/Controllers/Storages/FileStorages.cpp b/Swift/Controllers/Storages/FileStorages.cpp
index 7e564bf..7ba2b0f 100644
--- a/Swift/Controllers/Storages/FileStorages.cpp
+++ b/Swift/Controllers/Storages/FileStorages.cpp
@@ -17,47 +17,47 @@
namespace Swift {
FileStorages::FileStorages(const boost::filesystem::path& baseDir, const JID& jid, CryptoProvider* crypto) {
- boost::filesystem::path profile = stringToPath(jid.toBare());
- vcardStorage = new VCardFileStorage(baseDir / profile / "vcards", crypto);
- capsStorage = new CapsFileStorage(baseDir / "caps");
- avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars", crypto);
- rosterStorage = new RosterFileStorage(baseDir / profile / "roster.xml");
+ boost::filesystem::path profile = stringToPath(jid.toBare());
+ vcardStorage = new VCardFileStorage(baseDir / profile / "vcards", crypto);
+ capsStorage = new CapsFileStorage(baseDir / "caps");
+ avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars", crypto);
+ rosterStorage = new RosterFileStorage(baseDir / profile / "roster.xml");
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- historyStorage = new SQLiteHistoryStorage(baseDir / "history.db");
+ historyStorage = new SQLiteHistoryStorage(baseDir / "history.db");
#else
- historyStorage = NULL;
+ historyStorage = NULL;
#endif
}
FileStorages::~FileStorages() {
- delete rosterStorage;
- delete avatarStorage;
- delete capsStorage;
- delete vcardStorage;
- delete historyStorage;
+ delete rosterStorage;
+ delete avatarStorage;
+ delete capsStorage;
+ delete vcardStorage;
+ delete historyStorage;
}
VCardStorage* FileStorages::getVCardStorage() const {
- return vcardStorage;
+ return vcardStorage;
}
CapsStorage* FileStorages::getCapsStorage() const {
- return capsStorage;
+ return capsStorage;
}
AvatarStorage* FileStorages::getAvatarStorage() const {
- return avatarStorage;
+ return avatarStorage;
}
RosterStorage* FileStorages::getRosterStorage() const {
- return rosterStorage;
+ return rosterStorage;
}
HistoryStorage* FileStorages::getHistoryStorage() const {
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- return historyStorage;
+ return historyStorage;
#else
- return NULL;
+ return NULL;
#endif
}
diff --git a/Swift/Controllers/Storages/FileStorages.h b/Swift/Controllers/Storages/FileStorages.h
index 195d0fa..e71d665 100644
--- a/Swift/Controllers/Storages/FileStorages.h
+++ b/Swift/Controllers/Storages/FileStorages.h
@@ -11,47 +11,47 @@
#include <Swiften/Client/Storages.h>
namespace Swift {
- class VCardFileStorage;
- class AvatarFileStorage;
- class CapsFileStorage;
- class RosterFileStorage;
- class HistoryStorage;
- class JID;
- class CryptoProvider;
+ class VCardFileStorage;
+ class AvatarFileStorage;
+ class CapsFileStorage;
+ class RosterFileStorage;
+ class HistoryStorage;
+ class JID;
+ class CryptoProvider;
- /**
- * A storages implementation that stores all controller data on disk.
- */
- class FileStorages : public Storages {
- public:
- /**
- * Creates the storages interface.
- *
- * All data will be stored relative to a base directory, and
- * for some controllers, in a subdirectory for the given profile.
- * The data is stored in the following places:
- * - Avatars: $basedir/avatars
- * - VCards: $basedir/$profile/vcards
- * - Entity capabilities: $basedir/caps
- *
- * \param baseDir the base dir to store data relative to
- * \param jid the subdir in which profile-specific data will be stored.
- * The bare JID will be used as the subdir name.
- */
- FileStorages(const boost::filesystem::path& baseDir, const JID& jid, CryptoProvider*);
- ~FileStorages();
+ /**
+ * A storages implementation that stores all controller data on disk.
+ */
+ class FileStorages : public Storages {
+ public:
+ /**
+ * Creates the storages interface.
+ *
+ * All data will be stored relative to a base directory, and
+ * for some controllers, in a subdirectory for the given profile.
+ * The data is stored in the following places:
+ * - Avatars: $basedir/avatars
+ * - VCards: $basedir/$profile/vcards
+ * - Entity capabilities: $basedir/caps
+ *
+ * \param baseDir the base dir to store data relative to
+ * \param jid the subdir in which profile-specific data will be stored.
+ * The bare JID will be used as the subdir name.
+ */
+ FileStorages(const boost::filesystem::path& baseDir, const JID& jid, CryptoProvider*);
+ ~FileStorages();
- virtual VCardStorage* getVCardStorage() const;
- virtual AvatarStorage* getAvatarStorage() const;
- virtual CapsStorage* getCapsStorage() const;
- virtual RosterStorage* getRosterStorage() const;
- virtual HistoryStorage* getHistoryStorage() const;
+ virtual VCardStorage* getVCardStorage() const;
+ virtual AvatarStorage* getAvatarStorage() const;
+ virtual CapsStorage* getCapsStorage() const;
+ virtual RosterStorage* getRosterStorage() const;
+ virtual HistoryStorage* getHistoryStorage() const;
- private:
- VCardFileStorage* vcardStorage;
- AvatarFileStorage* avatarStorage;
- CapsFileStorage* capsStorage;
- RosterFileStorage* rosterStorage;
- HistoryStorage* historyStorage;
- };
+ private:
+ VCardFileStorage* vcardStorage;
+ AvatarFileStorage* avatarStorage;
+ CapsFileStorage* capsStorage;
+ RosterFileStorage* rosterStorage;
+ HistoryStorage* historyStorage;
+ };
}
diff --git a/Swift/Controllers/Storages/FileStoragesFactory.h b/Swift/Controllers/Storages/FileStoragesFactory.h
index 66b3841..ec0106e 100644
--- a/Swift/Controllers/Storages/FileStoragesFactory.h
+++ b/Swift/Controllers/Storages/FileStoragesFactory.h
@@ -10,18 +10,18 @@
#include <Swift/Controllers/Storages/StoragesFactory.h>
namespace Swift {
- class CryptoProvider;
+ class CryptoProvider;
- class FileStoragesFactory : public StoragesFactory {
- public:
- FileStoragesFactory(const boost::filesystem::path& basePath, CryptoProvider* crypto) : basePath(basePath), crypto(crypto) {}
+ class FileStoragesFactory : public StoragesFactory {
+ public:
+ FileStoragesFactory(const boost::filesystem::path& basePath, CryptoProvider* crypto) : basePath(basePath), crypto(crypto) {}
- virtual Storages* createStorages(const JID& profile) const {
- return new FileStorages(basePath, profile, crypto);
- }
+ virtual Storages* createStorages(const JID& profile) const {
+ return new FileStorages(basePath, profile, crypto);
+ }
- private:
- boost::filesystem::path basePath;
- CryptoProvider* crypto;
- };
+ private:
+ boost::filesystem::path basePath;
+ CryptoProvider* crypto;
+ };
}
diff --git a/Swift/Controllers/Storages/MemoryStoragesFactory.h b/Swift/Controllers/Storages/MemoryStoragesFactory.h
index 6f6523c..28e9138 100644
--- a/Swift/Controllers/Storages/MemoryStoragesFactory.h
+++ b/Swift/Controllers/Storages/MemoryStoragesFactory.h
@@ -11,17 +11,17 @@
#include <Swift/Controllers/Storages/StoragesFactory.h>
namespace Swift {
- class JID;
- class CryptoProvider;
+ class JID;
+ class CryptoProvider;
- class MemoryStoragesFactory : public StoragesFactory {
- public:
- MemoryStoragesFactory(CryptoProvider* cryptoProvider) : cryptoProvider_(cryptoProvider) {}
+ class MemoryStoragesFactory : public StoragesFactory {
+ public:
+ MemoryStoragesFactory(CryptoProvider* cryptoProvider) : cryptoProvider_(cryptoProvider) {}
- virtual Storages* createStorages(const JID& /*profile*/) const {
- return new MemoryStorages(cryptoProvider_);
- }
- private:
- CryptoProvider* cryptoProvider_;
- };
+ virtual Storages* createStorages(const JID& /*profile*/) const {
+ return new MemoryStorages(cryptoProvider_);
+ }
+ private:
+ CryptoProvider* cryptoProvider_;
+ };
}
diff --git a/Swift/Controllers/Storages/RosterFileStorage.cpp b/Swift/Controllers/Storages/RosterFileStorage.cpp
index c55bcf1..6cc5c61 100644
--- a/Swift/Controllers/Storages/RosterFileStorage.cpp
+++ b/Swift/Controllers/Storages/RosterFileStorage.cpp
@@ -18,9 +18,9 @@ RosterFileStorage::RosterFileStorage(const boost::filesystem::path& path) : path
}
boost::shared_ptr<RosterPayload> RosterFileStorage::getRoster() const {
- return RosterPersister().loadPayloadGeneric(path);
+ return RosterPersister().loadPayloadGeneric(path);
}
void RosterFileStorage::setRoster(boost::shared_ptr<RosterPayload> roster) {
- RosterPersister().savePayload(roster, path);
+ RosterPersister().savePayload(roster, path);
}
diff --git a/Swift/Controllers/Storages/RosterFileStorage.h b/Swift/Controllers/Storages/RosterFileStorage.h
index d100793..dd1a6c9 100644
--- a/Swift/Controllers/Storages/RosterFileStorage.h
+++ b/Swift/Controllers/Storages/RosterFileStorage.h
@@ -11,14 +11,14 @@
#include <Swiften/Roster/RosterStorage.h>
namespace Swift {
- class RosterFileStorage : public RosterStorage {
- public:
- RosterFileStorage(const boost::filesystem::path& path);
+ class RosterFileStorage : public RosterStorage {
+ public:
+ RosterFileStorage(const boost::filesystem::path& path);
- virtual boost::shared_ptr<RosterPayload> getRoster() const;
- virtual void setRoster(boost::shared_ptr<RosterPayload>);
+ virtual boost::shared_ptr<RosterPayload> getRoster() const;
+ virtual void setRoster(boost::shared_ptr<RosterPayload>);
- private:
- boost::filesystem::path path;
- };
+ private:
+ boost::filesystem::path path;
+ };
}
diff --git a/Swift/Controllers/Storages/StoragesFactory.h b/Swift/Controllers/Storages/StoragesFactory.h
index 4eb991b..771230b 100644
--- a/Swift/Controllers/Storages/StoragesFactory.h
+++ b/Swift/Controllers/Storages/StoragesFactory.h
@@ -7,13 +7,13 @@
#pragma once
namespace Swift {
- class Storages;
- class JID;
+ class Storages;
+ class JID;
- class StoragesFactory {
- public:
- virtual ~StoragesFactory() {}
+ class StoragesFactory {
+ public:
+ virtual ~StoragesFactory() {}
- virtual Storages* createStorages(const JID& profile) const = 0;
- };
+ virtual Storages* createStorages(const JID& profile) const = 0;
+ };
}
diff --git a/Swift/Controllers/Storages/VCardFileStorage.cpp b/Swift/Controllers/Storages/VCardFileStorage.cpp
index a93e286..720165a 100644
--- a/Swift/Controllers/Storages/VCardFileStorage.cpp
+++ b/Swift/Controllers/Storages/VCardFileStorage.cpp
@@ -28,100 +28,100 @@ using namespace Swift;
typedef GenericPayloadPersister<VCard, VCardParser, VCardSerializer> VCardPersister;
VCardFileStorage::VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto) : VCardStorage(crypto), vcardsPath(dir), crypto(crypto) {
- cacheFile = vcardsPath / "phashes";
- if (boost::filesystem::exists(cacheFile)) {
- try {
- boost::filesystem::ifstream file(cacheFile);
- std::string line;
- if (file.is_open()) {
- while (!file.eof()) {
- getline(file, line);
- std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' ');
- JID jid(r.second);
- if (jid.isValid()) {
- photoHashes.insert(std::make_pair(jid, r.first));
- }
- else if (!r.first.empty() || !r.second.empty()) {
- std::cerr << "Invalid entry in phashes file" << std::endl;
- }
- }
- }
- }
- catch (...) {
- std::cerr << "Error reading phashes file" << std::endl;
- }
- }
+ cacheFile = vcardsPath / "phashes";
+ if (boost::filesystem::exists(cacheFile)) {
+ try {
+ boost::filesystem::ifstream file(cacheFile);
+ std::string line;
+ if (file.is_open()) {
+ while (!file.eof()) {
+ getline(file, line);
+ std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' ');
+ JID jid(r.second);
+ if (jid.isValid()) {
+ photoHashes.insert(std::make_pair(jid, r.first));
+ }
+ else if (!r.first.empty() || !r.second.empty()) {
+ std::cerr << "Invalid entry in phashes file" << std::endl;
+ }
+ }
+ }
+ }
+ catch (...) {
+ std::cerr << "Error reading phashes file" << std::endl;
+ }
+ }
}
boost::shared_ptr<VCard> VCardFileStorage::getVCard(const JID& jid) const {
- boost::shared_ptr<VCard> result = VCardPersister().loadPayloadGeneric(getVCardPath(jid));
- getAndUpdatePhotoHash(jid, result);
- return result;
+ boost::shared_ptr<VCard> result = VCardPersister().loadPayloadGeneric(getVCardPath(jid));
+ getAndUpdatePhotoHash(jid, result);
+ return result;
}
boost::posix_time::ptime VCardFileStorage::getVCardWriteTime(const JID& jid) const {
- if (vcardWriteTimes.find(jid) == vcardWriteTimes.end()) {
- return boost::posix_time::ptime();
- }
- else {
- return vcardWriteTimes.at(jid);
- }
+ if (vcardWriteTimes.find(jid) == vcardWriteTimes.end()) {
+ return boost::posix_time::ptime();
+ }
+ else {
+ return vcardWriteTimes.at(jid);
+ }
}
void VCardFileStorage::setVCard(const JID& jid, VCard::ref v) {
- vcardWriteTimes[jid] = boost::posix_time::second_clock::universal_time();
- VCardPersister().savePayload(v, getVCardPath(jid));
- getAndUpdatePhotoHash(jid, v);
+ vcardWriteTimes[jid] = boost::posix_time::second_clock::universal_time();
+ VCardPersister().savePayload(v, getVCardPath(jid));
+ getAndUpdatePhotoHash(jid, v);
}
boost::filesystem::path VCardFileStorage::getVCardPath(const JID& jid) const {
- try {
- std::string file(jid.toString());
- String::replaceAll(file, '/', "%2f");
- return boost::filesystem::path(vcardsPath / stringToPath(file + ".xml"));
- }
- catch (const boost::filesystem::filesystem_error& e) {
- std::cerr << "ERROR: " << e.what() << std::endl;
- return boost::filesystem::path();
- }
+ try {
+ std::string file(jid.toString());
+ String::replaceAll(file, '/', "%2f");
+ return boost::filesystem::path(vcardsPath / stringToPath(file + ".xml"));
+ }
+ catch (const boost::filesystem::filesystem_error& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ return boost::filesystem::path();
+ }
}
std::string VCardFileStorage::getPhotoHash(const JID& jid) const {
- PhotoHashMap::const_iterator i = photoHashes.find(jid);
- if (i != photoHashes.end()) {
- return i->second;
- }
- else {
- VCard::ref vCard = getVCard(jid);
- return getAndUpdatePhotoHash(jid, vCard);
- }
+ PhotoHashMap::const_iterator i = photoHashes.find(jid);
+ if (i != photoHashes.end()) {
+ return i->second;
+ }
+ else {
+ VCard::ref vCard = getVCard(jid);
+ return getAndUpdatePhotoHash(jid, vCard);
+ }
}
std::string VCardFileStorage::getAndUpdatePhotoHash(const JID& jid, VCard::ref vCard) const {
- std::string hash;
- if (vCard && !vCard->getPhoto().empty()) {
- hash = Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto()));
- }
- std::pair<PhotoHashMap::iterator, bool> r = photoHashes.insert(std::make_pair(jid, hash));
- if (r.second) {
- savePhotoHashes();
- }
- else if (r.first->second != hash) {
- r.first->second = hash;
- savePhotoHashes();
- }
- return hash;
+ std::string hash;
+ if (vCard && !vCard->getPhoto().empty()) {
+ hash = Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto()));
+ }
+ std::pair<PhotoHashMap::iterator, bool> r = photoHashes.insert(std::make_pair(jid, hash));
+ if (r.second) {
+ savePhotoHashes();
+ }
+ else if (r.first->second != hash) {
+ r.first->second = hash;
+ savePhotoHashes();
+ }
+ return hash;
}
void VCardFileStorage::savePhotoHashes() const {
- try {
- boost::filesystem::ofstream file(cacheFile);
- for (PhotoHashMap::const_iterator i = photoHashes.begin(); i != photoHashes.end(); ++i) {
- file << i->second << " " << i->first.toString() << std::endl;
- }
- file.close();
- }
- catch (...) {
- std::cerr << "Error writing vcards file" << std::endl;
- }
+ try {
+ boost::filesystem::ofstream file(cacheFile);
+ for (PhotoHashMap::const_iterator i = photoHashes.begin(); i != photoHashes.end(); ++i) {
+ file << i->second << " " << i->first.toString() << std::endl;
+ }
+ file.close();
+ }
+ catch (...) {
+ std::cerr << "Error writing vcards file" << std::endl;
+ }
}
diff --git a/Swift/Controllers/Storages/VCardFileStorage.h b/Swift/Controllers/Storages/VCardFileStorage.h
index 56e06f2..971a3f9 100644
--- a/Swift/Controllers/Storages/VCardFileStorage.h
+++ b/Swift/Controllers/Storages/VCardFileStorage.h
@@ -15,30 +15,30 @@
#include <Swiften/VCards/VCardStorage.h>
namespace Swift {
- class CryptoProvider;
+ class CryptoProvider;
- class VCardFileStorage : public VCardStorage {
- public:
- VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto);
+ class VCardFileStorage : public VCardStorage {
+ public:
+ VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto);
- virtual VCard::ref getVCard(const JID& jid) const;
- virtual boost::posix_time::ptime getVCardWriteTime(const JID& jid) const;
- virtual void setVCard(const JID& jid, VCard::ref v);
+ virtual VCard::ref getVCard(const JID& jid) const;
+ virtual boost::posix_time::ptime getVCardWriteTime(const JID& jid) const;
+ virtual void setVCard(const JID& jid, VCard::ref v);
- virtual std::string getPhotoHash(const JID&) const;
+ virtual std::string getPhotoHash(const JID&) const;
- private:
- boost::filesystem::path getVCardPath(const JID&) const;
+ private:
+ boost::filesystem::path getVCardPath(const JID&) const;
- std::string getAndUpdatePhotoHash(const JID& jid, VCard::ref vcard) const;
- void savePhotoHashes() const;
+ std::string getAndUpdatePhotoHash(const JID& jid, VCard::ref vcard) const;
+ void savePhotoHashes() const;
- private:
- boost::filesystem::path vcardsPath;
- CryptoProvider* crypto;
- boost::filesystem::path cacheFile;
- typedef std::map<JID, std::string> PhotoHashMap;
- mutable PhotoHashMap photoHashes;
- std::map<JID, boost::posix_time::ptime> vcardWriteTimes;
- };
+ private:
+ boost::filesystem::path vcardsPath;
+ CryptoProvider* crypto;
+ boost::filesystem::path cacheFile;
+ typedef std::map<JID, std::string> PhotoHashMap;
+ mutable PhotoHashMap photoHashes;
+ std::map<JID, boost::posix_time::ptime> vcardWriteTimes;
+ };
}
diff --git a/Swift/Controllers/SystemTray.h b/Swift/Controllers/SystemTray.h
index fd8fe01..094857f 100644
--- a/Swift/Controllers/SystemTray.h
+++ b/Swift/Controllers/SystemTray.h
@@ -9,11 +9,11 @@
#include <Swiften/Elements/StatusShow.h>
namespace Swift {
- class SystemTray {
- public:
- virtual ~SystemTray(){}
- virtual void setUnreadMessages(bool some) = 0;
- virtual void setStatusType(StatusShow::Type type) = 0;
- virtual void setConnecting() = 0;
- };
+ class SystemTray {
+ public:
+ virtual ~SystemTray(){}
+ virtual void setUnreadMessages(bool some) = 0;
+ virtual void setStatusType(StatusShow::Type type) = 0;
+ virtual void setConnecting() = 0;
+ };
}
diff --git a/Swift/Controllers/SystemTrayController.cpp b/Swift/Controllers/SystemTrayController.cpp
index e4029e0..72d3403 100644
--- a/Swift/Controllers/SystemTrayController.cpp
+++ b/Swift/Controllers/SystemTrayController.cpp
@@ -14,29 +14,29 @@
namespace Swift {
SystemTrayController::SystemTrayController(EventController* eventController, SystemTray* systemTray) {
- systemTray_ = systemTray;
- eventController_ = eventController;
- eventController_->onEventQueueLengthChange.connect(boost::bind(&SystemTrayController::handleEventQueueLengthChange, this, _1));
+ systemTray_ = systemTray;
+ eventController_ = eventController;
+ eventController_->onEventQueueLengthChange.connect(boost::bind(&SystemTrayController::handleEventQueueLengthChange, this, _1));
}
void SystemTrayController::handleEventQueueLengthChange(int /*length*/) {
- EventList events = eventController_->getEvents();
- bool found = false;
- for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
- if (boost::dynamic_pointer_cast<MessageEvent>(*it)) {
- found = true;
- break;
- }
- }
- systemTray_->setUnreadMessages(found);
+ EventList events = eventController_->getEvents();
+ bool found = false;
+ for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
+ if (boost::dynamic_pointer_cast<MessageEvent>(*it)) {
+ found = true;
+ break;
+ }
+ }
+ systemTray_->setUnreadMessages(found);
}
void SystemTrayController::setMyStatusType(StatusShow::Type type) {
- systemTray_->setStatusType(type);
+ systemTray_->setStatusType(type);
}
void SystemTrayController::setConnecting() {
- systemTray_->setConnecting();
+ systemTray_->setConnecting();
}
}
diff --git a/Swift/Controllers/SystemTrayController.h b/Swift/Controllers/SystemTrayController.h
index f19b127..850ac71 100644
--- a/Swift/Controllers/SystemTrayController.h
+++ b/Swift/Controllers/SystemTrayController.h
@@ -9,19 +9,19 @@
#include <Swiften/Elements/StatusShow.h>
namespace Swift {
- class EventController;
- class SystemTray;
+ class EventController;
+ class SystemTray;
- class SystemTrayController {
- public:
- SystemTrayController(EventController* eventController, SystemTray* systemTray);
- void setMyStatusType(StatusShow::Type type);
- void setConnecting();
- private:
- void handleEventQueueLengthChange(int length);
+ class SystemTrayController {
+ public:
+ SystemTrayController(EventController* eventController, SystemTray* systemTray);
+ void setMyStatusType(StatusShow::Type type);
+ void setConnecting();
+ private:
+ void handleEventQueueLengthChange(int length);
- private:
- EventController* eventController_;
- SystemTray* systemTray_;
- };
+ private:
+ EventController* eventController_;
+ SystemTray* systemTray_;
+ };
}
diff --git a/Swift/Controllers/Translator.cpp b/Swift/Controllers/Translator.cpp
index 13230ab..b62fd28 100644
--- a/Swift/Controllers/Translator.cpp
+++ b/Swift/Controllers/Translator.cpp
@@ -11,9 +11,9 @@
namespace Swift {
static struct DefaultTranslator : public Translator {
- virtual std::string translate(const std::string& text, const std::string&) {
- return text;
- }
+ virtual std::string translate(const std::string& text, const std::string&) {
+ return text;
+ }
} defaultTranslator;
Translator* Translator::translator = &defaultTranslator;
@@ -22,7 +22,7 @@ Translator::~Translator() {
}
void Translator::setInstance(Translator* t) {
- translator = t;
+ translator = t;
}
}
diff --git a/Swift/Controllers/Translator.h b/Swift/Controllers/Translator.h
index 801e8b5..5c52e9f 100644
--- a/Swift/Controllers/Translator.h
+++ b/Swift/Controllers/Translator.h
@@ -9,19 +9,19 @@
#include <string>
namespace Swift {
- class Translator {
- public:
- virtual ~Translator();
+ class Translator {
+ public:
+ virtual ~Translator();
- virtual std::string translate(const std::string& text, const std::string& context) = 0;
+ virtual std::string translate(const std::string& text, const std::string& context) = 0;
- static void setInstance(Translator* translator);
+ static void setInstance(Translator* translator);
- static Translator* getInstance() {
- return translator;
- }
+ static Translator* getInstance() {
+ return translator;
+ }
- private:
- static Translator* translator;
- };
+ private:
+ static Translator* translator;
+ };
}
diff --git a/Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h b/Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h
index 93cad03..b46774c 100644
--- a/Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h
+++ b/Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h
@@ -13,12 +13,12 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class AcceptWhiteboardSessionUIEvent : public UIEvent {
- typedef boost::shared_ptr<AcceptWhiteboardSessionUIEvent> ref;
- public:
- AcceptWhiteboardSessionUIEvent(const JID& jid) : jid_(jid) {}
- const JID& getContact() const {return jid_;}
- private:
- JID jid_;
- };
+ class AcceptWhiteboardSessionUIEvent : public UIEvent {
+ typedef boost::shared_ptr<AcceptWhiteboardSessionUIEvent> ref;
+ public:
+ AcceptWhiteboardSessionUIEvent(const JID& jid) : jid_(jid) {}
+ const JID& getContact() const {return jid_;}
+ private:
+ JID jid_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/AddContactUIEvent.h b/Swift/Controllers/UIEvents/AddContactUIEvent.h
index 127dba2..d2176ac 100644
--- a/Swift/Controllers/UIEvents/AddContactUIEvent.h
+++ b/Swift/Controllers/UIEvents/AddContactUIEvent.h
@@ -12,25 +12,25 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class AddContactUIEvent : public UIEvent {
- public:
- AddContactUIEvent(const JID& jid, const std::string& name, const std::set<std::string>& groups) : jid_(jid), name_(name), groups_(groups) {}
-
- const std::string& getName() const {
- return name_;
- }
-
- const JID& getJID() const {
- return jid_;
- }
-
- const std::set<std::string>& getGroups() const {
- return groups_;
- }
-
- private:
- JID jid_;
- std::string name_;
- std::set<std::string> groups_;
- };
+ class AddContactUIEvent : public UIEvent {
+ public:
+ AddContactUIEvent(const JID& jid, const std::string& name, const std::set<std::string>& groups) : jid_(jid), name_(name), groups_(groups) {}
+
+ const std::string& getName() const {
+ return name_;
+ }
+
+ const JID& getJID() const {
+ return jid_;
+ }
+
+ const std::set<std::string>& getGroups() const {
+ return groups_;
+ }
+
+ private:
+ JID jid_;
+ std::string name_;
+ std::set<std::string> groups_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h b/Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h
index d19a402..526fc0d 100644
--- a/Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h
+++ b/Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h
@@ -13,12 +13,12 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class AddMUCBookmarkUIEvent : public UIEvent {
- public:
- AddMUCBookmarkUIEvent(const MUCBookmark& bookmark) : bookmark(bookmark) {}
- const MUCBookmark& getBookmark() { return bookmark; }
+ class AddMUCBookmarkUIEvent : public UIEvent {
+ public:
+ AddMUCBookmarkUIEvent(const MUCBookmark& bookmark) : bookmark(bookmark) {}
+ const MUCBookmark& getBookmark() { return bookmark; }
- private:
- MUCBookmark bookmark;
- };
+ private:
+ MUCBookmark bookmark;
+ };
}
diff --git a/Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h b/Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h
index f5c3b0e..62751b6 100644
--- a/Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h
+++ b/Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h
@@ -13,12 +13,12 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class CancelWhiteboardSessionUIEvent : public UIEvent {
- typedef boost::shared_ptr<CancelWhiteboardSessionUIEvent> ref;
- public:
- CancelWhiteboardSessionUIEvent(const JID& jid) : jid_(jid) {}
- const JID& getContact() const {return jid_;}
- private:
- JID jid_;
- };
+ class CancelWhiteboardSessionUIEvent : public UIEvent {
+ typedef boost::shared_ptr<CancelWhiteboardSessionUIEvent> ref;
+ public:
+ CancelWhiteboardSessionUIEvent(const JID& jid) : jid_(jid) {}
+ const JID& getContact() const {return jid_;}
+ private:
+ JID jid_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/CreateImpromptuMUCUIEvent.h b/Swift/Controllers/UIEvents/CreateImpromptuMUCUIEvent.h
index 57e181d..b566be6 100644
--- a/Swift/Controllers/UIEvents/CreateImpromptuMUCUIEvent.h
+++ b/Swift/Controllers/UIEvents/CreateImpromptuMUCUIEvent.h
@@ -11,16 +11,16 @@
namespace Swift {
class CreateImpromptuMUCUIEvent : public UIEvent {
- public:
- CreateImpromptuMUCUIEvent(const std::vector<JID>& jids, const JID& roomJID = JID(), const std::string reason = "") : jids_(jids), roomJID_(roomJID), reason_(reason) { }
+ public:
+ CreateImpromptuMUCUIEvent(const std::vector<JID>& jids, const JID& roomJID = JID(), const std::string reason = "") : jids_(jids), roomJID_(roomJID), reason_(reason) { }
- std::vector<JID> getJIDs() const { return jids_; }
- JID getRoomJID() const { return roomJID_; }
- std::string getReason() const { return reason_; }
- private:
- std::vector<JID> jids_;
- JID roomJID_;
- std::string reason_;
+ std::vector<JID> getJIDs() const { return jids_; }
+ JID getRoomJID() const { return roomJID_; }
+ std::string getReason() const { return reason_; }
+ private:
+ std::vector<JID> jids_;
+ JID roomJID_;
+ std::string reason_;
};
}
diff --git a/Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h b/Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h
index 602f45e..b3d3118 100644
--- a/Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h
+++ b/Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h
@@ -13,15 +13,15 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class EditMUCBookmarkUIEvent : public UIEvent {
- public:
- EditMUCBookmarkUIEvent(const MUCBookmark& oldBookmark, const MUCBookmark& newBookmark) : oldBookmark(oldBookmark) , newBookmark(newBookmark) {}
+ class EditMUCBookmarkUIEvent : public UIEvent {
+ public:
+ EditMUCBookmarkUIEvent(const MUCBookmark& oldBookmark, const MUCBookmark& newBookmark) : oldBookmark(oldBookmark) , newBookmark(newBookmark) {}
- const MUCBookmark& getOldBookmark() {return oldBookmark;}
- const MUCBookmark& getNewBookmark() {return newBookmark;}
+ const MUCBookmark& getOldBookmark() {return oldBookmark;}
+ const MUCBookmark& getNewBookmark() {return newBookmark;}
- private:
- MUCBookmark oldBookmark;
- MUCBookmark newBookmark;
- };
+ private:
+ MUCBookmark oldBookmark;
+ MUCBookmark newBookmark;
+ };
}
diff --git a/Swift/Controllers/UIEvents/InviteToMUCUIEvent.h b/Swift/Controllers/UIEvents/InviteToMUCUIEvent.h
index 70c46b0..e1416de 100644
--- a/Swift/Controllers/UIEvents/InviteToMUCUIEvent.h
+++ b/Swift/Controllers/UIEvents/InviteToMUCUIEvent.h
@@ -21,28 +21,28 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class InviteToMUCUIEvent : public UIEvent {
- public:
- typedef boost::shared_ptr<InviteToMUCUIEvent> ref;
-
- InviteToMUCUIEvent(const JID& room, const std::vector<JID>& JIDsToInvite, const std::string& reason) : room_(room), invite_(JIDsToInvite), reason_(reason) {
- }
-
- const JID& getRoom() const {
- return room_;
- }
-
- const std::vector<JID> getInvites() const {
- return invite_;
- }
-
- const std::string getReason() const {
- return reason_;
- }
-
- private:
- JID room_;
- std::vector<JID> invite_;
- std::string reason_;
- };
+ class InviteToMUCUIEvent : public UIEvent {
+ public:
+ typedef boost::shared_ptr<InviteToMUCUIEvent> ref;
+
+ InviteToMUCUIEvent(const JID& room, const std::vector<JID>& JIDsToInvite, const std::string& reason) : room_(room), invite_(JIDsToInvite), reason_(reason) {
+ }
+
+ const JID& getRoom() const {
+ return room_;
+ }
+
+ const std::vector<JID> getInvites() const {
+ return invite_;
+ }
+
+ const std::string getReason() const {
+ return reason_;
+ }
+
+ private:
+ JID room_;
+ std::vector<JID> invite_;
+ std::string reason_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/JoinMUCUIEvent.h b/Swift/Controllers/UIEvents/JoinMUCUIEvent.h
index 8d74858..076b5b6 100644
--- a/Swift/Controllers/UIEvents/JoinMUCUIEvent.h
+++ b/Swift/Controllers/UIEvents/JoinMUCUIEvent.h
@@ -16,25 +16,25 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class JoinMUCUIEvent : public UIEvent {
- public:
- typedef boost::shared_ptr<JoinMUCUIEvent> ref;
- JoinMUCUIEvent(const JID& jid, const boost::optional<std::string>& password = boost::optional<std::string>(), const boost::optional<std::string>& nick = boost::optional<std::string>(), bool joinAutomaticallyInFuture = false, bool createAsReservedRoomIfNew = false, bool isImpromptu = false, bool isContinuation = false) : jid_(jid), nick_(nick), joinAutomatically_(joinAutomaticallyInFuture), createAsReservedRoomIfNew_(createAsReservedRoomIfNew), password_(password), isImpromptuMUC_(isImpromptu), isContinuation_(isContinuation) {}
- const boost::optional<std::string>& getNick() const {return nick_;}
- const JID& getJID() const {return jid_;}
- bool getShouldJoinAutomatically() const {return joinAutomatically_;}
- bool getCreateAsReservedRoomIfNew() const {return createAsReservedRoomIfNew_;}
- const boost::optional<std::string>& getPassword() const {return password_;}
- bool isImpromptu() const {return isImpromptuMUC_;}
- bool isContinuation() const {return isContinuation_;}
+ class JoinMUCUIEvent : public UIEvent {
+ public:
+ typedef boost::shared_ptr<JoinMUCUIEvent> ref;
+ JoinMUCUIEvent(const JID& jid, const boost::optional<std::string>& password = boost::optional<std::string>(), const boost::optional<std::string>& nick = boost::optional<std::string>(), bool joinAutomaticallyInFuture = false, bool createAsReservedRoomIfNew = false, bool isImpromptu = false, bool isContinuation = false) : jid_(jid), nick_(nick), joinAutomatically_(joinAutomaticallyInFuture), createAsReservedRoomIfNew_(createAsReservedRoomIfNew), password_(password), isImpromptuMUC_(isImpromptu), isContinuation_(isContinuation) {}
+ const boost::optional<std::string>& getNick() const {return nick_;}
+ const JID& getJID() const {return jid_;}
+ bool getShouldJoinAutomatically() const {return joinAutomatically_;}
+ bool getCreateAsReservedRoomIfNew() const {return createAsReservedRoomIfNew_;}
+ const boost::optional<std::string>& getPassword() const {return password_;}
+ bool isImpromptu() const {return isImpromptuMUC_;}
+ bool isContinuation() const {return isContinuation_;}
- private:
- JID jid_;
- boost::optional<std::string> nick_;
- bool joinAutomatically_;
- bool createAsReservedRoomIfNew_;
- boost::optional<std::string> password_;
- bool isImpromptuMUC_;
- bool isContinuation_;
- };
+ private:
+ JID jid_;
+ boost::optional<std::string> nick_;
+ bool joinAutomatically_;
+ bool createAsReservedRoomIfNew_;
+ boost::optional<std::string> password_;
+ bool isImpromptuMUC_;
+ bool isContinuation_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h b/Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h
index f6655e4..2803197 100644
--- a/Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h
+++ b/Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h
@@ -13,12 +13,12 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RemoveMUCBookmarkUIEvent : public UIEvent {
- public:
- RemoveMUCBookmarkUIEvent(const MUCBookmark& bookmark) : bookmark(bookmark) {}
- const MUCBookmark& getBookmark() { return bookmark; }
+ class RemoveMUCBookmarkUIEvent : public UIEvent {
+ public:
+ RemoveMUCBookmarkUIEvent(const MUCBookmark& bookmark) : bookmark(bookmark) {}
+ const MUCBookmark& getBookmark() { return bookmark; }
- private:
- MUCBookmark bookmark;
- };
+ private:
+ MUCBookmark bookmark;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h b/Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h
index 95b59b1..0f4a89d 100644
--- a/Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h
+++ b/Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h
@@ -13,12 +13,12 @@
namespace Swift {
class RemoveRosterItemUIEvent : public UIEvent {
- public:
- RemoveRosterItemUIEvent(const JID& jid) : jid_(jid) {}
- virtual ~RemoveRosterItemUIEvent() {}
- JID getJID() {return jid_;}
- private:
- JID jid_;
+ public:
+ RemoveRosterItemUIEvent(const JID& jid) : jid_(jid) {}
+ virtual ~RemoveRosterItemUIEvent() {}
+ JID getJID() {return jid_;}
+ private:
+ JID jid_;
};
diff --git a/Swift/Controllers/UIEvents/RenameGroupUIEvent.h b/Swift/Controllers/UIEvents/RenameGroupUIEvent.h
index cea1afc..ea19efe 100644
--- a/Swift/Controllers/UIEvents/RenameGroupUIEvent.h
+++ b/Swift/Controllers/UIEvents/RenameGroupUIEvent.h
@@ -11,21 +11,21 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RenameGroupUIEvent : public UIEvent {
- public:
- RenameGroupUIEvent(const std::string& group, const std::string& newName) : group(group), newName(newName) {
- }
+ class RenameGroupUIEvent : public UIEvent {
+ public:
+ RenameGroupUIEvent(const std::string& group, const std::string& newName) : group(group), newName(newName) {
+ }
- const std::string& getGroup() const {
- return group;
- }
+ const std::string& getGroup() const {
+ return group;
+ }
- const std::string& getNewName() const {
- return newName;
- }
+ const std::string& getNewName() const {
+ return newName;
+ }
- private:
- std::string group;
- std::string newName;
- };
+ private:
+ std::string group;
+ std::string newName;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h b/Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h
index fbf3814..7d370e2 100644
--- a/Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h
+++ b/Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h
@@ -13,15 +13,15 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RenameRosterItemUIEvent : public UIEvent {
- public:
- RenameRosterItemUIEvent(const JID& jid, const std::string& newName) : jid_(jid), newName_(newName) {}
+ class RenameRosterItemUIEvent : public UIEvent {
+ public:
+ RenameRosterItemUIEvent(const JID& jid, const std::string& newName) : jid_(jid), newName_(newName) {}
- const JID& getJID() const {return jid_;}
- const std::string& getNewName() const {return newName_;}
+ const JID& getJID() const {return jid_;}
+ const std::string& getNewName() const {return newName_;}
- private:
- JID jid_;
- std::string newName_;
- };
+ private:
+ JID jid_;
+ std::string newName_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestAdHocUIEvent.h b/Swift/Controllers/UIEvents/RequestAdHocUIEvent.h
index afc0a34..f6fa1c7 100644
--- a/Swift/Controllers/UIEvents/RequestAdHocUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestAdHocUIEvent.h
@@ -10,11 +10,11 @@
#include <Swift/Controllers/UIInterfaces/MainWindow.h>
namespace Swift {
- class RequestAdHocUIEvent : public UIEvent {
- public:
- RequestAdHocUIEvent(const DiscoItems::Item& command) : command_(command) {}
- const DiscoItems::Item& getCommand() const {return command_;}
- private:
- DiscoItems::Item command_;
- };
+ class RequestAdHocUIEvent : public UIEvent {
+ public:
+ RequestAdHocUIEvent(const DiscoItems::Item& command) : command_(command) {}
+ const DiscoItems::Item& getCommand() const {return command_;}
+ private:
+ DiscoItems::Item command_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestAdHocWithJIDUIEvent.h b/Swift/Controllers/UIEvents/RequestAdHocWithJIDUIEvent.h
index 5c7e97a..8d8bd19 100644
--- a/Swift/Controllers/UIEvents/RequestAdHocWithJIDUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestAdHocWithJIDUIEvent.h
@@ -9,13 +9,13 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestAdHocWithJIDUIEvent : public UIEvent {
- public:
- RequestAdHocWithJIDUIEvent(const JID& jid, const std::string& node) : jid_(jid), node_(node) {}
- JID getJID() const { return jid_; }
- std::string getNode() const { return node_; }
- private:
- JID jid_;
- std::string node_;
- };
+ class RequestAdHocWithJIDUIEvent : public UIEvent {
+ public:
+ RequestAdHocWithJIDUIEvent(const JID& jid, const std::string& node) : jid_(jid), node_(node) {}
+ JID getJID() const { return jid_; }
+ std::string getNode() const { return node_; }
+ private:
+ JID jid_;
+ std::string node_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h b/Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h
index 73ad20e..474d155 100644
--- a/Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h
@@ -13,18 +13,18 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestAddUserDialogUIEvent : public UIEvent {
+ class RequestAddUserDialogUIEvent : public UIEvent {
- public:
- RequestAddUserDialogUIEvent(const JID& predefinedJID, const std::string& predefinedName) : preJID_(predefinedJID), preName_(predefinedName) {}
- RequestAddUserDialogUIEvent() : preJID_(), preName_() {}
+ public:
+ RequestAddUserDialogUIEvent(const JID& predefinedJID, const std::string& predefinedName) : preJID_(predefinedJID), preName_(predefinedName) {}
+ RequestAddUserDialogUIEvent() : preJID_(), preName_() {}
- const JID& getPredefinedJID() const { return preJID_; }
- const std::string& getPredefinedName() const { return preName_; }
+ const JID& getPredefinedJID() const { return preJID_; }
+ const std::string& getPredefinedName() const { return preName_; }
- private:
- JID preJID_;
- std::string preName_;
+ private:
+ JID preJID_;
+ std::string preName_;
- };
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h b/Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h
index 6594897..4dcf8be 100644
--- a/Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h
@@ -19,25 +19,25 @@
namespace Swift {
class RequestChangeBlockStateUIEvent : public UIEvent {
- public:
- enum BlockState {
- Blocked,
- Unblocked
- };
-
- public:
- RequestChangeBlockStateUIEvent(BlockState newState, const JID& contact) : state_(newState), contact_(contact) {}
-
- BlockState getBlockState() const {
- return state_;
- }
-
- JID getContact() const {
- return contact_;
- }
- private:
- BlockState state_;
- JID contact_;
+ public:
+ enum BlockState {
+ Blocked,
+ Unblocked
+ };
+
+ public:
+ RequestChangeBlockStateUIEvent(BlockState newState, const JID& contact) : state_(newState), contact_(contact) {}
+
+ BlockState getBlockState() const {
+ return state_;
+ }
+
+ JID getContact() const {
+ return contact_;
+ }
+ private:
+ BlockState state_;
+ JID contact_;
};
}
diff --git a/Swift/Controllers/UIEvents/RequestChatUIEvent.h b/Swift/Controllers/UIEvents/RequestChatUIEvent.h
index 95d6075..4eca5d4 100644
--- a/Swift/Controllers/UIEvents/RequestChatUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestChatUIEvent.h
@@ -11,11 +11,11 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestChatUIEvent : public UIEvent {
- public:
- RequestChatUIEvent(const JID& contact) : contact_(contact) {}
- JID getContact() {return contact_;}
- private:
- JID contact_;
- };
+ class RequestChatUIEvent : public UIEvent {
+ public:
+ RequestChatUIEvent(const JID& contact) : contact_(contact) {}
+ JID getContact() {return contact_;}
+ private:
+ JID contact_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h b/Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h
index 76aa1f7..08804f4 100644
--- a/Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h
@@ -9,7 +9,7 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestChatWithUserDialogUIEvent : public UIEvent {
+ class RequestChatWithUserDialogUIEvent : public UIEvent {
- };
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h b/Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h
index 61ddbe9..5693ab1 100644
--- a/Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h
@@ -11,18 +11,18 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestContactEditorUIEvent : public UIEvent {
- public:
- typedef boost::shared_ptr<RequestContactEditorUIEvent> ref;
+ class RequestContactEditorUIEvent : public UIEvent {
+ public:
+ typedef boost::shared_ptr<RequestContactEditorUIEvent> ref;
- RequestContactEditorUIEvent(const JID& jid) : jid(jid) {
- }
+ RequestContactEditorUIEvent(const JID& jid) : jid(jid) {
+ }
- const JID& getJID() const {
- return jid;
- }
+ const JID& getJID() const {
+ return jid;
+ }
- private:
- JID jid;
- };
+ private:
+ JID jid;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestHighlightEditorUIEvent.h b/Swift/Controllers/UIEvents/RequestHighlightEditorUIEvent.h
index 42e22a2..0bfa458 100644
--- a/Swift/Controllers/UIEvents/RequestHighlightEditorUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestHighlightEditorUIEvent.h
@@ -10,7 +10,7 @@
namespace Swift {
- class RequestHighlightEditorUIEvent : public UIEvent {
- };
+ class RequestHighlightEditorUIEvent : public UIEvent {
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestHistoryUIEvent.h b/Swift/Controllers/UIEvents/RequestHistoryUIEvent.h
index 025e91f..8282204 100644
--- a/Swift/Controllers/UIEvents/RequestHistoryUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestHistoryUIEvent.h
@@ -9,6 +9,6 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestHistoryUIEvent : public UIEvent {
- };
+ class RequestHistoryUIEvent : public UIEvent {
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h b/Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h
index 3733532..9a1abb1 100644
--- a/Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h
@@ -21,34 +21,34 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestInviteToMUCUIEvent : public UIEvent {
- public:
- typedef boost::shared_ptr<RequestInviteToMUCUIEvent> ref;
-
- enum ImpromptuMode {
- Impromptu,
- NotImpromptu
- };
-
- RequestInviteToMUCUIEvent(const JID& room, const std::vector<JID>& JIDsToInvite, ImpromptuMode impromptu) : room_(room), invite_(JIDsToInvite) {
- isImpromptu_ = impromptu == Impromptu;
- }
-
- const JID& getRoom() const {
- return room_;
- }
-
- const std::vector<JID> getInvites() const {
- return invite_;
- }
-
- bool isImpromptu() const {
- return isImpromptu_;
- }
-
- private:
- JID room_;
- std::vector<JID> invite_;
- bool isImpromptu_;
- };
+ class RequestInviteToMUCUIEvent : public UIEvent {
+ public:
+ typedef boost::shared_ptr<RequestInviteToMUCUIEvent> ref;
+
+ enum ImpromptuMode {
+ Impromptu,
+ NotImpromptu
+ };
+
+ RequestInviteToMUCUIEvent(const JID& room, const std::vector<JID>& JIDsToInvite, ImpromptuMode impromptu) : room_(room), invite_(JIDsToInvite) {
+ isImpromptu_ = impromptu == Impromptu;
+ }
+
+ const JID& getRoom() const {
+ return room_;
+ }
+
+ const std::vector<JID> getInvites() const {
+ return invite_;
+ }
+
+ bool isImpromptu() const {
+ return isImpromptu_;
+ }
+
+ private:
+ JID room_;
+ std::vector<JID> invite_;
+ bool isImpromptu_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h b/Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h
index a3ba6c8..a2a4183 100644
--- a/Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h
@@ -15,18 +15,18 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestJoinMUCUIEvent : public UIEvent {
- public:
- typedef boost::shared_ptr<RequestJoinMUCUIEvent> ref;
+ class RequestJoinMUCUIEvent : public UIEvent {
+ public:
+ typedef boost::shared_ptr<RequestJoinMUCUIEvent> ref;
- RequestJoinMUCUIEvent(const JID& room = JID()) : room(room) {
- }
+ RequestJoinMUCUIEvent(const JID& room = JID()) : room(room) {
+ }
- const JID& getRoom() const {
- return room;
- }
+ const JID& getRoom() const {
+ return room;
+ }
- private:
- JID room;
- };
+ private:
+ JID room;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h b/Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h
index 1907242..1a02af4 100644
--- a/Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h
@@ -9,8 +9,8 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestProfileEditorUIEvent : public UIEvent {
- public:
- RequestProfileEditorUIEvent() {}
- };
+ class RequestProfileEditorUIEvent : public UIEvent {
+ public:
+ RequestProfileEditorUIEvent() {}
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h b/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h
index 625736f..9c2b01d 100644
--- a/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h
@@ -17,11 +17,11 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestWhiteboardUIEvent : public UIEvent {
- public:
- RequestWhiteboardUIEvent(const JID& contact) : contact_(contact) {}
- const JID& getContact() const {return contact_;}
- private:
- JID contact_;
- };
+ class RequestWhiteboardUIEvent : public UIEvent {
+ public:
+ RequestWhiteboardUIEvent(const JID& contact) : contact_(contact) {}
+ const JID& getContact() const {return contact_;}
+ private:
+ JID contact_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h b/Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h
index 41eecc4..4d780be 100644
--- a/Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h
+++ b/Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h
@@ -9,6 +9,6 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class RequestXMLConsoleUIEvent : public UIEvent {
- };
+ class RequestXMLConsoleUIEvent : public UIEvent {
+ };
}
diff --git a/Swift/Controllers/UIEvents/SendFileUIEvent.h b/Swift/Controllers/UIEvents/SendFileUIEvent.h
index ea29453..72452df 100644
--- a/Swift/Controllers/UIEvents/SendFileUIEvent.h
+++ b/Swift/Controllers/UIEvents/SendFileUIEvent.h
@@ -19,23 +19,23 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class SendFileUIEvent : public UIEvent {
- public:
- typedef boost::shared_ptr<SendFileUIEvent> ref;
-
- SendFileUIEvent(const JID& jid, const std::string& filename) : jid(jid), filename(filename) {
- }
-
- const JID& getJID() const {
- return jid;
- }
-
- const std::string& getFilename() const {
- return filename;
- }
-
- private:
- JID jid;
- std::string filename;
- };
+ class SendFileUIEvent : public UIEvent {
+ public:
+ typedef boost::shared_ptr<SendFileUIEvent> ref;
+
+ SendFileUIEvent(const JID& jid, const std::string& filename) : jid(jid), filename(filename) {
+ }
+
+ const JID& getJID() const {
+ return jid;
+ }
+
+ const std::string& getFilename() const {
+ return filename;
+ }
+
+ private:
+ JID jid;
+ std::string filename;
+ };
}
diff --git a/Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h b/Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h
index 586f036..88528d7 100644
--- a/Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h
+++ b/Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h
@@ -19,14 +19,14 @@
namespace Swift {
class ShowProfileForRosterItemUIEvent : public UIEvent {
- public:
- typedef boost::shared_ptr<ShowProfileForRosterItemUIEvent> ref;
- public:
- ShowProfileForRosterItemUIEvent(const JID& jid) : jid_(jid) {}
- virtual ~ShowProfileForRosterItemUIEvent() {}
- JID getJID() const {return jid_;}
- private:
- JID jid_;
+ public:
+ typedef boost::shared_ptr<ShowProfileForRosterItemUIEvent> ref;
+ public:
+ ShowProfileForRosterItemUIEvent(const JID& jid) : jid_(jid) {}
+ virtual ~ShowProfileForRosterItemUIEvent() {}
+ JID getJID() const {return jid_;}
+ private:
+ JID jid_;
};
}
diff --git a/Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h b/Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h
index 0d16cb6..a1b6efb 100644
--- a/Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h
+++ b/Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h
@@ -17,12 +17,12 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class ShowWhiteboardUIEvent : public UIEvent {
- public:
- ShowWhiteboardUIEvent(const JID& contact) : contact_(contact) {}
- const JID& getContact() const {return contact_;}
- private:
- JID contact_;
- };
+ class ShowWhiteboardUIEvent : public UIEvent {
+ public:
+ ShowWhiteboardUIEvent(const JID& contact) : contact_(contact) {}
+ const JID& getContact() const {return contact_;}
+ private:
+ JID contact_;
+ };
}
diff --git a/Swift/Controllers/UIEvents/UIEvent.h b/Swift/Controllers/UIEvents/UIEvent.h
index 548f356..333582d 100644
--- a/Swift/Controllers/UIEvents/UIEvent.h
+++ b/Swift/Controllers/UIEvents/UIEvent.h
@@ -9,10 +9,10 @@
#include <boost/shared_ptr.hpp>
namespace Swift {
- class UIEvent {
- public:
- typedef boost::shared_ptr<UIEvent> ref;
+ class UIEvent {
+ public:
+ typedef boost::shared_ptr<UIEvent> ref;
- virtual ~UIEvent();
- };
+ virtual ~UIEvent();
+ };
}
diff --git a/Swift/Controllers/UIEvents/UIEventStream.h b/Swift/Controllers/UIEvents/UIEventStream.h
index a630522..7ff1b54 100644
--- a/Swift/Controllers/UIEvents/UIEventStream.h
+++ b/Swift/Controllers/UIEvents/UIEventStream.h
@@ -13,12 +13,12 @@
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
- class UIEventStream {
- public:
- boost::signal<void (boost::shared_ptr<UIEvent>)> onUIEvent;
+ class UIEventStream {
+ public:
+ boost::signal<void (boost::shared_ptr<UIEvent>)> onUIEvent;
- void send(boost::shared_ptr<UIEvent> event) {
- onUIEvent(event);
- }
- };
+ void send(boost::shared_ptr<UIEvent> event) {
+ onUIEvent(event);
+ }
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h b/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h
index e5d95fa..06d3988 100644
--- a/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h
+++ b/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h
@@ -9,10 +9,10 @@
#include <Swiften/Base/boost_bsignals.h>
namespace Swift {
- class AdHocCommandWindow {
- public:
- virtual ~AdHocCommandWindow() {}
- virtual void setOnline(bool /*online*/) {}
- boost::signal<void ()> onClosing;
- };
+ class AdHocCommandWindow {
+ public:
+ virtual ~AdHocCommandWindow() {}
+ virtual void setOnline(bool /*online*/) {}
+ boost::signal<void ()> onClosing;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h b/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h
index d7b456d..d3003f7 100644
--- a/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h
@@ -12,9 +12,9 @@
namespace Swift {
class AdHocCommandWindow;
- class AdHocCommandWindowFactory {
- public:
- virtual ~AdHocCommandWindowFactory() {}
- virtual AdHocCommandWindow* createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) = 0;
- };
+ class AdHocCommandWindowFactory {
+ public:
+ virtual ~AdHocCommandWindowFactory() {}
+ virtual AdHocCommandWindow* createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h b/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h
index 201377d..ebfa0c4 100644
--- a/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h
+++ b/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h
@@ -19,22 +19,22 @@
namespace Swift {
- class ClientBlockListManager;
+ class ClientBlockListManager;
- class BlockListEditorWidget {
- public:
- virtual ~BlockListEditorWidget() {}
+ class BlockListEditorWidget {
+ public:
+ virtual ~BlockListEditorWidget() {}
- virtual void show() = 0;
- virtual void hide() = 0;
+ virtual void show() = 0;
+ virtual void hide() = 0;
- virtual void setCurrentBlockList(const std::vector<JID>& blockedJIDs) = 0;
- virtual void setBusy(bool isBusy) = 0;
- virtual void setError(const std::string&) = 0;
+ virtual void setCurrentBlockList(const std::vector<JID>& blockedJIDs) = 0;
+ virtual void setBusy(bool isBusy) = 0;
+ virtual void setError(const std::string&) = 0;
- virtual std::vector<JID> getCurrentBlockList() const = 0;
+ virtual std::vector<JID> getCurrentBlockList() const = 0;
- boost::signal<void (const std::vector<JID>& /* blockedJID */)> onSetNewBlockList;
- };
+ boost::signal<void (const std::vector<JID>& /* blockedJID */)> onSetNewBlockList;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/BlockListEditorWidgetFactory.h b/Swift/Controllers/UIInterfaces/BlockListEditorWidgetFactory.h
index eb91ac1..05e7f3a 100644
--- a/Swift/Controllers/UIInterfaces/BlockListEditorWidgetFactory.h
+++ b/Swift/Controllers/UIInterfaces/BlockListEditorWidgetFactory.h
@@ -8,13 +8,13 @@
namespace Swift {
- class BlockListEditorWidget;
+ class BlockListEditorWidget;
- class BlockListEditorWidgetFactory {
- public:
- virtual ~BlockListEditorWidgetFactory() {}
+ class BlockListEditorWidgetFactory {
+ public:
+ virtual ~BlockListEditorWidgetFactory() {}
- virtual BlockListEditorWidget* createBlockListEditorWidget() = 0;
- };
+ virtual BlockListEditorWidget* createBlockListEditorWidget() = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/ChatListWindow.h b/Swift/Controllers/UIInterfaces/ChatListWindow.h
index 8b5036b..a94e14e 100644
--- a/Swift/Controllers/UIInterfaces/ChatListWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatListWindow.h
@@ -19,83 +19,83 @@
#include <Swiften/MUC/MUCBookmark.h>
namespace Swift {
- class ChatListWindow {
- public:
- class Chat {
- public:
- Chat() : statusType(StatusShow::None), isMUC(false), unreadCount(0), isPrivateMessage(false) {}
- Chat(const JID& jid, const std::string& chatName, const std::string& activity, int unreadCount, StatusShow::Type statusType, const boost::filesystem::path& avatarPath, bool isMUC, bool isPrivateMessage = false, const std::string& nick = "", const boost::optional<std::string> password = boost::optional<std::string>())
- : jid(jid), chatName(chatName), activity(activity), statusType(statusType), isMUC(isMUC), nick(nick), password(password), unreadCount(unreadCount), avatarPath(avatarPath), isPrivateMessage(isPrivateMessage) {}
- /** Assume that nicks and other transient features aren't important for equality */
- bool operator==(const Chat& other) const {
- if (impromptuJIDs.empty()) {
- return jid.toBare() == other.jid.toBare()
- && isMUC == other.isMUC;
- } else { /* compare the chat occupant lists */
- typedef std::map<std::string, JID> JIDMap;
- foreach (const JIDMap::value_type& jid, impromptuJIDs) {
- bool found = false;
- foreach (const JIDMap::value_type& otherJID, other.impromptuJIDs) {
- if (jid.second.toBare() == otherJID.second.toBare()) {
- found = true;
- break;
- }
- }
- if (!found) {
- return false;
- }
- }
- return true;
- }
- }
- void setUnreadCount(int unread) {
- unreadCount = unread;
- }
- void setStatusType(StatusShow::Type type) {
- statusType = type;
- }
- void setAvatarPath(const boost::filesystem::path& path) {
- avatarPath = path;
- }
- std::string getImpromptuTitle() const {
- typedef std::pair<std::string, JID> StringJIDPair;
- std::string title;
- foreach(StringJIDPair pair, impromptuJIDs) {
- if (title.empty()) {
- title += pair.first;
- } else {
- title += ", " + pair.first;
- }
- }
- return title;
- }
- JID jid;
- std::string chatName;
- std::string activity;
- StatusShow::Type statusType;
- bool isMUC;
- std::string nick;
- boost::optional<std::string> password;
- int unreadCount;
- boost::filesystem::path avatarPath;
- std::map<std::string, JID> impromptuJIDs;
- bool isPrivateMessage;
- };
- virtual ~ChatListWindow();
+ class ChatListWindow {
+ public:
+ class Chat {
+ public:
+ Chat() : statusType(StatusShow::None), isMUC(false), unreadCount(0), isPrivateMessage(false) {}
+ Chat(const JID& jid, const std::string& chatName, const std::string& activity, int unreadCount, StatusShow::Type statusType, const boost::filesystem::path& avatarPath, bool isMUC, bool isPrivateMessage = false, const std::string& nick = "", const boost::optional<std::string> password = boost::optional<std::string>())
+ : jid(jid), chatName(chatName), activity(activity), statusType(statusType), isMUC(isMUC), nick(nick), password(password), unreadCount(unreadCount), avatarPath(avatarPath), isPrivateMessage(isPrivateMessage) {}
+ /** Assume that nicks and other transient features aren't important for equality */
+ bool operator==(const Chat& other) const {
+ if (impromptuJIDs.empty()) {
+ return jid.toBare() == other.jid.toBare()
+ && isMUC == other.isMUC;
+ } else { /* compare the chat occupant lists */
+ typedef std::map<std::string, JID> JIDMap;
+ foreach (const JIDMap::value_type& jid, impromptuJIDs) {
+ bool found = false;
+ foreach (const JIDMap::value_type& otherJID, other.impromptuJIDs) {
+ if (jid.second.toBare() == otherJID.second.toBare()) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ void setUnreadCount(int unread) {
+ unreadCount = unread;
+ }
+ void setStatusType(StatusShow::Type type) {
+ statusType = type;
+ }
+ void setAvatarPath(const boost::filesystem::path& path) {
+ avatarPath = path;
+ }
+ std::string getImpromptuTitle() const {
+ typedef std::pair<std::string, JID> StringJIDPair;
+ std::string title;
+ foreach(StringJIDPair pair, impromptuJIDs) {
+ if (title.empty()) {
+ title += pair.first;
+ } else {
+ title += ", " + pair.first;
+ }
+ }
+ return title;
+ }
+ JID jid;
+ std::string chatName;
+ std::string activity;
+ StatusShow::Type statusType;
+ bool isMUC;
+ std::string nick;
+ boost::optional<std::string> password;
+ int unreadCount;
+ boost::filesystem::path avatarPath;
+ std::map<std::string, JID> impromptuJIDs;
+ bool isPrivateMessage;
+ };
+ virtual ~ChatListWindow();
- virtual void setBookmarksEnabled(bool enabled) = 0;
- virtual void addMUCBookmark(const MUCBookmark& bookmark) = 0;
- virtual void addWhiteboardSession(const ChatListWindow::Chat& chat) = 0;
- virtual void removeWhiteboardSession(const JID& jid) = 0;
- virtual void removeMUCBookmark(const MUCBookmark& bookmark) = 0;
- virtual void setRecents(const std::list<Chat>& recents) = 0;
- virtual void setUnreadCount(int unread) = 0;
- virtual void clearBookmarks() = 0;
- virtual void setOnline(bool isOnline) = 0;
+ virtual void setBookmarksEnabled(bool enabled) = 0;
+ virtual void addMUCBookmark(const MUCBookmark& bookmark) = 0;
+ virtual void addWhiteboardSession(const ChatListWindow::Chat& chat) = 0;
+ virtual void removeWhiteboardSession(const JID& jid) = 0;
+ virtual void removeMUCBookmark(const MUCBookmark& bookmark) = 0;
+ virtual void setRecents(const std::list<Chat>& recents) = 0;
+ virtual void setUnreadCount(int unread) = 0;
+ virtual void clearBookmarks() = 0;
+ virtual void setOnline(bool isOnline) = 0;
- boost::signal<void (const MUCBookmark&)> onMUCBookmarkActivated;
- boost::signal<void (const Chat&)> onRecentActivated;
- boost::signal<void (const JID&)> onWhiteboardActivated;
- boost::signal<void ()> onClearRecentsRequested;
- };
+ boost::signal<void (const MUCBookmark&)> onMUCBookmarkActivated;
+ boost::signal<void (const Chat&)> onRecentActivated;
+ boost::signal<void (const JID&)> onWhiteboardActivated;
+ boost::signal<void ()> onClearRecentsRequested;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/ChatListWindowFactory.h b/Swift/Controllers/UIInterfaces/ChatListWindowFactory.h
index fcd979b..3ae1ec6 100644
--- a/Swift/Controllers/UIInterfaces/ChatListWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/ChatListWindowFactory.h
@@ -9,10 +9,10 @@
#include <Swift/Controllers/UIInterfaces/ChatListWindow.h>
namespace Swift {
- class UIEventStream;
- class ChatListWindowFactory {
- public:
- virtual ~ChatListWindowFactory() {}
- virtual ChatListWindow* createChatListWindow(UIEventStream* uiEventStream) = 0;
- };
+ class UIEventStream;
+ class ChatListWindowFactory {
+ public:
+ virtual ~ChatListWindowFactory() {}
+ virtual ChatListWindow* createChatListWindow(UIEventStream* uiEventStream) = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h
index 05331bb..310c967 100644
--- a/Swift/Controllers/UIInterfaces/ChatWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatWindow.h
@@ -26,233 +26,233 @@
#include <Swift/Controllers/HighlightManager.h>
namespace Swift {
- class AvatarManager;
- class TreeWidget;
- class Roster;
- class TabComplete;
- class RosterItem;
- class ContactRosterItem;
- class FileTransferController;
- class UserSearchWindow;
-
-
- class ChatWindow {
- public:
- class ChatMessagePart {
- public:
- virtual ~ChatMessagePart() {}
- };
-
- class ChatMessage {
- public:
- ChatMessage() {}
- ChatMessage(const std::string& text) {
- append(boost::make_shared<ChatTextMessagePart>(text));
- }
- void append(const boost::shared_ptr<ChatMessagePart>& part) {
- parts_.push_back(part);
- }
-
- const std::vector<boost::shared_ptr<ChatMessagePart> >& getParts() const {
- return parts_;
- }
-
- void setFullMessageHighlightAction(const HighlightAction& action) {
- fullMessageHighlightAction_ = action;
- }
-
- const HighlightAction& getFullMessageHighlightAction() const {
- return fullMessageHighlightAction_;
- }
-
- bool isMeCommand() const {
- bool isMeCommand = false;
- if (!parts_.empty()) {
- boost::shared_ptr<ChatTextMessagePart> textPart = boost::dynamic_pointer_cast<ChatTextMessagePart>(parts_[0]);
- if (textPart) {
- if (boost::starts_with(textPart->text, "/me ")) {
- isMeCommand = true;
- }
- }
- }
- return isMeCommand;
- }
-
- private:
- std::vector<boost::shared_ptr<ChatMessagePart> > parts_;
- HighlightAction fullMessageHighlightAction_;
- };
-
- class ChatTextMessagePart : public ChatMessagePart {
- public:
- ChatTextMessagePart(const std::string& text) : text(text) {}
- std::string text;
- };
-
- class ChatURIMessagePart : public ChatMessagePart {
- public:
- ChatURIMessagePart(const std::string& target) : target(target) {}
- std::string target;
- };
-
- class ChatEmoticonMessagePart : public ChatMessagePart {
- public:
- std::string imagePath;
- std::string alternativeText;
- };
-
- class ChatHighlightingMessagePart : public ChatMessagePart {
- public:
- HighlightAction action;
- std::string text;
- };
-
-
- enum AckState {Pending, Received, Failed};
- enum ReceiptState {ReceiptRequested, ReceiptReceived, ReceiptFailed};
- enum OccupantAction {Kick, Ban, MakeModerator, MakeParticipant, MakeVisitor, AddContact, ShowProfile};
- enum RoomAction {ChangeSubject, Configure, Affiliations, Destroy, Invite};
- enum FileTransferState {
- Initialisation, ///< Collecting information required for sending the request out.
- WaitingForAccept, ///< The file transfer request was send out.
- Negotiating, ///< The other party accepted the file transfer request and a suitable transfer method is negotiated.
- Transferring, ///< The negotiation was successful and the file is currently transferred.
- Canceled, ///< Someone actively canceled the transfer.
- Finished, ///< The file was transferred successfully.
- FTFailed ///< The negotiation, the transfer itself or the verification failed.
- };
- enum WhiteboardSessionState {WhiteboardAccepted, WhiteboardTerminated, WhiteboardRejected};
- enum BlockingState {BlockingUnsupported, IsBlocked, IsUnblocked};
- enum Direction { UnknownDirection, DefaultDirection };
- enum MUCType { StandardMUC, ImpromptuMUC };
- enum TimestampBehaviour { KeepTimestamp, UpdateTimestamp };
- enum RoomBookmarkState { RoomNotBookmarked, RoomBookmarked, RoomAutoJoined };
-
- ChatWindow() {}
- virtual ~ChatWindow() {}
-
- /** Add message to window.
- * @return id of added message (for acks).
- */
- virtual std::string addMessage(const ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0;
- /** Adds action to window.
- * @return id of added message (for acks);
- */
- virtual std::string addAction(const ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0;
-
- /** Adds system message to window
- * @return id of added message (for replacement)
- */
- virtual std::string addSystemMessage(const ChatMessage& message, Direction direction) = 0;
- virtual void addPresenceMessage(const ChatMessage& message, Direction direction) = 0;
-
- virtual void addErrorMessage(const ChatMessage& message) = 0;
- virtual void replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) = 0;
- virtual void replaceSystemMessage(const ChatMessage& message, const std::string& id, const TimestampBehaviour timestampBehaviour) = 0;
- virtual void replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) = 0;
-
- // File transfer related stuff
- virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) = 0;
- virtual void setFileTransferProgress(std::string, const int percentageDone) = 0;
- virtual void setFileTransferStatus(std::string, const FileTransferState state, const std::string& msg = "") = 0;
- virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct = true, bool isImpromptu = false, bool isContinuation = false) = 0;
-
- virtual std::string addWhiteboardRequest(bool senderIsSelf) = 0;
- virtual void setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state) = 0;
-
- // message receipts
- virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) = 0;
-
- virtual void setContactChatState(ChatState::ChatStateType state) = 0;
- virtual void setName(const std::string& name) = 0;
- virtual void show() = 0;
- virtual bool isVisible() const = 0;
- virtual void activate() = 0;
- virtual void setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels) = 0;
- virtual void setSecurityLabelsEnabled(bool enabled) = 0;
- virtual void setCorrectionEnabled(Tristate enabled) = 0;
- virtual void setFileTransferEnabled(Tristate enabled) = 0;
- virtual void setUnreadMessageCount(int count) = 0;
- virtual void convertToMUC(MUCType mucType) = 0;
-// virtual TreeWidget *getTreeWidget() = 0;
- virtual void setSecurityLabelsError() = 0;
- virtual SecurityLabelsCatalog::Item getSelectedSecurityLabel() = 0;
- virtual void setOnline(bool online) = 0;
- virtual void setRosterModel(Roster* model) = 0;
- virtual void setTabComplete(TabComplete* completer) = 0;
- virtual void replaceLastMessage(const ChatMessage& message, const TimestampBehaviour timestampBehaviour) = 0;
- virtual void setAckState(const std::string& id, AckState state) = 0;
- virtual void flash() = 0;
- virtual void setSubject(const std::string& subject) = 0;
- virtual void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>&) = 0;
- virtual void setAvailableRoomActions(const std::vector<RoomAction> &actions) = 0;
- virtual void setBlockingState(BlockingState state) = 0;
- virtual void setCanInitiateImpromptuChats(bool supportsImpromptu) = 0;
- virtual void showBookmarkWindow(const MUCBookmark& bookmark) = 0;
- virtual void setBookmarkState(RoomBookmarkState bookmarkState) = 0;
-
- /**
- * A handle that uniquely identities an alert message.
- */
- typedef int AlertID;
- /**
- * Set an alert on the window.
- * @param alertText Description of alert (required).
- * @param buttonText Button text to use (optional, no button is shown if empty).
- * @return A handle to the alert message.
- */
- virtual AlertID addAlert(const std::string& alertText) = 0;
- /**
- * Removes an alert.
- * @param id An alert ID previously returned from setAlert
- */
- virtual void removeAlert(const AlertID id) = 0;
-
- /**
- * Actions that can be performed on the selected occupant.
- */
- virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions) = 0;
-
- /**
- * A room configuration has been requested, show the form.
- * If the form is cancelled, must emit onConfigurationFormCancelled().
- */
- virtual void showRoomConfigurationForm(Form::ref) = 0;
-
- boost::signal<void ()> onClosed;
- boost::signal<void ()> onAllMessagesRead;
- boost::signal<void (const std::string&, bool isCorrection)> onSendMessageRequest;
- boost::signal<void ()> onSendCorrectionMessageRequest;
- boost::signal<void ()> onUserTyping;
- boost::signal<void ()> onUserCancelsTyping;
- boost::signal<void ()> onAlertButtonClicked;
- boost::signal<void (ContactRosterItem*)> onOccupantSelectionChanged;
- boost::signal<void (ChatWindow::OccupantAction, ContactRosterItem*)> onOccupantActionSelected;
- boost::signal<void (const std::string&)> onChangeSubjectRequest;
- boost::signal<void ()> onBookmarkRequest;
- boost::signal<void (Form::ref)> onConfigureRequest;
- boost::signal<void ()> onDestroyRequest;
- boost::signal<void (const std::vector<JID>&)> onInviteToChat;
- boost::signal<void ()> onConfigurationFormCancelled;
- boost::signal<void ()> onGetAffiliationsRequest;
- boost::signal<void (MUCOccupant::Affiliation, const JID&)> onSetAffiliationRequest;
- boost::signal<void (const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& changes)> onChangeAffiliationsRequest;
- boost::signal<void ()> onLogCleared;
-
- // File transfer related
- boost::signal<void (std::string /* id */)> onFileTransferCancel;
- boost::signal<void (std::string /* id */, std::string /* description */)> onFileTransferStart;
- boost::signal<void (std::string /* id */, std::string /* path */)> onFileTransferAccept;
- boost::signal<void (std::string /* path */)> onSendFileRequest;
-
- //Whiteboard related
- boost::signal<void ()> onWhiteboardSessionAccept;
- boost::signal<void ()> onWhiteboardSessionCancel;
- boost::signal<void ()> onWhiteboardWindowShow;
-
- // Blocking Command related
- boost::signal<void ()> onBlockUserRequest;
- boost::signal<void ()> onUnblockUserRequest;
- };
+ class AvatarManager;
+ class TreeWidget;
+ class Roster;
+ class TabComplete;
+ class RosterItem;
+ class ContactRosterItem;
+ class FileTransferController;
+ class UserSearchWindow;
+
+
+ class ChatWindow {
+ public:
+ class ChatMessagePart {
+ public:
+ virtual ~ChatMessagePart() {}
+ };
+
+ class ChatMessage {
+ public:
+ ChatMessage() {}
+ ChatMessage(const std::string& text) {
+ append(boost::make_shared<ChatTextMessagePart>(text));
+ }
+ void append(const boost::shared_ptr<ChatMessagePart>& part) {
+ parts_.push_back(part);
+ }
+
+ const std::vector<boost::shared_ptr<ChatMessagePart> >& getParts() const {
+ return parts_;
+ }
+
+ void setFullMessageHighlightAction(const HighlightAction& action) {
+ fullMessageHighlightAction_ = action;
+ }
+
+ const HighlightAction& getFullMessageHighlightAction() const {
+ return fullMessageHighlightAction_;
+ }
+
+ bool isMeCommand() const {
+ bool isMeCommand = false;
+ if (!parts_.empty()) {
+ boost::shared_ptr<ChatTextMessagePart> textPart = boost::dynamic_pointer_cast<ChatTextMessagePart>(parts_[0]);
+ if (textPart) {
+ if (boost::starts_with(textPart->text, "/me ")) {
+ isMeCommand = true;
+ }
+ }
+ }
+ return isMeCommand;
+ }
+
+ private:
+ std::vector<boost::shared_ptr<ChatMessagePart> > parts_;
+ HighlightAction fullMessageHighlightAction_;
+ };
+
+ class ChatTextMessagePart : public ChatMessagePart {
+ public:
+ ChatTextMessagePart(const std::string& text) : text(text) {}
+ std::string text;
+ };
+
+ class ChatURIMessagePart : public ChatMessagePart {
+ public:
+ ChatURIMessagePart(const std::string& target) : target(target) {}
+ std::string target;
+ };
+
+ class ChatEmoticonMessagePart : public ChatMessagePart {
+ public:
+ std::string imagePath;
+ std::string alternativeText;
+ };
+
+ class ChatHighlightingMessagePart : public ChatMessagePart {
+ public:
+ HighlightAction action;
+ std::string text;
+ };
+
+
+ enum AckState {Pending, Received, Failed};
+ enum ReceiptState {ReceiptRequested, ReceiptReceived, ReceiptFailed};
+ enum OccupantAction {Kick, Ban, MakeModerator, MakeParticipant, MakeVisitor, AddContact, ShowProfile};
+ enum RoomAction {ChangeSubject, Configure, Affiliations, Destroy, Invite};
+ enum FileTransferState {
+ Initialisation, ///< Collecting information required for sending the request out.
+ WaitingForAccept, ///< The file transfer request was send out.
+ Negotiating, ///< The other party accepted the file transfer request and a suitable transfer method is negotiated.
+ Transferring, ///< The negotiation was successful and the file is currently transferred.
+ Canceled, ///< Someone actively canceled the transfer.
+ Finished, ///< The file was transferred successfully.
+ FTFailed ///< The negotiation, the transfer itself or the verification failed.
+ };
+ enum WhiteboardSessionState {WhiteboardAccepted, WhiteboardTerminated, WhiteboardRejected};
+ enum BlockingState {BlockingUnsupported, IsBlocked, IsUnblocked};
+ enum Direction { UnknownDirection, DefaultDirection };
+ enum MUCType { StandardMUC, ImpromptuMUC };
+ enum TimestampBehaviour { KeepTimestamp, UpdateTimestamp };
+ enum RoomBookmarkState { RoomNotBookmarked, RoomBookmarked, RoomAutoJoined };
+
+ ChatWindow() {}
+ virtual ~ChatWindow() {}
+
+ /** Add message to window.
+ * @return id of added message (for acks).
+ */
+ virtual std::string addMessage(const ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0;
+ /** Adds action to window.
+ * @return id of added message (for acks);
+ */
+ virtual std::string addAction(const ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0;
+
+ /** Adds system message to window
+ * @return id of added message (for replacement)
+ */
+ virtual std::string addSystemMessage(const ChatMessage& message, Direction direction) = 0;
+ virtual void addPresenceMessage(const ChatMessage& message, Direction direction) = 0;
+
+ virtual void addErrorMessage(const ChatMessage& message) = 0;
+ virtual void replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) = 0;
+ virtual void replaceSystemMessage(const ChatMessage& message, const std::string& id, const TimestampBehaviour timestampBehaviour) = 0;
+ virtual void replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) = 0;
+
+ // File transfer related stuff
+ virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) = 0;
+ virtual void setFileTransferProgress(std::string, const int percentageDone) = 0;
+ virtual void setFileTransferStatus(std::string, const FileTransferState state, const std::string& msg = "") = 0;
+ virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct = true, bool isImpromptu = false, bool isContinuation = false) = 0;
+
+ virtual std::string addWhiteboardRequest(bool senderIsSelf) = 0;
+ virtual void setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state) = 0;
+
+ // message receipts
+ virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) = 0;
+
+ virtual void setContactChatState(ChatState::ChatStateType state) = 0;
+ virtual void setName(const std::string& name) = 0;
+ virtual void show() = 0;
+ virtual bool isVisible() const = 0;
+ virtual void activate() = 0;
+ virtual void setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels) = 0;
+ virtual void setSecurityLabelsEnabled(bool enabled) = 0;
+ virtual void setCorrectionEnabled(Tristate enabled) = 0;
+ virtual void setFileTransferEnabled(Tristate enabled) = 0;
+ virtual void setUnreadMessageCount(int count) = 0;
+ virtual void convertToMUC(MUCType mucType) = 0;
+// virtual TreeWidget *getTreeWidget() = 0;
+ virtual void setSecurityLabelsError() = 0;
+ virtual SecurityLabelsCatalog::Item getSelectedSecurityLabel() = 0;
+ virtual void setOnline(bool online) = 0;
+ virtual void setRosterModel(Roster* model) = 0;
+ virtual void setTabComplete(TabComplete* completer) = 0;
+ virtual void replaceLastMessage(const ChatMessage& message, const TimestampBehaviour timestampBehaviour) = 0;
+ virtual void setAckState(const std::string& id, AckState state) = 0;
+ virtual void flash() = 0;
+ virtual void setSubject(const std::string& subject) = 0;
+ virtual void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>&) = 0;
+ virtual void setAvailableRoomActions(const std::vector<RoomAction> &actions) = 0;
+ virtual void setBlockingState(BlockingState state) = 0;
+ virtual void setCanInitiateImpromptuChats(bool supportsImpromptu) = 0;
+ virtual void showBookmarkWindow(const MUCBookmark& bookmark) = 0;
+ virtual void setBookmarkState(RoomBookmarkState bookmarkState) = 0;
+
+ /**
+ * A handle that uniquely identities an alert message.
+ */
+ typedef int AlertID;
+ /**
+ * Set an alert on the window.
+ * @param alertText Description of alert (required).
+ * @param buttonText Button text to use (optional, no button is shown if empty).
+ * @return A handle to the alert message.
+ */
+ virtual AlertID addAlert(const std::string& alertText) = 0;
+ /**
+ * Removes an alert.
+ * @param id An alert ID previously returned from setAlert
+ */
+ virtual void removeAlert(const AlertID id) = 0;
+
+ /**
+ * Actions that can be performed on the selected occupant.
+ */
+ virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions) = 0;
+
+ /**
+ * A room configuration has been requested, show the form.
+ * If the form is cancelled, must emit onConfigurationFormCancelled().
+ */
+ virtual void showRoomConfigurationForm(Form::ref) = 0;
+
+ boost::signal<void ()> onClosed;
+ boost::signal<void ()> onAllMessagesRead;
+ boost::signal<void (const std::string&, bool isCorrection)> onSendMessageRequest;
+ boost::signal<void ()> onSendCorrectionMessageRequest;
+ boost::signal<void ()> onUserTyping;
+ boost::signal<void ()> onUserCancelsTyping;
+ boost::signal<void ()> onAlertButtonClicked;
+ boost::signal<void (ContactRosterItem*)> onOccupantSelectionChanged;
+ boost::signal<void (ChatWindow::OccupantAction, ContactRosterItem*)> onOccupantActionSelected;
+ boost::signal<void (const std::string&)> onChangeSubjectRequest;
+ boost::signal<void ()> onBookmarkRequest;
+ boost::signal<void (Form::ref)> onConfigureRequest;
+ boost::signal<void ()> onDestroyRequest;
+ boost::signal<void (const std::vector<JID>&)> onInviteToChat;
+ boost::signal<void ()> onConfigurationFormCancelled;
+ boost::signal<void ()> onGetAffiliationsRequest;
+ boost::signal<void (MUCOccupant::Affiliation, const JID&)> onSetAffiliationRequest;
+ boost::signal<void (const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& changes)> onChangeAffiliationsRequest;
+ boost::signal<void ()> onLogCleared;
+
+ // File transfer related
+ boost::signal<void (std::string /* id */)> onFileTransferCancel;
+ boost::signal<void (std::string /* id */, std::string /* description */)> onFileTransferStart;
+ boost::signal<void (std::string /* id */, std::string /* path */)> onFileTransferAccept;
+ boost::signal<void (std::string /* path */)> onSendFileRequest;
+
+ //Whiteboard related
+ boost::signal<void ()> onWhiteboardSessionAccept;
+ boost::signal<void ()> onWhiteboardSessionCancel;
+ boost::signal<void ()> onWhiteboardWindowShow;
+
+ // Blocking Command related
+ boost::signal<void ()> onBlockUserRequest;
+ boost::signal<void ()> onUnblockUserRequest;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/ChatWindowFactory.h b/Swift/Controllers/UIInterfaces/ChatWindowFactory.h
index 7c47e2a..38706ab 100644
--- a/Swift/Controllers/UIInterfaces/ChatWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/ChatWindowFactory.h
@@ -10,17 +10,17 @@
#include "Swiften/JID/JID.h"
namespace Swift {
- class ChatWindow;
- class UIEventStream;
- class ChatWindowFactory {
- public:
- virtual ~ChatWindowFactory() {}
- /**
- * Transfers ownership of result.
- */
- virtual ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream) = 0;
+ class ChatWindow;
+ class UIEventStream;
+ class ChatWindowFactory {
+ public:
+ virtual ~ChatWindowFactory() {}
+ /**
+ * Transfers ownership of result.
+ */
+ virtual ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream) = 0;
- };
+ };
}
#endif
diff --git a/Swift/Controllers/UIInterfaces/ContactEditWindow.h b/Swift/Controllers/UIInterfaces/ContactEditWindow.h
index 407959a..055c0f0 100644
--- a/Swift/Controllers/UIInterfaces/ContactEditWindow.h
+++ b/Swift/Controllers/UIInterfaces/ContactEditWindow.h
@@ -15,22 +15,22 @@
#include <Swiften/Base/boost_bsignals.h>
namespace Swift {
- class JID;
- class VCardManager;
+ class JID;
+ class VCardManager;
- class ContactEditWindow {
- public:
- virtual ~ContactEditWindow() {}
+ class ContactEditWindow {
+ public:
+ virtual ~ContactEditWindow() {}
- virtual void setEnabled(bool b) = 0;
+ virtual void setEnabled(bool b) = 0;
- virtual void setNameSuggestions(const std::vector<std::string>& suggestions) = 0;
- virtual void setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups) = 0;
+ virtual void setNameSuggestions(const std::vector<std::string>& suggestions) = 0;
+ virtual void setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups) = 0;
- virtual void show() = 0;
- virtual void hide() = 0;
+ virtual void show() = 0;
+ virtual void hide() = 0;
- boost::signal<void ()> onRemoveContactRequest;
- boost::signal<void (const std::string& /* name */, const std::set<std::string>& /* groups */)> onChangeContactRequest;
- };
+ boost::signal<void ()> onRemoveContactRequest;
+ boost::signal<void (const std::string& /* name */, const std::set<std::string>& /* groups */)> onChangeContactRequest;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h b/Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h
index 6955a69..f5a84d5 100644
--- a/Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h
@@ -9,10 +9,10 @@
#include <Swift/Controllers/UIInterfaces/ContactEditWindow.h>
namespace Swift {
- class ContactEditWindowFactory {
- public:
- virtual ~ContactEditWindowFactory() {}
+ class ContactEditWindowFactory {
+ public:
+ virtual ~ContactEditWindowFactory() {}
- virtual ContactEditWindow* createContactEditWindow() = 0;
- };
+ virtual ContactEditWindow* createContactEditWindow() = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/EventWindow.h b/Swift/Controllers/UIInterfaces/EventWindow.h
index 5ce99d8..1d254f4 100644
--- a/Swift/Controllers/UIInterfaces/EventWindow.h
+++ b/Swift/Controllers/UIInterfaces/EventWindow.h
@@ -11,19 +11,19 @@
#include <Swift/Controllers/XMPPEvents/StanzaEvent.h>
namespace Swift {
- class EventWindow {
- public:
- EventWindow(bool candelete = true) : canDelete_(candelete) {}
+ class EventWindow {
+ public:
+ EventWindow(bool candelete = true) : canDelete_(candelete) {}
- bool canDelete() const {
- return canDelete_;
- }
+ bool canDelete() const {
+ return canDelete_;
+ }
- virtual ~EventWindow() {}
- virtual void addEvent(boost::shared_ptr<StanzaEvent> event, bool active) = 0;
- virtual void removeEvent(boost::shared_ptr<StanzaEvent> event) = 0;
+ virtual ~EventWindow() {}
+ virtual void addEvent(boost::shared_ptr<StanzaEvent> event, bool active) = 0;
+ virtual void removeEvent(boost::shared_ptr<StanzaEvent> event) = 0;
- private:
- bool canDelete_;
- };
+ private:
+ bool canDelete_;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/EventWindowFactory.h b/Swift/Controllers/UIInterfaces/EventWindowFactory.h
index 7c9c87d..76638da 100644
--- a/Swift/Controllers/UIInterfaces/EventWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/EventWindowFactory.h
@@ -7,17 +7,17 @@
#pragma once
namespace Swift {
- class EventWindow;
+ class EventWindow;
- class EventWindowFactory {
- public:
- virtual ~EventWindowFactory() {}
- /**
- * Transfers ownership of result.
- */
- virtual EventWindow* createEventWindow() = 0;
+ class EventWindowFactory {
+ public:
+ virtual ~EventWindowFactory() {}
+ /**
+ * Transfers ownership of result.
+ */
+ virtual EventWindow* createEventWindow() = 0;
- };
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/FileTransferListWidget.h b/Swift/Controllers/UIInterfaces/FileTransferListWidget.h
index 01dcfd3..5a9eaeb 100644
--- a/Swift/Controllers/UIInterfaces/FileTransferListWidget.h
+++ b/Swift/Controllers/UIInterfaces/FileTransferListWidget.h
@@ -12,12 +12,12 @@ class FileTransferOverview;
class FileTransferListWidget {
public:
- virtual ~FileTransferListWidget() {}
+ virtual ~FileTransferListWidget() {}
- virtual void show() = 0;
- virtual void activate() = 0;
+ virtual void show() = 0;
+ virtual void activate() = 0;
- virtual void setFileTransferOverview(FileTransferOverview*) = 0;
+ virtual void setFileTransferOverview(FileTransferOverview*) = 0;
};
}
diff --git a/Swift/Controllers/UIInterfaces/FileTransferListWidgetFactory.h b/Swift/Controllers/UIInterfaces/FileTransferListWidgetFactory.h
index 6da2d07..da9fd37 100644
--- a/Swift/Controllers/UIInterfaces/FileTransferListWidgetFactory.h
+++ b/Swift/Controllers/UIInterfaces/FileTransferListWidgetFactory.h
@@ -18,9 +18,9 @@ namespace Swift {
class FileTransferListWidgetFactory {
public:
- virtual ~FileTransferListWidgetFactory() {}
+ virtual ~FileTransferListWidgetFactory() {}
- virtual FileTransferListWidget* createFileTransferListWidget() = 0;
+ virtual FileTransferListWidget* createFileTransferListWidget() = 0;
};
}
diff --git a/Swift/Controllers/UIInterfaces/HighlightEditorWidget.h b/Swift/Controllers/UIInterfaces/HighlightEditorWidget.h
index 4745035..ff888e6 100644
--- a/Swift/Controllers/UIInterfaces/HighlightEditorWidget.h
+++ b/Swift/Controllers/UIInterfaces/HighlightEditorWidget.h
@@ -8,15 +8,15 @@
namespace Swift {
- class HighlightManager;
+ class HighlightManager;
- class HighlightEditorWidget {
- public:
- virtual ~HighlightEditorWidget() {}
+ class HighlightEditorWidget {
+ public:
+ virtual ~HighlightEditorWidget() {}
- virtual void show() = 0;
+ virtual void show() = 0;
- virtual void setHighlightManager(HighlightManager* highlightManager) = 0;
- };
+ virtual void setHighlightManager(HighlightManager* highlightManager) = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/HighlightEditorWidgetFactory.h b/Swift/Controllers/UIInterfaces/HighlightEditorWidgetFactory.h
index ade575b..363e666 100644
--- a/Swift/Controllers/UIInterfaces/HighlightEditorWidgetFactory.h
+++ b/Swift/Controllers/UIInterfaces/HighlightEditorWidgetFactory.h
@@ -8,13 +8,13 @@
namespace Swift {
- class HighlightEditorWidget;
+ class HighlightEditorWidget;
- class HighlightEditorWidgetFactory {
- public:
- virtual ~HighlightEditorWidgetFactory() {}
+ class HighlightEditorWidgetFactory {
+ public:
+ virtual ~HighlightEditorWidgetFactory() {}
- virtual HighlightEditorWidget* createHighlightEditorWidget() = 0;
- };
+ virtual HighlightEditorWidget* createHighlightEditorWidget() = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/HighlightEditorWindow.h b/Swift/Controllers/UIInterfaces/HighlightEditorWindow.h
index 12adb3d..8cca4f9 100644
--- a/Swift/Controllers/UIInterfaces/HighlightEditorWindow.h
+++ b/Swift/Controllers/UIInterfaces/HighlightEditorWindow.h
@@ -14,14 +14,14 @@ class HighlightManager;
class HighlightEditorWindow {
public:
- HighlightEditorWindow();
- virtual ~HighlightEditorWindow();
- virtual void show() = 0;
- virtual void setHighlightManager(HighlightManager *highlightManager) = 0;
- virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions) = 0;
+ HighlightEditorWindow();
+ virtual ~HighlightEditorWindow();
+ virtual void show() = 0;
+ virtual void setHighlightManager(HighlightManager *highlightManager) = 0;
+ virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions) = 0;
public:
- boost::signal<void (const std::string&)> onContactSuggestionsRequested;
+ boost::signal<void (const std::string&)> onContactSuggestionsRequested;
};
}
diff --git a/Swift/Controllers/UIInterfaces/HighlightEditorWindowFactory.h b/Swift/Controllers/UIInterfaces/HighlightEditorWindowFactory.h
index 18fbeb7..ea05425 100644
--- a/Swift/Controllers/UIInterfaces/HighlightEditorWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/HighlightEditorWindowFactory.h
@@ -13,12 +13,12 @@
#pragma once
namespace Swift {
- class HighlightEditorWindow;
+ class HighlightEditorWindow;
- class HighlightEditorWindowFactory {
- public :
- virtual ~HighlightEditorWindowFactory() {}
+ class HighlightEditorWindowFactory {
+ public :
+ virtual ~HighlightEditorWindowFactory() {}
- virtual HighlightEditorWindow* createHighlightEditorWindow() = 0;
- };
+ virtual HighlightEditorWindow* createHighlightEditorWindow() = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/HistoryWindow.h b/Swift/Controllers/UIInterfaces/HistoryWindow.h
index 6d50f4b..db1a4b1 100644
--- a/Swift/Controllers/UIInterfaces/HistoryWindow.h
+++ b/Swift/Controllers/UIInterfaces/HistoryWindow.h
@@ -9,26 +9,26 @@
#include <Swift/Controllers/Roster/Roster.h>
namespace Swift {
- class HistoryWindow {
- public:
- virtual ~HistoryWindow() {}
+ class HistoryWindow {
+ public:
+ virtual ~HistoryWindow() {}
- virtual void activate() = 0;
- virtual void setRosterModel(Roster*) = 0;
- virtual void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop) = 0;
- virtual void resetConversationView() = 0;
- virtual void resetConversationViewTopInsertPoint() = 0; // this is a temporary fix used in adding messages at the top
- virtual void setDate(const boost::gregorian::date& date) = 0;
+ virtual void activate() = 0;
+ virtual void setRosterModel(Roster*) = 0;
+ virtual void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop) = 0;
+ virtual void resetConversationView() = 0;
+ virtual void resetConversationViewTopInsertPoint() = 0; // this is a temporary fix used in adding messages at the top
+ virtual void setDate(const boost::gregorian::date& date) = 0;
- virtual std::string getSearchBoxText() = 0;
- virtual boost::gregorian::date getLastVisibleDate() = 0;
+ virtual std::string getSearchBoxText() = 0;
+ virtual boost::gregorian::date getLastVisibleDate() = 0;
- boost::signal<void (RosterItem*)> onSelectedContactChanged;
- boost::signal<void (const std::string&)> onReturnPressed;
- boost::signal<void (const boost::gregorian::date&)> onScrollReachedTop;
- boost::signal<void (const boost::gregorian::date&)> onScrollReachedBottom;
- boost::signal<void ()> onPreviousButtonClicked;
- boost::signal<void ()> onNextButtonClicked;
- boost::signal<void (const boost::gregorian::date&)> onCalendarClicked;
- };
+ boost::signal<void (RosterItem*)> onSelectedContactChanged;
+ boost::signal<void (const std::string&)> onReturnPressed;
+ boost::signal<void (const boost::gregorian::date&)> onScrollReachedTop;
+ boost::signal<void (const boost::gregorian::date&)> onScrollReachedBottom;
+ boost::signal<void ()> onPreviousButtonClicked;
+ boost::signal<void ()> onNextButtonClicked;
+ boost::signal<void (const boost::gregorian::date&)> onCalendarClicked;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/HistoryWindowFactory.h b/Swift/Controllers/UIInterfaces/HistoryWindowFactory.h
index 807fec5..ab4cf0d 100644
--- a/Swift/Controllers/UIInterfaces/HistoryWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/HistoryWindowFactory.h
@@ -9,10 +9,10 @@
#include <Swift/Controllers/UIInterfaces/HistoryWindow.h>
namespace Swift {
- class UIEventStream;
- class HistoryWindowFactory {
- public:
- virtual ~HistoryWindowFactory() {}
- virtual HistoryWindow* createHistoryWindow(UIEventStream* eventStream) = 0;
- };
+ class UIEventStream;
+ class HistoryWindowFactory {
+ public:
+ virtual ~HistoryWindowFactory() {}
+ virtual HistoryWindow* createHistoryWindow(UIEventStream* eventStream) = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/JoinMUCWindow.h b/Swift/Controllers/UIInterfaces/JoinMUCWindow.h
index 62818c5..4d6cea1 100644
--- a/Swift/Controllers/UIInterfaces/JoinMUCWindow.h
+++ b/Swift/Controllers/UIInterfaces/JoinMUCWindow.h
@@ -13,14 +13,14 @@
#include <Swiften/JID/JID.h>
namespace Swift {
- class JoinMUCWindow {
- public:
- virtual ~JoinMUCWindow() {}
+ class JoinMUCWindow {
+ public:
+ virtual ~JoinMUCWindow() {}
- virtual void setNick(const std::string& nick) = 0;
- virtual void setMUC(const std::string& nick) = 0;
- virtual void show() = 0;
+ virtual void setNick(const std::string& nick) = 0;
+ virtual void setMUC(const std::string& nick) = 0;
+ virtual void show() = 0;
- boost::signal<void ()> onSearchMUC;
- };
+ boost::signal<void ()> onSearchMUC;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/JoinMUCWindowFactory.h b/Swift/Controllers/UIInterfaces/JoinMUCWindowFactory.h
index a711294..5e8b1d0 100644
--- a/Swift/Controllers/UIInterfaces/JoinMUCWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/JoinMUCWindowFactory.h
@@ -9,11 +9,11 @@
#include <Swift/Controllers/UIInterfaces/JoinMUCWindow.h>
namespace Swift {
- class UIEventStream;
- class JoinMUCWindowFactory {
- public:
- virtual ~JoinMUCWindowFactory() {}
+ class UIEventStream;
+ class JoinMUCWindowFactory {
+ public:
+ virtual ~JoinMUCWindowFactory() {}
- virtual JoinMUCWindow* createJoinMUCWindow(UIEventStream* uiEventStream) = 0;
- };
+ virtual JoinMUCWindow* createJoinMUCWindow(UIEventStream* uiEventStream) = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/LoginWindow.h b/Swift/Controllers/UIInterfaces/LoginWindow.h
index 5a7e178..cedc549 100644
--- a/Swift/Controllers/UIInterfaces/LoginWindow.h
+++ b/Swift/Controllers/UIInterfaces/LoginWindow.h
@@ -16,27 +16,27 @@
#include <Swiften/TLS/CertificateWithKey.h>
namespace Swift {
- class MainWindow;
- class LoginWindow {
- public:
- virtual ~LoginWindow() {}
- virtual void selectUser(const std::string&) = 0;
- virtual void morphInto(MainWindow *mainWindow) = 0;
- virtual void loggedOut() = 0;
- virtual void setShowNotificationToggle(bool) = 0;
- virtual void setMessage(const std::string&) = 0;
- virtual void setIsLoggingIn(bool loggingIn) = 0;
- virtual void addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate, const ClientOptions& options) = 0;
- virtual void removeAvailableAccount(const std::string& jid) = 0;
- /** The certificate is what is used for login, the certificatePath is used for remembering paths to populate the loginwindow with*/
- boost::signal<void (const std::string&, const std::string&, const std::string& /*CertificatePath*/, CertificateWithKey::ref /* clientCertificate */, const ClientOptions& /*options*/, bool /* remember password*/, bool /* login automatically */)> onLoginRequest;
- virtual void setLoginAutomatically(bool loginAutomatically) = 0;
- virtual void quit() = 0;
- /** Blocking request whether a cert should be permanently trusted.*/
- virtual bool askUserToTrustCertificatePermanently(const std::string& message, const std::vector<Certificate::ref>& certificateChain) = 0;
+ class MainWindow;
+ class LoginWindow {
+ public:
+ virtual ~LoginWindow() {}
+ virtual void selectUser(const std::string&) = 0;
+ virtual void morphInto(MainWindow *mainWindow) = 0;
+ virtual void loggedOut() = 0;
+ virtual void setShowNotificationToggle(bool) = 0;
+ virtual void setMessage(const std::string&) = 0;
+ virtual void setIsLoggingIn(bool loggingIn) = 0;
+ virtual void addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate, const ClientOptions& options) = 0;
+ virtual void removeAvailableAccount(const std::string& jid) = 0;
+ /** The certificate is what is used for login, the certificatePath is used for remembering paths to populate the loginwindow with*/
+ boost::signal<void (const std::string&, const std::string&, const std::string& /*CertificatePath*/, CertificateWithKey::ref /* clientCertificate */, const ClientOptions& /*options*/, bool /* remember password*/, bool /* login automatically */)> onLoginRequest;
+ virtual void setLoginAutomatically(bool loginAutomatically) = 0;
+ virtual void quit() = 0;
+ /** Blocking request whether a cert should be permanently trusted.*/
+ virtual bool askUserToTrustCertificatePermanently(const std::string& message, const std::vector<Certificate::ref>& certificateChain) = 0;
- boost::signal<void ()> onCancelLoginRequest;
- boost::signal<void ()> onQuitRequest;
- boost::signal<void (const std::string&)> onPurgeSavedLoginRequest;
- };
+ boost::signal<void ()> onCancelLoginRequest;
+ boost::signal<void ()> onQuitRequest;
+ boost::signal<void (const std::string&)> onPurgeSavedLoginRequest;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/LoginWindowFactory.h b/Swift/Controllers/UIInterfaces/LoginWindowFactory.h
index c040833..485f975 100644
--- a/Swift/Controllers/UIInterfaces/LoginWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/LoginWindowFactory.h
@@ -10,20 +10,20 @@
namespace Swift {
- class LoginWindow;
-
- class UIEventStream;
-
- class LoginWindowFactory {
- public:
- virtual ~LoginWindowFactory() {}
-
- /**
- * Transfers ownership of result.
- */
- virtual LoginWindow* createLoginWindow(UIEventStream* uiEventStream) = 0;
-
- };
+ class LoginWindow;
+
+ class UIEventStream;
+
+ class LoginWindowFactory {
+ public:
+ virtual ~LoginWindowFactory() {}
+
+ /**
+ * Transfers ownership of result.
+ */
+ virtual LoginWindow* createLoginWindow(UIEventStream* uiEventStream) = 0;
+
+ };
}
#endif
diff --git a/Swift/Controllers/UIInterfaces/MUCSearchWindow.h b/Swift/Controllers/UIInterfaces/MUCSearchWindow.h
index 10c6b38..d6c0065 100644
--- a/Swift/Controllers/UIInterfaces/MUCSearchWindow.h
+++ b/Swift/Controllers/UIInterfaces/MUCSearchWindow.h
@@ -18,18 +18,18 @@
namespace Swift {
- class MUCSearchWindow {
- public:
- virtual ~MUCSearchWindow() {}
+ class MUCSearchWindow {
+ public:
+ virtual ~MUCSearchWindow() {}
- virtual void clearList() = 0;
- virtual void addService(const MUCService& service) = 0;
- virtual void addSavedServices(const std::list<JID>& services) = 0;
- virtual void setSearchInProgress(bool searching) = 0;
+ virtual void clearList() = 0;
+ virtual void addService(const MUCService& service) = 0;
+ virtual void addSavedServices(const std::list<JID>& services) = 0;
+ virtual void setSearchInProgress(bool searching) = 0;
- virtual void show() = 0;
+ virtual void show() = 0;
- boost::signal<void (const JID&)> onSearchService;
- boost::signal<void (const boost::optional<JID>&)> onFinished;
- };
+ boost::signal<void (const JID&)> onSearchService;
+ boost::signal<void (const boost::optional<JID>&)> onFinished;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/MUCSearchWindowFactory.h b/Swift/Controllers/UIInterfaces/MUCSearchWindowFactory.h
index 38492cd..6e26ac3 100644
--- a/Swift/Controllers/UIInterfaces/MUCSearchWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/MUCSearchWindowFactory.h
@@ -9,11 +9,11 @@
#include <Swift/Controllers/UIInterfaces/MUCSearchWindow.h>
namespace Swift {
- class UIEventStream;
- class MUCSearchWindowFactory {
- public:
- virtual ~MUCSearchWindowFactory() {}
+ class UIEventStream;
+ class MUCSearchWindowFactory {
+ public:
+ virtual ~MUCSearchWindowFactory() {}
- virtual MUCSearchWindow* createMUCSearchWindow() = 0;
- };
+ virtual MUCSearchWindow* createMUCSearchWindow() = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/MainWindow.h b/Swift/Controllers/UIInterfaces/MainWindow.h
index aa8314d..d8bcb58 100644
--- a/Swift/Controllers/UIInterfaces/MainWindow.h
+++ b/Swift/Controllers/UIInterfaces/MainWindow.h
@@ -19,36 +19,36 @@
#include <Swift/Controllers/Roster/ContactRosterItem.h>
namespace Swift {
- class Roster;
-
- class MainWindow {
- public:
- MainWindow(bool candelete = true) : canDelete_(candelete) {}
- virtual ~MainWindow() {}
-
- bool canDelete() const {
- return canDelete_;
- }
-
- virtual void setMyNick(const std::string& name) = 0;
- virtual void setMyJID(const JID& jid) = 0;
- virtual void setMyAvatarPath(const std::string& path) = 0;
- virtual void setMyStatusText(const std::string& status) = 0;
- virtual void setMyStatusType(StatusShow::Type type) = 0;
- virtual void setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) = 0;
- /** Must be able to cope with NULL to clear the roster */
- virtual void setRosterModel(Roster* roster) = 0;
- virtual void setConnecting() = 0;
- virtual void setBlockingCommandAvailable(bool isAvailable) = 0;
- virtual void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands) = 0;
- virtual void setStreamEncryptionStatus(bool tlsInPlaceAndValid) = 0;
- virtual void openCertificateDialog(const std::vector<Certificate::ref>& chain) = 0;
-
- boost::signal<void (StatusShow::Type, const std::string&)> onChangeStatusRequest;
- boost::signal<void ()> onSignOutRequest;
- boost::signal<void ()> onShowCertificateRequest;
-
- private:
- bool canDelete_;
- };
+ class Roster;
+
+ class MainWindow {
+ public:
+ MainWindow(bool candelete = true) : canDelete_(candelete) {}
+ virtual ~MainWindow() {}
+
+ bool canDelete() const {
+ return canDelete_;
+ }
+
+ virtual void setMyNick(const std::string& name) = 0;
+ virtual void setMyJID(const JID& jid) = 0;
+ virtual void setMyAvatarPath(const std::string& path) = 0;
+ virtual void setMyStatusText(const std::string& status) = 0;
+ virtual void setMyStatusType(StatusShow::Type type) = 0;
+ virtual void setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) = 0;
+ /** Must be able to cope with NULL to clear the roster */
+ virtual void setRosterModel(Roster* roster) = 0;
+ virtual void setConnecting() = 0;
+ virtual void setBlockingCommandAvailable(bool isAvailable) = 0;
+ virtual void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands) = 0;
+ virtual void setStreamEncryptionStatus(bool tlsInPlaceAndValid) = 0;
+ virtual void openCertificateDialog(const std::vector<Certificate::ref>& chain) = 0;
+
+ boost::signal<void (StatusShow::Type, const std::string&)> onChangeStatusRequest;
+ boost::signal<void ()> onSignOutRequest;
+ boost::signal<void ()> onShowCertificateRequest;
+
+ private:
+ bool canDelete_;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/MainWindowFactory.h b/Swift/Controllers/UIInterfaces/MainWindowFactory.h
index 5c24187..c0110cf 100644
--- a/Swift/Controllers/UIInterfaces/MainWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/MainWindowFactory.h
@@ -11,17 +11,17 @@
#include "Swift/Controllers/UIEvents/UIEventStream.h"
namespace Swift {
- class MainWindow;
+ class MainWindow;
- class MainWindowFactory {
- public:
- virtual ~MainWindowFactory() {}
- /**
- * Transfers ownership of result.
- */
- virtual MainWindow* createMainWindow(UIEventStream* eventStream) = 0;
+ class MainWindowFactory {
+ public:
+ virtual ~MainWindowFactory() {}
+ /**
+ * Transfers ownership of result.
+ */
+ virtual MainWindow* createMainWindow(UIEventStream* eventStream) = 0;
- };
+ };
}
#endif
diff --git a/Swift/Controllers/UIInterfaces/ProfileWindow.h b/Swift/Controllers/UIInterfaces/ProfileWindow.h
index f396499..8aa620c 100644
--- a/Swift/Controllers/UIInterfaces/ProfileWindow.h
+++ b/Swift/Controllers/UIInterfaces/ProfileWindow.h
@@ -12,24 +12,24 @@
#include <Swiften/Elements/VCard.h>
namespace Swift {
- class JID;
+ class JID;
- class ProfileWindow {
- public:
- virtual ~ProfileWindow() {}
+ class ProfileWindow {
+ public:
+ virtual ~ProfileWindow() {}
- virtual void setJID(const JID& jid) = 0;
- virtual void setVCard(VCard::ref vcard) = 0;
+ virtual void setJID(const JID& jid) = 0;
+ virtual void setVCard(VCard::ref vcard) = 0;
- virtual void setEnabled(bool b) = 0;
- virtual void setProcessing(bool b) = 0;
- virtual void setError(const std::string&) = 0;
- virtual void setEditable(bool b) = 0;
+ virtual void setEnabled(bool b) = 0;
+ virtual void setProcessing(bool b) = 0;
+ virtual void setError(const std::string&) = 0;
+ virtual void setEditable(bool b) = 0;
- virtual void show() = 0;
- virtual void hide() = 0;
+ virtual void show() = 0;
+ virtual void hide() = 0;
- boost::signal<void (VCard::ref)> onVCardChangeRequest;
- boost::signal<void (const JID&)> onWindowAboutToBeClosed;
- };
+ boost::signal<void (VCard::ref)> onVCardChangeRequest;
+ boost::signal<void (const JID&)> onWindowAboutToBeClosed;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/ProfileWindowFactory.h b/Swift/Controllers/UIInterfaces/ProfileWindowFactory.h
index 5137151..6c2c6e5 100644
--- a/Swift/Controllers/UIInterfaces/ProfileWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/ProfileWindowFactory.h
@@ -9,10 +9,10 @@
#include <Swift/Controllers/UIInterfaces/ProfileWindow.h>
namespace Swift {
- class ProfileWindowFactory {
- public:
- virtual ~ProfileWindowFactory() {}
+ class ProfileWindowFactory {
+ public:
+ virtual ~ProfileWindowFactory() {}
- virtual ProfileWindow* createProfileWindow() = 0;
- };
+ virtual ProfileWindow* createProfileWindow() = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/UIFactory.h b/Swift/Controllers/UIInterfaces/UIFactory.h
index dd9d0df..a0976dc 100644
--- a/Swift/Controllers/UIInterfaces/UIFactory.h
+++ b/Swift/Controllers/UIInterfaces/UIFactory.h
@@ -25,25 +25,25 @@
#include <Swift/Controllers/UIInterfaces/XMLConsoleWidgetFactory.h>
namespace Swift {
- class UIFactory :
- public ChatListWindowFactory,
- public ChatWindowFactory,
- public HistoryWindowFactory,
- public EventWindowFactory,
- public LoginWindowFactory,
- public MainWindowFactory,
- public MUCSearchWindowFactory,
- public XMLConsoleWidgetFactory,
- public UserSearchWindowFactory,
- public JoinMUCWindowFactory,
- public ProfileWindowFactory,
- public ContactEditWindowFactory,
- public AdHocCommandWindowFactory,
- public FileTransferListWidgetFactory,
- public WhiteboardWindowFactory,
- public HighlightEditorWindowFactory,
- public BlockListEditorWidgetFactory {
- public:
- virtual ~UIFactory() {}
- };
+ class UIFactory :
+ public ChatListWindowFactory,
+ public ChatWindowFactory,
+ public HistoryWindowFactory,
+ public EventWindowFactory,
+ public LoginWindowFactory,
+ public MainWindowFactory,
+ public MUCSearchWindowFactory,
+ public XMLConsoleWidgetFactory,
+ public UserSearchWindowFactory,
+ public JoinMUCWindowFactory,
+ public ProfileWindowFactory,
+ public ContactEditWindowFactory,
+ public AdHocCommandWindowFactory,
+ public FileTransferListWidgetFactory,
+ public WhiteboardWindowFactory,
+ public HighlightEditorWindowFactory,
+ public BlockListEditorWidgetFactory {
+ public:
+ virtual ~UIFactory() {}
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/UserSearchWindow.h b/Swift/Controllers/UIInterfaces/UserSearchWindow.h
index da33db3..4ddc29b 100644
--- a/Swift/Controllers/UIInterfaces/UserSearchWindow.h
+++ b/Swift/Controllers/UIInterfaces/UserSearchWindow.h
@@ -17,40 +17,40 @@
namespace Swift {
- class UserSearchWindow {
- public:
- enum Type {AddContact, ChatToContact, InviteToChat};
- virtual ~UserSearchWindow() {}
-
- virtual void clear() = 0;
- virtual void setResults(const std::vector<UserSearchResult>& results) = 0;
- virtual void setResultsForm(const Form::ref results) = 0;
- virtual void addSavedServices(const std::vector<JID>& services) = 0;
- virtual void setSelectedService(const JID& service) = 0;
- virtual void setServerSupportsSearch(bool support) = 0;
- virtual void setSearchError(bool support) = 0;
- virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields) = 0;
- virtual void setNameSuggestions(const std::vector<std::string>& suggestions) = 0;
- virtual void prepopulateJIDAndName(const JID& jid, const std::string& name) = 0;
- virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions) = 0;
- virtual void setJIDs(const std::vector<JID>&) = 0;
- virtual void setRoomJID(const JID& roomJID) = 0;
- virtual std::string getReason() const = 0;
- virtual std::vector<JID> getJIDs() const = 0;
- virtual void setCanStartImpromptuChats(bool supportsImpromptu) = 0;
- virtual void updateContacts(const std::vector<Contact::ref>& contacts) = 0;
- virtual void addContacts(const std::vector<Contact::ref>& contacts) = 0;
- virtual void setCanSupplyDescription(bool allowed) = 0;
- virtual void setWarning(const boost::optional<std::string>& message) = 0;
-
- virtual void show() = 0;
-
- boost::signal<void (const JID&)> onFormRequested;
- boost::signal<void (boost::shared_ptr<SearchPayload>, const JID&)> onSearchRequested;
- boost::signal<void (const JID&)> onNameSuggestionRequested;
- boost::signal<void (const std::string&)> onContactSuggestionsRequested;
- boost::signal<void (const std::vector<JID>&)> onJIDUpdateRequested;
- boost::signal<void (const std::vector<JID>&)> onJIDAddRequested;
- boost::signal<void (const JID&)> onJIDEditFieldChanged;
- };
+ class UserSearchWindow {
+ public:
+ enum Type {AddContact, ChatToContact, InviteToChat};
+ virtual ~UserSearchWindow() {}
+
+ virtual void clear() = 0;
+ virtual void setResults(const std::vector<UserSearchResult>& results) = 0;
+ virtual void setResultsForm(const Form::ref results) = 0;
+ virtual void addSavedServices(const std::vector<JID>& services) = 0;
+ virtual void setSelectedService(const JID& service) = 0;
+ virtual void setServerSupportsSearch(bool support) = 0;
+ virtual void setSearchError(bool support) = 0;
+ virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields) = 0;
+ virtual void setNameSuggestions(const std::vector<std::string>& suggestions) = 0;
+ virtual void prepopulateJIDAndName(const JID& jid, const std::string& name) = 0;
+ virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions) = 0;
+ virtual void setJIDs(const std::vector<JID>&) = 0;
+ virtual void setRoomJID(const JID& roomJID) = 0;
+ virtual std::string getReason() const = 0;
+ virtual std::vector<JID> getJIDs() const = 0;
+ virtual void setCanStartImpromptuChats(bool supportsImpromptu) = 0;
+ virtual void updateContacts(const std::vector<Contact::ref>& contacts) = 0;
+ virtual void addContacts(const std::vector<Contact::ref>& contacts) = 0;
+ virtual void setCanSupplyDescription(bool allowed) = 0;
+ virtual void setWarning(const boost::optional<std::string>& message) = 0;
+
+ virtual void show() = 0;
+
+ boost::signal<void (const JID&)> onFormRequested;
+ boost::signal<void (boost::shared_ptr<SearchPayload>, const JID&)> onSearchRequested;
+ boost::signal<void (const JID&)> onNameSuggestionRequested;
+ boost::signal<void (const std::string&)> onContactSuggestionsRequested;
+ boost::signal<void (const std::vector<JID>&)> onJIDUpdateRequested;
+ boost::signal<void (const std::vector<JID>&)> onJIDAddRequested;
+ boost::signal<void (const JID&)> onJIDEditFieldChanged;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h b/Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h
index 4eee510..d5d6135 100644
--- a/Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h
@@ -11,11 +11,11 @@
#include <Swift/Controllers/UIInterfaces/UserSearchWindow.h>
namespace Swift {
- class UIEventStream;
- class UserSearchWindowFactory {
- public:
- virtual ~UserSearchWindowFactory() {}
+ class UIEventStream;
+ class UserSearchWindowFactory {
+ public:
+ virtual ~UserSearchWindowFactory() {}
- virtual UserSearchWindow* createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups) = 0;
- };
+ virtual UserSearchWindow* createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups) = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindow.h b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h
index 84aefde..f3b35db 100644
--- a/Swift/Controllers/UIInterfaces/WhiteboardWindow.h
+++ b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h
@@ -17,16 +17,16 @@
#include <Swiften/Base/boost_bsignals.h>
namespace Swift {
- class WhiteboardSession;
- class WhiteboardElement;
+ class WhiteboardSession;
+ class WhiteboardElement;
- class WhiteboardWindow {
- public:
- virtual ~WhiteboardWindow() {}
+ class WhiteboardWindow {
+ public:
+ virtual ~WhiteboardWindow() {}
- virtual void show() = 0;
- virtual void setSession(boost::shared_ptr<WhiteboardSession> session) = 0;
- virtual void activateWindow() = 0;
- virtual void setName(const std::string& name) = 0;
- };
+ virtual void show() = 0;
+ virtual void setSession(boost::shared_ptr<WhiteboardSession> session) = 0;
+ virtual void activateWindow() = 0;
+ virtual void setName(const std::string& name) = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h
index 2be0f9c..163368b 100644
--- a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h
@@ -7,13 +7,13 @@
#pragma once
namespace Swift {
- class WhiteboardSession;
- class WhiteboardWindow;
+ class WhiteboardSession;
+ class WhiteboardWindow;
- class WhiteboardWindowFactory {
- public :
- virtual ~WhiteboardWindowFactory() {}
+ class WhiteboardWindowFactory {
+ public :
+ virtual ~WhiteboardWindowFactory() {}
- virtual WhiteboardWindow* createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession) = 0;
- };
+ virtual WhiteboardWindow* createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession) = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/XMLConsoleWidget.h b/Swift/Controllers/UIInterfaces/XMLConsoleWidget.h
index 7e477a9..872b9de 100644
--- a/Swift/Controllers/UIInterfaces/XMLConsoleWidget.h
+++ b/Swift/Controllers/UIInterfaces/XMLConsoleWidget.h
@@ -9,14 +9,14 @@
#include <Swiften/Base/SafeByteArray.h>
namespace Swift {
- class XMLConsoleWidget {
- public:
- virtual ~XMLConsoleWidget();
+ class XMLConsoleWidget {
+ public:
+ virtual ~XMLConsoleWidget();
- virtual void handleDataRead(const SafeByteArray& data) = 0;
- virtual void handleDataWritten(const SafeByteArray& data) = 0;
+ virtual void handleDataRead(const SafeByteArray& data) = 0;
+ virtual void handleDataWritten(const SafeByteArray& data) = 0;
- virtual void show() = 0;
- virtual void activate() = 0;
- };
+ virtual void show() = 0;
+ virtual void activate() = 0;
+ };
}
diff --git a/Swift/Controllers/UIInterfaces/XMLConsoleWidgetFactory.h b/Swift/Controllers/UIInterfaces/XMLConsoleWidgetFactory.h
index 69b3e16..bbc055e 100644
--- a/Swift/Controllers/UIInterfaces/XMLConsoleWidgetFactory.h
+++ b/Swift/Controllers/UIInterfaces/XMLConsoleWidgetFactory.h
@@ -9,11 +9,11 @@
#include <Swift/Controllers/UIInterfaces/XMLConsoleWidget.h>
namespace Swift {
- class UIEventStream;
- class XMLConsoleWidgetFactory {
- public:
- virtual ~XMLConsoleWidgetFactory() {}
+ class UIEventStream;
+ class XMLConsoleWidgetFactory {
+ public:
+ virtual ~XMLConsoleWidgetFactory() {}
- virtual XMLConsoleWidget* createXMLConsoleWidget() = 0;
- };
+ virtual XMLConsoleWidget* createXMLConsoleWidget() = 0;
+ };
}
diff --git a/Swift/Controllers/UnitTest/ChatMessageSummarizerTest.cpp b/Swift/Controllers/UnitTest/ChatMessageSummarizerTest.cpp
index 118c502..59c57b9 100644
--- a/Swift/Controllers/UnitTest/ChatMessageSummarizerTest.cpp
+++ b/Swift/Controllers/UnitTest/ChatMessageSummarizerTest.cpp
@@ -13,109 +13,109 @@ using namespace Swift;
using namespace std;
class ChatMessageSummarizerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(ChatMessageSummarizerTest);
- CPPUNIT_TEST(testEmpty);
- CPPUNIT_TEST(testCurrentNone);
- CPPUNIT_TEST(testCurrentCount);
- CPPUNIT_TEST(testCurrentCountOthersNone);
- CPPUNIT_TEST(testCurrentCountOtherCount);
- CPPUNIT_TEST(testCurrentNoneOtherCount);
- CPPUNIT_TEST(testCurrentCountOthersCount);
- CPPUNIT_TEST(testCurrentNoneOthersCount);
- CPPUNIT_TEST(testCurrentCountSomeOthersCount);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(ChatMessageSummarizerTest);
+ CPPUNIT_TEST(testEmpty);
+ CPPUNIT_TEST(testCurrentNone);
+ CPPUNIT_TEST(testCurrentCount);
+ CPPUNIT_TEST(testCurrentCountOthersNone);
+ CPPUNIT_TEST(testCurrentCountOtherCount);
+ CPPUNIT_TEST(testCurrentNoneOtherCount);
+ CPPUNIT_TEST(testCurrentCountOthersCount);
+ CPPUNIT_TEST(testCurrentNoneOthersCount);
+ CPPUNIT_TEST(testCurrentCountSomeOthersCount);
+ CPPUNIT_TEST_SUITE_END();
public:
- ChatMessageSummarizerTest() {}
-
- void setUp() {
-
- }
-
- void testEmpty() {
- string current("");
- vector<UnreadPair> unreads;
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(current, summary.getSummary(current, unreads));
- }
-
- void testCurrentNone() {
- string current("Bob");
- vector<UnreadPair> unreads;
- unreads.push_back(UnreadPair("Bob", 0));
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(current, summary.getSummary(current, unreads));
- }
-
- void testCurrentCount() {
- string current("Bob");
- vector<UnreadPair> unreads;
- unreads.push_back(UnreadPair("Bob", 3));
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(string("Bob (3)"), summary.getSummary(current, unreads));
- }
-
- void testCurrentCountOthersNone() {
- string current("Bob");
- vector<UnreadPair> unreads;
- unreads.push_back(UnreadPair("Bert", 0));
- unreads.push_back(UnreadPair("Bob", 3));
- unreads.push_back(UnreadPair("Betty", 0));
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(string("Bob (3)"), summary.getSummary(current, unreads));
- }
-
- void testCurrentCountOtherCount() {
- string current("Bob");
- vector<UnreadPair> unreads;
- unreads.push_back(UnreadPair("Bert", 0));
- unreads.push_back(UnreadPair("Bob", 3));
- unreads.push_back(UnreadPair("Betty", 7));
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(string("Bob (3); Betty (7)"), summary.getSummary(current, unreads));
- }
-
- void testCurrentNoneOtherCount() {
- string current("Bob");
- vector<UnreadPair> unreads;
- unreads.push_back(UnreadPair("Bert", 0));
- unreads.push_back(UnreadPair("Bob", 0));
- unreads.push_back(UnreadPair("Betty", 7));
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(string("Bob; Betty (7)"), summary.getSummary(current, unreads));
- }
-
- void testCurrentNoneOthersCount() {
- string current("Bob");
- vector<UnreadPair> unreads;
- unreads.push_back(UnreadPair("Bert", 2));
- unreads.push_back(UnreadPair("Bob", 0));
- unreads.push_back(UnreadPair("Betty", 7));
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(string("Bob and 2 others (9)"), summary.getSummary(current, unreads));
- }
-
- void testCurrentCountOthersCount() {
- string current("Bob");
- vector<UnreadPair> unreads;
- unreads.push_back(UnreadPair("Bert", 2));
- unreads.push_back(UnreadPair("Bob", 11));
- unreads.push_back(UnreadPair("Betty", 7));
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(string("Bob (11) and 2 others (9)"), summary.getSummary(current, unreads));
- }
-
- void testCurrentCountSomeOthersCount() {
- string current("Bob");
- vector<UnreadPair> unreads;
- unreads.push_back(UnreadPair("Bert", 2));
- unreads.push_back(UnreadPair("Beverly", 0));
- unreads.push_back(UnreadPair("Bob", 11));
- unreads.push_back(UnreadPair("Beatrice", 0));
- unreads.push_back(UnreadPair("Betty", 7));
- ChatMessageSummarizer summary;
- CPPUNIT_ASSERT_EQUAL(string("Bob (11) and 2 others (9)"), summary.getSummary(current, unreads));
- }
+ ChatMessageSummarizerTest() {}
+
+ void setUp() {
+
+ }
+
+ void testEmpty() {
+ string current("");
+ vector<UnreadPair> unreads;
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(current, summary.getSummary(current, unreads));
+ }
+
+ void testCurrentNone() {
+ string current("Bob");
+ vector<UnreadPair> unreads;
+ unreads.push_back(UnreadPair("Bob", 0));
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(current, summary.getSummary(current, unreads));
+ }
+
+ void testCurrentCount() {
+ string current("Bob");
+ vector<UnreadPair> unreads;
+ unreads.push_back(UnreadPair("Bob", 3));
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(string("Bob (3)"), summary.getSummary(current, unreads));
+ }
+
+ void testCurrentCountOthersNone() {
+ string current("Bob");
+ vector<UnreadPair> unreads;
+ unreads.push_back(UnreadPair("Bert", 0));
+ unreads.push_back(UnreadPair("Bob", 3));
+ unreads.push_back(UnreadPair("Betty", 0));
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(string("Bob (3)"), summary.getSummary(current, unreads));
+ }
+
+ void testCurrentCountOtherCount() {
+ string current("Bob");
+ vector<UnreadPair> unreads;
+ unreads.push_back(UnreadPair("Bert", 0));
+ unreads.push_back(UnreadPair("Bob", 3));
+ unreads.push_back(UnreadPair("Betty", 7));
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(string("Bob (3); Betty (7)"), summary.getSummary(current, unreads));
+ }
+
+ void testCurrentNoneOtherCount() {
+ string current("Bob");
+ vector<UnreadPair> unreads;
+ unreads.push_back(UnreadPair("Bert", 0));
+ unreads.push_back(UnreadPair("Bob", 0));
+ unreads.push_back(UnreadPair("Betty", 7));
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(string("Bob; Betty (7)"), summary.getSummary(current, unreads));
+ }
+
+ void testCurrentNoneOthersCount() {
+ string current("Bob");
+ vector<UnreadPair> unreads;
+ unreads.push_back(UnreadPair("Bert", 2));
+ unreads.push_back(UnreadPair("Bob", 0));
+ unreads.push_back(UnreadPair("Betty", 7));
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(string("Bob and 2 others (9)"), summary.getSummary(current, unreads));
+ }
+
+ void testCurrentCountOthersCount() {
+ string current("Bob");
+ vector<UnreadPair> unreads;
+ unreads.push_back(UnreadPair("Bert", 2));
+ unreads.push_back(UnreadPair("Bob", 11));
+ unreads.push_back(UnreadPair("Betty", 7));
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(string("Bob (11) and 2 others (9)"), summary.getSummary(current, unreads));
+ }
+
+ void testCurrentCountSomeOthersCount() {
+ string current("Bob");
+ vector<UnreadPair> unreads;
+ unreads.push_back(UnreadPair("Bert", 2));
+ unreads.push_back(UnreadPair("Beverly", 0));
+ unreads.push_back(UnreadPair("Bob", 11));
+ unreads.push_back(UnreadPair("Beatrice", 0));
+ unreads.push_back(UnreadPair("Betty", 7));
+ ChatMessageSummarizer summary;
+ CPPUNIT_ASSERT_EQUAL(string("Bob (11) and 2 others (9)"), summary.getSummary(current, unreads));
+ }
};
diff --git a/Swift/Controllers/UnitTest/ContactSuggesterTest.cpp b/Swift/Controllers/UnitTest/ContactSuggesterTest.cpp
index 9b625fe..2bfca4b 100644
--- a/Swift/Controllers/UnitTest/ContactSuggesterTest.cpp
+++ b/Swift/Controllers/UnitTest/ContactSuggesterTest.cpp
@@ -18,111 +18,111 @@
using namespace Swift;
class ContactSuggesterTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(ContactSuggesterTest);
- CPPUNIT_TEST(equalityTest);
- CPPUNIT_TEST(lexicographicalSortTest);
- CPPUNIT_TEST(sortTest);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(ContactSuggesterTest);
+ CPPUNIT_TEST(equalityTest);
+ CPPUNIT_TEST(lexicographicalSortTest);
+ CPPUNIT_TEST(sortTest);
+ CPPUNIT_TEST_SUITE_END();
public:
- std::vector<std::string> wordList() {
- const std::string words[] = {
- "abc",
- "ab",
- "bc",
- "d"
- };
-
- return std::vector<std::string>(words, words+sizeof(words)/sizeof(*words));
- }
-
- std::vector<StatusShow::Type> statusList() {
- StatusShow::Type types[] = {
- StatusShow::Online,
- StatusShow::Away,
- StatusShow::FFC,
- StatusShow::XA,
- StatusShow::DND,
- StatusShow::None
- };
-
- return std::vector<StatusShow::Type>(types, types+sizeof(types)/sizeof(*types));
- }
-
- std::vector<Contact::ref> contactList() {
- std::vector<Contact::ref> contacts;
- std::vector<std::string> words = wordList();
- std::vector<StatusShow::Type> statuses = statusList();
- foreach (const std::string& name, words) {
- foreach (const std::string& jid, words) {
- foreach (const StatusShow::Type& status, statuses) {
- contacts.push_back(boost::make_shared<Contact>(name, jid, status, ""));
- }
- }
- }
- return contacts;
- }
-
- /* a = a */
- bool isReflexive(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
- std::vector<Contact::ref> contacts = contactList();
- foreach (const Contact::ref& a, contacts) {
- if (!comparitor(a, a)) {
- return false;
- }
- }
- return true;
- }
-
- /* a = b -> b = a */
- bool isSymmetric(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
- std::vector<Contact::ref> contacts = contactList();
- foreach (const Contact::ref& a, contacts) {
- foreach (const Contact::ref& b, contacts) {
- if (comparitor(a, b)) {
- if (!comparitor(b, a)) {
- return false;
- }
- }
- }
- }
- return true;
- }
-
- /* a = b && b = c -> a = c */
- bool isTransitive(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
- std::vector<Contact::ref> contacts = contactList();
- foreach (const Contact::ref& a, contacts) {
- foreach (const Contact::ref& b, contacts) {
- foreach (const Contact::ref& c, contacts) {
- if (comparitor(a, b) && comparitor(b, c)) {
- if (!comparitor(a, c)) {
- return false;
- }
- }
- }
- }
- }
- return true;
- }
-
- void equalityTest() {
- CPPUNIT_ASSERT(isReflexive(Contact::equalityPredicate));
- CPPUNIT_ASSERT(isSymmetric(Contact::equalityPredicate));
- CPPUNIT_ASSERT(isTransitive(Contact::equalityPredicate));
- }
-
- void lexicographicalSortTest() {
- CPPUNIT_ASSERT(isTransitive(Contact::lexicographicalSortPredicate));
- }
-
- void sortTest() {
- std::vector<std::string> words = wordList();
- foreach (const std::string& word, words) {
- CPPUNIT_ASSERT(isTransitive(boost::bind(Contact::sortPredicate, _1, _2, word)));
- }
- }
+ std::vector<std::string> wordList() {
+ const std::string words[] = {
+ "abc",
+ "ab",
+ "bc",
+ "d"
+ };
+
+ return std::vector<std::string>(words, words+sizeof(words)/sizeof(*words));
+ }
+
+ std::vector<StatusShow::Type> statusList() {
+ StatusShow::Type types[] = {
+ StatusShow::Online,
+ StatusShow::Away,
+ StatusShow::FFC,
+ StatusShow::XA,
+ StatusShow::DND,
+ StatusShow::None
+ };
+
+ return std::vector<StatusShow::Type>(types, types+sizeof(types)/sizeof(*types));
+ }
+
+ std::vector<Contact::ref> contactList() {
+ std::vector<Contact::ref> contacts;
+ std::vector<std::string> words = wordList();
+ std::vector<StatusShow::Type> statuses = statusList();
+ foreach (const std::string& name, words) {
+ foreach (const std::string& jid, words) {
+ foreach (const StatusShow::Type& status, statuses) {
+ contacts.push_back(boost::make_shared<Contact>(name, jid, status, ""));
+ }
+ }
+ }
+ return contacts;
+ }
+
+ /* a = a */
+ bool isReflexive(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
+ std::vector<Contact::ref> contacts = contactList();
+ foreach (const Contact::ref& a, contacts) {
+ if (!comparitor(a, a)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /* a = b -> b = a */
+ bool isSymmetric(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
+ std::vector<Contact::ref> contacts = contactList();
+ foreach (const Contact::ref& a, contacts) {
+ foreach (const Contact::ref& b, contacts) {
+ if (comparitor(a, b)) {
+ if (!comparitor(b, a)) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ /* a = b && b = c -> a = c */
+ bool isTransitive(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
+ std::vector<Contact::ref> contacts = contactList();
+ foreach (const Contact::ref& a, contacts) {
+ foreach (const Contact::ref& b, contacts) {
+ foreach (const Contact::ref& c, contacts) {
+ if (comparitor(a, b) && comparitor(b, c)) {
+ if (!comparitor(a, c)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ void equalityTest() {
+ CPPUNIT_ASSERT(isReflexive(Contact::equalityPredicate));
+ CPPUNIT_ASSERT(isSymmetric(Contact::equalityPredicate));
+ CPPUNIT_ASSERT(isTransitive(Contact::equalityPredicate));
+ }
+
+ void lexicographicalSortTest() {
+ CPPUNIT_ASSERT(isTransitive(Contact::lexicographicalSortPredicate));
+ }
+
+ void sortTest() {
+ std::vector<std::string> words = wordList();
+ foreach (const std::string& word, words) {
+ CPPUNIT_ASSERT(isTransitive(boost::bind(Contact::sortPredicate, _1, _2, word)));
+ }
+ }
};
diff --git a/Swift/Controllers/UnitTest/HighlightRuleTest.cpp b/Swift/Controllers/UnitTest/HighlightRuleTest.cpp
index 62c403f..8d49d5d 100644
--- a/Swift/Controllers/UnitTest/HighlightRuleTest.cpp
+++ b/Swift/Controllers/UnitTest/HighlightRuleTest.cpp
@@ -21,304 +21,304 @@
using namespace Swift;
class HighlightRuleTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(HighlightRuleTest);
- CPPUNIT_TEST(testEmptyRuleNeverMatches);
- CPPUNIT_TEST(testKeyword);
- CPPUNIT_TEST(testNickKeyword);
- CPPUNIT_TEST(testNickWithoutOtherKeywords);
- CPPUNIT_TEST(testSender);
- CPPUNIT_TEST(testSenderAndKeyword);
- CPPUNIT_TEST(testWholeWords);
- CPPUNIT_TEST(testCase);
- CPPUNIT_TEST(testWholeWordsAndCase);
- CPPUNIT_TEST(testMUC);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- std::vector<std::string> keywords;
- keywords.push_back("keyword1");
- keywords.push_back("KEYWORD2");
-
- std::vector<std::string> senders;
- senders.push_back("sender1");
- senders.push_back("SENDER2");
-
- emptyRule = new HighlightRule();
-
- keywordRule = new HighlightRule();
- keywordRule->setKeywords(keywords);
-
- keywordChatRule = new HighlightRule();
- keywordChatRule->setKeywords(keywords);
- keywordChatRule->setMatchChat(true);
-
- keywordNickChatRule = new HighlightRule();
- keywordNickChatRule->setKeywords(keywords);
- keywordNickChatRule->setNickIsKeyword(true);
- keywordNickChatRule->setMatchChat(true);
-
- nickChatRule = new HighlightRule();
- nickChatRule->setNickIsKeyword(true);
- nickChatRule->setMatchChat(true);
-
- nickRule = new HighlightRule();
- nickRule->setNickIsKeyword(true);
-
- senderRule = new HighlightRule();
- senderRule->setSenders(senders);
-
- senderChatRule = new HighlightRule();
- senderChatRule->setSenders(senders);
- senderChatRule->setMatchChat(true);
-
- senderKeywordChatRule = new HighlightRule();
- senderKeywordChatRule->setSenders(senders);
- senderKeywordChatRule->setKeywords(keywords);
- senderKeywordChatRule->setMatchChat(true);
-
- senderKeywordNickChatRule = new HighlightRule();
- senderKeywordNickChatRule->setSenders(senders);
- senderKeywordNickChatRule->setKeywords(keywords);
- senderKeywordNickChatRule->setNickIsKeyword(true);
- senderKeywordNickChatRule->setMatchChat(true);
-
- senderKeywordNickWordChatRule = new HighlightRule();
- senderKeywordNickWordChatRule->setSenders(senders);
- senderKeywordNickWordChatRule->setKeywords(keywords);
- senderKeywordNickWordChatRule->setNickIsKeyword(true);
- senderKeywordNickWordChatRule->setMatchWholeWords(true);
- senderKeywordNickWordChatRule->setMatchChat(true);
-
- senderKeywordNickCaseChatRule = new HighlightRule();
- senderKeywordNickCaseChatRule->setSenders(senders);
- senderKeywordNickCaseChatRule->setKeywords(keywords);
- senderKeywordNickCaseChatRule->setNickIsKeyword(true);
- senderKeywordNickCaseChatRule->setMatchCase(true);
- senderKeywordNickCaseChatRule->setMatchChat(true);
-
- senderKeywordNickCaseWordChatRule = new HighlightRule();
- senderKeywordNickCaseWordChatRule->setSenders(senders);
- senderKeywordNickCaseWordChatRule->setKeywords(keywords);
- senderKeywordNickCaseWordChatRule->setNickIsKeyword(true);
- senderKeywordNickCaseWordChatRule->setMatchCase(true);
- senderKeywordNickCaseWordChatRule->setMatchWholeWords(true);
- senderKeywordNickCaseWordChatRule->setMatchChat(true);
-
- senderKeywordNickMUCRule = new HighlightRule();
- senderKeywordNickMUCRule->setSenders(senders);
- senderKeywordNickMUCRule->setKeywords(keywords);
- senderKeywordNickMUCRule->setNickIsKeyword(true);
- senderKeywordNickMUCRule->setMatchMUC(true);
- }
+ CPPUNIT_TEST_SUITE(HighlightRuleTest);
+ CPPUNIT_TEST(testEmptyRuleNeverMatches);
+ CPPUNIT_TEST(testKeyword);
+ CPPUNIT_TEST(testNickKeyword);
+ CPPUNIT_TEST(testNickWithoutOtherKeywords);
+ CPPUNIT_TEST(testSender);
+ CPPUNIT_TEST(testSenderAndKeyword);
+ CPPUNIT_TEST(testWholeWords);
+ CPPUNIT_TEST(testCase);
+ CPPUNIT_TEST(testWholeWordsAndCase);
+ CPPUNIT_TEST(testMUC);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ std::vector<std::string> keywords;
+ keywords.push_back("keyword1");
+ keywords.push_back("KEYWORD2");
+
+ std::vector<std::string> senders;
+ senders.push_back("sender1");
+ senders.push_back("SENDER2");
+
+ emptyRule = new HighlightRule();
+
+ keywordRule = new HighlightRule();
+ keywordRule->setKeywords(keywords);
+
+ keywordChatRule = new HighlightRule();
+ keywordChatRule->setKeywords(keywords);
+ keywordChatRule->setMatchChat(true);
+
+ keywordNickChatRule = new HighlightRule();
+ keywordNickChatRule->setKeywords(keywords);
+ keywordNickChatRule->setNickIsKeyword(true);
+ keywordNickChatRule->setMatchChat(true);
+
+ nickChatRule = new HighlightRule();
+ nickChatRule->setNickIsKeyword(true);
+ nickChatRule->setMatchChat(true);
+
+ nickRule = new HighlightRule();
+ nickRule->setNickIsKeyword(true);
+
+ senderRule = new HighlightRule();
+ senderRule->setSenders(senders);
+
+ senderChatRule = new HighlightRule();
+ senderChatRule->setSenders(senders);
+ senderChatRule->setMatchChat(true);
+
+ senderKeywordChatRule = new HighlightRule();
+ senderKeywordChatRule->setSenders(senders);
+ senderKeywordChatRule->setKeywords(keywords);
+ senderKeywordChatRule->setMatchChat(true);
+
+ senderKeywordNickChatRule = new HighlightRule();
+ senderKeywordNickChatRule->setSenders(senders);
+ senderKeywordNickChatRule->setKeywords(keywords);
+ senderKeywordNickChatRule->setNickIsKeyword(true);
+ senderKeywordNickChatRule->setMatchChat(true);
+
+ senderKeywordNickWordChatRule = new HighlightRule();
+ senderKeywordNickWordChatRule->setSenders(senders);
+ senderKeywordNickWordChatRule->setKeywords(keywords);
+ senderKeywordNickWordChatRule->setNickIsKeyword(true);
+ senderKeywordNickWordChatRule->setMatchWholeWords(true);
+ senderKeywordNickWordChatRule->setMatchChat(true);
+
+ senderKeywordNickCaseChatRule = new HighlightRule();
+ senderKeywordNickCaseChatRule->setSenders(senders);
+ senderKeywordNickCaseChatRule->setKeywords(keywords);
+ senderKeywordNickCaseChatRule->setNickIsKeyword(true);
+ senderKeywordNickCaseChatRule->setMatchCase(true);
+ senderKeywordNickCaseChatRule->setMatchChat(true);
+
+ senderKeywordNickCaseWordChatRule = new HighlightRule();
+ senderKeywordNickCaseWordChatRule->setSenders(senders);
+ senderKeywordNickCaseWordChatRule->setKeywords(keywords);
+ senderKeywordNickCaseWordChatRule->setNickIsKeyword(true);
+ senderKeywordNickCaseWordChatRule->setMatchCase(true);
+ senderKeywordNickCaseWordChatRule->setMatchWholeWords(true);
+ senderKeywordNickCaseWordChatRule->setMatchChat(true);
+
+ senderKeywordNickMUCRule = new HighlightRule();
+ senderKeywordNickMUCRule->setSenders(senders);
+ senderKeywordNickMUCRule->setKeywords(keywords);
+ senderKeywordNickMUCRule->setNickIsKeyword(true);
+ senderKeywordNickMUCRule->setMatchMUC(true);
+ }
- void tearDown() {
- delete emptyRule;
+ void tearDown() {
+ delete emptyRule;
- delete keywordRule;
- delete keywordChatRule;
- delete keywordNickChatRule;
- delete nickChatRule;
- delete nickRule;
-
- delete senderRule;
- delete senderChatRule;
- delete senderKeywordChatRule;
- delete senderKeywordNickChatRule;
+ delete keywordRule;
+ delete keywordChatRule;
+ delete keywordNickChatRule;
+ delete nickChatRule;
+ delete nickRule;
+
+ delete senderRule;
+ delete senderChatRule;
+ delete senderKeywordChatRule;
+ delete senderKeywordNickChatRule;
- delete senderKeywordNickWordChatRule;
- delete senderKeywordNickCaseChatRule;
- delete senderKeywordNickCaseWordChatRule;
+ delete senderKeywordNickWordChatRule;
+ delete senderKeywordNickCaseChatRule;
+ delete senderKeywordNickCaseWordChatRule;
- delete senderKeywordNickMUCRule;
- }
+ delete senderKeywordNickMUCRule;
+ }
- void testEmptyRuleNeverMatches() {
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "from", "nick", HighlightRule::MUCMessage), false);
+ void testEmptyRuleNeverMatches() {
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "from", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "from", "", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "from", "", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "from", "", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "from", "", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "", "nick", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "from", "nick", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "from", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "", "", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "", "", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "", "", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("body", "", "", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "from", "", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "from", "", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "from", "", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "from", "", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "", "nick", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "", "", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "", "", HighlightRule::MUCMessage), false);
- }
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "", "", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(emptyRule->isMatch("", "", "", HighlightRule::MUCMessage), false);
+ }
- void testKeyword() {
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("body", "from", "nick", HighlightRule::MUCMessage), false);
+ void testKeyword() {
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("body", "from", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(keywordRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(keywordRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("body", "sender contains keyword1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("body", "sender contains keyword1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("abc keyword1 xyz", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("abckeyword1xyz", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("abc keyword1 xyz", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("abckeyword1xyz", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("KEYword1", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("abc KEYword1 xyz", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("abcKEYword1xyz", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("KEYword1", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("abc KEYword1 xyz", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("abcKEYword1xyz", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("keyword2", "from", "nick", HighlightRule::ChatMessage), true);
- }
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("keyword2", "from", "nick", HighlightRule::ChatMessage), true);
+ }
- void testNickKeyword() {
- CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::ChatMessage), false);
+ void testNickKeyword() {
+ CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(keywordChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body", "sender contains nick", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body", "sender contains nick", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body contains mixed-case NiCk", "sender", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body contains mixed-case NiCk", "sender", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("nickname", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("NIckNAME", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("nickname", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("NIckNAME", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body", "from", "", HighlightRule::ChatMessage), false);
- }
+ CPPUNIT_ASSERT_EQUAL(keywordNickChatRule->isMatch("body", "from", "", HighlightRule::ChatMessage), false);
+ }
- void testNickWithoutOtherKeywords() {
- CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(nickRule->isMatch("body contains nick", "from", "nick", HighlightRule::ChatMessage), false);
+ void testNickWithoutOtherKeywords() {
+ CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body contains nick", "from", "nick", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(nickRule->isMatch("body contains nick", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body", "sender contains nick but it does't matter", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body", "sender contains nick but it does't matter", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body contains mixed-case NiCk", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body contains mixed-case NiCk", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("nickname", "from", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("NIckNAME", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("nickname", "from", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("NIckNAME", "from", "nick", HighlightRule::ChatMessage), true);
- // there are no keywords in this rule and empty nick is not treated as a keyword, so we don't check for keywords to get a match
- CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body", "from", "", HighlightRule::ChatMessage), true);
- }
+ // there are no keywords in this rule and empty nick is not treated as a keyword, so we don't check for keywords to get a match
+ CPPUNIT_ASSERT_EQUAL(nickChatRule->isMatch("body", "from", "", HighlightRule::ChatMessage), true);
+ }
- void testSender() {
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "from", "nick", HighlightRule::MUCMessage), false);
+ void testSender() {
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "from", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "sender1", "nick", HighlightRule::MUCMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "sender1", "nick", HighlightRule::MUCMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderRule->isMatch("body contains sender1", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderRule->isMatch("body contains sender1", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "abc sender1 xyz", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "abcsender1xyz", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "abc sender1 xyz", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "abcsender1xyz", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "SENDer1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "abc SENDer1 xyz", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "abcSENDer1xyz", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "SENDer1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "abc SENDer1 xyz", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "abcSENDer1xyz", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "sender2", "nick", HighlightRule::ChatMessage), true);
- }
+ CPPUNIT_ASSERT_EQUAL(senderChatRule->isMatch("body", "sender2", "nick", HighlightRule::ChatMessage), true);
+ }
- void testSenderAndKeyword() {
- CPPUNIT_ASSERT_EQUAL(senderKeywordChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordChatRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), true);
- }
+ void testSenderAndKeyword() {
+ CPPUNIT_ASSERT_EQUAL(senderKeywordChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordChatRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), true);
+ }
- void testWholeWords() {
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
+ void testWholeWords() {
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("xkeyword1", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("keyword1", "xsender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("xkeyword1", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("keyword1", "xsender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body contains nick", "sender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body contains xnick", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body contains nick", "sender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body contains xnick", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("KEYword1", "SENDer1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body contains NiCk", "sender1", "nick", HighlightRule::ChatMessage), true);
- }
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("KEYword1", "SENDer1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickWordChatRule->isMatch("body contains NiCk", "sender1", "nick", HighlightRule::ChatMessage), true);
+ }
- void testCase() {
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
+ void testCase() {
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("xkeyword1", "xsender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("xkeyword1", "xsender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body contains nick", "sender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body contains xnick", "sender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body contains nick", "sender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body contains xnick", "sender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("KEYword1", "SENDer1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("keyword1", "SENDer1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("KEYword1", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body contains NiCk", "sender1", "nick", HighlightRule::ChatMessage), false);
- }
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("KEYword1", "SENDer1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("keyword1", "SENDer1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("KEYword1", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseChatRule->isMatch("body contains NiCk", "sender1", "nick", HighlightRule::ChatMessage), false);
+ }
- void testWholeWordsAndCase() {
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
+ void testWholeWordsAndCase() {
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("keyword1", "from", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("xkeyword1", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("keyword1", "xsender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("xkeyword1", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("keyword1", "xsender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body contains nick", "sender1", "nick", HighlightRule::ChatMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body contains xnick", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body contains nick", "sender1", "nick", HighlightRule::ChatMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body contains xnick", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("KEYword1", "SENDer1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("keyword1", "SENDer1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("KEYword1", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body contains NiCk", "sender1", "nick", HighlightRule::ChatMessage), false);
- }
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("KEYword1", "SENDer1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("keyword1", "SENDer1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("KEYword1", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickCaseWordChatRule->isMatch("body contains NiCk", "sender1", "nick", HighlightRule::ChatMessage), false);
+ }
- void testMUC() {
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickMUCRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
+ void testMUC() {
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickMUCRule->isMatch("body", "from", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickMUCRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), false);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickMUCRule->isMatch("keyword1", "sender1", "nick", HighlightRule::MUCMessage), true);
- CPPUNIT_ASSERT_EQUAL(senderKeywordNickMUCRule->isMatch("body contains nick", "sender1", "nick", HighlightRule::MUCMessage), true);
- }
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickMUCRule->isMatch("keyword1", "sender1", "nick", HighlightRule::ChatMessage), false);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickMUCRule->isMatch("keyword1", "sender1", "nick", HighlightRule::MUCMessage), true);
+ CPPUNIT_ASSERT_EQUAL(senderKeywordNickMUCRule->isMatch("body contains nick", "sender1", "nick", HighlightRule::MUCMessage), true);
+ }
- private:
- HighlightRule* emptyRule;
+ private:
+ HighlightRule* emptyRule;
- HighlightRule* keywordRule;
- HighlightRule* keywordChatRule;
- HighlightRule* keywordNickChatRule;
- HighlightRule* nickChatRule;
- HighlightRule* nickRule;
+ HighlightRule* keywordRule;
+ HighlightRule* keywordChatRule;
+ HighlightRule* keywordNickChatRule;
+ HighlightRule* nickChatRule;
+ HighlightRule* nickRule;
- HighlightRule* senderRule;
- HighlightRule* senderChatRule;
- HighlightRule* senderKeywordChatRule;
- HighlightRule* senderKeywordNickChatRule;
+ HighlightRule* senderRule;
+ HighlightRule* senderChatRule;
+ HighlightRule* senderKeywordChatRule;
+ HighlightRule* senderKeywordNickChatRule;
- HighlightRule* senderKeywordNickWordChatRule;
- HighlightRule* senderKeywordNickCaseChatRule;
- HighlightRule* senderKeywordNickCaseWordChatRule;
+ HighlightRule* senderKeywordNickWordChatRule;
+ HighlightRule* senderKeywordNickCaseChatRule;
+ HighlightRule* senderKeywordNickCaseWordChatRule;
- HighlightRule* senderKeywordNickMUCRule;
+ HighlightRule* senderKeywordNickMUCRule;
};
CPPUNIT_TEST_SUITE_REGISTRATION(HighlightRuleTest);
diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h
index 20c51bc..b4588e7 100644
--- a/Swift/Controllers/UnitTest/MockChatWindow.h
+++ b/Swift/Controllers/UnitTest/MockChatWindow.h
@@ -13,103 +13,103 @@
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
namespace Swift {
- class MockChatWindow : public ChatWindow {
- public:
- MockChatWindow() : labelsEnabled_(false), impromptuMUCSupported_(false) {}
- virtual ~MockChatWindow();
-
- virtual std::string addMessage(const ChatMessage& message, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/) {
- lastMessageBody_ = bodyFromMessage(message);
- return "id";
- }
-
- virtual std::string addAction(const ChatMessage& /*message*/, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/) {return "id";}
-
- virtual std::string addSystemMessage(const ChatMessage& message, Direction /*direction*/) {
- lastAddedSystemMessage_ = message;
- return "id";
- }
-
- virtual void addPresenceMessage(const ChatMessage& message, Direction /*direction*/) {
- lastAddedPresence_ = message;
- }
-
- virtual void addErrorMessage(const ChatMessage& /*message*/) {}
- virtual void replaceMessage(const ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/) {}
- virtual void replaceWithAction(const ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/) {}
- virtual void replaceLastMessage(const ChatMessage& message, const TimestampBehaviour /*timestampBehaviour*/) {
- lastReplacedMessage_ = message;
- }
- virtual void replaceSystemMessage(const ChatMessage& /*message*/, const std::string& /*id*/, const TimestampBehaviour /*timestampBehaviour*/) {}
-
- // File transfer related stuff
- virtual std::string addFileTransfer(const std::string& /*senderName*/, bool /*senderIsSelf*/,const std::string& /*filename*/, const boost::uintmax_t /*sizeInBytes*/, const std::string& /*description*/) { return 0; }
- virtual void setFileTransferProgress(std::string /*id*/, const int /*alreadyTransferedBytes*/) { }
- virtual void setFileTransferStatus(std::string /*id*/, const FileTransferState /*state*/, const std::string& /*msg*/) { }
-
- virtual void setMessageReceiptState(const std::string &/* id */, ReceiptState /* state */) { }
-
- virtual void setContactChatState(ChatState::ChatStateType /*state*/) {}
- virtual void setName(const std::string& name) {name_ = name;}
- virtual void show() {}
- virtual bool isVisible() const { return true; }
- virtual void activate() {}
- virtual void setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels) {labels_ = labels;}
- virtual void setSecurityLabelsEnabled(bool enabled) {labelsEnabled_ = enabled;}
- virtual void setUnreadMessageCount(int /*count*/) {}
- virtual void convertToMUC(MUCType /*mucType*/) {}
- virtual void setSecurityLabelsError() {}
- virtual SecurityLabelsCatalog::Item getSelectedSecurityLabel() {return label_;}
- virtual void setOnline(bool /*online*/) {}
- virtual void setRosterModel(Roster* roster) { roster_ = roster; }
- Roster* getRosterModel() { return roster_; }
- virtual void setTabComplete(TabComplete*) {}
-
- void setAckState(const std::string& /*id*/, AckState /*state*/) {}
- virtual void flash() {}
- virtual AlertID addAlert(const std::string& /*alertText*/) { return 0; }
- virtual void removeAlert(const AlertID /*id*/) {}
- virtual void setCorrectionEnabled(Tristate /*enabled*/) {}
- virtual void setFileTransferEnabled(Tristate /*enabled*/) {}
- void setAvailableOccupantActions(const std::vector<OccupantAction>&/* actions*/) {}
- void setSubject(const std::string& /*subject*/) {}
- virtual void showRoomConfigurationForm(Form::ref) {}
- virtual void addMUCInvitation(const std::string& /*senderName*/, const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/, bool = true, bool = false, bool = false) {}
-
- virtual std::string addWhiteboardRequest(bool) {return "";}
- virtual void setWhiteboardSessionStatus(std::string, const ChatWindow::WhiteboardSessionState){}
-
- virtual void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>&) {}
- virtual void setAvailableRoomActions(const std::vector<RoomAction> &) {}
-
- virtual void setBlockingState(BlockingState) {}
- virtual void setCanInitiateImpromptuChats(bool supportsImpromptu) {
- impromptuMUCSupported_ = supportsImpromptu;
- }
-
- virtual void showBookmarkWindow(const MUCBookmark& /*bookmark*/) {}
- virtual void setBookmarkState(RoomBookmarkState) {}
-
- static std::string bodyFromMessage(const ChatMessage& message) {
- boost::shared_ptr<ChatTextMessagePart> text;
- foreach (boost::shared_ptr<ChatMessagePart> part, message.getParts()) {
- if ((text = boost::dynamic_pointer_cast<ChatTextMessagePart>(part))) {
- return text->text;
- }
- }
- return "";
- }
-
- std::string name_;
- std::string lastMessageBody_;
- ChatMessage lastAddedPresence_;
- ChatMessage lastReplacedMessage_;
- ChatMessage lastAddedSystemMessage_;
- std::vector<SecurityLabelsCatalog::Item> labels_;
- bool labelsEnabled_;
- bool impromptuMUCSupported_;
- SecurityLabelsCatalog::Item label_;
- Roster* roster_;
- };
+ class MockChatWindow : public ChatWindow {
+ public:
+ MockChatWindow() : labelsEnabled_(false), impromptuMUCSupported_(false) {}
+ virtual ~MockChatWindow();
+
+ virtual std::string addMessage(const ChatMessage& message, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/) {
+ lastMessageBody_ = bodyFromMessage(message);
+ return "id";
+ }
+
+ virtual std::string addAction(const ChatMessage& /*message*/, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/) {return "id";}
+
+ virtual std::string addSystemMessage(const ChatMessage& message, Direction /*direction*/) {
+ lastAddedSystemMessage_ = message;
+ return "id";
+ }
+
+ virtual void addPresenceMessage(const ChatMessage& message, Direction /*direction*/) {
+ lastAddedPresence_ = message;
+ }
+
+ virtual void addErrorMessage(const ChatMessage& /*message*/) {}
+ virtual void replaceMessage(const ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/) {}
+ virtual void replaceWithAction(const ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/) {}
+ virtual void replaceLastMessage(const ChatMessage& message, const TimestampBehaviour /*timestampBehaviour*/) {
+ lastReplacedMessage_ = message;
+ }
+ virtual void replaceSystemMessage(const ChatMessage& /*message*/, const std::string& /*id*/, const TimestampBehaviour /*timestampBehaviour*/) {}
+
+ // File transfer related stuff
+ virtual std::string addFileTransfer(const std::string& /*senderName*/, bool /*senderIsSelf*/,const std::string& /*filename*/, const boost::uintmax_t /*sizeInBytes*/, const std::string& /*description*/) { return 0; }
+ virtual void setFileTransferProgress(std::string /*id*/, const int /*alreadyTransferedBytes*/) { }
+ virtual void setFileTransferStatus(std::string /*id*/, const FileTransferState /*state*/, const std::string& /*msg*/) { }
+
+ virtual void setMessageReceiptState(const std::string &/* id */, ReceiptState /* state */) { }
+
+ virtual void setContactChatState(ChatState::ChatStateType /*state*/) {}
+ virtual void setName(const std::string& name) {name_ = name;}
+ virtual void show() {}
+ virtual bool isVisible() const { return true; }
+ virtual void activate() {}
+ virtual void setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels) {labels_ = labels;}
+ virtual void setSecurityLabelsEnabled(bool enabled) {labelsEnabled_ = enabled;}
+ virtual void setUnreadMessageCount(int /*count*/) {}
+ virtual void convertToMUC(MUCType /*mucType*/) {}
+ virtual void setSecurityLabelsError() {}
+ virtual SecurityLabelsCatalog::Item getSelectedSecurityLabel() {return label_;}
+ virtual void setOnline(bool /*online*/) {}
+ virtual void setRosterModel(Roster* roster) { roster_ = roster; }
+ Roster* getRosterModel() { return roster_; }
+ virtual void setTabComplete(TabComplete*) {}
+
+ void setAckState(const std::string& /*id*/, AckState /*state*/) {}
+ virtual void flash() {}
+ virtual AlertID addAlert(const std::string& /*alertText*/) { return 0; }
+ virtual void removeAlert(const AlertID /*id*/) {}
+ virtual void setCorrectionEnabled(Tristate /*enabled*/) {}
+ virtual void setFileTransferEnabled(Tristate /*enabled*/) {}
+ void setAvailableOccupantActions(const std::vector<OccupantAction>&/* actions*/) {}
+ void setSubject(const std::string& /*subject*/) {}
+ virtual void showRoomConfigurationForm(Form::ref) {}
+ virtual void addMUCInvitation(const std::string& /*senderName*/, const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/, bool = true, bool = false, bool = false) {}
+
+ virtual std::string addWhiteboardRequest(bool) {return "";}
+ virtual void setWhiteboardSessionStatus(std::string, const ChatWindow::WhiteboardSessionState){}
+
+ virtual void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>&) {}
+ virtual void setAvailableRoomActions(const std::vector<RoomAction> &) {}
+
+ virtual void setBlockingState(BlockingState) {}
+ virtual void setCanInitiateImpromptuChats(bool supportsImpromptu) {
+ impromptuMUCSupported_ = supportsImpromptu;
+ }
+
+ virtual void showBookmarkWindow(const MUCBookmark& /*bookmark*/) {}
+ virtual void setBookmarkState(RoomBookmarkState) {}
+
+ static std::string bodyFromMessage(const ChatMessage& message) {
+ boost::shared_ptr<ChatTextMessagePart> text;
+ foreach (boost::shared_ptr<ChatMessagePart> part, message.getParts()) {
+ if ((text = boost::dynamic_pointer_cast<ChatTextMessagePart>(part))) {
+ return text->text;
+ }
+ }
+ return "";
+ }
+
+ std::string name_;
+ std::string lastMessageBody_;
+ ChatMessage lastAddedPresence_;
+ ChatMessage lastReplacedMessage_;
+ ChatMessage lastAddedSystemMessage_;
+ std::vector<SecurityLabelsCatalog::Item> labels_;
+ bool labelsEnabled_;
+ bool impromptuMUCSupported_;
+ SecurityLabelsCatalog::Item label_;
+ Roster* roster_;
+ };
}
diff --git a/Swift/Controllers/UnitTest/MockMainWindow.h b/Swift/Controllers/UnitTest/MockMainWindow.h
index af4267f..9177bdc 100644
--- a/Swift/Controllers/UnitTest/MockMainWindow.h
+++ b/Swift/Controllers/UnitTest/MockMainWindow.h
@@ -9,24 +9,24 @@
#include <Swift/Controllers/UIInterfaces/MainWindow.h>
namespace Swift {
- class Roster;
- class MockMainWindow : public MainWindow {
- public:
- MockMainWindow() : roster(NULL) {}
- virtual ~MockMainWindow() {}
- virtual void setRosterModel(Roster* roster) {this->roster = roster;}
- virtual void setMyNick(const std::string& /*name*/) {}
- virtual void setMyJID(const JID& /*jid*/) {}
- virtual void setMyAvatarPath(const std::string& /*path*/) {}
- virtual void setMyStatusText(const std::string& /*status*/) {}
- virtual void setMyStatusType(StatusShow::Type /*type*/) {}
- virtual void setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> /*contact*/) {}
- virtual void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& /*commands*/) {}
- virtual void setConnecting() {}
- virtual void setStreamEncryptionStatus(bool /*tlsInPlaceAndValid*/) {}
- virtual void openCertificateDialog(const std::vector<Certificate::ref>& /*chain*/) {}
- virtual void setBlockingCommandAvailable(bool /*isAvailable*/) {}
- Roster* roster;
+ class Roster;
+ class MockMainWindow : public MainWindow {
+ public:
+ MockMainWindow() : roster(NULL) {}
+ virtual ~MockMainWindow() {}
+ virtual void setRosterModel(Roster* roster) {this->roster = roster;}
+ virtual void setMyNick(const std::string& /*name*/) {}
+ virtual void setMyJID(const JID& /*jid*/) {}
+ virtual void setMyAvatarPath(const std::string& /*path*/) {}
+ virtual void setMyStatusText(const std::string& /*status*/) {}
+ virtual void setMyStatusType(StatusShow::Type /*type*/) {}
+ virtual void setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> /*contact*/) {}
+ virtual void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& /*commands*/) {}
+ virtual void setConnecting() {}
+ virtual void setStreamEncryptionStatus(bool /*tlsInPlaceAndValid*/) {}
+ virtual void openCertificateDialog(const std::vector<Certificate::ref>& /*chain*/) {}
+ virtual void setBlockingCommandAvailable(bool /*isAvailable*/) {}
+ Roster* roster;
- };
+ };
}
diff --git a/Swift/Controllers/UnitTest/MockMainWindowFactory.h b/Swift/Controllers/UnitTest/MockMainWindowFactory.h
index 0298bf2..4af0c79 100644
--- a/Swift/Controllers/UnitTest/MockMainWindowFactory.h
+++ b/Swift/Controllers/UnitTest/MockMainWindowFactory.h
@@ -11,18 +11,18 @@
namespace Swift {
- class MockMainWindowFactory : public MainWindowFactory {
- public:
- MockMainWindowFactory() : last(NULL) {}
-
- virtual ~MockMainWindowFactory() {}
-
- /**
- * Transfers ownership of result.
- */
- virtual MainWindow* createMainWindow(UIEventStream*) {last = new MockMainWindow();return last;}
- MockMainWindow* last;
- };
+ class MockMainWindowFactory : public MainWindowFactory {
+ public:
+ MockMainWindowFactory() : last(NULL) {}
+
+ virtual ~MockMainWindowFactory() {}
+
+ /**
+ * Transfers ownership of result.
+ */
+ virtual MainWindow* createMainWindow(UIEventStream*) {last = new MockMainWindow();return last;}
+ MockMainWindow* last;
+ };
}
diff --git a/Swift/Controllers/UnitTest/PresenceNotifierTest.cpp b/Swift/Controllers/UnitTest/PresenceNotifierTest.cpp
index 40530dc..e1284fd 100644
--- a/Swift/Controllers/UnitTest/PresenceNotifierTest.cpp
+++ b/Swift/Controllers/UnitTest/PresenceNotifierTest.cpp
@@ -26,297 +26,297 @@
using namespace Swift;
class PresenceNotifierTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(PresenceNotifierTest);
- CPPUNIT_TEST(testReceiveFirstPresenceCreatesAvailableNotification);
- CPPUNIT_TEST(testReceiveSecondPresenceCreatesStatusChangeNotification);
- CPPUNIT_TEST(testReceiveUnavailablePresenceAfterAvailablePresenceCreatesUnavailableNotification);
- CPPUNIT_TEST(testReceiveUnavailablePresenceWithoutAvailableDoesNotCreateNotification);
- CPPUNIT_TEST(testReceiveAvailablePresenceAfterUnavailableCreatesAvailableNotification);
- CPPUNIT_TEST(testReceiveAvailablePresenceAfterReconnectCreatesAvailableNotification);
- CPPUNIT_TEST(testReceiveAvailablePresenceFromMUCDoesNotCreateNotification);
- CPPUNIT_TEST(testNotificationSubjectContainsNameForJIDInRoster);
- CPPUNIT_TEST(testNotificationSubjectContainsJIDForJIDNotInRoster);
- CPPUNIT_TEST(testNotificationSubjectContainsStatus);
- CPPUNIT_TEST(testNotificationMessageContainsStatusMessage);
- CPPUNIT_TEST(testNotificationPicture);
- CPPUNIT_TEST(testNotificationActivationEmitsSignal);
- CPPUNIT_TEST(testReceiveFirstPresenceWithQuietPeriodDoesNotNotify);
- CPPUNIT_TEST(testReceiveFirstPresenceWithQuietPeriodDoesNotCountAsQuietPeriod);
- CPPUNIT_TEST(testReceivePresenceDuringQuietPeriodDoesNotNotify);
- CPPUNIT_TEST(testReceivePresenceDuringQuietPeriodResetsTimer);
- CPPUNIT_TEST(testReceivePresenceAfterQuietPeriodNotifies);
- CPPUNIT_TEST(testReceiveFirstPresenceAfterReconnectWithQuietPeriodDoesNotNotify);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- stanzaChannel = new DummyStanzaChannel();
- notifier = new LoggingNotifier();
- mucRegistry = new MUCRegistry();
- user1 = JID("user1@bar.com/bla");
- user2 = JID("user2@foo.com/baz");
- avatarManager = new DummyAvatarManager();
- roster = new XMPPRosterImpl();
- nickResolver = new NickResolver(JID("foo@bar.com"), roster, NULL, mucRegistry);
- presenceOracle = new PresenceOracle(stanzaChannel, roster);
- timerFactory = new DummyTimerFactory();
- }
-
- void tearDown() {
- delete timerFactory;
- delete presenceOracle;
- delete nickResolver;
- delete roster;
- delete avatarManager;
- delete mucRegistry;
- delete notifier;
- delete stanzaChannel;
- }
-
- void testReceiveFirstPresenceCreatesAvailableNotification() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
-
- sendPresence(user1, StatusShow::Online);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- CPPUNIT_ASSERT_EQUAL(Notifier::ContactAvailable, notifier->notifications[0].type);
- }
-
- void testReceiveSecondPresenceCreatesStatusChangeNotification() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- sendPresence(user1, StatusShow::Away);
- notifier->notifications.clear();
-
- sendPresence(user1, StatusShow::Online);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- CPPUNIT_ASSERT_EQUAL(Notifier::ContactStatusChange, notifier->notifications[0].type);
- }
-
- void testReceiveUnavailablePresenceAfterAvailablePresenceCreatesUnavailableNotification() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- sendPresence(user1, StatusShow::Away);
- notifier->notifications.clear();
-
- sendUnavailablePresence(user1);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- CPPUNIT_ASSERT_EQUAL(Notifier::ContactUnavailable, notifier->notifications[0].type);
- }
-
- void testReceiveUnavailablePresenceWithoutAvailableDoesNotCreateNotification() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
-
- sendUnavailablePresence(user1);
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
- }
-
- void testReceiveAvailablePresenceAfterUnavailableCreatesAvailableNotification() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- sendPresence(user1, StatusShow::Away);
- sendUnavailablePresence(user1);
- notifier->notifications.clear();
-
- sendPresence(user1, StatusShow::Away);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- CPPUNIT_ASSERT_EQUAL(Notifier::ContactAvailable, notifier->notifications[0].type);
- }
-
- void testReceiveAvailablePresenceAfterReconnectCreatesAvailableNotification() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- sendPresence(user1, StatusShow::Away);
- stanzaChannel->setAvailable(false);
- stanzaChannel->setAvailable(true);
- notifier->notifications.clear();
-
- sendPresence(user1, StatusShow::Away);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- CPPUNIT_ASSERT_EQUAL(Notifier::ContactAvailable, notifier->notifications[0].type);
- }
+ CPPUNIT_TEST_SUITE(PresenceNotifierTest);
+ CPPUNIT_TEST(testReceiveFirstPresenceCreatesAvailableNotification);
+ CPPUNIT_TEST(testReceiveSecondPresenceCreatesStatusChangeNotification);
+ CPPUNIT_TEST(testReceiveUnavailablePresenceAfterAvailablePresenceCreatesUnavailableNotification);
+ CPPUNIT_TEST(testReceiveUnavailablePresenceWithoutAvailableDoesNotCreateNotification);
+ CPPUNIT_TEST(testReceiveAvailablePresenceAfterUnavailableCreatesAvailableNotification);
+ CPPUNIT_TEST(testReceiveAvailablePresenceAfterReconnectCreatesAvailableNotification);
+ CPPUNIT_TEST(testReceiveAvailablePresenceFromMUCDoesNotCreateNotification);
+ CPPUNIT_TEST(testNotificationSubjectContainsNameForJIDInRoster);
+ CPPUNIT_TEST(testNotificationSubjectContainsJIDForJIDNotInRoster);
+ CPPUNIT_TEST(testNotificationSubjectContainsStatus);
+ CPPUNIT_TEST(testNotificationMessageContainsStatusMessage);
+ CPPUNIT_TEST(testNotificationPicture);
+ CPPUNIT_TEST(testNotificationActivationEmitsSignal);
+ CPPUNIT_TEST(testReceiveFirstPresenceWithQuietPeriodDoesNotNotify);
+ CPPUNIT_TEST(testReceiveFirstPresenceWithQuietPeriodDoesNotCountAsQuietPeriod);
+ CPPUNIT_TEST(testReceivePresenceDuringQuietPeriodDoesNotNotify);
+ CPPUNIT_TEST(testReceivePresenceDuringQuietPeriodResetsTimer);
+ CPPUNIT_TEST(testReceivePresenceAfterQuietPeriodNotifies);
+ CPPUNIT_TEST(testReceiveFirstPresenceAfterReconnectWithQuietPeriodDoesNotNotify);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ stanzaChannel = new DummyStanzaChannel();
+ notifier = new LoggingNotifier();
+ mucRegistry = new MUCRegistry();
+ user1 = JID("user1@bar.com/bla");
+ user2 = JID("user2@foo.com/baz");
+ avatarManager = new DummyAvatarManager();
+ roster = new XMPPRosterImpl();
+ nickResolver = new NickResolver(JID("foo@bar.com"), roster, NULL, mucRegistry);
+ presenceOracle = new PresenceOracle(stanzaChannel, roster);
+ timerFactory = new DummyTimerFactory();
+ }
+
+ void tearDown() {
+ delete timerFactory;
+ delete presenceOracle;
+ delete nickResolver;
+ delete roster;
+ delete avatarManager;
+ delete mucRegistry;
+ delete notifier;
+ delete stanzaChannel;
+ }
+
+ void testReceiveFirstPresenceCreatesAvailableNotification() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+
+ sendPresence(user1, StatusShow::Online);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ CPPUNIT_ASSERT_EQUAL(Notifier::ContactAvailable, notifier->notifications[0].type);
+ }
+
+ void testReceiveSecondPresenceCreatesStatusChangeNotification() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ sendPresence(user1, StatusShow::Away);
+ notifier->notifications.clear();
+
+ sendPresence(user1, StatusShow::Online);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ CPPUNIT_ASSERT_EQUAL(Notifier::ContactStatusChange, notifier->notifications[0].type);
+ }
+
+ void testReceiveUnavailablePresenceAfterAvailablePresenceCreatesUnavailableNotification() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ sendPresence(user1, StatusShow::Away);
+ notifier->notifications.clear();
+
+ sendUnavailablePresence(user1);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ CPPUNIT_ASSERT_EQUAL(Notifier::ContactUnavailable, notifier->notifications[0].type);
+ }
+
+ void testReceiveUnavailablePresenceWithoutAvailableDoesNotCreateNotification() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+
+ sendUnavailablePresence(user1);
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
+ }
+
+ void testReceiveAvailablePresenceAfterUnavailableCreatesAvailableNotification() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ sendPresence(user1, StatusShow::Away);
+ sendUnavailablePresence(user1);
+ notifier->notifications.clear();
+
+ sendPresence(user1, StatusShow::Away);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ CPPUNIT_ASSERT_EQUAL(Notifier::ContactAvailable, notifier->notifications[0].type);
+ }
+
+ void testReceiveAvailablePresenceAfterReconnectCreatesAvailableNotification() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ sendPresence(user1, StatusShow::Away);
+ stanzaChannel->setAvailable(false);
+ stanzaChannel->setAvailable(true);
+ notifier->notifications.clear();
+
+ sendPresence(user1, StatusShow::Away);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ CPPUNIT_ASSERT_EQUAL(Notifier::ContactAvailable, notifier->notifications[0].type);
+ }
- void testReceiveAvailablePresenceFromMUCDoesNotCreateNotification() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- mucRegistry->addMUC(JID("teaparty@wonderland.lit"));
+ void testReceiveAvailablePresenceFromMUCDoesNotCreateNotification() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ mucRegistry->addMUC(JID("teaparty@wonderland.lit"));
- sendPresence(JID("teaparty@wonderland.lit/Alice"), StatusShow::Away);
+ sendPresence(JID("teaparty@wonderland.lit/Alice"), StatusShow::Away);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
- }
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
+ }
- void testNotificationPicture() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- avatarManager->avatars[user1] = createByteArray("abcdef");
+ void testNotificationPicture() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ avatarManager->avatars[user1] = createByteArray("abcdef");
- sendPresence(user1, StatusShow::Online);
+ sendPresence(user1, StatusShow::Online);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- CPPUNIT_ASSERT_EQUAL(boost::filesystem::path("/avatars/user1@bar.com/bla"), notifier->notifications[0].picture);
- }
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ CPPUNIT_ASSERT_EQUAL(boost::filesystem::path("/avatars/user1@bar.com/bla"), notifier->notifications[0].picture);
+ }
- void testNotificationActivationEmitsSignal() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ void testNotificationActivationEmitsSignal() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- sendPresence(user1, StatusShow::Online);
- CPPUNIT_ASSERT(notifier->notifications[0].callback);
- notifier->notifications[0].callback();
+ sendPresence(user1, StatusShow::Online);
+ CPPUNIT_ASSERT(notifier->notifications[0].callback);
+ notifier->notifications[0].callback();
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(activatedNotifications.size()));
- CPPUNIT_ASSERT_EQUAL(user1, activatedNotifications[0]);
- }
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(activatedNotifications.size()));
+ CPPUNIT_ASSERT_EQUAL(user1, activatedNotifications[0]);
+ }
- void testNotificationSubjectContainsNameForJIDInRoster() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- roster->addContact(user1.toBare(), "User 1", std::vector<std::string>(), RosterItemPayload::Both);
+ void testNotificationSubjectContainsNameForJIDInRoster() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ roster->addContact(user1.toBare(), "User 1", std::vector<std::string>(), RosterItemPayload::Both);
- sendPresence(user1, StatusShow::Online);
+ sendPresence(user1, StatusShow::Online);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- std::string subject = notifier->notifications[0].subject;
- CPPUNIT_ASSERT(subject.find("User 1") != std::string::npos);
- }
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ std::string subject = notifier->notifications[0].subject;
+ CPPUNIT_ASSERT(subject.find("User 1") != std::string::npos);
+ }
- void testNotificationSubjectContainsJIDForJIDNotInRoster() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ void testNotificationSubjectContainsJIDForJIDNotInRoster() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- sendPresence(user1, StatusShow::Online);
+ sendPresence(user1, StatusShow::Online);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- std::string subject = notifier->notifications[0].subject;
- CPPUNIT_ASSERT(subject.find(user1.toBare().toString()) != std::string::npos);
- }
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ std::string subject = notifier->notifications[0].subject;
+ CPPUNIT_ASSERT(subject.find(user1.toBare().toString()) != std::string::npos);
+ }
- void testNotificationSubjectContainsStatus() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ void testNotificationSubjectContainsStatus() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- sendPresence(user1, StatusShow::Away);
+ sendPresence(user1, StatusShow::Away);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- std::string subject = notifier->notifications[0].subject;
- CPPUNIT_ASSERT(subject.find("Away") != std::string::npos);
- }
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ std::string subject = notifier->notifications[0].subject;
+ CPPUNIT_ASSERT(subject.find("Away") != std::string::npos);
+ }
- void testNotificationMessageContainsStatusMessage() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ void testNotificationMessageContainsStatusMessage() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- sendPresence(user1, StatusShow::Away);
+ sendPresence(user1, StatusShow::Away);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- CPPUNIT_ASSERT(notifier->notifications[0].description.find("Status Message") != std::string::npos);
- }
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ CPPUNIT_ASSERT(notifier->notifications[0].description.find("Status Message") != std::string::npos);
+ }
- void testReceiveFirstPresenceWithQuietPeriodDoesNotNotify() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- testling->setInitialQuietPeriodMS(10);
+ void testReceiveFirstPresenceWithQuietPeriodDoesNotNotify() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ testling->setInitialQuietPeriodMS(10);
- sendPresence(user1, StatusShow::Online);
+ sendPresence(user1, StatusShow::Online);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
- }
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
+ }
- void testReceivePresenceDuringQuietPeriodDoesNotNotify() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- testling->setInitialQuietPeriodMS(10);
+ void testReceivePresenceDuringQuietPeriodDoesNotNotify() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ testling->setInitialQuietPeriodMS(10);
- sendPresence(user1, StatusShow::Online);
- timerFactory->setTime(1);
- sendPresence(user2, StatusShow::Away);
+ sendPresence(user1, StatusShow::Online);
+ timerFactory->setTime(1);
+ sendPresence(user2, StatusShow::Away);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
- }
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
+ }
- void testReceivePresenceDuringQuietPeriodResetsTimer() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- testling->setInitialQuietPeriodMS(10);
+ void testReceivePresenceDuringQuietPeriodResetsTimer() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ testling->setInitialQuietPeriodMS(10);
- sendPresence(user1, StatusShow::Online);
- timerFactory->setTime(9);
- sendPresence(user2, StatusShow::Away);
- timerFactory->setTime(18);
- sendPresence(user1, StatusShow::Away);
+ sendPresence(user1, StatusShow::Online);
+ timerFactory->setTime(9);
+ sendPresence(user2, StatusShow::Away);
+ timerFactory->setTime(18);
+ sendPresence(user1, StatusShow::Away);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
- }
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
+ }
- void testReceivePresenceAfterQuietPeriodNotifies() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- testling->setInitialQuietPeriodMS(10);
-
- sendPresence(user1, StatusShow::Online);
- timerFactory->setTime(11);
- sendPresence(user2, StatusShow::Away);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
- }
-
- void testReceiveFirstPresenceWithQuietPeriodDoesNotCountAsQuietPeriod() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- testling->setInitialQuietPeriodMS(10);
-
- timerFactory->setTime(11);
- sendPresence(user1, StatusShow::Away);
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
- }
-
- void testReceiveFirstPresenceAfterReconnectWithQuietPeriodDoesNotNotify() {
- boost::shared_ptr<PresenceNotifier> testling = createNotifier();
- testling->setInitialQuietPeriodMS(10);
- sendPresence(user1, StatusShow::Online);
- timerFactory->setTime(15);
- notifier->notifications.clear();
-
- stanzaChannel->setAvailable(false);
- stanzaChannel->setAvailable(true);
- sendPresence(user1, StatusShow::Online);
- timerFactory->setTime(21);
- sendPresence(user2, StatusShow::Online);
-
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
- }
-
-
- private:
- boost::shared_ptr<PresenceNotifier> createNotifier() {
- boost::shared_ptr<PresenceNotifier> result(new PresenceNotifier(stanzaChannel, notifier, mucRegistry, avatarManager, nickResolver, presenceOracle, timerFactory));
- result->onNotificationActivated.connect(boost::bind(&PresenceNotifierTest::handleNotificationActivated, this, _1));
- result->setInitialQuietPeriodMS(0);
- return result;
- }
-
- void sendPresence(const JID& jid, StatusShow::Type type) {
- boost::shared_ptr<Presence> presence(new Presence());
- presence->setFrom(jid);
- presence->setShow(type);
- presence->setStatus("Status Message");
- stanzaChannel->onPresenceReceived(presence);
- }
-
- void sendUnavailablePresence(const JID& jid) {
- boost::shared_ptr<Presence> presence(new Presence());
- presence->setType(Presence::Unavailable);
- presence->setFrom(jid);
- stanzaChannel->onPresenceReceived(presence);
- }
-
- void handleNotificationActivated(const JID& j) {
- activatedNotifications.push_back(j);
- }
-
- private:
- DummyStanzaChannel* stanzaChannel;
- LoggingNotifier* notifier;
- MUCRegistry* mucRegistry;
- DummyAvatarManager* avatarManager;
- XMPPRosterImpl* roster;
- NickResolver* nickResolver;
- PresenceOracle* presenceOracle;
- DummyTimerFactory* timerFactory;
- JID user1;
- JID user2;
- std::vector<JID> activatedNotifications;
+ void testReceivePresenceAfterQuietPeriodNotifies() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ testling->setInitialQuietPeriodMS(10);
+
+ sendPresence(user1, StatusShow::Online);
+ timerFactory->setTime(11);
+ sendPresence(user2, StatusShow::Away);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(notifier->notifications.size()));
+ }
+
+ void testReceiveFirstPresenceWithQuietPeriodDoesNotCountAsQuietPeriod() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ testling->setInitialQuietPeriodMS(10);
+
+ timerFactory->setTime(11);
+ sendPresence(user1, StatusShow::Away);
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
+ }
+
+ void testReceiveFirstPresenceAfterReconnectWithQuietPeriodDoesNotNotify() {
+ boost::shared_ptr<PresenceNotifier> testling = createNotifier();
+ testling->setInitialQuietPeriodMS(10);
+ sendPresence(user1, StatusShow::Online);
+ timerFactory->setTime(15);
+ notifier->notifications.clear();
+
+ stanzaChannel->setAvailable(false);
+ stanzaChannel->setAvailable(true);
+ sendPresence(user1, StatusShow::Online);
+ timerFactory->setTime(21);
+ sendPresence(user2, StatusShow::Online);
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(notifier->notifications.size()));
+ }
+
+
+ private:
+ boost::shared_ptr<PresenceNotifier> createNotifier() {
+ boost::shared_ptr<PresenceNotifier> result(new PresenceNotifier(stanzaChannel, notifier, mucRegistry, avatarManager, nickResolver, presenceOracle, timerFactory));
+ result->onNotificationActivated.connect(boost::bind(&PresenceNotifierTest::handleNotificationActivated, this, _1));
+ result->setInitialQuietPeriodMS(0);
+ return result;
+ }
+
+ void sendPresence(const JID& jid, StatusShow::Type type) {
+ boost::shared_ptr<Presence> presence(new Presence());
+ presence->setFrom(jid);
+ presence->setShow(type);
+ presence->setStatus("Status Message");
+ stanzaChannel->onPresenceReceived(presence);
+ }
+
+ void sendUnavailablePresence(const JID& jid) {
+ boost::shared_ptr<Presence> presence(new Presence());
+ presence->setType(Presence::Unavailable);
+ presence->setFrom(jid);
+ stanzaChannel->onPresenceReceived(presence);
+ }
+
+ void handleNotificationActivated(const JID& j) {
+ activatedNotifications.push_back(j);
+ }
+
+ private:
+ DummyStanzaChannel* stanzaChannel;
+ LoggingNotifier* notifier;
+ MUCRegistry* mucRegistry;
+ DummyAvatarManager* avatarManager;
+ XMPPRosterImpl* roster;
+ NickResolver* nickResolver;
+ PresenceOracle* presenceOracle;
+ DummyTimerFactory* timerFactory;
+ JID user1;
+ JID user2;
+ std::vector<JID> activatedNotifications;
};
CPPUNIT_TEST_SUITE_REGISTRATION(PresenceNotifierTest);
diff --git a/Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp b/Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp
index 266cd64..be35468 100644
--- a/Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp
+++ b/Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp
@@ -12,33 +12,33 @@
using namespace Swift;
class PreviousStatusStoreTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(PreviousStatusStoreTest);
- CPPUNIT_TEST(testGetAll);
- //CPPUNIT_TEST(testGetAllLimited);
- //CPPUNIT_TEST(testGetSuggestionsInexact);
- //CPPUNIT_TEST(testGetSuggestionsExact);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(PreviousStatusStoreTest);
+ CPPUNIT_TEST(testGetAll);
+ //CPPUNIT_TEST(testGetAllLimited);
+ //CPPUNIT_TEST(testGetSuggestionsInexact);
+ //CPPUNIT_TEST(testGetSuggestionsExact);
+ CPPUNIT_TEST_SUITE_END();
public:
- void setUp() {
- store_ = new PreviousStatusStore();
- store_->addStatus(StatusShow::Online, "At home in the study");
- store_->addStatus(StatusShow::DND, "In a meeting");
- store_->addStatus(StatusShow::DND, "With a client");
- store_->addStatus(StatusShow::Away, "Walking the elephant");
- store_->addStatus(StatusShow::Online, "In the office, at my desk");
- }
+ void setUp() {
+ store_ = new PreviousStatusStore();
+ store_->addStatus(StatusShow::Online, "At home in the study");
+ store_->addStatus(StatusShow::DND, "In a meeting");
+ store_->addStatus(StatusShow::DND, "With a client");
+ store_->addStatus(StatusShow::Away, "Walking the elephant");
+ store_->addStatus(StatusShow::Online, "In the office, at my desk");
+ }
- void tearDown() {
- delete store_;
- }
+ void tearDown() {
+ delete store_;
+ }
- void testGetAll() {
+ void testGetAll() {
- }
+ }
private:
- PreviousStatusStore* store_;
+ PreviousStatusStore* store_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(PreviousStatusStoreTest);
diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp
index f62a94a..91f01c8 100644
--- a/Swift/Controllers/WhiteboardManager.cpp
+++ b/Swift/Controllers/WhiteboardManager.cpp
@@ -25,121 +25,121 @@
#include <Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h>
namespace Swift {
- typedef std::pair<JID, WhiteboardWindow*> JIDWhiteboardWindowPair;
+ typedef std::pair<JID, WhiteboardWindow*> JIDWhiteboardWindowPair;
- WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, NickResolver* nickResolver, WhiteboardSessionManager* whiteboardSessionManager) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), nickResolver_(nickResolver), whiteboardSessionManager_(whiteboardSessionManager) {
+ WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, NickResolver* nickResolver, WhiteboardSessionManager* whiteboardSessionManager) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), nickResolver_(nickResolver), whiteboardSessionManager_(whiteboardSessionManager) {
#ifdef SWIFT_EXPERIMENTAL_WB
- whiteboardSessionManager_->onSessionRequest.connect(boost::bind(&WhiteboardManager::handleIncomingSession, this, _1));
+ whiteboardSessionManager_->onSessionRequest.connect(boost::bind(&WhiteboardManager::handleIncomingSession, this, _1));
#endif
- uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1));
- }
-
- WhiteboardManager::~WhiteboardManager() {
- foreach (JIDWhiteboardWindowPair whiteboardWindowPair, whiteboardWindows_) {
- delete whiteboardWindowPair.second;
- }
- }
-
- WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session) {
- WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(session);
- window->setName(nickResolver_->jidToNick(contact));
- whiteboardWindows_[contact.toBare()] = window;
- return window;
- }
-
- WhiteboardWindow* WhiteboardManager::findWhiteboardWindow(const JID& contact) {
- if (whiteboardWindows_.find(contact.toBare()) == whiteboardWindows_.end()) {
- return NULL;
- }
- return whiteboardWindows_[contact.toBare()];
- }
-
- void WhiteboardManager::handleUIEvent(boost::shared_ptr<UIEvent> event) {
- boost::shared_ptr<RequestWhiteboardUIEvent> requestWhiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event);
- if (requestWhiteboardEvent) {
- requestSession(requestWhiteboardEvent->getContact());
- }
- boost::shared_ptr<AcceptWhiteboardSessionUIEvent> sessionAcceptEvent = boost::dynamic_pointer_cast<AcceptWhiteboardSessionUIEvent>(event);
- if (sessionAcceptEvent) {
- acceptSession(sessionAcceptEvent->getContact());
- }
- boost::shared_ptr<CancelWhiteboardSessionUIEvent> sessionCancelEvent = boost::dynamic_pointer_cast<CancelWhiteboardSessionUIEvent>(event);
- if (sessionCancelEvent) {
- cancelSession(sessionCancelEvent->getContact());
- }
- boost::shared_ptr<ShowWhiteboardUIEvent> showWindowEvent = boost::dynamic_pointer_cast<ShowWhiteboardUIEvent>(event);
- if (showWindowEvent) {
- WhiteboardWindow* window = findWhiteboardWindow(showWindowEvent->getContact());
- if (window != NULL) {
- window->activateWindow();
- }
- }
- }
-
- void WhiteboardManager::acceptSession(const JID& from) {
- IncomingWhiteboardSession::ref session = boost::dynamic_pointer_cast<IncomingWhiteboardSession>(whiteboardSessionManager_->getSession(from));
- WhiteboardWindow* window = findWhiteboardWindow(from);
- if (session && window) {
- session->accept();
- window->show();
- }
- }
-
- void WhiteboardManager::requestSession(const JID& contact) {
- WhiteboardSession::ref session = whiteboardSessionManager_->requestSession(contact);
- session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1));
- session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1));
- session->onRequestRejected.connect(boost::bind(&WhiteboardManager::handleRequestReject, this, _1));
-
- WhiteboardWindow* window = findWhiteboardWindow(contact);
- if (window == NULL) {
- createNewWhiteboardWindow(contact, session);
- } else {
- window->setSession(session);
- }
- onSessionRequest(session->getTo(), true);
- }
-
- void WhiteboardManager::cancelSession(const JID& from) {
- WhiteboardSession::ref session = whiteboardSessionManager_->getSession(from);
- if (session) {
- session->cancel();
- }
- }
-
- void WhiteboardManager::handleIncomingSession(IncomingWhiteboardSession::ref session) {
- session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1));
- session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1));
-
- WhiteboardWindow* window = findWhiteboardWindow(session->getTo());
- if (window == NULL) {
- createNewWhiteboardWindow(session->getTo(), session);
- } else {
- window->setSession(session);
- }
-
- onSessionRequest(session->getTo(), false);
- }
-
- void WhiteboardManager::handleSessionTerminate(const JID& contact) {
- onSessionTerminate(contact);
- }
-
- void WhiteboardManager::handleSessionCancel(const JID& contact) {
- onSessionTerminate(contact);
- }
-
- void WhiteboardManager::handleSessionAccept(const JID& contact) {
- WhiteboardWindow* window = findWhiteboardWindow(contact);
- if (window != NULL) {
- window->show();
- }
- onRequestAccepted(contact);
- }
-
- void WhiteboardManager::handleRequestReject(const JID& contact) {
- onRequestRejected(contact);
- }
+ uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1));
+ }
+
+ WhiteboardManager::~WhiteboardManager() {
+ foreach (JIDWhiteboardWindowPair whiteboardWindowPair, whiteboardWindows_) {
+ delete whiteboardWindowPair.second;
+ }
+ }
+
+ WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session) {
+ WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(session);
+ window->setName(nickResolver_->jidToNick(contact));
+ whiteboardWindows_[contact.toBare()] = window;
+ return window;
+ }
+
+ WhiteboardWindow* WhiteboardManager::findWhiteboardWindow(const JID& contact) {
+ if (whiteboardWindows_.find(contact.toBare()) == whiteboardWindows_.end()) {
+ return NULL;
+ }
+ return whiteboardWindows_[contact.toBare()];
+ }
+
+ void WhiteboardManager::handleUIEvent(boost::shared_ptr<UIEvent> event) {
+ boost::shared_ptr<RequestWhiteboardUIEvent> requestWhiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event);
+ if (requestWhiteboardEvent) {
+ requestSession(requestWhiteboardEvent->getContact());
+ }
+ boost::shared_ptr<AcceptWhiteboardSessionUIEvent> sessionAcceptEvent = boost::dynamic_pointer_cast<AcceptWhiteboardSessionUIEvent>(event);
+ if (sessionAcceptEvent) {
+ acceptSession(sessionAcceptEvent->getContact());
+ }
+ boost::shared_ptr<CancelWhiteboardSessionUIEvent> sessionCancelEvent = boost::dynamic_pointer_cast<CancelWhiteboardSessionUIEvent>(event);
+ if (sessionCancelEvent) {
+ cancelSession(sessionCancelEvent->getContact());
+ }
+ boost::shared_ptr<ShowWhiteboardUIEvent> showWindowEvent = boost::dynamic_pointer_cast<ShowWhiteboardUIEvent>(event);
+ if (showWindowEvent) {
+ WhiteboardWindow* window = findWhiteboardWindow(showWindowEvent->getContact());
+ if (window != NULL) {
+ window->activateWindow();
+ }
+ }
+ }
+
+ void WhiteboardManager::acceptSession(const JID& from) {
+ IncomingWhiteboardSession::ref session = boost::dynamic_pointer_cast<IncomingWhiteboardSession>(whiteboardSessionManager_->getSession(from));
+ WhiteboardWindow* window = findWhiteboardWindow(from);
+ if (session && window) {
+ session->accept();
+ window->show();
+ }
+ }
+
+ void WhiteboardManager::requestSession(const JID& contact) {
+ WhiteboardSession::ref session = whiteboardSessionManager_->requestSession(contact);
+ session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1));
+ session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1));
+ session->onRequestRejected.connect(boost::bind(&WhiteboardManager::handleRequestReject, this, _1));
+
+ WhiteboardWindow* window = findWhiteboardWindow(contact);
+ if (window == NULL) {
+ createNewWhiteboardWindow(contact, session);
+ } else {
+ window->setSession(session);
+ }
+ onSessionRequest(session->getTo(), true);
+ }
+
+ void WhiteboardManager::cancelSession(const JID& from) {
+ WhiteboardSession::ref session = whiteboardSessionManager_->getSession(from);
+ if (session) {
+ session->cancel();
+ }
+ }
+
+ void WhiteboardManager::handleIncomingSession(IncomingWhiteboardSession::ref session) {
+ session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1));
+ session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1));
+
+ WhiteboardWindow* window = findWhiteboardWindow(session->getTo());
+ if (window == NULL) {
+ createNewWhiteboardWindow(session->getTo(), session);
+ } else {
+ window->setSession(session);
+ }
+
+ onSessionRequest(session->getTo(), false);
+ }
+
+ void WhiteboardManager::handleSessionTerminate(const JID& contact) {
+ onSessionTerminate(contact);
+ }
+
+ void WhiteboardManager::handleSessionCancel(const JID& contact) {
+ onSessionTerminate(contact);
+ }
+
+ void WhiteboardManager::handleSessionAccept(const JID& contact) {
+ WhiteboardWindow* window = findWhiteboardWindow(contact);
+ if (window != NULL) {
+ window->show();
+ }
+ onRequestAccepted(contact);
+ }
+
+ void WhiteboardManager::handleRequestReject(const JID& contact) {
+ onRequestRejected(contact);
+ }
}
diff --git a/Swift/Controllers/WhiteboardManager.h b/Swift/Controllers/WhiteboardManager.h
index 863dd60..35ed9bd 100644
--- a/Swift/Controllers/WhiteboardManager.h
+++ b/Swift/Controllers/WhiteboardManager.h
@@ -26,40 +26,40 @@
#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h>
namespace Swift {
- class WhiteboardSessionManager;
- class NickResolver;
+ class WhiteboardSessionManager;
+ class NickResolver;
- class WhiteboardManager {
- public:
- WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, NickResolver* nickResolver, WhiteboardSessionManager* whiteboardSessionManager);
- ~WhiteboardManager();
+ class WhiteboardManager {
+ public:
+ WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, NickResolver* nickResolver, WhiteboardSessionManager* whiteboardSessionManager);
+ ~WhiteboardManager();
- WhiteboardWindow* createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session);
+ WhiteboardWindow* createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session);
- public:
- boost::signal< void (const JID&, bool senderIsSelf)> onSessionRequest;
- boost::signal< void (const JID&)> onSessionTerminate;
- boost::signal< void (const JID&)> onRequestAccepted;
- boost::signal< void (const JID&)> onRequestRejected;
+ public:
+ boost::signal< void (const JID&, bool senderIsSelf)> onSessionRequest;
+ boost::signal< void (const JID&)> onSessionTerminate;
+ boost::signal< void (const JID&)> onRequestAccepted;
+ boost::signal< void (const JID&)> onRequestRejected;
- private:
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void handleSessionTerminate(const JID& contact);
- void handleSessionCancel(const JID& contact);
- void handleSessionAccept(const JID& contact);
- void handleRequestReject(const JID& contact);
- void handleIncomingSession(IncomingWhiteboardSession::ref session);
- void acceptSession(const JID& from);
- void requestSession(const JID& contact);
- void cancelSession(const JID& from);
- WhiteboardWindow* findWhiteboardWindow(const JID& contact);
+ private:
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleSessionTerminate(const JID& contact);
+ void handleSessionCancel(const JID& contact);
+ void handleSessionAccept(const JID& contact);
+ void handleRequestReject(const JID& contact);
+ void handleIncomingSession(IncomingWhiteboardSession::ref session);
+ void acceptSession(const JID& from);
+ void requestSession(const JID& contact);
+ void cancelSession(const JID& from);
+ WhiteboardWindow* findWhiteboardWindow(const JID& contact);
- private:
- std::map<JID, WhiteboardWindow*> whiteboardWindows_;
- WhiteboardWindowFactory* whiteboardWindowFactory_;
- UIEventStream* uiEventStream_;
- NickResolver* nickResolver_;
- boost::bsignals::scoped_connection uiEventConnection_;
- WhiteboardSessionManager* whiteboardSessionManager_;
- };
+ private:
+ std::map<JID, WhiteboardWindow*> whiteboardWindows_;
+ WhiteboardWindowFactory* whiteboardWindowFactory_;
+ UIEventStream* uiEventStream_;
+ NickResolver* nickResolver_;
+ boost::bsignals::scoped_connection uiEventConnection_;
+ WhiteboardSessionManager* whiteboardSessionManager_;
+ };
}
diff --git a/Swift/Controllers/XMLConsoleController.cpp b/Swift/Controllers/XMLConsoleController.cpp
index 22be4f6..175a4eb 100644
--- a/Swift/Controllers/XMLConsoleController.cpp
+++ b/Swift/Controllers/XMLConsoleController.cpp
@@ -12,34 +12,34 @@
namespace Swift {
XMLConsoleController::XMLConsoleController(UIEventStream* uiEventStream, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory) : xmlConsoleWidgetFactory(xmlConsoleWidgetFactory), xmlConsoleWidget(NULL) {
- uiEventStream->onUIEvent.connect(boost::bind(&XMLConsoleController::handleUIEvent, this, _1));
+ uiEventStream->onUIEvent.connect(boost::bind(&XMLConsoleController::handleUIEvent, this, _1));
}
XMLConsoleController::~XMLConsoleController() {
- delete xmlConsoleWidget;
+ delete xmlConsoleWidget;
}
void XMLConsoleController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
- boost::shared_ptr<RequestXMLConsoleUIEvent> event = boost::dynamic_pointer_cast<RequestXMLConsoleUIEvent>(rawEvent);
- if (event != NULL) {
- if (xmlConsoleWidget == NULL) {
- xmlConsoleWidget = xmlConsoleWidgetFactory->createXMLConsoleWidget();
- }
- xmlConsoleWidget->show();
- xmlConsoleWidget->activate();
- }
+ boost::shared_ptr<RequestXMLConsoleUIEvent> event = boost::dynamic_pointer_cast<RequestXMLConsoleUIEvent>(rawEvent);
+ if (event != NULL) {
+ if (xmlConsoleWidget == NULL) {
+ xmlConsoleWidget = xmlConsoleWidgetFactory->createXMLConsoleWidget();
+ }
+ xmlConsoleWidget->show();
+ xmlConsoleWidget->activate();
+ }
}
void XMLConsoleController::handleDataRead(const SafeByteArray& data) {
- if (xmlConsoleWidget) {
- xmlConsoleWidget->handleDataRead(data);
- }
+ if (xmlConsoleWidget) {
+ xmlConsoleWidget->handleDataRead(data);
+ }
}
void XMLConsoleController::handleDataWritten(const SafeByteArray& data) {
- if (xmlConsoleWidget) {
- xmlConsoleWidget->handleDataWritten(data);
- }
+ if (xmlConsoleWidget) {
+ xmlConsoleWidget->handleDataWritten(data);
+ }
}
}
diff --git a/Swift/Controllers/XMLConsoleController.h b/Swift/Controllers/XMLConsoleController.h
index bd4d256..eac27d3 100644
--- a/Swift/Controllers/XMLConsoleController.h
+++ b/Swift/Controllers/XMLConsoleController.h
@@ -15,24 +15,24 @@
#include <Swift/Controllers/UIEvents/UIEventStream.h>
namespace Swift {
-
- class XMLConsoleWidgetFactory;
- class XMLConsoleWidget;
-
- class XMLConsoleController {
- public:
- XMLConsoleController(UIEventStream* uiEventStream, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory);
- ~XMLConsoleController();
-
- public:
- void handleDataRead(const SafeByteArray& data);
- void handleDataWritten(const SafeByteArray& data);
-
- private:
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
-
- private:
- XMLConsoleWidgetFactory* xmlConsoleWidgetFactory;
- XMLConsoleWidget* xmlConsoleWidget;
- };
+
+ class XMLConsoleWidgetFactory;
+ class XMLConsoleWidget;
+
+ class XMLConsoleController {
+ public:
+ XMLConsoleController(UIEventStream* uiEventStream, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory);
+ ~XMLConsoleController();
+
+ public:
+ void handleDataRead(const SafeByteArray& data);
+ void handleDataWritten(const SafeByteArray& data);
+
+ private:
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+
+ private:
+ XMLConsoleWidgetFactory* xmlConsoleWidgetFactory;
+ XMLConsoleWidget* xmlConsoleWidget;
+ };
}
diff --git a/Swift/Controllers/XMPPEvents/ErrorEvent.h b/Swift/Controllers/XMPPEvents/ErrorEvent.h
index 0b18dfc..959f210 100644
--- a/Swift/Controllers/XMPPEvents/ErrorEvent.h
+++ b/Swift/Controllers/XMPPEvents/ErrorEvent.h
@@ -17,16 +17,16 @@
#include <Swift/Controllers/XMPPEvents/StanzaEvent.h>
namespace Swift {
- class ErrorEvent : public StanzaEvent {
- public:
- ErrorEvent(const JID& jid, const std::string& text) : jid_(jid), text_(text){}
- virtual ~ErrorEvent(){}
- const JID& getJID() const {return jid_;}
- const std::string& getText() const {return text_;}
-
- private:
- JID jid_;
- std::string text_;
- };
+ class ErrorEvent : public StanzaEvent {
+ public:
+ ErrorEvent(const JID& jid, const std::string& text) : jid_(jid), text_(text){}
+ virtual ~ErrorEvent(){}
+ const JID& getJID() const {return jid_;}
+ const std::string& getText() const {return text_;}
+
+ private:
+ JID jid_;
+ std::string text_;
+ };
}
diff --git a/Swift/Controllers/XMPPEvents/EventController.cpp b/Swift/Controllers/XMPPEvents/EventController.cpp
index bbe7356..4c6b3bc 100644
--- a/Swift/Controllers/XMPPEvents/EventController.cpp
+++ b/Swift/Controllers/XMPPEvents/EventController.cpp
@@ -25,56 +25,56 @@ EventController::EventController() {
}
EventController::~EventController() {
- foreach(boost::shared_ptr<StanzaEvent> event, events_) {
- event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event));
- }
+ foreach(boost::shared_ptr<StanzaEvent> event, events_) {
+ event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event));
+ }
}
void EventController::handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceEvent) {
- boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(sourceEvent);
- boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent);
- boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(sourceEvent);
- boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent);
- boost::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(sourceEvent);
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(sourceEvent);
+ boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent);
+ boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(sourceEvent);
+ boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent);
+ boost::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(sourceEvent);
- /* If it's a duplicate subscription request, remove the previous request first */
- if (subscriptionEvent) {
- EventList existingEvents(events_);
- foreach(boost::shared_ptr<StanzaEvent> existingEvent, existingEvents) {
- boost::shared_ptr<SubscriptionRequestEvent> existingSubscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(existingEvent);
- if (existingSubscriptionEvent) {
- if (existingSubscriptionEvent->getJID() == subscriptionEvent->getJID()) {
- existingEvent->conclude();
- }
- }
- }
- }
+ /* If it's a duplicate subscription request, remove the previous request first */
+ if (subscriptionEvent) {
+ EventList existingEvents(events_);
+ foreach(boost::shared_ptr<StanzaEvent> existingEvent, existingEvents) {
+ boost::shared_ptr<SubscriptionRequestEvent> existingSubscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(existingEvent);
+ if (existingSubscriptionEvent) {
+ if (existingSubscriptionEvent->getJID() == subscriptionEvent->getJID()) {
+ existingEvent->conclude();
+ }
+ }
+ }
+ }
- if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent || incomingFileTransferEvent) {
- events_.push_back(sourceEvent);
- sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent));
- onEventQueueLengthChange(boost::numeric_cast<int>(events_.size()));
- onEventQueueEventAdded(sourceEvent);
- if (sourceEvent->getConcluded()) {
- handleEventConcluded(sourceEvent);
- }
- }
+ if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent || incomingFileTransferEvent) {
+ events_.push_back(sourceEvent);
+ sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent));
+ onEventQueueLengthChange(boost::numeric_cast<int>(events_.size()));
+ onEventQueueEventAdded(sourceEvent);
+ if (sourceEvent->getConcluded()) {
+ handleEventConcluded(sourceEvent);
+ }
+ }
}
void EventController::handleEventConcluded(boost::shared_ptr<StanzaEvent> event) {
- event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event));
- events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end());
- onEventQueueLengthChange(boost::numeric_cast<int>(events_.size()));
+ event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event));
+ events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end());
+ onEventQueueLengthChange(boost::numeric_cast<int>(events_.size()));
}
void EventController::disconnectAll() {
- onEventQueueLengthChange.disconnect_all_slots();
- onEventQueueEventAdded.disconnect_all_slots();
+ onEventQueueLengthChange.disconnect_all_slots();
+ onEventQueueEventAdded.disconnect_all_slots();
}
void EventController::clear() {
- events_.clear();
- onEventQueueLengthChange(0);
+ events_.clear();
+ onEventQueueLengthChange(0);
}
}
diff --git a/Swift/Controllers/XMPPEvents/EventController.h b/Swift/Controllers/XMPPEvents/EventController.h
index 35938ac..3081449 100644
--- a/Swift/Controllers/XMPPEvents/EventController.h
+++ b/Swift/Controllers/XMPPEvents/EventController.h
@@ -16,21 +16,21 @@
#include <Swift/Controllers/XMPPEvents/StanzaEvent.h>
namespace Swift {
- typedef std::vector<boost::shared_ptr<StanzaEvent> > EventList;
- class EventController {
- public:
- EventController();
- ~EventController();
-
- void handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceEvent);
- boost::signal<void (int)> onEventQueueLengthChange;
- boost::signal<void (boost::shared_ptr<StanzaEvent>)> onEventQueueEventAdded;
- const EventList& getEvents() const {return events_;}
- void disconnectAll();
- void clear();
-
- private:
- void handleEventConcluded(boost::shared_ptr<StanzaEvent> event);
- EventList events_;
- };
+ typedef std::vector<boost::shared_ptr<StanzaEvent> > EventList;
+ class EventController {
+ public:
+ EventController();
+ ~EventController();
+
+ void handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceEvent);
+ boost::signal<void (int)> onEventQueueLengthChange;
+ boost::signal<void (boost::shared_ptr<StanzaEvent>)> onEventQueueEventAdded;
+ const EventList& getEvents() const {return events_;}
+ void disconnectAll();
+ void clear();
+
+ private:
+ void handleEventConcluded(boost::shared_ptr<StanzaEvent> event);
+ EventList events_;
+ };
}
diff --git a/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h b/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h
index 24af640..4c128e8 100644
--- a/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h
+++ b/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h
@@ -13,18 +13,18 @@
#include <Swift/Controllers/XMPPEvents/StanzaEvent.h>
namespace Swift {
- class IncomingFileTransferEvent : public StanzaEvent {
- public:
- typedef boost::shared_ptr<IncomingFileTransferEvent> ref;
+ class IncomingFileTransferEvent : public StanzaEvent {
+ public:
+ typedef boost::shared_ptr<IncomingFileTransferEvent> ref;
- IncomingFileTransferEvent(const JID& sender) : sender_(sender) {}
+ IncomingFileTransferEvent(const JID& sender) : sender_(sender) {}
- const JID& getSender() const {
- return sender_;
- }
+ const JID& getSender() const {
+ return sender_;
+ }
- private:
- JID sender_;
- };
+ private:
+ JID sender_;
+ };
}
diff --git a/Swift/Controllers/XMPPEvents/MUCInviteEvent.h b/Swift/Controllers/XMPPEvents/MUCInviteEvent.h
index 1ae9891..7d333fb 100644
--- a/Swift/Controllers/XMPPEvents/MUCInviteEvent.h
+++ b/Swift/Controllers/XMPPEvents/MUCInviteEvent.h
@@ -22,26 +22,26 @@
namespace Swift {
- class MUCInviteEvent : public StanzaEvent {
- public:
- typedef boost::shared_ptr<MUCInviteEvent> ref;
-
- public:
- MUCInviteEvent(const JID& inviter, const JID& roomJID, const std::string& reason, const std::string& password, bool direct, bool impromptu) : inviter_(inviter), roomJID_(roomJID), reason_(reason), password_(password), direct_(direct), impromptu_(impromptu) {}
-
- const JID& getInviter() const { return inviter_; }
- const JID& getRoomJID() const { return roomJID_; }
- const std::string& getReason() const { return reason_; }
- const std::string& getPassword() const { return password_; }
- bool getDirect() const { return direct_; }
- bool getImpromptu() const { return impromptu_; }
-
- private:
- JID inviter_;
- JID roomJID_;
- std::string reason_;
- std::string password_;
- bool direct_;
- bool impromptu_;
- };
+ class MUCInviteEvent : public StanzaEvent {
+ public:
+ typedef boost::shared_ptr<MUCInviteEvent> ref;
+
+ public:
+ MUCInviteEvent(const JID& inviter, const JID& roomJID, const std::string& reason, const std::string& password, bool direct, bool impromptu) : inviter_(inviter), roomJID_(roomJID), reason_(reason), password_(password), direct_(direct), impromptu_(impromptu) {}
+
+ const JID& getInviter() const { return inviter_; }
+ const JID& getRoomJID() const { return roomJID_; }
+ const std::string& getReason() const { return reason_; }
+ const std::string& getPassword() const { return password_; }
+ bool getDirect() const { return direct_; }
+ bool getImpromptu() const { return impromptu_; }
+
+ private:
+ JID inviter_;
+ JID roomJID_;
+ std::string reason_;
+ std::string password_;
+ bool direct_;
+ bool impromptu_;
+ };
}
diff --git a/Swift/Controllers/XMPPEvents/MessageEvent.h b/Swift/Controllers/XMPPEvents/MessageEvent.h
index b5b1215..4ec0406 100644
--- a/Swift/Controllers/XMPPEvents/MessageEvent.h
+++ b/Swift/Controllers/XMPPEvents/MessageEvent.h
@@ -4,7 +4,7 @@
* See the COPYING file for more information.
*/
-#pragma once
+#pragma once
#include <cassert>
@@ -15,34 +15,34 @@
#include <Swift/Controllers/XMPPEvents/StanzaEvent.h>
namespace Swift {
- class MessageEvent : public StanzaEvent {
- public:
- typedef boost::shared_ptr<MessageEvent> ref;
+ class MessageEvent : public StanzaEvent {
+ public:
+ typedef boost::shared_ptr<MessageEvent> ref;
- MessageEvent(boost::shared_ptr<Message> stanza) : stanza_(stanza), targetsMe_(true) {}
+ MessageEvent(boost::shared_ptr<Message> stanza) : stanza_(stanza), targetsMe_(true) {}
- boost::shared_ptr<Message> getStanza() {return stanza_;}
+ boost::shared_ptr<Message> getStanza() {return stanza_;}
- bool isReadable() {
- return getStanza()->isError() || !getStanza()->getBody().get_value_or("").empty();
- }
+ bool isReadable() {
+ return getStanza()->isError() || !getStanza()->getBody().get_value_or("").empty();
+ }
- void read() {
- assert (isReadable());
- conclude();
- }
+ void read() {
+ assert (isReadable());
+ conclude();
+ }
- void setTargetsMe(bool targetsMe) {
- targetsMe_ = targetsMe;
- }
+ void setTargetsMe(bool targetsMe) {
+ targetsMe_ = targetsMe;
+ }
- bool targetsMe() const {
- return targetsMe_;
- }
+ bool targetsMe() const {
+ return targetsMe_;
+ }
- private:
- boost::shared_ptr<Message> stanza_;
- bool targetsMe_;
- };
+ private:
+ boost::shared_ptr<Message> stanza_;
+ bool targetsMe_;
+ };
}
diff --git a/Swift/Controllers/XMPPEvents/StanzaEvent.h b/Swift/Controllers/XMPPEvents/StanzaEvent.h
index e8d5eb9..fe97e23 100644
--- a/Swift/Controllers/XMPPEvents/StanzaEvent.h
+++ b/Swift/Controllers/XMPPEvents/StanzaEvent.h
@@ -12,18 +12,18 @@
#include <Swiften/Base/boost_bsignals.h>
namespace Swift {
- class StanzaEvent {
- public:
- StanzaEvent() : time_(boost::posix_time::microsec_clock::universal_time()) {concluded_ = false;}
- virtual ~StanzaEvent() {}
- void conclude() {concluded_ = true; onConclusion();}
- /** Do not call this directly from outside the class.
- * If you connect to this signal, you *must* disconnect from it manually. */
- boost::signal<void()> onConclusion;
- bool getConcluded() {return concluded_;}
- boost::posix_time::ptime getTime() {return time_;}
- private:
- bool concluded_;
- boost::posix_time::ptime time_;
- };
+ class StanzaEvent {
+ public:
+ StanzaEvent() : time_(boost::posix_time::microsec_clock::universal_time()) {concluded_ = false;}
+ virtual ~StanzaEvent() {}
+ void conclude() {concluded_ = true; onConclusion();}
+ /** Do not call this directly from outside the class.
+ * If you connect to this signal, you *must* disconnect from it manually. */
+ boost::signal<void()> onConclusion;
+ bool getConcluded() {return concluded_;}
+ boost::posix_time::ptime getTime() {return time_;}
+ private:
+ bool concluded_;
+ boost::posix_time::ptime time_;
+ };
}
diff --git a/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h b/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h
index a22399b..92922e9 100644
--- a/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h
+++ b/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h
@@ -17,31 +17,31 @@
#include <Swift/Controllers/XMPPEvents/StanzaEvent.h>
namespace Swift {
- class SubscriptionRequestEvent : public StanzaEvent {
- public:
- SubscriptionRequestEvent(const JID& jid, const std::string& reason) : jid_(jid), reason_(reason){}
- virtual ~SubscriptionRequestEvent(){}
- const JID& getJID() const {return jid_;}
- const std::string& getReason() const {return reason_;}
- boost::signal<void()> onAccept;
- boost::signal<void()> onDecline;
- void accept() {
- onAccept();
- conclude();
- }
-
- void decline() {
- onDecline();
- conclude();
- }
-
- void defer() {
- conclude();
- }
-
- private:
- JID jid_;
- std::string reason_;
- };
+ class SubscriptionRequestEvent : public StanzaEvent {
+ public:
+ SubscriptionRequestEvent(const JID& jid, const std::string& reason) : jid_(jid), reason_(reason){}
+ virtual ~SubscriptionRequestEvent(){}
+ const JID& getJID() const {return jid_;}
+ const std::string& getReason() const {return reason_;}
+ boost::signal<void()> onAccept;
+ boost::signal<void()> onDecline;
+ void accept() {
+ onAccept();
+ conclude();
+ }
+
+ void decline() {
+ onDecline();
+ conclude();
+ }
+
+ void defer() {
+ conclude();
+ }
+
+ private:
+ JID jid_;
+ std::string reason_;
+ };
}
diff --git a/Swift/Controllers/XMPPURIController.cpp b/Swift/Controllers/XMPPURIController.cpp
index 3deb2d8..57c0ca4 100644
--- a/Swift/Controllers/XMPPURIController.cpp
+++ b/Swift/Controllers/XMPPURIController.cpp
@@ -19,21 +19,21 @@
using namespace Swift;
XMPPURIController::XMPPURIController(URIHandler* uriHandler, UIEventStream* uiEventStream) : uriHandler(uriHandler), uiEventStream(uiEventStream) {
- uriHandler->onURI.connect(boost::bind(&XMPPURIController::handleURI, this, _1));
+ uriHandler->onURI.connect(boost::bind(&XMPPURIController::handleURI, this, _1));
}
XMPPURIController::~XMPPURIController() {
- uriHandler->onURI.disconnect(boost::bind(&XMPPURIController::handleURI, this, _1));
+ uriHandler->onURI.disconnect(boost::bind(&XMPPURIController::handleURI, this, _1));
}
void XMPPURIController::handleURI(const std::string& s) {
- XMPPURI uri = XMPPURI::fromString(s);
- if (!uri.isNull()) {
- if (uri.getQueryType() == "join") {
- uiEventStream->send(boost::make_shared<RequestJoinMUCUIEvent>(uri.getPath()));
- }
- else {
- uiEventStream->send(boost::make_shared<RequestChatUIEvent>(uri.getPath()));
- }
- }
+ XMPPURI uri = XMPPURI::fromString(s);
+ if (!uri.isNull()) {
+ if (uri.getQueryType() == "join") {
+ uiEventStream->send(boost::make_shared<RequestJoinMUCUIEvent>(uri.getPath()));
+ }
+ else {
+ uiEventStream->send(boost::make_shared<RequestChatUIEvent>(uri.getPath()));
+ }
+ }
}
diff --git a/Swift/Controllers/XMPPURIController.h b/Swift/Controllers/XMPPURIController.h
index 4938ad7..4d2fb5c 100644
--- a/Swift/Controllers/XMPPURIController.h
+++ b/Swift/Controllers/XMPPURIController.h
@@ -11,23 +11,23 @@
#include <Swiften/Base/boost_bsignals.h>
namespace Swift {
- class URIHandler;
- class JID;
- class UIEventStream;
+ class URIHandler;
+ class JID;
+ class UIEventStream;
- class XMPPURIController {
- public:
- XMPPURIController(URIHandler* uriHandler, UIEventStream* uiEventStream);
- ~XMPPURIController();
+ class XMPPURIController {
+ public:
+ XMPPURIController(URIHandler* uriHandler, UIEventStream* uiEventStream);
+ ~XMPPURIController();
- boost::signal<void (const JID&)> onStartChat;
- boost::signal<void (const JID&)> onJoinMUC;
+ boost::signal<void (const JID&)> onStartChat;
+ boost::signal<void (const JID&)> onJoinMUC;
- private:
- void handleURI(const std::string&);
+ private:
+ void handleURI(const std::string&);
- private:
- URIHandler* uriHandler;
- UIEventStream* uiEventStream;
- };
+ private:
+ URIHandler* uriHandler;
+ UIEventStream* uiEventStream;
+ };
}
diff --git a/Swift/QtUI/ApplicationTest/main.cpp b/Swift/QtUI/ApplicationTest/main.cpp
index 489865e..782bbf1 100644
--- a/Swift/QtUI/ApplicationTest/main.cpp
+++ b/Swift/QtUI/ApplicationTest/main.cpp
@@ -18,31 +18,31 @@
using namespace Swift;
class MyWidget : public QWidget {
- Q_OBJECT
-
- public:
- MyWidget() : application_("MyApplication") {
- QVBoxLayout *layout = new QVBoxLayout(this);
- input_ = new QLineEdit(this);
- layout->addWidget(input_);
- connect(input_, SIGNAL(returnPressed()), SLOT(handleReturnPressed()));
- }
-
- private slots:
- void handleReturnPressed() {
- application_.getApplicationMessageDisplay()->setMessage(Q2PSTRING(input_->text()));
- }
-
- private:
- PlatformApplication application_;
- QLineEdit* input_;
+ Q_OBJECT
+
+ public:
+ MyWidget() : application_("MyApplication") {
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ input_ = new QLineEdit(this);
+ layout->addWidget(input_);
+ connect(input_, SIGNAL(returnPressed()), SLOT(handleReturnPressed()));
+ }
+
+ private slots:
+ void handleReturnPressed() {
+ application_.getApplicationMessageDisplay()->setMessage(Q2PSTRING(input_->text()));
+ }
+
+ private:
+ PlatformApplication application_;
+ QLineEdit* input_;
};
int main(int argc, char* argv[]) {
- QApplication app(argc, argv);
- MyWidget widget;
- widget.show();
- return app.exec();
+ QApplication app(argc, argv);
+ MyWidget widget;
+ widget.show();
+ return app.exec();
}
#include "main.moc"
diff --git a/Swift/QtUI/CAPICertificateSelector.cpp b/Swift/QtUI/CAPICertificateSelector.cpp
index 953051b..36d8c54 100644
--- a/Swift/QtUI/CAPICertificateSelector.cpp
+++ b/Swift/QtUI/CAPICertificateSelector.cpp
@@ -23,94 +23,94 @@
namespace Swift {
/////Hmm, maybe we should not exlude the "location" column
-#define exclude_columns CRYPTUI_SELECT_LOCATION_COLUMN | CRYPTUI_SELECT_INTENDEDUSE_COLUMN
+#define exclude_columns CRYPTUI_SELECT_LOCATION_COLUMN | CRYPTUI_SELECT_INTENDEDUSE_COLUMN
#define SHA1_HASH_LENGTH 20
static std::string getCertUri(PCCERT_CONTEXT cert, const char * cert_store_name) {
- DWORD cbHash = SHA1_HASH_LENGTH;
- BYTE aHash[SHA1_HASH_LENGTH];
- std::string result("certstore:");
+ DWORD cbHash = SHA1_HASH_LENGTH;
+ BYTE aHash[SHA1_HASH_LENGTH];
+ std::string result("certstore:");
- result += cert_store_name;
- result += ":sha1:";
+ result += cert_store_name;
+ result += ":sha1:";
- if (CertGetCertificateContextProperty(cert, CERT_HASH_PROP_ID, aHash, &cbHash) == FALSE ) {
- return "";
- }
+ if (CertGetCertificateContextProperty(cert, CERT_HASH_PROP_ID, aHash, &cbHash) == FALSE ) {
+ return "";
+ }
- ByteArray byteArray = createByteArray((char *)(&aHash[0]), cbHash);
- result += Hexify::hexify(byteArray);
+ ByteArray byteArray = createByteArray((char *)(&aHash[0]), cbHash);
+ result += Hexify::hexify(byteArray);
- return result;
+ return result;
}
std::string selectCAPICertificate() {
- const char* certStoreName = "MY";
+ const char* certStoreName = "MY";
- DWORD storeFlags = CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG | CERT_SYSTEM_STORE_CURRENT_USER;
+ DWORD storeFlags = CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG | CERT_SYSTEM_STORE_CURRENT_USER;
- HCERTSTORE hstore = CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, 0, storeFlags, certStoreName);
- if (!hstore) {
- return "";
- }
+ HCERTSTORE hstore = CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, 0, storeFlags, certStoreName);
+ if (!hstore) {
+ return "";
+ }
- HWND hwnd = GetForegroundWindow();
- if (!hwnd) {
- hwnd = GetActiveWindow();
- }
+ HWND hwnd = GetForegroundWindow();
+ if (!hwnd) {
+ hwnd = GetActiveWindow();
+ }
- std::string certificateDialogTitle = QT_TRANSLATE_NOOP("", "TLS Client Certificate Selection");
- std::string certificateDialogPrompt = QT_TRANSLATE_NOOP("", "Select a certificate to use for authentication");
+ std::string certificateDialogTitle = QT_TRANSLATE_NOOP("", "TLS Client Certificate Selection");
+ std::string certificateDialogPrompt = QT_TRANSLATE_NOOP("", "Select a certificate to use for authentication");
- int titleLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, certificateDialogTitle.c_str(), -1, NULL, 0);
- int promptLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, certificateDialogPrompt.c_str(), -1, NULL, 0);
+ int titleLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, certificateDialogTitle.c_str(), -1, NULL, 0);
+ int promptLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, certificateDialogPrompt.c_str(), -1, NULL, 0);
- wchar_t* titleChars = new wchar_t[titleLength];
- wchar_t* promptChars = new wchar_t[promptLength];
+ wchar_t* titleChars = new wchar_t[titleLength];
+ wchar_t* promptChars = new wchar_t[promptLength];
- //titleChars[titleLength] = '\0';
- //promptChars[promptLength] = '\0';
+ //titleChars[titleLength] = '\0';
+ //promptChars[promptLength] = '\0';
- titleLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, certificateDialogTitle.c_str(), -1, titleChars, titleLength);
- promptLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, certificateDialogPrompt.c_str(), -1, promptChars, promptLength);
+ titleLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, certificateDialogTitle.c_str(), -1, titleChars, titleLength);
+ promptLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, certificateDialogPrompt.c_str(), -1, promptChars, promptLength);
- if (titleLength == 0 || promptLength == 0) {
- int error = GetLastError();
- switch (error) {
- case ERROR_INSUFFICIENT_BUFFER: SWIFT_LOG(error) << "Insufficient buffer for rendering cert dialog" << std::endl;break;
- case ERROR_INVALID_FLAGS: SWIFT_LOG(error) << "Invalid flags for rendering cert dialog" << std::endl;break;
- case ERROR_INVALID_PARAMETER: SWIFT_LOG(error) << "Invalid parameter for rendering cert dialog" << std::endl;break;
- case ERROR_NO_UNICODE_TRANSLATION: SWIFT_LOG(error) << "Invalid unicode for rendering cert dialog" << std::endl;break;
- default: SWIFT_LOG(error) << "Unexpected multibyte conversion errorcode" << std::endl;
+ if (titleLength == 0 || promptLength == 0) {
+ int error = GetLastError();
+ switch (error) {
+ case ERROR_INSUFFICIENT_BUFFER: SWIFT_LOG(error) << "Insufficient buffer for rendering cert dialog" << std::endl;break;
+ case ERROR_INVALID_FLAGS: SWIFT_LOG(error) << "Invalid flags for rendering cert dialog" << std::endl;break;
+ case ERROR_INVALID_PARAMETER: SWIFT_LOG(error) << "Invalid parameter for rendering cert dialog" << std::endl;break;
+ case ERROR_NO_UNICODE_TRANSLATION: SWIFT_LOG(error) << "Invalid unicode for rendering cert dialog" << std::endl;break;
+ default: SWIFT_LOG(error) << "Unexpected multibyte conversion errorcode" << std::endl;
- }
- }
+ }
+ }
-
- /* Call Windows dialog to select a suitable certificate */
- PCCERT_CONTEXT cert = CryptUIDlgSelectCertificateFromStore(hstore, hwnd, titleChars, promptChars, exclude_columns, 0, NULL);
- delete[] titleChars;
- delete[] promptChars;
+ /* Call Windows dialog to select a suitable certificate */
+ PCCERT_CONTEXT cert = CryptUIDlgSelectCertificateFromStore(hstore, hwnd, titleChars, promptChars, exclude_columns, 0, NULL);
- if (hstore) {
- CertCloseStore(hstore, 0);
- }
+ delete[] titleChars;
+ delete[] promptChars;
- std::string result;
+ if (hstore) {
+ CertCloseStore(hstore, 0);
+ }
- if (cert) {
- result = getCertUri(cert, certStoreName);
- CertFreeCertificateContext(cert);
- }
+ std::string result;
- return result;
+ if (cert) {
+ result = getCertUri(cert, certStoreName);
+ CertFreeCertificateContext(cert);
+ }
+
+ return result;
}
bool isCAPIURI(std::string uri) {
- return (boost::iequals(uri.substr(0, 10), "certstore:"));
+ return (boost::iequals(uri.substr(0, 10), "certstore:"));
}
}
diff --git a/Swift/QtUI/CAPICertificateSelector.h b/Swift/QtUI/CAPICertificateSelector.h
index 714f1c5..8273c78 100644
--- a/Swift/QtUI/CAPICertificateSelector.h
+++ b/Swift/QtUI/CAPICertificateSelector.h
@@ -9,6 +9,6 @@
#include <string>
namespace Swift {
- std::string selectCAPICertificate();
- bool isCAPIURI(std::string uri);
+ std::string selectCAPICertificate();
+ bool isCAPIURI(std::string uri);
}
diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp
index 5fa4e23..29eb29a 100644
--- a/Swift/QtUI/ChatList/ChatListDelegate.cpp
+++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp
@@ -19,125 +19,125 @@
namespace Swift {
ChatListDelegate::ChatListDelegate(bool compact) : compact_(compact) {
- groupDelegate_ = new GroupItemDelegate();
+ groupDelegate_ = new GroupItemDelegate();
}
ChatListDelegate::~ChatListDelegate() {
- delete groupDelegate_;
+ delete groupDelegate_;
}
void ChatListDelegate::setCompact(bool compact) {
- compact_ = compact;
- emit sizeHintChanged(QModelIndex());
+ compact_ = compact;
+ emit sizeHintChanged(QModelIndex());
}
QSize ChatListDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
- ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer());
- if (item && dynamic_cast<ChatListMUCItem*>(item)) {
- return mucSizeHint(option, index);
- }
- else if (item && dynamic_cast<ChatListRecentItem*>(item)) {
- return common_.contactSizeHint(option, index, compact_);
- }
- else if (item && dynamic_cast<ChatListGroupItem*>(item)) {
- return groupDelegate_->sizeHint(option, index);
- }
- else if (item && dynamic_cast<ChatListWhiteboardItem*>(item)) {
- return common_.contactSizeHint(option, index, compact_);
- }
- return QStyledItemDelegate::sizeHint(option, index);
+ ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer());
+ if (item && dynamic_cast<ChatListMUCItem*>(item)) {
+ return mucSizeHint(option, index);
+ }
+ else if (item && dynamic_cast<ChatListRecentItem*>(item)) {
+ return common_.contactSizeHint(option, index, compact_);
+ }
+ else if (item && dynamic_cast<ChatListGroupItem*>(item)) {
+ return groupDelegate_->sizeHint(option, index);
+ }
+ else if (item && dynamic_cast<ChatListWhiteboardItem*>(item)) {
+ return common_.contactSizeHint(option, index, compact_);
+ }
+ return QStyledItemDelegate::sizeHint(option, index);
}
QSize ChatListDelegate::mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const {
- QFontMetrics nameMetrics(common_.nameFont);
- QFontMetrics statusMetrics(common_.detailFont);
- int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
- return QSize(150, sizeByText);
+ QFontMetrics nameMetrics(common_.nameFont);
+ QFontMetrics statusMetrics(common_.detailFont);
+ int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
+ return QSize(150, sizeByText);
}
QSize ChatListDelegate::recentSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const {
- return mucSizeHint(option, index);
+ return mucSizeHint(option, index);
}
void ChatListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer());
- if (item && dynamic_cast<ChatListMUCItem*>(item)) {
- paintMUC(painter, option, dynamic_cast<ChatListMUCItem*>(item));
- }
- else if (item && dynamic_cast<ChatListRecentItem*>(item)) {
- paintRecent(painter, option, dynamic_cast<ChatListRecentItem*>(item));
- }
- else if (item && dynamic_cast<ChatListGroupItem*>(item)) {
- ChatListGroupItem* group = dynamic_cast<ChatListGroupItem*>(item);
- groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open);
- }
- else if (item && dynamic_cast<ChatListWhiteboardItem*>(item)) {
- paintWhiteboard(painter, option, dynamic_cast<ChatListWhiteboardItem*>(item));
- }
- else {
- QStyledItemDelegate::paint(painter, option, index);
- }
+ ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer());
+ if (item && dynamic_cast<ChatListMUCItem*>(item)) {
+ paintMUC(painter, option, dynamic_cast<ChatListMUCItem*>(item));
+ }
+ else if (item && dynamic_cast<ChatListRecentItem*>(item)) {
+ paintRecent(painter, option, dynamic_cast<ChatListRecentItem*>(item));
+ }
+ else if (item && dynamic_cast<ChatListGroupItem*>(item)) {
+ ChatListGroupItem* group = dynamic_cast<ChatListGroupItem*>(item);
+ groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open);
+ }
+ else if (item && dynamic_cast<ChatListWhiteboardItem*>(item)) {
+ paintWhiteboard(painter, option, dynamic_cast<ChatListWhiteboardItem*>(item));
+ }
+ else {
+ QStyledItemDelegate::paint(painter, option, index);
+ }
}
void ChatListDelegate::paintMUC(QPainter* painter, const QStyleOptionViewItem& option, ChatListMUCItem* item) const {
- painter->save();
- QRect fullRegion(option.rect);
- if ( option.state & QStyle::State_Selected ) {
- painter->fillRect(fullRegion, option.palette.highlight());
- painter->setPen(option.palette.highlightedText().color());
- } else {
- QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
- painter->setPen(QPen(nameColor));
- }
-
- QFontMetrics nameMetrics(common_.nameFont);
- painter->setFont(common_.nameFont);
- int extraFontWidth = nameMetrics.width("H");
- int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
- QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
-
- int nameHeight = nameMetrics.height() + common_.verticalMargin;
- QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
-
- DelegateCommons::drawElidedText(painter, nameRegion, item->data(Qt::DisplayRole).toString());
-
- painter->setFont(common_.detailFont);
- painter->setPen(QPen(QColor(160,160,160)));
-
- QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
- DelegateCommons::drawElidedText(painter, detailRegion, item->data(ChatListMUCItem::DetailTextRole).toString());
-
- painter->restore();
+ painter->save();
+ QRect fullRegion(option.rect);
+ if ( option.state & QStyle::State_Selected ) {
+ painter->fillRect(fullRegion, option.palette.highlight());
+ painter->setPen(option.palette.highlightedText().color());
+ } else {
+ QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
+ painter->setPen(QPen(nameColor));
+ }
+
+ QFontMetrics nameMetrics(common_.nameFont);
+ painter->setFont(common_.nameFont);
+ int extraFontWidth = nameMetrics.width("H");
+ int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
+ QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
+
+ int nameHeight = nameMetrics.height() + common_.verticalMargin;
+ QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
+
+ DelegateCommons::drawElidedText(painter, nameRegion, item->data(Qt::DisplayRole).toString());
+
+ painter->setFont(common_.detailFont);
+ painter->setPen(QPen(QColor(160,160,160)));
+
+ QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
+ DelegateCommons::drawElidedText(painter, detailRegion, item->data(ChatListMUCItem::DetailTextRole).toString());
+
+ painter->restore();
}
void ChatListDelegate::paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const {
- QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
- QString avatarPath;
- if (item->data(ChatListRecentItem::AvatarRole).isValid() && !item->data(ChatListRecentItem::AvatarRole).value<QString>().isNull()) {
- avatarPath = item->data(ChatListRecentItem::AvatarRole).value<QString>();
- }
- QIcon presenceIcon = item->data(ChatListRecentItem::PresenceIconRole).isValid() && !item->data(ChatListRecentItem::PresenceIconRole).value<QIcon>().isNull()
- ? item->data(ChatListRecentItem::PresenceIconRole).value<QIcon>()
- : QIcon(":/icons/offline.png");
- QString name = item->data(Qt::DisplayRole).toString();
- //qDebug() << "Avatar for " << name << " = " << avatarPath;
- QString statusText = item->data(ChatListRecentItem::DetailTextRole).toString();
- common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, item->getChat().unreadCount, compact_);
+ QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
+ QString avatarPath;
+ if (item->data(ChatListRecentItem::AvatarRole).isValid() && !item->data(ChatListRecentItem::AvatarRole).value<QString>().isNull()) {
+ avatarPath = item->data(ChatListRecentItem::AvatarRole).value<QString>();
+ }
+ QIcon presenceIcon = item->data(ChatListRecentItem::PresenceIconRole).isValid() && !item->data(ChatListRecentItem::PresenceIconRole).value<QIcon>().isNull()
+ ? item->data(ChatListRecentItem::PresenceIconRole).value<QIcon>()
+ : QIcon(":/icons/offline.png");
+ QString name = item->data(Qt::DisplayRole).toString();
+ //qDebug() << "Avatar for " << name << " = " << avatarPath;
+ QString statusText = item->data(ChatListRecentItem::DetailTextRole).toString();
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, item->getChat().unreadCount, compact_);
}
void ChatListDelegate::paintWhiteboard(QPainter* painter, const QStyleOptionViewItem& option, ChatListWhiteboardItem* item) const {
- QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
- QString avatarPath;
- if (item->data(ChatListWhiteboardItem::AvatarRole).isValid() && !item->data(ChatListWhiteboardItem::AvatarRole).value<QString>().isNull()) {
- avatarPath = item->data(ChatListWhiteboardItem::AvatarRole).value<QString>();
- }
- QIcon presenceIcon;/* = item->data(ChatListWhiteboardItem::PresenceIconRole).isValid() && !item->data(ChatListWhiteboardItem::PresenceIconRole).value<QIcon>().isNull()
- ? item->data(ChatListWhiteboardItem::PresenceIconRole).value<QIcon>()
- : QIcon(":/icons/offline.png");*/
- QString name = item->data(Qt::DisplayRole).toString();
- //qDebug() << "Avatar for " << name << " = " << avatarPath;
- QString statusText = item->data(ChatListWhiteboardItem::DetailTextRole).toString();
- common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, item->getChat().unreadCount, compact_);
+ QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
+ QString avatarPath;
+ if (item->data(ChatListWhiteboardItem::AvatarRole).isValid() && !item->data(ChatListWhiteboardItem::AvatarRole).value<QString>().isNull()) {
+ avatarPath = item->data(ChatListWhiteboardItem::AvatarRole).value<QString>();
+ }
+ QIcon presenceIcon;/* = item->data(ChatListWhiteboardItem::PresenceIconRole).isValid() && !item->data(ChatListWhiteboardItem::PresenceIconRole).value<QIcon>().isNull()
+ ? item->data(ChatListWhiteboardItem::PresenceIconRole).value<QIcon>()
+ : QIcon(":/icons/offline.png");*/
+ QString name = item->data(Qt::DisplayRole).toString();
+ //qDebug() << "Avatar for " << name << " = " << avatarPath;
+ QString statusText = item->data(ChatListWhiteboardItem::DetailTextRole).toString();
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, item->getChat().unreadCount, compact_);
}
diff --git a/Swift/QtUI/ChatList/ChatListDelegate.h b/Swift/QtUI/ChatList/ChatListDelegate.h
index 2de209d..44ca947 100644
--- a/Swift/QtUI/ChatList/ChatListDelegate.h
+++ b/Swift/QtUI/ChatList/ChatListDelegate.h
@@ -11,28 +11,28 @@
#include <Swift/QtUI/Roster/GroupItemDelegate.h>
namespace Swift {
- class ChatListMUCItem;
- class ChatListRecentItem;
- class ChatListWhiteboardItem;
- class ChatListDelegate : public QStyledItemDelegate {
- public:
- ChatListDelegate(bool compact);
- ~ChatListDelegate();
- QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
- void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
- public slots:
- void setCompact(bool compact);
- private:
- void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, ChatListMUCItem* item) const;
- void paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const;
- void paintWhiteboard(QPainter* painter, const QStyleOptionViewItem& option, ChatListWhiteboardItem* item) const;
- QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;
- QSize recentSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;
+ class ChatListMUCItem;
+ class ChatListRecentItem;
+ class ChatListWhiteboardItem;
+ class ChatListDelegate : public QStyledItemDelegate {
+ public:
+ ChatListDelegate(bool compact);
+ ~ChatListDelegate();
+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ public slots:
+ void setCompact(bool compact);
+ private:
+ void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, ChatListMUCItem* item) const;
+ void paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const;
+ void paintWhiteboard(QPainter* painter, const QStyleOptionViewItem& option, ChatListWhiteboardItem* item) const;
+ QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;
+ QSize recentSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;
- bool compact_;
- DelegateCommons common_;
- GroupItemDelegate* groupDelegate_;
- };
+ bool compact_;
+ DelegateCommons common_;
+ GroupItemDelegate* groupDelegate_;
+ };
}
diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h
index 9330505..427f00b 100644
--- a/Swift/QtUI/ChatList/ChatListGroupItem.h
+++ b/Swift/QtUI/ChatList/ChatListGroupItem.h
@@ -13,33 +13,33 @@
#include <Swift/QtUI/ChatList/ChatListItem.h>
namespace Swift {
- class ChatListGroupItem : public ChatListItem {
- public:
- ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {}
- virtual ~ChatListGroupItem() {clear();}
- void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}}
- void remove(int index) {items_.removeAt(index);}
- int rowCount() {return items_.size();}
- ChatListItem* item(int i) {return items_[i];}
- int row(ChatListItem* item) {return items_.indexOf(item);}
- QVariant data(int role) const {return (role == Qt::DisplayRole) ? name_ : QVariant();}
- void clear() {
- foreach (ChatListItem* item, items_) {
- delete item;
- }
- items_.clear();
- }
-
-
- private:
- static bool pointerItemLessThan(const ChatListItem* first, const ChatListItem* second) {
- QString myName = first->data(Qt::DisplayRole).toString().toLower();
- QString theirName = second->data(Qt::DisplayRole).toString().toLower();
- return myName < theirName;
- }
-
- QString name_;
- QList<ChatListItem*> items_;
- bool sorted_;
- };
+ class ChatListGroupItem : public ChatListItem {
+ public:
+ ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {}
+ virtual ~ChatListGroupItem() {clear();}
+ void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}}
+ void remove(int index) {items_.removeAt(index);}
+ int rowCount() {return items_.size();}
+ ChatListItem* item(int i) {return items_[i];}
+ int row(ChatListItem* item) {return items_.indexOf(item);}
+ QVariant data(int role) const {return (role == Qt::DisplayRole) ? name_ : QVariant();}
+ void clear() {
+ foreach (ChatListItem* item, items_) {
+ delete item;
+ }
+ items_.clear();
+ }
+
+
+ private:
+ static bool pointerItemLessThan(const ChatListItem* first, const ChatListItem* second) {
+ QString myName = first->data(Qt::DisplayRole).toString().toLower();
+ QString theirName = second->data(Qt::DisplayRole).toString().toLower();
+ return myName < theirName;
+ }
+
+ QString name_;
+ QList<ChatListItem*> items_;
+ bool sorted_;
+ };
}
diff --git a/Swift/QtUI/ChatList/ChatListItem.h b/Swift/QtUI/ChatList/ChatListItem.h
index fa8b18a..c6fd762 100644
--- a/Swift/QtUI/ChatList/ChatListItem.h
+++ b/Swift/QtUI/ChatList/ChatListItem.h
@@ -11,16 +11,16 @@
#include <qdebug.h>
namespace Swift {
- class ChatListGroupItem;
- class ChatListItem {
- public:
- ChatListItem(ChatListGroupItem* parent) {parent_ = parent;}
- virtual ~ChatListItem() {}
+ class ChatListGroupItem;
+ class ChatListItem {
+ public:
+ ChatListItem(ChatListGroupItem* parent) {parent_ = parent;}
+ virtual ~ChatListItem() {}
- ChatListGroupItem* parent() {return parent_;}
- virtual QVariant data(int role) const = 0;
+ ChatListGroupItem* parent() {return parent_;}
+ virtual QVariant data(int role) const = 0;
- private:
- ChatListGroupItem* parent_;
- };
+ private:
+ ChatListGroupItem* parent_;
+ };
}
diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.cpp b/Swift/QtUI/ChatList/ChatListMUCItem.cpp
index 1ad622d..7d072df 100644
--- a/Swift/QtUI/ChatList/ChatListMUCItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListMUCItem.cpp
@@ -14,21 +14,21 @@ ChatListMUCItem::ChatListMUCItem(const MUCBookmark& bookmark, ChatListGroupItem*
}
const MUCBookmark& ChatListMUCItem::getBookmark() const {
- return bookmark_;
+ return bookmark_;
}
QVariant ChatListMUCItem::data(int role) const {
- switch (role) {
- case Qt::DisplayRole: return P2QSTRING(bookmark_.getName());
- case DetailTextRole: return P2QSTRING(bookmark_.getRoom().toString());
- /*case Qt::TextColorRole: return textColor_;
- case Qt::BackgroundColorRole: return backgroundColor_;
- case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
- case StatusTextRole: return statusText_;
- case AvatarRole: return avatar_;
- case PresenceIconRole: return getPresenceIcon();*/
- default: return QVariant();
- }
+ switch (role) {
+ case Qt::DisplayRole: return P2QSTRING(bookmark_.getName());
+ case DetailTextRole: return P2QSTRING(bookmark_.getRoom().toString());
+ /*case Qt::TextColorRole: return textColor_;
+ case Qt::BackgroundColorRole: return backgroundColor_;
+ case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
+ case StatusTextRole: return statusText_;
+ case AvatarRole: return avatar_;
+ case PresenceIconRole: return getPresenceIcon();*/
+ default: return QVariant();
+ }
}
}
diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.h b/Swift/QtUI/ChatList/ChatListMUCItem.h
index fb90b88..4e93600 100644
--- a/Swift/QtUI/ChatList/ChatListMUCItem.h
+++ b/Swift/QtUI/ChatList/ChatListMUCItem.h
@@ -15,19 +15,19 @@
#include <Swift/QtUI/ChatList/ChatListItem.h>
namespace Swift {
- class ChatListMUCItem : public ChatListItem {
- public:
- enum MUCItemRoles {
- DetailTextRole = Qt::UserRole/*,
- AvatarRole = Qt::UserRole + 1,
- PresenceIconRole = Qt::UserRole + 2,
- StatusShowTypeRole = Qt::UserRole + 3*/
- };
- ChatListMUCItem(const MUCBookmark& bookmark, ChatListGroupItem* parent);
- const MUCBookmark& getBookmark() const;
- QVariant data(int role) const;
- private:
- MUCBookmark bookmark_;
- QList<ChatListItem*> items_;
- };
+ class ChatListMUCItem : public ChatListItem {
+ public:
+ enum MUCItemRoles {
+ DetailTextRole = Qt::UserRole/*,
+ AvatarRole = Qt::UserRole + 1,
+ PresenceIconRole = Qt::UserRole + 2,
+ StatusShowTypeRole = Qt::UserRole + 3*/
+ };
+ ChatListMUCItem(const MUCBookmark& bookmark, ChatListGroupItem* parent);
+ const MUCBookmark& getBookmark() const;
+ QVariant data(int role) const;
+ private:
+ MUCBookmark bookmark_;
+ QList<ChatListItem*> items_;
+ };
}
diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp
index 2447aa1..307cdea 100644
--- a/Swift/QtUI/ChatList/ChatListModel.cpp
+++ b/Swift/QtUI/ChatList/ChatListModel.cpp
@@ -17,172 +17,172 @@
namespace Swift {
ChatListModel::ChatListModel() : whiteboards_(NULL) {
- root_ = new ChatListGroupItem("", NULL, false);
- mucBookmarks_ = new ChatListGroupItem(tr("Bookmarked Rooms"), root_);
- recents_ = new ChatListGroupItem(tr("Recent Chats"), root_, false);
+ root_ = new ChatListGroupItem("", NULL, false);
+ mucBookmarks_ = new ChatListGroupItem(tr("Bookmarked Rooms"), root_);
+ recents_ = new ChatListGroupItem(tr("Recent Chats"), root_, false);
#ifdef SWIFT_EXPERIMENTAL_WB
- whiteboards_ = new ChatListGroupItem(tr("Opened Whiteboards"), root_, false);
- root_->addItem(whiteboards_);
+ whiteboards_ = new ChatListGroupItem(tr("Opened Whiteboards"), root_, false);
+ root_->addItem(whiteboards_);
#endif
- root_->addItem(recents_);
- root_->addItem(mucBookmarks_);
+ root_->addItem(recents_);
+ root_->addItem(mucBookmarks_);
- QModelIndex idx = index(0, 0, QModelIndex());
- while (idx.isValid()) {
- if (idx.internalPointer() == mucBookmarks_) {
- mucBookmarksIndex_ = idx;
- } else if (idx.internalPointer() == recents_) {
- recentsIndex_ = idx;
- } else if (idx.internalPointer() == whiteboards_) {
- whiteboardsIndex_ = idx;
- }
- idx = index(idx.row() + 1, 0, QModelIndex());
- }
+ QModelIndex idx = index(0, 0, QModelIndex());
+ while (idx.isValid()) {
+ if (idx.internalPointer() == mucBookmarks_) {
+ mucBookmarksIndex_ = idx;
+ } else if (idx.internalPointer() == recents_) {
+ recentsIndex_ = idx;
+ } else if (idx.internalPointer() == whiteboards_) {
+ whiteboardsIndex_ = idx;
+ }
+ idx = index(idx.row() + 1, 0, QModelIndex());
+ }
}
Qt::ItemFlags ChatListModel::flags(const QModelIndex& index) const {
- Qt::ItemFlags flags = QAbstractItemModel::flags(index);
- if (dynamic_cast<ChatListRecentItem*>(getItemForIndex(index))) {
- flags |= Qt::ItemIsDragEnabled;
- }
- return flags;
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ if (dynamic_cast<ChatListRecentItem*>(getItemForIndex(index))) {
+ flags |= Qt::ItemIsDragEnabled;
+ }
+ return flags;
}
void ChatListModel::clearBookmarks() {
- beginRemoveRows(mucBookmarksIndex_, 0, mucBookmarks_->rowCount());
- mucBookmarks_->clear();
- endRemoveRows();
+ beginRemoveRows(mucBookmarksIndex_, 0, mucBookmarks_->rowCount());
+ mucBookmarks_->clear();
+ endRemoveRows();
}
void ChatListModel::addMUCBookmark(const Swift::MUCBookmark& bookmark) {
- beginInsertRows(mucBookmarksIndex_, 0, mucBookmarks_->rowCount());
- mucBookmarks_->addItem(new ChatListMUCItem(bookmark, mucBookmarks_));
- endInsertRows();
+ beginInsertRows(mucBookmarksIndex_, 0, mucBookmarks_->rowCount());
+ mucBookmarks_->addItem(new ChatListMUCItem(bookmark, mucBookmarks_));
+ endInsertRows();
}
void ChatListModel::removeMUCBookmark(const Swift::MUCBookmark& bookmark) {
- for (int i = 0; i < mucBookmarks_->rowCount(); i++) {
- ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i));
- if (item->getBookmark() == bookmark) {
- beginRemoveRows(mucBookmarksIndex_, i, i+1);
- mucBookmarks_->remove(i);
- endRemoveRows();
- break;
- }
- }
+ for (int i = 0; i < mucBookmarks_->rowCount(); i++) {
+ ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i));
+ if (item->getBookmark() == bookmark) {
+ beginRemoveRows(mucBookmarksIndex_, i, i+1);
+ mucBookmarks_->remove(i);
+ endRemoveRows();
+ break;
+ }
+ }
}
void ChatListModel::addWhiteboardSession(const ChatListWindow::Chat& chat) {
- beginInsertRows(whiteboardsIndex_, 0, whiteboards_->rowCount());
- whiteboards_->addItem(new ChatListWhiteboardItem(chat, whiteboards_));
- endInsertRows();
+ beginInsertRows(whiteboardsIndex_, 0, whiteboards_->rowCount());
+ whiteboards_->addItem(new ChatListWhiteboardItem(chat, whiteboards_));
+ endInsertRows();
}
void ChatListModel::removeWhiteboardSession(const JID& jid) {
- for (int i = 0; i < whiteboards_->rowCount(); i++) {
- ChatListWhiteboardItem* item = dynamic_cast<ChatListWhiteboardItem*>(whiteboards_->item(i));
- if (item->getChat().jid == jid) {
- beginRemoveRows(whiteboardsIndex_, i, i+1);
- whiteboards_->remove(i);
- endRemoveRows();
- break;
- }
- }
+ for (int i = 0; i < whiteboards_->rowCount(); i++) {
+ ChatListWhiteboardItem* item = dynamic_cast<ChatListWhiteboardItem*>(whiteboards_->item(i));
+ if (item->getChat().jid == jid) {
+ beginRemoveRows(whiteboardsIndex_, i, i+1);
+ whiteboards_->remove(i);
+ endRemoveRows();
+ break;
+ }
+ }
}
void ChatListModel::setRecents(const std::list<ChatListWindow::Chat>& recents) {
- beginRemoveRows(recentsIndex_, 0, recents_->rowCount());
- recents_->clear();
- endRemoveRows();
- beginInsertRows(recentsIndex_, 0, recents.size());
- foreach (const ChatListWindow::Chat chat, recents) {
- recents_->addItem(new ChatListRecentItem(chat, recents_));
+ beginRemoveRows(recentsIndex_, 0, recents_->rowCount());
+ recents_->clear();
+ endRemoveRows();
+ beginInsertRows(recentsIndex_, 0, recents.size());
+ foreach (const ChatListWindow::Chat chat, recents) {
+ recents_->addItem(new ChatListRecentItem(chat, recents_));
//whiteboards_->addItem(new ChatListRecentItem(chat, whiteboards_));
- }
- endInsertRows();
+ }
+ endInsertRows();
}
QMimeData* ChatListModel::mimeData(const QModelIndexList& indexes) const {
- QMimeData* data = QAbstractItemModel::mimeData(indexes);
- ChatListRecentItem *item = dynamic_cast<ChatListRecentItem*>(getItemForIndex(indexes.first()));
- if (item == NULL) {
- return data;
- }
-
- QByteArray itemData;
- QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- const ChatListWindow::Chat& chat = item->getChat();
-
- QString mimeType = "application/vnd.swift.contact-jid-list";
- if (!chat.impromptuJIDs.size()) {
- if (chat.isMUC) {
- mimeType = "application/vnd.swift.contact-jid-muc";
- }
- dataStream << P2QSTRING(chat.jid.toString());
- } else {
- typedef std::map<std::string, JID> JIDMap;
- foreach (const JIDMap::value_type& jid, chat.impromptuJIDs) {
- dataStream << P2QSTRING(jid.second.toString());
- }
- }
-
- data->setData(mimeType, itemData);
- return data;
+ QMimeData* data = QAbstractItemModel::mimeData(indexes);
+ ChatListRecentItem *item = dynamic_cast<ChatListRecentItem*>(getItemForIndex(indexes.first()));
+ if (item == NULL) {
+ return data;
+ }
+
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+ const ChatListWindow::Chat& chat = item->getChat();
+
+ QString mimeType = "application/vnd.swift.contact-jid-list";
+ if (!chat.impromptuJIDs.size()) {
+ if (chat.isMUC) {
+ mimeType = "application/vnd.swift.contact-jid-muc";
+ }
+ dataStream << P2QSTRING(chat.jid.toString());
+ } else {
+ typedef std::map<std::string, JID> JIDMap;
+ foreach (const JIDMap::value_type& jid, chat.impromptuJIDs) {
+ dataStream << P2QSTRING(jid.second.toString());
+ }
+ }
+
+ data->setData(mimeType, itemData);
+ return data;
}
const ChatListMUCItem* ChatListModel::getChatListMUCItem(const JID& roomJID) const {
- const ChatListMUCItem* mucItem = NULL;
- for (int i = 0; i < mucBookmarks_->rowCount(); i++) {
- ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i));
- if (item->getBookmark().getRoom() == roomJID) {
- mucItem = item;
- break;
- }
- }
- return mucItem;
+ const ChatListMUCItem* mucItem = NULL;
+ for (int i = 0; i < mucBookmarks_->rowCount(); i++) {
+ ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i));
+ if (item->getBookmark().getRoom() == roomJID) {
+ mucItem = item;
+ break;
+ }
+ }
+ return mucItem;
}
int ChatListModel::columnCount(const QModelIndex& /*parent*/) const {
- return 1;
+ return 1;
}
ChatListItem* ChatListModel::getItemForIndex(const QModelIndex& index) const {
- return index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL;
+ return index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL;
}
QVariant ChatListModel::data(const QModelIndex& index, int role) const {
- ChatListItem* item = getItemForIndex(index);
- return item ? item->data(role) : QVariant();
+ ChatListItem* item = getItemForIndex(index);
+ return item ? item->data(role) : QVariant();
}
QModelIndex ChatListModel::index(int row, int column, const QModelIndex & parent) const {
- if (!hasIndex(row, column, parent)) {
- return QModelIndex();
- }
+ if (!hasIndex(row, column, parent)) {
+ return QModelIndex();
+ }
- ChatListGroupItem *parentItem = parent.isValid() ? static_cast<ChatListGroupItem*>(parent.internalPointer()) : root_;
+ ChatListGroupItem *parentItem = parent.isValid() ? static_cast<ChatListGroupItem*>(parent.internalPointer()) : root_;
- return row < parentItem->rowCount() ? createIndex(row, column, parentItem->item(row)) : QModelIndex();
+ return row < parentItem->rowCount() ? createIndex(row, column, parentItem->item(row)) : QModelIndex();
}
QModelIndex ChatListModel::parent(const QModelIndex& index) const {
- if (!index.isValid()) {
- return QModelIndex();
- }
- ChatListGroupItem* parent = static_cast<ChatListGroupItem*>(index.internalPointer())->parent();
- return (parent == root_) ? QModelIndex() : createIndex(parent->parent()->row(parent), 0, parent);
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+ ChatListGroupItem* parent = static_cast<ChatListGroupItem*>(index.internalPointer())->parent();
+ return (parent == root_) ? QModelIndex() : createIndex(parent->parent()->row(parent), 0, parent);
}
int ChatListModel::rowCount(const QModelIndex& parentIndex) const {
- ChatListGroupItem* parent = NULL;
- if (parentIndex.isValid()) {
- parent = dynamic_cast<ChatListGroupItem*>(static_cast<ChatListItem*>(parentIndex.internalPointer()));
- } else {
- parent = root_;
- }
- int count = (parent ? parent->rowCount() : 0);
- return count;
+ ChatListGroupItem* parent = NULL;
+ if (parentIndex.isValid()) {
+ parent = dynamic_cast<ChatListGroupItem*>(static_cast<ChatListItem*>(parentIndex.internalPointer()));
+ } else {
+ parent = root_;
+ }
+ int count = (parent ? parent->rowCount() : 0);
+ return count;
}
}
diff --git a/Swift/QtUI/ChatList/ChatListModel.h b/Swift/QtUI/ChatList/ChatListModel.h
index ea85efb..363b2e6 100644
--- a/Swift/QtUI/ChatList/ChatListModel.h
+++ b/Swift/QtUI/ChatList/ChatListModel.h
@@ -16,38 +16,38 @@
#include <Swift/QtUI/ChatList/ChatListGroupItem.h>
namespace Swift {
- class ChatListMUCItem;
-
- class ChatListModel : public QAbstractItemModel {
- Q_OBJECT
- public:
- ChatListModel();
- Qt::ItemFlags flags(const QModelIndex& index) const;
- void addMUCBookmark(const MUCBookmark& bookmark);
- void removeMUCBookmark(const MUCBookmark& bookmark);
- void addWhiteboardSession(const ChatListWindow::Chat& chat);
- void removeWhiteboardSession(const JID& jid);
- int columnCount(const QModelIndex& parent = QModelIndex()) const;
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex& index) const;
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
- ChatListItem* getItemForIndex(const QModelIndex& index) const;
- void clearBookmarks();
- void setRecents(const std::list<ChatListWindow::Chat>& recents);
- QMimeData* mimeData(const QModelIndexList& indexes) const;
-
- const ChatListMUCItem* getChatListMUCItem(const JID& roomJID) const;
-
- private:
- ChatListGroupItem* mucBookmarks_;
- ChatListGroupItem* recents_;
- ChatListGroupItem* whiteboards_;
- ChatListGroupItem* root_;
-
- QPersistentModelIndex mucBookmarksIndex_;
- QPersistentModelIndex recentsIndex_;
- QPersistentModelIndex whiteboardsIndex_;
- };
+ class ChatListMUCItem;
+
+ class ChatListModel : public QAbstractItemModel {
+ Q_OBJECT
+ public:
+ ChatListModel();
+ Qt::ItemFlags flags(const QModelIndex& index) const;
+ void addMUCBookmark(const MUCBookmark& bookmark);
+ void removeMUCBookmark(const MUCBookmark& bookmark);
+ void addWhiteboardSession(const ChatListWindow::Chat& chat);
+ void removeWhiteboardSession(const JID& jid);
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex& index) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ ChatListItem* getItemForIndex(const QModelIndex& index) const;
+ void clearBookmarks();
+ void setRecents(const std::list<ChatListWindow::Chat>& recents);
+ QMimeData* mimeData(const QModelIndexList& indexes) const;
+
+ const ChatListMUCItem* getChatListMUCItem(const JID& roomJID) const;
+
+ private:
+ ChatListGroupItem* mucBookmarks_;
+ ChatListGroupItem* recents_;
+ ChatListGroupItem* whiteboards_;
+ ChatListGroupItem* root_;
+
+ QPersistentModelIndex mucBookmarksIndex_;
+ QPersistentModelIndex recentsIndex_;
+ QPersistentModelIndex whiteboardsIndex_;
+ };
}
diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.cpp b/Swift/QtUI/ChatList/ChatListRecentItem.cpp
index dc40855..383f312 100644
--- a/Swift/QtUI/ChatList/ChatListRecentItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListRecentItem.cpp
@@ -17,25 +17,25 @@ ChatListRecentItem::ChatListRecentItem(const ChatListWindow::Chat& chat, ChatLis
}
const ChatListWindow::Chat& ChatListRecentItem::getChat() const {
- return chat_;
+ return chat_;
}
QVariant ChatListRecentItem::data(int role) const {
- switch (role) {
- case Qt::DisplayRole: return chat_.impromptuJIDs.empty() ? P2QSTRING(chat_.chatName) : P2QSTRING(chat_.getImpromptuTitle());
- case DetailTextRole: return P2QSTRING(chat_.activity);
- /*case Qt::TextColorRole: return textColor_;
- case Qt::BackgroundColorRole: return backgroundColor_;
- case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
- case StatusTextRole: return statusText_;*/
- case AvatarRole: return QVariant(P2QSTRING(pathToString(chat_.avatarPath)));
- case PresenceIconRole: return getPresenceIcon();
- default: return QVariant();
- }
+ switch (role) {
+ case Qt::DisplayRole: return chat_.impromptuJIDs.empty() ? P2QSTRING(chat_.chatName) : P2QSTRING(chat_.getImpromptuTitle());
+ case DetailTextRole: return P2QSTRING(chat_.activity);
+ /*case Qt::TextColorRole: return textColor_;
+ case Qt::BackgroundColorRole: return backgroundColor_;
+ case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
+ case StatusTextRole: return statusText_;*/
+ case AvatarRole: return QVariant(P2QSTRING(pathToString(chat_.avatarPath)));
+ case PresenceIconRole: return getPresenceIcon();
+ default: return QVariant();
+ }
}
QIcon ChatListRecentItem::getPresenceIcon() const {
- return QIcon(statusShowTypeToIconPath(chat_.statusType));
+ return QIcon(statusShowTypeToIconPath(chat_.statusType));
}
}
diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.h b/Swift/QtUI/ChatList/ChatListRecentItem.h
index 338bc43..4f0a363 100644
--- a/Swift/QtUI/ChatList/ChatListRecentItem.h
+++ b/Swift/QtUI/ChatList/ChatListRecentItem.h
@@ -18,20 +18,20 @@
#include <Swift/QtUI/ChatList/ChatListItem.h>
namespace Swift {
- class ChatListRecentItem : public ChatListItem {
- public:
- enum RecentItemRoles {
- DetailTextRole = Qt::UserRole,
- AvatarRole = Qt::UserRole + 1,
- PresenceIconRole = Qt::UserRole + 2/*,
- StatusShowTypeRole = Qt::UserRole + 3,
- IdleRole = Qt::UserRole + 4*/
- };
- ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent);
- const ChatListWindow::Chat& getChat() const;
- QVariant data(int role) const;
- private:
- QIcon getPresenceIcon() const;
- ChatListWindow::Chat chat_;
- };
+ class ChatListRecentItem : public ChatListItem {
+ public:
+ enum RecentItemRoles {
+ DetailTextRole = Qt::UserRole,
+ AvatarRole = Qt::UserRole + 1,
+ PresenceIconRole = Qt::UserRole + 2/*,
+ StatusShowTypeRole = Qt::UserRole + 3,
+ IdleRole = Qt::UserRole + 4*/
+ };
+ ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent);
+ const ChatListWindow::Chat& getChat() const;
+ QVariant data(int role) const;
+ private:
+ QIcon getPresenceIcon() const;
+ ChatListWindow::Chat chat_;
+ };
}
diff --git a/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp b/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp
index f6ecec1..b6f8951 100644
--- a/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp
@@ -18,30 +18,30 @@
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
- ChatListWhiteboardItem::ChatListWhiteboardItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent) : ChatListItem(parent), chat_(chat) {
-
- }
-
- const ChatListWindow::Chat& ChatListWhiteboardItem::getChat() const {
- return chat_;
- }
-
- QVariant ChatListWhiteboardItem::data(int role) const {
- switch (role) {
- case Qt::DisplayRole: return P2QSTRING(chat_.chatName);
- case DetailTextRole: return P2QSTRING(chat_.activity);
- /*case Qt::TextColorRole: return textColor_;
- case Qt::BackgroundColorRole: return backgroundColor_;
- case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
- case StatusTextRole: return statusText_;*/
- case AvatarRole: return QVariant(P2QSTRING(pathToString(chat_.avatarPath)));
- case PresenceIconRole: return getPresenceIcon();
- default: return QVariant();
- }
- }
-
- QIcon ChatListWhiteboardItem::getPresenceIcon() const {
- return QIcon(statusShowTypeToIconPath(chat_.statusType));
- }
+ ChatListWhiteboardItem::ChatListWhiteboardItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent) : ChatListItem(parent), chat_(chat) {
+
+ }
+
+ const ChatListWindow::Chat& ChatListWhiteboardItem::getChat() const {
+ return chat_;
+ }
+
+ QVariant ChatListWhiteboardItem::data(int role) const {
+ switch (role) {
+ case Qt::DisplayRole: return P2QSTRING(chat_.chatName);
+ case DetailTextRole: return P2QSTRING(chat_.activity);
+ /*case Qt::TextColorRole: return textColor_;
+ case Qt::BackgroundColorRole: return backgroundColor_;
+ case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
+ case StatusTextRole: return statusText_;*/
+ case AvatarRole: return QVariant(P2QSTRING(pathToString(chat_.avatarPath)));
+ case PresenceIconRole: return getPresenceIcon();
+ default: return QVariant();
+ }
+ }
+
+ QIcon ChatListWhiteboardItem::getPresenceIcon() const {
+ return QIcon(statusShowTypeToIconPath(chat_.statusType));
+ }
}
diff --git a/Swift/QtUI/ChatList/ChatListWhiteboardItem.h b/Swift/QtUI/ChatList/ChatListWhiteboardItem.h
index fbbe7c5..92acb1c 100644
--- a/Swift/QtUI/ChatList/ChatListWhiteboardItem.h
+++ b/Swift/QtUI/ChatList/ChatListWhiteboardItem.h
@@ -18,19 +18,19 @@
#include <Swift/QtUI/ChatList/ChatListItem.h>
namespace Swift {
- class ChatListWhiteboardItem : public ChatListItem {
- public:
- enum RecentItemRoles {
- DetailTextRole = Qt::UserRole,
- AvatarRole = Qt::UserRole + 1,
- PresenceIconRole = Qt::UserRole + 2/*,
- StatusShowTypeRole = Qt::UserRole + 3*/
- };
- ChatListWhiteboardItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent);
- const ChatListWindow::Chat& getChat() const;
- QVariant data(int role) const;
- private:
- QIcon getPresenceIcon() const;
- ChatListWindow::Chat chat_;
- };
+ class ChatListWhiteboardItem : public ChatListItem {
+ public:
+ enum RecentItemRoles {
+ DetailTextRole = Qt::UserRole,
+ AvatarRole = Qt::UserRole + 1,
+ PresenceIconRole = Qt::UserRole + 2/*,
+ StatusShowTypeRole = Qt::UserRole + 3*/
+ };
+ ChatListWhiteboardItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent);
+ const ChatListWindow::Chat& getChat() const;
+ QVariant data(int role) const;
+ private:
+ QIcon getPresenceIcon() const;
+ ChatListWindow::Chat chat_;
+ };
}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp
index b990b84..eddd0cd 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.cpp
+++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp
@@ -31,197 +31,197 @@
namespace Swift {
QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, SettingsProvider* settings, QWidget* parent) : QTreeView(parent), isOnline_(false) {
- eventStream_ = uiEventStream;
- settings_ = settings;
- bookmarksEnabled_ = false;
- model_ = new ChatListModel();
- setModel(model_);
- delegate_ = new ChatListDelegate(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
- setItemDelegate(delegate_);
- setHeaderHidden(true);
+ eventStream_ = uiEventStream;
+ settings_ = settings;
+ bookmarksEnabled_ = false;
+ model_ = new ChatListModel();
+ setModel(model_);
+ delegate_ = new ChatListDelegate(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ setItemDelegate(delegate_);
+ setHeaderHidden(true);
#ifdef SWIFT_PLATFORM_MACOSX
- setAlternatingRowColors(true);
+ setAlternatingRowColors(true);
#endif
- expandAll();
- setAnimated(true);
- setIndentation(0);
- setDragEnabled(true);
- setRootIsDecorated(true);
- setupContextMenus();
- connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
- connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&)));
+ expandAll();
+ setAnimated(true);
+ setIndentation(0);
+ setDragEnabled(true);
+ setRootIsDecorated(true);
+ setupContextMenus();
+ connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
+ connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&)));
- settings_->onSettingChanged.connect(boost::bind(&QtChatListWindow::handleSettingChanged, this, _1));
+ settings_->onSettingChanged.connect(boost::bind(&QtChatListWindow::handleSettingChanged, this, _1));
}
QtChatListWindow::~QtChatListWindow() {
- settings_->onSettingChanged.disconnect(boost::bind(&QtChatListWindow::handleSettingChanged, this, _1));
- delete model_;
- delete delegate_;
- delete mucMenu_;
- delete emptyMenu_;
+ settings_->onSettingChanged.disconnect(boost::bind(&QtChatListWindow::handleSettingChanged, this, _1));
+ delete model_;
+ delete delegate_;
+ delete mucMenu_;
+ delete emptyMenu_;
}
void QtChatListWindow::handleSettingChanged(const std::string& setting) {
- if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
- delegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
- repaint();
- }
+ if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
+ delegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ repaint();
+ }
}
void QtChatListWindow::handleClearRecentsRequested() {
- onClearRecentsRequested();
+ onClearRecentsRequested();
}
void QtChatListWindow::setBookmarksEnabled(bool enabled) {
- bookmarksEnabled_ = enabled;
+ bookmarksEnabled_ = enabled;
}
void QtChatListWindow::handleClicked(const QModelIndex& index) {
- ChatListGroupItem* item = dynamic_cast<ChatListGroupItem*>(static_cast<ChatListItem*>(index.internalPointer()));
- if (item) {
- setExpanded(index, !isExpanded(index));
- }
+ ChatListGroupItem* item = dynamic_cast<ChatListGroupItem*>(static_cast<ChatListItem*>(index.internalPointer()));
+ if (item) {
+ setExpanded(index, !isExpanded(index));
+ }
}
void QtChatListWindow::setupContextMenus() {
- mucMenu_ = new QMenu();
- onlineOnlyActions_ << mucMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
- onlineOnlyActions_ << mucMenu_->addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark()));
- onlineOnlyActions_ << mucMenu_->addAction(tr("Remove Bookmark"), this, SLOT(handleRemoveBookmark()));
- emptyMenu_ = new QMenu();
- onlineOnlyActions_ << emptyMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
+ mucMenu_ = new QMenu();
+ onlineOnlyActions_ << mucMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
+ onlineOnlyActions_ << mucMenu_->addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark()));
+ onlineOnlyActions_ << mucMenu_->addAction(tr("Remove Bookmark"), this, SLOT(handleRemoveBookmark()));
+ emptyMenu_ = new QMenu();
+ onlineOnlyActions_ << emptyMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
}
void QtChatListWindow::handleItemActivated(const QModelIndex& index) {
- ChatListItem* item = model_->getItemForIndex(index);
- if (ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item)) {
- onMUCBookmarkActivated(mucItem->getBookmark());
- }
- else if (ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(item)) {
- onRecentActivated(recentItem->getChat());
- }
- else if (ChatListWhiteboardItem* whiteboardItem = dynamic_cast<ChatListWhiteboardItem*>(item)) {
- if (!whiteboardItem->getChat().isMUC || bookmarksEnabled_) {
- eventStream_->send(boost::make_shared<ShowWhiteboardUIEvent>(whiteboardItem->getChat().jid));
- }
- }
+ ChatListItem* item = model_->getItemForIndex(index);
+ if (ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item)) {
+ onMUCBookmarkActivated(mucItem->getBookmark());
+ }
+ else if (ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(item)) {
+ onRecentActivated(recentItem->getChat());
+ }
+ else if (ChatListWhiteboardItem* whiteboardItem = dynamic_cast<ChatListWhiteboardItem*>(item)) {
+ if (!whiteboardItem->getChat().isMUC || bookmarksEnabled_) {
+ eventStream_->send(boost::make_shared<ShowWhiteboardUIEvent>(whiteboardItem->getChat().jid));
+ }
+ }
}
void QtChatListWindow::clearBookmarks() {
- model_->clearBookmarks();
+ model_->clearBookmarks();
}
void QtChatListWindow::addMUCBookmark(const MUCBookmark& bookmark) {
- model_->addMUCBookmark(bookmark);
+ model_->addMUCBookmark(bookmark);
}
void QtChatListWindow::removeMUCBookmark(const MUCBookmark& bookmark) {
- model_->removeMUCBookmark(bookmark);
+ model_->removeMUCBookmark(bookmark);
}
void QtChatListWindow::addWhiteboardSession(const ChatListWindow::Chat& chat) {
- model_->addWhiteboardSession(chat);
+ model_->addWhiteboardSession(chat);
}
void QtChatListWindow::removeWhiteboardSession(const JID& jid) {
- model_->removeWhiteboardSession(jid);
+ model_->removeWhiteboardSession(jid);
}
void QtChatListWindow::setRecents(const std::list<ChatListWindow::Chat>& recents) {
- model_->setRecents(recents);
+ model_->setRecents(recents);
}
void QtChatListWindow::setUnreadCount(int unread) {
- emit onCountUpdated(unread);
+ emit onCountUpdated(unread);
}
void QtChatListWindow::setOnline(bool isOnline) {
- isOnline_ = isOnline;
+ isOnline_ = isOnline;
}
void QtChatListWindow::handleRemoveBookmark() {
- const ChatListMUCItem* mucItem = dynamic_cast<const ChatListMUCItem*>(contextMenuItem_);
- if (!mucItem) return;
- eventStream_->send(boost::shared_ptr<UIEvent>(new RemoveMUCBookmarkUIEvent(mucItem->getBookmark())));
+ const ChatListMUCItem* mucItem = dynamic_cast<const ChatListMUCItem*>(contextMenuItem_);
+ if (!mucItem) return;
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RemoveMUCBookmarkUIEvent(mucItem->getBookmark())));
}
void QtChatListWindow::handleAddBookmarkFromRecents() {
- const ChatListRecentItem* item = dynamic_cast<const ChatListRecentItem*>(contextMenuItem_);
- if (item) {
- const ChatListWindow::Chat& chat = item->getChat();
- MUCBookmark bookmark(chat.jid, chat.jid.toBare().toString());
- bookmark.setNick(chat.nick);
- bookmark.setPassword(chat.password);
- eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(bookmark)));
- }
+ const ChatListRecentItem* item = dynamic_cast<const ChatListRecentItem*>(contextMenuItem_);
+ if (item) {
+ const ChatListWindow::Chat& chat = item->getChat();
+ MUCBookmark bookmark(chat.jid, chat.jid.toBare().toString());
+ bookmark.setNick(chat.nick);
+ bookmark.setPassword(chat.password);
+ eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(bookmark)));
+ }
}
void QtChatListWindow::handleAddBookmark() {
- (new QtAddBookmarkWindow(eventStream_))->show();
+ (new QtAddBookmarkWindow(eventStream_))->show();
}
void QtChatListWindow::handleEditBookmark() {
- const ChatListMUCItem* mucItem = dynamic_cast<const ChatListMUCItem*>(contextMenuItem_);
- if (!mucItem) return;
- QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, mucItem->getBookmark());
- window->show();
+ const ChatListMUCItem* mucItem = dynamic_cast<const ChatListMUCItem*>(contextMenuItem_);
+ if (!mucItem) return;
+ QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, mucItem->getBookmark());
+ window->show();
}
void QtChatListWindow::dragEnterEvent(QDragEnterEvent *event) {
- if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
- event->acceptProposedAction();
- }
+ if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
+ event->acceptProposedAction();
+ }
}
void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) {
- QModelIndex index = indexAt(event->pos());
- ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL;
- contextMenuItem_ = baseItem;
-
- foreach(QAction* action, onlineOnlyActions_) {
- action->setEnabled(isOnline_);
- }
-
- if (!baseItem) {
- emptyMenu_->exec(QCursor::pos());
- return;
- }
-
- ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem);
- if (mucItem) {
- if (!bookmarksEnabled_) {
- return;
- }
- mucMenu_->exec(QCursor::pos());
- return;
- }
-
- ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(baseItem);
- if (recentItem) {
- const ChatListWindow::Chat& chat = recentItem->getChat();
- if (chat.isMUC) {
- QMenu mucRecentsMenu;
- QAction* bookmarkAction = NULL;
- const ChatListMUCItem* mucItem = model_->getChatListMUCItem(chat.jid);
- if (mucItem) {
- contextMenuItem_ = mucItem;
- bookmarkAction = mucRecentsMenu.addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark()));
- }
- else {
- bookmarkAction = mucRecentsMenu.addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents()));
- }
- bookmarkAction->setEnabled(isOnline_);
- mucRecentsMenu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested()));
- mucRecentsMenu.exec(QCursor::pos());
- return;
- }
- }
-
- QMenu menu;
- menu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested()));
- menu.exec(event->globalPos());
+ QModelIndex index = indexAt(event->pos());
+ ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL;
+ contextMenuItem_ = baseItem;
+
+ foreach(QAction* action, onlineOnlyActions_) {
+ action->setEnabled(isOnline_);
+ }
+
+ if (!baseItem) {
+ emptyMenu_->exec(QCursor::pos());
+ return;
+ }
+
+ ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem);
+ if (mucItem) {
+ if (!bookmarksEnabled_) {
+ return;
+ }
+ mucMenu_->exec(QCursor::pos());
+ return;
+ }
+
+ ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(baseItem);
+ if (recentItem) {
+ const ChatListWindow::Chat& chat = recentItem->getChat();
+ if (chat.isMUC) {
+ QMenu mucRecentsMenu;
+ QAction* bookmarkAction = NULL;
+ const ChatListMUCItem* mucItem = model_->getChatListMUCItem(chat.jid);
+ if (mucItem) {
+ contextMenuItem_ = mucItem;
+ bookmarkAction = mucRecentsMenu.addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark()));
+ }
+ else {
+ bookmarkAction = mucRecentsMenu.addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents()));
+ }
+ bookmarkAction->setEnabled(isOnline_);
+ mucRecentsMenu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested()));
+ mucRecentsMenu.exec(QCursor::pos());
+ return;
+ }
+ }
+
+ QMenu menu;
+ menu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested()));
+ menu.exec(event->globalPos());
}
}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h
index 627dcd4..61f8391 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.h
+++ b/Swift/QtUI/ChatList/QtChatListWindow.h
@@ -15,50 +15,50 @@
#include <Swift/QtUI/ChatList/ChatListModel.h>
namespace Swift {
- class SettingsProvider;
- class QtChatListWindow : public QTreeView, public ChatListWindow {
- Q_OBJECT
- public:
- QtChatListWindow(UIEventStream *uiEventStream, SettingsProvider* settings, QWidget* parent = NULL);
- virtual ~QtChatListWindow();
- void addMUCBookmark(const MUCBookmark& bookmark);
- void removeMUCBookmark(const MUCBookmark& bookmark);
- void addWhiteboardSession(const ChatListWindow::Chat& chat);
- void removeWhiteboardSession(const JID& jid);
- void setBookmarksEnabled(bool enabled);
- void setRecents(const std::list<ChatListWindow::Chat>& recents);
- void setUnreadCount(int unread);
- void clearBookmarks();
- virtual void setOnline(bool isOnline);
+ class SettingsProvider;
+ class QtChatListWindow : public QTreeView, public ChatListWindow {
+ Q_OBJECT
+ public:
+ QtChatListWindow(UIEventStream *uiEventStream, SettingsProvider* settings, QWidget* parent = NULL);
+ virtual ~QtChatListWindow();
+ void addMUCBookmark(const MUCBookmark& bookmark);
+ void removeMUCBookmark(const MUCBookmark& bookmark);
+ void addWhiteboardSession(const ChatListWindow::Chat& chat);
+ void removeWhiteboardSession(const JID& jid);
+ void setBookmarksEnabled(bool enabled);
+ void setRecents(const std::list<ChatListWindow::Chat>& recents);
+ void setUnreadCount(int unread);
+ void clearBookmarks();
+ virtual void setOnline(bool isOnline);
- signals:
- void onCountUpdated(int count);
- private slots:
- void handleItemActivated(const QModelIndex&);
- void handleAddBookmark();
- void handleEditBookmark();
- void handleRemoveBookmark();
- void handleAddBookmarkFromRecents();
- void handleClicked(const QModelIndex& index);
- void handleSettingChanged(const std::string& setting);
- void handleClearRecentsRequested();
+ signals:
+ void onCountUpdated(int count);
+ private slots:
+ void handleItemActivated(const QModelIndex&);
+ void handleAddBookmark();
+ void handleEditBookmark();
+ void handleRemoveBookmark();
+ void handleAddBookmarkFromRecents();
+ void handleClicked(const QModelIndex& index);
+ void handleSettingChanged(const std::string& setting);
+ void handleClearRecentsRequested();
- protected:
- void dragEnterEvent(QDragEnterEvent* event);
- void contextMenuEvent(QContextMenuEvent* event);
+ protected:
+ void dragEnterEvent(QDragEnterEvent* event);
+ void contextMenuEvent(QContextMenuEvent* event);
- private:
- void setupContextMenus();
- bool bookmarksEnabled_;
- UIEventStream* eventStream_;
- ChatListModel* model_;
- ChatListDelegate* delegate_;
- QMenu* mucMenu_;
- QMenu* emptyMenu_;
- const ChatListItem* contextMenuItem_;
- SettingsProvider* settings_;
- QList<QAction*> onlineOnlyActions_;
- bool isOnline_;
- };
+ private:
+ void setupContextMenus();
+ bool bookmarksEnabled_;
+ UIEventStream* eventStream_;
+ ChatListModel* model_;
+ ChatListDelegate* delegate_;
+ QMenu* mucMenu_;
+ QMenu* emptyMenu_;
+ const ChatListItem* contextMenuItem_;
+ SettingsProvider* settings_;
+ QList<QAction*> onlineOnlyActions_;
+ bool isOnline_;
+ };
}
diff --git a/Swift/QtUI/ChatSnippet.cpp b/Swift/QtUI/ChatSnippet.cpp
index d8b64c1..14e4674 100644
--- a/Swift/QtUI/ChatSnippet.cpp
+++ b/Swift/QtUI/ChatSnippet.cpp
@@ -19,79 +19,79 @@ ChatSnippet::~ChatSnippet() {
}
QString ChatSnippet::timeToEscapedString(const QDateTime& time) {
- QDate now(QDate::currentDate());
- QString date = "";
- if (time.date().daysTo(now) > 0) {
- date = "ddd ";
- }
- if (time.date().month() != now.month()) {
- date = date + "MMMM ";
- }
- if (time.date().daysTo(now) > 6) {
- date = date + "d ";
- }
- if (time.date().year() != now.year()) {
- date = date + "yy ";
- }
- date += "h:mm";
- return escape(time.toString(date));
+ QDate now(QDate::currentDate());
+ QString date = "";
+ if (time.date().daysTo(now) > 0) {
+ date = "ddd ";
+ }
+ if (time.date().month() != now.month()) {
+ date = date + "MMMM ";
+ }
+ if (time.date().daysTo(now) > 6) {
+ date = date + "d ";
+ }
+ if (time.date().year() != now.year()) {
+ date = date + "yy ";
+ }
+ date += "h:mm";
+ return escape(time.toString(date));
}
QString ChatSnippet::wrapResizable(const QString& text) {
- return "<span class='swift_resizable'>" + text + "</span>";
+ return "<span class='swift_resizable'>" + text + "</span>";
}
QString ChatSnippet::directionToCSS(Direction direction) {
- return direction == RTL ? QString("rtl") : QString("ltr");
+ return direction == RTL ? QString("rtl") : QString("ltr");
}
ChatSnippet::Direction ChatSnippet::getDirection(const ChatWindow::ChatMessage& message) {
- boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
- std::string text = "";
- foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
- if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
- text = textPart->text;
- break;
- }
- }
- return getDirection(text);
+ boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
+ std::string text = "";
+ foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
+ if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
+ text = textPart->text;
+ break;
+ }
+ }
+ return getDirection(text);
}
ChatSnippet::Direction ChatSnippet::getDirection(const std::string& message) {
- return getDirection(P2QSTRING(message));
+ return getDirection(P2QSTRING(message));
}
ChatSnippet::Direction ChatSnippet::getDirection(const QString& message) {
- /*
- for (int i = 0; i < message.size(); ++i) {
- switch (message.at(i).direction()) {
- case QChar::DirL:
- case QChar::DirLRE:
- case QChar::DirLRO:
- return ChatSnippet::LTR;
- case QChar::DirR:
- case QChar::DirAL:
- case QChar::DirRLE:
- case QChar::DirRLO:
- return ChatSnippet::RTL;
- case QChar::DirEN:
- case QChar::DirES:
- case QChar::DirET:
- case QChar::DirAN:
- case QChar::DirCS:
- case QChar::DirB:
- case QChar::DirWS:
- case QChar::DirON:
- case QChar::DirS:
- case QChar::DirPDF:
- case QChar::DirNSM:
- case QChar::DirBN:
- break;
- }
- }
- return ChatSnippet::LTR;
- */
- return message.isRightToLeft() ? ChatSnippet::RTL : ChatSnippet::LTR;
+ /*
+ for (int i = 0; i < message.size(); ++i) {
+ switch (message.at(i).direction()) {
+ case QChar::DirL:
+ case QChar::DirLRE:
+ case QChar::DirLRO:
+ return ChatSnippet::LTR;
+ case QChar::DirR:
+ case QChar::DirAL:
+ case QChar::DirRLE:
+ case QChar::DirRLO:
+ return ChatSnippet::RTL;
+ case QChar::DirEN:
+ case QChar::DirES:
+ case QChar::DirET:
+ case QChar::DirAN:
+ case QChar::DirCS:
+ case QChar::DirB:
+ case QChar::DirWS:
+ case QChar::DirON:
+ case QChar::DirS:
+ case QChar::DirPDF:
+ case QChar::DirNSM:
+ case QChar::DirBN:
+ break;
+ }
+ }
+ return ChatSnippet::LTR;
+ */
+ return message.isRightToLeft() ? ChatSnippet::RTL : ChatSnippet::LTR;
}
diff --git a/Swift/QtUI/ChatSnippet.h b/Swift/QtUI/ChatSnippet.h
index 7c99928..bf2d6d2 100644
--- a/Swift/QtUI/ChatSnippet.h
+++ b/Swift/QtUI/ChatSnippet.h
@@ -18,55 +18,55 @@
#include <Swift/QtUI/QtChatTheme.h>
namespace Swift {
- class ChatSnippet {
- public:
- enum Direction {
- RTL,
- LTR
- };
-
- ChatSnippet(bool appendToPrevious);
- virtual ~ChatSnippet();
-
- virtual const QString& getContent() const = 0;
- virtual QString getContinuationElementID() const { return ""; }
-
- boost::shared_ptr<ChatSnippet> getContinuationFallbackSnippet() const {return continuationFallback_;}
-
- bool getAppendToPrevious() const {
- return appendToPrevious_;
- }
-
- static QString escape(const QString& original) {
- QString result(original);
- result.replace("%message%", "&#37;message&#37;");
- result.replace("%sender%", "&#37;sender&#37;");
- result.replace("%wrapped_sender%", "&#37;wrapped_sender&#37;");
- result.replace("%time%", "%&#37;time&#37;");
- result.replace("%shortTime%", "%&#37;shortTime&#37;");
- result.replace("%userIconPath%", "&#37;userIconPath&#37;");
- result.replace("%id%", "&#37;id&#37;");
- result.replace("\t", " ");
- result.replace(" ", "&nbsp;&nbsp;");
- return result;
- }
-
- static QString timeToEscapedString(const QDateTime& time);
-
- static Direction getDirection(const std::string& message);
- static Direction getDirection(const ChatWindow::ChatMessage& message);
- static Direction getDirection(const QString& message);
-
- protected:
- static QString directionToCSS(Direction direction);
-
- QString wrapResizable(const QString& text);
- void setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet> continuationFallback) {
- continuationFallback_ = continuationFallback;
- }
- private:
- bool appendToPrevious_;
- boost::shared_ptr<ChatSnippet> continuationFallback_;
- };
+ class ChatSnippet {
+ public:
+ enum Direction {
+ RTL,
+ LTR
+ };
+
+ ChatSnippet(bool appendToPrevious);
+ virtual ~ChatSnippet();
+
+ virtual const QString& getContent() const = 0;
+ virtual QString getContinuationElementID() const { return ""; }
+
+ boost::shared_ptr<ChatSnippet> getContinuationFallbackSnippet() const {return continuationFallback_;}
+
+ bool getAppendToPrevious() const {
+ return appendToPrevious_;
+ }
+
+ static QString escape(const QString& original) {
+ QString result(original);
+ result.replace("%message%", "&#37;message&#37;");
+ result.replace("%sender%", "&#37;sender&#37;");
+ result.replace("%wrapped_sender%", "&#37;wrapped_sender&#37;");
+ result.replace("%time%", "%&#37;time&#37;");
+ result.replace("%shortTime%", "%&#37;shortTime&#37;");
+ result.replace("%userIconPath%", "&#37;userIconPath&#37;");
+ result.replace("%id%", "&#37;id&#37;");
+ result.replace("\t", " ");
+ result.replace(" ", "&nbsp;&nbsp;");
+ return result;
+ }
+
+ static QString timeToEscapedString(const QDateTime& time);
+
+ static Direction getDirection(const std::string& message);
+ static Direction getDirection(const ChatWindow::ChatMessage& message);
+ static Direction getDirection(const QString& message);
+
+ protected:
+ static QString directionToCSS(Direction direction);
+
+ QString wrapResizable(const QString& text);
+ void setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet> continuationFallback) {
+ continuationFallback_ = continuationFallback;
+ }
+ private:
+ bool appendToPrevious_;
+ boost::shared_ptr<ChatSnippet> continuationFallback_;
+ };
}
diff --git a/Swift/QtUI/ChatView/main.cpp b/Swift/QtUI/ChatView/main.cpp
index 4bde1ef..aa3255e 100644
--- a/Swift/QtUI/ChatView/main.cpp
+++ b/Swift/QtUI/ChatView/main.cpp
@@ -27,154 +27,154 @@ using namespace Swift;
/*
class MyNetworkReply : public QNetworkReply {
- public:
- MyNetworkReply() {
- }
-
- qint64 readData(char*, qint64) {
- return 0;
- }
-
- virtual void abort() {
- }
+ public:
+ MyNetworkReply() {
+ }
+
+ qint64 readData(char*, qint64) {
+ return 0;
+ }
+
+ virtual void abort() {
+ }
};
class MyNetworkAccessManager : public QNetworkAccessManager {
- public:
- MyNetworkAccessManager() {
- }
-
- QNetworkReply * createRequest (Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0) {
- assert(op == QNetworkAccessManager::GetOperation);
- qDebug() << "Requesting: " << request.url();
- return QNetworkAccessManager::createRequest(op, request, outgoingData);
- //return new MyNetworkReply();
- }
+ public:
+ MyNetworkAccessManager() {
+ }
+
+ QNetworkReply * createRequest (Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0) {
+ assert(op == QNetworkAccessManager::GetOperation);
+ qDebug() << "Requesting: " << request.url();
+ return QNetworkAccessManager::createRequest(op, request, outgoingData);
+ //return new MyNetworkReply();
+ }
};
- QVBoxLayout* mainLayout = new QVBoxLayout(this);
- webView_ = new QWebView(this);
-
- QFile file(":/themes/Stockholm/Contents/Resources/Incoming/Content.html");
- file.open(QIODevice::ReadOnly);
- QString content = QString::fromUtf8(file.readAll());
-
- webPage_ = new QWebPage(this);
- webPage_->setNetworkAccessManager(new MyNetworkAccessManager());
- webView_->setPage(webPage_);
- QString pagehtml =
- "<head>"
- //"<base href=\"file:///Users/remko/src/swift/resources/themes/Stockholm/Contents/Resources/\"/>"
- "<base href=\"file:///Users/remko/src/swift/resources/themes/Stockholm/Contents/Resources/\"/>"
- "<link rel=\"stylesheet\" type=\"text/css\" href=\"main.css\"/>"
- "<link rel=\"stylesheet\" type=\"text/css\" href=\"Variants/Alt Blue - Blue.css\"/>"
- "</head><body>" + content + "</body>";
- qDebug() << pagehtml;
- webPage_->mainFrame()->setHtml(pagehtml);
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
+ webView_ = new QWebView(this);
+
+ QFile file(":/themes/Stockholm/Contents/Resources/Incoming/Content.html");
+ file.open(QIODevice::ReadOnly);
+ QString content = QString::fromUtf8(file.readAll());
+
+ webPage_ = new QWebPage(this);
+ webPage_->setNetworkAccessManager(new MyNetworkAccessManager());
+ webView_->setPage(webPage_);
+ QString pagehtml =
+ "<head>"
+ //"<base href=\"file:///Users/remko/src/swift/resources/themes/Stockholm/Contents/Resources/\"/>"
+ "<base href=\"file:///Users/remko/src/swift/resources/themes/Stockholm/Contents/Resources/\"/>"
+ "<link rel=\"stylesheet\" type=\"text/css\" href=\"main.css\"/>"
+ "<link rel=\"stylesheet\" type=\"text/css\" href=\"Variants/Alt Blue - Blue.css\"/>"
+ "</head><body>" + content + "</body>";
+ qDebug() << pagehtml;
+ webPage_->mainFrame()->setHtml(pagehtml);
*/
/*
class ChatView : public QWidget {
- public:
- ChatView(QWidget* parent) : QWidget(parent) {
- setFocusPolicy(Qt::NoFocus);
-
- QVBoxLayout* mainLayout = new QVBoxLayout(this);
- mainLayout->setSpacing(0);
- mainLayout->setContentsMargins(0,0,0,0);
-
- webView_ = new QWebView(this);
- webView_->setFocusPolicy(Qt::NoFocus);
- mainLayout->addWidget(webView_);
-
- webPage_ = new QWebPage(this);
- webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
- webView_->setPage(webPage_);
- connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
-
- QString pageHTML = "<head></head><body><div id=\"chat\"></div></body>";
- webPage_->mainFrame()->setHtml(pageHTML);
- }
-
- void appendHTML(const QString& html) {
- webPage_->mainFrame()->evaluateJavaScript(
- "newNode = document.createElement(\"div\");"
- "newNode.innerHTML = \"" + html + "\";"
- "chatElement = document.getElementById(\"chat\");"
- "chatElement.appendChild(newNode);");
- webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical));
- }
-
- private:
- QWebView* webView_;
- QWebPage* webPage_;
+ public:
+ ChatView(QWidget* parent) : QWidget(parent) {
+ setFocusPolicy(Qt::NoFocus);
+
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
+ mainLayout->setSpacing(0);
+ mainLayout->setContentsMargins(0,0,0,0);
+
+ webView_ = new QWebView(this);
+ webView_->setFocusPolicy(Qt::NoFocus);
+ mainLayout->addWidget(webView_);
+
+ webPage_ = new QWebPage(this);
+ webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
+ webView_->setPage(webPage_);
+ connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
+
+ QString pageHTML = "<head></head><body><div id=\"chat\"></div></body>";
+ webPage_->mainFrame()->setHtml(pageHTML);
+ }
+
+ void appendHTML(const QString& html) {
+ webPage_->mainFrame()->evaluateJavaScript(
+ "newNode = document.createElement(\"div\");"
+ "newNode.innerHTML = \"" + html + "\";"
+ "chatElement = document.getElementById(\"chat\");"
+ "chatElement.appendChild(newNode);");
+ webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical));
+ }
+
+ private:
+ QWebView* webView_;
+ QWebPage* webPage_;
};
*/
class MyWidget : public QWidget {
- Q_OBJECT
-
- public:
- MyWidget() : previousWasIncoming_(false), previousWasOutgoing_(false), previousWasSystem_(false) {
- QVBoxLayout* mainLayout = new QVBoxLayout(this);
- chatView_ = new QtChatView(this);
- mainLayout->addWidget(chatView_);
- input1_ = new QLineEdit(this);
- connect(input1_, SIGNAL(returnPressed()), SLOT(addIncoming()));
- mainLayout->addWidget(input1_);
- input2_ = new QLineEdit(this);
- connect(input2_, SIGNAL(returnPressed()), SLOT(addOutgoing()));
- mainLayout->addWidget(input2_);
- input3_ = new QLineEdit(this);
- connect(input3_, SIGNAL(returnPressed()), SLOT(addSystem()));
- mainLayout->addWidget(input3_);
-
- resize(300,200);
- }
-
- public slots:
- void addIncoming() {
- chatView_->addMessage(MessageSnippet(input1_->text(), "Me", QDateTime::currentDateTime(), "qrc:/icons/avatar.png", true, previousWasIncoming_));
- previousWasIncoming_ = true;
- previousWasOutgoing_ = false;
- previousWasSystem_ = false;
- input1_->clear();
- }
-
- void addOutgoing() {
- chatView_->addMessage(MessageSnippet(input2_->text(), "You", QDateTime::currentDateTime(), "qrc:/icons/avatar.png", false, previousWasOutgoing_));
- previousWasIncoming_ = false;
- previousWasOutgoing_ = true;
- previousWasSystem_ = false;
- input2_->clear();
- }
-
- void addSystem() {
- chatView_->addMessage(SystemMessageSnippet(input3_->text(), QDateTime::currentDateTime(), previousWasSystem_));
- previousWasIncoming_ = false;
- previousWasOutgoing_ = false;
- previousWasSystem_ = true;
- input3_->clear();
- }
-
- private:
- bool previousWasIncoming_;
- bool previousWasOutgoing_;
- bool previousWasSystem_;
- QtChatView* chatView_;
- QLineEdit* input1_;
- QLineEdit* input2_;
- QLineEdit* input3_;
+ Q_OBJECT
+
+ public:
+ MyWidget() : previousWasIncoming_(false), previousWasOutgoing_(false), previousWasSystem_(false) {
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
+ chatView_ = new QtChatView(this);
+ mainLayout->addWidget(chatView_);
+ input1_ = new QLineEdit(this);
+ connect(input1_, SIGNAL(returnPressed()), SLOT(addIncoming()));
+ mainLayout->addWidget(input1_);
+ input2_ = new QLineEdit(this);
+ connect(input2_, SIGNAL(returnPressed()), SLOT(addOutgoing()));
+ mainLayout->addWidget(input2_);
+ input3_ = new QLineEdit(this);
+ connect(input3_, SIGNAL(returnPressed()), SLOT(addSystem()));
+ mainLayout->addWidget(input3_);
+
+ resize(300,200);
+ }
+
+ public slots:
+ void addIncoming() {
+ chatView_->addMessage(MessageSnippet(input1_->text(), "Me", QDateTime::currentDateTime(), "qrc:/icons/avatar.png", true, previousWasIncoming_));
+ previousWasIncoming_ = true;
+ previousWasOutgoing_ = false;
+ previousWasSystem_ = false;
+ input1_->clear();
+ }
+
+ void addOutgoing() {
+ chatView_->addMessage(MessageSnippet(input2_->text(), "You", QDateTime::currentDateTime(), "qrc:/icons/avatar.png", false, previousWasOutgoing_));
+ previousWasIncoming_ = false;
+ previousWasOutgoing_ = true;
+ previousWasSystem_ = false;
+ input2_->clear();
+ }
+
+ void addSystem() {
+ chatView_->addMessage(SystemMessageSnippet(input3_->text(), QDateTime::currentDateTime(), previousWasSystem_));
+ previousWasIncoming_ = false;
+ previousWasOutgoing_ = false;
+ previousWasSystem_ = true;
+ input3_->clear();
+ }
+
+ private:
+ bool previousWasIncoming_;
+ bool previousWasOutgoing_;
+ bool previousWasSystem_;
+ QtChatView* chatView_;
+ QLineEdit* input1_;
+ QLineEdit* input2_;
+ QLineEdit* input3_;
};
-
+
int main(int argc, char* argv[]) {
- QApplication app(argc, argv);
- MyWidget w;
- w.show();
- return app.exec();
+ QApplication app(argc, argv);
+ MyWidget w;
+ w.show();
+ return app.exec();
}
#include "main.moc"
diff --git a/Swift/QtUI/CocoaApplicationActivateHelper.h b/Swift/QtUI/CocoaApplicationActivateHelper.h
index 2b166e2..c7aa5b3 100644
--- a/Swift/QtUI/CocoaApplicationActivateHelper.h
+++ b/Swift/QtUI/CocoaApplicationActivateHelper.h
@@ -9,20 +9,20 @@
#include <QObject>
namespace Swift {
- /**
- * This class is here as a workaround for a bug in Qt.
- * See Case #501.
- */
- class CocoaApplicationActivateHelper : public QObject {
- public:
- CocoaApplicationActivateHelper();
- virtual ~CocoaApplicationActivateHelper();
+ /**
+ * This class is here as a workaround for a bug in Qt.
+ * See Case #501.
+ */
+ class CocoaApplicationActivateHelper : public QObject {
+ public:
+ CocoaApplicationActivateHelper();
+ virtual ~CocoaApplicationActivateHelper();
- private:
- bool eventFilter(QObject* o, QEvent* e);
+ private:
+ bool eventFilter(QObject* o, QEvent* e);
- private:
- struct Private;
- Private* p;
- };
+ private:
+ struct Private;
+ Private* p;
+ };
}
diff --git a/Swift/QtUI/CocoaApplicationActivateHelper.mm b/Swift/QtUI/CocoaApplicationActivateHelper.mm
index f9c455c..4d4409d 100644
--- a/Swift/QtUI/CocoaApplicationActivateHelper.mm
+++ b/Swift/QtUI/CocoaApplicationActivateHelper.mm
@@ -19,37 +19,37 @@
@implementation CocoaApplicationActivateHelperDelegate
- (void) handleActivate: (NSAppleEventDescriptor*) event withReply: (NSAppleEventDescriptor*) reply {
- (void) event; (void) reply;
- QApplication::postEvent(qApp, new QEvent(QEvent::ApplicationActivate));
+ (void) event; (void) reply;
+ QApplication::postEvent(qApp, new QEvent(QEvent::ApplicationActivate));
}
@end
namespace Swift {
struct CocoaApplicationActivateHelper::Private {
- CocoaApplicationActivateHelperDelegate* delegate;
- bool initialized;
+ CocoaApplicationActivateHelperDelegate* delegate;
+ bool initialized;
};
CocoaApplicationActivateHelper::CocoaApplicationActivateHelper() {
- p = new Private();
- p->delegate = [[CocoaApplicationActivateHelperDelegate alloc] init];
- p->initialized = false;
- qApp->installEventFilter(this);
+ p = new Private();
+ p->delegate = [[CocoaApplicationActivateHelperDelegate alloc] init];
+ p->initialized = false;
+ qApp->installEventFilter(this);
}
CocoaApplicationActivateHelper::~CocoaApplicationActivateHelper() {
- [[NSAppleEventManager sharedAppleEventManager] removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEReopenApplication];
- [p->delegate release];
- delete p;
+ [[NSAppleEventManager sharedAppleEventManager] removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEReopenApplication];
+ [p->delegate release];
+ delete p;
}
bool CocoaApplicationActivateHelper::eventFilter(QObject* object, QEvent* event) {
- if (object == qApp && event->type() == QEvent::ApplicationActivate && !p->initialized) {
- [[NSAppleEventManager sharedAppleEventManager] setEventHandler:p->delegate andSelector:@selector(handleActivate:withReply:) forEventClass:kCoreEventClass andEventID:kAEReopenApplication];
- p->initialized = true;
- }
- return QObject::eventFilter(object, event);
+ if (object == qApp && event->type() == QEvent::ApplicationActivate && !p->initialized) {
+ [[NSAppleEventManager sharedAppleEventManager] setEventHandler:p->delegate andSelector:@selector(handleActivate:withReply:) forEventClass:kCoreEventClass andEventID:kAEReopenApplication];
+ p->initialized = true;
+ }
+ return QObject::eventFilter(object, event);
}
diff --git a/Swift/QtUI/CocoaUIHelpers.h b/Swift/QtUI/CocoaUIHelpers.h
index f5ec457..58cd539 100644
--- a/Swift/QtUI/CocoaUIHelpers.h
+++ b/Swift/QtUI/CocoaUIHelpers.h
@@ -20,7 +20,7 @@ namespace Swift {
class CocoaUIHelpers {
public:
- static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
+ static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
};
}
diff --git a/Swift/QtUI/CocoaUIHelpers.mm b/Swift/QtUI/CocoaUIHelpers.mm
index 3cb62f3..16fe2ce 100644
--- a/Swift/QtUI/CocoaUIHelpers.mm
+++ b/Swift/QtUI/CocoaUIHelpers.mm
@@ -21,23 +21,23 @@
namespace Swift {
void CocoaUIHelpers::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
- NSWindow* parentWindow = [((NSView*)parent->winId()) window];
- NSMutableArray* certificates = [[NSMutableArray alloc] init];
- foreach(Certificate::ref cert, chain) {
- // convert chain to SecCertificateRef
- ByteArray certAsDER = cert->toDER();
- boost::shared_ptr<boost::remove_pointer<CFDataRef>::type> certData(CFDataCreate(NULL, certAsDER.data(), certAsDER.size()), CFRelease);
- boost::shared_ptr<OpaqueSecCertificateRef> macCert(SecCertificateCreateWithData(NULL, certData.get()), CFRelease);
-
- // add to NSMutable array
- [certificates addObject: (id)macCert.get()];
- }
-
-
- SFCertificatePanel* panel = [[SFCertificatePanel alloc] init];
- //[panel setPolicies:(id)policies.get()];
- [panel beginSheetForWindow:parentWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL certificates:certificates showGroup:YES];
- [certificates release];
+ NSWindow* parentWindow = [((NSView*)parent->winId()) window];
+ NSMutableArray* certificates = [[NSMutableArray alloc] init];
+ foreach(Certificate::ref cert, chain) {
+ // convert chain to SecCertificateRef
+ ByteArray certAsDER = cert->toDER();
+ boost::shared_ptr<boost::remove_pointer<CFDataRef>::type> certData(CFDataCreate(NULL, certAsDER.data(), certAsDER.size()), CFRelease);
+ boost::shared_ptr<OpaqueSecCertificateRef> macCert(SecCertificateCreateWithData(NULL, certData.get()), CFRelease);
+
+ // add to NSMutable array
+ [certificates addObject: (id)macCert.get()];
+ }
+
+
+ SFCertificatePanel* panel = [[SFCertificatePanel alloc] init];
+ //[panel setPolicies:(id)policies.get()];
+ [panel beginSheetForWindow:parentWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL certificates:certificates showGroup:YES];
+ [certificates release];
}
}
diff --git a/Swift/QtUI/EventViewer/EventDelegate.cpp b/Swift/QtUI/EventViewer/EventDelegate.cpp
index cd657b8..eff9a7b 100644
--- a/Swift/QtUI/EventViewer/EventDelegate.cpp
+++ b/Swift/QtUI/EventViewer/EventDelegate.cpp
@@ -17,69 +17,69 @@
namespace Swift {
EventDelegate::EventDelegate() : QStyledItemDelegate(),
- messageDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false),
- subscriptionDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true),
- errorDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true),
- mucInviteDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false),
- incomingFileTransferDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false) {
+ messageDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false),
+ subscriptionDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true),
+ errorDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true),
+ mucInviteDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false),
+ incomingFileTransferDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false) {
}
QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
- QtEvent* item = static_cast<QtEvent*>(index.internalPointer());
- if (!item) {
- return QStyledItemDelegate::sizeHint(option, index);
- }
- switch (getEventType(item->getEvent())) {
- case MessageEventType: return messageDelegate_.sizeHint(option, item);
- case SubscriptionEventType: return subscriptionDelegate_.sizeHint(option, item);
- case ErrorEventType: return errorDelegate_.sizeHint(option, item);
- case MUCInviteEventType: return mucInviteDelegate_.sizeHint(option, item);
- case IncomingFileTransferEventType: return incomingFileTransferDelegate_.sizeHint(option, item);
- }
- assert(false);
- return QSize();
+ QtEvent* item = static_cast<QtEvent*>(index.internalPointer());
+ if (!item) {
+ return QStyledItemDelegate::sizeHint(option, index);
+ }
+ switch (getEventType(item->getEvent())) {
+ case MessageEventType: return messageDelegate_.sizeHint(option, item);
+ case SubscriptionEventType: return subscriptionDelegate_.sizeHint(option, item);
+ case ErrorEventType: return errorDelegate_.sizeHint(option, item);
+ case MUCInviteEventType: return mucInviteDelegate_.sizeHint(option, item);
+ case IncomingFileTransferEventType: return incomingFileTransferDelegate_.sizeHint(option, item);
+ }
+ assert(false);
+ return QSize();
}
void EventDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- QtEvent* item = static_cast<QtEvent*>(index.internalPointer());
- if (!item) {
- QStyledItemDelegate::paint(painter, option, index);
- return;
- }
- switch (getEventType(item->getEvent())) {
- case MessageEventType: messageDelegate_.paint(painter, option, item);break;
- case SubscriptionEventType: subscriptionDelegate_.paint(painter, option, item);break;
- case ErrorEventType: errorDelegate_.paint(painter, option, item);break;
- case MUCInviteEventType: mucInviteDelegate_.paint(painter, option, item);break;
- case IncomingFileTransferEventType: incomingFileTransferDelegate_.paint(painter, option, item);break;
- }
+ QtEvent* item = static_cast<QtEvent*>(index.internalPointer());
+ if (!item) {
+ QStyledItemDelegate::paint(painter, option, index);
+ return;
+ }
+ switch (getEventType(item->getEvent())) {
+ case MessageEventType: messageDelegate_.paint(painter, option, item);break;
+ case SubscriptionEventType: subscriptionDelegate_.paint(painter, option, item);break;
+ case ErrorEventType: errorDelegate_.paint(painter, option, item);break;
+ case MUCInviteEventType: mucInviteDelegate_.paint(painter, option, item);break;
+ case IncomingFileTransferEventType: incomingFileTransferDelegate_.paint(painter, option, item);break;
+ }
}
EventType EventDelegate::getEventType(boost::shared_ptr<StanzaEvent> event) const {
- boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event);
- if (messageEvent) {
- return MessageEventType;
- }
- boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event);
- if (subscriptionEvent) {
- return SubscriptionEventType;
- }
- boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event);
- if (errorEvent) {
- return ErrorEventType;
- }
- boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event);
- if (mucInviteEvent) {
- return MUCInviteEventType;
- }
- boost::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event);
- if (incomingFileTransferEvent) {
- return IncomingFileTransferEventType;
- }
- //I don't know what this is.
- assert(false);
- return MessageEventType;
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event);
+ if (messageEvent) {
+ return MessageEventType;
+ }
+ boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event);
+ if (subscriptionEvent) {
+ return SubscriptionEventType;
+ }
+ boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event);
+ if (errorEvent) {
+ return ErrorEventType;
+ }
+ boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event);
+ if (mucInviteEvent) {
+ return MUCInviteEventType;
+ }
+ boost::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event);
+ if (incomingFileTransferEvent) {
+ return IncomingFileTransferEventType;
+ }
+ //I don't know what this is.
+ assert(false);
+ return MessageEventType;
}
}
diff --git a/Swift/QtUI/EventViewer/EventDelegate.h b/Swift/QtUI/EventViewer/EventDelegate.h
index 6ab96e4..0804589 100644
--- a/Swift/QtUI/EventViewer/EventDelegate.h
+++ b/Swift/QtUI/EventViewer/EventDelegate.h
@@ -12,21 +12,21 @@
#include <Swift/QtUI/Roster/DelegateCommons.h>
namespace Swift {
- enum EventType {MessageEventType, SubscriptionEventType, ErrorEventType, MUCInviteEventType, IncomingFileTransferEventType};
- class EventDelegate : public QStyledItemDelegate {
- Q_OBJECT
- public:
- EventDelegate();
- QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
- void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
- private:
- EventType getEventType(boost::shared_ptr<StanzaEvent> event) const;
- DelegateCommons common_;
- TwoLineDelegate messageDelegate_;
- TwoLineDelegate subscriptionDelegate_;
- TwoLineDelegate errorDelegate_;
- TwoLineDelegate mucInviteDelegate_;
- TwoLineDelegate incomingFileTransferDelegate_;
- };
+ enum EventType {MessageEventType, SubscriptionEventType, ErrorEventType, MUCInviteEventType, IncomingFileTransferEventType};
+ class EventDelegate : public QStyledItemDelegate {
+ Q_OBJECT
+ public:
+ EventDelegate();
+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ private:
+ EventType getEventType(boost::shared_ptr<StanzaEvent> event) const;
+ DelegateCommons common_;
+ TwoLineDelegate messageDelegate_;
+ TwoLineDelegate subscriptionDelegate_;
+ TwoLineDelegate errorDelegate_;
+ TwoLineDelegate mucInviteDelegate_;
+ TwoLineDelegate incomingFileTransferDelegate_;
+ };
}
diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp
index 889bcac..1568ec7 100644
--- a/Swift/QtUI/EventViewer/EventModel.cpp
+++ b/Swift/QtUI/EventViewer/EventModel.cpp
@@ -11,100 +11,100 @@
namespace Swift {
namespace {
- const int inactiveEventsLimit = 50;
+ const int inactiveEventsLimit = 50;
}
EventModel::EventModel() {
-
+
}
EventModel::~EventModel() {
- foreach (QtEvent* event, activeEvents_) {
- delete event;
- }
- foreach (QtEvent* event, inactiveEvents_) {
- delete event;
- }
+ foreach (QtEvent* event, activeEvents_) {
+ delete event;
+ }
+ foreach (QtEvent* event, inactiveEvents_) {
+ delete event;
+ }
}
QtEvent* EventModel::getItem(int row) const {
- QtEvent* event = NULL;
- if (row < activeEvents_.size()) {
- event = activeEvents_[row];
- }
- else {
- int inactiveRow = row - activeEvents_.size();
- if (inactiveRow < inactiveEvents_.size()) {
- event = inactiveEvents_[inactiveRow];
- }
- else {
- SWIFT_LOG(error) << "Misbehaving EventModel requests row index outside of range";
- }
- }
- return event;
+ QtEvent* event = NULL;
+ if (row < activeEvents_.size()) {
+ event = activeEvents_[row];
+ }
+ else {
+ int inactiveRow = row - activeEvents_.size();
+ if (inactiveRow < inactiveEvents_.size()) {
+ event = inactiveEvents_[inactiveRow];
+ }
+ else {
+ SWIFT_LOG(error) << "Misbehaving EventModel requests row index outside of range";
+ }
+ }
+ return event;
}
int EventModel::getNewEventCount() {
- return activeEvents_.size();
+ return activeEvents_.size();
}
QVariant EventModel::data(const QModelIndex& index, int role) const {
- if (!index.isValid()) {
- return QVariant();
- }
- QtEvent* item = getItem(index.row());
- QVariant result = item ? item->data(role) : QVariant();
- return result;
+ if (!index.isValid()) {
+ return QVariant();
+ }
+ QtEvent* item = getItem(index.row());
+ QVariant result = item ? item->data(role) : QVariant();
+ return result;
}
/*
* We only reimplement this to get the pointers inside the indices.
*/
QModelIndex EventModel::index(int row, int column, const QModelIndex & parent) const {
- if (!hasIndex(row, column, parent) || parent.isValid()) {
- return QModelIndex();
- }
+ if (!hasIndex(row, column, parent) || parent.isValid()) {
+ return QModelIndex();
+ }
- return row < rowCount() ? createIndex(row, column, getItem(row)) : QModelIndex();
+ return row < rowCount() ? createIndex(row, column, getItem(row)) : QModelIndex();
}
int EventModel::rowCount(const QModelIndex& parent) const {
- /* Invalid parent = root, valid parent = child, and we're a list not a tree.*/
- int count = parent.isValid() ? 0 : activeEvents_.size() + inactiveEvents_.size();
- return count;
+ /* Invalid parent = root, valid parent = child, and we're a list not a tree.*/
+ int count = parent.isValid() ? 0 : activeEvents_.size() + inactiveEvents_.size();
+ return count;
}
void EventModel::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) {
- beginResetModel();
- if (active) {
- activeEvents_.push_front(new QtEvent(event, active));
- } else {
- inactiveEvents_.push_front(new QtEvent(event, active));
- if (inactiveEvents_.size() > inactiveEventsLimit) {
- removeEvent(inactiveEvents_[inactiveEventsLimit]->getEvent());
- }
- }
- endResetModel();
+ beginResetModel();
+ if (active) {
+ activeEvents_.push_front(new QtEvent(event, active));
+ } else {
+ inactiveEvents_.push_front(new QtEvent(event, active));
+ if (inactiveEvents_.size() > inactiveEventsLimit) {
+ removeEvent(inactiveEvents_[inactiveEventsLimit]->getEvent());
+ }
+ }
+ endResetModel();
}
void EventModel::removeEvent(boost::shared_ptr<StanzaEvent> event) {
- beginResetModel();
- for (int i = inactiveEvents_.size() - 1; i >= 0; i--) {
- if (event == inactiveEvents_[i]->getEvent()) {
- inactiveEvents_.removeAt(i);
- endResetModel();
- return;
- }
- }
-
- for (int i = 0; i < activeEvents_.size(); i++) {
- if (event == activeEvents_[i]->getEvent()) {
- activeEvents_.removeAt(i);
- endResetModel();
- return;
- }
- }
- endResetModel();
+ beginResetModel();
+ for (int i = inactiveEvents_.size() - 1; i >= 0; i--) {
+ if (event == inactiveEvents_[i]->getEvent()) {
+ inactiveEvents_.removeAt(i);
+ endResetModel();
+ return;
+ }
+ }
+
+ for (int i = 0; i < activeEvents_.size(); i++) {
+ if (event == activeEvents_[i]->getEvent()) {
+ activeEvents_.removeAt(i);
+ endResetModel();
+ return;
+ }
+ }
+ endResetModel();
}
}
diff --git a/Swift/QtUI/EventViewer/EventModel.h b/Swift/QtUI/EventViewer/EventModel.h
index 844e50f..5cd5028 100644
--- a/Swift/QtUI/EventViewer/EventModel.h
+++ b/Swift/QtUI/EventViewer/EventModel.h
@@ -17,21 +17,21 @@
namespace Swift {
class EventModel : public QAbstractListModel {
- Q_OBJECT
- public:
- EventModel();
- virtual ~EventModel();
- void addEvent(boost::shared_ptr<StanzaEvent> event, bool active);
- void removeEvent(boost::shared_ptr<StanzaEvent> event);
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
- QtEvent* getItem(int row) const;
- int getNewEventCount();
- protected:
- QModelIndex index(int row, int column = 0, const QModelIndex & parent = QModelIndex()) const;
- private:
- QList<QtEvent*> activeEvents_;
- QList<QtEvent*> inactiveEvents_;
+ Q_OBJECT
+ public:
+ EventModel();
+ virtual ~EventModel();
+ void addEvent(boost::shared_ptr<StanzaEvent> event, bool active);
+ void removeEvent(boost::shared_ptr<StanzaEvent> event);
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ QtEvent* getItem(int row) const;
+ int getNewEventCount();
+ protected:
+ QModelIndex index(int row, int column = 0, const QModelIndex & parent = QModelIndex()) const;
+ private:
+ QList<QtEvent*> activeEvents_;
+ QList<QtEvent*> inactiveEvents_;
};
}
diff --git a/Swift/QtUI/EventViewer/EventView.cpp b/Swift/QtUI/EventViewer/EventView.cpp
index fe299b8..4d56548 100644
--- a/Swift/QtUI/EventViewer/EventView.cpp
+++ b/Swift/QtUI/EventViewer/EventView.cpp
@@ -8,7 +8,7 @@
namespace Swift {
EventView::EventView(QWidget* parent) : QListView(parent) {
-
+
}
}
diff --git a/Swift/QtUI/EventViewer/EventView.h b/Swift/QtUI/EventViewer/EventView.h
index 36c67f3..83898bd 100644
--- a/Swift/QtUI/EventViewer/EventView.h
+++ b/Swift/QtUI/EventViewer/EventView.h
@@ -9,9 +9,9 @@
#include <QListView>
namespace Swift {
- class EventView : public QListView {
- Q_OBJECT
- public:
- EventView(QWidget* parent);
- };
+ class EventView : public QListView {
+ Q_OBJECT
+ public:
+ EventView(QWidget* parent);
+ };
}
diff --git a/Swift/QtUI/EventViewer/QtEvent.cpp b/Swift/QtUI/EventViewer/QtEvent.cpp
index cc52ba6..c287c66 100644
--- a/Swift/QtUI/EventViewer/QtEvent.cpp
+++ b/Swift/QtUI/EventViewer/QtEvent.cpp
@@ -20,79 +20,79 @@
namespace Swift {
QtEvent::QtEvent(boost::shared_ptr<StanzaEvent> event, bool active) : event_(event) {
- active_ = active;
+ active_ = active;
}
QVariant QtEvent::data(int role) {
- switch (role) {
- case Qt::ToolTipRole: return QVariant(text()).toString() + "\n" + B2QDATE(event_->getTime()).toString();
- case Qt::DisplayRole: return QVariant(text());
- case Qt::TextColorRole: return QColor(active_ ? Qt::black : Qt::darkGray);
- case Qt::BackgroundColorRole: return QColor(active_ ? Qt::white : Qt::lightGray);
- case SenderRole: return QVariant(sender());
- /*case StatusTextRole: return statusText_;
- case AvatarRole: return avatar_;
- case PresenceIconRole: return getPresenceIcon();*/
- default: return QVariant();
- }
+ switch (role) {
+ case Qt::ToolTipRole: return QVariant(text()).toString() + "\n" + B2QDATE(event_->getTime()).toString();
+ case Qt::DisplayRole: return QVariant(text());
+ case Qt::TextColorRole: return QColor(active_ ? Qt::black : Qt::darkGray);
+ case Qt::BackgroundColorRole: return QColor(active_ ? Qt::white : Qt::lightGray);
+ case SenderRole: return QVariant(sender());
+ /*case StatusTextRole: return statusText_;
+ case AvatarRole: return avatar_;
+ case PresenceIconRole: return getPresenceIcon();*/
+ default: return QVariant();
+ }
}
QString QtEvent::sender() {
- boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
- if (messageEvent) {
- return P2QSTRING(messageEvent->getStanza()->getFrom().toString());
- }
- boost::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event_);
- if (subscriptionRequestEvent) {
- return P2QSTRING(subscriptionRequestEvent->getJID().toBare().toString());
- }
- boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event_);
- if (errorEvent) {
- return P2QSTRING(errorEvent->getJID().toBare().toString());
- }
- boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_);
- if (mucInviteEvent) {
- return P2QSTRING(mucInviteEvent->getInviter().toString());
- }
- boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event_);
- if (incomingFTEvent) {
- return P2QSTRING(incomingFTEvent->getSender().toString());
- }
- return "";
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
+ if (messageEvent) {
+ return P2QSTRING(messageEvent->getStanza()->getFrom().toString());
+ }
+ boost::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event_);
+ if (subscriptionRequestEvent) {
+ return P2QSTRING(subscriptionRequestEvent->getJID().toBare().toString());
+ }
+ boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event_);
+ if (errorEvent) {
+ return P2QSTRING(errorEvent->getJID().toBare().toString());
+ }
+ boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_);
+ if (mucInviteEvent) {
+ return P2QSTRING(mucInviteEvent->getInviter().toString());
+ }
+ boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event_);
+ if (incomingFTEvent) {
+ return P2QSTRING(incomingFTEvent->getSender().toString());
+ }
+ return "";
}
QString QtEvent::text() {
- boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
- if (messageEvent) {
- return P2QSTRING(messageEvent->getStanza()->getBody().get_value_or(""));
- }
- boost::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event_);
- if (subscriptionRequestEvent) {
- std::string reason = subscriptionRequestEvent->getReason();
- QString message;
- if (reason.empty()) {
- message = QString(QObject::tr("%1 would like to add you to their contact list.")).arg(subscriptionRequestEvent->getJID().toBare().toString().c_str());
- }
- else {
- message = QString(QObject::tr("%1 would like to add you to their contact list, saying '%2'")).arg(subscriptionRequestEvent->getJID().toBare().toString().c_str()).arg(reason.c_str());
- }
- return message;
- }
- boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event_);
- if (errorEvent) {
- return P2QSTRING(errorEvent->getText());
- }
- boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_);
- if (mucInviteEvent) {
- QString message = QString(QObject::tr("%1 has invited you to enter the %2 room.")).arg(P2QSTRING(mucInviteEvent->getInviter().toBare().toString())).arg(P2QSTRING(mucInviteEvent->getRoomJID().toString()));
- return message;
- }
- boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event_);
- if (incomingFTEvent) {
- QString message = QString(QObject::tr("%1 would like to send a file to you.")).arg(P2QSTRING(incomingFTEvent->getSender().toBare().toString()));
- return message;
- }
- return "";
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
+ if (messageEvent) {
+ return P2QSTRING(messageEvent->getStanza()->getBody().get_value_or(""));
+ }
+ boost::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event_);
+ if (subscriptionRequestEvent) {
+ std::string reason = subscriptionRequestEvent->getReason();
+ QString message;
+ if (reason.empty()) {
+ message = QString(QObject::tr("%1 would like to add you to their contact list.")).arg(subscriptionRequestEvent->getJID().toBare().toString().c_str());
+ }
+ else {
+ message = QString(QObject::tr("%1 would like to add you to their contact list, saying '%2'")).arg(subscriptionRequestEvent->getJID().toBare().toString().c_str()).arg(reason.c_str());
+ }
+ return message;
+ }
+ boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event_);
+ if (errorEvent) {
+ return P2QSTRING(errorEvent->getText());
+ }
+ boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_);
+ if (mucInviteEvent) {
+ QString message = QString(QObject::tr("%1 has invited you to enter the %2 room.")).arg(P2QSTRING(mucInviteEvent->getInviter().toBare().toString())).arg(P2QSTRING(mucInviteEvent->getRoomJID().toString()));
+ return message;
+ }
+ boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event_);
+ if (incomingFTEvent) {
+ QString message = QString(QObject::tr("%1 would like to send a file to you.")).arg(P2QSTRING(incomingFTEvent->getSender().toBare().toString()));
+ return message;
+ }
+ return "";
}
}
diff --git a/Swift/QtUI/EventViewer/QtEvent.h b/Swift/QtUI/EventViewer/QtEvent.h
index 3be041c..d369255 100644
--- a/Swift/QtUI/EventViewer/QtEvent.h
+++ b/Swift/QtUI/EventViewer/QtEvent.h
@@ -13,20 +13,20 @@
#include <Swift/Controllers/XMPPEvents/StanzaEvent.h>
namespace Swift {
- class QtEvent {
- public:
- QtEvent(boost::shared_ptr<StanzaEvent> event, bool active);
- QVariant data(int role);
- boost::shared_ptr<StanzaEvent> getEvent() { return event_; }
- enum EventRoles {
- SenderRole = Qt::UserRole
+ class QtEvent {
+ public:
+ QtEvent(boost::shared_ptr<StanzaEvent> event, bool active);
+ QVariant data(int role);
+ boost::shared_ptr<StanzaEvent> getEvent() { return event_; }
+ enum EventRoles {
+ SenderRole = Qt::UserRole
- };
+ };
- private:
- QString text();
- QString sender();
- boost::shared_ptr<StanzaEvent> event_;
- bool active_;
- };
+ private:
+ QString text();
+ QString sender();
+ boost::shared_ptr<StanzaEvent> event_;
+ bool active_;
+ };
}
diff --git a/Swift/QtUI/EventViewer/QtEventWindow.cpp b/Swift/QtUI/EventViewer/QtEventWindow.cpp
index f92cd07..8395a6c 100644
--- a/Swift/QtUI/EventViewer/QtEventWindow.cpp
+++ b/Swift/QtUI/EventViewer/QtEventWindow.cpp
@@ -26,97 +26,97 @@
namespace Swift {
QtEventWindow::QtEventWindow(UIEventStream* eventStream) : EventWindow(false) {
- QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
- layout->setContentsMargins(0,0,0,0);
- layout->setSpacing(0);
-
- view_ = new QTreeView(this);
- layout->addWidget(view_);
- eventStream_ = eventStream;
- model_ = new EventModel();
- view_->setModel(model_);
- delegate_ = new EventDelegate();
- view_->setItemDelegate(delegate_);
- view_->setHeaderHidden(true);
+ QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+ layout->setContentsMargins(0,0,0,0);
+ layout->setSpacing(0);
+
+ view_ = new QTreeView(this);
+ layout->addWidget(view_);
+ eventStream_ = eventStream;
+ model_ = new EventModel();
+ view_->setModel(model_);
+ delegate_ = new EventDelegate();
+ view_->setItemDelegate(delegate_);
+ view_->setHeaderHidden(true);
#ifdef SWIFT_PLATFORM_MACOSX
- view_->setAlternatingRowColors(true);
+ view_->setAlternatingRowColors(true);
#endif
- view_->setAnimated(true);
- view_->setIndentation(0);
- view_->setRootIsDecorated(true);
-
- readButton_ = new QPushButton(tr("Display Notice"), this);
- layout->addWidget(readButton_);
- readButton_->setEnabled(false);
- connect(readButton_, SIGNAL(clicked()), this, SLOT(handleReadClicked()));
- connect(view_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleItemClicked(const QModelIndex&)));
- connect(view_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
+ view_->setAnimated(true);
+ view_->setIndentation(0);
+ view_->setRootIsDecorated(true);
+
+ readButton_ = new QPushButton(tr("Display Notice"), this);
+ layout->addWidget(readButton_);
+ readButton_->setEnabled(false);
+ connect(readButton_, SIGNAL(clicked()), this, SLOT(handleReadClicked()));
+ connect(view_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleItemClicked(const QModelIndex&)));
+ connect(view_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
}
QtEventWindow::~QtEventWindow() {
- delete model_;
- delete delegate_;
- /* Not view_ because this is the parent */
+ delete model_;
+ delete delegate_;
+ /* Not view_ because this is the parent */
}
void QtEventWindow::handleItemClicked(const QModelIndex&) {
- readButton_->setEnabled(true);
+ readButton_->setEnabled(true);
}
void QtEventWindow::handleReadClicked() {
- QModelIndex index = view_->currentIndex();
- if (!index.isValid()) {
- return;
- }
- handleItemActivated(index);
+ QModelIndex index = view_->currentIndex();
+ if (!index.isValid()) {
+ return;
+ }
+ handleItemActivated(index);
}
void QtEventWindow::handleItemActivated(const QModelIndex& item) {
- QtEvent* event = model_->getItem(item.row());
- boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event->getEvent());
- boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event->getEvent());
- boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event->getEvent());
- boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event->getEvent());
- boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event->getEvent());
-
- if (messageEvent) {
- if (messageEvent->getStanza()->getType() == Message::Groupchat) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new JoinMUCUIEvent(messageEvent->getStanza()->getFrom().toBare(), messageEvent->getStanza()->getTo().getResource())));
- } else {
- eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(messageEvent->getStanza()->getFrom())));
- }
- } else if (subscriptionEvent) {
- QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this);
- window->show();
- } else if (mucInviteEvent) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(mucInviteEvent->getInviter())));
- mucInviteEvent->conclude();
- } else if (incomingFTEvent) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(incomingFTEvent->getSender())));
- incomingFTEvent->conclude();
- } else {
- if (errorEvent) {
- errorEvent->conclude();
- }
- QMessageBox msgBox;
- msgBox.setText(model_->data(item, Qt::DisplayRole).toString());
- msgBox.exec();
- }
+ QtEvent* event = model_->getItem(item.row());
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event->getEvent());
+ boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event->getEvent());
+ boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event->getEvent());
+ boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event->getEvent());
+ boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event->getEvent());
+
+ if (messageEvent) {
+ if (messageEvent->getStanza()->getType() == Message::Groupchat) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new JoinMUCUIEvent(messageEvent->getStanza()->getFrom().toBare(), messageEvent->getStanza()->getTo().getResource())));
+ } else {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(messageEvent->getStanza()->getFrom())));
+ }
+ } else if (subscriptionEvent) {
+ QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this);
+ window->show();
+ } else if (mucInviteEvent) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(mucInviteEvent->getInviter())));
+ mucInviteEvent->conclude();
+ } else if (incomingFTEvent) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(incomingFTEvent->getSender())));
+ incomingFTEvent->conclude();
+ } else {
+ if (errorEvent) {
+ errorEvent->conclude();
+ }
+ QMessageBox msgBox;
+ msgBox.setText(model_->data(item, Qt::DisplayRole).toString());
+ msgBox.exec();
+ }
}
void QtEventWindow::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) {
- view_->clearSelection();
- model_->addEvent(event, active);
- emit onNewEventCountUpdated(model_->getNewEventCount());
- readButton_->setEnabled(model_->rowCount() > 0);
+ view_->clearSelection();
+ model_->addEvent(event, active);
+ emit onNewEventCountUpdated(model_->getNewEventCount());
+ readButton_->setEnabled(model_->rowCount() > 0);
}
void QtEventWindow::removeEvent(boost::shared_ptr<StanzaEvent> event) {
- view_->clearSelection();
- model_->removeEvent(event);
- emit onNewEventCountUpdated(model_->getNewEventCount());
- readButton_->setEnabled(model_->rowCount() > 0);
+ view_->clearSelection();
+ model_->removeEvent(event);
+ emit onNewEventCountUpdated(model_->getNewEventCount());
+ readButton_->setEnabled(model_->rowCount() > 0);
}
}
diff --git a/Swift/QtUI/EventViewer/QtEventWindow.h b/Swift/QtUI/EventViewer/QtEventWindow.h
index 1591c15..92f8de0 100644
--- a/Swift/QtUI/EventViewer/QtEventWindow.h
+++ b/Swift/QtUI/EventViewer/QtEventWindow.h
@@ -20,26 +20,26 @@
class QPushButton;
namespace Swift {
- class QtEventWindow : public QWidget, public EventWindow {
- Q_OBJECT
- public:
- QtEventWindow(UIEventStream* eventStream);
- ~QtEventWindow();
- void addEvent(boost::shared_ptr<StanzaEvent> event, bool active);
- void removeEvent(boost::shared_ptr<StanzaEvent> event);
- signals:
- void onNewEventCountUpdated(int count);
- private slots:
- void handleItemActivated(const QModelIndex& item);
- void handleItemClicked(const QModelIndex& item);
- void handleReadClicked();
- private:
- EventModel* model_;
- EventDelegate* delegate_;
- UIEventStream* eventStream_;
- QTreeView* view_;
- QPushButton* readButton_;
- };
-
+ class QtEventWindow : public QWidget, public EventWindow {
+ Q_OBJECT
+ public:
+ QtEventWindow(UIEventStream* eventStream);
+ ~QtEventWindow();
+ void addEvent(boost::shared_ptr<StanzaEvent> event, bool active);
+ void removeEvent(boost::shared_ptr<StanzaEvent> event);
+ signals:
+ void onNewEventCountUpdated(int count);
+ private slots:
+ void handleItemActivated(const QModelIndex& item);
+ void handleItemClicked(const QModelIndex& item);
+ void handleReadClicked();
+ private:
+ EventModel* model_;
+ EventDelegate* delegate_;
+ UIEventStream* eventStream_;
+ QTreeView* view_;
+ QPushButton* readButton_;
+ };
+
}
diff --git a/Swift/QtUI/EventViewer/TwoLineDelegate.cpp b/Swift/QtUI/EventViewer/TwoLineDelegate.cpp
index 586de55..b90acca 100644
--- a/Swift/QtUI/EventViewer/TwoLineDelegate.cpp
+++ b/Swift/QtUI/EventViewer/TwoLineDelegate.cpp
@@ -12,9 +12,9 @@
namespace Swift {
TwoLineDelegate::TwoLineDelegate(int firstRole, int secondRole, bool wrap) {
- firstRole_ = firstRole;
- secondRole_ = secondRole;
- wrap_ = wrap;
+ firstRole_ = firstRole;
+ secondRole_ = secondRole;
+ wrap_ = wrap;
}
TwoLineDelegate::~TwoLineDelegate() {
@@ -22,41 +22,41 @@ TwoLineDelegate::~TwoLineDelegate() {
}
QSize TwoLineDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, QtEvent* /*event*/ ) const {
- QFontMetrics nameMetrics(common_.nameFont);
- QFontMetrics statusMetrics(common_.detailFont);
- int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
- return QSize(150, sizeByText);
+ QFontMetrics nameMetrics(common_.nameFont);
+ QFontMetrics statusMetrics(common_.detailFont);
+ int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
+ return QSize(150, sizeByText);
}
void TwoLineDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, QtEvent* event) const {
- painter->save();
- QRect fullRegion(option.rect);
- if ( option.state & QStyle::State_Selected ) {
- painter->fillRect(fullRegion, option.palette.highlight());
- painter->setPen(option.palette.highlightedText().color());
- } else {
- QColor nameColor = event->data(Qt::TextColorRole).value<QColor>();
- painter->setPen(QPen(nameColor));
- }
-
- QFontMetrics nameMetrics(common_.nameFont);
- painter->setFont(common_.nameFont);
- int extraFontWidth = nameMetrics.width("H");
- int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
- QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
-
- int nameHeight = nameMetrics.height() + common_.verticalMargin;
- QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
-
- DelegateCommons::drawElidedText(painter, nameRegion, event->data(firstRole_).toString());
-
- painter->setFont(common_.detailFont);
- painter->setPen(QPen(QColor(160,160,160)));
-
- QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
- DelegateCommons::drawElidedText(painter, detailRegion, event->data(secondRole_).toString());
-
- painter->restore();
+ painter->save();
+ QRect fullRegion(option.rect);
+ if ( option.state & QStyle::State_Selected ) {
+ painter->fillRect(fullRegion, option.palette.highlight());
+ painter->setPen(option.palette.highlightedText().color());
+ } else {
+ QColor nameColor = event->data(Qt::TextColorRole).value<QColor>();
+ painter->setPen(QPen(nameColor));
+ }
+
+ QFontMetrics nameMetrics(common_.nameFont);
+ painter->setFont(common_.nameFont);
+ int extraFontWidth = nameMetrics.width("H");
+ int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
+ QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
+
+ int nameHeight = nameMetrics.height() + common_.verticalMargin;
+ QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
+
+ DelegateCommons::drawElidedText(painter, nameRegion, event->data(firstRole_).toString());
+
+ painter->setFont(common_.detailFont);
+ painter->setPen(QPen(QColor(160,160,160)));
+
+ QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
+ DelegateCommons::drawElidedText(painter, detailRegion, event->data(secondRole_).toString());
+
+ painter->restore();
}
}
diff --git a/Swift/QtUI/EventViewer/TwoLineDelegate.h b/Swift/QtUI/EventViewer/TwoLineDelegate.h
index 9eebb68..089f97a 100644
--- a/Swift/QtUI/EventViewer/TwoLineDelegate.h
+++ b/Swift/QtUI/EventViewer/TwoLineDelegate.h
@@ -12,18 +12,18 @@
#include <Swift/QtUI/Roster/DelegateCommons.h>
namespace Swift {
- class TwoLineDelegate {
- public:
- TwoLineDelegate(int firstRole, int secondRole, bool wrap);
- ~TwoLineDelegate();
- QSize sizeHint(const QStyleOptionViewItem& option, QtEvent* event) const;
- void paint(QPainter* painter, const QStyleOptionViewItem& option, QtEvent* event) const;
- private:
- DelegateCommons common_;
- int firstRole_;
- int secondRole_;
- bool wrap_;
- };
+ class TwoLineDelegate {
+ public:
+ TwoLineDelegate(int firstRole, int secondRole, bool wrap);
+ ~TwoLineDelegate();
+ QSize sizeHint(const QStyleOptionViewItem& option, QtEvent* event) const;
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, QtEvent* event) const;
+ private:
+ DelegateCommons common_;
+ int firstRole_;
+ int secondRole_;
+ bool wrap_;
+ };
}
diff --git a/Swift/QtUI/EventViewer/main.cpp b/Swift/QtUI/EventViewer/main.cpp
index ba2ab4b..5eddd90 100644
--- a/Swift/QtUI/EventViewer/main.cpp
+++ b/Swift/QtUI/EventViewer/main.cpp
@@ -17,17 +17,17 @@
int main(int argc, char *argv[])
{
- QApplication app(argc, argv);
- Swift::UIEventStream eventStream;
- Swift::QtEventWindow* viewer = new Swift::QtEventWindow(&eventStream);
- viewer->show();
- boost::shared_ptr<Swift::Message> message1(new Swift::Message());
- message1->setBody("Oooh, shiny");
- boost::shared_ptr<Swift::MessageEvent> event1(new Swift::MessageEvent(message1));
- viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(event1), true);
- for (int i = 0; i < 100; i++) {
- viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(event1), false);
- }
- viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(boost::make_shared<Swift::ErrorEvent>(Swift::JID("me@example.com"), "Something bad did happen to you.")), true);
- return app.exec();
+ QApplication app(argc, argv);
+ Swift::UIEventStream eventStream;
+ Swift::QtEventWindow* viewer = new Swift::QtEventWindow(&eventStream);
+ viewer->show();
+ boost::shared_ptr<Swift::Message> message1(new Swift::Message());
+ message1->setBody("Oooh, shiny");
+ boost::shared_ptr<Swift::MessageEvent> event1(new Swift::MessageEvent(message1));
+ viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(event1), true);
+ for (int i = 0; i < 100; i++) {
+ viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(event1), false);
+ }
+ viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(boost::make_shared<Swift::ErrorEvent>(Swift::JID("me@example.com"), "Something bad did happen to you.")), true);
+ return app.exec();
}
diff --git a/Swift/QtUI/FreeDesktopNotifier.cpp b/Swift/QtUI/FreeDesktopNotifier.cpp
index 54e0ccc..16f6a11 100644
--- a/Swift/QtUI/FreeDesktopNotifier.cpp
+++ b/Swift/QtUI/FreeDesktopNotifier.cpp
@@ -23,37 +23,37 @@ FreeDesktopNotifier::FreeDesktopNotifier(const std::string& name) : applicationN
}
void FreeDesktopNotifier::showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()>) {
- QDBusConnection bus = QDBusConnection::sessionBus();
- if (!bus.isConnected()) {
- return;
- }
- std::vector<Notifier::Type> defaultTypes = getDefaultTypes();
- if (std::find(defaultTypes.begin(), defaultTypes.end(), type) == defaultTypes.end()) {
- return;
- }
-
- QString body = description.c_str();
- body = body.replace("&", "&amp;");
- body = body.replace("<", "&lt;");
- body = body.replace(">", "&gt;");
-
- int timeout = (type == IncomingMessage || type == SystemMessage) ? DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS : DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS;
-
- QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "", "Notify");
-
- QStringList actions;
- QMap<QString, QVariant> hints;
- hints["x-canonical-append"] = QString("allowed");
- msg << applicationName.c_str();
- msg << quint32(0); // ID of previous notification to replace
- msg << P2QSTRING(pathToString(imageScaler.getScaledImage(picture, 48))); // Icon to display
- msg << subject.c_str(); // Summary / Header of the message to display
- msg << body; // Body of the message to display
- msg << actions; // Actions from which the user may choose
- msg << hints; // Hints to the server displaying the message
- msg << qint32(timeout*1000); // Timeout in milliseconds
-
- bus.asyncCall(msg);
+ QDBusConnection bus = QDBusConnection::sessionBus();
+ if (!bus.isConnected()) {
+ return;
+ }
+ std::vector<Notifier::Type> defaultTypes = getDefaultTypes();
+ if (std::find(defaultTypes.begin(), defaultTypes.end(), type) == defaultTypes.end()) {
+ return;
+ }
+
+ QString body = description.c_str();
+ body = body.replace("&", "&amp;");
+ body = body.replace("<", "&lt;");
+ body = body.replace(">", "&gt;");
+
+ int timeout = (type == IncomingMessage || type == SystemMessage) ? DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS : DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS;
+
+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "", "Notify");
+
+ QStringList actions;
+ QMap<QString, QVariant> hints;
+ hints["x-canonical-append"] = QString("allowed");
+ msg << applicationName.c_str();
+ msg << quint32(0); // ID of previous notification to replace
+ msg << P2QSTRING(pathToString(imageScaler.getScaledImage(picture, 48))); // Icon to display
+ msg << subject.c_str(); // Summary / Header of the message to display
+ msg << body; // Body of the message to display
+ msg << actions; // Actions from which the user may choose
+ msg << hints; // Hints to the server displaying the message
+ msg << qint32(timeout*1000); // Timeout in milliseconds
+
+ bus.asyncCall(msg);
}
}
diff --git a/Swift/QtUI/FreeDesktopNotifier.h b/Swift/QtUI/FreeDesktopNotifier.h
index 50601a0..dab7e73 100644
--- a/Swift/QtUI/FreeDesktopNotifier.h
+++ b/Swift/QtUI/FreeDesktopNotifier.h
@@ -11,15 +11,15 @@
#include <Swift/QtUI/QtCachedImageScaler.h>
namespace Swift {
- class FreeDesktopNotifier : public Notifier {
- public:
- FreeDesktopNotifier(const std::string& name);
+ class FreeDesktopNotifier : public Notifier {
+ public:
+ FreeDesktopNotifier(const std::string& name);
- virtual void showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback);
- virtual void purgeCallbacks() {}
+ virtual void showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback);
+ virtual void purgeCallbacks() {}
- private:
- std::string applicationName;
- QtCachedImageScaler imageScaler;
- };
+ private:
+ std::string applicationName;
+ QtCachedImageScaler imageScaler;
+ };
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp b/Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp
index c5f4685..0163e03 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp
+++ b/Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp
@@ -25,63 +25,63 @@ MUCSearchDelegate::~MUCSearchDelegate() {
}
// QSize MUCSearchDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
-// // MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer());
-// // if (item && dynamic_cast<MUCSearchMUCItem*>(item)) {
-// // return mucSizeHint(option, index);
-// // } else if (item && dynamic_cast<MUCSearchGroupItem*>(item)) {
-// // return groupDelegate_->sizeHint(option, index);
-// // }
-// return QStyledItemDelegate::sizeHint(option, index);
+// // MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer());
+// // if (item && dynamic_cast<MUCSearchMUCItem*>(item)) {
+// // return mucSizeHint(option, index);
+// // } else if (item && dynamic_cast<MUCSearchGroupItem*>(item)) {
+// // return groupDelegate_->sizeHint(option, index);
+// // }
+// return QStyledItemDelegate::sizeHint(option, index);
// }
// QSize MUCSearchDelegate::mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const {
-// QFontMetrics nameMetrics(common_.nameFont);
-// QFontMetrics statusMetrics(common_.detailFont);
-// int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
-// return QSize(150, sizeByText);
+// QFontMetrics nameMetrics(common_.nameFont);
+// QFontMetrics statusMetrics(common_.detailFont);
+// int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
+// return QSize(150, sizeByText);
// }
// void MUCSearchDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
-// MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer());
-// if (item && dynamic_cast<MUCSearchMUCItem*>(item)) {
-// paintMUC(painter, option, dynamic_cast<MUCSearchMUCItem*>(item));
-// } else if (item && dynamic_cast<MUCSearchGroupItem*>(item)) {
-// MUCSearchGroupItem* group = dynamic_cast<MUCSearchGroupItem*>(item);
-// groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open);
-// } else {
-// QStyledItemDelegate::paint(painter, option, index);
-// }
+// MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer());
+// if (item && dynamic_cast<MUCSearchMUCItem*>(item)) {
+// paintMUC(painter, option, dynamic_cast<MUCSearchMUCItem*>(item));
+// } else if (item && dynamic_cast<MUCSearchGroupItem*>(item)) {
+// MUCSearchGroupItem* group = dynamic_cast<MUCSearchGroupItem*>(item);
+// groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open);
+// } else {
+// QStyledItemDelegate::paint(painter, option, index);
+// }
// }
// void MUCSearchDelegate::paintMUC(QPainter* painter, const QStyleOptionViewItem& option, MUCSearchMUCItem* item) const {
-// painter->save();
-// QRect fullRegion(option.rect);
-// if ( option.state & QStyle::State_Selected ) {
-// painter->fillRect(fullRegion, option.palette.highlight());
-// painter->setPen(option.palette.highlightedText().color());
-// } else {
-// QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
-// painter->setPen(QPen(nameColor));
-// }
-
-// QFontMetrics nameMetrics(common_.nameFont);
-// painter->setFont(common_.nameFont);
-// int extraFontWidth = nameMetrics.width("H");
-// int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
-// QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
-
-// int nameHeight = nameMetrics.height() + common_.verticalMargin;
-// QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
-
-// painter->drawText(nameRegion, Qt::AlignTop, item->data(Qt::DisplayRole).toString());
-
-// painter->setFont(common_.detailFont);
-// painter->setPen(QPen(QColor(160,160,160)));
-
-// QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
-// painter->drawText(detailRegion, Qt::AlignTop, item->data(DetailTextRole).toString());
-
-// painter->restore();
+// painter->save();
+// QRect fullRegion(option.rect);
+// if ( option.state & QStyle::State_Selected ) {
+// painter->fillRect(fullRegion, option.palette.highlight());
+// painter->setPen(option.palette.highlightedText().color());
+// } else {
+// QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
+// painter->setPen(QPen(nameColor));
+// }
+
+// QFontMetrics nameMetrics(common_.nameFont);
+// painter->setFont(common_.nameFont);
+// int extraFontWidth = nameMetrics.width("H");
+// int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
+// QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
+
+// int nameHeight = nameMetrics.height() + common_.verticalMargin;
+// QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
+
+// painter->drawText(nameRegion, Qt::AlignTop, item->data(Qt::DisplayRole).toString());
+
+// painter->setFont(common_.detailFont);
+// painter->setPen(QPen(QColor(160,160,160)));
+
+// QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
+// painter->drawText(detailRegion, Qt::AlignTop, item->data(DetailTextRole).toString());
+
+// painter->restore();
// }
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchDelegate.h b/Swift/QtUI/MUCSearch/MUCSearchDelegate.h
index d521d7b..5bf9646 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchDelegate.h
+++ b/Swift/QtUI/MUCSearch/MUCSearchDelegate.h
@@ -11,18 +11,18 @@
#include <Swift/QtUI/Roster/DelegateCommons.h>
namespace Swift {
- class MUCSearchDelegate : public QStyledItemDelegate {
- public:
- MUCSearchDelegate();
- ~MUCSearchDelegate();
- /* QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; */
- /* void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; */
- private:
-// void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, MUCSearchMUCItem* item) const;
-// QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;
+ class MUCSearchDelegate : public QStyledItemDelegate {
+ public:
+ MUCSearchDelegate();
+ ~MUCSearchDelegate();
+ /* QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; */
+ /* void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; */
+ private:
+// void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, MUCSearchMUCItem* item) const;
+// QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;
- DelegateCommons common_;
- };
+ DelegateCommons common_;
+ };
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp b/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp
index 5ab6391..d95682c 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp
+++ b/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp
@@ -13,27 +13,27 @@
namespace Swift {
MUCSearchEmptyItem::MUCSearchEmptyItem(MUCSearchServiceItem* parent) : parent(parent) {
- parent->addRoom(this);
+ parent->addRoom(this);
}
MUCSearchServiceItem* MUCSearchEmptyItem::getParent() {
- return parent;
+ return parent;
}
QVariant MUCSearchEmptyItem::data(int role) {
- switch (role) {
- case Qt::DisplayRole:
- return QVariant(QObject::tr("No rooms found"));
- case Qt::FontRole: {
- QFont font;
- font.setItalic(true);
- return font;
- }
- case Qt::ForegroundRole:
- return QColor(Qt::gray);
- default:
- return QVariant();
- }
+ switch (role) {
+ case Qt::DisplayRole:
+ return QVariant(QObject::tr("No rooms found"));
+ case Qt::FontRole: {
+ QFont font;
+ font.setItalic(true);
+ return font;
+ }
+ case Qt::ForegroundRole:
+ return QColor(Qt::gray);
+ default:
+ return QVariant();
+ }
}
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h b/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h
index 74e0154..ca4b2b2 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h
+++ b/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h
@@ -9,17 +9,17 @@
#include <Swift/QtUI/MUCSearch/MUCSearchItem.h>
namespace Swift {
- class MUCSearchServiceItem;
+ class MUCSearchServiceItem;
- class MUCSearchEmptyItem : public MUCSearchItem {
- public:
- MUCSearchEmptyItem(MUCSearchServiceItem* parent);
+ class MUCSearchEmptyItem : public MUCSearchItem {
+ public:
+ MUCSearchEmptyItem(MUCSearchServiceItem* parent);
- MUCSearchServiceItem* getParent();
+ MUCSearchServiceItem* getParent();
- QVariant data(int role);
+ QVariant data(int role);
- private:
- MUCSearchServiceItem* parent;
- };
+ private:
+ MUCSearchServiceItem* parent;
+ };
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchItem.h b/Swift/QtUI/MUCSearch/MUCSearchItem.h
index d2a2c2d..c378247 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchItem.h
+++ b/Swift/QtUI/MUCSearch/MUCSearchItem.h
@@ -9,9 +9,9 @@
#include <QVariant>
namespace Swift {
- class MUCSearchItem {
- public:
- virtual ~MUCSearchItem() {}
- virtual QVariant data(int role) = 0;
- };
+ class MUCSearchItem {
+ public:
+ virtual ~MUCSearchItem() {}
+ virtual QVariant data(int role) = 0;
+ };
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchModel.cpp b/Swift/QtUI/MUCSearch/MUCSearchModel.cpp
index 1a3ccc4..af6f17f 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchModel.cpp
+++ b/Swift/QtUI/MUCSearch/MUCSearchModel.cpp
@@ -14,78 +14,78 @@ MUCSearchModel::MUCSearchModel() {
}
void MUCSearchModel::clear() {
- emit layoutAboutToBeChanged();
- services_.clear();
- emit layoutChanged();
+ emit layoutAboutToBeChanged();
+ services_.clear();
+ emit layoutChanged();
}
void MUCSearchModel::addService(MUCSearchServiceItem* service) {
- emit layoutAboutToBeChanged();
- services_.push_back(service);
- emit layoutChanged();
+ emit layoutAboutToBeChanged();
+ services_.push_back(service);
+ emit layoutChanged();
}
int MUCSearchModel::columnCount(const QModelIndex& /*parent*/) const {
- return 1;
+ return 1;
}
QVariant MUCSearchModel::data(const QModelIndex& index, int role) const {
- return index.isValid() ? static_cast<MUCSearchItem*>(index.internalPointer())->data(role) : QVariant();
+ return index.isValid() ? static_cast<MUCSearchItem*>(index.internalPointer())->data(role) : QVariant();
}
QModelIndex MUCSearchModel::index(int row, int column, const QModelIndex & parent) const {
- if (!hasIndex(row, column, parent)) {
- return QModelIndex();
- }
-
- if (parent.isValid()) {
- MUCSearchServiceItem* parentItem = static_cast<MUCSearchServiceItem*>(parent.internalPointer());
- return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex();
- } else {
- return row < services_.size() ? createIndex(row, column, services_[row]) : QModelIndex();
- }
+ if (!hasIndex(row, column, parent)) {
+ return QModelIndex();
+ }
+
+ if (parent.isValid()) {
+ MUCSearchServiceItem* parentItem = static_cast<MUCSearchServiceItem*>(parent.internalPointer());
+ return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex();
+ } else {
+ return row < services_.size() ? createIndex(row, column, services_[row]) : QModelIndex();
+ }
}
QModelIndex MUCSearchModel::parent(const QModelIndex& index) const {
- if (!index.isValid()) {
- return QModelIndex();
- }
- MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer());
- if (!item) {
- return QModelIndex();
- }
- else if (dynamic_cast<MUCSearchServiceItem*>(item)) {
- return QModelIndex();
- }
-
- MUCSearchServiceItem* parent = NULL;
- if (MUCSearchRoomItem* roomItem = dynamic_cast<MUCSearchRoomItem*>(item)) {
- parent = roomItem->getParent();
- }
- else if (MUCSearchEmptyItem* emptyItem = dynamic_cast<MUCSearchEmptyItem*>(item)) {
- parent = emptyItem->getParent();
- }
- if (parent) {
- int row = services_.indexOf(parent);
- return createIndex(row, 1, parent);
- }
- else {
- return QModelIndex();
- }
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+ MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer());
+ if (!item) {
+ return QModelIndex();
+ }
+ else if (dynamic_cast<MUCSearchServiceItem*>(item)) {
+ return QModelIndex();
+ }
+
+ MUCSearchServiceItem* parent = NULL;
+ if (MUCSearchRoomItem* roomItem = dynamic_cast<MUCSearchRoomItem*>(item)) {
+ parent = roomItem->getParent();
+ }
+ else if (MUCSearchEmptyItem* emptyItem = dynamic_cast<MUCSearchEmptyItem*>(item)) {
+ parent = emptyItem->getParent();
+ }
+ if (parent) {
+ int row = services_.indexOf(parent);
+ return createIndex(row, 1, parent);
+ }
+ else {
+ return QModelIndex();
+ }
}
int MUCSearchModel::rowCount(const QModelIndex& parentIndex) const {
- if (!parentIndex.isValid()) {
- return services_.size();
- }
- if (dynamic_cast<MUCSearchServiceItem*>(static_cast<MUCSearchItem*>(parentIndex.internalPointer()))) {
- return services_[parentIndex.row()]->rowCount();
- }
- else {
- return 0;
- }
+ if (!parentIndex.isValid()) {
+ return services_.size();
+ }
+ if (dynamic_cast<MUCSearchServiceItem*>(static_cast<MUCSearchItem*>(parentIndex.internalPointer()))) {
+ return services_[parentIndex.row()]->rowCount();
+ }
+ else {
+ return 0;
+ }
}
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchModel.h b/Swift/QtUI/MUCSearch/MUCSearchModel.h
index 4ea811f..d6a24f3 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchModel.h
+++ b/Swift/QtUI/MUCSearch/MUCSearchModel.h
@@ -14,22 +14,22 @@
#include <Swift/QtUI/MUCSearch/MUCSearchServiceItem.h>
namespace Swift {
- class MUCSearchModel : public QAbstractItemModel {
- Q_OBJECT
- public:
- MUCSearchModel();
- void clear();
- void addService(MUCSearchServiceItem* service);
- int columnCount(const QModelIndex& parent = QModelIndex()) const;
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex& index) const;
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
-// ChatListItem* getItemForIndex(const QModelIndex& index) const;
- private:
-// ChatListGroupItem* mucBookmarks_;
-// ChatListGroupItem* root_;
- QList<MUCSearchServiceItem*> services_;
- };
+ class MUCSearchModel : public QAbstractItemModel {
+ Q_OBJECT
+ public:
+ MUCSearchModel();
+ void clear();
+ void addService(MUCSearchServiceItem* service);
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex& index) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+// ChatListItem* getItemForIndex(const QModelIndex& index) const;
+ private:
+// ChatListGroupItem* mucBookmarks_;
+// ChatListGroupItem* root_;
+ QList<MUCSearchServiceItem*> services_;
+ };
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp b/Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp
index 169ab49..cb7ee2d 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp
+++ b/Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp
@@ -10,17 +10,17 @@
namespace Swift {
MUCSearchRoomItem::MUCSearchRoomItem(const QString& node, MUCSearchServiceItem* parent) : parent_(parent), node_(node) {
- parent_->addRoom(this);
+ parent_->addRoom(this);
}
MUCSearchServiceItem* MUCSearchRoomItem::getParent() {
- return parent_;
+ return parent_;
}
QVariant MUCSearchRoomItem::data(int role) {
- switch (role) {
- case Qt::DisplayRole: return QVariant(node_);
- default: return QVariant();
- }
+ switch (role) {
+ case Qt::DisplayRole: return QVariant(node_);
+ default: return QVariant();
+ }
}
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchRoomItem.h b/Swift/QtUI/MUCSearch/MUCSearchRoomItem.h
index c853221..d2b88bc 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchRoomItem.h
+++ b/Swift/QtUI/MUCSearch/MUCSearchRoomItem.h
@@ -9,15 +9,15 @@
#include <Swift/QtUI/MUCSearch/MUCSearchItem.h>
namespace Swift {
- class MUCSearchServiceItem;
- class MUCSearchRoomItem : public MUCSearchItem {
- public:
- MUCSearchRoomItem(const QString& node, MUCSearchServiceItem* parent);
- MUCSearchServiceItem* getParent();
- QVariant data(int role);
- QString getNode() const {return node_;}
- private:
- MUCSearchServiceItem* parent_;
- QString node_;
- };
+ class MUCSearchServiceItem;
+ class MUCSearchRoomItem : public MUCSearchItem {
+ public:
+ MUCSearchRoomItem(const QString& node, MUCSearchServiceItem* parent);
+ MUCSearchServiceItem* getParent();
+ QVariant data(int role);
+ QString getNode() const {return node_;}
+ private:
+ MUCSearchServiceItem* parent_;
+ QString node_;
+ };
}
diff --git a/Swift/QtUI/MUCSearch/MUCSearchServiceItem.h b/Swift/QtUI/MUCSearch/MUCSearchServiceItem.h
index 421ac25..cfde071 100644
--- a/Swift/QtUI/MUCSearch/MUCSearchServiceItem.h
+++ b/Swift/QtUI/MUCSearch/MUCSearchServiceItem.h
@@ -12,21 +12,21 @@
#include <Swift/QtUI/MUCSearch/MUCSearchRoomItem.h>
namespace Swift {
- class MUCSearchServiceItem : public MUCSearchItem {
- public:
- MUCSearchServiceItem(const QString& jidString) : jidString_(jidString) {}
- void addRoom(MUCSearchItem* room) {rooms_.push_back(room);}
- int rowCount() {return rooms_.count();}
- MUCSearchItem* getItem(int i) {return rooms_[i];}
- QVariant data(int role) {
- switch (role) {
- case Qt::DisplayRole: return QVariant(jidString_);
- default: return QVariant();
- }
- }
- QString getHost() const {return jidString_;}
- private:
- QList<MUCSearchItem*> rooms_;
- QString jidString_;
- };
+ class MUCSearchServiceItem : public MUCSearchItem {
+ public:
+ MUCSearchServiceItem(const QString& jidString) : jidString_(jidString) {}
+ void addRoom(MUCSearchItem* room) {rooms_.push_back(room);}
+ int rowCount() {return rooms_.count();}
+ MUCSearchItem* getItem(int i) {return rooms_[i];}
+ QVariant data(int role) {
+ switch (role) {
+ case Qt::DisplayRole: return QVariant(jidString_);
+ default: return QVariant();
+ }
+ }
+ QString getHost() const {return jidString_;}
+ private:
+ QList<MUCSearchItem*> rooms_;
+ QString jidString_;
+ };
}
diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
index e3bd7f3..03fa582 100644
--- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
+++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
@@ -24,37 +24,37 @@
namespace Swift {
QtMUCSearchWindow::QtMUCSearchWindow() {
- ui_.setupUi(this);
+ ui_.setupUi(this);
#ifndef Q_OS_MAC
- setWindowIcon(QIcon(":/logo-icon-16.png"));
+ setWindowIcon(QIcon(":/logo-icon-16.png"));
#endif
- setModal(true);
- ui_.filter_->hide();
- model_ = new MUCSearchModel();
- delegate_ = new MUCSearchDelegate();
- ui_.results_->setModel(model_);
- ui_.results_->setItemDelegate(delegate_);
- ui_.results_->setHeaderHidden(true);
- ui_.results_->setRootIsDecorated(true);
- ui_.results_->setAnimated(true);
- ui_.results_->setAlternatingRowColors(true);
- connect(ui_.searchButton, SIGNAL(clicked()), this, SLOT(handleSearch()));
- connect(ui_.service_, SIGNAL(activated(const QString&)), this, SLOT(handleSearch(const QString&)));
- connect(ui_.results_->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), this, SLOT(handleSelectionChanged (const QItemSelection&, const QItemSelection&)));
- connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&)));
- connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&)));
- // Not using a button box, because i can't seem to be able to make the ok button non-default (on mac)
- connect(ui_.okButton, SIGNAL(clicked()), this, SLOT(accept()));
- ui_.okButton->setEnabled(false);
- connect(ui_.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
-
- throbber_ = new QLabel(tr("Searching"), ui_.results_);
- throbber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), throbber_));
- throbber_->setToolTip(tr("Searching"));
-
- hasHadScrollBars_ = false;
- updateThrobberPosition();
- setSearchInProgress(false);
+ setModal(true);
+ ui_.filter_->hide();
+ model_ = new MUCSearchModel();
+ delegate_ = new MUCSearchDelegate();
+ ui_.results_->setModel(model_);
+ ui_.results_->setItemDelegate(delegate_);
+ ui_.results_->setHeaderHidden(true);
+ ui_.results_->setRootIsDecorated(true);
+ ui_.results_->setAnimated(true);
+ ui_.results_->setAlternatingRowColors(true);
+ connect(ui_.searchButton, SIGNAL(clicked()), this, SLOT(handleSearch()));
+ connect(ui_.service_, SIGNAL(activated(const QString&)), this, SLOT(handleSearch(const QString&)));
+ connect(ui_.results_->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), this, SLOT(handleSelectionChanged (const QItemSelection&, const QItemSelection&)));
+ connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&)));
+ connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&)));
+ // Not using a button box, because i can't seem to be able to make the ok button non-default (on mac)
+ connect(ui_.okButton, SIGNAL(clicked()), this, SLOT(accept()));
+ ui_.okButton->setEnabled(false);
+ connect(ui_.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+
+ throbber_ = new QLabel(tr("Searching"), ui_.results_);
+ throbber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), throbber_));
+ throbber_->setToolTip(tr("Searching"));
+
+ hasHadScrollBars_ = false;
+ updateThrobberPosition();
+ setSearchInProgress(false);
}
QtMUCSearchWindow::~QtMUCSearchWindow() {
@@ -62,136 +62,136 @@ QtMUCSearchWindow::~QtMUCSearchWindow() {
}
void QtMUCSearchWindow::resizeEvent(QResizeEvent* /*event*/) {
- updateThrobberPosition();
+ updateThrobberPosition();
}
void QtMUCSearchWindow::updateThrobberPosition() {
- bool isShown = throbber_->isVisible();
- int resultWidth = ui_.results_->width();
- int resultHeight = ui_.results_->height();
- //throbberWidth = throbber_->movie()->scaledSize().width();
- //throbberHeight = throbber_->movie()->scaledSize().height();
- int throbberWidth = 16; /* This is nasty, but the above doesn't work! */
- int throbberHeight = 16;
- /* It's difficult (or I spent a while trying) to work out whether the scrollbars are currently shown and their appropriate size,
- * because if you listen for the expanded/collapsed signals, you seem to get them before the scrollbars are updated.
- * This seems an acceptable workaround.
- */
- hasHadScrollBars_ |= ui_.results_->verticalScrollBar()->isVisible();
- int hMargin = hasHadScrollBars_ ? ui_.results_->verticalScrollBar()->width() + 2 : 2;
- int vMargin = 2; /* We don't get horizontal scrollbars */
- throbber_->setGeometry(QRect(resultWidth - throbberWidth - hMargin, resultHeight - throbberHeight - vMargin, throbberWidth, throbberHeight)); /* include margins */
- throbber_->setVisible(isShown);
+ bool isShown = throbber_->isVisible();
+ int resultWidth = ui_.results_->width();
+ int resultHeight = ui_.results_->height();
+ //throbberWidth = throbber_->movie()->scaledSize().width();
+ //throbberHeight = throbber_->movie()->scaledSize().height();
+ int throbberWidth = 16; /* This is nasty, but the above doesn't work! */
+ int throbberHeight = 16;
+ /* It's difficult (or I spent a while trying) to work out whether the scrollbars are currently shown and their appropriate size,
+ * because if you listen for the expanded/collapsed signals, you seem to get them before the scrollbars are updated.
+ * This seems an acceptable workaround.
+ */
+ hasHadScrollBars_ |= ui_.results_->verticalScrollBar()->isVisible();
+ int hMargin = hasHadScrollBars_ ? ui_.results_->verticalScrollBar()->width() + 2 : 2;
+ int vMargin = 2; /* We don't get horizontal scrollbars */
+ throbber_->setGeometry(QRect(resultWidth - throbberWidth - hMargin, resultHeight - throbberHeight - vMargin, throbberWidth, throbberHeight)); /* include margins */
+ throbber_->setVisible(isShown);
}
void QtMUCSearchWindow::addSavedServices(const std::list<JID>& services) {
- ui_.service_->clear();
- foreach (const JID& jid, services) {
- ui_.service_->addItem(P2QSTRING(jid.toString()));
- }
- if (!services.empty()) {
- ui_.service_->setEditText(P2QSTRING(services.begin()->toString()));
- }
- else {
- ui_.service_->clearEditText();
- }
+ ui_.service_->clear();
+ foreach (const JID& jid, services) {
+ ui_.service_->addItem(P2QSTRING(jid.toString()));
+ }
+ if (!services.empty()) {
+ ui_.service_->setEditText(P2QSTRING(services.begin()->toString()));
+ }
+ else {
+ ui_.service_->clearEditText();
+ }
}
void QtMUCSearchWindow::handleActivated(const QModelIndex& index) {
- if (!index.isValid()) {
- return;
- }
- if (dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(index.internalPointer()))) {
- accept();
- }
+ if (!index.isValid()) {
+ return;
+ }
+ if (dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(index.internalPointer()))) {
+ accept();
+ }
}
void QtMUCSearchWindow::handleSearch() {
- handleSearch(ui_.service_->currentText());
+ handleSearch(ui_.service_->currentText());
}
void QtMUCSearchWindow::handleSearch(const QString& service) {
- if (!service.isEmpty()) {
- onSearchService(JID(Q2PSTRING(service)));
- }
+ if (!service.isEmpty()) {
+ onSearchService(JID(Q2PSTRING(service)));
+ }
}
void QtMUCSearchWindow::show() {
- QWidget::show();
- QWidget::activateWindow();
+ QWidget::show();
+ QWidget::activateWindow();
}
void QtMUCSearchWindow::clearList() {
- model_->clear();
+ model_->clear();
}
void QtMUCSearchWindow::addService(const MUCService& service) {
- updateThrobberPosition();
- MUCSearchServiceItem* serviceItem = new MUCSearchServiceItem(P2QSTRING(service.getJID().toString()));
- if (service.getRooms().size() > 0) {
- foreach (MUCService::MUCRoom room, service.getRooms()) {
- new MUCSearchRoomItem(P2QSTRING(room.getNode()), serviceItem);
- }
- }
- else {
- new MUCSearchEmptyItem(serviceItem);
- }
- model_->addService(serviceItem);
- ui_.results_->expandAll();
+ updateThrobberPosition();
+ MUCSearchServiceItem* serviceItem = new MUCSearchServiceItem(P2QSTRING(service.getJID().toString()));
+ if (service.getRooms().size() > 0) {
+ foreach (MUCService::MUCRoom room, service.getRooms()) {
+ new MUCSearchRoomItem(P2QSTRING(room.getNode()), serviceItem);
+ }
+ }
+ else {
+ new MUCSearchEmptyItem(serviceItem);
+ }
+ model_->addService(serviceItem);
+ ui_.results_->expandAll();
}
void QtMUCSearchWindow::setSearchInProgress(bool searching) {
- if (searching) {
- throbber_->movie()->start();
- } else {
- throbber_->movie()->stop();
- }
- throbber_->setVisible(searching);
+ if (searching) {
+ throbber_->movie()->start();
+ } else {
+ throbber_->movie()->stop();
+ }
+ throbber_->setVisible(searching);
}
void QtMUCSearchWindow::accept() {
- MUCSearchRoomItem* room = getSelectedRoom();
- if (room) {
- onFinished(JID(Q2PSTRING(room->getNode()), Q2PSTRING(room->getParent()->getHost())));
- }
- else {
- onFinished(boost::optional<JID>());
- }
- QDialog::accept();
+ MUCSearchRoomItem* room = getSelectedRoom();
+ if (room) {
+ onFinished(JID(Q2PSTRING(room->getNode()), Q2PSTRING(room->getParent()->getHost())));
+ }
+ else {
+ onFinished(boost::optional<JID>());
+ }
+ QDialog::accept();
}
void QtMUCSearchWindow::reject() {
- onFinished(boost::optional<JID>());
- QDialog::reject();
+ onFinished(boost::optional<JID>());
+ QDialog::reject();
}
void QtMUCSearchWindow::handleSelectionChanged(const QItemSelection&, const QItemSelection&) {
- ui_.okButton->setEnabled(getSelectedRoom());
+ ui_.okButton->setEnabled(getSelectedRoom());
}
MUCSearchRoomItem* QtMUCSearchWindow::getSelectedRoom() const {
- // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the
- // QModelIndexList destructor.
- // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case
- // was resolved by linking against the debug libs, ours isn't, and we're not alone)
- QItemSelection ranges = ui_.results_->selectionModel()->selection();
- QModelIndexList lstIndex;
- for (int i = 0; i < ranges.count(); ++i) {
- QModelIndex parent = ranges.at(i).parent();
- int right = ranges.at(i).model()->columnCount(parent) - 1;
- if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) {
- for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) {
- lstIndex.append(ranges.at(i).model()->index(r, 0, parent));
- }
- }
- }
- if (lstIndex.isEmpty()) {
- return NULL;
- }
- else {
- return dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(lstIndex.first().internalPointer()));
- }
+ // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the
+ // QModelIndexList destructor.
+ // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case
+ // was resolved by linking against the debug libs, ours isn't, and we're not alone)
+ QItemSelection ranges = ui_.results_->selectionModel()->selection();
+ QModelIndexList lstIndex;
+ for (int i = 0; i < ranges.count(); ++i) {
+ QModelIndex parent = ranges.at(i).parent();
+ int right = ranges.at(i).model()->columnCount(parent) - 1;
+ if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) {
+ for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) {
+ lstIndex.append(ranges.at(i).model()->index(r, 0, parent));
+ }
+ }
+ }
+ if (lstIndex.isEmpty()) {
+ return NULL;
+ }
+ else {
+ return dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(lstIndex.first().internalPointer()));
+ }
}
}
diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h
index 4ac845a..b115e6f 100644
--- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h
+++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h
@@ -11,41 +11,41 @@
#include <Swift/QtUI/MUCSearch/ui_QtMUCSearchWindow.h>
namespace Swift {
- class MUCSearchModel;
- class MUCSearchDelegate;
- class MUCSearchRoomItem;
-
- class QtMUCSearchWindow : public QDialog, public MUCSearchWindow {
- Q_OBJECT
- public:
- QtMUCSearchWindow();
- virtual ~QtMUCSearchWindow();
-
- virtual void clearList();
- virtual void addService(const MUCService& service);
- virtual void addSavedServices(const std::list<JID>& services);
- virtual void setSearchInProgress(bool searching);
-
- virtual void show();
- virtual void accept();
- virtual void reject();
-
- protected:
- virtual void resizeEvent(QResizeEvent* event);
-
- private slots:
- void handleSearch();
- void handleSearch(const QString&);
- void handleActivated(const QModelIndex& index);
- void updateThrobberPosition();
- void handleSelectionChanged (const QItemSelection&, const QItemSelection&);
- MUCSearchRoomItem* getSelectedRoom() const;
-
- private:
- Ui::QtMUCSearchWindow ui_;
- MUCSearchModel* model_;
- MUCSearchDelegate* delegate_;
- QLabel* throbber_;
- bool hasHadScrollBars_;
- };
+ class MUCSearchModel;
+ class MUCSearchDelegate;
+ class MUCSearchRoomItem;
+
+ class QtMUCSearchWindow : public QDialog, public MUCSearchWindow {
+ Q_OBJECT
+ public:
+ QtMUCSearchWindow();
+ virtual ~QtMUCSearchWindow();
+
+ virtual void clearList();
+ virtual void addService(const MUCService& service);
+ virtual void addSavedServices(const std::list<JID>& services);
+ virtual void setSearchInProgress(bool searching);
+
+ virtual void show();
+ virtual void accept();
+ virtual void reject();
+
+ protected:
+ virtual void resizeEvent(QResizeEvent* event);
+
+ private slots:
+ void handleSearch();
+ void handleSearch(const QString&);
+ void handleActivated(const QModelIndex& index);
+ void updateThrobberPosition();
+ void handleSelectionChanged (const QItemSelection&, const QItemSelection&);
+ MUCSearchRoomItem* getSelectedRoom() const;
+
+ private:
+ Ui::QtMUCSearchWindow ui_;
+ MUCSearchModel* model_;
+ MUCSearchDelegate* delegate_;
+ QLabel* throbber_;
+ bool hasHadScrollBars_;
+ };
}
diff --git a/Swift/QtUI/MessageSnippet.cpp b/Swift/QtUI/MessageSnippet.cpp
index c2969cf..85cbdb9 100644
--- a/Swift/QtUI/MessageSnippet.cpp
+++ b/Swift/QtUI/MessageSnippet.cpp
@@ -11,33 +11,33 @@
namespace Swift {
MessageSnippet::MessageSnippet(const QString& message, const QString& sender, const QDateTime& time, const QString& iconURI, bool isIncoming, bool appendToPrevious, QtChatTheme* theme, const QString& id, Direction direction) : ChatSnippet(appendToPrevious) {
- if (appendToPrevious) {
- setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet>(new MessageSnippet(message, sender, time, iconURI, isIncoming, false, theme, id, direction)));
- }
- if (isIncoming) {
- if (appendToPrevious) {
- content_ = theme->getIncomingNextContent();
- }
- else {
- content_ = theme->getIncomingContent();
- }
- }
- else {
- if (appendToPrevious) {
- content_ = theme->getOutgoingNextContent();
- }
- else {
- content_ = theme->getOutgoingContent();
- }
- }
-
- content_.replace("%direction%", directionToCSS(direction));
- content_.replace("%message%", wrapResizable("<span class='swift_message'>" + escape(message) + "</span>"));
- content_.replace("%wrapped_sender%", wrapResizable(escape(sender)));
- content_.replace("%sender%", escape(sender));
- content_.replace("%time%", wrapResizable("<span class='swift_time'>" + timeToEscapedString(time) + "</span>"));
- content_.replace("%userIconPath%", escape(iconURI));
- content_.replace("%id%", id);
+ if (appendToPrevious) {
+ setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet>(new MessageSnippet(message, sender, time, iconURI, isIncoming, false, theme, id, direction)));
+ }
+ if (isIncoming) {
+ if (appendToPrevious) {
+ content_ = theme->getIncomingNextContent();
+ }
+ else {
+ content_ = theme->getIncomingContent();
+ }
+ }
+ else {
+ if (appendToPrevious) {
+ content_ = theme->getOutgoingNextContent();
+ }
+ else {
+ content_ = theme->getOutgoingContent();
+ }
+ }
+
+ content_.replace("%direction%", directionToCSS(direction));
+ content_.replace("%message%", wrapResizable("<span class='swift_message'>" + escape(message) + "</span>"));
+ content_.replace("%wrapped_sender%", wrapResizable(escape(sender)));
+ content_.replace("%sender%", escape(sender));
+ content_.replace("%time%", wrapResizable("<span class='swift_time'>" + timeToEscapedString(time) + "</span>"));
+ content_.replace("%userIconPath%", escape(iconURI));
+ content_.replace("%id%", id);
}
MessageSnippet::~MessageSnippet() {
diff --git a/Swift/QtUI/MessageSnippet.h b/Swift/QtUI/MessageSnippet.h
index e6972a1..302785f 100644
--- a/Swift/QtUI/MessageSnippet.h
+++ b/Swift/QtUI/MessageSnippet.h
@@ -13,19 +13,19 @@
class QDateTime;
namespace Swift {
- class MessageSnippet : public ChatSnippet {
- public:
- MessageSnippet(const QString& message, const QString& sender, const QDateTime& time, const QString& iconURI, bool isIncoming, bool appendToPrevious, QtChatTheme* theme, const QString& id, Direction direction);
- virtual ~MessageSnippet();
- const QString& getContent() const {
- return content_;
- }
+ class MessageSnippet : public ChatSnippet {
+ public:
+ MessageSnippet(const QString& message, const QString& sender, const QDateTime& time, const QString& iconURI, bool isIncoming, bool appendToPrevious, QtChatTheme* theme, const QString& id, Direction direction);
+ virtual ~MessageSnippet();
+ const QString& getContent() const {
+ return content_;
+ }
- QString getContinuationElementID() const {
- return "insert";
- }
+ QString getContinuationElementID() const {
+ return "insert";
+ }
- private:
- QString content_;
- };
+ private:
+ QString content_;
+ };
}
diff --git a/Swift/QtUI/NotifierTest/NotifierTest.cpp b/Swift/QtUI/NotifierTest/NotifierTest.cpp
index 56f7985..8d2e467 100644
--- a/Swift/QtUI/NotifierTest/NotifierTest.cpp
+++ b/Swift/QtUI/NotifierTest/NotifierTest.cpp
@@ -17,12 +17,12 @@
using namespace Swift;
void notificationClicked(const std::string& message) {
- std::cout << "Notification clicked: " << message << std::endl;
+ std::cout << "Notification clicked: " << message << std::endl;
}
int main(int argc, char* argv[]) {
- QApplication app(argc, argv);
- GrowlNotifier notifier("Swift-NotifierTest");
- notifier.showMessage(Notifier::ContactAvailable, "Contact is available", "The contact has become available", ByteArray(), boost::bind(&notificationClicked, "Message 1"));
- return app.exec();
+ QApplication app(argc, argv);
+ GrowlNotifier notifier("Swift-NotifierTest");
+ notifier.showMessage(Notifier::ContactAvailable, "Contact is available", "The contact has become available", ByteArray(), boost::bind(&notificationClicked, "Message 1"));
+ return app.exec();
}
diff --git a/Swift/QtUI/QtAboutWidget.cpp b/Swift/QtUI/QtAboutWidget.cpp
index 9fb07ed..b69113f 100644
--- a/Swift/QtUI/QtAboutWidget.cpp
+++ b/Swift/QtUI/QtAboutWidget.cpp
@@ -22,67 +22,67 @@ namespace Swift {
QtAboutWidget::QtAboutWidget() : QDialog() {
#ifndef Q_OS_MAC
- setWindowTitle(QString(tr("About %1")).arg("Swift"));
+ setWindowTitle(QString(tr("About %1")).arg("Swift"));
#endif
- setWindowIcon(QIcon(":/logo-icon-16.png"));
+ setWindowIcon(QIcon(":/logo-icon-16.png"));
- resize(180, 240);
- QVBoxLayout *mainLayout = new QVBoxLayout(this);
- mainLayout->setAlignment(Qt::AlignHCenter);
- setLayout(mainLayout);
-
- QLabel* iconLabel = new QLabel(this);
- iconLabel->setPixmap(QIcon(":/logo-shaded-text.256.png").pixmap(90, 90));
- iconLabel->setAlignment(Qt::AlignHCenter);
- mainLayout->addWidget(iconLabel);
-
- QLabel* appNameLabel = new QLabel("<center><font size='+1'><b>" + QCoreApplication::applicationName() + "</b></font></center>", this);
- mainLayout->addWidget(appNameLabel);
-
- QLabel* versionLabel = new QLabel((QString("<center><font size='-1'>") + tr("Version %1") + "</font></center><center><font size='-1'><br/>" + QString(tr("Built with Qt %2")) + QString("<br/>") + QString(tr("Running with Qt %3")) + "</font></center>").arg(QCoreApplication::applicationVersion()).arg(QT_VERSION_STR).arg(qVersion()));
- versionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
- mainLayout->addWidget(versionLabel);
+ resize(180, 240);
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ mainLayout->setAlignment(Qt::AlignHCenter);
+ setLayout(mainLayout);
- if (QCoreApplication::translate("TRANSLATION_INFO", "TRANSLATION_AUTHOR") != "TRANSLATION_AUTHOR") {
- mainLayout->addWidget(new QLabel(QString("<center><font size='-1'>") + QString(tr("Using the English translation by\n%1")).arg(QCoreApplication::translate("TRANSLATION_INFO", "TRANSLATION_AUTHOR")).replace("\n", "<br/>") + "</font></center>", this));
- }
- QCoreApplication::translate("TRANSLATION_INFO", "TRANSLATION_LICENSE", "This string contains the license under which this translation is licensed. We ask you to license the translation under the BSD license. Please read http://www.opensource.org/licenses/bsd-license.php, and if you agree to release your translation under this license, use the following (untranslated) text: 'This translation is licensed under the BSD License. See http://www.opensource.org/licenses/bsd-license.php'");
+ QLabel* iconLabel = new QLabel(this);
+ iconLabel->setPixmap(QIcon(":/logo-shaded-text.256.png").pixmap(90, 90));
+ iconLabel->setAlignment(Qt::AlignHCenter);
+ mainLayout->addWidget(iconLabel);
+
+ QLabel* appNameLabel = new QLabel("<center><font size='+1'><b>" + QCoreApplication::applicationName() + "</b></font></center>", this);
+ mainLayout->addWidget(appNameLabel);
+
+ QLabel* versionLabel = new QLabel((QString("<center><font size='-1'>") + tr("Version %1") + "</font></center><center><font size='-1'><br/>" + QString(tr("Built with Qt %2")) + QString("<br/>") + QString(tr("Running with Qt %3")) + "</font></center>").arg(QCoreApplication::applicationVersion()).arg(QT_VERSION_STR).arg(qVersion()));
+ versionLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ mainLayout->addWidget(versionLabel);
+
+ if (QCoreApplication::translate("TRANSLATION_INFO", "TRANSLATION_AUTHOR") != "TRANSLATION_AUTHOR") {
+ mainLayout->addWidget(new QLabel(QString("<center><font size='-1'>") + QString(tr("Using the English translation by\n%1")).arg(QCoreApplication::translate("TRANSLATION_INFO", "TRANSLATION_AUTHOR")).replace("\n", "<br/>") + "</font></center>", this));
+ }
+ QCoreApplication::translate("TRANSLATION_INFO", "TRANSLATION_LICENSE", "This string contains the license under which this translation is licensed. We ask you to license the translation under the BSD license. Please read http://www.opensource.org/licenses/bsd-license.php, and if you agree to release your translation under this license, use the following (untranslated) text: 'This translation is licensed under the BSD License. See http://www.opensource.org/licenses/bsd-license.php'");
#if defined(SWIFTEN_PLATFORM_WINDOWS) || defined(SWIFTEN_PLATFORM_MACOSX)
- QPushButton* licenseButton = new QPushButton(tr("View License"), this);
- mainLayout->addWidget(licenseButton);
- connect(licenseButton, SIGNAL(clicked()), this, SLOT(handleLicenseClicked()));
+ QPushButton* licenseButton = new QPushButton(tr("View License"), this);
+ mainLayout->addWidget(licenseButton);
+ connect(licenseButton, SIGNAL(clicked()), this, SLOT(handleLicenseClicked()));
#else
- // Some Linux desktops have dialog window decorations without close window buttons.
- // This code adds a dedicated button to close the about window dialog.
- QHBoxLayout* buttonLayout = new QHBoxLayout();
- mainLayout->addLayout(buttonLayout);
+ // Some Linux desktops have dialog window decorations without close window buttons.
+ // This code adds a dedicated button to close the about window dialog.
+ QHBoxLayout* buttonLayout = new QHBoxLayout();
+ mainLayout->addLayout(buttonLayout);
- QPushButton* licenseButton = new QPushButton(tr("View License"), this);
- buttonLayout->addWidget(licenseButton);
- connect(licenseButton, SIGNAL(clicked()), this, SLOT(handleLicenseClicked()));
+ QPushButton* licenseButton = new QPushButton(tr("View License"), this);
+ buttonLayout->addWidget(licenseButton);
+ connect(licenseButton, SIGNAL(clicked()), this, SLOT(handleLicenseClicked()));
- buttonLayout->addItem(new QSpacerItem(20,20));
+ buttonLayout->addItem(new QSpacerItem(20,20));
- QPushButton* closeButton = new QPushButton(tr("Close"), this);
- buttonLayout->addWidget(closeButton);
- connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
+ QPushButton* closeButton = new QPushButton(tr("Close"), this);
+ buttonLayout->addWidget(closeButton);
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
#endif
- setFixedSize(minimumSizeHint());
+ setFixedSize(minimumSizeHint());
}
void QtAboutWidget::handleLicenseClicked() {
- QTextEdit* text = new QTextEdit();
- text->setAttribute(Qt::WA_DeleteOnClose);
- text->setReadOnly(true);
- QFile file(":/COPYING");
- file.open(QIODevice::ReadOnly);
- QTextStream in(&file);
- in.setCodec("UTF-8");
- text->setPlainText(in.readAll());
- file.close();
- text->resize(500, 600);
- text->show();
- text->activateWindow();
+ QTextEdit* text = new QTextEdit();
+ text->setAttribute(Qt::WA_DeleteOnClose);
+ text->setReadOnly(true);
+ QFile file(":/COPYING");
+ file.open(QIODevice::ReadOnly);
+ QTextStream in(&file);
+ in.setCodec("UTF-8");
+ text->setPlainText(in.readAll());
+ file.close();
+ text->resize(500, 600);
+ text->show();
+ text->activateWindow();
}
}
diff --git a/Swift/QtUI/QtAboutWidget.h b/Swift/QtUI/QtAboutWidget.h
index d09010b..7d0d628 100644
--- a/Swift/QtUI/QtAboutWidget.h
+++ b/Swift/QtUI/QtAboutWidget.h
@@ -9,13 +9,13 @@
#include <QDialog>
namespace Swift {
- class QtAboutWidget : public QDialog {
- Q_OBJECT
+ class QtAboutWidget : public QDialog {
+ Q_OBJECT
- public:
- QtAboutWidget();
+ public:
+ QtAboutWidget();
- private slots:
- void handleLicenseClicked();
- };
+ private slots:
+ void handleLicenseClicked();
+ };
}
diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp
index ef397f4..87b1585 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.cpp
+++ b/Swift/QtUI/QtAdHocCommandWindow.cpp
@@ -20,155 +20,155 @@ const int FormLayoutIndex = 1;
namespace Swift {
QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) : command_(command) {
- formWidget_ = NULL;
-
- setAttribute(Qt::WA_DeleteOnClose);
- command->onNextStageReceived.connect(boost::bind(&QtAdHocCommandWindow::handleNextStageReceived, this, _1));
- command->onError.connect(boost::bind(&QtAdHocCommandWindow::handleError, this, _1));
- command->start();
-
- layout_ = new QBoxLayout(QBoxLayout::TopToBottom, this);
- layout_->setContentsMargins(0,0,0,0);
- layout_->setSpacing(2);
- label_ = new QLabel(this);
- label_->setTextFormat(Qt::PlainText);
- layout_->addWidget(label_);
-
- errorLabel_ = new QLabel(this);
- errorLabel_->setText(QString("<b>%1</b>").arg(tr("Unable to complete the command because you have been disconnected")));
- errorLabel_->setVisible(false);
- errorLabel_->setFrameStyle(QFrame::Box|QFrame::Sunken);
- layout_->addWidget(errorLabel_);
-
- dialogButtons_ = new QDialogButtonBox(this);
- layout_->addWidget(dialogButtons_);
-
- dialogButtons_->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
- okButton_ = dialogButtons_->button(QDialogButtonBox::Ok);
- connect(okButton_, SIGNAL(clicked()), this, SLOT(close()));
- cancelButton_ = dialogButtons_->button(QDialogButtonBox::Cancel);
- connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked()));
- // Buttons appear next to the Ok button, right of Cancel with YesRole
- completeButton_ = dialogButtons_->addButton(tr("Complete"), QDialogButtonBox::YesRole);
- connect(completeButton_, SIGNAL(clicked()), this, SLOT(handleCompleteClicked()));
- nextButton_ = dialogButtons_->addButton(tr("Next"), QDialogButtonBox::YesRole);
- connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked()));
- backButton_ = dialogButtons_->addButton(tr("Back"), QDialogButtonBox::YesRole);
- connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked()));
-
- okButton_->setEnabled(false);
- okButton_->hide();
-
- nextButton_->setEnabled(false);
- backButton_->setEnabled(false);
- completeButton_->setEnabled(false);
-
- actions_[Command::Next] = nextButton_;
- actions_[Command::Prev] = backButton_;
- actions_[Command::Complete] = completeButton_;
- actions_[Command::Cancel] = cancelButton_;
+ formWidget_ = NULL;
+
+ setAttribute(Qt::WA_DeleteOnClose);
+ command->onNextStageReceived.connect(boost::bind(&QtAdHocCommandWindow::handleNextStageReceived, this, _1));
+ command->onError.connect(boost::bind(&QtAdHocCommandWindow::handleError, this, _1));
+ command->start();
+
+ layout_ = new QBoxLayout(QBoxLayout::TopToBottom, this);
+ layout_->setContentsMargins(0,0,0,0);
+ layout_->setSpacing(2);
+ label_ = new QLabel(this);
+ label_->setTextFormat(Qt::PlainText);
+ layout_->addWidget(label_);
+
+ errorLabel_ = new QLabel(this);
+ errorLabel_->setText(QString("<b>%1</b>").arg(tr("Unable to complete the command because you have been disconnected")));
+ errorLabel_->setVisible(false);
+ errorLabel_->setFrameStyle(QFrame::Box|QFrame::Sunken);
+ layout_->addWidget(errorLabel_);
+
+ dialogButtons_ = new QDialogButtonBox(this);
+ layout_->addWidget(dialogButtons_);
+
+ dialogButtons_->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
+ okButton_ = dialogButtons_->button(QDialogButtonBox::Ok);
+ connect(okButton_, SIGNAL(clicked()), this, SLOT(close()));
+ cancelButton_ = dialogButtons_->button(QDialogButtonBox::Cancel);
+ connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked()));
+ // Buttons appear next to the Ok button, right of Cancel with YesRole
+ completeButton_ = dialogButtons_->addButton(tr("Complete"), QDialogButtonBox::YesRole);
+ connect(completeButton_, SIGNAL(clicked()), this, SLOT(handleCompleteClicked()));
+ nextButton_ = dialogButtons_->addButton(tr("Next"), QDialogButtonBox::YesRole);
+ connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked()));
+ backButton_ = dialogButtons_->addButton(tr("Back"), QDialogButtonBox::YesRole);
+ connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked()));
+
+ okButton_->setEnabled(false);
+ okButton_->hide();
+
+ nextButton_->setEnabled(false);
+ backButton_->setEnabled(false);
+ completeButton_->setEnabled(false);
+
+ actions_[Command::Next] = nextButton_;
+ actions_[Command::Prev] = backButton_;
+ actions_[Command::Complete] = completeButton_;
+ actions_[Command::Cancel] = cancelButton_;
}
QtAdHocCommandWindow::~QtAdHocCommandWindow() {
}
void QtAdHocCommandWindow::setOnline(bool online) {
- if (!online) {
- nextButton_->setEnabled(false);
- backButton_->setEnabled(false);
- completeButton_->setEnabled(false);
- errorLabel_->setVisible(true);
- }
+ if (!online) {
+ nextButton_->setEnabled(false);
+ backButton_->setEnabled(false);
+ completeButton_->setEnabled(false);
+ errorLabel_->setVisible(true);
+ }
}
void QtAdHocCommandWindow::closeEvent(QCloseEvent*) {
- onClosing();
+ onClosing();
}
void QtAdHocCommandWindow::handleCancelClicked() {
- command_->cancel();
- close();
+ command_->cancel();
+ close();
}
void QtAdHocCommandWindow::handlePrevClicked() {
- command_->goBack();
+ command_->goBack();
}
void QtAdHocCommandWindow::handleNextClicked() {
- command_->goNext(formWidget_ ? formWidget_->getCompletedForm() : Form::ref());
+ command_->goNext(formWidget_ ? formWidget_->getCompletedForm() : Form::ref());
}
void QtAdHocCommandWindow::handleCompleteClicked() {
- command_->complete(formWidget_ ? formWidget_->getCompletedForm() : Form::ref());
+ command_->complete(formWidget_ ? formWidget_->getCompletedForm() : Form::ref());
}
void QtAdHocCommandWindow::handleNextStageReceived(Command::ref command) {
- QString notes;
- foreach (Command::Note note, command->getNotes()) {
- if (!notes.isEmpty()) {
- notes += "\n";
- }
- QString qNote(P2QSTRING(note.note));
- switch (note.type) {
- case Command::Note::Error: notes += tr("Error: %1").arg(qNote); break;
- case Command::Note::Warn: notes += tr("Warning: %1").arg(qNote); break;
- case Command::Note::Info: notes += qNote; break;
- }
- }
- label_->setText(notes);
- if (command->getForm()) {
- setForm(command->getForm());
- } else {
- setNoForm(notes.isEmpty());
- }
- setAvailableActions(command);
+ QString notes;
+ foreach (Command::Note note, command->getNotes()) {
+ if (!notes.isEmpty()) {
+ notes += "\n";
+ }
+ QString qNote(P2QSTRING(note.note));
+ switch (note.type) {
+ case Command::Note::Error: notes += tr("Error: %1").arg(qNote); break;
+ case Command::Note::Warn: notes += tr("Warning: %1").arg(qNote); break;
+ case Command::Note::Info: notes += qNote; break;
+ }
+ }
+ label_->setText(notes);
+ if (command->getForm()) {
+ setForm(command->getForm());
+ } else {
+ setNoForm(notes.isEmpty());
+ }
+ setAvailableActions(command);
}
void QtAdHocCommandWindow::handleError(ErrorPayload::ref /*error*/) {
- nextButton_->setEnabled(false);
- backButton_->setEnabled(false);
- completeButton_->setEnabled(false);
- label_->setText(tr("Error executing command"));
+ nextButton_->setEnabled(false);
+ backButton_->setEnabled(false);
+ completeButton_->setEnabled(false);
+ label_->setText(tr("Error executing command"));
}
void QtAdHocCommandWindow::setForm(Form::ref form) {
- form_ = form;
- delete formWidget_;
- formWidget_ = new QtFormWidget(form, this);
- layout_->insertWidget(FormLayoutIndex, formWidget_);
- show();
+ form_ = form;
+ delete formWidget_;
+ formWidget_ = new QtFormWidget(form, this);
+ layout_->insertWidget(FormLayoutIndex, formWidget_);
+ show();
}
void QtAdHocCommandWindow::setNoForm(bool andHide) {
- form_.reset();
- delete formWidget_;
- formWidget_ = NULL;
- resize(minimumSize());
- setVisible(!andHide);
+ form_.reset();
+ delete formWidget_;
+ formWidget_ = NULL;
+ resize(minimumSize());
+ setVisible(!andHide);
}
typedef std::pair<Command::Action, QPushButton*> ActionButton;
void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
- okButton_->show();
- okButton_->setEnabled(true);
- foreach (ActionButton pair, actions_) {
- OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first);
- if (state & OutgoingAdHocCommandSession::Present) {
- okButton_->hide();
- okButton_->setEnabled(false);
- pair.second->show();
- }
- else {
- pair.second->hide();
- }
- if (state & OutgoingAdHocCommandSession::Enabled) {
- pair.second->setEnabled(true);
- }
- else {
- pair.second->setEnabled(false);
- }
- }
+ okButton_->show();
+ okButton_->setEnabled(true);
+ foreach (ActionButton pair, actions_) {
+ OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first);
+ if (state & OutgoingAdHocCommandSession::Present) {
+ okButton_->hide();
+ okButton_->setEnabled(false);
+ pair.second->show();
+ }
+ else {
+ pair.second->hide();
+ }
+ if (state & OutgoingAdHocCommandSession::Enabled) {
+ pair.second->setEnabled(true);
+ }
+ else {
+ pair.second->setEnabled(false);
+ }
+ }
}
}
diff --git a/Swift/QtUI/QtAdHocCommandWindow.h b/Swift/QtUI/QtAdHocCommandWindow.h
index c8d493c..61cd5be 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.h
+++ b/Swift/QtUI/QtAdHocCommandWindow.h
@@ -18,41 +18,41 @@
class QBoxLayout;
namespace Swift {
- class QtFormWidget;
- class QtAdHocCommandWindow : public QWidget, public AdHocCommandWindow {
- Q_OBJECT
- public:
- QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command);
- virtual ~QtAdHocCommandWindow();
- virtual void setOnline(bool online);
-
- private:
- void closeEvent(QCloseEvent* event);
- void handleNextStageReceived(Command::ref command);
- void handleError(ErrorPayload::ref error);
- void setForm(Form::ref);
- void setNoForm(bool andHide);
- void setAvailableActions(Command::ref commandResult);
-
- private slots:
- void handleCancelClicked();
- void handlePrevClicked();
- void handleNextClicked();
- void handleCompleteClicked();
-
- private:
- boost::shared_ptr<OutgoingAdHocCommandSession> command_;
- QtFormWidget* formWidget_;
- Form::ref form_;
- QLabel* label_;
- QLabel* errorLabel_;
- QPushButton* backButton_;
- QPushButton* nextButton_;
- QPushButton* completeButton_;
- QPushButton* cancelButton_;
- QPushButton* okButton_;
- std::map<Command::Action, QPushButton*> actions_;
- QDialogButtonBox* dialogButtons_;
- QBoxLayout* layout_;
- };
+ class QtFormWidget;
+ class QtAdHocCommandWindow : public QWidget, public AdHocCommandWindow {
+ Q_OBJECT
+ public:
+ QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command);
+ virtual ~QtAdHocCommandWindow();
+ virtual void setOnline(bool online);
+
+ private:
+ void closeEvent(QCloseEvent* event);
+ void handleNextStageReceived(Command::ref command);
+ void handleError(ErrorPayload::ref error);
+ void setForm(Form::ref);
+ void setNoForm(bool andHide);
+ void setAvailableActions(Command::ref commandResult);
+
+ private slots:
+ void handleCancelClicked();
+ void handlePrevClicked();
+ void handleNextClicked();
+ void handleCompleteClicked();
+
+ private:
+ boost::shared_ptr<OutgoingAdHocCommandSession> command_;
+ QtFormWidget* formWidget_;
+ Form::ref form_;
+ QLabel* label_;
+ QLabel* errorLabel_;
+ QPushButton* backButton_;
+ QPushButton* nextButton_;
+ QPushButton* completeButton_;
+ QPushButton* cancelButton_;
+ QPushButton* okButton_;
+ std::map<Command::Action, QPushButton*> actions_;
+ QDialogButtonBox* dialogButtons_;
+ QBoxLayout* layout_;
+ };
}
diff --git a/Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp b/Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp
index ac2a603..69e1d68 100644
--- a/Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp
+++ b/Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp
@@ -23,42 +23,42 @@
namespace Swift {
QtAdHocCommandWithJIDWindow::QtAdHocCommandWithJIDWindow(UIEventStream* uiEventStream) : uiEventStream_(uiEventStream) {
- QVBoxLayout* hlayout = new QVBoxLayout(this);
+ QVBoxLayout* hlayout = new QVBoxLayout(this);
- QLabel* jidLabel = new QLabel("JID:", this);
- hlayout->addWidget(jidLabel);
- jid_ = new QLineEdit(this);
- hlayout->addWidget(jid_);
+ QLabel* jidLabel = new QLabel("JID:", this);
+ hlayout->addWidget(jidLabel);
+ jid_ = new QLineEdit(this);
+ hlayout->addWidget(jid_);
- QLabel* commandLabel = new QLabel("Command:", this);
- hlayout->addWidget(commandLabel);
- node_ = new QLineEdit(this);
- hlayout->addWidget(node_);
+ QLabel* commandLabel = new QLabel("Command:", this);
+ hlayout->addWidget(commandLabel);
+ node_ = new QLineEdit(this);
+ hlayout->addWidget(node_);
- QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
- QPushButton* rejectButton = buttonBox->addButton("Cancel", QDialogButtonBox::RejectRole);
- connect(rejectButton, SIGNAL(clicked()), this, SLOT(handleRejectClick()));
- QPushButton* acceptButton = buttonBox->addButton("Complete", QDialogButtonBox::AcceptRole);
- connect(acceptButton, SIGNAL(clicked()), this, SLOT(handleAcceptClick()));
- hlayout->addWidget(buttonBox);
+ QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
+ QPushButton* rejectButton = buttonBox->addButton("Cancel", QDialogButtonBox::RejectRole);
+ connect(rejectButton, SIGNAL(clicked()), this, SLOT(handleRejectClick()));
+ QPushButton* acceptButton = buttonBox->addButton("Complete", QDialogButtonBox::AcceptRole);
+ connect(acceptButton, SIGNAL(clicked()), this, SLOT(handleAcceptClick()));
+ hlayout->addWidget(buttonBox);
- setLayout(hlayout);
- show();
+ setLayout(hlayout);
+ show();
}
QtAdHocCommandWithJIDWindow::~QtAdHocCommandWithJIDWindow() {
}
void QtAdHocCommandWithJIDWindow::handleAcceptClick() {
- const JID jid = JID(Q2PSTRING(jid_->text()));
- const std::string node = Q2PSTRING(node_->text());
- boost::shared_ptr<UIEvent> event(new RequestAdHocWithJIDUIEvent(jid, node));
- uiEventStream_->send(event);
- accept();
+ const JID jid = JID(Q2PSTRING(jid_->text()));
+ const std::string node = Q2PSTRING(node_->text());
+ boost::shared_ptr<UIEvent> event(new RequestAdHocWithJIDUIEvent(jid, node));
+ uiEventStream_->send(event);
+ accept();
}
void QtAdHocCommandWithJIDWindow::handleRejectClick() {
- reject();
+ reject();
}
}
diff --git a/Swift/QtUI/QtAdHocCommandWithJIDWindow.h b/Swift/QtUI/QtAdHocCommandWithJIDWindow.h
index e1f7a9c..0e83555 100644
--- a/Swift/QtUI/QtAdHocCommandWithJIDWindow.h
+++ b/Swift/QtUI/QtAdHocCommandWithJIDWindow.h
@@ -14,19 +14,19 @@
class QBoxLayout;
namespace Swift {
- class UIEventStream;
- class QtFormWidget;
- class QtAdHocCommandWithJIDWindow : public QDialog {
- Q_OBJECT
- public:
- QtAdHocCommandWithJIDWindow(UIEventStream* eventStream);
- virtual ~QtAdHocCommandWithJIDWindow();
- public slots:
- void handleAcceptClick();
- void handleRejectClick();
- private:
- UIEventStream* uiEventStream_;
- QLineEdit* jid_;
- QLineEdit* node_;
- };
+ class UIEventStream;
+ class QtFormWidget;
+ class QtAdHocCommandWithJIDWindow : public QDialog {
+ Q_OBJECT
+ public:
+ QtAdHocCommandWithJIDWindow(UIEventStream* eventStream);
+ virtual ~QtAdHocCommandWithJIDWindow();
+ public slots:
+ void handleAcceptClick();
+ void handleRejectClick();
+ private:
+ UIEventStream* uiEventStream_;
+ QLineEdit* jid_;
+ QLineEdit* node_;
+ };
}
diff --git a/Swift/QtUI/QtAddBookmarkWindow.cpp b/Swift/QtUI/QtAddBookmarkWindow.cpp
index 087628d..500b298 100644
--- a/Swift/QtUI/QtAddBookmarkWindow.cpp
+++ b/Swift/QtUI/QtAddBookmarkWindow.cpp
@@ -8,23 +8,23 @@
namespace Swift {
QtAddBookmarkWindow::QtAddBookmarkWindow(UIEventStream* eventStream) : eventStream_(eventStream) {
- setWindowTitle(tr("Add Bookmark Details"));
+ setWindowTitle(tr("Add Bookmark Details"));
}
QtAddBookmarkWindow::QtAddBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark) : eventStream_(eventStream) {
- createFormFromBookmark(bookmark);
- setWindowTitle(tr("Add Bookmark Details"));
+ createFormFromBookmark(bookmark);
+ setWindowTitle(tr("Add Bookmark Details"));
}
bool QtAddBookmarkWindow::commit() {
- boost::optional<MUCBookmark> bookmark = createBookmarkFromForm();
- if (bookmark) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(*bookmark)));
- return true;
- }
- else {
- return false;
- }
+ boost::optional<MUCBookmark> bookmark = createBookmarkFromForm();
+ if (bookmark) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(*bookmark)));
+ return true;
+ }
+ else {
+ return false;
+ }
}
}
diff --git a/Swift/QtUI/QtAddBookmarkWindow.h b/Swift/QtUI/QtAddBookmarkWindow.h
index 7b08b8e..607f647 100644
--- a/Swift/QtUI/QtAddBookmarkWindow.h
+++ b/Swift/QtUI/QtAddBookmarkWindow.h
@@ -12,13 +12,13 @@
#include <Swift/QtUI/QtBookmarkDetailWindow.h>
namespace Swift {
- class QtAddBookmarkWindow : public QtBookmarkDetailWindow {
- Q_OBJECT
- public:
- QtAddBookmarkWindow(UIEventStream* eventStream);
- QtAddBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark);
- bool commit();
- private:
- UIEventStream* eventStream_;
- };
+ class QtAddBookmarkWindow : public QtBookmarkDetailWindow {
+ Q_OBJECT
+ public:
+ QtAddBookmarkWindow(UIEventStream* eventStream);
+ QtAddBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark);
+ bool commit();
+ private:
+ UIEventStream* eventStream_;
+ };
}
diff --git a/Swift/QtUI/QtAffiliationEditor.cpp b/Swift/QtUI/QtAffiliationEditor.cpp
index d732c4e..980b26a 100644
--- a/Swift/QtUI/QtAffiliationEditor.cpp
+++ b/Swift/QtUI/QtAffiliationEditor.cpp
@@ -13,66 +13,66 @@
namespace Swift {
QtAffiliationEditor::QtAffiliationEditor(QWidget* parent) : QDialog(parent){
- ui_.setupUi(this);
- setAttribute(Qt::WA_DeleteOnClose);
- connect(ui_.affiliation, SIGNAL(currentIndexChanged(int)), this, SLOT(handleCurrentIndexChanged(int)));
- connect(ui_.addJID, SIGNAL(clicked()), this, SLOT(handleAddClicked()));
- connect(ui_.removeJID, SIGNAL(clicked()), this, SLOT(handleRemoveClicked()));
+ ui_.setupUi(this);
+ setAttribute(Qt::WA_DeleteOnClose);
+ connect(ui_.affiliation, SIGNAL(currentIndexChanged(int)), this, SLOT(handleCurrentIndexChanged(int)));
+ connect(ui_.addJID, SIGNAL(clicked()), this, SLOT(handleAddClicked()));
+ connect(ui_.removeJID, SIGNAL(clicked()), this, SLOT(handleRemoveClicked()));
}
QtAffiliationEditor::~QtAffiliationEditor() {
-
+
}
void QtAffiliationEditor::setAffiliations(MUCOccupant::Affiliation affiliation, const std::vector<JID>& jids) {
- affiliations_[affiliation] = jids;
- if (affiliationFromIndex(ui_.affiliation->currentIndex()) == affiliation) {
- handleCurrentIndexChanged(ui_.affiliation->currentIndex());
- }
+ affiliations_[affiliation] = jids;
+ if (affiliationFromIndex(ui_.affiliation->currentIndex()) == affiliation) {
+ handleCurrentIndexChanged(ui_.affiliation->currentIndex());
+ }
}
const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& QtAffiliationEditor::getChanges() const {
- return changes_;
+ return changes_;
}
void QtAffiliationEditor::handleCurrentIndexChanged(int index) {
- ui_.list->clear();
- foreach (const JID& jid, affiliations_[affiliationFromIndex(index)]) {
- ui_.list->addItem(P2QSTRING(jid.toString()));
- }
+ ui_.list->clear();
+ foreach (const JID& jid, affiliations_[affiliationFromIndex(index)]) {
+ ui_.list->addItem(P2QSTRING(jid.toString()));
+ }
}
void QtAffiliationEditor::handleAddClicked() {
- bool ok = false;
- JID jid = JID(Q2PSTRING(QInputDialog::getText(this, tr("Add User"), tr("Added User's Address:"), QLineEdit::Normal, "", &ok)));
- if (ok && jid.isValid()) {
- //FIXME: validation
- MUCOccupant::Affiliation affiliation = affiliationFromIndex(ui_.affiliation->currentIndex());
- changes_.push_back(ChangePair(affiliation, jid));
- ui_.list->addItem(P2QSTRING(jid.toString()));
- affiliations_[affiliation].push_back(jid);
- }
+ bool ok = false;
+ JID jid = JID(Q2PSTRING(QInputDialog::getText(this, tr("Add User"), tr("Added User's Address:"), QLineEdit::Normal, "", &ok)));
+ if (ok && jid.isValid()) {
+ //FIXME: validation
+ MUCOccupant::Affiliation affiliation = affiliationFromIndex(ui_.affiliation->currentIndex());
+ changes_.push_back(ChangePair(affiliation, jid));
+ ui_.list->addItem(P2QSTRING(jid.toString()));
+ affiliations_[affiliation].push_back(jid);
+ }
}
void QtAffiliationEditor::handleRemoveClicked() {
- QListWidgetItem* item = ui_.list->currentItem();
- if (item) {
- JID jid(Q2PSTRING(item->text()));
- changes_.push_back(ChangePair(MUCOccupant::NoAffiliation, jid));
- std::vector<JID>& jids = affiliations_[affiliationFromIndex(ui_.affiliation->currentIndex())];
- jids.erase(std::remove(jids.begin(), jids.end(), jid), jids.end());
- handleCurrentIndexChanged(ui_.affiliation->currentIndex());
- }
+ QListWidgetItem* item = ui_.list->currentItem();
+ if (item) {
+ JID jid(Q2PSTRING(item->text()));
+ changes_.push_back(ChangePair(MUCOccupant::NoAffiliation, jid));
+ std::vector<JID>& jids = affiliations_[affiliationFromIndex(ui_.affiliation->currentIndex())];
+ jids.erase(std::remove(jids.begin(), jids.end(), jid), jids.end());
+ handleCurrentIndexChanged(ui_.affiliation->currentIndex());
+ }
}
MUCOccupant::Affiliation QtAffiliationEditor::affiliationFromIndex(int affiliation) {
- switch (affiliation) {
- case 0: return MUCOccupant::Owner;
- case 1: return MUCOccupant::Admin;
- case 2: return MUCOccupant::Member;
- case 3: return MUCOccupant::Outcast;
- default: return MUCOccupant::Outcast;
- }
+ switch (affiliation) {
+ case 0: return MUCOccupant::Owner;
+ case 1: return MUCOccupant::Admin;
+ case 2: return MUCOccupant::Member;
+ case 3: return MUCOccupant::Outcast;
+ default: return MUCOccupant::Outcast;
+ }
}
}
diff --git a/Swift/QtUI/QtAffiliationEditor.h b/Swift/QtUI/QtAffiliationEditor.h
index d706926..3b7e548 100644
--- a/Swift/QtUI/QtAffiliationEditor.h
+++ b/Swift/QtUI/QtAffiliationEditor.h
@@ -17,22 +17,22 @@
#include <Swift/QtUI/ui_QtAffiliationEditor.h>
namespace Swift {
- class QtAffiliationEditor : public QDialog {
- Q_OBJECT
- public:
- QtAffiliationEditor(QWidget* parent = NULL);
- ~QtAffiliationEditor();
- void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>& jids);
- const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& getChanges() const;
- private slots:
- void handleCurrentIndexChanged(int);
- void handleAddClicked();
- void handleRemoveClicked();
- private:
- typedef std::pair<MUCOccupant::Affiliation, JID> ChangePair;
- MUCOccupant::Affiliation affiliationFromIndex(int affiliation);
- Ui::QtAffiliationEditor ui_;
- std::map<MUCOccupant::Affiliation, std::vector<JID> > affiliations_;
- std::vector<ChangePair> changes_;
- };
+ class QtAffiliationEditor : public QDialog {
+ Q_OBJECT
+ public:
+ QtAffiliationEditor(QWidget* parent = NULL);
+ ~QtAffiliationEditor();
+ void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>& jids);
+ const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& getChanges() const;
+ private slots:
+ void handleCurrentIndexChanged(int);
+ void handleAddClicked();
+ void handleRemoveClicked();
+ private:
+ typedef std::pair<MUCOccupant::Affiliation, JID> ChangePair;
+ MUCOccupant::Affiliation affiliationFromIndex(int affiliation);
+ Ui::QtAffiliationEditor ui_;
+ std::map<MUCOccupant::Affiliation, std::vector<JID> > affiliations_;
+ std::vector<ChangePair> changes_;
+ };
}
diff --git a/Swift/QtUI/QtAvatarWidget.cpp b/Swift/QtUI/QtAvatarWidget.cpp
index 2474e80..7f6e275 100644
--- a/Swift/QtUI/QtAvatarWidget.cpp
+++ b/Swift/QtUI/QtAvatarWidget.cpp
@@ -27,85 +27,85 @@
namespace Swift {
QtAvatarWidget::QtAvatarWidget(QWidget* parent) : QWidget(parent), editable(false) {
- QVBoxLayout* layout = new QVBoxLayout(this);
- layout->setContentsMargins(0,0,0,0);
-
- QSizePolicy sp(QSizePolicy::Fixed, QSizePolicy::Fixed);
- sp.setHorizontalStretch(0);
- sp.setVerticalStretch(0);
- setSizePolicy(sp);
- setMinimumSize(QSize(96, 96));
- setMaximumSize(QSize(96, 96));
-
- label = new QLabel(this);
- label->setWordWrap(true);
- label->setSizePolicy(sp);
- label->setMinimumSize(QSize(96, 96));
- label->setMaximumSize(QSize(96, 96));
- label->setAlignment(Qt::AlignCenter);
- layout->addWidget(label);
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->setContentsMargins(0,0,0,0);
+
+ QSizePolicy sp(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ sp.setHorizontalStretch(0);
+ sp.setVerticalStretch(0);
+ setSizePolicy(sp);
+ setMinimumSize(QSize(96, 96));
+ setMaximumSize(QSize(96, 96));
+
+ label = new QLabel(this);
+ label->setWordWrap(true);
+ label->setSizePolicy(sp);
+ label->setMinimumSize(QSize(96, 96));
+ label->setMaximumSize(QSize(96, 96));
+ label->setAlignment(Qt::AlignCenter);
+ layout->addWidget(label);
}
void QtAvatarWidget::setAvatar(const ByteArray& data, const std::string& type) {
- this->data = data;
- this->type = type;
-
- QImage image;
- if (!data.empty()) {
- image.loadFromData(reinterpret_cast<const uchar*>(vecptr(data)), data.size());
- }
-
- if (image.isNull()) {
- image = QImage(":/icons/no-avatar.png");
- QPainter painter(&image);
- painter.setPen(Qt::gray);
- QFont font = painter.font();
- font.setPointSize(14);
- painter.setFont(font);
- painter.drawText(0, 0, image.height(), image.width(), Qt::AlignHCenter | Qt::AlignVCenter, tr("No picture"));
- }
-
- if (image.height() > label->height() || image.width() > label->width()) {
- image = image.scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
- }
- label->setPixmap(QPixmap::fromImage(image));
+ this->data = data;
+ this->type = type;
+
+ QImage image;
+ if (!data.empty()) {
+ image.loadFromData(reinterpret_cast<const uchar*>(vecptr(data)), data.size());
+ }
+
+ if (image.isNull()) {
+ image = QImage(":/icons/no-avatar.png");
+ QPainter painter(&image);
+ painter.setPen(Qt::gray);
+ QFont font = painter.font();
+ font.setPointSize(14);
+ painter.setFont(font);
+ painter.drawText(0, 0, image.height(), image.width(), Qt::AlignHCenter | Qt::AlignVCenter, tr("No picture"));
+ }
+
+ if (image.height() > label->height() || image.width() > label->width()) {
+ image = image.scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ }
+ label->setPixmap(QPixmap::fromImage(image));
}
void QtAvatarWidget::mousePressEvent(QMouseEvent* event) {
- if (!editable) {
- return;
- }
- QMenu menu;
-
- QAction* selectPicture = new QAction(tr("Select picture ..."), this);
- menu.addAction(selectPicture);
-
- QAction* clearPicture = new QAction(tr("Clear picture"), this);
- menu.addAction(clearPicture);
-
- QAction* result = menu.exec(event->globalPos());
- if (result == selectPicture) {
- QString fileName = QFileDialog::getOpenFileName(this, tr("Select picture"), "", tr("Image Files (*.png *.jpg *.jpeg *.gif)"));
- if (!fileName.isEmpty()) {
- ByteArray data;
- readByteArrayFromFile(data, stringToPath(Q2PSTRING(fileName)));
-
- QBuffer buffer;
- buffer.setData(reinterpret_cast<const char*>(vecptr(data)), data.size());
- buffer.open(QIODevice::ReadOnly);
- QString type = QImageReader::imageFormat(&buffer).toLower();
- if (!type.isEmpty()) {
- type = "image/" + type;
- setAvatar(data, Q2PSTRING(type));
- }
- else {
- QMessageBox::critical(this, tr("Error"), tr("The selected picture is in an unrecognized format"));
- }
- }
- }
- else if (result == clearPicture) {
- setAvatar(ByteArray(), "");
- }
+ if (!editable) {
+ return;
+ }
+ QMenu menu;
+
+ QAction* selectPicture = new QAction(tr("Select picture ..."), this);
+ menu.addAction(selectPicture);
+
+ QAction* clearPicture = new QAction(tr("Clear picture"), this);
+ menu.addAction(clearPicture);
+
+ QAction* result = menu.exec(event->globalPos());
+ if (result == selectPicture) {
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Select picture"), "", tr("Image Files (*.png *.jpg *.jpeg *.gif)"));
+ if (!fileName.isEmpty()) {
+ ByteArray data;
+ readByteArrayFromFile(data, stringToPath(Q2PSTRING(fileName)));
+
+ QBuffer buffer;
+ buffer.setData(reinterpret_cast<const char*>(vecptr(data)), data.size());
+ buffer.open(QIODevice::ReadOnly);
+ QString type = QImageReader::imageFormat(&buffer).toLower();
+ if (!type.isEmpty()) {
+ type = "image/" + type;
+ setAvatar(data, Q2PSTRING(type));
+ }
+ else {
+ QMessageBox::critical(this, tr("Error"), tr("The selected picture is in an unrecognized format"));
+ }
+ }
+ }
+ else if (result == clearPicture) {
+ setAvatar(ByteArray(), "");
+ }
}
diff --git a/Swift/QtUI/QtAvatarWidget.h b/Swift/QtUI/QtAvatarWidget.h
index bcdc7be..612c79b 100644
--- a/Swift/QtUI/QtAvatarWidget.h
+++ b/Swift/QtUI/QtAvatarWidget.h
@@ -14,36 +14,36 @@
class QLabel;
namespace Swift {
- class QtAvatarWidget : public QWidget {
- Q_OBJECT
- Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
- public:
- QtAvatarWidget(QWidget* parent);
-
- void setAvatar(const ByteArray& data, const std::string& type);
-
- const ByteArray& getAvatarData() const {
- return data;
- }
-
- const std::string& getAvatarType() const {
- return type;
- }
-
- void setEditable(bool b) {
- editable = b;
- }
-
- bool isEditable() const {
- return editable;
- }
-
- void mousePressEvent(QMouseEvent* event);
-
- private:
- bool editable;
- ByteArray data;
- std::string type;
- QLabel* label;
- };
+ class QtAvatarWidget : public QWidget {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+ public:
+ QtAvatarWidget(QWidget* parent);
+
+ void setAvatar(const ByteArray& data, const std::string& type);
+
+ const ByteArray& getAvatarData() const {
+ return data;
+ }
+
+ const std::string& getAvatarType() const {
+ return type;
+ }
+
+ void setEditable(bool b) {
+ editable = b;
+ }
+
+ bool isEditable() const {
+ return editable;
+ }
+
+ void mousePressEvent(QMouseEvent* event);
+
+ private:
+ bool editable;
+ ByteArray data;
+ std::string type;
+ QLabel* label;
+ };
}
diff --git a/Swift/QtUI/QtBlockListEditorWindow.cpp b/Swift/QtUI/QtBlockListEditorWindow.cpp
index 98c9e98..5b04b49 100644
--- a/Swift/QtUI/QtBlockListEditorWindow.cpp
+++ b/Swift/QtUI/QtBlockListEditorWindow.cpp
@@ -31,197 +31,197 @@
namespace Swift {
class QtJIDValidator : public QValidator {
- public:
- QtJIDValidator(QObject* parent) : QValidator(parent) {}
- virtual ~QtJIDValidator() {}
- virtual QValidator::State validate(QString& input, int&) const {
- return JID(Q2PSTRING(input)).isValid() ? Acceptable : Intermediate;
- }
+ public:
+ QtJIDValidator(QObject* parent) : QValidator(parent) {}
+ virtual ~QtJIDValidator() {}
+ virtual QValidator::State validate(QString& input, int&) const {
+ return JID(Q2PSTRING(input)).isValid() ? Acceptable : Intermediate;
+ }
};
class QtJIDValidatedItemDelegate : public QItemDelegate {
- public:
- QtJIDValidatedItemDelegate(QObject* parent) : QItemDelegate(parent) {}
- virtual ~QtJIDValidatedItemDelegate() {}
-
- virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const {
- QLineEdit *editor = new QLineEdit(parent);
- editor->setValidator(new QtJIDValidator(editor));
- return editor;
- }
-
- void setEditorData(QWidget *editor, const QModelIndex &index) const {
- QString value = index.model()->data(index, Qt::EditRole).toString();
-
- QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
- lineEdit->setText(value);
- }
-
- void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
- QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
- QString currentValue = lineEdit->text();
- int pos = 0;
- if (lineEdit->validator()->validate(currentValue, pos) == QValidator::Acceptable) {
- model->setData(index, lineEdit->text(), Qt::EditRole);
- } else {
- model->setData(index, QString(), Qt::EditRole);
- }
- }
-
- void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
- editor->setGeometry(option.rect);
- }
+ public:
+ QtJIDValidatedItemDelegate(QObject* parent) : QItemDelegate(parent) {}
+ virtual ~QtJIDValidatedItemDelegate() {}
+
+ virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const {
+ QLineEdit *editor = new QLineEdit(parent);
+ editor->setValidator(new QtJIDValidator(editor));
+ return editor;
+ }
+
+ void setEditorData(QWidget *editor, const QModelIndex &index) const {
+ QString value = index.model()->data(index, Qt::EditRole).toString();
+
+ QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
+ lineEdit->setText(value);
+ }
+
+ void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
+ QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
+ QString currentValue = lineEdit->text();
+ int pos = 0;
+ if (lineEdit->validator()->validate(currentValue, pos) == QValidator::Acceptable) {
+ model->setData(index, lineEdit->text(), Qt::EditRole);
+ } else {
+ model->setData(index, QString(), Qt::EditRole);
+ }
+ }
+
+ void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
+ editor->setGeometry(option.rect);
+ }
};
QtBlockListEditorWindow::QtBlockListEditorWindow() : QWidget(), ui(new Ui::QtBlockListEditorWindow), removeItemDelegate(0), editItemDelegate(0) {
- ui->setupUi(this);
+ ui->setupUi(this);
- freshBlockListTemplate = tr("Double-click to add contact");
+ freshBlockListTemplate = tr("Double-click to add contact");
- new QShortcut(QKeySequence::Close, this, SLOT(close()));
- ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
+ new QShortcut(QKeySequence::Close, this, SLOT(close()));
+ ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
- removeItemDelegate = new QtRemovableItemDelegate(style());
- editItemDelegate = new QtJIDValidatedItemDelegate(this);
+ removeItemDelegate = new QtRemovableItemDelegate(style());
+ editItemDelegate = new QtJIDValidatedItemDelegate(this);
- connect(ui->savePushButton, SIGNAL(clicked()), SLOT(applyChanges()));
+ connect(ui->savePushButton, SIGNAL(clicked()), SLOT(applyChanges()));
- ui->blockListTreeWidget->setColumnCount(2);
- ui->blockListTreeWidget->header()->setStretchLastSection(false);
- ui->blockListTreeWidget->header()->resizeSection(1, removeItemDelegate->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
+ ui->blockListTreeWidget->setColumnCount(2);
+ ui->blockListTreeWidget->header()->setStretchLastSection(false);
+ ui->blockListTreeWidget->header()->resizeSection(1, removeItemDelegate->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
#if QT_VERSION >= 0x050000
- ui->blockListTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
+ ui->blockListTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
#else
- ui->blockListTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
+ ui->blockListTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
#endif
- ui->blockListTreeWidget->setHeaderHidden(true);
- ui->blockListTreeWidget->setRootIsDecorated(false);
- ui->blockListTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed);
- ui->blockListTreeWidget->setItemDelegateForColumn(0, editItemDelegate);
- ui->blockListTreeWidget->setItemDelegateForColumn(1, removeItemDelegate);
- connect(ui->blockListTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(handleItemChanged(QTreeWidgetItem*,int)));
- ui->blockListTreeWidget->installEventFilter(this);
-
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- ui->blockListTreeWidget->addTopLevelItem(item);
+ ui->blockListTreeWidget->setHeaderHidden(true);
+ ui->blockListTreeWidget->setRootIsDecorated(false);
+ ui->blockListTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed);
+ ui->blockListTreeWidget->setItemDelegateForColumn(0, editItemDelegate);
+ ui->blockListTreeWidget->setItemDelegateForColumn(1, removeItemDelegate);
+ connect(ui->blockListTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(handleItemChanged(QTreeWidgetItem*,int)));
+ ui->blockListTreeWidget->installEventFilter(this);
+
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ ui->blockListTreeWidget->addTopLevelItem(item);
}
QtBlockListEditorWindow::~QtBlockListEditorWindow() {
}
void QtBlockListEditorWindow::show() {
- QWidget::showNormal();
- QWidget::activateWindow();
- QWidget::raise();
+ QWidget::showNormal();
+ QWidget::activateWindow();
+ QWidget::raise();
}
void QtBlockListEditorWindow::hide() {
- QWidget::hide();
+ QWidget::hide();
}
void QtBlockListEditorWindow::handleItemChanged(QTreeWidgetItem *item, int) {
- // check whether changed item contains a valid JID and make it removable
- if (item && item->text(0) != freshBlockListTemplate) {
- item->setText(1, "");
- }
-
- // check for empty rows and add an empty one so the user can add items
- bool hasEmptyRow = false;
- for( int i = 0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i ) {
- QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
- if (row->text(0) == freshBlockListTemplate) {
- hasEmptyRow = true;
- }
- else if (row->text(0).isEmpty()) {
- ui->blockListTreeWidget->removeItemWidget(row, 0);
- }
- }
-
- if (!hasEmptyRow) {
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- ui->blockListTreeWidget->addTopLevelItem(item);
- }
-
- if (!item) {
- ui->blockListTreeWidget->setCurrentItem(ui->blockListTreeWidget->topLevelItem(0));
- }
+ // check whether changed item contains a valid JID and make it removable
+ if (item && item->text(0) != freshBlockListTemplate) {
+ item->setText(1, "");
+ }
+
+ // check for empty rows and add an empty one so the user can add items
+ bool hasEmptyRow = false;
+ for( int i = 0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i ) {
+ QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
+ if (row->text(0) == freshBlockListTemplate) {
+ hasEmptyRow = true;
+ }
+ else if (row->text(0).isEmpty()) {
+ ui->blockListTreeWidget->removeItemWidget(row, 0);
+ }
+ }
+
+ if (!hasEmptyRow) {
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ ui->blockListTreeWidget->addTopLevelItem(item);
+ }
+
+ if (!item) {
+ ui->blockListTreeWidget->setCurrentItem(ui->blockListTreeWidget->topLevelItem(0));
+ }
}
void QtBlockListEditorWindow::applyChanges() {
- onSetNewBlockList(getCurrentBlockList());
+ onSetNewBlockList(getCurrentBlockList());
}
void QtBlockListEditorWindow::setCurrentBlockList(const std::vector<JID> &blockedJIDs) {
- ui->blockListTreeWidget->clear();
-
- foreach(const JID& jid, blockedJIDs) {
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(jid.toString())) << "");
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- ui->blockListTreeWidget->addTopLevelItem(item);
- }
- handleItemChanged(0,0);
+ ui->blockListTreeWidget->clear();
+
+ foreach(const JID& jid, blockedJIDs) {
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(jid.toString())) << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ ui->blockListTreeWidget->addTopLevelItem(item);
+ }
+ handleItemChanged(0,0);
}
void QtBlockListEditorWindow::setBusy(bool isBusy) {
- if (isBusy) {
- ui->throbberLabel->movie()->start();
- ui->throbberLabel->show();
- ui->blockListTreeWidget->setEnabled(false);
- ui->savePushButton->setEnabled(false);
- } else {
- ui->throbberLabel->movie()->stop();
- ui->throbberLabel->hide();
- ui->blockListTreeWidget->setEnabled(true);
- ui->savePushButton->setEnabled(true);
- }
+ if (isBusy) {
+ ui->throbberLabel->movie()->start();
+ ui->throbberLabel->show();
+ ui->blockListTreeWidget->setEnabled(false);
+ ui->savePushButton->setEnabled(false);
+ } else {
+ ui->throbberLabel->movie()->stop();
+ ui->throbberLabel->hide();
+ ui->blockListTreeWidget->setEnabled(true);
+ ui->savePushButton->setEnabled(true);
+ }
}
void QtBlockListEditorWindow::setError(const std::string& error) {
- if (!error.empty()) {
- ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
- }
- else {
- ui->errorLabel->setText("");
- }
+ if (!error.empty()) {
+ ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
+ }
+ else {
+ ui->errorLabel->setText("");
+ }
}
std::vector<JID> Swift::QtBlockListEditorWindow::getCurrentBlockList() const {
- std::vector<JID> futureBlockedJIDs;
-
- for(int i=0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i) {
- QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
- JID jid = JID(Q2PSTRING(row->text(0)));
- if (!jid.toString().empty() && jid.isValid()) {
- futureBlockedJIDs.push_back(jid);
- }
- }
- return futureBlockedJIDs;
+ std::vector<JID> futureBlockedJIDs;
+
+ for(int i=0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
+ JID jid = JID(Q2PSTRING(row->text(0)));
+ if (!jid.toString().empty() && jid.isValid()) {
+ futureBlockedJIDs.push_back(jid);
+ }
+ }
+ return futureBlockedJIDs;
}
bool QtBlockListEditorWindow::eventFilter(QObject* target, QEvent* event) {
- if (target == ui->blockListTreeWidget) {
- if (event->type() == QEvent::KeyPress) {
- QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
- if (keyEvent->key() == Qt::Key_Backspace) {
- // remove currently selected item
- QTreeWidgetItem* currentItem = ui->blockListTreeWidget->currentItem();
- if (currentItem->text(0) != freshBlockListTemplate) {
- ui->blockListTreeWidget->takeTopLevelItem(ui->blockListTreeWidget->indexOfTopLevelItem(currentItem));
- return true;
- }
- }
- else if (keyEvent->key() == Qt::Key_Return) {
- // open editor for return key d
- ui->blockListTreeWidget->editItem(ui->blockListTreeWidget->currentItem(), 0);
- return true;
- }
- }
- }
- return QWidget::eventFilter(target, event);
+ if (target == ui->blockListTreeWidget) {
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Backspace) {
+ // remove currently selected item
+ QTreeWidgetItem* currentItem = ui->blockListTreeWidget->currentItem();
+ if (currentItem->text(0) != freshBlockListTemplate) {
+ ui->blockListTreeWidget->takeTopLevelItem(ui->blockListTreeWidget->indexOfTopLevelItem(currentItem));
+ return true;
+ }
+ }
+ else if (keyEvent->key() == Qt::Key_Return) {
+ // open editor for return key d
+ ui->blockListTreeWidget->editItem(ui->blockListTreeWidget->currentItem(), 0);
+ return true;
+ }
+ }
+ }
+ return QWidget::eventFilter(target, event);
}
}
diff --git a/Swift/QtUI/QtBlockListEditorWindow.h b/Swift/QtUI/QtBlockListEditorWindow.h
index a594210..dc900ab 100644
--- a/Swift/QtUI/QtBlockListEditorWindow.h
+++ b/Swift/QtUI/QtBlockListEditorWindow.h
@@ -20,7 +20,7 @@
#include <Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h>
namespace Ui {
- class QtBlockListEditorWindow;
+ class QtBlockListEditorWindow;
}
namespace Swift {
@@ -28,29 +28,29 @@ namespace Swift {
class QtJIDValidatedItemDelegate;
class QtBlockListEditorWindow : public QWidget, public BlockListEditorWidget {
- Q_OBJECT
-
- public:
- QtBlockListEditorWindow();
- virtual ~QtBlockListEditorWindow();
-
- virtual void show();
- virtual void hide();
- virtual void setCurrentBlockList(const std::vector<JID>& blockedJIDs);
- virtual void setBusy(bool isBusy);
- virtual void setError(const std::string& error);
- virtual std::vector<JID> getCurrentBlockList() const;
- virtual bool eventFilter(QObject* target, QEvent* event);
-
- private slots:
- void handleItemChanged(QTreeWidgetItem*, int);
- void applyChanges();
-
- private:
- Ui::QtBlockListEditorWindow* ui;
- QtRemovableItemDelegate* removeItemDelegate;
- QtJIDValidatedItemDelegate* editItemDelegate;
- QString freshBlockListTemplate;
+ Q_OBJECT
+
+ public:
+ QtBlockListEditorWindow();
+ virtual ~QtBlockListEditorWindow();
+
+ virtual void show();
+ virtual void hide();
+ virtual void setCurrentBlockList(const std::vector<JID>& blockedJIDs);
+ virtual void setBusy(bool isBusy);
+ virtual void setError(const std::string& error);
+ virtual std::vector<JID> getCurrentBlockList() const;
+ virtual bool eventFilter(QObject* target, QEvent* event);
+
+ private slots:
+ void handleItemChanged(QTreeWidgetItem*, int);
+ void applyChanges();
+
+ private:
+ Ui::QtBlockListEditorWindow* ui;
+ QtRemovableItemDelegate* removeItemDelegate;
+ QtJIDValidatedItemDelegate* editItemDelegate;
+ QString freshBlockListTemplate;
};
}
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.cpp b/Swift/QtUI/QtBookmarkDetailWindow.cpp
index ea5b217..920e94e 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.cpp
+++ b/Swift/QtUI/QtBookmarkDetailWindow.cpp
@@ -13,67 +13,67 @@
namespace Swift {
QtBookmarkDetailWindow::QtBookmarkDetailWindow(QWidget* parent) : QDialog(parent) {
- setupUi(this);
- setAttribute(Qt::WA_DeleteOnClose, true);
- //connect(buttons_, SIGNAL(accepted()), SLOT(accept()));
- //connect(buttons_, SIGNAL(rejected()), SLOT(reject()));
- setFixedHeight(sizeHint().height());
+ setupUi(this);
+ setAttribute(Qt::WA_DeleteOnClose, true);
+ //connect(buttons_, SIGNAL(accepted()), SLOT(accept()));
+ //connect(buttons_, SIGNAL(rejected()), SLOT(reject()));
+ setFixedHeight(sizeHint().height());
}
void QtBookmarkDetailWindow::accept() {
- if (commit()) {
- QDialog::accept();
- }
+ if (commit()) {
+ QDialog::accept();
+ }
}
boost::optional<MUCBookmark> QtBookmarkDetailWindow::createBookmarkFromForm() {
- //check room
- //check bookmarkName
- JID room(Q2PSTRING(room_->text()));
- if (!room.isValid() || room.getNode().empty() || !room.getResource().empty()) {
- QMessageBox::warning(this, tr("Bookmark not valid"), tr("You must specify a valid room address (e.g. someroom@rooms.example.com)."));
- return boost::optional<MUCBookmark>();
- }
- std::string name(Q2PSTRING(name_->text()));
- if (name.empty()) {
- name = room.toString();
- }
+ //check room
+ //check bookmarkName
+ JID room(Q2PSTRING(room_->text()));
+ if (!room.isValid() || room.getNode().empty() || !room.getResource().empty()) {
+ QMessageBox::warning(this, tr("Bookmark not valid"), tr("You must specify a valid room address (e.g. someroom@rooms.example.com)."));
+ return boost::optional<MUCBookmark>();
+ }
+ std::string name(Q2PSTRING(name_->text()));
+ if (name.empty()) {
+ name = room.toString();
+ }
- MUCBookmark bookmark(room, name);
- std::string nick(Q2PSTRING(nick_->text()));
- std::string password(Q2PSTRING(password_->text()));
- bookmark.setAutojoin(autojoin_->isChecked());
- if (!nick.empty()) {
- bookmark.setNick(nick);
- }
- if (!password.empty()) {
- bookmark.setPassword(password);
- }
- return bookmark;
+ MUCBookmark bookmark(room, name);
+ std::string nick(Q2PSTRING(nick_->text()));
+ std::string password(Q2PSTRING(password_->text()));
+ bookmark.setAutojoin(autojoin_->isChecked());
+ if (!nick.empty()) {
+ bookmark.setNick(nick);
+ }
+ if (!password.empty()) {
+ bookmark.setPassword(password);
+ }
+ return bookmark;
}
void QtBookmarkDetailWindow::createFormFromBookmark(const MUCBookmark& bookmark) {
- if (bookmark.getRoom().isValid()) {
- room_->setText(P2QSTRING(bookmark.getRoom().toString()));
- }
+ if (bookmark.getRoom().isValid()) {
+ room_->setText(P2QSTRING(bookmark.getRoom().toString()));
+ }
- if (!bookmark.getName().empty()) {
- name_->setText(P2QSTRING(bookmark.getName()));
- }
+ if (!bookmark.getName().empty()) {
+ name_->setText(P2QSTRING(bookmark.getName()));
+ }
- if (bookmark.getNick()) {
- nick_->setText(P2QSTRING((*bookmark.getNick())));
- }
+ if (bookmark.getNick()) {
+ nick_->setText(P2QSTRING((*bookmark.getNick())));
+ }
- if (bookmark.getPassword()) {
- password_->setText(P2QSTRING((*bookmark.getPassword())));
- }
+ if (bookmark.getPassword()) {
+ password_->setText(P2QSTRING((*bookmark.getPassword())));
+ }
- if (bookmark.getAutojoin()) {
- autojoin_->setCheckState(Qt::Checked);
- } else {
- autojoin_->setCheckState(Qt::Unchecked);
- }
+ if (bookmark.getAutojoin()) {
+ autojoin_->setCheckState(Qt::Checked);
+ } else {
+ autojoin_->setCheckState(Qt::Unchecked);
+ }
}
}
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.h b/Swift/QtUI/QtBookmarkDetailWindow.h
index 427614a..19c6462 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.h
+++ b/Swift/QtUI/QtBookmarkDetailWindow.h
@@ -15,18 +15,18 @@
#include <Swift/QtUI/ui_QtBookmarkDetailWindow.h>
namespace Swift {
- class QtBookmarkDetailWindow : public QDialog, protected Ui::QtBookmarkDetailWindow {
- Q_OBJECT
- public:
- QtBookmarkDetailWindow(QWidget* parent = NULL);
- virtual bool commit() = 0;
- boost::optional<MUCBookmark> createBookmarkFromForm();
-
- protected:
- void createFormFromBookmark(const MUCBookmark& bookmark);
-
- public slots:
- void accept();
- };
+ class QtBookmarkDetailWindow : public QDialog, protected Ui::QtBookmarkDetailWindow {
+ Q_OBJECT
+ public:
+ QtBookmarkDetailWindow(QWidget* parent = NULL);
+ virtual bool commit() = 0;
+ boost::optional<MUCBookmark> createBookmarkFromForm();
+
+ protected:
+ void createFormFromBookmark(const MUCBookmark& bookmark);
+
+ public slots:
+ void accept();
+ };
}
diff --git a/Swift/QtUI/QtCachedImageScaler.cpp b/Swift/QtUI/QtCachedImageScaler.cpp
index 0e10062..e1f540b 100644
--- a/Swift/QtUI/QtCachedImageScaler.cpp
+++ b/Swift/QtUI/QtCachedImageScaler.cpp
@@ -20,25 +20,25 @@ QtCachedImageScaler::QtCachedImageScaler() {
}
boost::filesystem::path QtCachedImageScaler::getScaledImage(const boost::filesystem::path& imagePath, int size) {
- boost::filesystem::path scaledImagePath(imagePath);
- std::string suffix = "." + boost::lexical_cast<std::string>(size);
- scaledImagePath = stringToPath(pathToString(scaledImagePath) + suffix);
- if (!boost::filesystem::exists(scaledImagePath)) {
- QImage image(P2QSTRING(pathToString(imagePath)));
- if (!image.isNull()) {
- if (image.width() > size || image.height() > size) {
- QImage scaledImage = image.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- scaledImage.save(P2QSTRING(pathToString(scaledImagePath)), "PNG");
- }
- else {
- image.save(P2QSTRING(pathToString(scaledImagePath)), "PNG");
- }
- }
- else {
- return imagePath;
- }
- }
- return scaledImagePath;
+ boost::filesystem::path scaledImagePath(imagePath);
+ std::string suffix = "." + boost::lexical_cast<std::string>(size);
+ scaledImagePath = stringToPath(pathToString(scaledImagePath) + suffix);
+ if (!boost::filesystem::exists(scaledImagePath)) {
+ QImage image(P2QSTRING(pathToString(imagePath)));
+ if (!image.isNull()) {
+ if (image.width() > size || image.height() > size) {
+ QImage scaledImage = image.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ scaledImage.save(P2QSTRING(pathToString(scaledImagePath)), "PNG");
+ }
+ else {
+ image.save(P2QSTRING(pathToString(scaledImagePath)), "PNG");
+ }
+ }
+ else {
+ return imagePath;
+ }
+ }
+ return scaledImagePath;
}
diff --git a/Swift/QtUI/QtCachedImageScaler.h b/Swift/QtUI/QtCachedImageScaler.h
index fcc2a2d..15d868e 100644
--- a/Swift/QtUI/QtCachedImageScaler.h
+++ b/Swift/QtUI/QtCachedImageScaler.h
@@ -9,11 +9,11 @@
#include <boost/filesystem.hpp>
namespace Swift {
- class QtCachedImageScaler {
- public:
- QtCachedImageScaler();
+ class QtCachedImageScaler {
+ public:
+ QtCachedImageScaler();
- boost::filesystem::path getScaledImage(const boost::filesystem::path& image, int size);
- };
+ boost::filesystem::path getScaledImage(const boost::filesystem::path& image, int size);
+ };
}
diff --git a/Swift/QtUI/QtCertificateViewerDialog.cpp b/Swift/QtUI/QtCertificateViewerDialog.cpp
index 4b8b0cb..a99c29a 100644
--- a/Swift/QtUI/QtCertificateViewerDialog.cpp
+++ b/Swift/QtUI/QtCertificateViewerDialog.cpp
@@ -25,126 +25,126 @@
namespace Swift {
QtCertificateViewerDialog::QtCertificateViewerDialog(QWidget* parent) : QDialog(parent), ui(new Ui::QtCertificateViewerDialog) {
- ui->setupUi(this);
- connect(ui->certChainTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
+ ui->setupUi(this);
+ connect(ui->certChainTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
- setAttribute(Qt::WA_DeleteOnClose);
+ setAttribute(Qt::WA_DeleteOnClose);
}
QtCertificateViewerDialog::~QtCertificateViewerDialog() {
- delete ui;
+ delete ui;
}
void QtCertificateViewerDialog::setCertificateChain(const std::vector<Certificate::ref>& chain) {
- // clean widgets
- ui->certChainTreeWidget->clear();
-
- if (chain.empty()) return;
-
- // convert Swift certificate chain to qt certificate chain (root goes first)
- currentChain.clear();
- foreach(Certificate::ref cert, chain) {
- ByteArray certAsDer = cert->toDER();
- QByteArray dataArray(reinterpret_cast<const char*>(certAsDer.data()), certAsDer.size());
- currentChain.push_front(QSslCertificate(dataArray, QSsl::Der));
- }
-
- // fill treeWidget
- QTreeWidgetItem* root = new QTreeWidgetItem(ui->certChainTreeWidget, QStringList(currentChain.at(0).subjectInfo(QSslCertificate::CommonName)));
- root->setData(0, Qt::UserRole, QVariant(0));
- root->setExpanded(true);
- ui->certChainTreeWidget->addTopLevelItem(root);
- if (currentChain.size() > 1) {
- QTreeWidgetItem* parent = root;
- for (int n = 1; n < currentChain.size(); n++) {
- QTreeWidgetItem* link = new QTreeWidgetItem(parent, QStringList(QString("↳ ") + (QStringList(currentChain.at(n).subjectInfo(QSslCertificate::CommonName)).join(", "))));
- link->setExpanded(true);
- link->setData(0, Qt::UserRole, QVariant(n));
- parent = link;
- }
- ui->certChainTreeWidget->setCurrentItem(parent);
- } else {
- ui->certChainTreeWidget->setCurrentItem(root);
- }
+ // clean widgets
+ ui->certChainTreeWidget->clear();
+
+ if (chain.empty()) return;
+
+ // convert Swift certificate chain to qt certificate chain (root goes first)
+ currentChain.clear();
+ foreach(Certificate::ref cert, chain) {
+ ByteArray certAsDer = cert->toDER();
+ QByteArray dataArray(reinterpret_cast<const char*>(certAsDer.data()), certAsDer.size());
+ currentChain.push_front(QSslCertificate(dataArray, QSsl::Der));
+ }
+
+ // fill treeWidget
+ QTreeWidgetItem* root = new QTreeWidgetItem(ui->certChainTreeWidget, QStringList(currentChain.at(0).subjectInfo(QSslCertificate::CommonName)));
+ root->setData(0, Qt::UserRole, QVariant(0));
+ root->setExpanded(true);
+ ui->certChainTreeWidget->addTopLevelItem(root);
+ if (currentChain.size() > 1) {
+ QTreeWidgetItem* parent = root;
+ for (int n = 1; n < currentChain.size(); n++) {
+ QTreeWidgetItem* link = new QTreeWidgetItem(parent, QStringList(QString("↳ ") + (QStringList(currentChain.at(n).subjectInfo(QSslCertificate::CommonName)).join(", "))));
+ link->setExpanded(true);
+ link->setData(0, Qt::UserRole, QVariant(n));
+ parent = link;
+ }
+ ui->certChainTreeWidget->setCurrentItem(parent);
+ } else {
+ ui->certChainTreeWidget->setCurrentItem(root);
+ }
}
void QtCertificateViewerDialog::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
- QtCertificateViewerDialog* dialog = new QtCertificateViewerDialog(parent);
- dialog->setCertificateChain(chain);
- dialog->show();
+ QtCertificateViewerDialog* dialog = new QtCertificateViewerDialog(parent);
+ dialog->setCertificateChain(chain);
+ dialog->show();
}
void QtCertificateViewerDialog::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem*) {
- setCertificateDetails(currentChain.at(current->data(0, Qt::UserRole).toInt()));
+ setCertificateDetails(currentChain.at(current->data(0, Qt::UserRole).toInt()));
}
#define ADD_SECTION( TITLE ) \
- ui->certGridLayout->addWidget(new QLabel("<strong>" + TITLE + "</strong>"), rowCount++, 0, 1, 2);
+ ui->certGridLayout->addWidget(new QLabel("<strong>" + TITLE + "</strong>"), rowCount++, 0, 1, 2);
#define ADD_FIELD( TITLE, VALUE) \
- ui->certGridLayout->addWidget(new QLabel(TITLE), rowCount, 0, 1, 1, Qt::AlignRight); \
- valueLabel = new QLabel(); \
- valueLabel->setText(QStringList(VALUE).join(", ")); \
- valueLabel->setTextFormat(Qt::PlainText); \
- valueLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); \
- ui->certGridLayout->addWidget(valueLabel, rowCount++, 1, 1, 1, Qt::AlignLeft);
+ ui->certGridLayout->addWidget(new QLabel(TITLE), rowCount, 0, 1, 1, Qt::AlignRight); \
+ valueLabel = new QLabel(); \
+ valueLabel->setText(QStringList(VALUE).join(", ")); \
+ valueLabel->setTextFormat(Qt::PlainText); \
+ valueLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); \
+ ui->certGridLayout->addWidget(valueLabel, rowCount++, 1, 1, 1, Qt::AlignLeft);
void QtCertificateViewerDialog::setCertificateDetails(const QSslCertificate& cert) {
- QLayoutItem* item;
- while ((item = ui->certGridLayout->takeAt(0)) != NULL ) {
- delete item->widget();
- delete item;
- }
+ QLayoutItem* item;
+ while ((item = ui->certGridLayout->takeAt(0)) != NULL ) {
+ delete item->widget();
+ delete item;
+ }
- int rowCount = 0;
+ int rowCount = 0;
- ui->certGridLayout->setColumnStretch(2, 1);
+ ui->certGridLayout->setColumnStretch(2, 1);
- QLabel* valueLabel = 0;
+ QLabel* valueLabel = 0;
- ADD_SECTION(tr("General"));
- ADD_FIELD(tr("Valid From"), cert.effectiveDate().toString(Qt::TextDate));
- ADD_FIELD(tr("Valid To"), cert.expiryDate().toString(Qt::TextDate));
- ADD_FIELD(tr("Serial Number"), QString(cert.serialNumber().toHex()));
- ADD_FIELD(tr("Version"), QString(cert.version()));
+ ADD_SECTION(tr("General"));
+ ADD_FIELD(tr("Valid From"), cert.effectiveDate().toString(Qt::TextDate));
+ ADD_FIELD(tr("Valid To"), cert.expiryDate().toString(Qt::TextDate));
+ ADD_FIELD(tr("Serial Number"), QString(cert.serialNumber().toHex()));
+ ADD_FIELD(tr("Version"), QString(cert.version()));
- ADD_SECTION(tr("Subject"));
- ADD_FIELD(tr("Organization"), cert.subjectInfo(QSslCertificate::Organization));
- ADD_FIELD(tr("Common Name"), cert.subjectInfo(QSslCertificate::CommonName));
- ADD_FIELD(tr("Locality"), cert.subjectInfo(QSslCertificate::LocalityName));
- ADD_FIELD(tr("Organizational Unit"), cert.subjectInfo(QSslCertificate::OrganizationalUnitName));
- ADD_FIELD(tr("Country"), cert.subjectInfo(QSslCertificate::CountryName));
- ADD_FIELD(tr("State"), cert.subjectInfo(QSslCertificate::StateOrProvinceName));
+ ADD_SECTION(tr("Subject"));
+ ADD_FIELD(tr("Organization"), cert.subjectInfo(QSslCertificate::Organization));
+ ADD_FIELD(tr("Common Name"), cert.subjectInfo(QSslCertificate::CommonName));
+ ADD_FIELD(tr("Locality"), cert.subjectInfo(QSslCertificate::LocalityName));
+ ADD_FIELD(tr("Organizational Unit"), cert.subjectInfo(QSslCertificate::OrganizationalUnitName));
+ ADD_FIELD(tr("Country"), cert.subjectInfo(QSslCertificate::CountryName));
+ ADD_FIELD(tr("State"), cert.subjectInfo(QSslCertificate::StateOrProvinceName));
#if QT_VERSION < 0x050000
- QMultiMap<QSsl::AlternateNameEntryType, QString> altNames = cert.alternateSubjectNames();
+ QMultiMap<QSsl::AlternateNameEntryType, QString> altNames = cert.alternateSubjectNames();
#define SANTYPE QSsl::AlternateNameEntryType
#else
- QMultiMap<QSsl::AlternativeNameEntryType, QString> altNames = cert.subjectAlternativeNames();
+ QMultiMap<QSsl::AlternativeNameEntryType, QString> altNames = cert.subjectAlternativeNames();
#define SANTYPE QSsl::AlternativeNameEntryType
#endif
- if (!altNames.empty()) {
- ADD_SECTION(tr("Alternate Subject Names"));
- foreach (const SANTYPE &type, altNames.uniqueKeys()) {
- foreach (QString name, altNames.values(type)) {
- if (type == QSsl::EmailEntry) {
- ADD_FIELD(tr("E-mail Address"), name);
- } else {
- ADD_FIELD(tr("DNS Name"), name);
- }
- }
- }
- }
-
- ADD_SECTION(tr("Issuer"));
- ADD_FIELD(tr("Organization"), cert.issuerInfo(QSslCertificate::Organization));
- ADD_FIELD(tr("Common Name"), cert.issuerInfo(QSslCertificate::CommonName));
- ADD_FIELD(tr("Locality"), cert.issuerInfo(QSslCertificate::LocalityName));
- ADD_FIELD(tr("Organizational Unit"), cert.issuerInfo(QSslCertificate::OrganizationalUnitName));
- ADD_FIELD(tr("Country"), cert.issuerInfo(QSslCertificate::CountryName));
- ADD_FIELD(tr("State"), cert.issuerInfo(QSslCertificate::StateOrProvinceName));
-
- ui->certGridLayout->setRowStretch(rowCount + 1, 1);
+ if (!altNames.empty()) {
+ ADD_SECTION(tr("Alternate Subject Names"));
+ foreach (const SANTYPE &type, altNames.uniqueKeys()) {
+ foreach (QString name, altNames.values(type)) {
+ if (type == QSsl::EmailEntry) {
+ ADD_FIELD(tr("E-mail Address"), name);
+ } else {
+ ADD_FIELD(tr("DNS Name"), name);
+ }
+ }
+ }
+ }
+
+ ADD_SECTION(tr("Issuer"));
+ ADD_FIELD(tr("Organization"), cert.issuerInfo(QSslCertificate::Organization));
+ ADD_FIELD(tr("Common Name"), cert.issuerInfo(QSslCertificate::CommonName));
+ ADD_FIELD(tr("Locality"), cert.issuerInfo(QSslCertificate::LocalityName));
+ ADD_FIELD(tr("Organizational Unit"), cert.issuerInfo(QSslCertificate::OrganizationalUnitName));
+ ADD_FIELD(tr("Country"), cert.issuerInfo(QSslCertificate::CountryName));
+ ADD_FIELD(tr("State"), cert.issuerInfo(QSslCertificate::StateOrProvinceName));
+
+ ui->certGridLayout->setRowStretch(rowCount + 1, 1);
}
}
diff --git a/Swift/QtUI/QtCertificateViewerDialog.h b/Swift/QtUI/QtCertificateViewerDialog.h
index 9475a83..7b72f1d 100644
--- a/Swift/QtUI/QtCertificateViewerDialog.h
+++ b/Swift/QtUI/QtCertificateViewerDialog.h
@@ -20,25 +20,25 @@ class QtCertificateViewerDialog;
namespace Swift {
class QtCertificateViewerDialog : public QDialog {
- Q_OBJECT
-
- public:
- explicit QtCertificateViewerDialog(QWidget* parent = 0);
- ~QtCertificateViewerDialog();
+ Q_OBJECT
- void setCertificateChain(const std::vector<Certificate::ref>& chain);
+ public:
+ explicit QtCertificateViewerDialog(QWidget* parent = 0);
+ ~QtCertificateViewerDialog();
- static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
+ void setCertificateChain(const std::vector<Certificate::ref>& chain);
- private slots:
- void currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*);
+ static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
- private:
- void setCertificateDetails(const QSslCertificate& cert);
+ private slots:
+ void currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*);
- private:
- Ui::QtCertificateViewerDialog *ui;
- QList<QSslCertificate> currentChain;
+ private:
+ void setCertificateDetails(const QSslCertificate& cert);
+
+ private:
+ Ui::QtCertificateViewerDialog *ui;
+ QList<QSslCertificate> currentChain;
};
}
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index f22d869..4a77ffd 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -35,389 +35,389 @@
namespace Swift {
QtChatTabs::QtChatTabs(bool singleWindow, SettingsProvider* settingsProvider, bool trellisMode) : QWidget(), singleWindow_(singleWindow), settingsProvider_(settingsProvider), trellisMode_(trellisMode), dynamicGrid_(NULL), gridSelectionDialog_(NULL) {
#ifndef Q_OS_MAC
- setWindowIcon(QIcon(":/logo-chat-16.png"));
+ setWindowIcon(QIcon(":/logo-chat-16.png"));
#else
- setAttribute(Qt::WA_ShowWithoutActivating);
+ setAttribute(Qt::WA_ShowWithoutActivating);
#endif
- dynamicGrid_ = new QtDynamicGridLayout(this, trellisMode);
- connect(dynamicGrid_, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabCloseRequested(int)));
- connect(dynamicGrid_, SIGNAL(onCurrentIndexChanged(int)), this, SLOT(handleCurrentTabIndexChanged(int)));
-
- QVBoxLayout *layout = new QVBoxLayout;
- layout->setSpacing(0);
- layout->setContentsMargins(0, 0, 0, 0);
- layout->addWidget(dynamicGrid_);
- setLayout(layout);
-
- if (trellisMode) {
- // restore size
- std::string gridSizeString = settingsProvider->getSetting(SettingConstants::TRELLIS_GRID_SIZE);
- if (!gridSizeString.empty()) {
- QByteArray gridSizeData = QByteArray::fromBase64(P2QSTRING(gridSizeString).toUtf8());
- QDataStream dataStreamGridSize(&gridSizeData, QIODevice::ReadWrite);
- QSize gridSize(1,1);
- dataStreamGridSize >> gridSize;
- dynamicGrid_->setDimensions(gridSize);
- }
-
- // restore positions
- std::string tabPositionsString = settingsProvider->getSetting(SettingConstants::TRELLIS_GRID_POSITIONS);
- if (!tabPositionsString.empty()) {
- QByteArray tabPositionsData = QByteArray::fromBase64(P2QSTRING(tabPositionsString).toUtf8());
- QDataStream inTabPositions(&tabPositionsData, QIODevice::ReadWrite);
- QHash<QString, QPoint> tabPositions;
- inTabPositions >> tabPositions;
- dynamicGrid_->setTabPositions(tabPositions);
- }
- }
-
- gridSelectionDialog_ = new QtGridSelectionDialog();
-
- // setup shortcuts
- shortcuts_ << new QShortcut(QKeySequence(tr("CTRL+W", "Close chat tab.")), window(), SLOT(handleCloseTabShortcut()));
- shortcuts_ << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), window(), SLOT(handleRequestedPreviousTab()));
- shortcuts_ << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown), window(), SLOT(handleRequestedNextTab()));
- shortcuts_ << new QShortcut(QKeySequence(Qt::ALT + Qt::Key_A), window(), SLOT(handleRequestedActiveTab()));
+ dynamicGrid_ = new QtDynamicGridLayout(this, trellisMode);
+ connect(dynamicGrid_, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabCloseRequested(int)));
+ connect(dynamicGrid_, SIGNAL(onCurrentIndexChanged(int)), this, SLOT(handleCurrentTabIndexChanged(int)));
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->setSpacing(0);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addWidget(dynamicGrid_);
+ setLayout(layout);
+
+ if (trellisMode) {
+ // restore size
+ std::string gridSizeString = settingsProvider->getSetting(SettingConstants::TRELLIS_GRID_SIZE);
+ if (!gridSizeString.empty()) {
+ QByteArray gridSizeData = QByteArray::fromBase64(P2QSTRING(gridSizeString).toUtf8());
+ QDataStream dataStreamGridSize(&gridSizeData, QIODevice::ReadWrite);
+ QSize gridSize(1,1);
+ dataStreamGridSize >> gridSize;
+ dynamicGrid_->setDimensions(gridSize);
+ }
+
+ // restore positions
+ std::string tabPositionsString = settingsProvider->getSetting(SettingConstants::TRELLIS_GRID_POSITIONS);
+ if (!tabPositionsString.empty()) {
+ QByteArray tabPositionsData = QByteArray::fromBase64(P2QSTRING(tabPositionsString).toUtf8());
+ QDataStream inTabPositions(&tabPositionsData, QIODevice::ReadWrite);
+ QHash<QString, QPoint> tabPositions;
+ inTabPositions >> tabPositions;
+ dynamicGrid_->setTabPositions(tabPositions);
+ }
+ }
+
+ gridSelectionDialog_ = new QtGridSelectionDialog();
+
+ // setup shortcuts
+ shortcuts_ << new QShortcut(QKeySequence(tr("CTRL+W", "Close chat tab.")), window(), SLOT(handleCloseTabShortcut()));
+ shortcuts_ << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), window(), SLOT(handleRequestedPreviousTab()));
+ shortcuts_ << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown), window(), SLOT(handleRequestedNextTab()));
+ shortcuts_ << new QShortcut(QKeySequence(Qt::ALT + Qt::Key_A), window(), SLOT(handleRequestedActiveTab()));
}
QtChatTabs::~QtChatTabs() {
- foreach (QShortcut* shortcut, shortcuts_) {
- delete shortcut;
- }
-
- if (trellisMode_) {
- storeTabPositions();
- }
- delete gridSelectionDialog_;
+ foreach (QShortcut* shortcut, shortcuts_) {
+ delete shortcut;
+ }
+
+ if (trellisMode_) {
+ storeTabPositions();
+ }
+ delete gridSelectionDialog_;
}
void QtChatTabs::closeEvent(QCloseEvent* event) {
- //Hide first to prevent flickering as each tab is removed.
- hide();
- if (trellisMode_) {
- storeTabPositions();
- }
-
- for (int i = dynamicGrid_->count() - 1; i >= 0; i--) {
- dynamicGrid_->widget(i)->close();
- }
- event->accept();
+ //Hide first to prevent flickering as each tab is removed.
+ hide();
+ if (trellisMode_) {
+ storeTabPositions();
+ }
+
+ for (int i = dynamicGrid_->count() - 1; i >= 0; i--) {
+ dynamicGrid_->widget(i)->close();
+ }
+ event->accept();
}
QtTabbable* QtChatTabs::getCurrentTab() {
- return qobject_cast<QtTabbable*>(dynamicGrid_->currentWidget());
+ return qobject_cast<QtTabbable*>(dynamicGrid_->currentWidget());
}
void QtChatTabs::setViewMenu(QMenu* viewMenu) {
- if (trellisMode_) {
- viewMenu->addSeparator();
- QAction* action = new QAction(tr("Change &layout"), this);
- action->setShortcutContext(Qt::ApplicationShortcut);
- action->setShortcut(QKeySequence(tr("Ctrl+Alt+L")));
- connect(action, SIGNAL(triggered()), this, SLOT(handleOpenLayoutChangeDialog()));
- viewMenu->addAction(action);
-
- action = new QAction(tr("Move Tab right"), this);
- action->setShortcutContext(Qt::ApplicationShortcut);
- action->setShortcut(QKeySequence(tr("Ctrl+Shift+PgDown")));
- connect(action, SIGNAL(triggered()), dynamicGrid_, SLOT(moveCurrentTabRight()));
- viewMenu->addAction(action);
-
- action = new QAction(tr("Move Tab left"), this);
- action->setShortcutContext(Qt::ApplicationShortcut);
- action->setShortcut(QKeySequence(tr("Ctrl+Shift+PgUp")));
- connect(action, SIGNAL(triggered()), dynamicGrid_, SLOT(moveCurrentTabLeft()));
- viewMenu->addAction(action);
-
- action = new QAction(tr("Move Tab to next group"), this);
- action->setShortcutContext(Qt::ApplicationShortcut);
- action->setShortcut(QKeySequence(tr("Ctrl+Alt+PgDown")));
- connect(action, SIGNAL(triggered()), dynamicGrid_, SLOT(moveCurrentTabToNextGroup()));
- viewMenu->addAction(action);
-
- action = new QAction(tr("Move Tab to previous group"), this);
- action->setShortcutContext(Qt::ApplicationShortcut);
- action->setShortcut(QKeySequence(tr("Ctrl+Alt+PgUp")));
- connect(action, SIGNAL(triggered()), dynamicGrid_, SLOT(moveCurrentTabToPreviousGroup()));
- viewMenu->addAction(action);
- }
+ if (trellisMode_) {
+ viewMenu->addSeparator();
+ QAction* action = new QAction(tr("Change &layout"), this);
+ action->setShortcutContext(Qt::ApplicationShortcut);
+ action->setShortcut(QKeySequence(tr("Ctrl+Alt+L")));
+ connect(action, SIGNAL(triggered()), this, SLOT(handleOpenLayoutChangeDialog()));
+ viewMenu->addAction(action);
+
+ action = new QAction(tr("Move Tab right"), this);
+ action->setShortcutContext(Qt::ApplicationShortcut);
+ action->setShortcut(QKeySequence(tr("Ctrl+Shift+PgDown")));
+ connect(action, SIGNAL(triggered()), dynamicGrid_, SLOT(moveCurrentTabRight()));
+ viewMenu->addAction(action);
+
+ action = new QAction(tr("Move Tab left"), this);
+ action->setShortcutContext(Qt::ApplicationShortcut);
+ action->setShortcut(QKeySequence(tr("Ctrl+Shift+PgUp")));
+ connect(action, SIGNAL(triggered()), dynamicGrid_, SLOT(moveCurrentTabLeft()));
+ viewMenu->addAction(action);
+
+ action = new QAction(tr("Move Tab to next group"), this);
+ action->setShortcutContext(Qt::ApplicationShortcut);
+ action->setShortcut(QKeySequence(tr("Ctrl+Alt+PgDown")));
+ connect(action, SIGNAL(triggered()), dynamicGrid_, SLOT(moveCurrentTabToNextGroup()));
+ viewMenu->addAction(action);
+
+ action = new QAction(tr("Move Tab to previous group"), this);
+ action->setShortcutContext(Qt::ApplicationShortcut);
+ action->setShortcut(QKeySequence(tr("Ctrl+Alt+PgUp")));
+ connect(action, SIGNAL(triggered()), dynamicGrid_, SLOT(moveCurrentTabToPreviousGroup()));
+ viewMenu->addAction(action);
+ }
}
void QtChatTabs::addTab(QtTabbable* tab) {
- QSizePolicy policy = sizePolicy();
- /* Chat windows like to grow - don't let them */
- setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- dynamicGrid_->addTab(tab, tab->windowTitle());
- connect(tab, SIGNAL(titleUpdated()), this, SLOT(handleTabTitleUpdated()), Qt::UniqueConnection);
- connect(tab, SIGNAL(countUpdated()), this, SLOT(handleTabTitleUpdated()), Qt::UniqueConnection);
- connect(tab, SIGNAL(windowClosing()), this, SLOT(handleTabClosing()), Qt::UniqueConnection);
- connect(tab, SIGNAL(windowOpening()), this, SLOT(handleWidgetShown()), Qt::UniqueConnection);
- connect(tab, SIGNAL(wantsToActivate()), this, SLOT(handleWantsToActivate()), Qt::UniqueConnection);
- connect(tab, SIGNAL(requestNextTab()), this, SLOT(handleRequestedNextTab()), Qt::UniqueConnection);
- connect(tab, SIGNAL(requestActiveTab()), this, SLOT(handleRequestedActiveTab()), Qt::UniqueConnection);
- connect(tab, SIGNAL(requestPreviousTab()), this, SLOT(handleRequestedPreviousTab()), Qt::UniqueConnection);
- connect(tab, SIGNAL(requestFlash()), this, SLOT(flash()), Qt::UniqueConnection);
- setSizePolicy(policy);
+ QSizePolicy policy = sizePolicy();
+ /* Chat windows like to grow - don't let them */
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ dynamicGrid_->addTab(tab, tab->windowTitle());
+ connect(tab, SIGNAL(titleUpdated()), this, SLOT(handleTabTitleUpdated()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(countUpdated()), this, SLOT(handleTabTitleUpdated()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(windowClosing()), this, SLOT(handleTabClosing()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(windowOpening()), this, SLOT(handleWidgetShown()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(wantsToActivate()), this, SLOT(handleWantsToActivate()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(requestNextTab()), this, SLOT(handleRequestedNextTab()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(requestActiveTab()), this, SLOT(handleRequestedActiveTab()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(requestPreviousTab()), this, SLOT(handleRequestedPreviousTab()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(requestFlash()), this, SLOT(flash()), Qt::UniqueConnection);
+ setSizePolicy(policy);
}
void QtChatTabs::handleWidgetShown() {
- QtTabbable* widget = qobject_cast<QtTabbable*>(sender());
- if (!widget) {
- return;
- }
- checkForFirstShow();
- if (dynamicGrid_->indexOf(widget) >= 0) {
- handleTabTitleUpdated(widget);
- return;
- }
- widget->blockSignals(true);
- addTab(widget);
- widget->blockSignals(false);
- show();
+ QtTabbable* widget = qobject_cast<QtTabbable*>(sender());
+ if (!widget) {
+ return;
+ }
+ checkForFirstShow();
+ if (dynamicGrid_->indexOf(widget) >= 0) {
+ handleTabTitleUpdated(widget);
+ return;
+ }
+ widget->blockSignals(true);
+ addTab(widget);
+ widget->blockSignals(false);
+ show();
}
void QtChatTabs::handleCurrentTabIndexChanged(int newIndex) {
- handleTabTitleUpdated(dynamicGrid_->widget(newIndex));
+ handleTabTitleUpdated(dynamicGrid_->widget(newIndex));
}
void QtChatTabs::handleWantsToActivate() {
- QtTabbable* widget = qobject_cast<QtTabbable*>(sender());
- Q_ASSERT(widget);
- //Un-minimize and bring to front.
- setWindowState(windowState() & ~Qt::WindowMinimized);
- setWindowState(windowState() | Qt::WindowActive);
- show();
- widget->show();
- dynamicGrid_->setCurrentWidget(widget);
- handleTabTitleUpdated(widget);
- widget->setFocus();
- raise();
- activateWindow();
+ QtTabbable* widget = qobject_cast<QtTabbable*>(sender());
+ Q_ASSERT(widget);
+ //Un-minimize and bring to front.
+ setWindowState(windowState() & ~Qt::WindowMinimized);
+ setWindowState(windowState() | Qt::WindowActive);
+ show();
+ widget->show();
+ dynamicGrid_->setCurrentWidget(widget);
+ handleTabTitleUpdated(widget);
+ widget->setFocus();
+ raise();
+ activateWindow();
}
void QtChatTabs::handleTabClosing() {
- QWidget* widget = qobject_cast<QWidget*>(sender());
- int index;
- if (widget && ((index = dynamicGrid_->indexOf(widget)) >= 0)) {
- dynamicGrid_->removeTab(index);
- if (dynamicGrid_->count() == 0) {
- if (!singleWindow_) {
- hide();
- }
- else {
- setWindowTitle("");
- onTitleChanged("");
- }
- }
- else {
- handleTabTitleUpdated(dynamicGrid_->currentWidget());
- }
- }
+ QWidget* widget = qobject_cast<QWidget*>(sender());
+ int index;
+ if (widget && ((index = dynamicGrid_->indexOf(widget)) >= 0)) {
+ dynamicGrid_->removeTab(index);
+ if (dynamicGrid_->count() == 0) {
+ if (!singleWindow_) {
+ hide();
+ }
+ else {
+ setWindowTitle("");
+ onTitleChanged("");
+ }
+ }
+ else {
+ handleTabTitleUpdated(dynamicGrid_->currentWidget());
+ }
+ }
}
void QtChatTabs::handleRequestedPreviousTab() {
- int newIndex = dynamicGrid_->currentIndex() - 1;
- dynamicGrid_->setCurrentIndex(newIndex >= 0 ? newIndex : dynamicGrid_->count() - 1);
+ int newIndex = dynamicGrid_->currentIndex() - 1;
+ dynamicGrid_->setCurrentIndex(newIndex >= 0 ? newIndex : dynamicGrid_->count() - 1);
}
void QtChatTabs::handleRequestedNextTab() {
- int newIndex = dynamicGrid_->currentIndex() + 1;
- dynamicGrid_->setCurrentIndex(newIndex < dynamicGrid_->count() ? newIndex : 0);
+ int newIndex = dynamicGrid_->currentIndex() + 1;
+ dynamicGrid_->setCurrentIndex(newIndex < dynamicGrid_->count() ? newIndex : 0);
}
void QtChatTabs::handleRequestedActiveTab() {
- QtTabbable::AlertType types[] = {QtTabbable::WaitingActivity, QtTabbable::ImpendingActivity};
- bool finished = false;
- for (int j = 0; j < 2; j++) {
- bool looped = false;
- for (int i = dynamicGrid_->currentIndex() + 1; !finished && i != dynamicGrid_->currentIndex(); i++) {
- if (i >= dynamicGrid_->count()) {
- if (looped) {
- break;
- }
- looped = true;
- i = 0;
- }
- if (qobject_cast<QtTabbable*>(dynamicGrid_->widget(i))->getWidgetAlertState() == types[j]) {
- dynamicGrid_->setCurrentIndex(i);
- finished = true;
- break;
- }
- }
- }
+ QtTabbable::AlertType types[] = {QtTabbable::WaitingActivity, QtTabbable::ImpendingActivity};
+ bool finished = false;
+ for (int j = 0; j < 2; j++) {
+ bool looped = false;
+ for (int i = dynamicGrid_->currentIndex() + 1; !finished && i != dynamicGrid_->currentIndex(); i++) {
+ if (i >= dynamicGrid_->count()) {
+ if (looped) {
+ break;
+ }
+ looped = true;
+ i = 0;
+ }
+ if (qobject_cast<QtTabbable*>(dynamicGrid_->widget(i))->getWidgetAlertState() == types[j]) {
+ dynamicGrid_->setCurrentIndex(i);
+ finished = true;
+ break;
+ }
+ }
+ }
}
void QtChatTabs::handleCloseTabShortcut() {
- QWidget* currentWidget = dynamicGrid_->currentWidget();
- if (currentWidget) {
- currentWidget->close();
- }
+ QWidget* currentWidget = dynamicGrid_->currentWidget();
+ if (currentWidget) {
+ currentWidget->close();
+ }
}
void QtChatTabs::handleTabCloseRequested(int index) {
- if (trellisMode_) {
- storeTabPositions();
- }
-
- assert(index < dynamicGrid_->count());
- QWidget* widget = dynamicGrid_->widget(index);
- assert(widget);
- widget->close();
+ if (trellisMode_) {
+ storeTabPositions();
+ }
+
+ assert(index < dynamicGrid_->count());
+ QWidget* widget = dynamicGrid_->widget(index);
+ assert(widget);
+ widget->close();
}
void QtChatTabs::handleTabTitleUpdated() {
- QWidget* widget = qobject_cast<QWidget*>(sender());
- handleTabTitleUpdated(widget);
+ QWidget* widget = qobject_cast<QWidget*>(sender());
+ handleTabTitleUpdated(widget);
}
void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
- if (!widget) {
- return;
- }
- QtTabbable* tabbable = qobject_cast<QtTabbable*>(widget);
- int index = dynamicGrid_->indexOf(widget);
- if (index < 0) {
- return;
- }
-
- QString tabText = tabbable->windowTitle().simplified();
- // look for spectrum-generated and other long JID localparts, and
- // try to abbreviate the resulting long tab texts
- QRegExp hasTrailingGarbage("^(.[-\\w\\s,&]+)([^\\s\\,w].*)$");
- if (hasTrailingGarbage.exactMatch(tabText) &&
- hasTrailingGarbage.cap(1).simplified().length() >= 2 &&
- hasTrailingGarbage.cap(2).length() >= 7) {
- // there may be some trailing garbage, and it's long
- // enough to be worth removing, and we'd leave at
- // least a couple of characters.
- tabText = hasTrailingGarbage.cap(1).simplified();
- }
- // QTabBar interprets &, so escape that
- tabText.replace("&", "&&");
- // see which alt[a-z] keys other tabs use
- bool accelsTaken[26];
- int i = 0;
- while (i < 26) {
- accelsTaken[i] = (i == 0); //A is used for 'switch to active tab'
- i++;
- }
-
- int other = dynamicGrid_->count();
- while (other >= 0) {
- other--;
- if (other != index) {
- int tabIndex = -1;
- QtTabWidget* tabWidget = dynamicGrid_->indexToTabWidget(other, tabIndex);
- QString t = tabWidget->tabBar()->tabText(tabIndex).toLower();
- int r = t.indexOf('&');
- if (r >= 0 && t[r+1] >= 'a' && t[r+1] <= 'z') {
- accelsTaken[t[r+1].unicode()-'a'] = true;
- }
- }
- }
- // then look to see which letters in tabText may be used
- i = 0;
- int accelPos = -1;
- while (i < tabText.length() && accelPos < 0) {
- if (tabText[i] >= 'A' && tabText[i] <= 'Z' &&
- !accelsTaken[tabText[i].unicode()-'A']) {
- accelPos = i;
- }
- if (tabText[i] >= 'a' && tabText[i] <= 'z' &&
- !accelsTaken[tabText[i].unicode()-'a']) {
- accelPos = i;
- }
- ++i;
- }
- if (accelPos >= 0) {
- tabText = tabText.mid(0, accelPos) + "&" + tabText.mid(accelPos);
- }
- // this could be improved on some european keyboards, such as
- // the German one (where alt-Sz-Ligature is available) and basically
- // doesn't work on Arabic/Indic keyboards (where Latin letters
- // aren't available), but I don't care to deal with those.
-
- int tabIndex = -1;
- QtTabWidget* tabWidget = dynamicGrid_->indexToTabWidget(index, tabIndex);
- tabWidget->setTabText(tabIndex, tabbable->getCount() > 0 ? QString("(%1) %2").arg(tabbable->getCount()).arg(tabText) : tabText);
- QColor tabTextColor;
- switch (tabbable->getWidgetAlertState()) {
- case QtTabbable::WaitingActivity : tabTextColor = QColor(217, 20, 43); break;
- case QtTabbable::ImpendingActivity : tabTextColor = QColor(27, 171, 32); break;
- case QtTabbable::NoActivity : tabTextColor = QColor(); break;
- }
- tabWidget->tabBar()->setTabTextColor(tabIndex, tabTextColor);
-
- std::vector<std::pair<std::string, int> > unreads;
- for (int i = 0; i < dynamicGrid_->count(); i++) {
- QtTabbable* tab = qobject_cast<QtTabbable*>(dynamicGrid_->widget(i));
- if (tab) {
- unreads.push_back(std::pair<std::string, int>(Q2PSTRING(tab->windowTitle()), tab->getCount()));
- }
- }
-
- std::string current(Q2PSTRING(qobject_cast<QtTabbable*>(dynamicGrid_->currentWidget())->windowTitle()));
- ChatMessageSummarizer summary;
- QString title = summary.getSummary(current, unreads).c_str();
- setWindowTitle(title);
- emit onTitleChanged(title);
+ if (!widget) {
+ return;
+ }
+ QtTabbable* tabbable = qobject_cast<QtTabbable*>(widget);
+ int index = dynamicGrid_->indexOf(widget);
+ if (index < 0) {
+ return;
+ }
+
+ QString tabText = tabbable->windowTitle().simplified();
+ // look for spectrum-generated and other long JID localparts, and
+ // try to abbreviate the resulting long tab texts
+ QRegExp hasTrailingGarbage("^(.[-\\w\\s,&]+)([^\\s\\,w].*)$");
+ if (hasTrailingGarbage.exactMatch(tabText) &&
+ hasTrailingGarbage.cap(1).simplified().length() >= 2 &&
+ hasTrailingGarbage.cap(2).length() >= 7) {
+ // there may be some trailing garbage, and it's long
+ // enough to be worth removing, and we'd leave at
+ // least a couple of characters.
+ tabText = hasTrailingGarbage.cap(1).simplified();
+ }
+ // QTabBar interprets &, so escape that
+ tabText.replace("&", "&&");
+ // see which alt[a-z] keys other tabs use
+ bool accelsTaken[26];
+ int i = 0;
+ while (i < 26) {
+ accelsTaken[i] = (i == 0); //A is used for 'switch to active tab'
+ i++;
+ }
+
+ int other = dynamicGrid_->count();
+ while (other >= 0) {
+ other--;
+ if (other != index) {
+ int tabIndex = -1;
+ QtTabWidget* tabWidget = dynamicGrid_->indexToTabWidget(other, tabIndex);
+ QString t = tabWidget->tabBar()->tabText(tabIndex).toLower();
+ int r = t.indexOf('&');
+ if (r >= 0 && t[r+1] >= 'a' && t[r+1] <= 'z') {
+ accelsTaken[t[r+1].unicode()-'a'] = true;
+ }
+ }
+ }
+ // then look to see which letters in tabText may be used
+ i = 0;
+ int accelPos = -1;
+ while (i < tabText.length() && accelPos < 0) {
+ if (tabText[i] >= 'A' && tabText[i] <= 'Z' &&
+ !accelsTaken[tabText[i].unicode()-'A']) {
+ accelPos = i;
+ }
+ if (tabText[i] >= 'a' && tabText[i] <= 'z' &&
+ !accelsTaken[tabText[i].unicode()-'a']) {
+ accelPos = i;
+ }
+ ++i;
+ }
+ if (accelPos >= 0) {
+ tabText = tabText.mid(0, accelPos) + "&" + tabText.mid(accelPos);
+ }
+ // this could be improved on some european keyboards, such as
+ // the German one (where alt-Sz-Ligature is available) and basically
+ // doesn't work on Arabic/Indic keyboards (where Latin letters
+ // aren't available), but I don't care to deal with those.
+
+ int tabIndex = -1;
+ QtTabWidget* tabWidget = dynamicGrid_->indexToTabWidget(index, tabIndex);
+ tabWidget->setTabText(tabIndex, tabbable->getCount() > 0 ? QString("(%1) %2").arg(tabbable->getCount()).arg(tabText) : tabText);
+ QColor tabTextColor;
+ switch (tabbable->getWidgetAlertState()) {
+ case QtTabbable::WaitingActivity : tabTextColor = QColor(217, 20, 43); break;
+ case QtTabbable::ImpendingActivity : tabTextColor = QColor(27, 171, 32); break;
+ case QtTabbable::NoActivity : tabTextColor = QColor(); break;
+ }
+ tabWidget->tabBar()->setTabTextColor(tabIndex, tabTextColor);
+
+ std::vector<std::pair<std::string, int> > unreads;
+ for (int i = 0; i < dynamicGrid_->count(); i++) {
+ QtTabbable* tab = qobject_cast<QtTabbable*>(dynamicGrid_->widget(i));
+ if (tab) {
+ unreads.push_back(std::pair<std::string, int>(Q2PSTRING(tab->windowTitle()), tab->getCount()));
+ }
+ }
+
+ std::string current(Q2PSTRING(qobject_cast<QtTabbable*>(dynamicGrid_->currentWidget())->windowTitle()));
+ ChatMessageSummarizer summary;
+ QString title = summary.getSummary(current, unreads).c_str();
+ setWindowTitle(title);
+ emit onTitleChanged(title);
}
void QtChatTabs::flash() {
#ifndef SWIFTEN_PLATFORM_MACOSX
- QApplication::alert(this, 0);
+ QApplication::alert(this, 0);
#endif
}
void QtChatTabs::handleOpenLayoutChangeDialog() {
- disconnect(gridSelectionDialog_, SIGNAL(currentGridSizeChanged(QSize)), dynamicGrid_, SLOT(setDimensions(QSize)));
- gridSelectionDialog_->setCurrentGridSize(dynamicGrid_->getDimension());
- gridSelectionDialog_->move(QCursor::pos());
- connect(gridSelectionDialog_, SIGNAL(currentGridSizeChanged(QSize)), dynamicGrid_, SLOT(setDimensions(QSize)));
- gridSelectionDialog_->show();
+ disconnect(gridSelectionDialog_, SIGNAL(currentGridSizeChanged(QSize)), dynamicGrid_, SLOT(setDimensions(QSize)));
+ gridSelectionDialog_->setCurrentGridSize(dynamicGrid_->getDimension());
+ gridSelectionDialog_->move(QCursor::pos());
+ connect(gridSelectionDialog_, SIGNAL(currentGridSizeChanged(QSize)), dynamicGrid_, SLOT(setDimensions(QSize)));
+ gridSelectionDialog_->show();
}
void QtChatTabs::storeTabPositions() {
- // save size
- QByteArray gridSizeData;
- QDataStream dataStreamGridSize(&gridSizeData, QIODevice::ReadWrite);
- dataStreamGridSize << dynamicGrid_->getDimension();
- settingsProvider_->storeSetting(SettingConstants::TRELLIS_GRID_SIZE, Q2PSTRING(QString(gridSizeData.toBase64())));
-
- // save positions
- QByteArray tabPositionsData;
- QDataStream dataStreamTabPositions(&tabPositionsData, QIODevice::ReadWrite);
- dynamicGrid_->updateTabPositions();
- dataStreamTabPositions << dynamicGrid_->getTabPositions();
- settingsProvider_->storeSetting(SettingConstants::TRELLIS_GRID_POSITIONS, Q2PSTRING(QString(tabPositionsData.toBase64())));
+ // save size
+ QByteArray gridSizeData;
+ QDataStream dataStreamGridSize(&gridSizeData, QIODevice::ReadWrite);
+ dataStreamGridSize << dynamicGrid_->getDimension();
+ settingsProvider_->storeSetting(SettingConstants::TRELLIS_GRID_SIZE, Q2PSTRING(QString(gridSizeData.toBase64())));
+
+ // save positions
+ QByteArray tabPositionsData;
+ QDataStream dataStreamTabPositions(&tabPositionsData, QIODevice::ReadWrite);
+ dynamicGrid_->updateTabPositions();
+ dataStreamTabPositions << dynamicGrid_->getTabPositions();
+ settingsProvider_->storeSetting(SettingConstants::TRELLIS_GRID_POSITIONS, Q2PSTRING(QString(tabPositionsData.toBase64())));
}
void QtChatTabs::resizeEvent(QResizeEvent*) {
- emit geometryChanged();
+ emit geometryChanged();
}
void QtChatTabs::moveEvent(QMoveEvent*) {
- emit geometryChanged();
+ emit geometryChanged();
}
void QtChatTabs::checkForFirstShow() {
- if (!isVisible()) {
+ if (!isVisible()) {
#ifndef Q_OS_MAC
- showMinimized();
+ showMinimized();
#else
- /* https://bugreports.qt-project.org/browse/QTBUG-19194
- * ^ When the above is fixed we can swap the below for just show();
- * WA_ShowWithoutActivating seems to helpfully not work, so... */
-
- QWidget* currentWindow = QApplication::activeWindow(); /* Remember who had focus if we're the current application*/
- show();
- QCoreApplication::processEvents(); /* Run through the eventloop to clear the show() */
- if (currentWindow) {
- currentWindow->activateWindow(); /* Set focus back */
- }
+ /* https://bugreports.qt-project.org/browse/QTBUG-19194
+ * ^ When the above is fixed we can swap the below for just show();
+ * WA_ShowWithoutActivating seems to helpfully not work, so... */
+
+ QWidget* currentWindow = QApplication::activeWindow(); /* Remember who had focus if we're the current application*/
+ show();
+ QCoreApplication::processEvents(); /* Run through the eventloop to clear the show() */
+ if (currentWindow) {
+ currentWindow->activateWindow(); /* Set focus back */
+ }
#endif
- }
+ }
}
}
diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h
index 8fcbf4a..0c12d96 100644
--- a/Swift/QtUI/QtChatTabs.h
+++ b/Swift/QtUI/QtChatTabs.h
@@ -16,62 +16,62 @@ class QTabWidget;
class QMenu;
namespace Swift {
- class SettingsProvider;
-
- class QtTabbable;
- class QtTabWidget;
- class QtDynamicGridLayout;
- class QtGridSelectionDialog;
-
- class QtChatTabs : public QWidget, public QtChatTabsBase {
- Q_OBJECT
- public:
- QtChatTabs(bool singleWindow, SettingsProvider* settingsProvider, bool trellisMode);
- virtual ~QtChatTabs();
-
- virtual void addTab(QtTabbable* tab);
- void minimise();
- QtTabbable* getCurrentTab();
- void setViewMenu(QMenu* viewMenu);
-
- signals:
- void geometryChanged();
- void onTitleChanged(const QString& title);
-
- protected slots:
- void closeEvent(QCloseEvent* event);
- void resizeEvent(QResizeEvent* event);
- void moveEvent(QMoveEvent* event);
-
- private slots:
- void handleCurrentTabIndexChanged(int newIndex);
- void handleTabClosing();
- void handleTabTitleUpdated();
- void handleTabTitleUpdated(QWidget* widget);
- void handleTabCloseRequested(int index);
- void handleWidgetShown();
- void handleWantsToActivate();
- void handleRequestedPreviousTab();
- void handleRequestedNextTab();
- void handleRequestedActiveTab();
- void flash();
-
- void handleOpenLayoutChangeDialog();
-
- void handleCloseTabShortcut();
-
- private:
- void storeTabPositions();
- void checkForFirstShow();
-
- private:
- bool singleWindow_;
- SettingsProvider* settingsProvider_;
- bool trellisMode_;
- QtDynamicGridLayout* dynamicGrid_;
- QtGridSelectionDialog* gridSelectionDialog_;
-
- QList<QShortcut*> shortcuts_;
- };
+ class SettingsProvider;
+
+ class QtTabbable;
+ class QtTabWidget;
+ class QtDynamicGridLayout;
+ class QtGridSelectionDialog;
+
+ class QtChatTabs : public QWidget, public QtChatTabsBase {
+ Q_OBJECT
+ public:
+ QtChatTabs(bool singleWindow, SettingsProvider* settingsProvider, bool trellisMode);
+ virtual ~QtChatTabs();
+
+ virtual void addTab(QtTabbable* tab);
+ void minimise();
+ QtTabbable* getCurrentTab();
+ void setViewMenu(QMenu* viewMenu);
+
+ signals:
+ void geometryChanged();
+ void onTitleChanged(const QString& title);
+
+ protected slots:
+ void closeEvent(QCloseEvent* event);
+ void resizeEvent(QResizeEvent* event);
+ void moveEvent(QMoveEvent* event);
+
+ private slots:
+ void handleCurrentTabIndexChanged(int newIndex);
+ void handleTabClosing();
+ void handleTabTitleUpdated();
+ void handleTabTitleUpdated(QWidget* widget);
+ void handleTabCloseRequested(int index);
+ void handleWidgetShown();
+ void handleWantsToActivate();
+ void handleRequestedPreviousTab();
+ void handleRequestedNextTab();
+ void handleRequestedActiveTab();
+ void flash();
+
+ void handleOpenLayoutChangeDialog();
+
+ void handleCloseTabShortcut();
+
+ private:
+ void storeTabPositions();
+ void checkForFirstShow();
+
+ private:
+ bool singleWindow_;
+ SettingsProvider* settingsProvider_;
+ bool trellisMode_;
+ QtDynamicGridLayout* dynamicGrid_;
+ QtGridSelectionDialog* gridSelectionDialog_;
+
+ QList<QShortcut*> shortcuts_;
+ };
}
diff --git a/Swift/QtUI/QtChatTabsBase.h b/Swift/QtUI/QtChatTabsBase.h
index 753b706..b49bb10 100644
--- a/Swift/QtUI/QtChatTabsBase.h
+++ b/Swift/QtUI/QtChatTabsBase.h
@@ -11,11 +11,11 @@ namespace Swift {
class QtTabbable;
class QtChatTabsBase {
- public:
- QtChatTabsBase();
- virtual ~QtChatTabsBase();
+ public:
+ QtChatTabsBase();
+ virtual ~QtChatTabsBase();
- virtual void addTab(QtTabbable* tab) = 0;
+ virtual void addTab(QtTabbable* tab) = 0;
};
}
diff --git a/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp b/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp
index 7f44177..2c064f8 100644
--- a/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp
+++ b/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp
@@ -27,82 +27,82 @@ QtChatTabsShortcutOnlySubstitute::~QtChatTabsShortcutOnlySubstitute() {
}
void QtChatTabsShortcutOnlySubstitute::addTab(QtTabbable* tab) {
- connect(tab, SIGNAL(requestNextTab()), this, SLOT(handleRequestedNextTab()), Qt::UniqueConnection);
- connect(tab, SIGNAL(requestActiveTab()), this, SLOT(handleRequestedActiveTab()), Qt::UniqueConnection);
- connect(tab, SIGNAL(requestPreviousTab()), this, SLOT(handleRequestedPreviousTab()), Qt::UniqueConnection);
-
- connect(new QShortcut(QKeySequence(tr("CTRL+W", "Close chat tab.")), tab), SIGNAL(activated()), this, SLOT(handleCloseTabShortcut()));
- connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), tab), SIGNAL(activated()), tab, SIGNAL(requestPreviousTab()));
- connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown), tab), SIGNAL(activated()), tab, SIGNAL(requestNextTab()));
- connect(new QShortcut(QKeySequence(Qt::ALT + Qt::Key_A), tab), SIGNAL(activated()), tab, SIGNAL(requestActiveTab()));
+ connect(tab, SIGNAL(requestNextTab()), this, SLOT(handleRequestedNextTab()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(requestActiveTab()), this, SLOT(handleRequestedActiveTab()), Qt::UniqueConnection);
+ connect(tab, SIGNAL(requestPreviousTab()), this, SLOT(handleRequestedPreviousTab()), Qt::UniqueConnection);
+
+ connect(new QShortcut(QKeySequence(tr("CTRL+W", "Close chat tab.")), tab), SIGNAL(activated()), this, SLOT(handleCloseTabShortcut()));
+ connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), tab), SIGNAL(activated()), tab, SIGNAL(requestPreviousTab()));
+ connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown), tab), SIGNAL(activated()), tab, SIGNAL(requestNextTab()));
+ connect(new QShortcut(QKeySequence(Qt::ALT + Qt::Key_A), tab), SIGNAL(activated()), tab, SIGNAL(requestActiveTab()));
}
void QtChatTabsShortcutOnlySubstitute::handleCloseTabShortcut() {
- QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender()->parent());
- SWIFT_LOG_ASSERT(senderTab, debug) << "No window to close." << std::endl;
- if (senderTab) {
- senderTab->close();
- }
+ QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender()->parent());
+ SWIFT_LOG_ASSERT(senderTab, debug) << "No window to close." << std::endl;
+ if (senderTab) {
+ senderTab->close();
+ }
}
void QtChatTabsShortcutOnlySubstitute::handleRequestedNextTab() {
- QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender());
+ QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender());
- QList<QtTabbable*> tabs = tabbableWindows();
+ QList<QtTabbable*> tabs = tabbableWindows();
- int currentIndex = tabs.indexOf(senderTab);
- assert(currentIndex >= 0);
+ int currentIndex = tabs.indexOf(senderTab);
+ assert(currentIndex >= 0);
- QtTabbable* nextTab = tabs.at((currentIndex + 1) % tabs.size());
- nextTab->activateWindow();
+ QtTabbable* nextTab = tabs.at((currentIndex + 1) % tabs.size());
+ nextTab->activateWindow();
}
void QtChatTabsShortcutOnlySubstitute::handleRequestedActiveTab() {
- QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender());
+ QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender());
- QtTabbable::AlertType types[] = {QtTabbable::WaitingActivity, QtTabbable::ImpendingActivity};
+ QtTabbable::AlertType types[] = {QtTabbable::WaitingActivity, QtTabbable::ImpendingActivity};
- QList<QtTabbable*> tabs = tabbableWindows();
+ QList<QtTabbable*> tabs = tabbableWindows();
- for (int j = 0; j < 2; j++) {
- int startIndex = tabs.indexOf(senderTab);
- int currentIndex = startIndex;
+ for (int j = 0; j < 2; j++) {
+ int startIndex = tabs.indexOf(senderTab);
+ int currentIndex = startIndex;
- do {
- currentIndex = (currentIndex + 1) % tabs.size();
- QtTabbable* currentTab = tabs.at(currentIndex);
- if (currentTab->getWidgetAlertState() == types[j]) {
- currentTab->activateWindow();
- return;
- }
- } while (startIndex != currentIndex);
- }
+ do {
+ currentIndex = (currentIndex + 1) % tabs.size();
+ QtTabbable* currentTab = tabs.at(currentIndex);
+ if (currentTab->getWidgetAlertState() == types[j]) {
+ currentTab->activateWindow();
+ return;
+ }
+ } while (startIndex != currentIndex);
+ }
}
void QtChatTabsShortcutOnlySubstitute::handleRequestedPreviousTab() {
- QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender());
+ QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender());
- QList<QtTabbable*> tabs = tabbableWindows();
+ QList<QtTabbable*> tabs = tabbableWindows();
- int currentIndex = tabs.indexOf(senderTab);
- assert(currentIndex >= 0);
+ int currentIndex = tabs.indexOf(senderTab);
+ assert(currentIndex >= 0);
- QtTabbable* previousTab = tabs.at((currentIndex + tabs.size() - 1) % tabs.size());
- previousTab->activateWindow();
+ QtTabbable* previousTab = tabs.at((currentIndex + tabs.size() - 1) % tabs.size());
+ previousTab->activateWindow();
}
QList<QtTabbable*> QtChatTabsShortcutOnlySubstitute::tabbableWindows() const {
- QList<QWidget*> windows = qApp->topLevelWidgets();
+ QList<QWidget*> windows = qApp->topLevelWidgets();
- QList<QtTabbable*> tabbables;
- foreach(QWidget* topLevelWidget, windows) {
- QtTabbable* tabbable = dynamic_cast<QtTabbable*>(topLevelWidget);
- if (tabbable) {
- tabbables << tabbable;
- }
- }
+ QList<QtTabbable*> tabbables;
+ foreach(QWidget* topLevelWidget, windows) {
+ QtTabbable* tabbable = dynamic_cast<QtTabbable*>(topLevelWidget);
+ if (tabbable) {
+ tabbables << tabbable;
+ }
+ }
- return tabbables;
+ return tabbables;
}
}
diff --git a/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.h b/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.h
index 80af008..b330fe7 100644
--- a/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.h
+++ b/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.h
@@ -16,25 +16,25 @@ class QShortcut;
namespace Swift {
class QtChatTabsShortcutOnlySubstitute : public QWidget, public QtChatTabsBase {
- Q_OBJECT
+ Q_OBJECT
- public:
- QtChatTabsShortcutOnlySubstitute();
- virtual ~QtChatTabsShortcutOnlySubstitute();
+ public:
+ QtChatTabsShortcutOnlySubstitute();
+ virtual ~QtChatTabsShortcutOnlySubstitute();
- virtual void addTab(QtTabbable* tab);
+ virtual void addTab(QtTabbable* tab);
- private slots:
- void handleCloseTabShortcut();
- void handleRequestedNextTab();
- void handleRequestedActiveTab();
- void handleRequestedPreviousTab();
+ private slots:
+ void handleCloseTabShortcut();
+ void handleRequestedNextTab();
+ void handleRequestedActiveTab();
+ void handleRequestedPreviousTab();
- private:
- QList<QtTabbable*> tabbableWindows() const;
+ private:
+ QList<QtTabbable*> tabbableWindows() const;
- private:
- QList<QShortcut*> shortcuts_;
+ private:
+ QList<QShortcut*> shortcuts_;
};
}
diff --git a/Swift/QtUI/QtChatTheme.cpp b/Swift/QtUI/QtChatTheme.cpp
index a7628d9..e73f8ac 100644
--- a/Swift/QtUI/QtChatTheme.cpp
+++ b/Swift/QtUI/QtChatTheme.cpp
@@ -14,58 +14,58 @@ namespace Swift {
* Load Adium themes, as http://trac.adium.im/wiki/CreatingMessageStyles
*/
QtChatTheme::QtChatTheme(const QString& themePath) : qrc_(themePath[0] == ':'), themePath_(qrc_ ? themePath : themePath + "/Contents/Resources/") {
- QString fileNames[EndMarker];
- fileNames[Header] = "Header.html";
- fileNames[Footer] = "Footer.html";
- fileNames[Content] = "Content.html";
- fileNames[Status] = "Status.html";
- fileNames[Topic] = "Topic.html";
- fileNames[FileTransferRequest] = "FileTransferRequest.html";
- fileNames[IncomingContent] = "Incoming/Content.html";
- fileNames[IncomingNextContent] = "Incoming/NextContent.html";
- fileNames[IncomingContext] = "Incoming/Context.html";
- fileNames[IncomingNextContext] = "Incoming/NextContext.html";
- fileNames[OutgoingContent] = "Outgoing/Content.html";
- fileNames[OutgoingNextContent] = "Outgoing/NextContent.html";
- fileNames[OutgoingContext] = "Outgoing/Context.html";
- fileNames[OutgoingNextContext] = "Outgoing/NextContext.html";
- fileNames[Template] = "Template.html";
- fileNames[MainCSS] = "main.css";
- fileNames[Unread] = "Unread.html";
- fileNames[TemplateDefault] = ":/themes/Template.html";
- for (int i = 0; i < EndMarker; i++) {
- QString source;
- QFile sourceFile((i != TemplateDefault ? themePath_ : "") + fileNames[i]);
- if (sourceFile.exists() && sourceFile.open(QIODevice::ReadOnly)) {
- source = sourceFile.readAll();
- sourceFile.close();
- } else {
- //qWarning() << "Couldn't load file " << sourceFile.fileName();
- }
- fileContents_.append(source);
- }
+ QString fileNames[EndMarker];
+ fileNames[Header] = "Header.html";
+ fileNames[Footer] = "Footer.html";
+ fileNames[Content] = "Content.html";
+ fileNames[Status] = "Status.html";
+ fileNames[Topic] = "Topic.html";
+ fileNames[FileTransferRequest] = "FileTransferRequest.html";
+ fileNames[IncomingContent] = "Incoming/Content.html";
+ fileNames[IncomingNextContent] = "Incoming/NextContent.html";
+ fileNames[IncomingContext] = "Incoming/Context.html";
+ fileNames[IncomingNextContext] = "Incoming/NextContext.html";
+ fileNames[OutgoingContent] = "Outgoing/Content.html";
+ fileNames[OutgoingNextContent] = "Outgoing/NextContent.html";
+ fileNames[OutgoingContext] = "Outgoing/Context.html";
+ fileNames[OutgoingNextContext] = "Outgoing/NextContext.html";
+ fileNames[Template] = "Template.html";
+ fileNames[MainCSS] = "main.css";
+ fileNames[Unread] = "Unread.html";
+ fileNames[TemplateDefault] = ":/themes/Template.html";
+ for (int i = 0; i < EndMarker; i++) {
+ QString source;
+ QFile sourceFile((i != TemplateDefault ? themePath_ : "") + fileNames[i]);
+ if (sourceFile.exists() && sourceFile.open(QIODevice::ReadOnly)) {
+ source = sourceFile.readAll();
+ sourceFile.close();
+ } else {
+ //qWarning() << "Couldn't load file " << sourceFile.fileName();
+ }
+ fileContents_.append(source);
+ }
- /* Fallbacks */
- if (fileContents_[Template].isEmpty()) fileContents_[Template] = fileContents_[TemplateDefault];
- if (fileContents_[Status].isEmpty()) fileContents_[Status] = fileContents_[Content];
- if (fileContents_[IncomingContent].isEmpty()) fileContents_[IncomingContent] = fileContents_[Content];
- if (fileContents_[IncomingNextContent].isEmpty()) fileContents_[IncomingNextContent] = fileContents_[IncomingContent];
- if (fileContents_[FileTransferRequest].isEmpty()) fileContents_[FileTransferRequest] = fileContents_[Status];
- if (fileContents_[IncomingContext].isEmpty()) fileContents_[IncomingContext] = fileContents_[IncomingContent];
- if (fileContents_[IncomingNextContext].isEmpty()) fileContents_[IncomingNextContext] = fileContents_[IncomingNextContent];
- if (fileContents_[OutgoingContent].isEmpty()) fileContents_[OutgoingContent] = fileContents_[IncomingContent];
- if (fileContents_[OutgoingContext].isEmpty()) fileContents_[OutgoingContext] = fileContents_[OutgoingContent];
- if (fileContents_[OutgoingNextContent].isEmpty()) fileContents_[OutgoingNextContent] = fileContents_[OutgoingContent];
- if (fileContents_[OutgoingNextContext].isEmpty()) fileContents_[OutgoingNextContext] = fileContents_[OutgoingNextContent];
+ /* Fallbacks */
+ if (fileContents_[Template].isEmpty()) fileContents_[Template] = fileContents_[TemplateDefault];
+ if (fileContents_[Status].isEmpty()) fileContents_[Status] = fileContents_[Content];
+ if (fileContents_[IncomingContent].isEmpty()) fileContents_[IncomingContent] = fileContents_[Content];
+ if (fileContents_[IncomingNextContent].isEmpty()) fileContents_[IncomingNextContent] = fileContents_[IncomingContent];
+ if (fileContents_[FileTransferRequest].isEmpty()) fileContents_[FileTransferRequest] = fileContents_[Status];
+ if (fileContents_[IncomingContext].isEmpty()) fileContents_[IncomingContext] = fileContents_[IncomingContent];
+ if (fileContents_[IncomingNextContext].isEmpty()) fileContents_[IncomingNextContext] = fileContents_[IncomingNextContent];
+ if (fileContents_[OutgoingContent].isEmpty()) fileContents_[OutgoingContent] = fileContents_[IncomingContent];
+ if (fileContents_[OutgoingContext].isEmpty()) fileContents_[OutgoingContext] = fileContents_[OutgoingContent];
+ if (fileContents_[OutgoingNextContent].isEmpty()) fileContents_[OutgoingNextContent] = fileContents_[OutgoingContent];
+ if (fileContents_[OutgoingNextContext].isEmpty()) fileContents_[OutgoingNextContext] = fileContents_[OutgoingNextContent];
}
QString QtChatTheme::getBase() const {
- return qrc_ ? "qrc" + themePath_ : "file://" + themePath_;
+ return qrc_ ? "qrc" + themePath_ : "file://" + themePath_;
}
QString QtChatTheme::getUnread() const {
- return fileContents_[Unread].isEmpty() ? "<hr/>" : fileContents_[Unread];
+ return fileContents_[Unread].isEmpty() ? "<hr/>" : fileContents_[Unread];
}
}
diff --git a/Swift/QtUI/QtChatTheme.h b/Swift/QtUI/QtChatTheme.h
index 2997de0..8db662f 100644
--- a/Swift/QtUI/QtChatTheme.h
+++ b/Swift/QtUI/QtChatTheme.h
@@ -10,32 +10,32 @@
#include <QString>
namespace Swift {
- class QtChatTheme {
- public:
- QtChatTheme(const QString& themePath);
- QString getHeader() const {return fileContents_[Header];}
- QString getFooter() const {return fileContents_[Footer];}
- QString getContent() const {return fileContents_[Content];}
- QString getStatus() const {return fileContents_[Status];}
- QString getTopic() const {return fileContents_[Topic];}
- QString getFileTransferRequest() const {return fileContents_[FileTransferRequest];}
- QString getIncomingContent() const {return fileContents_[IncomingContent];}
- QString getIncomingNextContent() const {return fileContents_[IncomingNextContent];}
- QString getIncomingContext() const {return fileContents_[IncomingContext];}
- QString getIncomingNextContext() const {return fileContents_[IncomingNextContext];}
- QString getOutgoingContent() const {return fileContents_[OutgoingContent];}
- QString getOutgoingNextContent() const {return fileContents_[OutgoingNextContent];}
- QString getOutgoingContext() const {return fileContents_[OutgoingContext];}
- QString getOutgoingNextContext() const {return fileContents_[OutgoingNextContext];}
- QString getTemplate() const {return fileContents_[Template];}
- QString getMainCSS() const {return fileContents_[MainCSS];}
- QString getBase() const;
- QString getUnread() const;
+ class QtChatTheme {
+ public:
+ QtChatTheme(const QString& themePath);
+ QString getHeader() const {return fileContents_[Header];}
+ QString getFooter() const {return fileContents_[Footer];}
+ QString getContent() const {return fileContents_[Content];}
+ QString getStatus() const {return fileContents_[Status];}
+ QString getTopic() const {return fileContents_[Topic];}
+ QString getFileTransferRequest() const {return fileContents_[FileTransferRequest];}
+ QString getIncomingContent() const {return fileContents_[IncomingContent];}
+ QString getIncomingNextContent() const {return fileContents_[IncomingNextContent];}
+ QString getIncomingContext() const {return fileContents_[IncomingContext];}
+ QString getIncomingNextContext() const {return fileContents_[IncomingNextContext];}
+ QString getOutgoingContent() const {return fileContents_[OutgoingContent];}
+ QString getOutgoingNextContent() const {return fileContents_[OutgoingNextContent];}
+ QString getOutgoingContext() const {return fileContents_[OutgoingContext];}
+ QString getOutgoingNextContext() const {return fileContents_[OutgoingNextContext];}
+ QString getTemplate() const {return fileContents_[Template];}
+ QString getMainCSS() const {return fileContents_[MainCSS];}
+ QString getBase() const;
+ QString getUnread() const;
- private:
- enum files {Header = 0, Footer, Content, Status, Topic, FileTransferRequest, IncomingContent, IncomingNextContent, IncomingContext, IncomingNextContext, OutgoingContent, OutgoingNextContent, OutgoingContext, OutgoingNextContext, Template, MainCSS, TemplateDefault, Unread, /*Must be last!*/EndMarker};
- bool qrc_;
- QList<QString> fileContents_;
- QString themePath_;
- };
+ private:
+ enum files {Header = 0, Footer, Content, Status, Topic, FileTransferRequest, IncomingContent, IncomingNextContent, IncomingContext, IncomingNextContext, OutgoingContent, OutgoingNextContent, OutgoingContext, OutgoingNextContext, Template, MainCSS, TemplateDefault, Unread, /*Must be last!*/EndMarker};
+ bool qrc_;
+ QList<QString> fileContents_;
+ QString themePath_;
+ };
}
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 05366c1..6d9a17d 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -13,7 +13,7 @@ QtChatView::QtChatView(QWidget* parent) : QWidget(parent) {
}
QtChatView::~QtChatView() {
-
+
}
}
diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h
index 9f0df44..cca3bdf 100644
--- a/Swift/QtUI/QtChatView.h
+++ b/Swift/QtUI/QtChatView.h
@@ -16,49 +16,49 @@
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
namespace Swift {
- class HighlightAction;
- class SecurityLabel;
+ class HighlightAction;
+ class SecurityLabel;
- class QtChatView : public QWidget {
- Q_OBJECT
- public:
- QtChatView(QWidget* parent);
- virtual ~QtChatView();
+ class QtChatView : public QWidget {
+ Q_OBJECT
+ public:
+ QtChatView(QWidget* parent);
+ virtual ~QtChatView();
- /** Add message to window.
- * @return id of added message (for acks).
- */
- virtual std::string addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0;
- /** Adds action to window.
- * @return id of added message (for acks);
- */
- virtual std::string addAction(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0;
+ /** Add message to window.
+ * @return id of added message (for acks).
+ */
+ virtual std::string addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0;
+ /** Adds action to window.
+ * @return id of added message (for acks);
+ */
+ virtual std::string addAction(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0;
- virtual std::string addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) = 0;
- virtual void addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) = 0;
+ virtual std::string addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) = 0;
+ virtual void addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) = 0;
- virtual void addErrorMessage(const ChatWindow::ChatMessage& message) = 0;
- virtual void replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) = 0;
- virtual void replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/) = 0;
- virtual void replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) = 0;
- virtual void replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/) = 0;
- virtual void setAckState(const std::string& id, ChatWindow::AckState state) = 0;
-
- virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) = 0;
- virtual void setFileTransferProgress(std::string, const int percentageDone) = 0;
- virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState state, const std::string& msg = "") = 0;
- virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) = 0;
- virtual std::string addWhiteboardRequest(const QString& contact, bool senderIsSelf) = 0;
- virtual void setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) = 0;
- virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) = 0;
+ virtual void addErrorMessage(const ChatWindow::ChatMessage& message) = 0;
+ virtual void replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) = 0;
+ virtual void replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/) = 0;
+ virtual void replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) = 0;
+ virtual void replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/) = 0;
+ virtual void setAckState(const std::string& id, ChatWindow::AckState state) = 0;
- virtual void showEmoticons(bool show) = 0;
- virtual void addLastSeenLine() = 0;
+ virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) = 0;
+ virtual void setFileTransferProgress(std::string, const int percentageDone) = 0;
+ virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState state, const std::string& msg = "") = 0;
+ virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) = 0;
+ virtual std::string addWhiteboardRequest(const QString& contact, bool senderIsSelf) = 0;
+ virtual void setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) = 0;
+ virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) = 0;
- public slots:
- virtual void resizeFont(int fontSizeSteps) = 0;
- virtual void scrollToBottom() = 0;
- virtual void handleKeyPressEvent(QKeyEvent* event) = 0;
+ virtual void showEmoticons(bool show) = 0;
+ virtual void addLastSeenLine() = 0;
- };
+ public slots:
+ virtual void resizeFont(int fontSizeSteps) = 0;
+ virtual void scrollToBottom() = 0;
+ virtual void handleKeyPressEvent(QKeyEvent* event) = 0;
+
+ };
}
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 7649256..95d643c 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -62,883 +62,883 @@
namespace Swift {
QtChatWindow::QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventStream* eventStream, SettingsProvider* settings, const std::map<std::string, std::string>& emoticons) : QtTabbable(), id_(Q2PSTRING(contact)), contact_(contact), nextAlertId_(0), eventStream_(eventStream), blockingState_(BlockingUnsupported), isMUC_(false), supportsImpromptuChat_(false), roomBookmarkState_(RoomNotBookmarked) {
- settings_ = settings;
- unreadCount_ = 0;
- isOnline_ = true;
- completer_ = NULL;
- affiliationEditor_ = NULL;
- theme_ = theme;
- isCorrection_ = false;
- labelModel_ = NULL;
- correctionEnabled_ = Maybe;
- fileTransferEnabled_ = Maybe;
- updateTitleWithUnreadCount();
- assert(settings);
- setAcceptDrops(true);
-
- alertStyleSheet_ = ".QWidget, QTextEdit { background: rgb(255, 255, 153); color: black }";
-
- QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
- layout->setContentsMargins(0,0,0,0);
- layout->setSpacing(2);
-
- alertLayout_ = new QVBoxLayout();
- layout->addLayout(alertLayout_);
-
- subjectLayout_ = new QBoxLayout(QBoxLayout::LeftToRight);
- subject_ = new QLineEdit(this);
- subjectLayout_->addWidget(subject_);
- setSubject("");
- subject_->setReadOnly(true);
-
- QPushButton* actionButton_ = new QPushButton(this);
- actionButton_->setIcon(QIcon(":/icons/actions.png"));
- connect(actionButton_, SIGNAL(clicked()), this, SLOT(handleActionButtonClicked()));
- subject_->hide();
-
- layout->addLayout(subjectLayout_);
-
- logRosterSplitter_ = new QSplitter(this);
- logRosterSplitter_->setAutoFillBackground(true);
- layout->addWidget(logRosterSplitter_);
- if (settings_->getSetting(QtUISettingConstants::USE_PLAIN_CHATS) || settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)) {
- messageLog_ = new QtPlainChatView(this, eventStream_);
- }
- else {
- messageLog_ = new QtWebKitChatView(this, eventStream_, theme, this); // I accept that passing the ChatWindow in so that the view can call the signals is somewhat inelegant, but it saves a lot of boilerplate. This patch is unpleasant enough already. So let's fix this soon (it at least needs fixing by the time history is sorted), but not now.
- }
- logRosterSplitter_->addWidget(messageLog_);
-
- treeWidget_ = new QtOccupantListWidget(eventStream_, settings_, QtTreeWidget::MessageDefaultJID, this);
- treeWidget_->hide();
- logRosterSplitter_->addWidget(treeWidget_);
- logRosterSplitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- connect(logRosterSplitter_, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int)));
-
- midBar_ = new QWidget(this);
- //layout->addWidget(midBar);
- midBar_->setAutoFillBackground(true);
- QHBoxLayout *midBarLayout = new QHBoxLayout(midBar_);
- midBarLayout->setContentsMargins(0,0,0,0);
- midBarLayout->setSpacing(2);
- //midBarLayout->addStretch();
-
- labelsWidget_ = new QComboBox(this);
- labelsWidget_->setFocusPolicy(Qt::NoFocus);
- labelsWidget_->hide();
- labelsWidget_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
- midBarLayout->addWidget(labelsWidget_,0);
- connect(labelsWidget_, SIGNAL(currentIndexChanged(int)), this, SLOT(handleCurrentLabelChanged(int)));
- defaultLabelsPalette_ = labelsWidget_->palette();
-
- QHBoxLayout* inputBarLayout = new QHBoxLayout();
- inputBarLayout->setContentsMargins(0,0,0,0);
- inputBarLayout->setSpacing(2);
- input_ = new QtTextEdit(settings_, this);
- input_->setAcceptRichText(false);
- inputBarLayout->addWidget(midBar_);
- inputBarLayout->addWidget(input_);
- correctingLabel_ = new QLabel(tr("Correcting"), this);
- inputBarLayout->addWidget(correctingLabel_);
- correctingLabel_->hide();
-
- connect(input_, SIGNAL(receivedFocus()), this, SLOT(handleTextInputReceivedFocus()));
- connect(input_, SIGNAL(lostFocus()), this, SLOT(handleTextInputLostFocus()));
- QPushButton* emoticonsButton_ = new QPushButton(this);
- emoticonsButton_->setIcon(QIcon(":/emoticons/smile.png"));
- connect(emoticonsButton_, SIGNAL(clicked()), this, SLOT(handleEmoticonsButtonClicked()));
-
- emoticonsMenu_ = new QMenu(this);
- QtEmoticonsGrid* emoticonsGrid = new QtEmoticonsGrid(emoticons, emoticonsMenu_);
- connect(emoticonsGrid, SIGNAL(emoticonClicked(QString)), this, SLOT(handleEmoticonClicked(QString)));
-
- // using an extra layout to work around Qt margin glitches on OS X
- QHBoxLayout* actionLayout = new QHBoxLayout();
- actionLayout->addWidget(emoticonsButton_);
- actionLayout->addWidget(actionButton_);
-
- inputBarLayout->addLayout(actionLayout);
- layout->addLayout(inputBarLayout);
-
- inputClearing_ = false;
- contactIsTyping_ = false;
- tabCompletion_ = false;
-
- connect(input_, SIGNAL(unhandledKeyPressEvent(QKeyEvent*)), this, SLOT(handleKeyPressEvent(QKeyEvent*)));
- connect(input_, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
- connect(input_, SIGNAL(textChanged()), this, SLOT(handleInputChanged()));
- connect(input_, SIGNAL(cursorPositionChanged()), this, SLOT(handleCursorPositionChanged()));
- setFocusProxy(input_);
- logRosterSplitter_->setFocusProxy(input_);
- midBar_->setFocusProxy(input_);
- messageLog_->setFocusProxy(input_);
- connect(messageLog_, SIGNAL(gotFocus()), input_, SLOT(setFocus()));
- resize(400,300);
- connect(messageLog_, SIGNAL(fontResized(int)), this, SIGNAL(fontResized(int)));
- connect(messageLog_, SIGNAL(logCleared()), this, SLOT(handleLogCleared()));
-
- treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QtChatWindow::handleOccupantSelectionChanged, this, _1));
- treeWidget_->onOccupantActionSelected.connect(boost::bind(boost::ref(onOccupantActionSelected), _1, _2));
-
- settings_->onSettingChanged.connect(boost::bind(&QtChatWindow::handleSettingChanged, this, _1));
- messageLog_->showEmoticons(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
- setMinimumSize(100, 100);
+ settings_ = settings;
+ unreadCount_ = 0;
+ isOnline_ = true;
+ completer_ = NULL;
+ affiliationEditor_ = NULL;
+ theme_ = theme;
+ isCorrection_ = false;
+ labelModel_ = NULL;
+ correctionEnabled_ = Maybe;
+ fileTransferEnabled_ = Maybe;
+ updateTitleWithUnreadCount();
+ assert(settings);
+ setAcceptDrops(true);
+
+ alertStyleSheet_ = ".QWidget, QTextEdit { background: rgb(255, 255, 153); color: black }";
+
+ QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+ layout->setContentsMargins(0,0,0,0);
+ layout->setSpacing(2);
+
+ alertLayout_ = new QVBoxLayout();
+ layout->addLayout(alertLayout_);
+
+ subjectLayout_ = new QBoxLayout(QBoxLayout::LeftToRight);
+ subject_ = new QLineEdit(this);
+ subjectLayout_->addWidget(subject_);
+ setSubject("");
+ subject_->setReadOnly(true);
+
+ QPushButton* actionButton_ = new QPushButton(this);
+ actionButton_->setIcon(QIcon(":/icons/actions.png"));
+ connect(actionButton_, SIGNAL(clicked()), this, SLOT(handleActionButtonClicked()));
+ subject_->hide();
+
+ layout->addLayout(subjectLayout_);
+
+ logRosterSplitter_ = new QSplitter(this);
+ logRosterSplitter_->setAutoFillBackground(true);
+ layout->addWidget(logRosterSplitter_);
+ if (settings_->getSetting(QtUISettingConstants::USE_PLAIN_CHATS) || settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)) {
+ messageLog_ = new QtPlainChatView(this, eventStream_);
+ }
+ else {
+ messageLog_ = new QtWebKitChatView(this, eventStream_, theme, this); // I accept that passing the ChatWindow in so that the view can call the signals is somewhat inelegant, but it saves a lot of boilerplate. This patch is unpleasant enough already. So let's fix this soon (it at least needs fixing by the time history is sorted), but not now.
+ }
+ logRosterSplitter_->addWidget(messageLog_);
+
+ treeWidget_ = new QtOccupantListWidget(eventStream_, settings_, QtTreeWidget::MessageDefaultJID, this);
+ treeWidget_->hide();
+ logRosterSplitter_->addWidget(treeWidget_);
+ logRosterSplitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ connect(logRosterSplitter_, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int)));
+
+ midBar_ = new QWidget(this);
+ //layout->addWidget(midBar);
+ midBar_->setAutoFillBackground(true);
+ QHBoxLayout *midBarLayout = new QHBoxLayout(midBar_);
+ midBarLayout->setContentsMargins(0,0,0,0);
+ midBarLayout->setSpacing(2);
+ //midBarLayout->addStretch();
+
+ labelsWidget_ = new QComboBox(this);
+ labelsWidget_->setFocusPolicy(Qt::NoFocus);
+ labelsWidget_->hide();
+ labelsWidget_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+ midBarLayout->addWidget(labelsWidget_,0);
+ connect(labelsWidget_, SIGNAL(currentIndexChanged(int)), this, SLOT(handleCurrentLabelChanged(int)));
+ defaultLabelsPalette_ = labelsWidget_->palette();
+
+ QHBoxLayout* inputBarLayout = new QHBoxLayout();
+ inputBarLayout->setContentsMargins(0,0,0,0);
+ inputBarLayout->setSpacing(2);
+ input_ = new QtTextEdit(settings_, this);
+ input_->setAcceptRichText(false);
+ inputBarLayout->addWidget(midBar_);
+ inputBarLayout->addWidget(input_);
+ correctingLabel_ = new QLabel(tr("Correcting"), this);
+ inputBarLayout->addWidget(correctingLabel_);
+ correctingLabel_->hide();
+
+ connect(input_, SIGNAL(receivedFocus()), this, SLOT(handleTextInputReceivedFocus()));
+ connect(input_, SIGNAL(lostFocus()), this, SLOT(handleTextInputLostFocus()));
+ QPushButton* emoticonsButton_ = new QPushButton(this);
+ emoticonsButton_->setIcon(QIcon(":/emoticons/smile.png"));
+ connect(emoticonsButton_, SIGNAL(clicked()), this, SLOT(handleEmoticonsButtonClicked()));
+
+ emoticonsMenu_ = new QMenu(this);
+ QtEmoticonsGrid* emoticonsGrid = new QtEmoticonsGrid(emoticons, emoticonsMenu_);
+ connect(emoticonsGrid, SIGNAL(emoticonClicked(QString)), this, SLOT(handleEmoticonClicked(QString)));
+
+ // using an extra layout to work around Qt margin glitches on OS X
+ QHBoxLayout* actionLayout = new QHBoxLayout();
+ actionLayout->addWidget(emoticonsButton_);
+ actionLayout->addWidget(actionButton_);
+
+ inputBarLayout->addLayout(actionLayout);
+ layout->addLayout(inputBarLayout);
+
+ inputClearing_ = false;
+ contactIsTyping_ = false;
+ tabCompletion_ = false;
+
+ connect(input_, SIGNAL(unhandledKeyPressEvent(QKeyEvent*)), this, SLOT(handleKeyPressEvent(QKeyEvent*)));
+ connect(input_, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
+ connect(input_, SIGNAL(textChanged()), this, SLOT(handleInputChanged()));
+ connect(input_, SIGNAL(cursorPositionChanged()), this, SLOT(handleCursorPositionChanged()));
+ setFocusProxy(input_);
+ logRosterSplitter_->setFocusProxy(input_);
+ midBar_->setFocusProxy(input_);
+ messageLog_->setFocusProxy(input_);
+ connect(messageLog_, SIGNAL(gotFocus()), input_, SLOT(setFocus()));
+ resize(400,300);
+ connect(messageLog_, SIGNAL(fontResized(int)), this, SIGNAL(fontResized(int)));
+ connect(messageLog_, SIGNAL(logCleared()), this, SLOT(handleLogCleared()));
+
+ treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QtChatWindow::handleOccupantSelectionChanged, this, _1));
+ treeWidget_->onOccupantActionSelected.connect(boost::bind(boost::ref(onOccupantActionSelected), _1, _2));
+
+ settings_->onSettingChanged.connect(boost::bind(&QtChatWindow::handleSettingChanged, this, _1));
+ messageLog_->showEmoticons(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
+ setMinimumSize(100, 100);
}
QtChatWindow::~QtChatWindow() {
- settings_->onSettingChanged.disconnect(boost::bind(&QtChatWindow::handleSettingChanged, this, _1));
- if (mucConfigurationWindow_) {
- delete mucConfigurationWindow_.data();
- }
+ settings_->onSettingChanged.disconnect(boost::bind(&QtChatWindow::handleSettingChanged, this, _1));
+ if (mucConfigurationWindow_) {
+ delete mucConfigurationWindow_.data();
+ }
}
void QtChatWindow::handleSettingChanged(const std::string& setting) {
- if (setting == QtUISettingConstants::SHOW_EMOTICONS.getKey()) {
- bool showEmoticons = settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS);
- messageLog_->showEmoticons(showEmoticons);
- }
+ if (setting == QtUISettingConstants::SHOW_EMOTICONS.getKey()) {
+ bool showEmoticons = settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS);
+ messageLog_->showEmoticons(showEmoticons);
+ }
}
void QtChatWindow::handleLogCleared() {
- onLogCleared();
+ onLogCleared();
}
void QtChatWindow::handleOccupantSelectionChanged(RosterItem* item) {
- onOccupantSelectionChanged(dynamic_cast<ContactRosterItem*>(item));
+ onOccupantSelectionChanged(dynamic_cast<ContactRosterItem*>(item));
}
void QtChatWindow::handleFontResized(int fontSizeSteps) {
- messageLog_->resizeFont(fontSizeSteps);
+ messageLog_->resizeFont(fontSizeSteps);
}
void QtChatWindow::handleAlertButtonClicked() {
- const QObject* alertWidget = QObject::sender()->parent();
- std::map<AlertID, QWidget*>::const_iterator i = alertWidgets_.begin();
- for ( ; i != alertWidgets_.end(); ++i) {
- if (i->second == alertWidget) {
- removeAlert(i->first);
- break;
- }
- }
+ const QObject* alertWidget = QObject::sender()->parent();
+ std::map<AlertID, QWidget*>::const_iterator i = alertWidgets_.begin();
+ for ( ; i != alertWidgets_.end(); ++i) {
+ if (i->second == alertWidget) {
+ removeAlert(i->first);
+ break;
+ }
+ }
}
QtChatWindow::AlertID QtChatWindow::addAlert(const std::string& alertText) {
- QWidget* alertWidget = new QWidget(this);
- QHBoxLayout* alertLayout = new QHBoxLayout(alertWidget);
- alertLayout_->addWidget(alertWidget);
- QLabel* alertLabel = new QLabel(this);
- alertLabel->setText(alertText.c_str());
- alertLayout->addWidget(alertLabel);
-
- QToolButton* closeButton = new QToolButton(alertWidget);
- closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
- closeButton->setIconSize(QSize(16,16));
- closeButton->setCursor(Qt::ArrowCursor);
- closeButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
- connect (closeButton, SIGNAL(clicked()), this, SLOT(handleAlertButtonClicked()));
-
- alertLayout->addWidget(closeButton);
- QPalette palette = alertWidget->palette();
- palette.setColor(QPalette::Window, QColor(Qt::yellow));
- palette.setColor(QPalette::WindowText, QColor(Qt::black));
- alertWidget->setStyleSheet(alertStyleSheet_);
- alertLabel->setStyleSheet(alertStyleSheet_);
-
- AlertID id = nextAlertId_++;
- alertWidgets_[id] = alertWidget;
- return id;
+ QWidget* alertWidget = new QWidget(this);
+ QHBoxLayout* alertLayout = new QHBoxLayout(alertWidget);
+ alertLayout_->addWidget(alertWidget);
+ QLabel* alertLabel = new QLabel(this);
+ alertLabel->setText(alertText.c_str());
+ alertLayout->addWidget(alertLabel);
+
+ QToolButton* closeButton = new QToolButton(alertWidget);
+ closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
+ closeButton->setIconSize(QSize(16,16));
+ closeButton->setCursor(Qt::ArrowCursor);
+ closeButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
+ connect (closeButton, SIGNAL(clicked()), this, SLOT(handleAlertButtonClicked()));
+
+ alertLayout->addWidget(closeButton);
+ QPalette palette = alertWidget->palette();
+ palette.setColor(QPalette::Window, QColor(Qt::yellow));
+ palette.setColor(QPalette::WindowText, QColor(Qt::black));
+ alertWidget->setStyleSheet(alertStyleSheet_);
+ alertLabel->setStyleSheet(alertStyleSheet_);
+
+ AlertID id = nextAlertId_++;
+ alertWidgets_[id] = alertWidget;
+ return id;
}
void QtChatWindow::removeAlert(const AlertID id) {
- std::map<AlertID, QWidget*>::iterator i = alertWidgets_.find(id);
- if (i != alertWidgets_.end()) {
- alertLayout_->removeWidget(i->second);
- delete i->second;
- alertWidgets_.erase(i);
- }
+ std::map<AlertID, QWidget*>::iterator i = alertWidgets_.find(id);
+ if (i != alertWidgets_.end()) {
+ alertLayout_->removeWidget(i->second);
+ delete i->second;
+ alertWidgets_.erase(i);
+ }
}
void QtChatWindow::setTabComplete(TabComplete* completer) {
- completer_ = completer;
+ completer_ = completer;
}
void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
- event->ignore();
- if (event->isAccepted()) {
- return;
- }
- event->accept();
-
- int key = event->key();
- if (key == Qt::Key_Tab) {
- tabComplete();
- }
- else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) {
- beginCorrection();
- }
- else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) {
- cancelCorrection();
- }
- else if (key == Qt::Key_Down || key == Qt::Key_Up) {
- event->ignore();
- }
- else {
- messageLog_->handleKeyPressEvent(event);
- }
+ event->ignore();
+ if (event->isAccepted()) {
+ return;
+ }
+ event->accept();
+
+ int key = event->key();
+ if (key == Qt::Key_Tab) {
+ tabComplete();
+ }
+ else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) {
+ beginCorrection();
+ }
+ else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) {
+ cancelCorrection();
+ }
+ else if (key == Qt::Key_Down || key == Qt::Key_Up) {
+ event->ignore();
+ }
+ else {
+ messageLog_->handleKeyPressEvent(event);
+ }
}
void QtChatWindow::beginCorrection() {
- boost::optional<AlertID> newCorrectingAlert;
- if (correctionEnabled_ == Maybe) {
- newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message")));
- }
- else if (correctionEnabled_ == No) {
- newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message")));
- }
-
- if (newCorrectingAlert) {
- if (correctingAlert_) {
- removeAlert(*correctingAlert_);
- }
- correctingAlert_ = newCorrectingAlert;
- }
-
- QTextCursor cursor = input_->textCursor();
- cursor.select(QTextCursor::Document);
- cursor.beginEditBlock();
- cursor.insertText(QString(lastSentMessage_));
- cursor.endEditBlock();
- isCorrection_ = true;
- correctingLabel_->show();
- input_->setStyleSheet(alertStyleSheet_);
- labelsWidget_->setEnabled(false);
+ boost::optional<AlertID> newCorrectingAlert;
+ if (correctionEnabled_ == Maybe) {
+ newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message")));
+ }
+ else if (correctionEnabled_ == No) {
+ newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message")));
+ }
+
+ if (newCorrectingAlert) {
+ if (correctingAlert_) {
+ removeAlert(*correctingAlert_);
+ }
+ correctingAlert_ = newCorrectingAlert;
+ }
+
+ QTextCursor cursor = input_->textCursor();
+ cursor.select(QTextCursor::Document);
+ cursor.beginEditBlock();
+ cursor.insertText(QString(lastSentMessage_));
+ cursor.endEditBlock();
+ isCorrection_ = true;
+ correctingLabel_->show();
+ input_->setStyleSheet(alertStyleSheet_);
+ labelsWidget_->setEnabled(false);
}
void QtChatWindow::cancelCorrection() {
- if (correctingAlert_) {
- removeAlert(*correctingAlert_);
- correctingAlert_.reset();
- }
- QTextCursor cursor = input_->textCursor();
- cursor.select(QTextCursor::Document);
- cursor.removeSelectedText();
- isCorrection_ = false;
- correctingLabel_->hide();
- input_->setStyleSheet(qApp->styleSheet());
- labelsWidget_->setEnabled(true);
+ if (correctingAlert_) {
+ removeAlert(*correctingAlert_);
+ correctingAlert_.reset();
+ }
+ QTextCursor cursor = input_->textCursor();
+ cursor.select(QTextCursor::Document);
+ cursor.removeSelectedText();
+ isCorrection_ = false;
+ correctingLabel_->hide();
+ input_->setStyleSheet(qApp->styleSheet());
+ labelsWidget_->setEnabled(true);
}
QByteArray QtChatWindow::getSplitterState() {
- return logRosterSplitter_->saveState();
+ return logRosterSplitter_->saveState();
}
void QtChatWindow::handleChangeSplitterState(QByteArray state) {
- logRosterSplitter_->restoreState(state);
+ logRosterSplitter_->restoreState(state);
}
void QtChatWindow::handleSplitterMoved(int, int) {
- emit splitterMoved();
+ emit splitterMoved();
}
void QtChatWindow::tabComplete() {
- if (!completer_) {
- return;
- }
-
- QTextCursor cursor;
- if (tabCompleteCursor_.hasSelection()) {
- cursor = tabCompleteCursor_;
- }
- else {
- cursor = input_->textCursor();
- while(cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor) && cursor.document()->characterAt(cursor.position() - 1) != ' ') { }
- }
- QString root = cursor.selectedText();
- if (root.isEmpty()) {
- return;
- }
- QString suggestion = P2QSTRING(completer_->completeWord(Q2PSTRING(root)));
- if (root == suggestion) {
- return;
- }
- tabCompletion_ = true;
- cursor.beginEditBlock();
- cursor.removeSelectedText();
- int oldPosition = cursor.position();
-
- cursor.insertText(suggestion);
- tabCompleteCursor_ = cursor;
- tabCompleteCursor_.setPosition(oldPosition, QTextCursor::KeepAnchor);
-
- cursor.endEditBlock();
- tabCompletion_ = false;
+ if (!completer_) {
+ return;
+ }
+
+ QTextCursor cursor;
+ if (tabCompleteCursor_.hasSelection()) {
+ cursor = tabCompleteCursor_;
+ }
+ else {
+ cursor = input_->textCursor();
+ while(cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor) && cursor.document()->characterAt(cursor.position() - 1) != ' ') { }
+ }
+ QString root = cursor.selectedText();
+ if (root.isEmpty()) {
+ return;
+ }
+ QString suggestion = P2QSTRING(completer_->completeWord(Q2PSTRING(root)));
+ if (root == suggestion) {
+ return;
+ }
+ tabCompletion_ = true;
+ cursor.beginEditBlock();
+ cursor.removeSelectedText();
+ int oldPosition = cursor.position();
+
+ cursor.insertText(suggestion);
+ tabCompleteCursor_ = cursor;
+ tabCompleteCursor_.setPosition(oldPosition, QTextCursor::KeepAnchor);
+
+ cursor.endEditBlock();
+ tabCompletion_ = false;
}
void QtChatWindow::setRosterModel(Roster* roster) {
- treeWidget_->setRosterModel(roster);
+ treeWidget_->setRosterModel(roster);
}
void QtChatWindow::setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels) {
- delete labelModel_;
- labelModel_ = new LabelModel();
- labelModel_->availableLabels_ = labels;
- int i = 0;
- int defaultIndex = 0;
- labelsWidget_->setModel(labelModel_);
- foreach (SecurityLabelsCatalog::Item label, labels) {
- if (label.getIsDefault()) {
- defaultIndex = i;
- break;
- }
- i++;
- }
- labelsWidget_->setCurrentIndex(defaultIndex);
+ delete labelModel_;
+ labelModel_ = new LabelModel();
+ labelModel_->availableLabels_ = labels;
+ int i = 0;
+ int defaultIndex = 0;
+ labelsWidget_->setModel(labelModel_);
+ foreach (SecurityLabelsCatalog::Item label, labels) {
+ if (label.getIsDefault()) {
+ defaultIndex = i;
+ break;
+ }
+ i++;
+ }
+ labelsWidget_->setCurrentIndex(defaultIndex);
}
void QtChatWindow::handleCurrentLabelChanged(int index) {
- if (static_cast<size_t>(index) >= labelModel_->availableLabels_.size()) {
- SWIFT_LOG(debug) << "User selected a label that doesn't exist";
- return;
- }
- const SecurityLabelsCatalog::Item& label = labelModel_->availableLabels_[index];
- if (label.getLabel()) {
- QPalette palette = labelsWidget_->palette();
- //palette.setColor(QPalette::Base, P2QSTRING(label.getLabel()->getBackgroundColor()));
- palette.setColor(labelsWidget_->backgroundRole(), P2QSTRING(label.getLabel()->getBackgroundColor()));
- palette.setColor(labelsWidget_->foregroundRole(), P2QSTRING(label.getLabel()->getForegroundColor()));
- labelsWidget_->setPalette(palette);
- midBar_->setPalette(palette);
- labelsWidget_->setAutoFillBackground(true);
- }
- else {
- labelsWidget_->setAutoFillBackground(false);
- labelsWidget_->setPalette(defaultLabelsPalette_);
- midBar_->setPalette(defaultLabelsPalette_);
- }
+ if (static_cast<size_t>(index) >= labelModel_->availableLabels_.size()) {
+ SWIFT_LOG(debug) << "User selected a label that doesn't exist";
+ return;
+ }
+ const SecurityLabelsCatalog::Item& label = labelModel_->availableLabels_[index];
+ if (label.getLabel()) {
+ QPalette palette = labelsWidget_->palette();
+ //palette.setColor(QPalette::Base, P2QSTRING(label.getLabel()->getBackgroundColor()));
+ palette.setColor(labelsWidget_->backgroundRole(), P2QSTRING(label.getLabel()->getBackgroundColor()));
+ palette.setColor(labelsWidget_->foregroundRole(), P2QSTRING(label.getLabel()->getForegroundColor()));
+ labelsWidget_->setPalette(palette);
+ midBar_->setPalette(palette);
+ labelsWidget_->setAutoFillBackground(true);
+ }
+ else {
+ labelsWidget_->setAutoFillBackground(false);
+ labelsWidget_->setPalette(defaultLabelsPalette_);
+ midBar_->setPalette(defaultLabelsPalette_);
+ }
}
void QtChatWindow::setSecurityLabelsError() {
- labelsWidget_->setEnabled(false);
+ labelsWidget_->setEnabled(false);
}
void QtChatWindow::setSecurityLabelsEnabled(bool enabled) {
- if (enabled) {
- labelsWidget_->setEnabled(true);
- labelsWidget_->show();
- }
- else {
- labelsWidget_->hide();
- }
+ if (enabled) {
+ labelsWidget_->setEnabled(true);
+ labelsWidget_->show();
+ }
+ else {
+ labelsWidget_->hide();
+ }
}
void QtChatWindow::setCorrectionEnabled(Tristate enabled) {
- correctionEnabled_ = enabled;
+ correctionEnabled_ = enabled;
}
void QtChatWindow::setFileTransferEnabled(Tristate enabled) {
- fileTransferEnabled_ = enabled;
+ fileTransferEnabled_ = enabled;
}
SecurityLabelsCatalog::Item QtChatWindow::getSelectedSecurityLabel() {
- assert(labelsWidget_->isEnabled());
- assert(labelsWidget_->currentIndex() >= 0 && static_cast<size_t>(labelsWidget_->currentIndex()) < labelModel_->availableLabels_.size());
- return labelModel_->availableLabels_[labelsWidget_->currentIndex()];
+ assert(labelsWidget_->isEnabled());
+ assert(labelsWidget_->currentIndex() >= 0 && static_cast<size_t>(labelsWidget_->currentIndex()) < labelModel_->availableLabels_.size());
+ return labelModel_->availableLabels_[labelsWidget_->currentIndex()];
}
void QtChatWindow::closeEvent(QCloseEvent* event) {
- event->accept();
- emit windowClosing();
- onClosed();
+ event->accept();
+ emit windowClosing();
+ onClosed();
}
void QtChatWindow::convertToMUC(MUCType mucType) {
- impromptu_ = (mucType == ImpromptuMUC);
- treeWidget_->setMessageTarget(impromptu_ ? QtTreeWidget::MessageDisplayJID : QtTreeWidget::MessageDefaultJID);
- isMUC_ = true;
- treeWidget_->show();
- subject_->setVisible(!impromptu_);
+ impromptu_ = (mucType == ImpromptuMUC);
+ treeWidget_->setMessageTarget(impromptu_ ? QtTreeWidget::MessageDisplayJID : QtTreeWidget::MessageDefaultJID);
+ isMUC_ = true;
+ treeWidget_->show();
+ subject_->setVisible(!impromptu_);
}
void QtChatWindow::setOnline(bool online) {
- isOnline_ = online;
- if (!online) {
- if (mucConfigurationWindow_) {
- delete mucConfigurationWindow_.data();
- }
- if (affiliationEditor_) {
- delete affiliationEditor_.data();
- }
- }
+ isOnline_ = online;
+ if (!online) {
+ if (mucConfigurationWindow_) {
+ delete mucConfigurationWindow_.data();
+ }
+ if (affiliationEditor_) {
+ delete affiliationEditor_.data();
+ }
+ }
}
void QtChatWindow::showEvent(QShowEvent* event) {
- emit windowOpening();
- QWidget::showEvent(event);
+ emit windowOpening();
+ QWidget::showEvent(event);
}
void QtChatWindow::setUnreadMessageCount(int count) {
- if (unreadCount_ != count) {
- unreadCount_ = count;
- updateTitleWithUnreadCount();
- emit countUpdated();
- }
+ if (unreadCount_ != count) {
+ unreadCount_ = count;
+ updateTitleWithUnreadCount();
+ emit countUpdated();
+ }
}
void QtChatWindow::setContactChatState(ChatState::ChatStateType state) {
- contactIsTyping_ = (state == ChatState::Composing);
- emit titleUpdated();
+ contactIsTyping_ = (state == ChatState::Composing);
+ emit titleUpdated();
}
QtTabbable::AlertType QtChatWindow::getWidgetAlertState() {
- if (contactIsTyping_) {
- return ImpendingActivity;
- }
- if (unreadCount_ > 0) {
- return WaitingActivity;
- }
- return NoActivity;
+ if (contactIsTyping_) {
+ return ImpendingActivity;
+ }
+ if (unreadCount_ > 0) {
+ return WaitingActivity;
+ }
+ return NoActivity;
}
void QtChatWindow::setName(const std::string& name) {
- contact_ = P2QSTRING(name);
- updateTitleWithUnreadCount();
+ contact_ = P2QSTRING(name);
+ updateTitleWithUnreadCount();
}
void QtChatWindow::updateTitleWithUnreadCount() {
- if (isWindow()) {
- setWindowTitle(unreadCount_ > 0 ? QString("(%1) %2").arg(unreadCount_).arg(contact_) : contact_);
- }
- else {
- setWindowTitle(contact_);
- }
- emit titleUpdated();
+ if (isWindow()) {
+ setWindowTitle(unreadCount_ > 0 ? QString("(%1) %2").arg(unreadCount_).arg(contact_) : contact_);
+ }
+ else {
+ setWindowTitle(contact_);
+ }
+ emit titleUpdated();
}
void QtChatWindow::flash() {
- emit requestFlash();
+ emit requestFlash();
}
int QtChatWindow::getCount() {
- return unreadCount_;
+ return unreadCount_;
}
void QtChatWindow::replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, const ChatWindow::TimestampBehaviour timestampBehaviour) {
- messageLog_->replaceSystemMessage(message, id, timestampBehaviour);
+ messageLog_->replaceSystemMessage(message, id, timestampBehaviour);
}
void QtChatWindow::returnPressed() {
- if (!isOnline_ || (blockingState_ == IsBlocked)) {
- return;
- }
- messageLog_->scrollToBottom();
- lastSentMessage_ = QString(input_->toPlainText());
- onSendMessageRequest(Q2PSTRING(input_->toPlainText()), isCorrection_);
- inputClearing_ = true;
- input_->clear();
- cancelCorrection();
- inputClearing_ = false;
+ if (!isOnline_ || (blockingState_ == IsBlocked)) {
+ return;
+ }
+ messageLog_->scrollToBottom();
+ lastSentMessage_ = QString(input_->toPlainText());
+ onSendMessageRequest(Q2PSTRING(input_->toPlainText()), isCorrection_);
+ inputClearing_ = true;
+ input_->clear();
+ cancelCorrection();
+ inputClearing_ = false;
}
void QtChatWindow::handleInputChanged() {
- if (inputClearing_) {
- return;
- }
- if (input_->toPlainText().isEmpty()) {
- onUserCancelsTyping();
- }
- else {
- onUserTyping();
- }
+ if (inputClearing_) {
+ return;
+ }
+ if (input_->toPlainText().isEmpty()) {
+ onUserCancelsTyping();
+ }
+ else {
+ onUserTyping();
+ }
}
void QtChatWindow::handleCursorPositionChanged() {
- if (tabCompletion_) {
- return;
- }
- tabCompleteCursor_.clearSelection();
+ if (tabCompletion_) {
+ return;
+ }
+ tabCompleteCursor_.clearSelection();
}
void QtChatWindow::show() {
- if (parentWidget() == NULL) {
- QWidget::show();
- }
- emit windowOpening();
+ if (parentWidget() == NULL) {
+ QWidget::show();
+ }
+ emit windowOpening();
}
bool QtChatWindow::isVisible() const {
- return QWidget::isVisible();
+ return QWidget::isVisible();
}
void QtChatWindow::activate() {
- if (isWindow()) {
- QWidget::show();
- }
- emit wantsToActivate();
- input_->setFocus();
+ if (isWindow()) {
+ QWidget::show();
+ }
+ emit wantsToActivate();
+ input_->setFocus();
}
void QtChatWindow::resizeEvent(QResizeEvent*) {
- emit geometryChanged();
+ emit geometryChanged();
}
void QtChatWindow::moveEvent(QMoveEvent*) {
- emit geometryChanged();
+ emit geometryChanged();
}
void QtChatWindow::dragEnterEvent(QDragEnterEvent *event) {
- if (isOnline_ && (blockingState_ != IsBlocked)) {
- if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
- if (!isMUC_ && fileTransferEnabled_ == Yes) {
- event->acceptProposedAction();
- }
- }
- else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
- if (isMUC_ || supportsImpromptuChat_) {
- // Prevent invitations or impromptu initializations for contacts that you are already chatting to.
- std::vector<JID> droppedJIDs =jidListFromQByteArray(event->mimeData()->data("application/vnd.swift.contact-jid-list"));
- std::set<JID> conversationJIDs;
- if (isMUC_) {
- conversationJIDs = treeWidget_->getRoster()->getJIDs();
- }
-
- for (std::vector<JID>::iterator i = droppedJIDs.begin(); i != droppedJIDs.end(); ) {
- const JID& droppedJID = *i;
- if (conversationJIDs.find(droppedJID) != conversationJIDs.end()) {
- i = droppedJIDs.erase(i);
- }
- else {
- ++i;
- }
- }
-
- if (droppedJIDs.empty()) {
- event->ignore();
- }
- else {
- event->acceptProposedAction();
- }
- }
- }
- }
+ if (isOnline_ && (blockingState_ != IsBlocked)) {
+ if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
+ if (!isMUC_ && fileTransferEnabled_ == Yes) {
+ event->acceptProposedAction();
+ }
+ }
+ else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
+ if (isMUC_ || supportsImpromptuChat_) {
+ // Prevent invitations or impromptu initializations for contacts that you are already chatting to.
+ std::vector<JID> droppedJIDs =jidListFromQByteArray(event->mimeData()->data("application/vnd.swift.contact-jid-list"));
+ std::set<JID> conversationJIDs;
+ if (isMUC_) {
+ conversationJIDs = treeWidget_->getRoster()->getJIDs();
+ }
+
+ for (std::vector<JID>::iterator i = droppedJIDs.begin(); i != droppedJIDs.end(); ) {
+ const JID& droppedJID = *i;
+ if (conversationJIDs.find(droppedJID) != conversationJIDs.end()) {
+ i = droppedJIDs.erase(i);
+ }
+ else {
+ ++i;
+ }
+ }
+
+ if (droppedJIDs.empty()) {
+ event->ignore();
+ }
+ else {
+ event->acceptProposedAction();
+ }
+ }
+ }
+ }
}
void QtChatWindow::dropEvent(QDropEvent *event) {
- if (fileTransferEnabled_ == Yes && event->mimeData()->hasUrls()) {
- if (event->mimeData()->urls().size() == 1) {
- onSendFileRequest(Q2PSTRING(event->mimeData()->urls().at(0).toLocalFile()));
- }
- else {
- std::string messageText(Q2PSTRING(tr("Sending of multiple files at once isn't supported at this time.")));
- ChatMessage message;
- message.append(boost::make_shared<ChatTextMessagePart>(messageText));
- addSystemMessage(message, DefaultDirection);
- }
- }
- else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
- std::vector<JID> invites = jidListFromQByteArray(event->mimeData()->data("application/vnd.swift.contact-jid-list"));
- onInviteToChat(invites);
- }
+ if (fileTransferEnabled_ == Yes && event->mimeData()->hasUrls()) {
+ if (event->mimeData()->urls().size() == 1) {
+ onSendFileRequest(Q2PSTRING(event->mimeData()->urls().at(0).toLocalFile()));
+ }
+ else {
+ std::string messageText(Q2PSTRING(tr("Sending of multiple files at once isn't supported at this time.")));
+ ChatMessage message;
+ message.append(boost::make_shared<ChatTextMessagePart>(messageText));
+ addSystemMessage(message, DefaultDirection);
+ }
+ }
+ else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
+ std::vector<JID> invites = jidListFromQByteArray(event->mimeData()->data("application/vnd.swift.contact-jid-list"));
+ onInviteToChat(invites);
+ }
}
std::vector<JID> QtChatWindow::jidListFromQByteArray(const QByteArray& dataBytes) {
- QDataStream dataStream(dataBytes);
- std::vector<JID> invites;
- while (!dataStream.atEnd()) {
- QString jidString;
- dataStream >> jidString;
- invites.push_back(Q2PSTRING(jidString));
- }
- return invites;
+ QDataStream dataStream(dataBytes);
+ std::vector<JID> invites;
+ while (!dataStream.atEnd()) {
+ QString jidString;
+ dataStream >> jidString;
+ invites.push_back(Q2PSTRING(jidString));
+ }
+ return invites;
}
void QtChatWindow::setAvailableOccupantActions(const std::vector<OccupantAction>& actions) {
- treeWidget_->setAvailableOccupantActions(actions);
+ treeWidget_->setAvailableOccupantActions(actions);
}
void QtChatWindow::setSubject(const std::string& subject) {
- //subject_->setVisible(!subject.empty());
- subject_->setText(P2QSTRING(subject));
- subject_->setToolTip(P2QSTRING(subject));
- subject_->setCursorPosition(0);
+ //subject_->setVisible(!subject.empty());
+ subject_->setText(P2QSTRING(subject));
+ subject_->setToolTip(P2QSTRING(subject));
+ subject_->setCursorPosition(0);
}
void QtChatWindow::handleEmoticonsButtonClicked() {
- emoticonsMenu_->adjustSize();
- QSize menuSize = emoticonsMenu_->size();
- emoticonsMenu_->exec(QPoint(QCursor::pos().x() - menuSize.width(), QCursor::pos().y() - menuSize.height()));
+ emoticonsMenu_->adjustSize();
+ QSize menuSize = emoticonsMenu_->size();
+ emoticonsMenu_->exec(QPoint(QCursor::pos().x() - menuSize.width(), QCursor::pos().y() - menuSize.height()));
}
void QtChatWindow::handleEmoticonClicked(QString emoticonAsText) {
- input_->textCursor().insertText(emoticonAsText);
- input_->setFocus();
+ input_->textCursor().insertText(emoticonAsText);
+ input_->setFocus();
}
void QtChatWindow::handleTextInputReceivedFocus() {
- lastLineTracker_.setHasFocus(true);
- input_->setFocus();
- onAllMessagesRead();
+ lastLineTracker_.setHasFocus(true);
+ input_->setFocus();
+ onAllMessagesRead();
}
void QtChatWindow::handleTextInputLostFocus() {
- lastLineTracker_.setHasFocus(false);
+ lastLineTracker_.setHasFocus(false);
}
void QtChatWindow::handleActionButtonClicked() {
- QMenu contextMenu;
- QAction* changeSubject = NULL;
- QAction* configure = NULL;
- QAction* affiliations = NULL;
- QAction* destroy = NULL;
- QAction* invite = NULL;
-
- QAction* block = NULL;
- QAction* unblock = NULL;
-
- if (availableRoomActions_.empty()) {
- if (blockingState_ == IsBlocked) {
- unblock = contextMenu.addAction(tr("Unblock"));
- unblock->setEnabled(isOnline_);
- }
- else if (!isMUC_ && blockingState_ == IsUnblocked) {
- block = contextMenu.addAction(tr("Block"));
- block->setEnabled(isOnline_);
- }
-
- if (supportsImpromptuChat_) {
- invite = contextMenu.addAction(tr("Invite person to this chat…"));
- invite->setEnabled(isOnline_ && (blockingState_ != IsBlocked));
- }
-
- }
- else {
- foreach(ChatWindow::RoomAction availableAction, availableRoomActions_)
- {
- if (impromptu_) {
- // hide options we don't need in impromptu chats
- if (availableAction == ChatWindow::ChangeSubject ||
- availableAction == ChatWindow::Configure ||
- availableAction == ChatWindow::Affiliations ||
- availableAction == ChatWindow::Destroy) {
- continue;
- }
- }
- switch(availableAction)
- {
- case ChatWindow::ChangeSubject:
- changeSubject = contextMenu.addAction(tr("Change subject…"));
- changeSubject->setEnabled(isOnline_);
- break;
- case ChatWindow::Configure:
- configure = contextMenu.addAction(tr("Configure room…"));
- configure->setEnabled(isOnline_);
- break;
- case ChatWindow::Affiliations:
- affiliations = contextMenu.addAction(tr("Edit affiliations…"));
- affiliations->setEnabled(isOnline_);
- break;
- case ChatWindow::Destroy:
- destroy = contextMenu.addAction(tr("Destroy room"));
- destroy->setEnabled(isOnline_);
- break;
- case ChatWindow::Invite:
- invite = contextMenu.addAction(tr("Invite person to this room…"));
- invite->setEnabled(isOnline_);
- break;
- }
- }
- }
-
- QAction* bookmark = NULL;
- if (isMUC_) {
- if (roomBookmarkState_ == RoomNotBookmarked) {
- bookmark = contextMenu.addAction(tr("Bookmark this room..."));
- }
- else {
- bookmark = contextMenu.addAction(tr("Edit bookmark..."));
- }
- bookmark->setEnabled(isOnline_);
- }
-
- QAction* result = contextMenu.exec(QCursor::pos());
- if (result == NULL) {
- /* Skip processing. Note that otherwise, because the actions could be null they could match */
- }
- else if (result == changeSubject) {
- bool ok;
- QString subject = QInputDialog::getText(this, tr("Change room subject"), tr("New subject:"), QLineEdit::Normal, subject_->text(), &ok);
- if (ok) {
- onChangeSubjectRequest(Q2PSTRING(subject));
- }
- }
- else if (result == configure) {
- onConfigureRequest(Form::ref());
- }
- else if (result == affiliations) {
- if (!affiliationEditor_) {
- onGetAffiliationsRequest();
- affiliationEditor_ = new QtAffiliationEditor(this);
- connect(affiliationEditor_, SIGNAL(accepted()), this, SLOT(handleAffiliationEditorAccepted()));
- }
- affiliationEditor_->show();
- }
- else if (result == destroy) {
- QMessageBox msgBox;
- msgBox.setWindowTitle(tr("Confirm room destruction"));
- msgBox.setText(tr("Are you sure you want to destroy the room?"));
- msgBox.setInformativeText(tr("This will destroy the room."));
- msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- msgBox.setDefaultButton(QMessageBox::No);
- if (msgBox.exec() == QMessageBox::Yes) {
- onDestroyRequest();
- }
- }
- else if (result == invite) {
- onInviteToChat(std::vector<JID>());
- }
- else if (result == block) {
- onBlockUserRequest();
- }
- else if (result == unblock) {
- onUnblockUserRequest();
- }
- else if (result == bookmark) {
- onBookmarkRequest();
- }
+ QMenu contextMenu;
+ QAction* changeSubject = NULL;
+ QAction* configure = NULL;
+ QAction* affiliations = NULL;
+ QAction* destroy = NULL;
+ QAction* invite = NULL;
+
+ QAction* block = NULL;
+ QAction* unblock = NULL;
+
+ if (availableRoomActions_.empty()) {
+ if (blockingState_ == IsBlocked) {
+ unblock = contextMenu.addAction(tr("Unblock"));
+ unblock->setEnabled(isOnline_);
+ }
+ else if (!isMUC_ && blockingState_ == IsUnblocked) {
+ block = contextMenu.addAction(tr("Block"));
+ block->setEnabled(isOnline_);
+ }
+
+ if (supportsImpromptuChat_) {
+ invite = contextMenu.addAction(tr("Invite person to this chat…"));
+ invite->setEnabled(isOnline_ && (blockingState_ != IsBlocked));
+ }
+
+ }
+ else {
+ foreach(ChatWindow::RoomAction availableAction, availableRoomActions_)
+ {
+ if (impromptu_) {
+ // hide options we don't need in impromptu chats
+ if (availableAction == ChatWindow::ChangeSubject ||
+ availableAction == ChatWindow::Configure ||
+ availableAction == ChatWindow::Affiliations ||
+ availableAction == ChatWindow::Destroy) {
+ continue;
+ }
+ }
+ switch(availableAction)
+ {
+ case ChatWindow::ChangeSubject:
+ changeSubject = contextMenu.addAction(tr("Change subject…"));
+ changeSubject->setEnabled(isOnline_);
+ break;
+ case ChatWindow::Configure:
+ configure = contextMenu.addAction(tr("Configure room…"));
+ configure->setEnabled(isOnline_);
+ break;
+ case ChatWindow::Affiliations:
+ affiliations = contextMenu.addAction(tr("Edit affiliations…"));
+ affiliations->setEnabled(isOnline_);
+ break;
+ case ChatWindow::Destroy:
+ destroy = contextMenu.addAction(tr("Destroy room"));
+ destroy->setEnabled(isOnline_);
+ break;
+ case ChatWindow::Invite:
+ invite = contextMenu.addAction(tr("Invite person to this room…"));
+ invite->setEnabled(isOnline_);
+ break;
+ }
+ }
+ }
+
+ QAction* bookmark = NULL;
+ if (isMUC_) {
+ if (roomBookmarkState_ == RoomNotBookmarked) {
+ bookmark = contextMenu.addAction(tr("Bookmark this room..."));
+ }
+ else {
+ bookmark = contextMenu.addAction(tr("Edit bookmark..."));
+ }
+ bookmark->setEnabled(isOnline_);
+ }
+
+ QAction* result = contextMenu.exec(QCursor::pos());
+ if (result == NULL) {
+ /* Skip processing. Note that otherwise, because the actions could be null they could match */
+ }
+ else if (result == changeSubject) {
+ bool ok;
+ QString subject = QInputDialog::getText(this, tr("Change room subject"), tr("New subject:"), QLineEdit::Normal, subject_->text(), &ok);
+ if (ok) {
+ onChangeSubjectRequest(Q2PSTRING(subject));
+ }
+ }
+ else if (result == configure) {
+ onConfigureRequest(Form::ref());
+ }
+ else if (result == affiliations) {
+ if (!affiliationEditor_) {
+ onGetAffiliationsRequest();
+ affiliationEditor_ = new QtAffiliationEditor(this);
+ connect(affiliationEditor_, SIGNAL(accepted()), this, SLOT(handleAffiliationEditorAccepted()));
+ }
+ affiliationEditor_->show();
+ }
+ else if (result == destroy) {
+ QMessageBox msgBox;
+ msgBox.setWindowTitle(tr("Confirm room destruction"));
+ msgBox.setText(tr("Are you sure you want to destroy the room?"));
+ msgBox.setInformativeText(tr("This will destroy the room."));
+ msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ msgBox.setDefaultButton(QMessageBox::No);
+ if (msgBox.exec() == QMessageBox::Yes) {
+ onDestroyRequest();
+ }
+ }
+ else if (result == invite) {
+ onInviteToChat(std::vector<JID>());
+ }
+ else if (result == block) {
+ onBlockUserRequest();
+ }
+ else if (result == unblock) {
+ onUnblockUserRequest();
+ }
+ else if (result == bookmark) {
+ onBookmarkRequest();
+ }
}
void QtChatWindow::handleAffiliationEditorAccepted() {
- onChangeAffiliationsRequest(affiliationEditor_->getChanges());
+ onChangeAffiliationsRequest(affiliationEditor_->getChanges());
}
void QtChatWindow::setAffiliations(MUCOccupant::Affiliation affiliation, const std::vector<JID>& jids) {
- if (!affiliationEditor_) return;
- affiliationEditor_->setAffiliations(affiliation, jids);
+ if (!affiliationEditor_) return;
+ affiliationEditor_->setAffiliations(affiliation, jids);
}
void QtChatWindow::setAvailableRoomActions(const std::vector<RoomAction>& actions) {
- availableRoomActions_ = actions;
+ availableRoomActions_ = actions;
}
void QtChatWindow::setBlockingState(BlockingState state) {
- blockingState_ = state;
+ blockingState_ = state;
}
void QtChatWindow::setCanInitiateImpromptuChats(bool supportsImpromptu) {
- supportsImpromptuChat_ = supportsImpromptu;
+ supportsImpromptuChat_ = supportsImpromptu;
}
void QtChatWindow::showBookmarkWindow(const MUCBookmark& bookmark) {
- if (roomBookmarkState_ == RoomNotBookmarked) {
- QtAddBookmarkWindow* window = new QtAddBookmarkWindow(eventStream_, bookmark);
- window->show();
- }
- else {
- QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, bookmark);
- window->show();
- }
+ if (roomBookmarkState_ == RoomNotBookmarked) {
+ QtAddBookmarkWindow* window = new QtAddBookmarkWindow(eventStream_, bookmark);
+ window->show();
+ }
+ else {
+ QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, bookmark);
+ window->show();
+ }
}
std::string QtChatWindow::getID() const {
- return id_;
+ return id_;
}
void QtChatWindow::showRoomConfigurationForm(Form::ref form) {
- if (mucConfigurationWindow_) {
- delete mucConfigurationWindow_.data();
- }
- mucConfigurationWindow_ = new QtMUCConfigurationWindow(form);
- mucConfigurationWindow_->onFormComplete.connect(boost::bind(boost::ref(onConfigureRequest), _1));
- mucConfigurationWindow_->onFormCancelled.connect(boost::bind(boost::ref(onConfigurationFormCancelled)));
+ if (mucConfigurationWindow_) {
+ delete mucConfigurationWindow_.data();
+ }
+ mucConfigurationWindow_ = new QtMUCConfigurationWindow(form);
+ mucConfigurationWindow_->onFormComplete.connect(boost::bind(boost::ref(onConfigureRequest), _1));
+ mucConfigurationWindow_->onFormCancelled.connect(boost::bind(boost::ref(onConfigurationFormCancelled)));
}
void QtChatWindow::handleAppendedToLog() {
- if (lastLineTracker_.getShouldMoveLastLine()) {
- /* should this be queued? */
- messageLog_->addLastSeenLine();
- }
- if (isWidgetSelected()) {
- onAllMessagesRead();
- }
+ if (lastLineTracker_.getShouldMoveLastLine()) {
+ /* should this be queued? */
+ messageLog_->addLastSeenLine();
+ }
+ if (isWidgetSelected()) {
+ onAllMessagesRead();
+ }
}
void QtChatWindow::addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) {
- handleAppendedToLog();
- messageLog_->addMUCInvitation(senderName, jid, reason, password, direct, isImpromptu, isContinuation);
+ handleAppendedToLog();
+ messageLog_->addMUCInvitation(senderName, jid, reason, password, direct, isImpromptu, isContinuation);
}
std::string QtChatWindow::addMessage(const ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) {
- handleAppendedToLog();
- return messageLog_->addMessage(message, senderName, senderIsSelf, label, avatarPath, time);
+ handleAppendedToLog();
+ return messageLog_->addMessage(message, senderName, senderIsSelf, label, avatarPath, time);
}
std::string QtChatWindow::addAction(const ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) {
- handleAppendedToLog();
- return messageLog_->addAction(message, senderName, senderIsSelf, label, avatarPath, time);
+ handleAppendedToLog();
+ return messageLog_->addAction(message, senderName, senderIsSelf, label, avatarPath, time);
}
std::string QtChatWindow::addSystemMessage(const ChatMessage& message, Direction direction) {
- handleAppendedToLog();
- return messageLog_->addSystemMessage(message, direction);
+ handleAppendedToLog();
+ return messageLog_->addSystemMessage(message, direction);
}
void QtChatWindow::addPresenceMessage(const ChatMessage& message, Direction direction) {
- handleAppendedToLog();
- messageLog_->addPresenceMessage(message, direction);
+ handleAppendedToLog();
+ messageLog_->addPresenceMessage(message, direction);
}
void QtChatWindow::addErrorMessage(const ChatMessage& message) {
- handleAppendedToLog();
- messageLog_->addErrorMessage(message);
+ handleAppendedToLog();
+ messageLog_->addErrorMessage(message);
}
void QtChatWindow::replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) {
- handleAppendedToLog();
- messageLog_->replaceMessage(message, id, time);
+ handleAppendedToLog();
+ messageLog_->replaceMessage(message, id, time);
}
void QtChatWindow::replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) {
- handleAppendedToLog();
- messageLog_->replaceWithAction(message, id, time);
+ handleAppendedToLog();
+ messageLog_->replaceWithAction(message, id, time);
}
std::string QtChatWindow::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) {
- handleAppendedToLog();
- return messageLog_->addFileTransfer(senderName, senderIsSelf, filename, sizeInBytes, description);
+ handleAppendedToLog();
+ return messageLog_->addFileTransfer(senderName, senderIsSelf, filename, sizeInBytes, description);
}
void QtChatWindow::setFileTransferProgress(std::string id, const int percentageDone) {
- messageLog_->setFileTransferProgress(id, percentageDone);
+ messageLog_->setFileTransferProgress(id, percentageDone);
}
void QtChatWindow::setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg) {
- messageLog_->setFileTransferStatus(id, state, msg);
+ messageLog_->setFileTransferStatus(id, state, msg);
}
std::string QtChatWindow::addWhiteboardRequest(bool senderIsSelf) {
- handleAppendedToLog();
- return messageLog_->addWhiteboardRequest(contact_, senderIsSelf);
+ handleAppendedToLog();
+ return messageLog_->addWhiteboardRequest(contact_, senderIsSelf);
}
void QtChatWindow::setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state) {
- messageLog_->setWhiteboardSessionStatus(id, state);
+ messageLog_->setWhiteboardSessionStatus(id, state);
}
void QtChatWindow::replaceLastMessage(const ChatMessage& message, const TimestampBehaviour timestampBehaviour) {
- messageLog_->replaceLastMessage(message, timestampBehaviour);
+ messageLog_->replaceLastMessage(message, timestampBehaviour);
}
void QtChatWindow::setAckState(const std::string& id, AckState state) {
- messageLog_->setAckState(id, state);
+ messageLog_->setAckState(id, state);
}
void QtChatWindow::setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) {
- messageLog_->setMessageReceiptState(id, state);
+ messageLog_->setMessageReceiptState(id, state);
}
void QtChatWindow::setBookmarkState(RoomBookmarkState bookmarkState) {
- roomBookmarkState_ = bookmarkState;
+ roomBookmarkState_ = bookmarkState;
}
}
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 8acb10c..2a23f5f 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -32,203 +32,203 @@ class QSplitter;
class QPushButton;
namespace Swift {
- class QtChatView;
- class QtOccupantListWidget;
- class QtChatTheme;
- class TreeWidget;
- class QtTextEdit;
- class UIEventStream;
- class QtChatWindowJSBridge;
- class SettingsProvider;
- class QtEmoticonsGrid;
-
- class LabelModel : public QAbstractListModel {
- Q_OBJECT
- public:
- LabelModel(QObject* parent = NULL) : QAbstractListModel(parent) {}
-
- virtual int rowCount(const QModelIndex& /*index*/) const {
- return static_cast<int>(availableLabels_.size());
- }
-
- virtual QVariant data(const QModelIndex& index, int role) const {
- if (!index.isValid()) {
- return QVariant();
- }
- boost::shared_ptr<SecurityLabel> label = availableLabels_[index.row()].getLabel();
- if (label && role == Qt::TextColorRole) {
- return P2QSTRING(label->getForegroundColor());
- }
- if (label && role == Qt::TextColorRole) {
- return P2QSTRING(label->getBackgroundColor());
- }
- if (role == Qt::DisplayRole) {
- std::string selector = availableLabels_[index.row()].getSelector();
- std::string displayMarking = label ? label->getDisplayMarking() : "";
- QString labelName = selector.empty() ? displayMarking.c_str() : selector.c_str();
- return labelName;
- }
- return QVariant();
- }
-
- std::vector<SecurityLabelsCatalog::Item> availableLabels_;
- };
-
- class QtChatWindow : public QtTabbable, public ChatWindow {
- Q_OBJECT
-
- public:
- QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventStream* eventStream, SettingsProvider* settings, const std::map<std::string, std::string>& emoticons);
- virtual ~QtChatWindow();
- std::string addMessage(const ChatMessage& message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time);
- std::string addAction(const ChatMessage& message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time);
-
- std::string addSystemMessage(const ChatMessage& message, Direction direction);
- void addPresenceMessage(const ChatMessage& message, Direction direction);
- void addErrorMessage(const ChatMessage& message);
-
- void replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time);
- void replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time);
- // File transfer related stuff
- std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description);
- void setFileTransferProgress(std::string id, const int percentageDone);
- void setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg);
-
- std::string addWhiteboardRequest(bool senderIsSelf);
- void setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state);
-
- void show();
- bool isVisible() const;
- void activate();
- void setUnreadMessageCount(int count);
- void convertToMUC(MUCType mucType);
-// TreeWidget *getTreeWidget();
- void setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels);
- void setSecurityLabelsEnabled(bool enabled);
- void setSecurityLabelsError();
- SecurityLabelsCatalog::Item getSelectedSecurityLabel();
- void setName(const std::string& name);
- void setOnline(bool online);
- QtTabbable::AlertType getWidgetAlertState();
- void setContactChatState(ChatState::ChatStateType state);
- void setRosterModel(Roster* roster);
- void setTabComplete(TabComplete* completer);
- int getCount();
- virtual void replaceSystemMessage(const ChatMessage& message, const std::string& id, const TimestampBehaviour timestampBehaviour);
- void replaceLastMessage(const ChatMessage& message, const TimestampBehaviour timestampBehaviour);
- void setAckState(const std::string& id, AckState state);
-
- // message receipts
- void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state);
-
- void flash();
- QByteArray getSplitterState();
- virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions);
- void setSubject(const std::string& subject);
- void showRoomConfigurationForm(Form::ref);
- void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct = true, bool isImpromptu = false, bool isContinuation = false);
- void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>&);
- void setAvailableRoomActions(const std::vector<RoomAction>& actions);
- void setBlockingState(BlockingState state);
- virtual void setCanInitiateImpromptuChats(bool supportsImpromptu);
- virtual void showBookmarkWindow(const MUCBookmark& bookmark);
- virtual void setBookmarkState(RoomBookmarkState bookmarkState);
- virtual std::string getID() const;
-
- public slots:
- void handleChangeSplitterState(QByteArray state);
- void handleFontResized(int fontSizeSteps);
- AlertID addAlert(const std::string& alertText);
- void removeAlert(const AlertID id);
- void setCorrectionEnabled(Tristate enabled);
- void setFileTransferEnabled(Tristate enabled);
-
- signals:
- void geometryChanged();
- void splitterMoved();
- void fontResized(int);
-
- protected slots:
- void closeEvent(QCloseEvent* event);
- void resizeEvent(QResizeEvent* event);
- void moveEvent(QMoveEvent* event);
-
- void dragEnterEvent(QDragEnterEvent *event);
- void dropEvent(QDropEvent *event);
-
- protected:
- void showEvent(QShowEvent* event);
-
- private slots:
- void handleLogCleared();
- void returnPressed();
- void handleInputChanged();
- void handleCursorPositionChanged();
- void handleKeyPressEvent(QKeyEvent* event);
- void handleSplitterMoved(int pos, int index);
- void handleAlertButtonClicked();
- void handleActionButtonClicked();
- void handleAffiliationEditorAccepted();
- void handleCurrentLabelChanged(int);
- void handleEmoticonsButtonClicked();
- void handleEmoticonClicked(QString emoticonAsText);
- void handleTextInputReceivedFocus();
- void handleTextInputLostFocus();
-
- private:
- void updateTitleWithUnreadCount();
- void tabComplete();
- void beginCorrection();
- void cancelCorrection();
- void handleSettingChanged(const std::string& setting);
-
- void handleOccupantSelectionChanged(RosterItem* item);
- void handleAppendedToLog();
-
- static std::vector<JID> jidListFromQByteArray(const QByteArray& dataBytes);
-
- private:
- int unreadCount_;
- bool contactIsTyping_;
- LastLineTracker lastLineTracker_;
- std::string id_;
- QString contact_;
- QString lastSentMessage_;
- QTextCursor tabCompleteCursor_;
- QtChatView* messageLog_;
- QtChatTheme* theme_;
- QtTextEdit* input_;
- QWidget* midBar_;
- QBoxLayout* subjectLayout_;
- QComboBox* labelsWidget_;
- QtOccupantListWidget* treeWidget_;
- QLabel* correctingLabel_;
- boost::optional<AlertID> correctingAlert_;
- QVBoxLayout* alertLayout_;
- std::map<AlertID, QWidget*> alertWidgets_;
- AlertID nextAlertId_;
- TabComplete* completer_;
- QLineEdit* subject_;
- bool isCorrection_;
- bool inputClearing_;
- bool tabCompletion_;
- UIEventStream* eventStream_;
- bool isOnline_;
- QSplitter *logRosterSplitter_;
- Tristate correctionEnabled_;
- Tristate fileTransferEnabled_;
- QString alertStyleSheet_;
- QPointer<QtMUCConfigurationWindow> mucConfigurationWindow_;
- QPointer<QtAffiliationEditor> affiliationEditor_;
- SettingsProvider* settings_;
- std::vector<ChatWindow::RoomAction> availableRoomActions_;
- QPalette defaultLabelsPalette_;
- LabelModel* labelModel_;
- BlockingState blockingState_;
- bool impromptu_;
- bool isMUC_;
- bool supportsImpromptuChat_;
- RoomBookmarkState roomBookmarkState_;
- QMenu* emoticonsMenu_;
- };
+ class QtChatView;
+ class QtOccupantListWidget;
+ class QtChatTheme;
+ class TreeWidget;
+ class QtTextEdit;
+ class UIEventStream;
+ class QtChatWindowJSBridge;
+ class SettingsProvider;
+ class QtEmoticonsGrid;
+
+ class LabelModel : public QAbstractListModel {
+ Q_OBJECT
+ public:
+ LabelModel(QObject* parent = NULL) : QAbstractListModel(parent) {}
+
+ virtual int rowCount(const QModelIndex& /*index*/) const {
+ return static_cast<int>(availableLabels_.size());
+ }
+
+ virtual QVariant data(const QModelIndex& index, int role) const {
+ if (!index.isValid()) {
+ return QVariant();
+ }
+ boost::shared_ptr<SecurityLabel> label = availableLabels_[index.row()].getLabel();
+ if (label && role == Qt::TextColorRole) {
+ return P2QSTRING(label->getForegroundColor());
+ }
+ if (label && role == Qt::TextColorRole) {
+ return P2QSTRING(label->getBackgroundColor());
+ }
+ if (role == Qt::DisplayRole) {
+ std::string selector = availableLabels_[index.row()].getSelector();
+ std::string displayMarking = label ? label->getDisplayMarking() : "";
+ QString labelName = selector.empty() ? displayMarking.c_str() : selector.c_str();
+ return labelName;
+ }
+ return QVariant();
+ }
+
+ std::vector<SecurityLabelsCatalog::Item> availableLabels_;
+ };
+
+ class QtChatWindow : public QtTabbable, public ChatWindow {
+ Q_OBJECT
+
+ public:
+ QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventStream* eventStream, SettingsProvider* settings, const std::map<std::string, std::string>& emoticons);
+ virtual ~QtChatWindow();
+ std::string addMessage(const ChatMessage& message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time);
+ std::string addAction(const ChatMessage& message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time);
+
+ std::string addSystemMessage(const ChatMessage& message, Direction direction);
+ void addPresenceMessage(const ChatMessage& message, Direction direction);
+ void addErrorMessage(const ChatMessage& message);
+
+ void replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time);
+ void replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time);
+ // File transfer related stuff
+ std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description);
+ void setFileTransferProgress(std::string id, const int percentageDone);
+ void setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg);
+
+ std::string addWhiteboardRequest(bool senderIsSelf);
+ void setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state);
+
+ void show();
+ bool isVisible() const;
+ void activate();
+ void setUnreadMessageCount(int count);
+ void convertToMUC(MUCType mucType);
+// TreeWidget *getTreeWidget();
+ void setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels);
+ void setSecurityLabelsEnabled(bool enabled);
+ void setSecurityLabelsError();
+ SecurityLabelsCatalog::Item getSelectedSecurityLabel();
+ void setName(const std::string& name);
+ void setOnline(bool online);
+ QtTabbable::AlertType getWidgetAlertState();
+ void setContactChatState(ChatState::ChatStateType state);
+ void setRosterModel(Roster* roster);
+ void setTabComplete(TabComplete* completer);
+ int getCount();
+ virtual void replaceSystemMessage(const ChatMessage& message, const std::string& id, const TimestampBehaviour timestampBehaviour);
+ void replaceLastMessage(const ChatMessage& message, const TimestampBehaviour timestampBehaviour);
+ void setAckState(const std::string& id, AckState state);
+
+ // message receipts
+ void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state);
+
+ void flash();
+ QByteArray getSplitterState();
+ virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions);
+ void setSubject(const std::string& subject);
+ void showRoomConfigurationForm(Form::ref);
+ void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct = true, bool isImpromptu = false, bool isContinuation = false);
+ void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>&);
+ void setAvailableRoomActions(const std::vector<RoomAction>& actions);
+ void setBlockingState(BlockingState state);
+ virtual void setCanInitiateImpromptuChats(bool supportsImpromptu);
+ virtual void showBookmarkWindow(const MUCBookmark& bookmark);
+ virtual void setBookmarkState(RoomBookmarkState bookmarkState);
+ virtual std::string getID() const;
+
+ public slots:
+ void handleChangeSplitterState(QByteArray state);
+ void handleFontResized(int fontSizeSteps);
+ AlertID addAlert(const std::string& alertText);
+ void removeAlert(const AlertID id);
+ void setCorrectionEnabled(Tristate enabled);
+ void setFileTransferEnabled(Tristate enabled);
+
+ signals:
+ void geometryChanged();
+ void splitterMoved();
+ void fontResized(int);
+
+ protected slots:
+ void closeEvent(QCloseEvent* event);
+ void resizeEvent(QResizeEvent* event);
+ void moveEvent(QMoveEvent* event);
+
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dropEvent(QDropEvent *event);
+
+ protected:
+ void showEvent(QShowEvent* event);
+
+ private slots:
+ void handleLogCleared();
+ void returnPressed();
+ void handleInputChanged();
+ void handleCursorPositionChanged();
+ void handleKeyPressEvent(QKeyEvent* event);
+ void handleSplitterMoved(int pos, int index);
+ void handleAlertButtonClicked();
+ void handleActionButtonClicked();
+ void handleAffiliationEditorAccepted();
+ void handleCurrentLabelChanged(int);
+ void handleEmoticonsButtonClicked();
+ void handleEmoticonClicked(QString emoticonAsText);
+ void handleTextInputReceivedFocus();
+ void handleTextInputLostFocus();
+
+ private:
+ void updateTitleWithUnreadCount();
+ void tabComplete();
+ void beginCorrection();
+ void cancelCorrection();
+ void handleSettingChanged(const std::string& setting);
+
+ void handleOccupantSelectionChanged(RosterItem* item);
+ void handleAppendedToLog();
+
+ static std::vector<JID> jidListFromQByteArray(const QByteArray& dataBytes);
+
+ private:
+ int unreadCount_;
+ bool contactIsTyping_;
+ LastLineTracker lastLineTracker_;
+ std::string id_;
+ QString contact_;
+ QString lastSentMessage_;
+ QTextCursor tabCompleteCursor_;
+ QtChatView* messageLog_;
+ QtChatTheme* theme_;
+ QtTextEdit* input_;
+ QWidget* midBar_;
+ QBoxLayout* subjectLayout_;
+ QComboBox* labelsWidget_;
+ QtOccupantListWidget* treeWidget_;
+ QLabel* correctingLabel_;
+ boost::optional<AlertID> correctingAlert_;
+ QVBoxLayout* alertLayout_;
+ std::map<AlertID, QWidget*> alertWidgets_;
+ AlertID nextAlertId_;
+ TabComplete* completer_;
+ QLineEdit* subject_;
+ bool isCorrection_;
+ bool inputClearing_;
+ bool tabCompletion_;
+ UIEventStream* eventStream_;
+ bool isOnline_;
+ QSplitter *logRosterSplitter_;
+ Tristate correctionEnabled_;
+ Tristate fileTransferEnabled_;
+ QString alertStyleSheet_;
+ QPointer<QtMUCConfigurationWindow> mucConfigurationWindow_;
+ QPointer<QtAffiliationEditor> affiliationEditor_;
+ SettingsProvider* settings_;
+ std::vector<ChatWindow::RoomAction> availableRoomActions_;
+ QPalette defaultLabelsPalette_;
+ LabelModel* labelModel_;
+ BlockingState blockingState_;
+ bool impromptu_;
+ bool isMUC_;
+ bool supportsImpromptuChat_;
+ RoomBookmarkState roomBookmarkState_;
+ QMenu* emoticonsMenu_;
+ };
}
diff --git a/Swift/QtUI/QtChatWindowFactory.cpp b/Swift/QtUI/QtChatWindowFactory.cpp
index 019eb21..a97fd7c 100644
--- a/Swift/QtUI/QtChatWindowFactory.cpp
+++ b/Swift/QtUI/QtChatWindowFactory.cpp
@@ -23,65 +23,65 @@ static const QString SPLITTER_STATE = "mucSplitterState";
static const QString CHAT_TABS_GEOMETRY = "chatTabsGeometry";
QtChatWindowFactory::QtChatWindowFactory(QtSingleWindow* splitter, SettingsProvider* settings, QtSettingsProvider* qtSettings, QtChatTabsBase* tabs, const QString& themePath, const std::map<std::string, std::string>& emoticons) : themePath_(themePath), emoticons_(emoticons) {
- qtOnlySettings_ = qtSettings;
- settings_ = settings;
- tabs_ = tabs;
- theme_ = NULL;
- QtChatTabs* fullTabs = dynamic_cast<QtChatTabs*>(tabs_);
- if (splitter) {
- assert(fullTabs && "Netbook mode and no-tabs interface is not supported!");
- splitter->addWidget(fullTabs);
- } else if (fullTabs) {
- QVariant chatTabsGeometryVariant = qtOnlySettings_->getQSettings()->value(CHAT_TABS_GEOMETRY);
- if (chatTabsGeometryVariant.isValid()) {
- fullTabs->restoreGeometry(chatTabsGeometryVariant.toByteArray());
- }
- connect(fullTabs, SIGNAL(geometryChanged()), this, SLOT(handleWindowGeometryChanged()));
- }
+ qtOnlySettings_ = qtSettings;
+ settings_ = settings;
+ tabs_ = tabs;
+ theme_ = NULL;
+ QtChatTabs* fullTabs = dynamic_cast<QtChatTabs*>(tabs_);
+ if (splitter) {
+ assert(fullTabs && "Netbook mode and no-tabs interface is not supported!");
+ splitter->addWidget(fullTabs);
+ } else if (fullTabs) {
+ QVariant chatTabsGeometryVariant = qtOnlySettings_->getQSettings()->value(CHAT_TABS_GEOMETRY);
+ if (chatTabsGeometryVariant.isValid()) {
+ fullTabs->restoreGeometry(chatTabsGeometryVariant.toByteArray());
+ }
+ connect(fullTabs, SIGNAL(geometryChanged()), this, SLOT(handleWindowGeometryChanged()));
+ }
}
QtChatWindowFactory::~QtChatWindowFactory() {
- delete theme_;
+ delete theme_;
}
ChatWindow* QtChatWindowFactory::createChatWindow(const JID &contact,UIEventStream* eventStream) {
- if (!theme_) {
- theme_ = new QtChatTheme(themePath_);
- if (theme_->getIncomingContent().isEmpty()) {
- delete theme_;
- theme_ = new QtChatTheme(":/themes/Default/"); /* Use the inbuilt theme */
- }
- }
+ if (!theme_) {
+ theme_ = new QtChatTheme(themePath_);
+ if (theme_->getIncomingContent().isEmpty()) {
+ delete theme_;
+ theme_ = new QtChatTheme(":/themes/Default/"); /* Use the inbuilt theme */
+ }
+ }
- QtChatWindow* chatWindow = new QtChatWindow(P2QSTRING(contact.toString()), theme_, eventStream, settings_, emoticons_);
- connect(chatWindow, SIGNAL(splitterMoved()), this, SLOT(handleSplitterMoved()));
- connect(this, SIGNAL(changeSplitterState(QByteArray)), chatWindow, SLOT(handleChangeSplitterState(QByteArray)));
+ QtChatWindow* chatWindow = new QtChatWindow(P2QSTRING(contact.toString()), theme_, eventStream, settings_, emoticons_);
+ connect(chatWindow, SIGNAL(splitterMoved()), this, SLOT(handleSplitterMoved()));
+ connect(this, SIGNAL(changeSplitterState(QByteArray)), chatWindow, SLOT(handleChangeSplitterState(QByteArray)));
- QVariant splitterState = qtOnlySettings_->getQSettings()->value(SPLITTER_STATE);
- if(splitterState.isValid()) {
- chatWindow->handleChangeSplitterState(splitterState.toByteArray());
- }
+ QVariant splitterState = qtOnlySettings_->getQSettings()->value(SPLITTER_STATE);
+ if(splitterState.isValid()) {
+ chatWindow->handleChangeSplitterState(splitterState.toByteArray());
+ }
- if (tabs_) {
- tabs_->addTab(chatWindow);
- } else {
- QVariant chatGeometryVariant = qtOnlySettings_->getQSettings()->value(CHAT_TABS_GEOMETRY);
- if (chatGeometryVariant.isValid()) {
- chatWindow->restoreGeometry(chatGeometryVariant.toByteArray());
- }
- connect(chatWindow, SIGNAL(geometryChanged()), this, SLOT(handleWindowGeometryChanged()));
- }
- return chatWindow;
+ if (tabs_) {
+ tabs_->addTab(chatWindow);
+ } else {
+ QVariant chatGeometryVariant = qtOnlySettings_->getQSettings()->value(CHAT_TABS_GEOMETRY);
+ if (chatGeometryVariant.isValid()) {
+ chatWindow->restoreGeometry(chatGeometryVariant.toByteArray());
+ }
+ connect(chatWindow, SIGNAL(geometryChanged()), this, SLOT(handleWindowGeometryChanged()));
+ }
+ return chatWindow;
}
void QtChatWindowFactory::handleWindowGeometryChanged() {
- qtOnlySettings_->getQSettings()->setValue(CHAT_TABS_GEOMETRY, qobject_cast<QWidget*>(sender())->saveGeometry());
+ qtOnlySettings_->getQSettings()->setValue(CHAT_TABS_GEOMETRY, qobject_cast<QWidget*>(sender())->saveGeometry());
}
void QtChatWindowFactory::handleSplitterMoved() {
- QByteArray splitterState = qobject_cast<QtChatWindow*>(sender())->getSplitterState();
- qtOnlySettings_->getQSettings()->setValue(SPLITTER_STATE, QVariant(splitterState));
- emit changeSplitterState(splitterState);
+ QByteArray splitterState = qobject_cast<QtChatWindow*>(sender())->getSplitterState();
+ qtOnlySettings_->getQSettings()->setValue(SPLITTER_STATE, QVariant(splitterState));
+ emit changeSplitterState(splitterState);
}
}
diff --git a/Swift/QtUI/QtChatWindowFactory.h b/Swift/QtUI/QtChatWindowFactory.h
index 6b1f0a1..29bc5bc 100644
--- a/Swift/QtUI/QtChatWindowFactory.h
+++ b/Swift/QtUI/QtChatWindowFactory.h
@@ -19,29 +19,29 @@
#include <Swift/QtUI/QtSettingsProvider.h>
namespace Swift {
- class QtChatTabsBase;
- class QtChatTheme;
- class UIEventStream;
- class QtUIPreferences;
- class QtSingleWindow;
- class QtChatWindowFactory : public QObject, public ChatWindowFactory {
- Q_OBJECT
- public:
- QtChatWindowFactory(QtSingleWindow* splitter, SettingsProvider* settings, QtSettingsProvider* qtSettings, QtChatTabsBase* tabs, const QString& themePath, const std::map<std::string, std::string>& emoticons);
- ~QtChatWindowFactory();
- ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream);
- signals:
- void changeSplitterState(QByteArray);
- private slots:
- void handleWindowGeometryChanged();
- void handleSplitterMoved();
- private:
- QString themePath_;
- SettingsProvider* settings_;
- QtSettingsProvider* qtOnlySettings_;
- QtChatTabsBase* tabs_;
- QtChatTheme* theme_;
- std::map<std::string, std::string> emoticons_;
- };
+ class QtChatTabsBase;
+ class QtChatTheme;
+ class UIEventStream;
+ class QtUIPreferences;
+ class QtSingleWindow;
+ class QtChatWindowFactory : public QObject, public ChatWindowFactory {
+ Q_OBJECT
+ public:
+ QtChatWindowFactory(QtSingleWindow* splitter, SettingsProvider* settings, QtSettingsProvider* qtSettings, QtChatTabsBase* tabs, const QString& themePath, const std::map<std::string, std::string>& emoticons);
+ ~QtChatWindowFactory();
+ ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream);
+ signals:
+ void changeSplitterState(QByteArray);
+ private slots:
+ void handleWindowGeometryChanged();
+ void handleSplitterMoved();
+ private:
+ QString themePath_;
+ SettingsProvider* settings_;
+ QtSettingsProvider* qtOnlySettings_;
+ QtChatTabsBase* tabs_;
+ QtChatTheme* theme_;
+ std::map<std::string, std::string> emoticons_;
+ };
}
diff --git a/Swift/QtUI/QtChatWindowJSBridge.cpp b/Swift/QtUI/QtChatWindowJSBridge.cpp
index fa6f906..3030689 100644
--- a/Swift/QtUI/QtChatWindowJSBridge.cpp
+++ b/Swift/QtUI/QtChatWindowJSBridge.cpp
@@ -15,11 +15,11 @@
namespace Swift {
QtChatWindowJSBridge::QtChatWindowJSBridge() {
-
+
}
QtChatWindowJSBridge::~QtChatWindowJSBridge() {
-
+
}
}
diff --git a/Swift/QtUI/QtChatWindowJSBridge.h b/Swift/QtUI/QtChatWindowJSBridge.h
index db01abb..bedf6a4 100644
--- a/Swift/QtUI/QtChatWindowJSBridge.h
+++ b/Swift/QtUI/QtChatWindowJSBridge.h
@@ -21,12 +21,12 @@ namespace Swift {
class FileTransferController;
class QtChatWindowJSBridge : public QObject {
- Q_OBJECT
+ Q_OBJECT
public:
- QtChatWindowJSBridge();
- virtual ~QtChatWindowJSBridge();
+ QtChatWindowJSBridge();
+ virtual ~QtChatWindowJSBridge();
signals:
- void buttonClicked(QString id, QString arg1, QString arg2, QString arg3, QString arg4, QString arg5);
+ void buttonClicked(QString id, QString arg1, QString arg2, QString arg3, QString arg4, QString arg5);
};
}
diff --git a/Swift/QtUI/QtClickableLabel.cpp b/Swift/QtUI/QtClickableLabel.cpp
index 3749cfe..7ce3325 100644
--- a/Swift/QtUI/QtClickableLabel.cpp
+++ b/Swift/QtUI/QtClickableLabel.cpp
@@ -12,7 +12,7 @@ QtClickableLabel::QtClickableLabel(QWidget* parent) : QLabel(parent) {
}
void QtClickableLabel::mousePressEvent(QMouseEvent*) {
- emit clicked();
+ emit clicked();
}
}
diff --git a/Swift/QtUI/QtClickableLabel.h b/Swift/QtUI/QtClickableLabel.h
index deaf646..83ed3f1 100644
--- a/Swift/QtUI/QtClickableLabel.h
+++ b/Swift/QtUI/QtClickableLabel.h
@@ -9,14 +9,14 @@
#include <QLabel>
namespace Swift {
- class QtClickableLabel : public QLabel {
- Q_OBJECT
- public:
- QtClickableLabel(QWidget* parent);
+ class QtClickableLabel : public QLabel {
+ Q_OBJECT
+ public:
+ QtClickableLabel(QWidget* parent);
- void mousePressEvent(QMouseEvent* event);
+ void mousePressEvent(QMouseEvent* event);
- signals:
- void clicked();
- };
+ signals:
+ void clicked();
+ };
}
diff --git a/Swift/QtUI/QtClosableLineEdit.cpp b/Swift/QtUI/QtClosableLineEdit.cpp
index 414463a..033db78 100644
--- a/Swift/QtUI/QtClosableLineEdit.cpp
+++ b/Swift/QtUI/QtClosableLineEdit.cpp
@@ -27,40 +27,40 @@ namespace Swift {
const int QtClosableLineEdit::clearButtonPadding = 2;
QtClosableLineEdit::QtClosableLineEdit(QWidget *parent) : QLineEdit(parent) {
- clearButton = new QToolButton(this);
- clearButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
- clearButton->setIconSize(QSize(16,16));
- clearButton->setCursor(Qt::ArrowCursor);
- clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
- clearButton->hide();
- connect(clearButton, SIGNAL(clicked()), this, SLOT(handleCloseButtonClicked()));
- connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
- int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
- QSize minimumSize = minimumSizeHint();
- setMinimumSize(qMax(minimumSize.width(), clearButton->sizeHint().width() + frameWidth * 2 + clearButtonPadding),
- qMax(minimumSize.height(), clearButton->sizeHint().height() + frameWidth * 2 + clearButtonPadding));
+ clearButton = new QToolButton(this);
+ clearButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
+ clearButton->setIconSize(QSize(16,16));
+ clearButton->setCursor(Qt::ArrowCursor);
+ clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
+ clearButton->hide();
+ connect(clearButton, SIGNAL(clicked()), this, SLOT(handleCloseButtonClicked()));
+ connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
+ QSize minimumSize = minimumSizeHint();
+ setMinimumSize(qMax(minimumSize.width(), clearButton->sizeHint().width() + frameWidth * 2 + clearButtonPadding),
+ qMax(minimumSize.height(), clearButton->sizeHint().height() + frameWidth * 2 + clearButtonPadding));
}
void QtClosableLineEdit::resizeEvent(QResizeEvent *) {
- QSize size = clearButton->sizeHint();
- int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- int verticalAdjustment = 1;
+ QSize size = clearButton->sizeHint();
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ int verticalAdjustment = 1;
#if defined(Q_OS_WIN32)
- // This vertical adjustment is required on Windows so the close button is vertically centered in the line edit.
- verticalAdjustment += 2;
-#endif
- clearButton->move(rect().right() - frameWidth - size.width(), (rect().bottom() + verticalAdjustment - size.height())/2);
+ // This vertical adjustment is required on Windows so the close button is vertically centered in the line edit.
+ verticalAdjustment += 2;
+#endif
+ clearButton->move(rect().right() - frameWidth - size.width(), (rect().bottom() + verticalAdjustment - size.height())/2);
}
void QtClosableLineEdit::updateCloseButton(const QString& text) {
- clearButton->setVisible(!text.isEmpty());
+ clearButton->setVisible(!text.isEmpty());
}
void QtClosableLineEdit::handleCloseButtonClicked() {
- clear();
- QApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier));
- QApplication::postEvent(this, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Escape, Qt::NoModifier));
+ clear();
+ QApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier));
+ QApplication::postEvent(this, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Escape, Qt::NoModifier));
}
}
diff --git a/Swift/QtUI/QtClosableLineEdit.h b/Swift/QtUI/QtClosableLineEdit.h
index da9f5a8..206851b 100644
--- a/Swift/QtUI/QtClosableLineEdit.h
+++ b/Swift/QtUI/QtClosableLineEdit.h
@@ -24,20 +24,20 @@ namespace Swift {
class QtClosableLineEdit : public QLineEdit
{
- Q_OBJECT
- public:
- QtClosableLineEdit(QWidget *parent = 0);
+ Q_OBJECT
+ public:
+ QtClosableLineEdit(QWidget *parent = 0);
- protected:
- void resizeEvent(QResizeEvent *);
+ protected:
+ void resizeEvent(QResizeEvent *);
- private slots:
- void updateCloseButton(const QString &text);
- void handleCloseButtonClicked();
+ private slots:
+ void updateCloseButton(const QString &text);
+ void handleCloseButtonClicked();
- private:
- static const int clearButtonPadding;
- QToolButton *clearButton;
+ private:
+ static const int clearButtonPadding;
+ QToolButton *clearButton;
};
}
diff --git a/Swift/QtUI/QtColorToolButton.cpp b/Swift/QtUI/QtColorToolButton.cpp
index a91fe0e..b349a47 100644
--- a/Swift/QtUI/QtColorToolButton.cpp
+++ b/Swift/QtUI/QtColorToolButton.cpp
@@ -18,34 +18,34 @@
namespace Swift {
QtColorToolButton::QtColorToolButton(QWidget* parent) :
- QToolButton(parent)
+ QToolButton(parent)
{
- connect(this, SIGNAL(clicked()), SLOT(onClicked()));
- setColorIcon(Qt::transparent);
+ connect(this, SIGNAL(clicked()), SLOT(onClicked()));
+ setColorIcon(Qt::transparent);
}
void QtColorToolButton::setColor(const QColor& color)
{
- if (color.isValid() != color_.isValid() || (color.isValid() && color != color_)) {
- color_ = color;
- setColorIcon(color_);
- emit colorChanged(color_);
- }
+ if (color.isValid() != color_.isValid() || (color.isValid() && color != color_)) {
+ color_ = color;
+ setColorIcon(color_);
+ emit colorChanged(color_);
+ }
}
void QtColorToolButton::onClicked()
{
- QColor c = QColorDialog::getColor(color_, this);
- if (c.isValid()) {
- setColor(c);
- }
+ QColor c = QColorDialog::getColor(color_, this);
+ if (c.isValid()) {
+ setColor(c);
+ }
}
void QtColorToolButton::setColorIcon(const QColor& color)
{
- QPixmap pix(iconSize());
- pix.fill(color.isValid() ? color : Qt::transparent);
- setIcon(pix);
+ QPixmap pix(iconSize());
+ pix.fill(color.isValid() ? color : Qt::transparent);
+ setIcon(pix);
}
}
diff --git a/Swift/QtUI/QtColorToolButton.h b/Swift/QtUI/QtColorToolButton.h
index 33d195d..5260048 100644
--- a/Swift/QtUI/QtColorToolButton.h
+++ b/Swift/QtUI/QtColorToolButton.h
@@ -10,23 +10,23 @@
namespace Swift {
- class QtColorToolButton : public QToolButton {
- Q_OBJECT
- Q_PROPERTY(QColor color READ getColor WRITE setColor NOTIFY colorChanged)
- public:
- explicit QtColorToolButton(QWidget* parent = NULL);
- void setColor(const QColor& color);
- const QColor& getColor() const { return color_; }
-
- signals:
- void colorChanged(const QColor&);
-
- private slots:
- void onClicked();
-
- private:
- void setColorIcon(const QColor& color);
- QColor color_;
- };
+ class QtColorToolButton : public QToolButton {
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ getColor WRITE setColor NOTIFY colorChanged)
+ public:
+ explicit QtColorToolButton(QWidget* parent = NULL);
+ void setColor(const QColor& color);
+ const QColor& getColor() const { return color_; }
+
+ signals:
+ void colorChanged(const QColor&);
+
+ private slots:
+ void onClicked();
+
+ private:
+ void setColorIcon(const QColor& color);
+ QColor color_;
+ };
}
diff --git a/Swift/QtUI/QtConnectionSettingsWindow.cpp b/Swift/QtUI/QtConnectionSettingsWindow.cpp
index 940625b..a58bc5c 100644
--- a/Swift/QtUI/QtConnectionSettingsWindow.cpp
+++ b/Swift/QtUI/QtConnectionSettingsWindow.cpp
@@ -25,147 +25,147 @@
namespace Swift {
QtConnectionSettingsWindow::QtConnectionSettingsWindow(const ClientOptions& options) : QDialog() {
- ui.setupUi(this);
-
- connect(ui.connectionMethod, SIGNAL(currentIndexChanged(int)), ui.stackedWidget, SLOT(setCurrentIndex(int)));
-
- connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostNameLabel, SLOT(setEnabled(bool)));
- connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostName, SLOT(setEnabled(bool)));
- connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostPortLabel, SLOT(setEnabled(bool)));
- connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostPort, SLOT(setEnabled(bool)));
-
- connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyHostLabel, SLOT(setEnabled(bool)));
- connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyHost, SLOT(setEnabled(bool)));
- connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyPortLabel, SLOT(setEnabled(bool)));
- connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyPort, SLOT(setEnabled(bool)));
-
- connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyHostLabel, SLOT(setEnabled(bool)));
- connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyHost, SLOT(setEnabled(bool)));
- connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyPortLabel, SLOT(setEnabled(bool)));
- connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyPort, SLOT(setEnabled(bool)));
-
- connect(ui.manual_proxyType, SIGNAL(currentIndexChanged(int)), SLOT(handleProxyTypeChanged(int)));
-
- connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(handleAcceptRequested()));
-
- QtURLValidator* urlValidator = new QtURLValidator(this);
- ui.bosh_uri->setValidator(urlValidator);
-
- ui.manual_useTLS->setCurrentIndex(2);
-
- ui.manual_proxyType->setCurrentIndex(0);
-
- ClientOptions defaults;
- if (options.boshURL.isEmpty()) {
- bool isDefault = options.useStreamCompression == defaults.useStreamCompression;
- isDefault &= options.useTLS == defaults.useTLS;
- isDefault &= options.allowPLAINWithoutTLS == defaults.allowPLAINWithoutTLS;
- isDefault &= options.useStreamCompression == defaults.useStreamCompression;
- isDefault &= options.useAcks == defaults.useAcks;
- isDefault &= options.manualHostname == defaults.manualHostname;
- isDefault &= options.manualPort == defaults.manualPort;
- isDefault &= options.proxyType == defaults.proxyType;
- isDefault &= options.manualProxyHostname == defaults.manualProxyHostname;
- isDefault &= options.manualProxyPort == defaults.manualProxyPort;
- isDefault &= options.tlsOptions.schannelTLS1_0Workaround == defaults.tlsOptions.schannelTLS1_0Workaround;
- if (isDefault) {
- ui.connectionMethod->setCurrentIndex(0);
- }
- else {
- ui.connectionMethod->setCurrentIndex(1);
- ui.manual_useTLS->setCurrentIndex(options.useTLS);
- ui.manual_allowPLAINWithoutTLS->setChecked(options.allowPLAINWithoutTLS);
- ui.manual_allowCompression->setChecked(options.useStreamCompression);
- if (!options.manualHostname.empty()) {
- ui.manual_manualHost->setChecked(true);
- ui.manual_manualHostName->setText(P2QSTRING(options.manualHostname));
- if (options.manualPort >=0) {
- ui.manual_manualHostPort->setText(P2QSTRING(boost::lexical_cast<std::string>(options.manualPort)));
- }
- }
- ui.manual_proxyType->setCurrentIndex(options.proxyType);
- if (!options.manualProxyHostname.empty()) {
- ui.manual_manualProxy->setChecked(true);
- ui.manual_manualProxyHost->setText(P2QSTRING(options.manualProxyHostname));
- ui.manual_manualProxyPort->setText(P2QSTRING(boost::lexical_cast<std::string>(options.manualProxyPort)));
- }
- ui.manual_forceTLS1_0->setChecked(options.tlsOptions.schannelTLS1_0Workaround);
- }
- } else {
- ui.connectionMethod->setCurrentIndex(2);
- ui.bosh_uri->setText(P2QSTRING(options.boshURL.toString()));
- if (!options.boshHTTPConnectProxyURL.isEmpty()) {
- ui.bosh_manualProxy->setChecked(true);
- ui.bosh_manualProxyHost->setText(P2QSTRING(options.boshHTTPConnectProxyURL.getHost()));
- if (options.boshHTTPConnectProxyURL.getPort()) {
- ui.bosh_manualProxyPort->setText(P2QSTRING(boost::lexical_cast<std::string>(*options.boshHTTPConnectProxyURL.getPort())));
- }
- }
- }
+ ui.setupUi(this);
+
+ connect(ui.connectionMethod, SIGNAL(currentIndexChanged(int)), ui.stackedWidget, SLOT(setCurrentIndex(int)));
+
+ connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostNameLabel, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostName, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostPortLabel, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostPort, SLOT(setEnabled(bool)));
+
+ connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyHostLabel, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyHost, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyPortLabel, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyPort, SLOT(setEnabled(bool)));
+
+ connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyHostLabel, SLOT(setEnabled(bool)));
+ connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyHost, SLOT(setEnabled(bool)));
+ connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyPortLabel, SLOT(setEnabled(bool)));
+ connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyPort, SLOT(setEnabled(bool)));
+
+ connect(ui.manual_proxyType, SIGNAL(currentIndexChanged(int)), SLOT(handleProxyTypeChanged(int)));
+
+ connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(handleAcceptRequested()));
+
+ QtURLValidator* urlValidator = new QtURLValidator(this);
+ ui.bosh_uri->setValidator(urlValidator);
+
+ ui.manual_useTLS->setCurrentIndex(2);
+
+ ui.manual_proxyType->setCurrentIndex(0);
+
+ ClientOptions defaults;
+ if (options.boshURL.isEmpty()) {
+ bool isDefault = options.useStreamCompression == defaults.useStreamCompression;
+ isDefault &= options.useTLS == defaults.useTLS;
+ isDefault &= options.allowPLAINWithoutTLS == defaults.allowPLAINWithoutTLS;
+ isDefault &= options.useStreamCompression == defaults.useStreamCompression;
+ isDefault &= options.useAcks == defaults.useAcks;
+ isDefault &= options.manualHostname == defaults.manualHostname;
+ isDefault &= options.manualPort == defaults.manualPort;
+ isDefault &= options.proxyType == defaults.proxyType;
+ isDefault &= options.manualProxyHostname == defaults.manualProxyHostname;
+ isDefault &= options.manualProxyPort == defaults.manualProxyPort;
+ isDefault &= options.tlsOptions.schannelTLS1_0Workaround == defaults.tlsOptions.schannelTLS1_0Workaround;
+ if (isDefault) {
+ ui.connectionMethod->setCurrentIndex(0);
+ }
+ else {
+ ui.connectionMethod->setCurrentIndex(1);
+ ui.manual_useTLS->setCurrentIndex(options.useTLS);
+ ui.manual_allowPLAINWithoutTLS->setChecked(options.allowPLAINWithoutTLS);
+ ui.manual_allowCompression->setChecked(options.useStreamCompression);
+ if (!options.manualHostname.empty()) {
+ ui.manual_manualHost->setChecked(true);
+ ui.manual_manualHostName->setText(P2QSTRING(options.manualHostname));
+ if (options.manualPort >=0) {
+ ui.manual_manualHostPort->setText(P2QSTRING(boost::lexical_cast<std::string>(options.manualPort)));
+ }
+ }
+ ui.manual_proxyType->setCurrentIndex(options.proxyType);
+ if (!options.manualProxyHostname.empty()) {
+ ui.manual_manualProxy->setChecked(true);
+ ui.manual_manualProxyHost->setText(P2QSTRING(options.manualProxyHostname));
+ ui.manual_manualProxyPort->setText(P2QSTRING(boost::lexical_cast<std::string>(options.manualProxyPort)));
+ }
+ ui.manual_forceTLS1_0->setChecked(options.tlsOptions.schannelTLS1_0Workaround);
+ }
+ } else {
+ ui.connectionMethod->setCurrentIndex(2);
+ ui.bosh_uri->setText(P2QSTRING(options.boshURL.toString()));
+ if (!options.boshHTTPConnectProxyURL.isEmpty()) {
+ ui.bosh_manualProxy->setChecked(true);
+ ui.bosh_manualProxyHost->setText(P2QSTRING(options.boshHTTPConnectProxyURL.getHost()));
+ if (options.boshHTTPConnectProxyURL.getPort()) {
+ ui.bosh_manualProxyPort->setText(P2QSTRING(boost::lexical_cast<std::string>(*options.boshHTTPConnectProxyURL.getPort())));
+ }
+ }
+ }
#ifndef HAVE_SCHANNEL
- ui.manual_forceTLS1_0->hide();
+ ui.manual_forceTLS1_0->hide();
#endif
}
void QtConnectionSettingsWindow::handleProxyTypeChanged(int index) {
- bool proxySettingsVisible = index != NoProxy && index != SystemProxy;
- ui.manual_manualProxy->setVisible(proxySettingsVisible);
- ui.manual_manualProxyHostLabel->setVisible(proxySettingsVisible);
- ui.manual_manualProxyHost->setVisible(proxySettingsVisible);
- ui.manual_manualProxyPortLabel->setVisible(proxySettingsVisible);
- ui.manual_manualProxyPort->setVisible(proxySettingsVisible);
+ bool proxySettingsVisible = index != NoProxy && index != SystemProxy;
+ ui.manual_manualProxy->setVisible(proxySettingsVisible);
+ ui.manual_manualProxyHostLabel->setVisible(proxySettingsVisible);
+ ui.manual_manualProxyHost->setVisible(proxySettingsVisible);
+ ui.manual_manualProxyPortLabel->setVisible(proxySettingsVisible);
+ ui.manual_manualProxyPort->setVisible(proxySettingsVisible);
}
void QtConnectionSettingsWindow::handleAcceptRequested() {
- if (ui.connectionMethod->currentIndex() != 2 || ui.bosh_uri->hasAcceptableInput()) {
- accept();
- }
- else {
- QMessageBox::critical(this, tr("Configuration invalid"), tr("The provided BOSH URL is not valid."));
- }
+ if (ui.connectionMethod->currentIndex() != 2 || ui.bosh_uri->hasAcceptableInput()) {
+ accept();
+ }
+ else {
+ QMessageBox::critical(this, tr("Configuration invalid"), tr("The provided BOSH URL is not valid."));
+ }
}
ClientOptions QtConnectionSettingsWindow::getOptions() {
- ClientOptions options;
- if (ui.connectionMethod->currentIndex() > 0) {
- /* Not automatic */
- if (ui.connectionMethod->currentIndex() == 1) {
- /* Manual */
- options.useTLS = static_cast<ClientOptions::UseTLS>(ui.manual_useTLS->currentIndex());
- options.useStreamCompression = ui.manual_allowCompression->isChecked();
- options.allowPLAINWithoutTLS = ui.manual_allowPLAINWithoutTLS->isChecked();
- options.tlsOptions.schannelTLS1_0Workaround = ui.manual_forceTLS1_0->isChecked();
- if (ui.manual_manualHost->isChecked()) {
- options.manualHostname = Q2PSTRING(ui.manual_manualHostName->text());
- try {
- options.manualPort = boost::lexical_cast<int>(Q2PSTRING(ui.manual_manualHostPort->text()));
- } catch (const boost::bad_lexical_cast&) {
- options.manualPort = -1;
- }
- }
- options.proxyType = static_cast<ClientOptions::ProxyType>(ui.manual_proxyType->currentIndex());
- if (ui.manual_manualProxy->isChecked()) {
- options.manualProxyHostname = Q2PSTRING(ui.manual_manualProxyHost->text());
- try {
- options.manualProxyPort = boost::lexical_cast<int>(Q2PSTRING(ui.manual_manualProxyPort->text()));
- } catch (const boost::bad_lexical_cast&) {}
- }
- }
- else {
- /* BOSH */
- options.boshURL = URL::fromString(Q2PSTRING(ui.bosh_uri->text()));
- if (ui.bosh_manualProxy->isChecked()) {
- std::string host = Q2PSTRING(ui.bosh_manualProxyHost->text());
- try {
- int port = boost::lexical_cast<int>(Q2PSTRING(ui.bosh_manualProxyPort->text()));
- options.boshHTTPConnectProxyURL = URL("http", host, port, "");
- } catch (const boost::bad_lexical_cast&) {
- options.boshHTTPConnectProxyURL = URL("http", host, "");
- }
- }
- }
- }
- return options;
+ ClientOptions options;
+ if (ui.connectionMethod->currentIndex() > 0) {
+ /* Not automatic */
+ if (ui.connectionMethod->currentIndex() == 1) {
+ /* Manual */
+ options.useTLS = static_cast<ClientOptions::UseTLS>(ui.manual_useTLS->currentIndex());
+ options.useStreamCompression = ui.manual_allowCompression->isChecked();
+ options.allowPLAINWithoutTLS = ui.manual_allowPLAINWithoutTLS->isChecked();
+ options.tlsOptions.schannelTLS1_0Workaround = ui.manual_forceTLS1_0->isChecked();
+ if (ui.manual_manualHost->isChecked()) {
+ options.manualHostname = Q2PSTRING(ui.manual_manualHostName->text());
+ try {
+ options.manualPort = boost::lexical_cast<int>(Q2PSTRING(ui.manual_manualHostPort->text()));
+ } catch (const boost::bad_lexical_cast&) {
+ options.manualPort = -1;
+ }
+ }
+ options.proxyType = static_cast<ClientOptions::ProxyType>(ui.manual_proxyType->currentIndex());
+ if (ui.manual_manualProxy->isChecked()) {
+ options.manualProxyHostname = Q2PSTRING(ui.manual_manualProxyHost->text());
+ try {
+ options.manualProxyPort = boost::lexical_cast<int>(Q2PSTRING(ui.manual_manualProxyPort->text()));
+ } catch (const boost::bad_lexical_cast&) {}
+ }
+ }
+ else {
+ /* BOSH */
+ options.boshURL = URL::fromString(Q2PSTRING(ui.bosh_uri->text()));
+ if (ui.bosh_manualProxy->isChecked()) {
+ std::string host = Q2PSTRING(ui.bosh_manualProxyHost->text());
+ try {
+ int port = boost::lexical_cast<int>(Q2PSTRING(ui.bosh_manualProxyPort->text()));
+ options.boshHTTPConnectProxyURL = URL("http", host, port, "");
+ } catch (const boost::bad_lexical_cast&) {
+ options.boshHTTPConnectProxyURL = URL("http", host, "");
+ }
+ }
+ }
+ }
+ return options;
}
}
diff --git a/Swift/QtUI/QtConnectionSettingsWindow.h b/Swift/QtUI/QtConnectionSettingsWindow.h
index a1d4739..f9fad84 100644
--- a/Swift/QtUI/QtConnectionSettingsWindow.h
+++ b/Swift/QtUI/QtConnectionSettingsWindow.h
@@ -13,25 +13,25 @@
#include <Swift/QtUI/ui_QtConnectionSettings.h>
namespace Swift {
- class QtConnectionSettingsWindow : public QDialog {
- Q_OBJECT
-
- public:
- QtConnectionSettingsWindow(const ClientOptions& options);
-
- ClientOptions getOptions();
-
- private slots:
- void handleProxyTypeChanged(int);
- void handleAcceptRequested();
-
- private:
- enum {
- NoProxy = 0,
- SystemProxy = 1,
- SOCKS5Proxy = 2,
- HTTPProxy = 3
- };
- Ui::QtConnectionSettings ui;
- };
+ class QtConnectionSettingsWindow : public QDialog {
+ Q_OBJECT
+
+ public:
+ QtConnectionSettingsWindow(const ClientOptions& options);
+
+ ClientOptions getOptions();
+
+ private slots:
+ void handleProxyTypeChanged(int);
+ void handleAcceptRequested();
+
+ private:
+ enum {
+ NoProxy = 0,
+ SystemProxy = 1,
+ SOCKS5Proxy = 2,
+ HTTPProxy = 3
+ };
+ Ui::QtConnectionSettings ui;
+ };
}
diff --git a/Swift/QtUI/QtContactEditWidget.cpp b/Swift/QtUI/QtContactEditWidget.cpp
index ad02bf9..ced9157 100644
--- a/Swift/QtUI/QtContactEditWidget.cpp
+++ b/Swift/QtUI/QtContactEditWidget.cpp
@@ -21,155 +21,155 @@
namespace Swift {
QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent) : QWidget(parent), nameRadioButton_(NULL), groups_(NULL) {
- QBoxLayout* layout = new QVBoxLayout(this);
- setContentsMargins(0,0,0,0);
- layout->setContentsMargins(0,0,0,0);
-
- nameLayout_ = new QHBoxLayout();
- suggestionsLayout_ = new QHBoxLayout();
- nameLayout_->addLayout(suggestionsLayout_);
-
- name_ = new QLineEdit(this);
- nameLayout_->addWidget(name_);
-
- throbberLabel_ = new QLabel(this);
- throbberLabel_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
- throbberLabel_->movie()->start();
- nameLayout_->addWidget(throbberLabel_);
-
- layout->addLayout(nameLayout_);
-
- layout->addWidget(new QLabel(tr("Groups:"), this));
-
- QScrollArea* groupsArea = new QScrollArea(this);
- layout->addWidget(groupsArea);
- groupsArea->setWidgetResizable(true);
- groupsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- groupsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
-
- QWidget* groups = new QWidget(groupsArea);
- groupsArea->setWidget(groups);
- QVBoxLayout* scrollLayout = new QVBoxLayout(groups);
-
- foreach (std::string group, allGroups) {
- QString groupName = doubleAmpersand(group);
- QCheckBox* check = new QCheckBox(groups);
- check->setText(groupName);
- check->setCheckState(Qt::Unchecked);
- checkBoxes_[group] = check;
- scrollLayout->addWidget(check);
- }
-
- QHBoxLayout* newGroupLayout = new QHBoxLayout();
- newGroup_ = new QCheckBox(groups);
- newGroup_->setText(tr("New Group:"));
- newGroup_->setCheckState(Qt::Unchecked);
- newGroupLayout->addWidget(newGroup_);
- newGroupName_ = new QLineEdit(groups);
- newGroupLayout->addWidget(newGroupName_);
- scrollLayout->addLayout(newGroupLayout);
-
- scrollLayout->addItem(new QSpacerItem(20, 73, QSizePolicy::Minimum, QSizePolicy::Expanding));
+ QBoxLayout* layout = new QVBoxLayout(this);
+ setContentsMargins(0,0,0,0);
+ layout->setContentsMargins(0,0,0,0);
+
+ nameLayout_ = new QHBoxLayout();
+ suggestionsLayout_ = new QHBoxLayout();
+ nameLayout_->addLayout(suggestionsLayout_);
+
+ name_ = new QLineEdit(this);
+ nameLayout_->addWidget(name_);
+
+ throbberLabel_ = new QLabel(this);
+ throbberLabel_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
+ throbberLabel_->movie()->start();
+ nameLayout_->addWidget(throbberLabel_);
+
+ layout->addLayout(nameLayout_);
+
+ layout->addWidget(new QLabel(tr("Groups:"), this));
+
+ QScrollArea* groupsArea = new QScrollArea(this);
+ layout->addWidget(groupsArea);
+ groupsArea->setWidgetResizable(true);
+ groupsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ groupsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+
+ QWidget* groups = new QWidget(groupsArea);
+ groupsArea->setWidget(groups);
+ QVBoxLayout* scrollLayout = new QVBoxLayout(groups);
+
+ foreach (std::string group, allGroups) {
+ QString groupName = doubleAmpersand(group);
+ QCheckBox* check = new QCheckBox(groups);
+ check->setText(groupName);
+ check->setCheckState(Qt::Unchecked);
+ checkBoxes_[group] = check;
+ scrollLayout->addWidget(check);
+ }
+
+ QHBoxLayout* newGroupLayout = new QHBoxLayout();
+ newGroup_ = new QCheckBox(groups);
+ newGroup_->setText(tr("New Group:"));
+ newGroup_->setCheckState(Qt::Unchecked);
+ newGroupLayout->addWidget(newGroup_);
+ newGroupName_ = new QLineEdit(groups);
+ newGroupLayout->addWidget(newGroupName_);
+ scrollLayout->addLayout(newGroupLayout);
+
+ scrollLayout->addItem(new QSpacerItem(20, 73, QSizePolicy::Minimum, QSizePolicy::Expanding));
}
void QtContactEditWidget::setName(const std::string& name) {
- name_->setText(P2QSTRING(name));
+ name_->setText(P2QSTRING(name));
}
std::string QtContactEditWidget::getName() const {
- std::string name = Q2PSTRING(name_->text());
- QList<QRadioButton*> buttons = findChildren<QRadioButton*>();
- foreach(const QRadioButton* button, buttons) {
- if (button->isChecked()) {
- if (button == nameRadioButton_) {
- name = Q2PSTRING(name_->text());
- } else {
- name = singleAmpersand(button->text());
- }
- break;
- }
- }
- return name;
+ std::string name = Q2PSTRING(name_->text());
+ QList<QRadioButton*> buttons = findChildren<QRadioButton*>();
+ foreach(const QRadioButton* button, buttons) {
+ if (button->isChecked()) {
+ if (button == nameRadioButton_) {
+ name = Q2PSTRING(name_->text());
+ } else {
+ name = singleAmpersand(button->text());
+ }
+ break;
+ }
+ }
+ return name;
}
void QtContactEditWidget::setSelectedGroups(const std::vector<std::string>& groups) {
- foreach (std::string group, groups) {
- checkBoxes_[group]->setCheckState(Qt::Checked);
- }
+ foreach (std::string group, groups) {
+ checkBoxes_[group]->setCheckState(Qt::Checked);
+ }
}
std::set<std::string> QtContactEditWidget::getSelectedGroups() const {
- std::set<std::string> groups;
- foreach(const CheckBoxMap::value_type& group, checkBoxes_) {
- if (group.second->checkState() == Qt::Checked) {
- groups.insert(group.first);
- }
- }
- if (newGroup_->checkState() == Qt::Checked && !newGroupName_->text().isEmpty()) {
- groups.insert(Q2PSTRING(newGroupName_->text()));
- }
- return groups;
+ std::set<std::string> groups;
+ foreach(const CheckBoxMap::value_type& group, checkBoxes_) {
+ if (group.second->checkState() == Qt::Checked) {
+ groups.insert(group.first);
+ }
+ }
+ if (newGroup_->checkState() == Qt::Checked && !newGroupName_->text().isEmpty()) {
+ groups.insert(Q2PSTRING(newGroupName_->text()));
+ }
+ return groups;
}
void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& suggestions) {
- throbberLabel_->movie()->stop();
- throbberLabel_->hide();
-
- // remove old suggestions except for the user input text field
- QLayoutItem* suggestionItem = NULL;
- while ((suggestionItem = suggestionsLayout_->itemAt(0)) && suggestionItem->widget() != name_) {
- QWidget* suggestionWidget = suggestionItem->widget();
- suggestionsLayout_->removeWidget(suggestionWidget);
- delete suggestionWidget;
- }
-
- // populate new suggestions
- foreach(const std::string& name, suggestions) {
- suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(doubleAmpersand(name), this));
- }
-
- nameRadioButton_ = new QRadioButton(tr("Name:"), this);
- suggestionsLayout_->insertWidget(nameLayout_->count(), nameRadioButton_);
-
- QRadioButton* suggestedRadioButton = 0;
- QList<QRadioButton*> radioButtons = findChildren<QRadioButton*>();
- foreach (QRadioButton* candidate, radioButtons) {
- if (candidate->text() == name_->text()) {
- suggestedRadioButton = candidate;
- break;
- }
- }
- if (suggestedRadioButton) {
- suggestedRadioButton->setChecked(true);
- } else {
- nameRadioButton_->setChecked(true);
- }
+ throbberLabel_->movie()->stop();
+ throbberLabel_->hide();
+
+ // remove old suggestions except for the user input text field
+ QLayoutItem* suggestionItem = NULL;
+ while ((suggestionItem = suggestionsLayout_->itemAt(0)) && suggestionItem->widget() != name_) {
+ QWidget* suggestionWidget = suggestionItem->widget();
+ suggestionsLayout_->removeWidget(suggestionWidget);
+ delete suggestionWidget;
+ }
+
+ // populate new suggestions
+ foreach(const std::string& name, suggestions) {
+ suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(doubleAmpersand(name), this));
+ }
+
+ nameRadioButton_ = new QRadioButton(tr("Name:"), this);
+ suggestionsLayout_->insertWidget(nameLayout_->count(), nameRadioButton_);
+
+ QRadioButton* suggestedRadioButton = 0;
+ QList<QRadioButton*> radioButtons = findChildren<QRadioButton*>();
+ foreach (QRadioButton* candidate, radioButtons) {
+ if (candidate->text() == name_->text()) {
+ suggestedRadioButton = candidate;
+ break;
+ }
+ }
+ if (suggestedRadioButton) {
+ suggestedRadioButton->setChecked(true);
+ } else {
+ nameRadioButton_->setChecked(true);
+ }
}
QString QtContactEditWidget::doubleAmpersand(const std::string& name) const {
- return P2QSTRING(name).replace("&", "&&");
+ return P2QSTRING(name).replace("&", "&&");
}
std::string QtContactEditWidget::singleAmpersand(const QString& name) const {
- return Q2PSTRING(QString(name).replace("&&", "&"));
+ return Q2PSTRING(QString(name).replace("&&", "&"));
}
void QtContactEditWidget::clear() {
- name_->clear();
- setSelectedGroups(std::vector<std::string>());
- newGroup_->setChecked(false);
- newGroupName_->clear();
- throbberLabel_->movie()->start();
- throbberLabel_->show();
-
- // clear suggestions
- while(suggestionsLayout_->count() != 0) {
- QLayoutItem *layoutItem = suggestionsLayout_->takeAt(0);
- delete layoutItem->widget();
- delete layoutItem;
- }
- nameRadioButton_ = NULL;
+ name_->clear();
+ setSelectedGroups(std::vector<std::string>());
+ newGroup_->setChecked(false);
+ newGroupName_->clear();
+ throbberLabel_->movie()->start();
+ throbberLabel_->show();
+
+ // clear suggestions
+ while(suggestionsLayout_->count() != 0) {
+ QLayoutItem *layoutItem = suggestionsLayout_->takeAt(0);
+ delete layoutItem->widget();
+ delete layoutItem;
+ }
+ nameRadioButton_ = NULL;
}
}
diff --git a/Swift/QtUI/QtContactEditWidget.h b/Swift/QtUI/QtContactEditWidget.h
index a9f1305..5c081e9 100644
--- a/Swift/QtUI/QtContactEditWidget.h
+++ b/Swift/QtUI/QtContactEditWidget.h
@@ -22,37 +22,37 @@ class QHBoxLayout;
class QRadioButton;
namespace Swift {
- class QtContactEditWidget : public QWidget {
- Q_OBJECT
-
- public:
- QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent);
-
- void setName(const std::string&);
- std::string getName() const;
-
- void setSelectedGroups(const std::vector<std::string>& groups);
- std::set<std::string> getSelectedGroups() const;
-
- void setNameSuggestions(const std::vector<std::string>& suggestions);
-
- void clear();
-
-
- private:
- QString doubleAmpersand(const std::string& name) const;
- std::string singleAmpersand(const QString& name) const;
- private:
- typedef std::map<std::string, QCheckBox*> CheckBoxMap;
- CheckBoxMap checkBoxes_;
- QHBoxLayout* nameLayout_;
- QHBoxLayout* suggestionsLayout_;
- QRadioButton* nameRadioButton_;
- QLineEdit* name_;
- QWidget* groups_;
- QCheckBox* newGroup_;
- QLineEdit* newGroupName_;
- QLabel* throbberLabel_;
- };
+ class QtContactEditWidget : public QWidget {
+ Q_OBJECT
+
+ public:
+ QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent);
+
+ void setName(const std::string&);
+ std::string getName() const;
+
+ void setSelectedGroups(const std::vector<std::string>& groups);
+ std::set<std::string> getSelectedGroups() const;
+
+ void setNameSuggestions(const std::vector<std::string>& suggestions);
+
+ void clear();
+
+
+ private:
+ QString doubleAmpersand(const std::string& name) const;
+ std::string singleAmpersand(const QString& name) const;
+ private:
+ typedef std::map<std::string, QCheckBox*> CheckBoxMap;
+ CheckBoxMap checkBoxes_;
+ QHBoxLayout* nameLayout_;
+ QHBoxLayout* suggestionsLayout_;
+ QRadioButton* nameRadioButton_;
+ QLineEdit* name_;
+ QWidget* groups_;
+ QCheckBox* newGroup_;
+ QLineEdit* newGroupName_;
+ QLabel* throbberLabel_;
+ };
}
diff --git a/Swift/QtUI/QtContactEditWindow.cpp b/Swift/QtUI/QtContactEditWindow.cpp
index abd247a..214f256 100644
--- a/Swift/QtUI/QtContactEditWindow.cpp
+++ b/Swift/QtUI/QtContactEditWindow.cpp
@@ -24,84 +24,84 @@
namespace Swift {
QtContactEditWindow::QtContactEditWindow() : contactEditWidget_(NULL) {
- resize(400,300);
- setWindowTitle(tr("Edit contact"));
- setContentsMargins(0,0,0,0);
-
- QBoxLayout* layout = new QVBoxLayout(this);
-
- jidLabel_ = new QLabel(this);
- jidLabel_->setAlignment(Qt::AlignHCenter);
- layout->addWidget(jidLabel_);
-
- groupsLayout_ = new QVBoxLayout();
- groupsLayout_->setContentsMargins(0,0,0,0);
- layout->addLayout(groupsLayout_);
-
- QHBoxLayout* buttonLayout = new QHBoxLayout();
- layout->addLayout(buttonLayout);
- QPushButton* removeButton = new QPushButton(tr("Remove contact"), this);
- connect(removeButton, SIGNAL(clicked()), this, SLOT(handleRemoveContact()));
- buttonLayout->addWidget(removeButton);
- QPushButton* okButton = new QPushButton(tr("OK"), this);
- okButton->setDefault( true );
- connect(okButton, SIGNAL(clicked()), this, SLOT(handleUpdateContact()));
- buttonLayout->addStretch();
- buttonLayout->addWidget(okButton);
+ resize(400,300);
+ setWindowTitle(tr("Edit contact"));
+ setContentsMargins(0,0,0,0);
+
+ QBoxLayout* layout = new QVBoxLayout(this);
+
+ jidLabel_ = new QLabel(this);
+ jidLabel_->setAlignment(Qt::AlignHCenter);
+ layout->addWidget(jidLabel_);
+
+ groupsLayout_ = new QVBoxLayout();
+ groupsLayout_->setContentsMargins(0,0,0,0);
+ layout->addLayout(groupsLayout_);
+
+ QHBoxLayout* buttonLayout = new QHBoxLayout();
+ layout->addLayout(buttonLayout);
+ QPushButton* removeButton = new QPushButton(tr("Remove contact"), this);
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(handleRemoveContact()));
+ buttonLayout->addWidget(removeButton);
+ QPushButton* okButton = new QPushButton(tr("OK"), this);
+ okButton->setDefault( true );
+ connect(okButton, SIGNAL(clicked()), this, SLOT(handleUpdateContact()));
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(okButton);
}
QtContactEditWindow::~QtContactEditWindow() {
}
void QtContactEditWindow::setNameSuggestions(const std::vector<std::string>& nameSuggestions) {
- if (contactEditWidget_) {
- contactEditWidget_->setNameSuggestions(nameSuggestions);
- }
+ if (contactEditWidget_) {
+ contactEditWidget_->setNameSuggestions(nameSuggestions);
+ }
}
void QtContactEditWindow::setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups) {
- delete contactEditWidget_;
- jid_ = jid;
- jidLabel_->setText("<b>" + P2QSTRING(jid.toString()) + "</b>");
-
- contactEditWidget_ = new QtContactEditWidget(allGroups, this);
- groupsLayout_->addWidget(contactEditWidget_);
- contactEditWidget_->setName(name);
- contactEditWidget_->setSelectedGroups(groups);
+ delete contactEditWidget_;
+ jid_ = jid;
+ jidLabel_->setText("<b>" + P2QSTRING(jid.toString()) + "</b>");
+
+ contactEditWidget_ = new QtContactEditWidget(allGroups, this);
+ groupsLayout_->addWidget(contactEditWidget_);
+ contactEditWidget_->setName(name);
+ contactEditWidget_->setSelectedGroups(groups);
}
void QtContactEditWindow::setEnabled(bool b) {
- QWidget::setEnabled(b);
+ QWidget::setEnabled(b);
}
void QtContactEditWindow::show() {
- QWidget::showNormal();
- QWidget::activateWindow();
- QWidget::raise();
+ QWidget::showNormal();
+ QWidget::activateWindow();
+ QWidget::raise();
}
void QtContactEditWindow::hide() {
- QWidget::hide();
+ QWidget::hide();
}
void QtContactEditWindow::handleRemoveContact() {
- if (confirmContactDeletion(jid_)) {
- onRemoveContactRequest();
- }
+ if (confirmContactDeletion(jid_)) {
+ onRemoveContactRequest();
+ }
}
bool QtContactEditWindow::confirmContactDeletion(const JID& jid) {
- QMessageBox msgBox;
- msgBox.setWindowTitle(tr("Confirm contact deletion"));
- msgBox.setText(tr("Are you sure you want to delete this contact?"));
- msgBox.setInformativeText(QString(tr("This will remove the contact '%1' from all groups they may be in.")).arg(P2QSTRING(jid.toString())));
- msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- msgBox.setDefaultButton(QMessageBox::Yes);
- return msgBox.exec() == QMessageBox::Yes;
+ QMessageBox msgBox;
+ msgBox.setWindowTitle(tr("Confirm contact deletion"));
+ msgBox.setText(tr("Are you sure you want to delete this contact?"));
+ msgBox.setInformativeText(QString(tr("This will remove the contact '%1' from all groups they may be in.")).arg(P2QSTRING(jid.toString())));
+ msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ msgBox.setDefaultButton(QMessageBox::Yes);
+ return msgBox.exec() == QMessageBox::Yes;
}
void QtContactEditWindow::handleUpdateContact() {
- onChangeContactRequest(contactEditWidget_->getName(), contactEditWidget_->getSelectedGroups());
+ onChangeContactRequest(contactEditWidget_->getName(), contactEditWidget_->getSelectedGroups());
}
}
diff --git a/Swift/QtUI/QtContactEditWindow.h b/Swift/QtUI/QtContactEditWindow.h
index a6c73b9..655fbb4 100644
--- a/Swift/QtUI/QtContactEditWindow.h
+++ b/Swift/QtUI/QtContactEditWindow.h
@@ -19,33 +19,33 @@ class QLabel;
class QVBoxLayout;
namespace Swift {
- class QtContactEditWidget;
+ class QtContactEditWidget;
- class QtContactEditWindow : public QWidget, public ContactEditWindow {
- Q_OBJECT
+ class QtContactEditWindow : public QWidget, public ContactEditWindow {
+ Q_OBJECT
- public:
- QtContactEditWindow();
- virtual ~QtContactEditWindow();
+ public:
+ QtContactEditWindow();
+ virtual ~QtContactEditWindow();
- virtual void setNameSuggestions(const std::vector<std::string>& nameSuggestions);
- virtual void setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups);
+ virtual void setNameSuggestions(const std::vector<std::string>& nameSuggestions);
+ virtual void setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups);
- void setEnabled(bool);
- void show();
- void hide();
+ void setEnabled(bool);
+ void show();
+ void hide();
- static bool confirmContactDeletion(const JID& jid);
+ static bool confirmContactDeletion(const JID& jid);
- private slots:
- void handleRemoveContact();
- void handleUpdateContact();
+ private slots:
+ void handleRemoveContact();
+ void handleUpdateContact();
- private:
- JID jid_;
- QVBoxLayout* groupsLayout_;
- QLabel* jidLabel_;
- QtContactEditWidget* contactEditWidget_;
- };
+ private:
+ JID jid_;
+ QVBoxLayout* groupsLayout_;
+ QLabel* jidLabel_;
+ QtContactEditWidget* contactEditWidget_;
+ };
}
diff --git a/Swift/QtUI/QtDBUSURIHandler.cpp b/Swift/QtUI/QtDBUSURIHandler.cpp
index 71a7016..c873676 100644
--- a/Swift/QtUI/QtDBUSURIHandler.cpp
+++ b/Swift/QtUI/QtDBUSURIHandler.cpp
@@ -14,28 +14,28 @@
using namespace Swift;
namespace {
- class DBUSAdaptor: public QDBusAbstractAdaptor {
- Q_OBJECT
- Q_CLASSINFO("D-Bus Interface", "im.swift.Swift.URIHandler");
- public:
- DBUSAdaptor(QtDBUSURIHandler* uriHandler) : QDBusAbstractAdaptor(uriHandler), uriHandler(uriHandler) {
- }
-
- public slots:
- void openURI(const QString& uri) {
- uriHandler->onURI(Q2PSTRING(uri));
- }
-
- private:
- QtDBUSURIHandler* uriHandler;
- };
+ class DBUSAdaptor: public QDBusAbstractAdaptor {
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "im.swift.Swift.URIHandler");
+ public:
+ DBUSAdaptor(QtDBUSURIHandler* uriHandler) : QDBusAbstractAdaptor(uriHandler), uriHandler(uriHandler) {
+ }
+
+ public slots:
+ void openURI(const QString& uri) {
+ uriHandler->onURI(Q2PSTRING(uri));
+ }
+
+ private:
+ QtDBUSURIHandler* uriHandler;
+ };
}
QtDBUSURIHandler::QtDBUSURIHandler() {
- new DBUSAdaptor(this);
- QDBusConnection connection = QDBusConnection::sessionBus();
- connection.registerService("im.swift.Swift.URIHandler");
- connection.registerObject("/", this);
+ new DBUSAdaptor(this);
+ QDBusConnection connection = QDBusConnection::sessionBus();
+ connection.registerService("im.swift.Swift.URIHandler");
+ connection.registerObject("/", this);
}
#include "QtDBUSURIHandler.moc"
diff --git a/Swift/QtUI/QtDBUSURIHandler.h b/Swift/QtUI/QtDBUSURIHandler.h
index cb16892..3cd12f7 100644
--- a/Swift/QtUI/QtDBUSURIHandler.h
+++ b/Swift/QtUI/QtDBUSURIHandler.h
@@ -11,8 +11,8 @@
#include <SwifTools/URIHandler/URIHandler.h>
namespace Swift {
- class QtDBUSURIHandler : public QObject, public URIHandler {
- public:
- QtDBUSURIHandler();
- };
+ class QtDBUSURIHandler : public QObject, public URIHandler {
+ public:
+ QtDBUSURIHandler();
+ };
}
diff --git a/Swift/QtUI/QtEditBookmarkWindow.cpp b/Swift/QtUI/QtEditBookmarkWindow.cpp
index 756e377..a17b1aa 100644
--- a/Swift/QtUI/QtEditBookmarkWindow.cpp
+++ b/Swift/QtUI/QtEditBookmarkWindow.cpp
@@ -10,20 +10,20 @@
namespace Swift {
QtEditBookmarkWindow::QtEditBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark) : eventStream_(eventStream), bookmark_(bookmark) {
- name_->setText(P2QSTRING(bookmark.getName()));
- room_->setText(P2QSTRING(bookmark.getRoom().toString()));
- autojoin_->setChecked(bookmark.getAutojoin());
- nick_->setText(bookmark.getNick() ? P2QSTRING(bookmark.getNick().get()) : "");
- password_->setText(bookmark.getPassword() ? P2QSTRING(bookmark.getPassword().get()) : "");
+ name_->setText(P2QSTRING(bookmark.getName()));
+ room_->setText(P2QSTRING(bookmark.getRoom().toString()));
+ autojoin_->setChecked(bookmark.getAutojoin());
+ nick_->setText(bookmark.getNick() ? P2QSTRING(bookmark.getNick().get()) : "");
+ password_->setText(bookmark.getPassword() ? P2QSTRING(bookmark.getPassword().get()) : "");
}
bool QtEditBookmarkWindow::commit() {
- boost::optional<MUCBookmark> bookmark = createBookmarkFromForm();
- if (!bookmark) {
- return false;
- }
- eventStream_->send(boost::shared_ptr<UIEvent>(new EditMUCBookmarkUIEvent(bookmark_, *bookmark)));
- return true;
+ boost::optional<MUCBookmark> bookmark = createBookmarkFromForm();
+ if (!bookmark) {
+ return false;
+ }
+ eventStream_->send(boost::shared_ptr<UIEvent>(new EditMUCBookmarkUIEvent(bookmark_, *bookmark)));
+ return true;
}
}
diff --git a/Swift/QtUI/QtEditBookmarkWindow.h b/Swift/QtUI/QtEditBookmarkWindow.h
index 1d7d08b..337ba1f 100644
--- a/Swift/QtUI/QtEditBookmarkWindow.h
+++ b/Swift/QtUI/QtEditBookmarkWindow.h
@@ -12,14 +12,14 @@
#include <Swift/QtUI/QtBookmarkDetailWindow.h>
namespace Swift {
- class QtEditBookmarkWindow : public QtBookmarkDetailWindow {
- Q_OBJECT
- public:
- QtEditBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark);
- bool commit();
-
- private:
- UIEventStream* eventStream_;
- MUCBookmark bookmark_;
- };
+ class QtEditBookmarkWindow : public QtBookmarkDetailWindow {
+ Q_OBJECT
+ public:
+ QtEditBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark);
+ bool commit();
+
+ private:
+ UIEventStream* eventStream_;
+ MUCBookmark bookmark_;
+ };
}
diff --git a/Swift/QtUI/QtElidingLabel.cpp b/Swift/QtUI/QtElidingLabel.cpp
index f5a39f0..4707f9f 100644
--- a/Swift/QtUI/QtElidingLabel.cpp
+++ b/Swift/QtUI/QtElidingLabel.cpp
@@ -8,17 +8,17 @@
namespace Swift {
QtElidingLabel::QtElidingLabel(QWidget* parent, Qt::WindowFlags f) : QLabel(parent, f) {
- fullText_ = "";
- dirty_ = true;
- setSizes();
- setTextFormat(Qt::PlainText);
+ fullText_ = "";
+ dirty_ = true;
+ setSizes();
+ setTextFormat(Qt::PlainText);
}
QtElidingLabel::QtElidingLabel(const QString& text, QWidget* parent, Qt::WindowFlags f) : QLabel(text, parent, f) {
- fullText_ = text;
- dirty_ = true;
- setSizes();
- setTextFormat(Qt::PlainText);
+ fullText_ = text;
+ dirty_ = true;
+ setSizes();
+ setTextFormat(Qt::PlainText);
}
QtElidingLabel::~QtElidingLabel() {
@@ -26,35 +26,35 @@ QtElidingLabel::~QtElidingLabel() {
}
QSize QtElidingLabel::sizeHint() const {
- return sizeHint_;
+ return sizeHint_;
}
void QtElidingLabel::setSizes() {
- setMinimumSize(1, minimumHeight());
+ setMinimumSize(1, minimumHeight());
}
void QtElidingLabel::setText(const QString& text) {
- fullText_ = text;
- QLabel::setText(text);
- sizeHint_ = QLabel::sizeHint();
- dirty_ = true;
+ fullText_ = text;
+ QLabel::setText(text);
+ sizeHint_ = QLabel::sizeHint();
+ dirty_ = true;
}
void QtElidingLabel::paintEvent(QPaintEvent* event) {
- QRect rect = contentsRect();
- dirty_ = dirty_ || rect != lastRect_;
- if (dirty_) {
- lastRect_ = rect;
- int fontWidth = fontMetrics().width(fullText_);
- if (fontWidth > rect.width()) {
- QString elidedText(fontMetrics().elidedText(fullText_, Qt::ElideRight, rect.width(), Qt::TextShowMnemonic));
- QLabel::setText(elidedText);
- } else {
- QLabel::setText(fullText_);
- }
- dirty_ = false;
- }
- QLabel::paintEvent(event);
+ QRect rect = contentsRect();
+ dirty_ = dirty_ || rect != lastRect_;
+ if (dirty_) {
+ lastRect_ = rect;
+ int fontWidth = fontMetrics().width(fullText_);
+ if (fontWidth > rect.width()) {
+ QString elidedText(fontMetrics().elidedText(fullText_, Qt::ElideRight, rect.width(), Qt::TextShowMnemonic));
+ QLabel::setText(elidedText);
+ } else {
+ QLabel::setText(fullText_);
+ }
+ dirty_ = false;
+ }
+ QLabel::paintEvent(event);
}
}
diff --git a/Swift/QtUI/QtElidingLabel.h b/Swift/QtUI/QtElidingLabel.h
index 84fa00f..9f590a8 100644
--- a/Swift/QtUI/QtElidingLabel.h
+++ b/Swift/QtUI/QtElidingLabel.h
@@ -9,23 +9,23 @@
#include <QLabel>
namespace Swift {
- class QtElidingLabel : public QLabel {
- Q_OBJECT
- public:
- QtElidingLabel(QWidget* parent = NULL, Qt::WindowFlags f = 0);
- QtElidingLabel(const QString &text, QWidget* parent = NULL, Qt::WindowFlags f = 0);
- void setText(const QString& text);
- virtual ~QtElidingLabel();
-
- virtual QSize sizeHint() const;
+ class QtElidingLabel : public QLabel {
+ Q_OBJECT
+ public:
+ QtElidingLabel(QWidget* parent = NULL, Qt::WindowFlags f = 0);
+ QtElidingLabel(const QString &text, QWidget* parent = NULL, Qt::WindowFlags f = 0);
+ void setText(const QString& text);
+ virtual ~QtElidingLabel();
- virtual void paintEvent(QPaintEvent* event);
+ virtual QSize sizeHint() const;
- private:
- void setSizes();
- bool dirty_;
- QString fullText_;
- QRect lastRect_;
- QSize sizeHint_;
- };
+ virtual void paintEvent(QPaintEvent* event);
+
+ private:
+ void setSizes();
+ bool dirty_;
+ QString fullText_;
+ QRect lastRect_;
+ QSize sizeHint_;
+ };
}
diff --git a/Swift/QtUI/QtEmoticonCell.cpp b/Swift/QtUI/QtEmoticonCell.cpp
index a781876..fe580aa 100644
--- a/Swift/QtUI/QtEmoticonCell.cpp
+++ b/Swift/QtUI/QtEmoticonCell.cpp
@@ -15,11 +15,11 @@
namespace Swift {
QtEmoticonCell::QtEmoticonCell(const QString emoticonAsText, QString filePath, QWidget* parent) : QLabel(parent), emoticonAsText_(emoticonAsText) {
- if (filePath.startsWith("qrc:/")) {
- filePath.remove(0, 3);
- }
- setPixmap(QPixmap(filePath));
- setToolTip(emoticonAsText_);
+ if (filePath.startsWith("qrc:/")) {
+ filePath.remove(0, 3);
+ }
+ setPixmap(QPixmap(filePath));
+ setToolTip(emoticonAsText_);
}
QtEmoticonCell::~QtEmoticonCell() {
@@ -27,8 +27,8 @@ QtEmoticonCell::~QtEmoticonCell() {
}
void QtEmoticonCell::mousePressEvent (QMouseEvent* event) {
- emit emoticonClicked(emoticonAsText_);
- QLabel::mousePressEvent(event);
+ emit emoticonClicked(emoticonAsText_);
+ QLabel::mousePressEvent(event);
}
}
diff --git a/Swift/QtUI/QtEmoticonCell.h b/Swift/QtUI/QtEmoticonCell.h
index 379f5d6..e408a83 100644
--- a/Swift/QtUI/QtEmoticonCell.h
+++ b/Swift/QtUI/QtEmoticonCell.h
@@ -18,17 +18,17 @@ class QMouseEvent;
namespace Swift {
- class QtEmoticonCell : public QLabel {
- Q_OBJECT
- public:
- QtEmoticonCell(const QString emoticonAsText, QString filePath, QWidget* parent = 0);
- ~QtEmoticonCell();
- virtual void mousePressEvent(QMouseEvent* event);
-
- signals:
- void emoticonClicked(QString emoticonAsText);
-
- private:
- QString emoticonAsText_;
- };
+ class QtEmoticonCell : public QLabel {
+ Q_OBJECT
+ public:
+ QtEmoticonCell(const QString emoticonAsText, QString filePath, QWidget* parent = 0);
+ ~QtEmoticonCell();
+ virtual void mousePressEvent(QMouseEvent* event);
+
+ signals:
+ void emoticonClicked(QString emoticonAsText);
+
+ private:
+ QString emoticonAsText_;
+ };
}
diff --git a/Swift/QtUI/QtEmoticonsGrid.cpp b/Swift/QtUI/QtEmoticonsGrid.cpp
index 82fb7e8..a81f516 100644
--- a/Swift/QtUI/QtEmoticonsGrid.cpp
+++ b/Swift/QtUI/QtEmoticonsGrid.cpp
@@ -25,23 +25,23 @@ namespace Swift {
typedef std::map<std::string, std::string> EmoticonsMap; // Without this typedef compiler complains when using foreach
QtEmoticonsGrid::QtEmoticonsGrid(const std::map<std::string, std::string>& emoticons, QWidget* parent) : QGridLayout(parent) {
- makeUniqueEmoticonsMap(emoticons);
-
- // Create grid: 3 columns, [uniqueEmoticons_.size()/3] rows
- int row = 0;
- int column = 0;
-
- foreach(EmoticonsMap::value_type emoticon, uniqueEmoticons_) {
- QtEmoticonCell* newCell = new QtEmoticonCell(P2QSTRING(emoticon.first), P2QSTRING(emoticon.second));
- addWidget(newCell, row, column);
- connect(newCell, SIGNAL(emoticonClicked(QString)), this, SLOT(emoticonClickedSlot(QString)));
-
- column++;
- if (column >= 3) {
- column = 0;
- row++;
- }
- }
+ makeUniqueEmoticonsMap(emoticons);
+
+ // Create grid: 3 columns, [uniqueEmoticons_.size()/3] rows
+ int row = 0;
+ int column = 0;
+
+ foreach(EmoticonsMap::value_type emoticon, uniqueEmoticons_) {
+ QtEmoticonCell* newCell = new QtEmoticonCell(P2QSTRING(emoticon.first), P2QSTRING(emoticon.second));
+ addWidget(newCell, row, column);
+ connect(newCell, SIGNAL(emoticonClicked(QString)), this, SLOT(emoticonClickedSlot(QString)));
+
+ column++;
+ if (column >= 3) {
+ column = 0;
+ row++;
+ }
+ }
}
QtEmoticonsGrid::~QtEmoticonsGrid() {
@@ -49,17 +49,17 @@ QtEmoticonsGrid::~QtEmoticonsGrid() {
}
void QtEmoticonsGrid::makeUniqueEmoticonsMap(const std::map<std::string, std::string>& emoticons) {
- std::set<std::string> paths;
- reverse_foreach(EmoticonsMap::value_type emoticon, emoticons) {
- if (paths.find(emoticon.second) == paths.end()) {
- uniqueEmoticons_.insert(emoticon);
- paths.insert(emoticon.second);
- }
- }
+ std::set<std::string> paths;
+ reverse_foreach(EmoticonsMap::value_type emoticon, emoticons) {
+ if (paths.find(emoticon.second) == paths.end()) {
+ uniqueEmoticons_.insert(emoticon);
+ paths.insert(emoticon.second);
+ }
+ }
}
void QtEmoticonsGrid::emoticonClickedSlot(QString emoticonAsText) {
- emit emoticonClicked(emoticonAsText);
+ emit emoticonClicked(emoticonAsText);
}
}
diff --git a/Swift/QtUI/QtEmoticonsGrid.h b/Swift/QtUI/QtEmoticonsGrid.h
index b045b26..0cae9ab 100644
--- a/Swift/QtUI/QtEmoticonsGrid.h
+++ b/Swift/QtUI/QtEmoticonsGrid.h
@@ -20,21 +20,21 @@ class QWidget;
namespace Swift {
- class QtEmoticonsGrid : public QGridLayout {
- Q_OBJECT
- public:
- explicit QtEmoticonsGrid(const std::map<std::string, std::string>& emoticons, QWidget* parent = 0);
- virtual ~QtEmoticonsGrid();
+ class QtEmoticonsGrid : public QGridLayout {
+ Q_OBJECT
+ public:
+ explicit QtEmoticonsGrid(const std::map<std::string, std::string>& emoticons, QWidget* parent = 0);
+ virtual ~QtEmoticonsGrid();
- signals:
- void emoticonClicked(QString emoticonAsText);
+ signals:
+ void emoticonClicked(QString emoticonAsText);
- public slots:
- void emoticonClickedSlot(QString emoticonAsText);
+ public slots:
+ void emoticonClickedSlot(QString emoticonAsText);
- private:
- void makeUniqueEmoticonsMap(const std::map<std::string, std::string>& emoticons);
+ private:
+ void makeUniqueEmoticonsMap(const std::map<std::string, std::string>& emoticons);
- std::map<std::string, std::string> uniqueEmoticons_;
- };
+ std::map<std::string, std::string> uniqueEmoticons_;
+ };
}
diff --git a/Swift/QtUI/QtFileTransferListItemModel.cpp b/Swift/QtUI/QtFileTransferListItemModel.cpp
index ef73f4f..d26733b 100644
--- a/Swift/QtUI/QtFileTransferListItemModel.cpp
+++ b/Swift/QtUI/QtFileTransferListItemModel.cpp
@@ -29,115 +29,115 @@ QtFileTransferListItemModel::QtFileTransferListItemModel(QObject *parent) : QAbs
}
QtFileTransferListItemModel::~QtFileTransferListItemModel() {
- if (fileTransferOverview) {
- fileTransferOverview->onNewFileTransferController.disconnect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1));
- fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this));
- }
+ if (fileTransferOverview) {
+ fileTransferOverview->onNewFileTransferController.disconnect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1));
+ fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this));
+ }
}
void QtFileTransferListItemModel::setFileTransferOverview(FileTransferOverview *overview) {
- if (fileTransferOverview) {
- fileTransferOverview->onNewFileTransferController.disconnect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1));
- fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this));
- }
- fileTransferOverview = overview;
- if (fileTransferOverview) {
- fileTransferOverview->onNewFileTransferController.connect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1));
- fileTransferOverview->onFileTransferListChanged.connect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this));
- }
- emit layoutAboutToBeChanged();
- emit layoutChanged();
+ if (fileTransferOverview) {
+ fileTransferOverview->onNewFileTransferController.disconnect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1));
+ fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this));
+ }
+ fileTransferOverview = overview;
+ if (fileTransferOverview) {
+ fileTransferOverview->onNewFileTransferController.connect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1));
+ fileTransferOverview->onFileTransferListChanged.connect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this));
+ }
+ emit layoutAboutToBeChanged();
+ emit layoutChanged();
}
void QtFileTransferListItemModel::handleNewFileTransferController(FileTransferController* newController) {
- emit layoutAboutToBeChanged();
- emit layoutChanged();
- dataChanged(createIndex(0,0), createIndex(fileTransferOverview->getFileTransfers().size(),4));
- newController->onStateChanged.connect(boost::bind(&QtFileTransferListItemModel::handleStateChange, this, fileTransferOverview->getFileTransfers().size() - 1));
- newController->onProgressChange.connect(boost::bind(&QtFileTransferListItemModel::handleProgressChange, this, fileTransferOverview->getFileTransfers().size() - 1));
+ emit layoutAboutToBeChanged();
+ emit layoutChanged();
+ dataChanged(createIndex(0,0), createIndex(fileTransferOverview->getFileTransfers().size(),4));
+ newController->onStateChanged.connect(boost::bind(&QtFileTransferListItemModel::handleStateChange, this, fileTransferOverview->getFileTransfers().size() - 1));
+ newController->onProgressChange.connect(boost::bind(&QtFileTransferListItemModel::handleProgressChange, this, fileTransferOverview->getFileTransfers().size() - 1));
}
void QtFileTransferListItemModel::handleFileTransferListChanged() {
- emit layoutAboutToBeChanged();
- emit layoutChanged();
+ emit layoutAboutToBeChanged();
+ emit layoutChanged();
}
void QtFileTransferListItemModel::handleStateChange(int index) {
- emit dataChanged(createIndex(index, 2), createIndex(index, 2));
+ emit dataChanged(createIndex(index, 2), createIndex(index, 2));
}
void QtFileTransferListItemModel::handleProgressChange(int index) {
- emit dataChanged(createIndex(index, 3), createIndex(index, 3));
+ emit dataChanged(createIndex(index, 3), createIndex(index, 3));
}
QVariant QtFileTransferListItemModel::headerData(int section, Qt::Orientation /* orientation */, int role) const {
- if (role != Qt::DisplayRole) return QVariant();
- if (section == Direction) return QVariant(QObject::tr("Direction"));
- if (section == OtherParty) return QVariant(QObject::tr("Other Party"));
- if (section == State) return QVariant(QObject::tr("State"));
- if (section == Progress) return QVariant(QObject::tr("Progress"));
- if (section == OverallSize) return QVariant(QObject::tr("Size"));
- return QVariant();
+ if (role != Qt::DisplayRole) return QVariant();
+ if (section == Direction) return QVariant(QObject::tr("Direction"));
+ if (section == OtherParty) return QVariant(QObject::tr("Other Party"));
+ if (section == State) return QVariant(QObject::tr("State"));
+ if (section == Progress) return QVariant(QObject::tr("Progress"));
+ if (section == OverallSize) return QVariant(QObject::tr("Size"));
+ return QVariant();
}
int QtFileTransferListItemModel::columnCount(const QModelIndex& /* parent */) const {
- return NoOfColumns;
+ return NoOfColumns;
}
QVariant QtFileTransferListItemModel::data(const QModelIndex &index, int role) const {
- if (role != Qt::DisplayRole || !index.isValid() ||
- !fileTransferOverview || static_cast<size_t>(index.row()) >= fileTransferOverview->getFileTransfers().size()) {
- return QVariant();
- }
- FileTransferController* controller = fileTransferOverview->getFileTransfers().at(index.row());
- if (index.column() == Direction) {
- return controller->isIncoming() ? QVariant(QObject::tr("Incoming")) : QVariant(QObject::tr("Outgoing"));
- }
- if (index.column() == OtherParty) {
- return QVariant(P2QSTRING(controller->getOtherParty().toString()));
- }
- if (index.column() == State) {
- FileTransfer::State state = controller->getState();
- switch(state.type) {
- case FileTransfer::State::Initial:
- assert(false);
- return QVariant("");
- case FileTransfer::State::WaitingForStart:
- return QVariant(QObject::tr("Waiting for start"));
- case FileTransfer::State::WaitingForAccept:
- return QVariant(QObject::tr("Waiting for other side to accept"));
- case FileTransfer::State::Negotiating:
- return QVariant(QObject::tr("Negotiating"));
- case FileTransfer::State::Transferring:
- return QVariant(QObject::tr("Transferring"));
- case FileTransfer::State::Finished:
- return QVariant(QObject::tr("Finished"));
- case FileTransfer::State::Failed:
- return QVariant(QObject::tr("Failed"));
- case FileTransfer::State::Canceled:
- return QVariant(QObject::tr("Canceled"));
- }
- }
-
- if (index.column() == Progress) {
- return QVariant(QString::number(controller->getProgress()));
- }
- if (index.column() == OverallSize) {
- return QVariant(P2QSTRING(formatSize((controller->getSize()))));
- }
- return QVariant();
+ if (role != Qt::DisplayRole || !index.isValid() ||
+ !fileTransferOverview || static_cast<size_t>(index.row()) >= fileTransferOverview->getFileTransfers().size()) {
+ return QVariant();
+ }
+ FileTransferController* controller = fileTransferOverview->getFileTransfers().at(index.row());
+ if (index.column() == Direction) {
+ return controller->isIncoming() ? QVariant(QObject::tr("Incoming")) : QVariant(QObject::tr("Outgoing"));
+ }
+ if (index.column() == OtherParty) {
+ return QVariant(P2QSTRING(controller->getOtherParty().toString()));
+ }
+ if (index.column() == State) {
+ FileTransfer::State state = controller->getState();
+ switch(state.type) {
+ case FileTransfer::State::Initial:
+ assert(false);
+ return QVariant("");
+ case FileTransfer::State::WaitingForStart:
+ return QVariant(QObject::tr("Waiting for start"));
+ case FileTransfer::State::WaitingForAccept:
+ return QVariant(QObject::tr("Waiting for other side to accept"));
+ case FileTransfer::State::Negotiating:
+ return QVariant(QObject::tr("Negotiating"));
+ case FileTransfer::State::Transferring:
+ return QVariant(QObject::tr("Transferring"));
+ case FileTransfer::State::Finished:
+ return QVariant(QObject::tr("Finished"));
+ case FileTransfer::State::Failed:
+ return QVariant(QObject::tr("Failed"));
+ case FileTransfer::State::Canceled:
+ return QVariant(QObject::tr("Canceled"));
+ }
+ }
+
+ if (index.column() == Progress) {
+ return QVariant(QString::number(controller->getProgress()));
+ }
+ if (index.column() == OverallSize) {
+ return QVariant(P2QSTRING(formatSize((controller->getSize()))));
+ }
+ return QVariant();
}
QModelIndex QtFileTransferListItemModel::parent(const QModelIndex& /* child */) const {
- return createIndex(0,0);
+ return createIndex(0,0);
}
int QtFileTransferListItemModel::rowCount(const QModelIndex& /* parent */) const {
- return fileTransferOverview ? fileTransferOverview->getFileTransfers().size() : 0;
+ return fileTransferOverview ? fileTransferOverview->getFileTransfers().size() : 0;
}
QModelIndex QtFileTransferListItemModel::index(int row, int column, const QModelIndex& /* parent */) const {
- return createIndex(row, column, static_cast<void*>(0));
+ return createIndex(row, column, static_cast<void*>(0));
}
}
diff --git a/Swift/QtUI/QtFileTransferListItemModel.h b/Swift/QtUI/QtFileTransferListItemModel.h
index 64cdca4..d0e0e42 100644
--- a/Swift/QtUI/QtFileTransferListItemModel.h
+++ b/Swift/QtUI/QtFileTransferListItemModel.h
@@ -20,42 +20,42 @@ class FileTransferController;
class FileTransferOverview;
class QtFileTransferListItemModel : public QAbstractItemModel {
- Q_OBJECT
+ Q_OBJECT
public:
- explicit QtFileTransferListItemModel(QObject *parent = 0);
- virtual ~QtFileTransferListItemModel();
+ explicit QtFileTransferListItemModel(QObject *parent = 0);
+ virtual ~QtFileTransferListItemModel();
- void setFileTransferOverview(FileTransferOverview*);
+ void setFileTransferOverview(FileTransferOverview*);
- QVariant headerData(int section, Qt::Orientation orientation, int role) const;
- int columnCount(const QModelIndex &parent) const;
- QVariant data(const QModelIndex &index, int role) const;
- QModelIndex parent(const QModelIndex &child) const;
- int rowCount(const QModelIndex &parent) const;
- QModelIndex index(int row, int column, const QModelIndex &parent) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ int columnCount(const QModelIndex &parent) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ QModelIndex parent(const QModelIndex &child) const;
+ int rowCount(const QModelIndex &parent) const;
+ QModelIndex index(int row, int column, const QModelIndex &parent) const;
private:
- enum Columns {
- Direction = 0,
- OtherParty,
- State,
- Progress,
- OverallSize,
- NoOfColumns
- };
+ enum Columns {
+ Direction = 0,
+ OtherParty,
+ State,
+ Progress,
+ OverallSize,
+ NoOfColumns
+ };
private:
- void handleNewFileTransferController(FileTransferController*);
- void handleFileTransferListChanged();
- void handleStateChange(int index);
- void handleProgressChange(int index);
+ void handleNewFileTransferController(FileTransferController*);
+ void handleFileTransferListChanged();
+ void handleStateChange(int index);
+ void handleProgressChange(int index);
signals:
public slots:
private:
- FileTransferOverview *fileTransferOverview;
+ FileTransferOverview *fileTransferOverview;
};
diff --git a/Swift/QtUI/QtFileTransferListWidget.cpp b/Swift/QtUI/QtFileTransferListWidget.cpp
index d95cd06..f67b510 100644
--- a/Swift/QtUI/QtFileTransferListWidget.cpp
+++ b/Swift/QtUI/QtFileTransferListWidget.cpp
@@ -26,86 +26,86 @@
namespace Swift {
QtFileTransferListWidget::QtFileTransferListWidget() : fileTransferOverview(0) {
- QVBoxLayout* layout = new QVBoxLayout(this);
- layout->setSpacing(0);
- layout->setContentsMargins(0,0,0,0);
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->setSpacing(0);
+ layout->setContentsMargins(0,0,0,0);
- treeView = new QTreeView(this);
- treeView->setRootIsDecorated(false);
- treeView->setItemsExpandable(false);
- layout->addWidget(treeView);
+ treeView = new QTreeView(this);
+ treeView->setRootIsDecorated(false);
+ treeView->setItemsExpandable(false);
+ layout->addWidget(treeView);
- itemModel = new QtFileTransferListItemModel();
- treeView->setModel(itemModel);
+ itemModel = new QtFileTransferListItemModel();
+ treeView->setModel(itemModel);
- QWidget* bottom = new QWidget(this);
- layout->addWidget(bottom);
- bottom->setAutoFillBackground(true);
+ QWidget* bottom = new QWidget(this);
+ layout->addWidget(bottom);
+ bottom->setAutoFillBackground(true);
- QHBoxLayout* buttonLayout = new QHBoxLayout(bottom);
- buttonLayout->setContentsMargins(10,0,20,0);
- buttonLayout->setSpacing(0);
+ QHBoxLayout* buttonLayout = new QHBoxLayout(bottom);
+ buttonLayout->setContentsMargins(10,0,20,0);
+ buttonLayout->setSpacing(0);
- clearFinished = new QPushButton(tr("Clear all"), bottom);
- clearFinished->setEnabled(false);
- connect(clearFinished, SIGNAL(clicked()), this, SLOT(clearInactiveTransfers()));
- buttonLayout->addWidget(clearFinished);
+ clearFinished = new QPushButton(tr("Clear all"), bottom);
+ clearFinished->setEnabled(false);
+ connect(clearFinished, SIGNAL(clicked()), this, SLOT(clearInactiveTransfers()));
+ buttonLayout->addWidget(clearFinished);
- setWindowTitle(tr("File Transfer List"));
- emit titleUpdated();
+ setWindowTitle(tr("File Transfer List"));
+ emit titleUpdated();
}
QtFileTransferListWidget::~QtFileTransferListWidget() {
- if (fileTransferOverview) {
- fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this));
- fileTransferOverview = NULL;
- }
- delete itemModel;
+ if (fileTransferOverview) {
+ fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this));
+ fileTransferOverview = NULL;
+ }
+ delete itemModel;
}
void QtFileTransferListWidget::showEvent(QShowEvent* event) {
- emit windowOpening();
- emit titleUpdated(); /* This just needs to be somewhere after construction */
- QWidget::showEvent(event);
+ emit windowOpening();
+ emit titleUpdated(); /* This just needs to be somewhere after construction */
+ QWidget::showEvent(event);
}
void QtFileTransferListWidget::handleFileTransferListChanged() {
- clearFinished->setEnabled(fileTransferOverview->isClearable());
+ clearFinished->setEnabled(fileTransferOverview->isClearable());
}
void QtFileTransferListWidget::clearInactiveTransfers() {
- fileTransferOverview->clearFinished();
+ fileTransferOverview->clearFinished();
}
void QtFileTransferListWidget::show() {
- QWidget::show();
- emit windowOpening();
+ QWidget::show();
+ emit windowOpening();
}
void QtFileTransferListWidget::activate() {
- emit wantsToActivate();
+ emit wantsToActivate();
}
void QtFileTransferListWidget::setFileTransferOverview(FileTransferOverview *overview) {
- if (fileTransferOverview) {
- fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this));
- fileTransferOverview = NULL;
- }
- if (overview) {
- fileTransferOverview = overview;
- fileTransferOverview->onFileTransferListChanged.connect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this));
- clearFinished->setEnabled(fileTransferOverview->isClearable());
- }
- itemModel->setFileTransferOverview(overview);
+ if (fileTransferOverview) {
+ fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this));
+ fileTransferOverview = NULL;
+ }
+ if (overview) {
+ fileTransferOverview = overview;
+ fileTransferOverview->onFileTransferListChanged.connect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this));
+ clearFinished->setEnabled(fileTransferOverview->isClearable());
+ }
+ itemModel->setFileTransferOverview(overview);
}
std::string QtFileTransferListWidget::getID() const {
- return "QtFileTransferListWidget";
+ return "QtFileTransferListWidget";
}
void QtFileTransferListWidget::closeEvent(QCloseEvent* event) {
- emit windowClosing();
- event->accept();
+ emit windowClosing();
+ event->accept();
}
}
diff --git a/Swift/QtUI/QtFileTransferListWidget.h b/Swift/QtUI/QtFileTransferListWidget.h
index 740eb15..cfc7dd2 100644
--- a/Swift/QtUI/QtFileTransferListWidget.h
+++ b/Swift/QtUI/QtFileTransferListWidget.h
@@ -27,33 +27,33 @@ class FileTransferOverview;
class QtFileTransferListItemModel;
class QtFileTransferListWidget : public QtTabbable, public FileTransferListWidget {
- Q_OBJECT
+ Q_OBJECT
public:
- QtFileTransferListWidget();
- virtual ~QtFileTransferListWidget();
+ QtFileTransferListWidget();
+ virtual ~QtFileTransferListWidget();
- void show();
- void activate();
+ void show();
+ void activate();
- void setFileTransferOverview(FileTransferOverview *);
+ void setFileTransferOverview(FileTransferOverview *);
- virtual std::string getID() const;
+ virtual std::string getID() const;
private:
- virtual void closeEvent(QCloseEvent* event);
- virtual void showEvent(QShowEvent* event);
- void handleFileTransferListChanged();
+ virtual void closeEvent(QCloseEvent* event);
+ virtual void showEvent(QShowEvent* event);
+ void handleFileTransferListChanged();
private slots:
- void clearInactiveTransfers();
+ void clearInactiveTransfers();
private:
- QTreeView* treeView;
+ QTreeView* treeView;
- QtFileTransferListItemModel* itemModel;
- FileTransferOverview* fileTransferOverview;
- QPushButton* clearFinished;
+ QtFileTransferListItemModel* itemModel;
+ FileTransferOverview* fileTransferOverview;
+ QPushButton* clearFinished;
};
}
diff --git a/Swift/QtUI/QtFormResultItemModel.cpp b/Swift/QtUI/QtFormResultItemModel.cpp
index 6a48bc5..60cf0c0 100644
--- a/Swift/QtUI/QtFormResultItemModel.cpp
+++ b/Swift/QtUI/QtFormResultItemModel.cpp
@@ -29,67 +29,67 @@ QtFormResultItemModel::QtFormResultItemModel(QObject* parent, Form::ref formResu
}
void QtFormResultItemModel::setForm(Form::ref formResult) {
- emit layoutAboutToBeChanged();
- formResult_ = formResult;
- emit layoutChanged();
+ emit layoutAboutToBeChanged();
+ formResult_ = formResult;
+ emit layoutChanged();
}
const Form::ref QtFormResultItemModel::getForm() const {
- return formResult_;
+ return formResult_;
}
QVariant QtFormResultItemModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const {
- if (!formResult_) return QVariant();
- if (role != Qt::DisplayRole) return QVariant();
- if (static_cast<size_t>(section) >= formResult_->getReportedFields().size()) return QVariant();
- return QVariant(P2QSTRING(formResult_->getReportedFields().at(section)->getLabel()));
+ if (!formResult_) return QVariant();
+ if (role != Qt::DisplayRole) return QVariant();
+ if (static_cast<size_t>(section) >= formResult_->getReportedFields().size()) return QVariant();
+ return QVariant(P2QSTRING(formResult_->getReportedFields().at(section)->getLabel()));
}
int QtFormResultItemModel::rowCount(const QModelIndex &/*parent*/) const {
- if (!formResult_) return 0;
- return formResult_->getItems().size();
+ if (!formResult_) return 0;
+ return formResult_->getItems().size();
}
int QtFormResultItemModel::columnCount(const QModelIndex &/*parent*/) const {
- if (!formResult_) return 0;
- return formResult_->getReportedFields().size();
+ if (!formResult_) return 0;
+ return formResult_->getReportedFields().size();
}
QVariant QtFormResultItemModel::data(const QModelIndex &index, int role) const {
- if (!formResult_) return QVariant();
- if (role != Qt::DisplayRole || !index.isValid()) {
- return QVariant();
- }
+ if (!formResult_) return QVariant();
+ if (role != Qt::DisplayRole || !index.isValid()) {
+ return QVariant();
+ }
- if (static_cast<size_t>(index.row()) >= formResult_->getItems().size()) return QVariant();
- if (static_cast<size_t>(index.column()) >= formResult_->getReportedFields().size()) return QVariant();
+ if (static_cast<size_t>(index.row()) >= formResult_->getItems().size()) return QVariant();
+ if (static_cast<size_t>(index.column()) >= formResult_->getReportedFields().size()) return QVariant();
- Form::FormItem item = formResult_->getItems().at(index.row());
+ Form::FormItem item = formResult_->getItems().at(index.row());
- return QVariant(P2QSTRING(getFieldValue(item, index.column())));
+ return QVariant(P2QSTRING(getFieldValue(item, index.column())));
}
const std::string QtFormResultItemModel::getFieldValue(const Form::FormItem& item, const int column) const {
- // determine field name
- std::string name = formResult_->getReportedFields().at(column)->getName();
-
- foreach(FormField::ref field, item) {
- if (field->getName() == name) {
- std::string delimiter = "";
- if (field->getType() == FormField::TextMultiType) {
- delimiter = "\n";
- }
- else if (field->getType() == FormField::JIDMultiType) {
- delimiter = ", ";
- }
- else if (field->getType() == FormField::ListMultiType) {
- delimiter = ", ";
- }
- return boost::algorithm::join(field->getValues(), delimiter);
- }
- }
-
- return "";
+ // determine field name
+ std::string name = formResult_->getReportedFields().at(column)->getName();
+
+ foreach(FormField::ref field, item) {
+ if (field->getName() == name) {
+ std::string delimiter = "";
+ if (field->getType() == FormField::TextMultiType) {
+ delimiter = "\n";
+ }
+ else if (field->getType() == FormField::JIDMultiType) {
+ delimiter = ", ";
+ }
+ else if (field->getType() == FormField::ListMultiType) {
+ delimiter = ", ";
+ }
+ return boost::algorithm::join(field->getValues(), delimiter);
+ }
+ }
+
+ return "";
}
}
diff --git a/Swift/QtUI/QtFormResultItemModel.h b/Swift/QtUI/QtFormResultItemModel.h
index f383f74..47f3549 100644
--- a/Swift/QtUI/QtFormResultItemModel.h
+++ b/Swift/QtUI/QtFormResultItemModel.h
@@ -13,24 +13,24 @@
namespace Swift {
class QtFormResultItemModel : public QAbstractTableModel {
- Q_OBJECT
- public:
- QtFormResultItemModel(QObject* parent);
- QtFormResultItemModel(QObject* parent, Form::ref formResult);
+ Q_OBJECT
+ public:
+ QtFormResultItemModel(QObject* parent);
+ QtFormResultItemModel(QObject* parent, Form::ref formResult);
- void setForm(Form::ref formResult);
- const Form::ref getForm() const;
+ void setForm(Form::ref formResult);
+ const Form::ref getForm() const;
- virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
- virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- private:
- const std::string getFieldValue(const Form::FormItem& item, const int column) const;
+ private:
+ const std::string getFieldValue(const Form::FormItem& item, const int column) const;
- private:
- Form::ref formResult_;
+ private:
+ Form::ref formResult_;
};
}
diff --git a/Swift/QtUI/QtFormWidget.cpp b/Swift/QtUI/QtFormWidget.cpp
index ea452dc..13049ca 100644
--- a/Swift/QtUI/QtFormWidget.cpp
+++ b/Swift/QtUI/QtFormWidget.cpp
@@ -26,46 +26,46 @@
namespace Swift {
QtFormWidget::QtFormWidget(Form::ref form, QWidget* parent) : QWidget(parent), form_(form) {
- QGridLayout* thisLayout = new QGridLayout(this);
- int row = 0;
- if (!form->getTitle().empty()) {
- QLabel* instructions = new QLabel(("<b>" + form->getTitle() + "</b>").c_str(), this);
- thisLayout->addWidget(instructions, row++, 0, 1, 2);
- }
- if (!form->getInstructions().empty()) {
- QLabel* instructions = new QLabel(form->getInstructions().c_str(), this);
- thisLayout->addWidget(instructions, row++, 0, 1, 2);
- }
- QScrollArea* scrollArea = new QScrollArea(this);
- thisLayout->addWidget(scrollArea);
- QWidget* scroll = new QWidget(this);
- QGridLayout* layout = new QGridLayout(scroll);
- const std::vector<Form::FormItem> items = form->getItems();
- if (items.empty()) { /* single item forms */
- foreach (FormField::ref field, form->getFields()) {
- QWidget* widget = createWidget(field, field->getType(), 0);
- if (widget) {
- layout->addWidget(new QLabel(field->getLabel().c_str(), this), row, 0);
- layout->addWidget(widget, row++, 1);
- }
- }
- } else { /* multi-item forms */
- const Form::FormItem& headers = form->getFields();
- for (size_t i = 0; i < items.size(); ++i) {
- const Form::FormItem& item = items[i];
- assert(item.size() == headers.size());
- for (size_t j = 0; j < item.size(); ++j) {
- QWidget* widget = createWidget(item[j], headers[j]->getType(), i);
- if (widget) {
- layout->addWidget(new QLabel(item[j]->getLabel().c_str(), this), row, 0);
- layout->addWidget(widget, row++, 1);
- }
- }
- }
- }
- scrollArea->setWidget(scroll);
- scrollArea->setWidgetResizable(true);
- setEditable(form->getType() != Form::CancelType && form->getType() != Form::ResultType);
+ QGridLayout* thisLayout = new QGridLayout(this);
+ int row = 0;
+ if (!form->getTitle().empty()) {
+ QLabel* instructions = new QLabel(("<b>" + form->getTitle() + "</b>").c_str(), this);
+ thisLayout->addWidget(instructions, row++, 0, 1, 2);
+ }
+ if (!form->getInstructions().empty()) {
+ QLabel* instructions = new QLabel(form->getInstructions().c_str(), this);
+ thisLayout->addWidget(instructions, row++, 0, 1, 2);
+ }
+ QScrollArea* scrollArea = new QScrollArea(this);
+ thisLayout->addWidget(scrollArea);
+ QWidget* scroll = new QWidget(this);
+ QGridLayout* layout = new QGridLayout(scroll);
+ const std::vector<Form::FormItem> items = form->getItems();
+ if (items.empty()) { /* single item forms */
+ foreach (FormField::ref field, form->getFields()) {
+ QWidget* widget = createWidget(field, field->getType(), 0);
+ if (widget) {
+ layout->addWidget(new QLabel(field->getLabel().c_str(), this), row, 0);
+ layout->addWidget(widget, row++, 1);
+ }
+ }
+ } else { /* multi-item forms */
+ const Form::FormItem& headers = form->getFields();
+ for (size_t i = 0; i < items.size(); ++i) {
+ const Form::FormItem& item = items[i];
+ assert(item.size() == headers.size());
+ for (size_t j = 0; j < item.size(); ++j) {
+ QWidget* widget = createWidget(item[j], headers[j]->getType(), i);
+ if (widget) {
+ layout->addWidget(new QLabel(item[j]->getLabel().c_str(), this), row, 0);
+ layout->addWidget(widget, row++, 1);
+ }
+ }
+ }
+ }
+ scrollArea->setWidget(scroll);
+ scrollArea->setWidgetResizable(true);
+ setEditable(form->getType() != Form::CancelType && form->getType() != Form::ResultType);
}
QtFormWidget::~QtFormWidget() {
@@ -73,168 +73,168 @@ QtFormWidget::~QtFormWidget() {
}
QListWidget* QtFormWidget::createList(FormField::ref field) {
- QListWidget* listWidget = new QListWidget(this);
- listWidget->setSortingEnabled(false);
- listWidget->setSelectionMode(field->getType() == FormField::ListMultiType ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection);
- std::vector<bool> selected;
- /* if this is an editable form, use the 'options' list, otherwise use the 'values' list */
- if (form_->getType() != Form::FormType) {
- foreach (const std::string& value, field->getValues()) {
- listWidget->addItem(P2QSTRING(value));
- selected.push_back(false);
- }
- } else {
- foreach (FormField::Option option, field->getOptions()) {
- listWidget->addItem(option.label.c_str());
- if (field->getType() == FormField::ListSingleType) {
- selected.push_back(!field->getValues().empty() && option.value == field->getValues()[0]);
- }
- else if (field->getType() == FormField::ListMultiType) {
- std::string text = option.value;
- selected.push_back(std::find(field->getValues().begin(), field->getValues().end(), text) != field->getValues().end());
- }
- }
- }
- for (int i = 0; i < listWidget->count(); i++) {
- QListWidgetItem* item = listWidget->item(i);
- item->setSelected(selected[i]);
- }
- return listWidget;
+ QListWidget* listWidget = new QListWidget(this);
+ listWidget->setSortingEnabled(false);
+ listWidget->setSelectionMode(field->getType() == FormField::ListMultiType ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection);
+ std::vector<bool> selected;
+ /* if this is an editable form, use the 'options' list, otherwise use the 'values' list */
+ if (form_->getType() != Form::FormType) {
+ foreach (const std::string& value, field->getValues()) {
+ listWidget->addItem(P2QSTRING(value));
+ selected.push_back(false);
+ }
+ } else {
+ foreach (FormField::Option option, field->getOptions()) {
+ listWidget->addItem(option.label.c_str());
+ if (field->getType() == FormField::ListSingleType) {
+ selected.push_back(!field->getValues().empty() && option.value == field->getValues()[0]);
+ }
+ else if (field->getType() == FormField::ListMultiType) {
+ std::string text = option.value;
+ selected.push_back(std::find(field->getValues().begin(), field->getValues().end(), text) != field->getValues().end());
+ }
+ }
+ }
+ for (int i = 0; i < listWidget->count(); i++) {
+ QListWidgetItem* item = listWidget->item(i);
+ item->setSelected(selected[i]);
+ }
+ return listWidget;
}
QWidget* QtFormWidget::createWidget(FormField::ref field, const FormField::Type type, const size_t index) {
- QWidget* widget = NULL;
- if (type == FormField::BooleanType) {
- QCheckBox* checkWidget = new QCheckBox(this);
- checkWidget->setCheckState(field->getBoolValue() ? Qt::Checked : Qt::Unchecked);
- widget = checkWidget;
- }
- if (type == FormField::FixedType) {
- QString value = field->getFixedValue().c_str();
- widget = new QLabel(value, this);
- }
- if (type == FormField::ListSingleType) {
- widget = createList(field);
- }
- if (type == FormField::TextMultiType) {
- QString value = field->getTextMultiValue().c_str();
- QTextEdit* textWidget = new QTextEdit(this);
- textWidget->setPlainText(value);
- widget = textWidget;
- }
- if (type == FormField::TextPrivateType) {
- QString value = field->getTextPrivateValue().c_str();
- QLineEdit* lineWidget = new QLineEdit(value, this);
- lineWidget->setEchoMode(QLineEdit::Password);
- widget = lineWidget;
- }
- if (type == FormField::TextSingleType) {
- QString value = field->getTextSingleValue().c_str();
- widget = new QLineEdit(value, this);
- }
- if (type == FormField::JIDSingleType) {
- QString value = field->getJIDSingleValue().toString().c_str();
- widget = new QLineEdit(value, this);
- }
- if (type == FormField::JIDMultiType) {
- QString text = boost::join(field->getValues(), "\n").c_str();
- QTextEdit* textWidget = new QTextEdit(this);
- textWidget->setPlainText(text);
- widget = textWidget;
- }
- if (type == FormField::ListMultiType) {
- widget = createList(field);
- }
- std::string indexString;
- if (index) {
- /* for multi-item forms we need to distinguish between the different rows */
- indexString = boost::lexical_cast<std::string>(index);
- }
- fields_[field->getName() + indexString] = widget;
- return widget;
+ QWidget* widget = NULL;
+ if (type == FormField::BooleanType) {
+ QCheckBox* checkWidget = new QCheckBox(this);
+ checkWidget->setCheckState(field->getBoolValue() ? Qt::Checked : Qt::Unchecked);
+ widget = checkWidget;
+ }
+ if (type == FormField::FixedType) {
+ QString value = field->getFixedValue().c_str();
+ widget = new QLabel(value, this);
+ }
+ if (type == FormField::ListSingleType) {
+ widget = createList(field);
+ }
+ if (type == FormField::TextMultiType) {
+ QString value = field->getTextMultiValue().c_str();
+ QTextEdit* textWidget = new QTextEdit(this);
+ textWidget->setPlainText(value);
+ widget = textWidget;
+ }
+ if (type == FormField::TextPrivateType) {
+ QString value = field->getTextPrivateValue().c_str();
+ QLineEdit* lineWidget = new QLineEdit(value, this);
+ lineWidget->setEchoMode(QLineEdit::Password);
+ widget = lineWidget;
+ }
+ if (type == FormField::TextSingleType) {
+ QString value = field->getTextSingleValue().c_str();
+ widget = new QLineEdit(value, this);
+ }
+ if (type == FormField::JIDSingleType) {
+ QString value = field->getJIDSingleValue().toString().c_str();
+ widget = new QLineEdit(value, this);
+ }
+ if (type == FormField::JIDMultiType) {
+ QString text = boost::join(field->getValues(), "\n").c_str();
+ QTextEdit* textWidget = new QTextEdit(this);
+ textWidget->setPlainText(text);
+ widget = textWidget;
+ }
+ if (type == FormField::ListMultiType) {
+ widget = createList(field);
+ }
+ std::string indexString;
+ if (index) {
+ /* for multi-item forms we need to distinguish between the different rows */
+ indexString = boost::lexical_cast<std::string>(index);
+ }
+ fields_[field->getName() + indexString] = widget;
+ return widget;
}
Form::ref QtFormWidget::getCompletedForm() {
- Form::ref result(new Form(Form::SubmitType));
- foreach (boost::shared_ptr<FormField> field, form_->getFields()) {
- boost::shared_ptr<FormField> resultField = boost::make_shared<FormField>(field->getType());
- if (field->getType() == FormField::BooleanType) {
- resultField->setBoolValue(qobject_cast<QCheckBox*>(fields_[field->getName()])->checkState() == Qt::Checked);
- }
- if (field->getType() == FormField::FixedType || field->getType() == FormField::HiddenType) {
- resultField->addValue(field->getValues().empty() ? "" : field->getValues()[0]);
- }
- if (field->getType() == FormField::ListSingleType) {
- QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]);
- if (listWidget->selectedItems().size() > 0) {
- int i = listWidget->row(listWidget->selectedItems()[0]);
- resultField->addValue(field->getOptions()[i].value);
- }
- }
- if (field->getType() == FormField::TextMultiType) {
- QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]);
- QString string = widget->toPlainText();
- if (!string.isEmpty()) {
- resultField->setTextMultiValue(Q2PSTRING(string));
- }
- }
- if (field->getType() == FormField::TextPrivateType || field->getType() == FormField::TextSingleType || field->getType() == FormField::JIDSingleType) {
- QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]);
- QString string = widget->text();
- if (!string.isEmpty()) {
- resultField->addValue(Q2PSTRING(string));
- }
- }
- if (field->getType() == FormField::JIDMultiType) {
- QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]);
- QString string = widget->toPlainText();
- if (!string.isEmpty()) {
- QStringList lines = string.split("\n");
- foreach (QString line, lines) {
- resultField->addValue(Q2PSTRING(line));
- }
- }
- }
- if (field->getType() == FormField::ListMultiType) {
- QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]);
- foreach (QListWidgetItem* item, listWidget->selectedItems()) {
- resultField->addValue(field->getOptions()[listWidget->row(item)].value);
- }
- }
- resultField->setName(field->getName());
- result->addField(resultField);
- }
- return result;
+ Form::ref result(new Form(Form::SubmitType));
+ foreach (boost::shared_ptr<FormField> field, form_->getFields()) {
+ boost::shared_ptr<FormField> resultField = boost::make_shared<FormField>(field->getType());
+ if (field->getType() == FormField::BooleanType) {
+ resultField->setBoolValue(qobject_cast<QCheckBox*>(fields_[field->getName()])->checkState() == Qt::Checked);
+ }
+ if (field->getType() == FormField::FixedType || field->getType() == FormField::HiddenType) {
+ resultField->addValue(field->getValues().empty() ? "" : field->getValues()[0]);
+ }
+ if (field->getType() == FormField::ListSingleType) {
+ QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]);
+ if (listWidget->selectedItems().size() > 0) {
+ int i = listWidget->row(listWidget->selectedItems()[0]);
+ resultField->addValue(field->getOptions()[i].value);
+ }
+ }
+ if (field->getType() == FormField::TextMultiType) {
+ QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]);
+ QString string = widget->toPlainText();
+ if (!string.isEmpty()) {
+ resultField->setTextMultiValue(Q2PSTRING(string));
+ }
+ }
+ if (field->getType() == FormField::TextPrivateType || field->getType() == FormField::TextSingleType || field->getType() == FormField::JIDSingleType) {
+ QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]);
+ QString string = widget->text();
+ if (!string.isEmpty()) {
+ resultField->addValue(Q2PSTRING(string));
+ }
+ }
+ if (field->getType() == FormField::JIDMultiType) {
+ QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]);
+ QString string = widget->toPlainText();
+ if (!string.isEmpty()) {
+ QStringList lines = string.split("\n");
+ foreach (QString line, lines) {
+ resultField->addValue(Q2PSTRING(line));
+ }
+ }
+ }
+ if (field->getType() == FormField::ListMultiType) {
+ QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]);
+ foreach (QListWidgetItem* item, listWidget->selectedItems()) {
+ resultField->addValue(field->getOptions()[listWidget->row(item)].value);
+ }
+ }
+ resultField->setName(field->getName());
+ result->addField(resultField);
+ }
+ return result;
}
template<class T> void QtFormWidget::setEnabled(QWidget* rawWidget, bool editable) {
- T* widget = qobject_cast<T*>(rawWidget);
- if (widget) {
- widget->setEnabled(editable);
- }
+ T* widget = qobject_cast<T*>(rawWidget);
+ if (widget) {
+ widget->setEnabled(editable);
+ }
}
template<class T> void QtFormWidget::setEditable(QWidget* rawWidget, bool editable) {
- T* widget = qobject_cast<T*>(rawWidget);
- if (widget) {
- widget->setReadOnly(!editable);
- }
+ T* widget = qobject_cast<T*>(rawWidget);
+ if (widget) {
+ widget->setReadOnly(!editable);
+ }
}
void QtFormWidget::setEditable(bool editable) {
- if (!form_) {
- return;
- }
- foreach (boost::shared_ptr<FormField> field, form_->getFields()) {
- QWidget* widget = NULL;
- if (field) {
- widget = fields_[field->getName()];
- }
- setEnabled<QCheckBox>(widget, editable);
- setEnabled<QListWidget>(widget, editable);
- setEditable<QTextEdit>(widget, editable);
- setEditable<QLineEdit>(widget, editable);
- }
+ if (!form_) {
+ return;
+ }
+ foreach (boost::shared_ptr<FormField> field, form_->getFields()) {
+ QWidget* widget = NULL;
+ if (field) {
+ widget = fields_[field->getName()];
+ }
+ setEnabled<QCheckBox>(widget, editable);
+ setEnabled<QListWidget>(widget, editable);
+ setEditable<QTextEdit>(widget, editable);
+ setEditable<QLineEdit>(widget, editable);
+ }
}
}
diff --git a/Swift/QtUI/QtFormWidget.h b/Swift/QtUI/QtFormWidget.h
index 4c6311c..1eec115 100644
--- a/Swift/QtUI/QtFormWidget.h
+++ b/Swift/QtUI/QtFormWidget.h
@@ -17,19 +17,19 @@ class QListWidget;
namespace Swift {
class QtFormWidget : public QWidget {
- Q_OBJECT
- public:
- QtFormWidget(Form::ref form, QWidget* parent = NULL);
- virtual ~QtFormWidget();
- Form::ref getCompletedForm();
- void setEditable(bool editable);
- private:
- QWidget* createWidget(FormField::ref field, const FormField::Type type, const size_t index);
- QListWidget* createList(FormField::ref field);
- template<class T> void setEnabled(QWidget* rawWidget, bool editable);
- template<class T> void setEditable(QWidget* rawWidget, bool editable);
- std::map<std::string, QWidget*> fields_;
- Form::ref form_;
+ Q_OBJECT
+ public:
+ QtFormWidget(Form::ref form, QWidget* parent = NULL);
+ virtual ~QtFormWidget();
+ Form::ref getCompletedForm();
+ void setEditable(bool editable);
+ private:
+ QWidget* createWidget(FormField::ref field, const FormField::Type type, const size_t index);
+ QListWidget* createList(FormField::ref field);
+ template<class T> void setEnabled(QWidget* rawWidget, bool editable);
+ template<class T> void setEditable(QWidget* rawWidget, bool editable);
+ std::map<std::string, QWidget*> fields_;
+ Form::ref form_;
};
}
diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp
index 1d47c4e..fdbff9e 100644
--- a/Swift/QtUI/QtHighlightEditor.cpp
+++ b/Swift/QtUI/QtHighlightEditor.cpp
@@ -29,61 +29,61 @@
namespace Swift {
QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* parent)
- : QWidget(parent), settings_(settings), previousRow_(-1)
+ : QWidget(parent), settings_(settings), previousRow_(-1)
{
- ui_.setupUi(this);
+ ui_.setupUi(this);
- connect(ui_.listWidget, SIGNAL(currentRowChanged(int)), SLOT(onCurrentRowChanged(int)));
+ connect(ui_.listWidget, SIGNAL(currentRowChanged(int)), SLOT(onCurrentRowChanged(int)));
- connect(ui_.newButton, SIGNAL(clicked()), SLOT(onNewButtonClicked()));
- connect(ui_.deleteButton, SIGNAL(clicked()), SLOT(onDeleteButtonClicked()));
+ connect(ui_.newButton, SIGNAL(clicked()), SLOT(onNewButtonClicked()));
+ connect(ui_.deleteButton, SIGNAL(clicked()), SLOT(onDeleteButtonClicked()));
- connect(ui_.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(onApplyButtonClick()));
- connect(ui_.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(onCancelButtonClick()));
- connect(ui_.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(onOkButtonClick()));
- connect(ui_.buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(onResetToDefaultRulesClicked()));
+ connect(ui_.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(onApplyButtonClick()));
+ connect(ui_.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(onCancelButtonClick()));
+ connect(ui_.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(onOkButtonClick()));
+ connect(ui_.buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(onResetToDefaultRulesClicked()));
- connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(colorOtherSelect()));
- connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(colorCustomSelect()));
+ connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(colorOtherSelect()));
+ connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(colorCustomSelect()));
- connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect()));
- connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect()));
- connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(soundCustomSelect()));
+ connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect()));
+ connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect()));
+ connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(soundCustomSelect()));
- /* replace the static line-edit control with the roster autocompleter */
- ui_.dummySenderName->setVisible(false);
- jid_ = new QtSuggestingJIDInput(this, settings);
- ui_.senderName->addWidget(jid_);
- jid_->onUserSelected.connect(boost::bind(&QtHighlightEditor::handleOnUserSelected, this, _1));
+ /* replace the static line-edit control with the roster autocompleter */
+ ui_.dummySenderName->setVisible(false);
+ jid_ = new QtSuggestingJIDInput(this, settings);
+ ui_.senderName->addWidget(jid_);
+ jid_->onUserSelected.connect(boost::bind(&QtHighlightEditor::handleOnUserSelected, this, _1));
- /* handle autocomplete */
- connect(jid_, SIGNAL(textEdited(QString)), SLOT(handleContactSuggestionRequested(QString)));
+ /* handle autocomplete */
+ connect(jid_, SIGNAL(textEdited(QString)), SLOT(handleContactSuggestionRequested(QString)));
- /* we need to be notified if any of the state changes so that we can update our textual rule description */
- connect(ui_.chatRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.roomRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.nickIsKeyword, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.allMsgRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.senderRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(jid_, SIGNAL(textChanged(const QString&)), SLOT(widgetClick()));
- connect(ui_.keywordRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.keyword, SIGNAL(textChanged(const QString&)), SLOT(widgetClick()));
- connect(ui_.matchPartialWords, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.matchCase, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ /* we need to be notified if any of the state changes so that we can update our textual rule description */
+ connect(ui_.chatRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.roomRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.nickIsKeyword, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.allMsgRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.senderRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(jid_, SIGNAL(textChanged(const QString&)), SLOT(widgetClick()));
+ connect(ui_.keywordRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.keyword, SIGNAL(textChanged(const QString&)), SLOT(widgetClick()));
+ connect(ui_.matchPartialWords, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.matchCase, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- /* allow selection of a custom sound file */
- connect(ui_.soundFileButton, SIGNAL(clicked()), SLOT(selectSoundFile()));
+ /* allow selection of a custom sound file */
+ connect(ui_.soundFileButton, SIGNAL(clicked()), SLOT(selectSoundFile()));
- /* allowing reordering items */
- connect(ui_.moveUpButton, SIGNAL(clicked()), this, SLOT(onUpButtonClicked()));
- connect(ui_.moveDownButton, SIGNAL(clicked()), this, SLOT(onDownButtonClicked()));
+ /* allowing reordering items */
+ connect(ui_.moveUpButton, SIGNAL(clicked()), this, SLOT(onUpButtonClicked()));
+ connect(ui_.moveDownButton, SIGNAL(clicked()), this, SLOT(onDownButtonClicked()));
- setWindowTitle(tr("Highlight Rules"));
+ setWindowTitle(tr("Highlight Rules"));
}
QtHighlightEditor::~QtHighlightEditor()
@@ -92,477 +92,477 @@ QtHighlightEditor::~QtHighlightEditor()
std::string formatShortDescription(const HighlightRule &rule)
{
- const std::string chatOrRoom = (rule.getMatchChat() ? "chat" : "room");
+ const std::string chatOrRoom = (rule.getMatchChat() ? "chat" : "room");
- std::vector<std::string> senders = rule.getSenders();
- std::vector<std::string> keywords = rule.getKeywords();
+ std::vector<std::string> senders = rule.getSenders();
+ std::vector<std::string> keywords = rule.getKeywords();
- if (senders.empty() && keywords.empty() && !rule.getNickIsKeyword()) {
- return std::string("All ") + chatOrRoom + " messages.";
- }
+ if (senders.empty() && keywords.empty() && !rule.getNickIsKeyword()) {
+ return std::string("All ") + chatOrRoom + " messages.";
+ }
- if (rule.getNickIsKeyword()) {
- return std::string("All ") + chatOrRoom + " messages that mention my name.";
- }
+ if (rule.getNickIsKeyword()) {
+ return std::string("All ") + chatOrRoom + " messages that mention my name.";
+ }
- if (!senders.empty()) {
- return std::string("All ") + chatOrRoom + " messages from " + senders[0] + ".";
- }
+ if (!senders.empty()) {
+ return std::string("All ") + chatOrRoom + " messages from " + senders[0] + ".";
+ }
- if (!keywords.empty()) {
- return std::string("All ") + chatOrRoom + " messages mentioning the keyword '" + keywords[0] + "'.";
- }
+ if (!keywords.empty()) {
+ return std::string("All ") + chatOrRoom + " messages mentioning the keyword '" + keywords[0] + "'.";
+ }
- return "Unknown Rule";
+ return "Unknown Rule";
}
void QtHighlightEditor::show()
{
- highlightManager_->loadSettings();
+ highlightManager_->loadSettings();
- populateList();
+ populateList();
- if (ui_.listWidget->count()) {
- selectRow(0);
- }
+ if (ui_.listWidget->count()) {
+ selectRow(0);
+ }
- updateResetToDefaultRulesVisibility();
+ updateResetToDefaultRulesVisibility();
- /* prepare default states */
- widgetClick();
+ /* prepare default states */
+ widgetClick();
- QWidget::show();
- QWidget::activateWindow();
+ QWidget::show();
+ QWidget::activateWindow();
}
void QtHighlightEditor::setHighlightManager(HighlightManager* highlightManager)
{
- highlightManager_ = highlightManager;
+ highlightManager_ = highlightManager;
}
void QtHighlightEditor::setContactSuggestions(const std::vector<Contact::ref>& suggestions)
{
- jid_->setSuggestions(suggestions);
+ jid_->setSuggestions(suggestions);
}
void QtHighlightEditor::colorOtherSelect()
{
- ui_.foregroundColor->setEnabled(false);
- ui_.backgroundColor->setEnabled(false);
+ ui_.foregroundColor->setEnabled(false);
+ ui_.backgroundColor->setEnabled(false);
}
void QtHighlightEditor::colorCustomSelect()
{
- ui_.foregroundColor->setEnabled(true);
- ui_.backgroundColor->setEnabled(true);
+ ui_.foregroundColor->setEnabled(true);
+ ui_.backgroundColor->setEnabled(true);
}
void QtHighlightEditor::soundOtherSelect()
{
- ui_.soundFile->setEnabled(false);
- ui_.soundFileButton->setEnabled(false);
+ ui_.soundFile->setEnabled(false);
+ ui_.soundFileButton->setEnabled(false);
}
void QtHighlightEditor::soundCustomSelect()
{
- ui_.soundFile->setEnabled(true);
- ui_.soundFileButton->setEnabled(true);
+ ui_.soundFile->setEnabled(true);
+ ui_.soundFileButton->setEnabled(true);
}
void QtHighlightEditor::onNewButtonClicked()
{
- int row = getSelectedRow() + 1;
- populateList();
- HighlightRule newRule;
- newRule.setMatchMUC(true);
- highlightManager_->insertRule(row, newRule);
- QListWidgetItem *item = new QListWidgetItem();
- item->setText(P2QSTRING(formatShortDescription(newRule)));
- QFont font;
- font.setItalic(true);
- item->setFont(font);
- ui_.listWidget->insertItem(row, item);
- selectRow(row);
+ int row = getSelectedRow() + 1;
+ populateList();
+ HighlightRule newRule;
+ newRule.setMatchMUC(true);
+ highlightManager_->insertRule(row, newRule);
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setText(P2QSTRING(formatShortDescription(newRule)));
+ QFont font;
+ font.setItalic(true);
+ item->setFont(font);
+ ui_.listWidget->insertItem(row, item);
+ selectRow(row);
}
void QtHighlightEditor::onDeleteButtonClicked()
{
- int selectedRow = getSelectedRow();
- assert(selectedRow>=0 && selectedRow<ui_.listWidget->count());
- delete ui_.listWidget->takeItem(selectedRow);
- highlightManager_->removeRule(selectedRow);
-
- if (!ui_.listWidget->count()) {
- disableDialog();
- ui_.deleteButton->setEnabled(false);
- } else {
- if (selectedRow == ui_.listWidget->count()) {
- selectRow(ui_.listWidget->count() - 1);
- } else {
- selectRow(selectedRow);
- }
- }
+ int selectedRow = getSelectedRow();
+ assert(selectedRow>=0 && selectedRow<ui_.listWidget->count());
+ delete ui_.listWidget->takeItem(selectedRow);
+ highlightManager_->removeRule(selectedRow);
+
+ if (!ui_.listWidget->count()) {
+ disableDialog();
+ ui_.deleteButton->setEnabled(false);
+ } else {
+ if (selectedRow == ui_.listWidget->count()) {
+ selectRow(ui_.listWidget->count() - 1);
+ } else {
+ selectRow(selectedRow);
+ }
+ }
}
void QtHighlightEditor::moveRowFromTo(int fromRow, int toRow) {
- int verticalScrollAreaPosition = ui_.scrollArea->verticalScrollBar()->value();
- highlightManager_->swapRules(fromRow, toRow);
- populateList();
- selectRow(toRow);
- ui_.scrollArea->verticalScrollBar()->setValue(verticalScrollAreaPosition);
+ int verticalScrollAreaPosition = ui_.scrollArea->verticalScrollBar()->value();
+ highlightManager_->swapRules(fromRow, toRow);
+ populateList();
+ selectRow(toRow);
+ ui_.scrollArea->verticalScrollBar()->setValue(verticalScrollAreaPosition);
}
void QtHighlightEditor::onUpButtonClicked() {
- const size_t moveFrom = ui_.listWidget->currentRow();
- const size_t moveTo = moveFrom - 1;
- moveRowFromTo(moveFrom, moveTo);
+ const size_t moveFrom = ui_.listWidget->currentRow();
+ const size_t moveTo = moveFrom - 1;
+ moveRowFromTo(moveFrom, moveTo);
}
void QtHighlightEditor::onDownButtonClicked() {
- const size_t moveFrom = ui_.listWidget->currentRow();
- const size_t moveTo = moveFrom + 1;
- moveRowFromTo(moveFrom, moveTo);
+ const size_t moveFrom = ui_.listWidget->currentRow();
+ const size_t moveTo = moveFrom + 1;
+ moveRowFromTo(moveFrom, moveTo);
}
void QtHighlightEditor::onCurrentRowChanged(int currentRow)
{
- ui_.deleteButton->setEnabled(currentRow != -1);
- ui_.moveUpButton->setEnabled(currentRow != -1 && currentRow != 0);
- ui_.moveDownButton->setEnabled(currentRow != -1 && currentRow != (ui_.listWidget->count()-1));
-
- if (previousRow_ != -1) {
- if (ui_.listWidget->count() > previousRow_) {
- QFont font;
- font.setItalic(false);
- ui_.listWidget->item(previousRow_)->setFont(font);
- highlightManager_->setRule(previousRow_, ruleFromDialog());
- }
- }
-
- if (currentRow != -1) {
- HighlightRule rule = highlightManager_->getRule(currentRow);
- ruleToDialog(rule);
- if (ui_.listWidget->currentItem()) {
- QFont font;
- font.setItalic(true);
- ui_.listWidget->currentItem()->setFont(font);
- ui_.listWidget->currentItem()->setText(P2QSTRING(formatShortDescription(rule)));
- }
- }
-
- /* grey the dialog if we have nothing selected */
- if (currentRow == -1) {
- disableDialog();
- }
-
- previousRow_ = currentRow;
-
- updateResetToDefaultRulesVisibility();
+ ui_.deleteButton->setEnabled(currentRow != -1);
+ ui_.moveUpButton->setEnabled(currentRow != -1 && currentRow != 0);
+ ui_.moveDownButton->setEnabled(currentRow != -1 && currentRow != (ui_.listWidget->count()-1));
+
+ if (previousRow_ != -1) {
+ if (ui_.listWidget->count() > previousRow_) {
+ QFont font;
+ font.setItalic(false);
+ ui_.listWidget->item(previousRow_)->setFont(font);
+ highlightManager_->setRule(previousRow_, ruleFromDialog());
+ }
+ }
+
+ if (currentRow != -1) {
+ HighlightRule rule = highlightManager_->getRule(currentRow);
+ ruleToDialog(rule);
+ if (ui_.listWidget->currentItem()) {
+ QFont font;
+ font.setItalic(true);
+ ui_.listWidget->currentItem()->setFont(font);
+ ui_.listWidget->currentItem()->setText(P2QSTRING(formatShortDescription(rule)));
+ }
+ }
+
+ /* grey the dialog if we have nothing selected */
+ if (currentRow == -1) {
+ disableDialog();
+ }
+
+ previousRow_ = currentRow;
+
+ updateResetToDefaultRulesVisibility();
}
void QtHighlightEditor::onApplyButtonClick()
{
- selectRow(getSelectedRow()); /* force save */
- highlightManager_->storeSettings();
+ selectRow(getSelectedRow()); /* force save */
+ highlightManager_->storeSettings();
}
void QtHighlightEditor::onCancelButtonClick()
{
- close();
+ close();
}
void QtHighlightEditor::onOkButtonClick()
{
- onApplyButtonClick();
- close();
+ onApplyButtonClick();
+ close();
}
void QtHighlightEditor::setChildWidgetStates()
{
- /* disable appropriate radio button child widgets */
-
- if (ui_.chatRadio->isChecked()) {
- if (ui_.nickIsKeyword->isChecked()) {
- /* switch to another choice before we disable this button */
- ui_.allMsgRadio->setChecked(true);
- }
- ui_.nickIsKeyword->setEnabled(false);
- } else if (ui_.roomRadio->isChecked()) {
- ui_.nickIsKeyword->setEnabled(true);
- } else { /* chats and rooms */
- ui_.nickIsKeyword->setEnabled(true);
- }
-
- if (ui_.senderRadio->isChecked()) {
- jid_->setEnabled(true);
- } else {
- jid_->setEnabled(false);
- }
-
- if (ui_.keywordRadio->isChecked()) {
- ui_.keyword->setEnabled(true);
- ui_.matchPartialWords->setEnabled(true);
- ui_.matchCase->setEnabled(true);
- } else {
- ui_.keyword->setEnabled(false);
- ui_.matchPartialWords->setEnabled(false);
- ui_.matchCase->setEnabled(false);
- }
-
- if (ui_.chatRadio->isChecked()) {
- ui_.allMsgRadio->setText(tr("Apply to all chat messages"));
- } else {
- ui_.allMsgRadio->setText(tr("Apply to all room messages"));
- }
+ /* disable appropriate radio button child widgets */
+
+ if (ui_.chatRadio->isChecked()) {
+ if (ui_.nickIsKeyword->isChecked()) {
+ /* switch to another choice before we disable this button */
+ ui_.allMsgRadio->setChecked(true);
+ }
+ ui_.nickIsKeyword->setEnabled(false);
+ } else if (ui_.roomRadio->isChecked()) {
+ ui_.nickIsKeyword->setEnabled(true);
+ } else { /* chats and rooms */
+ ui_.nickIsKeyword->setEnabled(true);
+ }
+
+ if (ui_.senderRadio->isChecked()) {
+ jid_->setEnabled(true);
+ } else {
+ jid_->setEnabled(false);
+ }
+
+ if (ui_.keywordRadio->isChecked()) {
+ ui_.keyword->setEnabled(true);
+ ui_.matchPartialWords->setEnabled(true);
+ ui_.matchCase->setEnabled(true);
+ } else {
+ ui_.keyword->setEnabled(false);
+ ui_.matchPartialWords->setEnabled(false);
+ ui_.matchCase->setEnabled(false);
+ }
+
+ if (ui_.chatRadio->isChecked()) {
+ ui_.allMsgRadio->setText(tr("Apply to all chat messages"));
+ } else {
+ ui_.allMsgRadio->setText(tr("Apply to all room messages"));
+ }
}
void QtHighlightEditor::widgetClick()
{
- setChildWidgetStates();
+ setChildWidgetStates();
- HighlightRule rule = ruleFromDialog();
+ HighlightRule rule = ruleFromDialog();
- if (ui_.listWidget->currentItem()) {
- ui_.listWidget->currentItem()->setText(P2QSTRING(formatShortDescription(rule)));
- }
+ if (ui_.listWidget->currentItem()) {
+ ui_.listWidget->currentItem()->setText(P2QSTRING(formatShortDescription(rule)));
+ }
}
void QtHighlightEditor::disableDialog()
{
- ui_.chatRadio->setEnabled(false);
- ui_.roomRadio->setEnabled(false);
- ui_.allMsgRadio->setEnabled(false);
- ui_.nickIsKeyword->setEnabled(false);
- ui_.senderRadio->setEnabled(false);
- ui_.dummySenderName->setEnabled(false);
- ui_.keywordRadio->setEnabled(false);
- ui_.keyword->setEnabled(false);
- ui_.matchPartialWords->setEnabled(false);
- ui_.matchCase->setEnabled(false);
- ui_.noColorRadio->setEnabled(false);
- ui_.customColorRadio->setEnabled(false);
- ui_.foregroundColor->setEnabled(false);
- ui_.backgroundColor->setEnabled(false);
- ui_.noSoundRadio->setEnabled(false);
- ui_.defaultSoundRadio->setEnabled(false);
- ui_.customSoundRadio->setEnabled(false);
- ui_.soundFile->setEnabled(false);
- ui_.soundFileButton->setEnabled(false);
+ ui_.chatRadio->setEnabled(false);
+ ui_.roomRadio->setEnabled(false);
+ ui_.allMsgRadio->setEnabled(false);
+ ui_.nickIsKeyword->setEnabled(false);
+ ui_.senderRadio->setEnabled(false);
+ ui_.dummySenderName->setEnabled(false);
+ ui_.keywordRadio->setEnabled(false);
+ ui_.keyword->setEnabled(false);
+ ui_.matchPartialWords->setEnabled(false);
+ ui_.matchCase->setEnabled(false);
+ ui_.noColorRadio->setEnabled(false);
+ ui_.customColorRadio->setEnabled(false);
+ ui_.foregroundColor->setEnabled(false);
+ ui_.backgroundColor->setEnabled(false);
+ ui_.noSoundRadio->setEnabled(false);
+ ui_.defaultSoundRadio->setEnabled(false);
+ ui_.customSoundRadio->setEnabled(false);
+ ui_.soundFile->setEnabled(false);
+ ui_.soundFileButton->setEnabled(false);
}
void QtHighlightEditor::handleContactSuggestionRequested(const QString& text)
{
- std::string stdText = Q2PSTRING(text);
- onContactSuggestionsRequested(stdText);
+ std::string stdText = Q2PSTRING(text);
+ onContactSuggestionsRequested(stdText);
}
void QtHighlightEditor::selectSoundFile()
{
- QString path = QFileDialog::getOpenFileName(this, tr("Select sound file..."), QString(), "Sounds (*.wav)");
- ui_.soundFile->setText(path);
+ QString path = QFileDialog::getOpenFileName(this, tr("Select sound file..."), QString(), "Sounds (*.wav)");
+ ui_.soundFile->setText(path);
}
void QtHighlightEditor::onResetToDefaultRulesClicked() {
- highlightManager_->resetToDefaultRulesList();
- populateList();
- updateResetToDefaultRulesVisibility();
+ highlightManager_->resetToDefaultRulesList();
+ populateList();
+ updateResetToDefaultRulesVisibility();
}
void QtHighlightEditor::handleOnUserSelected(const Contact::ref& contact) {
- /* this might seem like it should be standard behaviour for the suggesting input box, but is not desirable in all cases */
- if (contact->jid.isValid()) {
- jid_->setText(P2QSTRING(contact->jid.toString()));
- } else {
- jid_->setText(P2QSTRING(contact->name));
- }
+ /* this might seem like it should be standard behaviour for the suggesting input box, but is not desirable in all cases */
+ if (contact->jid.isValid()) {
+ jid_->setText(P2QSTRING(contact->jid.toString()));
+ } else {
+ jid_->setText(P2QSTRING(contact->name));
+ }
}
void QtHighlightEditor::populateList()
{
- previousRow_ = -1;
- ui_.listWidget->clear();
- HighlightRulesListPtr rules = highlightManager_->getRules();
- for (size_t i = 0; i < rules->getSize(); ++i) {
- const HighlightRule& rule = rules->getRule(i);
- QListWidgetItem *item = new QListWidgetItem();
- item->setText(P2QSTRING(formatShortDescription(rule)));
- ui_.listWidget->addItem(item);
- }
+ previousRow_ = -1;
+ ui_.listWidget->clear();
+ HighlightRulesListPtr rules = highlightManager_->getRules();
+ for (size_t i = 0; i < rules->getSize(); ++i) {
+ const HighlightRule& rule = rules->getRule(i);
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setText(P2QSTRING(formatShortDescription(rule)));
+ ui_.listWidget->addItem(item);
+ }
}
void QtHighlightEditor::selectRow(int row)
{
- for (int i = 0; i < ui_.listWidget->count(); ++i) {
- if (i == row) {
- ui_.listWidget->item(i)->setSelected(true);
- onCurrentRowChanged(i);
- } else {
- ui_.listWidget->item(i)->setSelected(false);
- }
- }
- ui_.listWidget->setCurrentRow(row);
+ for (int i = 0; i < ui_.listWidget->count(); ++i) {
+ if (i == row) {
+ ui_.listWidget->item(i)->setSelected(true);
+ onCurrentRowChanged(i);
+ } else {
+ ui_.listWidget->item(i)->setSelected(false);
+ }
+ }
+ ui_.listWidget->setCurrentRow(row);
}
int QtHighlightEditor::getSelectedRow() const
{
- for (int i = 0; i < ui_.listWidget->count(); ++i) {
- if (ui_.listWidget->item(i)->isSelected()) {
- return i;
- }
- }
- return -1;
+ for (int i = 0; i < ui_.listWidget->count(); ++i) {
+ if (ui_.listWidget->item(i)->isSelected()) {
+ return i;
+ }
+ }
+ return -1;
}
HighlightRule QtHighlightEditor::ruleFromDialog()
{
- HighlightRule rule;
- HighlightAction& action = rule.getAction();
-
- if (ui_.chatRadio->isChecked()) {
- rule.setMatchChat(true);
- rule.setMatchMUC(false);
- } else {
- rule.setMatchChat(false);
- rule.setMatchMUC(true);
- }
-
- if (ui_.allMsgRadio->isChecked()) {
- action.setHighlightWholeMessage(true);
- }
-
- if (ui_.senderRadio->isChecked()) {
- QString senderName = jid_->text();
- if (!senderName.isEmpty()) {
- std::vector<std::string> senders;
- senders.push_back(Q2PSTRING(senderName));
- rule.setSenders(senders);
- action.setHighlightWholeMessage(true);
- }
- }
-
- if (ui_.keywordRadio->isChecked()) {
- QString keywordString = ui_.keyword->text();
- if (!keywordString.isEmpty()) {
- std::vector<std::string> keywords;
- keywords.push_back(Q2PSTRING(keywordString));
- rule.setKeywords(keywords);
- }
- }
-
- if (ui_.nickIsKeyword->isChecked()) {
- rule.setNickIsKeyword(true);
- rule.setMatchWholeWords(true);
- rule.setMatchCase(true);
- } else {
- rule.setMatchWholeWords(!ui_.matchPartialWords->isChecked());
- rule.setMatchCase(ui_.matchCase->isChecked());
- }
-
- if (ui_.noColorRadio->isChecked()) {
- action.setTextColor("");
- action.setTextBackground("");
- } else {
- action.setTextColor(Q2PSTRING(ui_.foregroundColor->getColor().name()));
- action.setTextBackground(Q2PSTRING(ui_.backgroundColor->getColor().name()));
- }
-
- if (ui_.noSoundRadio->isChecked()) {
- action.setPlaySound(false);
- } else if (ui_.defaultSoundRadio->isChecked()) {
- action.setPlaySound(true);
- action.setSoundFile("");
- } else {
- action.setPlaySound(true);
- action.setSoundFile(Q2PSTRING(ui_.soundFile->text()));
- }
-
- return rule;
+ HighlightRule rule;
+ HighlightAction& action = rule.getAction();
+
+ if (ui_.chatRadio->isChecked()) {
+ rule.setMatchChat(true);
+ rule.setMatchMUC(false);
+ } else {
+ rule.setMatchChat(false);
+ rule.setMatchMUC(true);
+ }
+
+ if (ui_.allMsgRadio->isChecked()) {
+ action.setHighlightWholeMessage(true);
+ }
+
+ if (ui_.senderRadio->isChecked()) {
+ QString senderName = jid_->text();
+ if (!senderName.isEmpty()) {
+ std::vector<std::string> senders;
+ senders.push_back(Q2PSTRING(senderName));
+ rule.setSenders(senders);
+ action.setHighlightWholeMessage(true);
+ }
+ }
+
+ if (ui_.keywordRadio->isChecked()) {
+ QString keywordString = ui_.keyword->text();
+ if (!keywordString.isEmpty()) {
+ std::vector<std::string> keywords;
+ keywords.push_back(Q2PSTRING(keywordString));
+ rule.setKeywords(keywords);
+ }
+ }
+
+ if (ui_.nickIsKeyword->isChecked()) {
+ rule.setNickIsKeyword(true);
+ rule.setMatchWholeWords(true);
+ rule.setMatchCase(true);
+ } else {
+ rule.setMatchWholeWords(!ui_.matchPartialWords->isChecked());
+ rule.setMatchCase(ui_.matchCase->isChecked());
+ }
+
+ if (ui_.noColorRadio->isChecked()) {
+ action.setTextColor("");
+ action.setTextBackground("");
+ } else {
+ action.setTextColor(Q2PSTRING(ui_.foregroundColor->getColor().name()));
+ action.setTextBackground(Q2PSTRING(ui_.backgroundColor->getColor().name()));
+ }
+
+ if (ui_.noSoundRadio->isChecked()) {
+ action.setPlaySound(false);
+ } else if (ui_.defaultSoundRadio->isChecked()) {
+ action.setPlaySound(true);
+ action.setSoundFile("");
+ } else {
+ action.setPlaySound(true);
+ action.setSoundFile(Q2PSTRING(ui_.soundFile->text()));
+ }
+
+ return rule;
}
void QtHighlightEditor::ruleToDialog(const HighlightRule& rule)
{
- ui_.chatRadio->setEnabled(true);
- ui_.roomRadio->setEnabled(true);
-
- if (rule.getMatchMUC()) {
- ui_.chatRadio->setChecked(false);
- ui_.roomRadio->setChecked(true);
- } else {
- ui_.chatRadio->setChecked(true);
- ui_.roomRadio->setChecked(false);
- }
-
- ui_.allMsgRadio->setEnabled(true);
- ui_.allMsgRadio->setChecked(true); /* this is the default radio button */
- jid_->setText("");
- ui_.keyword->setText("");
- ui_.matchPartialWords->setChecked(false);
- ui_.matchCase->setChecked(false);
-
- ui_.nickIsKeyword->setEnabled(true);
- if (rule.getNickIsKeyword()) {
- ui_.nickIsKeyword->setChecked(true);
- }
-
- ui_.senderRadio->setEnabled(true);
- std::vector<std::string> senders = rule.getSenders();
- if (!senders.empty()) {
- ui_.senderRadio->setChecked(true);
- jid_->setText(P2QSTRING(senders[0]));
- }
-
- ui_.keywordRadio->setEnabled(true);
- std::vector<std::string> keywords = rule.getKeywords();
- if (!keywords.empty()) {
- ui_.keywordRadio->setChecked(true);
- ui_.keyword->setText(P2QSTRING(keywords[0]));
- ui_.matchPartialWords->setChecked(!rule.getMatchWholeWords());
- ui_.matchCase->setChecked(rule.getMatchCase());
- }
-
- const HighlightAction& action = rule.getAction();
-
- ui_.noColorRadio->setEnabled(true);
- ui_.customColorRadio->setEnabled(true);
- if (action.getTextColor().empty() && action.getTextBackground().empty()) {
- ui_.noColorRadio->setChecked(true);
- ui_.foregroundColor->setEnabled(false);
- ui_.backgroundColor->setEnabled(false);
- } else {
- ui_.foregroundColor->setEnabled(true);
- ui_.backgroundColor->setEnabled(true);
- QColor foregroundColor(P2QSTRING(action.getTextColor()));
- ui_.foregroundColor->setColor(foregroundColor);
- QColor backgroundColor(P2QSTRING(action.getTextBackground()));
- ui_.backgroundColor->setColor(backgroundColor);
- ui_.customColorRadio->setChecked(true);
- }
-
- ui_.noSoundRadio->setEnabled(true);
- ui_.defaultSoundRadio->setEnabled(true);
- ui_.customSoundRadio->setEnabled(true);
- ui_.soundFile->setText("");
- ui_.soundFile->setEnabled(false);
- ui_.soundFileButton->setEnabled(false);
- if (action.playSound()) {
- if (action.getSoundFile().empty()) {
- ui_.defaultSoundRadio->setChecked(true);
- } else {
- ui_.customSoundRadio->setChecked(true);
- ui_.soundFile->setText(P2QSTRING(action.getSoundFile()));
- ui_.soundFile->setEnabled(true);
- ui_.soundFileButton->setEnabled(true);
- }
- } else {
- ui_.noSoundRadio->setChecked(true);
- }
-
- /* set radio button child option states */
- setChildWidgetStates();
+ ui_.chatRadio->setEnabled(true);
+ ui_.roomRadio->setEnabled(true);
+
+ if (rule.getMatchMUC()) {
+ ui_.chatRadio->setChecked(false);
+ ui_.roomRadio->setChecked(true);
+ } else {
+ ui_.chatRadio->setChecked(true);
+ ui_.roomRadio->setChecked(false);
+ }
+
+ ui_.allMsgRadio->setEnabled(true);
+ ui_.allMsgRadio->setChecked(true); /* this is the default radio button */
+ jid_->setText("");
+ ui_.keyword->setText("");
+ ui_.matchPartialWords->setChecked(false);
+ ui_.matchCase->setChecked(false);
+
+ ui_.nickIsKeyword->setEnabled(true);
+ if (rule.getNickIsKeyword()) {
+ ui_.nickIsKeyword->setChecked(true);
+ }
+
+ ui_.senderRadio->setEnabled(true);
+ std::vector<std::string> senders = rule.getSenders();
+ if (!senders.empty()) {
+ ui_.senderRadio->setChecked(true);
+ jid_->setText(P2QSTRING(senders[0]));
+ }
+
+ ui_.keywordRadio->setEnabled(true);
+ std::vector<std::string> keywords = rule.getKeywords();
+ if (!keywords.empty()) {
+ ui_.keywordRadio->setChecked(true);
+ ui_.keyword->setText(P2QSTRING(keywords[0]));
+ ui_.matchPartialWords->setChecked(!rule.getMatchWholeWords());
+ ui_.matchCase->setChecked(rule.getMatchCase());
+ }
+
+ const HighlightAction& action = rule.getAction();
+
+ ui_.noColorRadio->setEnabled(true);
+ ui_.customColorRadio->setEnabled(true);
+ if (action.getTextColor().empty() && action.getTextBackground().empty()) {
+ ui_.noColorRadio->setChecked(true);
+ ui_.foregroundColor->setEnabled(false);
+ ui_.backgroundColor->setEnabled(false);
+ } else {
+ ui_.foregroundColor->setEnabled(true);
+ ui_.backgroundColor->setEnabled(true);
+ QColor foregroundColor(P2QSTRING(action.getTextColor()));
+ ui_.foregroundColor->setColor(foregroundColor);
+ QColor backgroundColor(P2QSTRING(action.getTextBackground()));
+ ui_.backgroundColor->setColor(backgroundColor);
+ ui_.customColorRadio->setChecked(true);
+ }
+
+ ui_.noSoundRadio->setEnabled(true);
+ ui_.defaultSoundRadio->setEnabled(true);
+ ui_.customSoundRadio->setEnabled(true);
+ ui_.soundFile->setText("");
+ ui_.soundFile->setEnabled(false);
+ ui_.soundFileButton->setEnabled(false);
+ if (action.playSound()) {
+ if (action.getSoundFile().empty()) {
+ ui_.defaultSoundRadio->setChecked(true);
+ } else {
+ ui_.customSoundRadio->setChecked(true);
+ ui_.soundFile->setText(P2QSTRING(action.getSoundFile()));
+ ui_.soundFile->setEnabled(true);
+ ui_.soundFileButton->setEnabled(true);
+ }
+ } else {
+ ui_.noSoundRadio->setChecked(true);
+ }
+
+ /* set radio button child option states */
+ setChildWidgetStates();
}
void QtHighlightEditor::updateResetToDefaultRulesVisibility() {
- ui_.buttonBox->button(QDialogButtonBox::RestoreDefaults)->setVisible(!highlightManager_->isDefaultRulesList());
+ ui_.buttonBox->button(QDialogButtonBox::RestoreDefaults)->setVisible(!highlightManager_->isDefaultRulesList());
}
}
diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h
index e45963c..2a9f06b 100644
--- a/Swift/QtUI/QtHighlightEditor.h
+++ b/Swift/QtUI/QtHighlightEditor.h
@@ -19,56 +19,56 @@
namespace Swift {
- class QtSettingsProvider;
- class QtSuggestingJIDInput;
- class QtWebKitChatView;
+ class QtSettingsProvider;
+ class QtSuggestingJIDInput;
+ class QtWebKitChatView;
- class QtHighlightEditor : public QWidget, public HighlightEditorWindow {
- Q_OBJECT
+ class QtHighlightEditor : public QWidget, public HighlightEditorWindow {
+ Q_OBJECT
- public:
- QtHighlightEditor(QtSettingsProvider* settings, QWidget* parent = NULL);
- virtual ~QtHighlightEditor();
+ public:
+ QtHighlightEditor(QtSettingsProvider* settings, QWidget* parent = NULL);
+ virtual ~QtHighlightEditor();
- virtual void show();
- virtual void setHighlightManager(HighlightManager* highlightManager);
- virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions);
+ virtual void show();
+ virtual void setHighlightManager(HighlightManager* highlightManager);
+ virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions);
- private slots:
- void colorOtherSelect();
- void colorCustomSelect();
- void soundOtherSelect();
- void soundCustomSelect();
- void onNewButtonClicked();
- void onDeleteButtonClicked();
- void onUpButtonClicked();
- void onDownButtonClicked();
- void onCurrentRowChanged(int currentRow);
- void onApplyButtonClick();
- void onCancelButtonClick();
- void onOkButtonClick();
- void setChildWidgetStates();
- void widgetClick();
- void disableDialog();
- void handleContactSuggestionRequested(const QString& text);
- void selectSoundFile();
- void onResetToDefaultRulesClicked();
+ private slots:
+ void colorOtherSelect();
+ void colorCustomSelect();
+ void soundOtherSelect();
+ void soundCustomSelect();
+ void onNewButtonClicked();
+ void onDeleteButtonClicked();
+ void onUpButtonClicked();
+ void onDownButtonClicked();
+ void onCurrentRowChanged(int currentRow);
+ void onApplyButtonClick();
+ void onCancelButtonClick();
+ void onOkButtonClick();
+ void setChildWidgetStates();
+ void widgetClick();
+ void disableDialog();
+ void handleContactSuggestionRequested(const QString& text);
+ void selectSoundFile();
+ void onResetToDefaultRulesClicked();
- private:
- void handleOnUserSelected(const Contact::ref& contact);
- void populateList();
- void selectRow(int row);
- int getSelectedRow() const;
- HighlightRule ruleFromDialog();
- void ruleToDialog(const HighlightRule& rule);
- void updateResetToDefaultRulesVisibility();
- void moveRowFromTo(int fromRow, int toRow);
+ private:
+ void handleOnUserSelected(const Contact::ref& contact);
+ void populateList();
+ void selectRow(int row);
+ int getSelectedRow() const;
+ HighlightRule ruleFromDialog();
+ void ruleToDialog(const HighlightRule& rule);
+ void updateResetToDefaultRulesVisibility();
+ void moveRowFromTo(int fromRow, int toRow);
- Ui::QtHighlightEditor ui_;
- QtSettingsProvider* settings_;
- HighlightManager* highlightManager_;
- QtSuggestingJIDInput* jid_;
- int previousRow_;
- };
+ Ui::QtHighlightEditor ui_;
+ QtSettingsProvider* settings_;
+ HighlightManager* highlightManager_;
+ QtSuggestingJIDInput* jid_;
+ int previousRow_;
+ };
}
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp
index 0a1f07a..5ed8114 100644
--- a/Swift/QtUI/QtHistoryWindow.cpp
+++ b/Swift/QtUI/QtHistoryWindow.cpp
@@ -42,227 +42,227 @@
namespace Swift {
QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* eventStream) :
- previousTopMessageWasSelf_(false),
- previousBottomMessageWasSelf_(false) {
- ui_.setupUi(this);
-
- theme_ = new QtChatTheme("");
- idCounter_ = 0;
-
- delete ui_.conversation_;
- conversation_ = new QtWebKitChatView(NULL, NULL, theme_, this, true); // Horrible unsafe. Do not do this. FIXME
- QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
- sizePolicy.setHorizontalStretch(80);
- sizePolicy.setVerticalStretch(0);
- conversation_->setSizePolicy(sizePolicy);
-
- ui_.conversation_ = conversation_;
- ui_.bottomLayout_->addWidget(conversation_);
-
- delete ui_.conversationRoster_;
- conversationRoster_ = new QtTreeWidget(eventStream, settings, QtTreeWidget::MessageDefaultJID, this);
- QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Expanding);
- sizePolicy2.setVerticalStretch(80);
- conversationRoster_->setSizePolicy(sizePolicy2);
- ui_.conversationRoster_ = conversationRoster_;
- ui_.bottomLeftLayout_->setDirection(QBoxLayout::BottomToTop);
- ui_.bottomLeftLayout_->addWidget(conversationRoster_);
-
- setWindowTitle(tr("History"));
-
- conversationRoster_->onSomethingSelectedChanged.connect(boost::bind(&QtHistoryWindow::handleSomethingSelectedChanged, this, _1));
- connect(conversation_, SIGNAL(scrollRequested(int)), this, SLOT(handleScrollRequested(int)));
- connect(conversation_, SIGNAL(scrollReachedTop()), this, SLOT(handleScrollReachedTop()));
- connect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
- connect(conversation_, SIGNAL(fontResized(int)), this, SLOT(handleFontResized(int)));
- connect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
- connect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
- connect(ui_.calendarWidget_, SIGNAL(activated(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
- connect(ui_.previousButton_, SIGNAL(clicked(bool)), this, SLOT(handlePreviousButtonClicked()));
- connect(ui_.nextButton_, SIGNAL(clicked(bool)), this, SLOT(handleNextButtonClicked()));
+ previousTopMessageWasSelf_(false),
+ previousBottomMessageWasSelf_(false) {
+ ui_.setupUi(this);
+
+ theme_ = new QtChatTheme("");
+ idCounter_ = 0;
+
+ delete ui_.conversation_;
+ conversation_ = new QtWebKitChatView(NULL, NULL, theme_, this, true); // Horrible unsafe. Do not do this. FIXME
+ QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ sizePolicy.setHorizontalStretch(80);
+ sizePolicy.setVerticalStretch(0);
+ conversation_->setSizePolicy(sizePolicy);
+
+ ui_.conversation_ = conversation_;
+ ui_.bottomLayout_->addWidget(conversation_);
+
+ delete ui_.conversationRoster_;
+ conversationRoster_ = new QtTreeWidget(eventStream, settings, QtTreeWidget::MessageDefaultJID, this);
+ QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Expanding);
+ sizePolicy2.setVerticalStretch(80);
+ conversationRoster_->setSizePolicy(sizePolicy2);
+ ui_.conversationRoster_ = conversationRoster_;
+ ui_.bottomLeftLayout_->setDirection(QBoxLayout::BottomToTop);
+ ui_.bottomLeftLayout_->addWidget(conversationRoster_);
+
+ setWindowTitle(tr("History"));
+
+ conversationRoster_->onSomethingSelectedChanged.connect(boost::bind(&QtHistoryWindow::handleSomethingSelectedChanged, this, _1));
+ connect(conversation_, SIGNAL(scrollRequested(int)), this, SLOT(handleScrollRequested(int)));
+ connect(conversation_, SIGNAL(scrollReachedTop()), this, SLOT(handleScrollReachedTop()));
+ connect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
+ connect(conversation_, SIGNAL(fontResized(int)), this, SLOT(handleFontResized(int)));
+ connect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
+ connect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+ connect(ui_.calendarWidget_, SIGNAL(activated(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+ connect(ui_.previousButton_, SIGNAL(clicked(bool)), this, SLOT(handlePreviousButtonClicked()));
+ connect(ui_.nextButton_, SIGNAL(clicked(bool)), this, SLOT(handleNextButtonClicked()));
}
QtHistoryWindow::~QtHistoryWindow() {
- disconnect(conversation_, SIGNAL(scrollRequested(int)), this, SLOT(handleScrollRequested(int)));
- disconnect(conversation_, SIGNAL(scrollReachedTop()), this, SLOT(handleScrollReachedTop()));
- disconnect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
- disconnect(conversation_, SIGNAL(fontResized(int)), this, SLOT(handleFontResized(int)));
- disconnect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
- disconnect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
- disconnect(ui_.calendarWidget_, SIGNAL(activated(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
- disconnect(ui_.previousButton_, SIGNAL(clicked(bool)), this, SLOT(handlePreviousButtonClicked()));
- disconnect(ui_.nextButton_, SIGNAL(clicked(bool)), this, SLOT(handleNextButtonClicked()));
-
- delete theme_;
- delete conversation_;
- // TODO: delete ui_
+ disconnect(conversation_, SIGNAL(scrollRequested(int)), this, SLOT(handleScrollRequested(int)));
+ disconnect(conversation_, SIGNAL(scrollReachedTop()), this, SLOT(handleScrollReachedTop()));
+ disconnect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
+ disconnect(conversation_, SIGNAL(fontResized(int)), this, SLOT(handleFontResized(int)));
+ disconnect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
+ disconnect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+ disconnect(ui_.calendarWidget_, SIGNAL(activated(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+ disconnect(ui_.previousButton_, SIGNAL(clicked(bool)), this, SLOT(handlePreviousButtonClicked()));
+ disconnect(ui_.nextButton_, SIGNAL(clicked(bool)), this, SLOT(handleNextButtonClicked()));
+
+ delete theme_;
+ delete conversation_;
+ // TODO: delete ui_
}
void QtHistoryWindow::activate() {
- emit wantsToActivate();
+ emit wantsToActivate();
}
void QtHistoryWindow::showEvent(QShowEvent* event) {
- emit windowOpening();
- emit titleUpdated();
- QWidget::showEvent(event);
+ emit windowOpening();
+ emit titleUpdated();
+ QWidget::showEvent(event);
}
void QtHistoryWindow::closeEvent(QCloseEvent* event) {
- emit windowClosing();
- event->accept();
+ emit windowClosing();
+ event->accept();
}
void QtHistoryWindow::setRosterModel(Roster* model) {
- conversationRoster_->setRosterModel(model);
+ conversationRoster_->setRosterModel(model);
}
void QtHistoryWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop) {
- QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str());
-
- QString messageHTML(P2QSTRING(message));
- messageHTML = QtUtilities::htmlEscape(messageHTML);
- QString searchTerm = ui_.searchBox_->lineEdit()->text();
- if (searchTerm.length()) {
- messageHTML.replace(searchTerm, "<span style='background-color: yellow'>" + searchTerm + "</span>");
- }
-
- // note: time uses localtime
- QDate date = QDate(time.date().year(), time.date().month(), time.date().day());
- QTime dayTime = QTime(time.time_of_day().hours(), time.time_of_day().minutes(), time.time_of_day().seconds());
- QDateTime qTime = QDateTime(date, dayTime);
-
- std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
-
- QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
-
- if (addAtTheTop) {
- bool appendToPrevious = ((senderIsSelf && previousTopMessageWasSelf_) || (!senderIsSelf && !previousTopMessageWasSelf_&& previousTopSenderName_ == P2QSTRING(senderName)));
- conversation_->addMessageTop(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, QtUtilities::htmlEscape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(message))));
-
- previousTopMessageWasSelf_ = senderIsSelf;
- previousTopSenderName_ = P2QSTRING(senderName);
- }
- else {
- bool appendToPrevious = ((senderIsSelf && previousBottomMessageWasSelf_) || (!senderIsSelf && !previousBottomMessageWasSelf_&& previousBottomSenderName_ == P2QSTRING(senderName)));
- conversation_->addMessageBottom(boost::make_shared<MessageSnippet>(messageHTML, QtUtilities::htmlEscape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(message)));
- previousBottomMessageWasSelf_ = senderIsSelf;
- previousBottomSenderName_ = P2QSTRING(senderName);
- }
-
- // keep track of the days viewable in the chatView
- if (!dates_.count(date)) {
- dates_.insert(date);
- }
+ QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str());
+
+ QString messageHTML(P2QSTRING(message));
+ messageHTML = QtUtilities::htmlEscape(messageHTML);
+ QString searchTerm = ui_.searchBox_->lineEdit()->text();
+ if (searchTerm.length()) {
+ messageHTML.replace(searchTerm, "<span style='background-color: yellow'>" + searchTerm + "</span>");
+ }
+
+ // note: time uses localtime
+ QDate date = QDate(time.date().year(), time.date().month(), time.date().day());
+ QTime dayTime = QTime(time.time_of_day().hours(), time.time_of_day().minutes(), time.time_of_day().seconds());
+ QDateTime qTime = QDateTime(date, dayTime);
+
+ std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
+
+ QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
+
+ if (addAtTheTop) {
+ bool appendToPrevious = ((senderIsSelf && previousTopMessageWasSelf_) || (!senderIsSelf && !previousTopMessageWasSelf_&& previousTopSenderName_ == P2QSTRING(senderName)));
+ conversation_->addMessageTop(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, QtUtilities::htmlEscape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(message))));
+
+ previousTopMessageWasSelf_ = senderIsSelf;
+ previousTopSenderName_ = P2QSTRING(senderName);
+ }
+ else {
+ bool appendToPrevious = ((senderIsSelf && previousBottomMessageWasSelf_) || (!senderIsSelf && !previousBottomMessageWasSelf_&& previousBottomSenderName_ == P2QSTRING(senderName)));
+ conversation_->addMessageBottom(boost::make_shared<MessageSnippet>(messageHTML, QtUtilities::htmlEscape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(message)));
+ previousBottomMessageWasSelf_ = senderIsSelf;
+ previousBottomSenderName_ = P2QSTRING(senderName);
+ }
+
+ // keep track of the days viewable in the chatView
+ if (!dates_.count(date)) {
+ dates_.insert(date);
+ }
}
void QtHistoryWindow::handleSomethingSelectedChanged(RosterItem* item) {
- onSelectedContactChanged(item);
+ onSelectedContactChanged(item);
}
void QtHistoryWindow::resetConversationView() {
- previousTopMessageWasSelf_ = false;
- previousBottomMessageWasSelf_ = false;
- previousTopSenderName_.clear();
- previousBottomSenderName_.clear();
+ previousTopMessageWasSelf_ = false;
+ previousBottomMessageWasSelf_ = false;
+ previousTopSenderName_.clear();
+ previousBottomSenderName_.clear();
- dates_.clear();
- conversation_->resetView();
+ dates_.clear();
+ conversation_->resetView();
}
void QtHistoryWindow::handleScrollRequested(int pos) {
- // first message starts with offset 5
- if (pos < 5) {
- pos = 5;
- }
-
- QDate currentDate;
- foreach (const QDate& date, dates_) {
- int snippetPosition = conversation_->getSnippetPositionByDate(date);
- if (snippetPosition <= pos) {
- currentDate = date;
- }
- }
-
- if (ui_.calendarWidget_->selectedDate() != currentDate) {
- ui_.calendarWidget_->setSelectedDate(currentDate);
- }
+ // first message starts with offset 5
+ if (pos < 5) {
+ pos = 5;
+ }
+
+ QDate currentDate;
+ foreach (const QDate& date, dates_) {
+ int snippetPosition = conversation_->getSnippetPositionByDate(date);
+ if (snippetPosition <= pos) {
+ currentDate = date;
+ }
+ }
+
+ if (ui_.calendarWidget_->selectedDate() != currentDate) {
+ ui_.calendarWidget_->setSelectedDate(currentDate);
+ }
}
void QtHistoryWindow::handleScrollReachedTop() {
- if (dates_.empty()) {
- return;
- }
-
- int year, month, day;
- QDate firstDate = *dates_.begin();
- firstDate.getDate(&year, &month, &day);
- onScrollReachedTop(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
+ if (dates_.empty()) {
+ return;
+ }
+
+ int year, month, day;
+ QDate firstDate = *dates_.begin();
+ firstDate.getDate(&year, &month, &day);
+ onScrollReachedTop(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
}
void QtHistoryWindow::handleScrollReachedBottom() {
- if (dates_.empty()) {
- return;
- }
-
- int year, month, day;
- QDate lastDate = *dates_.rbegin();
- lastDate.getDate(&year, &month, &day);
- onScrollReachedBottom(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
+ if (dates_.empty()) {
+ return;
+ }
+
+ int year, month, day;
+ QDate lastDate = *dates_.rbegin();
+ lastDate.getDate(&year, &month, &day);
+ onScrollReachedBottom(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
}
void QtHistoryWindow::handleReturnPressed() {
- onReturnPressed(ui_.searchBox_->lineEdit()->text().toStdString());
+ onReturnPressed(ui_.searchBox_->lineEdit()->text().toStdString());
}
void QtHistoryWindow::handleCalendarClicked(const QDate& date) {
- int year, month, day;
- QDate tempDate = date; // getDate discards const qualifier
- tempDate.getDate(&year, &month, &day);
- onCalendarClicked(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
+ int year, month, day;
+ QDate tempDate = date; // getDate discards const qualifier
+ tempDate.getDate(&year, &month, &day);
+ onCalendarClicked(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
}
void QtHistoryWindow::setDate(const boost::gregorian::date& date) {
- ui_.calendarWidget_->setSelectedDate(QDate::fromJulianDay(date.julian_day()));
+ ui_.calendarWidget_->setSelectedDate(QDate::fromJulianDay(date.julian_day()));
}
void QtHistoryWindow::handleNextButtonClicked() {
- onNextButtonClicked();
+ onNextButtonClicked();
}
void QtHistoryWindow::handlePreviousButtonClicked() {
- onPreviousButtonClicked();
+ onPreviousButtonClicked();
}
void QtHistoryWindow::handleFontResized(int fontSizeSteps) {
- conversation_->resizeFont(fontSizeSteps);
+ conversation_->resizeFont(fontSizeSteps);
- emit fontResized(fontSizeSteps);
+ emit fontResized(fontSizeSteps);
}
void QtHistoryWindow::resetConversationViewTopInsertPoint() {
- previousTopMessageWasSelf_ = false;
- previousTopSenderName_ = QString();
- conversation_->resetTopInsertPoint();
+ previousTopMessageWasSelf_ = false;
+ previousTopSenderName_ = QString();
+ conversation_->resetTopInsertPoint();
}
std::string QtHistoryWindow::getSearchBoxText() {
- return ui_.searchBox_->lineEdit()->text().toStdString();
+ return ui_.searchBox_->lineEdit()->text().toStdString();
}
boost::gregorian::date QtHistoryWindow::getLastVisibleDate() {
- if (!dates_.empty()) {
- QDate lastDate = *dates_.rbegin();
- int year, month, day;
- lastDate.getDate(&year, &month, &day);
-
- return boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day));
- }
- return boost::gregorian::date(boost::gregorian::not_a_date_time);
+ if (!dates_.empty()) {
+ QDate lastDate = *dates_.rbegin();
+ int year, month, day;
+ lastDate.getDate(&year, &month, &day);
+
+ return boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day));
+ }
+ return boost::gregorian::date(boost::gregorian::not_a_date_time);
}
std::string QtHistoryWindow::getID() const {
- return "QtHistoryWindow";
+ return "QtHistoryWindow";
}
}
diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h
index 2008079..02d7fb8 100644
--- a/Swift/QtUI/QtHistoryWindow.h
+++ b/Swift/QtUI/QtHistoryWindow.h
@@ -22,61 +22,61 @@
#include <Swift/QtUI/ui_QtHistoryWindow.h>
namespace Swift {
- class QtTabbable;
- class QtTreeWidget;
- class QtWebKitChatView;
- class QtChatTheme;
- class SettingsProvider;
- class UIEventStream;
-
- class QtHistoryWindow : public QtTabbable, public HistoryWindow {
- Q_OBJECT
-
- public:
- QtHistoryWindow(SettingsProvider*, UIEventStream*);
- ~QtHistoryWindow();
- void activate();
- void setRosterModel(Roster*);
- void addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop);
- void resetConversationView();
- void resetConversationViewTopInsertPoint();
- void setDate(const boost::gregorian::date& date);
-
- void closeEvent(QCloseEvent* event);
- void showEvent(QShowEvent* event);
-
- std::string getSearchBoxText();
- boost::gregorian::date getLastVisibleDate();
-
- virtual std::string getID() const;
-
- signals:
- void fontResized(int);
-
- public slots:
- void handleFontResized(int fontSizeSteps);
-
- protected slots:
- void handleScrollRequested(int pos);
- void handleScrollReachedTop();
- void handleScrollReachedBottom();
- void handleReturnPressed();
- void handleCalendarClicked(const QDate& date);
- void handlePreviousButtonClicked();
- void handleNextButtonClicked();
-
- private:
- void handleSomethingSelectedChanged(RosterItem* item);
-
- Ui::QtHistoryWindow ui_;
- QtChatTheme* theme_;
- QtWebKitChatView* conversation_;
- QtTreeWidget* conversationRoster_;
- std::set<QDate> dates_;
- int idCounter_;
- bool previousTopMessageWasSelf_;
- QString previousTopSenderName_;
- bool previousBottomMessageWasSelf_;
- QString previousBottomSenderName_;
- };
+ class QtTabbable;
+ class QtTreeWidget;
+ class QtWebKitChatView;
+ class QtChatTheme;
+ class SettingsProvider;
+ class UIEventStream;
+
+ class QtHistoryWindow : public QtTabbable, public HistoryWindow {
+ Q_OBJECT
+
+ public:
+ QtHistoryWindow(SettingsProvider*, UIEventStream*);
+ ~QtHistoryWindow();
+ void activate();
+ void setRosterModel(Roster*);
+ void addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop);
+ void resetConversationView();
+ void resetConversationViewTopInsertPoint();
+ void setDate(const boost::gregorian::date& date);
+
+ void closeEvent(QCloseEvent* event);
+ void showEvent(QShowEvent* event);
+
+ std::string getSearchBoxText();
+ boost::gregorian::date getLastVisibleDate();
+
+ virtual std::string getID() const;
+
+ signals:
+ void fontResized(int);
+
+ public slots:
+ void handleFontResized(int fontSizeSteps);
+
+ protected slots:
+ void handleScrollRequested(int pos);
+ void handleScrollReachedTop();
+ void handleScrollReachedBottom();
+ void handleReturnPressed();
+ void handleCalendarClicked(const QDate& date);
+ void handlePreviousButtonClicked();
+ void handleNextButtonClicked();
+
+ private:
+ void handleSomethingSelectedChanged(RosterItem* item);
+
+ Ui::QtHistoryWindow ui_;
+ QtChatTheme* theme_;
+ QtWebKitChatView* conversation_;
+ QtTreeWidget* conversationRoster_;
+ std::set<QDate> dates_;
+ int idCounter_;
+ bool previousTopMessageWasSelf_;
+ QString previousTopSenderName_;
+ bool previousBottomMessageWasSelf_;
+ QString previousBottomSenderName_;
+ };
}
diff --git a/Swift/QtUI/QtJoinMUCWindow.cpp b/Swift/QtUI/QtJoinMUCWindow.cpp
index 53944da..7225b06 100644
--- a/Swift/QtUI/QtJoinMUCWindow.cpp
+++ b/Swift/QtUI/QtJoinMUCWindow.cpp
@@ -17,59 +17,59 @@ namespace Swift {
QtJoinMUCWindow::QtJoinMUCWindow(UIEventStream* uiEventStream) : uiEventStream(uiEventStream) {
- ui.setupUi(this);
+ ui.setupUi(this);
#if QT_VERSION >= 0x040700
- ui.room->setPlaceholderText(tr("someroom@rooms.example.com"));
+ ui.room->setPlaceholderText(tr("someroom@rooms.example.com"));
#endif
- connect(ui.room, SIGNAL(returnPressed()), this, SLOT(handleJoin()));
- connect(ui.searchButton, SIGNAL(clicked()), this, SLOT(handleSearch()));
- connect(ui.joinButton, SIGNAL(clicked()), this, SLOT(handleJoin()));
+ connect(ui.room, SIGNAL(returnPressed()), this, SLOT(handleJoin()));
+ connect(ui.searchButton, SIGNAL(clicked()), this, SLOT(handleSearch()));
+ connect(ui.joinButton, SIGNAL(clicked()), this, SLOT(handleJoin()));
#if QT_VERSION < 0x050200
- // FIXME: Temporarily set focus on the nickName field first, so that the
- // placeholder for the room is visible. This is just because Qt hides
- // the placeholder when a widget is focused for some reason.
- // Tracked upstream as QTBUG-33237 and fixed with Qt 5.2.0.
- ui.nickName->setFocus();
+ // FIXME: Temporarily set focus on the nickName field first, so that the
+ // placeholder for the room is visible. This is just because Qt hides
+ // the placeholder when a widget is focused for some reason.
+ // Tracked upstream as QTBUG-33237 and fixed with Qt 5.2.0.
+ ui.nickName->setFocus();
#endif
- ui.instantRoom->setChecked(true);
- ui.nickName->setValidator(new NickValidator(this));
- ui.room->setValidator(new RoomJIDValidator(this));
+ ui.instantRoom->setChecked(true);
+ ui.nickName->setValidator(new NickValidator(this));
+ ui.room->setValidator(new RoomJIDValidator(this));
}
void QtJoinMUCWindow::handleJoin() {
- if (ui.room->text().isEmpty() || !ui.room->hasAcceptableInput()) {
- QToolTip::showText(ui.room->mapToGlobal(QPoint()), tr("Please enter a valid room address."), ui.room);
- return;
- }
- if (ui.nickName->text().isEmpty() || !ui.nickName->hasAcceptableInput()) {
- QToolTip::showText(ui.nickName->mapToGlobal(QPoint()), tr("Please enter a valid nickname."), ui.nickName);
- return;
- }
+ if (ui.room->text().isEmpty() || !ui.room->hasAcceptableInput()) {
+ QToolTip::showText(ui.room->mapToGlobal(QPoint()), tr("Please enter a valid room address."), ui.room);
+ return;
+ }
+ if (ui.nickName->text().isEmpty() || !ui.nickName->hasAcceptableInput()) {
+ QToolTip::showText(ui.nickName->mapToGlobal(QPoint()), tr("Please enter a valid nickname."), ui.nickName);
+ return;
+ }
- lastSetNick = Q2PSTRING(ui.nickName->text());
- std::string password = Q2PSTRING(ui.password->text());
- JID room(Q2PSTRING(ui.room->text()));
- uiEventStream->send(boost::make_shared<JoinMUCUIEvent>(room, password, lastSetNick, ui.joinAutomatically->isChecked(), !ui.instantRoom->isChecked()));
- hide();
+ lastSetNick = Q2PSTRING(ui.nickName->text());
+ std::string password = Q2PSTRING(ui.password->text());
+ JID room(Q2PSTRING(ui.room->text()));
+ uiEventStream->send(boost::make_shared<JoinMUCUIEvent>(room, password, lastSetNick, ui.joinAutomatically->isChecked(), !ui.instantRoom->isChecked()));
+ hide();
}
void QtJoinMUCWindow::handleSearch() {
- onSearchMUC();
+ onSearchMUC();
}
void QtJoinMUCWindow::setNick(const std::string& nick) {
- ui.nickName->setText(P2QSTRING(nick));
- lastSetNick = nick;
+ ui.nickName->setText(P2QSTRING(nick));
+ lastSetNick = nick;
}
void QtJoinMUCWindow::setMUC(const std::string& nick) {
- ui.room->setText(P2QSTRING(nick));
+ ui.room->setText(P2QSTRING(nick));
}
void QtJoinMUCWindow::show() {
- QWidget::show();
- QWidget::activateWindow();
- ui.password->setText("");
+ QWidget::show();
+ QWidget::activateWindow();
+ ui.password->setText("");
}
}
diff --git a/Swift/QtUI/QtJoinMUCWindow.h b/Swift/QtUI/QtJoinMUCWindow.h
index 618f2e9..c2e8068 100644
--- a/Swift/QtUI/QtJoinMUCWindow.h
+++ b/Swift/QtUI/QtJoinMUCWindow.h
@@ -16,60 +16,60 @@
#include <Swift/QtUI/ui_QtJoinMUCWindow.h>
namespace Swift {
- class UIEventStream;
- class NickValidator : public QValidator {
- Q_OBJECT
- public:
- NickValidator(QObject* parent) : QValidator(parent) {
- }
-
- virtual QValidator::State validate(QString& input, int& /*pos*/) const {
- if (input.isEmpty()) {
- return QValidator::Intermediate;
- }
- JID test("alice", "wonderland.lit", Q2PSTRING(input));
-
- return test.isValid() ? QValidator::Acceptable : QValidator::Invalid;
- }
- };
-
- class RoomJIDValidator : public QValidator {
- Q_OBJECT
- public:
- RoomJIDValidator(QObject* parent) : QValidator(parent) {
- }
-
- virtual QValidator::State validate(QString& input, int& /*pos*/) const {
- if (input.isEmpty()) {
- return QValidator::Intermediate;
- }
- JID roomJID(Q2PSTRING(input));
-
- if (roomJID.getNode().empty() || roomJID.getDomain().empty()) {
- return QValidator::Intermediate;
- }
-
- return (roomJID.getResource().empty() && !roomJID.getNode().empty() && !roomJID.getDomain().empty() && roomJID.isValid()) ? QValidator::Acceptable : QValidator::Invalid;
- }
- };
-
- class QtJoinMUCWindow : public QWidget, public JoinMUCWindow {
- Q_OBJECT
- public:
- QtJoinMUCWindow(UIEventStream* uiEventStream);
-
- virtual void setNick(const std::string& nick);
- virtual void setMUC(const std::string& nick);
-
- virtual void show();
-
- private slots:
- void handleJoin();
- void handleSearch();
-
- private:
- Ui::QtJoinMUCWindow ui;
- std::string lastSetNick;
- UIEventStream* uiEventStream;
- };
+ class UIEventStream;
+ class NickValidator : public QValidator {
+ Q_OBJECT
+ public:
+ NickValidator(QObject* parent) : QValidator(parent) {
+ }
+
+ virtual QValidator::State validate(QString& input, int& /*pos*/) const {
+ if (input.isEmpty()) {
+ return QValidator::Intermediate;
+ }
+ JID test("alice", "wonderland.lit", Q2PSTRING(input));
+
+ return test.isValid() ? QValidator::Acceptable : QValidator::Invalid;
+ }
+ };
+
+ class RoomJIDValidator : public QValidator {
+ Q_OBJECT
+ public:
+ RoomJIDValidator(QObject* parent) : QValidator(parent) {
+ }
+
+ virtual QValidator::State validate(QString& input, int& /*pos*/) const {
+ if (input.isEmpty()) {
+ return QValidator::Intermediate;
+ }
+ JID roomJID(Q2PSTRING(input));
+
+ if (roomJID.getNode().empty() || roomJID.getDomain().empty()) {
+ return QValidator::Intermediate;
+ }
+
+ return (roomJID.getResource().empty() && !roomJID.getNode().empty() && !roomJID.getDomain().empty() && roomJID.isValid()) ? QValidator::Acceptable : QValidator::Invalid;
+ }
+ };
+
+ class QtJoinMUCWindow : public QWidget, public JoinMUCWindow {
+ Q_OBJECT
+ public:
+ QtJoinMUCWindow(UIEventStream* uiEventStream);
+
+ virtual void setNick(const std::string& nick);
+ virtual void setMUC(const std::string& nick);
+
+ virtual void show();
+
+ private slots:
+ void handleJoin();
+ void handleSearch();
+
+ private:
+ Ui::QtJoinMUCWindow ui;
+ std::string lastSetNick;
+ UIEventStream* uiEventStream;
+ };
}
diff --git a/Swift/QtUI/QtLineEdit.cpp b/Swift/QtUI/QtLineEdit.cpp
index a98663c..d3ec4c4 100644
--- a/Swift/QtUI/QtLineEdit.cpp
+++ b/Swift/QtUI/QtLineEdit.cpp
@@ -14,10 +14,10 @@ QtLineEdit::QtLineEdit(QWidget* parent) : QLineEdit(parent) {
}
void QtLineEdit::keyPressEvent(QKeyEvent* event) {
- if (event->key() == Qt::Key_Escape) {
- emit escapePressed();
- }
- QLineEdit::keyPressEvent(event);
+ if (event->key() == Qt::Key_Escape) {
+ emit escapePressed();
+ }
+ QLineEdit::keyPressEvent(event);
}
}
diff --git a/Swift/QtUI/QtLineEdit.h b/Swift/QtUI/QtLineEdit.h
index 1c7240a..557f025 100644
--- a/Swift/QtUI/QtLineEdit.h
+++ b/Swift/QtUI/QtLineEdit.h
@@ -9,13 +9,13 @@
#include <QLineEdit>
namespace Swift {
- class QtLineEdit : public QLineEdit {
- Q_OBJECT
- public:
- QtLineEdit(QWidget* parent = NULL);
- signals:
- void escapePressed();
- protected:
- virtual void keyPressEvent(QKeyEvent* event);
- };
+ class QtLineEdit : public QLineEdit {
+ Q_OBJECT
+ public:
+ QtLineEdit(QWidget* parent = NULL);
+ signals:
+ void escapePressed();
+ protected:
+ virtual void keyPressEvent(QKeyEvent* event);
+ };
}
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp
index 229df7f..5f15f4c 100644
--- a/Swift/QtUI/QtLoginWindow.cpp
+++ b/Swift/QtUI/QtLoginWindow.cpp
@@ -54,524 +54,524 @@
namespace Swift{
QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* settings, TimerFactory* timerFactory) : QMainWindow(), settings_(settings), timerFactory_(timerFactory) {
- uiEventStream_ = uiEventStream;
+ uiEventStream_ = uiEventStream;
- setWindowTitle("Swift");
+ setWindowTitle("Swift");
#ifndef Q_OS_MAC
#ifdef Q_OS_WIN32
- setWindowIcon(QIcon(":/logo-icon-16-win.png"));
+ setWindowIcon(QIcon(":/logo-icon-16-win.png"));
#else
- setWindowIcon(QIcon(":/logo-icon-16.png"));
+ setWindowIcon(QIcon(":/logo-icon-16.png"));
#endif
#endif
- QtUtilities::setX11Resource(this, "Main");
- setAccessibleName(tr("Swift Login Window"));
- //setAccessibleDescription(tr("This window is used for providing credentials to log into your XMPP service"));
-
- resize(200, 500);
- setContentsMargins(0,0,0,0);
- QWidget *centralWidget = new QWidget(this);
- setCentralWidget(centralWidget);
- QBoxLayout *topLayout = new QBoxLayout(QBoxLayout::TopToBottom, centralWidget);
- stack_ = new QStackedWidget(centralWidget);
- topLayout->addWidget(stack_);
- topLayout->setMargin(0);
- loginWidgetWrapper_ = new QWidget(this);
- loginWidgetWrapper_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
- QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, loginWidgetWrapper_);
- layout->addStretch(2);
-
- QLabel* logo = new QLabel(this);
- logo->setPixmap(QPixmap(":/logo-shaded-text.256.png"));
- logo->setScaledContents(true);
- logo->setFixedSize(192,192);
-
- QWidget *logoWidget = new QWidget(this);
- QHBoxLayout *logoLayout = new QHBoxLayout();
- logoLayout->setMargin(0);
- logoLayout->addStretch(0);
- logoLayout->addWidget(logo);
- logoLayout->addStretch(0);
- logoWidget->setLayout(logoLayout);
- layout->addWidget(logoWidget);
-
- layout->addStretch(2);
-
- QLabel* jidLabel = new QLabel(this);
- jidLabel->setText("<font size='-1'>" + tr("User address:") + "</font>");
- layout->addWidget(jidLabel);
-
-
- username_ = new QComboBox(this);
- username_->setEditable(true);
- username_->setWhatsThis(tr("User address - looks like someuser@someserver.com"));
- username_->setToolTip(tr("User address - looks like someuser@someserver.com"));
- username_->view()->installEventFilter(this);
- username_->setAccessibleName(tr("User address (of the form someuser@someserver.com)"));
- username_->setAccessibleDescription(tr("This is the user address that you'll be using to log in with"));
- layout->addWidget(username_);
- QLabel* jidHintLabel = new QLabel(this);
- jidHintLabel->setText("<font size='-1' color='grey' >" + tr("Example: alice@wonderland.lit") + "</font>");
- jidHintLabel->setAlignment(Qt::AlignRight);
- layout->addWidget(jidHintLabel);
-
-
- QLabel* passwordLabel = new QLabel();
- passwordLabel->setText("<font size='-1'>" + tr("Password:") + "</font>");
- passwordLabel->setAccessibleName(tr("User password"));
- passwordLabel->setAccessibleDescription(tr("This is the password you'll use to log in to the XMPP service"));
- layout->addWidget(passwordLabel);
-
-
- QWidget* w = new QWidget(this);
- w->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
- layout->addWidget(w);
-
- QHBoxLayout* credentialsLayout = new QHBoxLayout(w);
- credentialsLayout->setMargin(0);
- credentialsLayout->setSpacing(3);
- password_ = new QLineEdit(this);
- password_->setEchoMode(QLineEdit::Password);
- connect(password_, SIGNAL(returnPressed()), this, SLOT(loginClicked()));
- connect(username_->lineEdit(), SIGNAL(returnPressed()), password_, SLOT(setFocus()));
- connect(username_, SIGNAL(editTextChanged(const QString&)), this, SLOT(handleUsernameTextChanged()));
- credentialsLayout->addWidget(password_);
-
- certificateButton_ = new QToolButton(this);
- certificateButton_->setCheckable(true);
- certificateButton_->setIcon(QIcon(":/icons/certificate.png"));
- certificateButton_->setToolTip(tr("Click if you have a personal certificate used for login to the service."));
- certificateButton_->setWhatsThis(tr("Click if you have a personal certificate used for login to the service."));
- certificateButton_->setAccessibleName(tr("Login with certificate"));
- certificateButton_->setAccessibleDescription(tr("Click if you have a personal certificate used for login to the service."));
-
- credentialsLayout->addWidget(certificateButton_);
- connect(certificateButton_, SIGNAL(clicked(bool)), SLOT(handleCertficateChecked(bool)));
-
- loginButton_ = new QPushButton(this);
- loginButton_->setText(tr("Connect"));
- loginButton_->setAutoDefault(true);
- loginButton_->setDefault(true);
- loginButton_->setAccessibleName(tr("Connect now"));
- layout->addWidget(loginButton_);
-
- QLabel* connectionOptionsLabel = new QLabel(this);
- connectionOptionsLabel->setText("<a href=\"#\"><font size='-1'>" + QObject::tr("Connection Options") + "</font></a>");
- connectionOptionsLabel->setTextFormat(Qt::RichText);
- connectionOptionsLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
- layout->addWidget(connectionOptionsLabel);
- connect(connectionOptionsLabel, SIGNAL(linkActivated(const QString&)), SLOT(handleOpenConnectionOptions()));
-
- message_ = new QLabel(this);
- message_->setTextFormat(Qt::RichText);
- message_->setWordWrap(true);
- layout->addWidget(message_);
-
- layout->addStretch(2);
- remember_ = new QCheckBox(tr("Remember Password?"), this);
- layout->addWidget(remember_);
- loginAutomatically_ = new QCheckBox(tr("Login Automatically?"), this);
- layout->addWidget(loginAutomatically_);
-
- connect(loginButton_, SIGNAL(clicked()), SLOT(loginClicked()));
- stack_->addWidget(loginWidgetWrapper_);
+ QtUtilities::setX11Resource(this, "Main");
+ setAccessibleName(tr("Swift Login Window"));
+ //setAccessibleDescription(tr("This window is used for providing credentials to log into your XMPP service"));
+
+ resize(200, 500);
+ setContentsMargins(0,0,0,0);
+ QWidget *centralWidget = new QWidget(this);
+ setCentralWidget(centralWidget);
+ QBoxLayout *topLayout = new QBoxLayout(QBoxLayout::TopToBottom, centralWidget);
+ stack_ = new QStackedWidget(centralWidget);
+ topLayout->addWidget(stack_);
+ topLayout->setMargin(0);
+ loginWidgetWrapper_ = new QWidget(this);
+ loginWidgetWrapper_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
+ QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, loginWidgetWrapper_);
+ layout->addStretch(2);
+
+ QLabel* logo = new QLabel(this);
+ logo->setPixmap(QPixmap(":/logo-shaded-text.256.png"));
+ logo->setScaledContents(true);
+ logo->setFixedSize(192,192);
+
+ QWidget *logoWidget = new QWidget(this);
+ QHBoxLayout *logoLayout = new QHBoxLayout();
+ logoLayout->setMargin(0);
+ logoLayout->addStretch(0);
+ logoLayout->addWidget(logo);
+ logoLayout->addStretch(0);
+ logoWidget->setLayout(logoLayout);
+ layout->addWidget(logoWidget);
+
+ layout->addStretch(2);
+
+ QLabel* jidLabel = new QLabel(this);
+ jidLabel->setText("<font size='-1'>" + tr("User address:") + "</font>");
+ layout->addWidget(jidLabel);
+
+
+ username_ = new QComboBox(this);
+ username_->setEditable(true);
+ username_->setWhatsThis(tr("User address - looks like someuser@someserver.com"));
+ username_->setToolTip(tr("User address - looks like someuser@someserver.com"));
+ username_->view()->installEventFilter(this);
+ username_->setAccessibleName(tr("User address (of the form someuser@someserver.com)"));
+ username_->setAccessibleDescription(tr("This is the user address that you'll be using to log in with"));
+ layout->addWidget(username_);
+ QLabel* jidHintLabel = new QLabel(this);
+ jidHintLabel->setText("<font size='-1' color='grey' >" + tr("Example: alice@wonderland.lit") + "</font>");
+ jidHintLabel->setAlignment(Qt::AlignRight);
+ layout->addWidget(jidHintLabel);
+
+
+ QLabel* passwordLabel = new QLabel();
+ passwordLabel->setText("<font size='-1'>" + tr("Password:") + "</font>");
+ passwordLabel->setAccessibleName(tr("User password"));
+ passwordLabel->setAccessibleDescription(tr("This is the password you'll use to log in to the XMPP service"));
+ layout->addWidget(passwordLabel);
+
+
+ QWidget* w = new QWidget(this);
+ w->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
+ layout->addWidget(w);
+
+ QHBoxLayout* credentialsLayout = new QHBoxLayout(w);
+ credentialsLayout->setMargin(0);
+ credentialsLayout->setSpacing(3);
+ password_ = new QLineEdit(this);
+ password_->setEchoMode(QLineEdit::Password);
+ connect(password_, SIGNAL(returnPressed()), this, SLOT(loginClicked()));
+ connect(username_->lineEdit(), SIGNAL(returnPressed()), password_, SLOT(setFocus()));
+ connect(username_, SIGNAL(editTextChanged(const QString&)), this, SLOT(handleUsernameTextChanged()));
+ credentialsLayout->addWidget(password_);
+
+ certificateButton_ = new QToolButton(this);
+ certificateButton_->setCheckable(true);
+ certificateButton_->setIcon(QIcon(":/icons/certificate.png"));
+ certificateButton_->setToolTip(tr("Click if you have a personal certificate used for login to the service."));
+ certificateButton_->setWhatsThis(tr("Click if you have a personal certificate used for login to the service."));
+ certificateButton_->setAccessibleName(tr("Login with certificate"));
+ certificateButton_->setAccessibleDescription(tr("Click if you have a personal certificate used for login to the service."));
+
+ credentialsLayout->addWidget(certificateButton_);
+ connect(certificateButton_, SIGNAL(clicked(bool)), SLOT(handleCertficateChecked(bool)));
+
+ loginButton_ = new QPushButton(this);
+ loginButton_->setText(tr("Connect"));
+ loginButton_->setAutoDefault(true);
+ loginButton_->setDefault(true);
+ loginButton_->setAccessibleName(tr("Connect now"));
+ layout->addWidget(loginButton_);
+
+ QLabel* connectionOptionsLabel = new QLabel(this);
+ connectionOptionsLabel->setText("<a href=\"#\"><font size='-1'>" + QObject::tr("Connection Options") + "</font></a>");
+ connectionOptionsLabel->setTextFormat(Qt::RichText);
+ connectionOptionsLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+ layout->addWidget(connectionOptionsLabel);
+ connect(connectionOptionsLabel, SIGNAL(linkActivated(const QString&)), SLOT(handleOpenConnectionOptions()));
+
+ message_ = new QLabel(this);
+ message_->setTextFormat(Qt::RichText);
+ message_->setWordWrap(true);
+ layout->addWidget(message_);
+
+ layout->addStretch(2);
+ remember_ = new QCheckBox(tr("Remember Password?"), this);
+ layout->addWidget(remember_);
+ loginAutomatically_ = new QCheckBox(tr("Login Automatically?"), this);
+ layout->addWidget(loginAutomatically_);
+
+ connect(loginButton_, SIGNAL(clicked()), SLOT(loginClicked()));
+ stack_->addWidget(loginWidgetWrapper_);
#ifdef SWIFTEN_PLATFORM_MACOSX
- menuBar_ = new QMenuBar(NULL);
+ menuBar_ = new QMenuBar(NULL);
#else
- menuBar_ = menuBar();
+ menuBar_ = menuBar();
#endif
- QApplication::setQuitOnLastWindowClosed(false);
+ QApplication::setQuitOnLastWindowClosed(false);
- swiftMenu_ = new QMenu(tr("&Swift"), this);
+ swiftMenu_ = new QMenu(tr("&Swift"), this);
#ifdef SWIFTEN_PLATFORM_MACOSX
- generalMenu_ = new QMenu(tr("&General"), this);
+ generalMenu_ = new QMenu(tr("&General"), this);
#else
- generalMenu_ = swiftMenu_;
+ generalMenu_ = swiftMenu_;
#endif
#ifdef SWIFTEN_PLATFORM_MACOSX
- QAction* aboutAction = new QAction(QString("&About %1").arg("Swift"), this);
+ QAction* aboutAction = new QAction(QString("&About %1").arg("Swift"), this);
#else
- QAction* aboutAction = new QAction(QString(tr("&About %1")).arg("Swift"), this);
+ QAction* aboutAction = new QAction(QString(tr("&About %1")).arg("Swift"), this);
#endif
- connect(aboutAction, SIGNAL(triggered()), SLOT(handleAbout()));
- swiftMenu_->addAction(aboutAction);
+ connect(aboutAction, SIGNAL(triggered()), SLOT(handleAbout()));
+ swiftMenu_->addAction(aboutAction);
- xmlConsoleAction_ = new QAction(tr("&Show Debug Console"), this);
- connect(xmlConsoleAction_, SIGNAL(triggered()), SLOT(handleShowXMLConsole()));
- generalMenu_->addAction(xmlConsoleAction_);
+ xmlConsoleAction_ = new QAction(tr("&Show Debug Console"), this);
+ connect(xmlConsoleAction_, SIGNAL(triggered()), SLOT(handleShowXMLConsole()));
+ generalMenu_->addAction(xmlConsoleAction_);
#ifdef SWIFT_EXPERIMENTAL_FT
- fileTransferOverviewAction_ = new QAction(tr("Show &File Transfer Overview"), this);
- connect(fileTransferOverviewAction_, SIGNAL(triggered()), SLOT(handleShowFileTransferOverview()));
- generalMenu_->addAction(fileTransferOverviewAction_);
+ fileTransferOverviewAction_ = new QAction(tr("Show &File Transfer Overview"), this);
+ connect(fileTransferOverviewAction_, SIGNAL(triggered()), SLOT(handleShowFileTransferOverview()));
+ generalMenu_->addAction(fileTransferOverviewAction_);
#endif
- highlightEditorAction_ = new QAction(tr("&Edit Highlight Rules"), this);
- connect(highlightEditorAction_, SIGNAL(triggered()), SLOT(handleShowHighlightEditor()));
- generalMenu_->addAction(highlightEditorAction_);
+ highlightEditorAction_ = new QAction(tr("&Edit Highlight Rules"), this);
+ connect(highlightEditorAction_, SIGNAL(triggered()), SLOT(handleShowHighlightEditor()));
+ generalMenu_->addAction(highlightEditorAction_);
- toggleSoundsAction_ = new QAction(tr("&Play Sounds"), this);
- toggleSoundsAction_->setCheckable(true);
- toggleSoundsAction_->setChecked(settings_->getSetting(SettingConstants::PLAY_SOUNDS));
- connect(toggleSoundsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleSounds(bool)));
- generalMenu_->addAction(toggleSoundsAction_);
+ toggleSoundsAction_ = new QAction(tr("&Play Sounds"), this);
+ toggleSoundsAction_->setCheckable(true);
+ toggleSoundsAction_->setChecked(settings_->getSetting(SettingConstants::PLAY_SOUNDS));
+ connect(toggleSoundsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleSounds(bool)));
+ generalMenu_->addAction(toggleSoundsAction_);
- toggleNotificationsAction_ = new QAction(tr("Display Pop-up &Notifications"), this);
- toggleNotificationsAction_->setCheckable(true);
- toggleNotificationsAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
- connect(toggleNotificationsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleNotifications(bool)));
+ toggleNotificationsAction_ = new QAction(tr("Display Pop-up &Notifications"), this);
+ toggleNotificationsAction_->setCheckable(true);
+ toggleNotificationsAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
+ connect(toggleNotificationsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleNotifications(bool)));
#ifndef SWIFTEN_PLATFORM_MACOSX
- swiftMenu_->addSeparator();
+ swiftMenu_->addSeparator();
#endif
#ifdef SWIFTEN_PLATFORM_MACOSX
- QAction* quitAction = new QAction("&Quit", this);
+ QAction* quitAction = new QAction("&Quit", this);
#else
- QAction* quitAction = new QAction(tr("&Quit"), this);
+ QAction* quitAction = new QAction(tr("&Quit"), this);
#endif
- connect(quitAction, SIGNAL(triggered()), SLOT(handleQuit()));
- swiftMenu_->addAction(quitAction);
+ connect(quitAction, SIGNAL(triggered()), SLOT(handleQuit()));
+ swiftMenu_->addAction(quitAction);
- setInitialMenus();
- settings_->onSettingChanged.connect(boost::bind(&QtLoginWindow::handleSettingChanged, this, _1));
+ setInitialMenus();
+ settings_->onSettingChanged.connect(boost::bind(&QtLoginWindow::handleSettingChanged, this, _1));
- bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);
- remember_->setEnabled(!eagle);
- loginAutomatically_->setEnabled(!eagle);
- xmlConsoleAction_->setEnabled(!eagle);
- if (eagle) {
- remember_->setChecked(false);
- loginAutomatically_->setChecked(false);
- }
+ bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);
+ remember_->setEnabled(!eagle);
+ loginAutomatically_->setEnabled(!eagle);
+ xmlConsoleAction_->setEnabled(!eagle);
+ if (eagle) {
+ remember_->setChecked(false);
+ loginAutomatically_->setChecked(false);
+ }
#ifdef SWIFTEN_PLATFORM_MACOSX
- // Temporary workaround for case 501. Could be that this code is still
- // needed when Qt provides a proper fix
- qApp->installEventFilter(this);
+ // Temporary workaround for case 501. Could be that this code is still
+ // needed when Qt provides a proper fix
+ qApp->installEventFilter(this);
#endif
- this->show();
+ this->show();
}
void QtLoginWindow::setShowNotificationToggle(bool toggle) {
- if (toggle) {
- QList< QAction* > generalMenuActions = generalMenu_->actions();
- generalMenu_->insertAction(generalMenuActions.at(generalMenuActions.count()-2), toggleNotificationsAction_);
- }
- else {
- generalMenu_->removeAction(toggleNotificationsAction_);
- }
+ if (toggle) {
+ QList< QAction* > generalMenuActions = generalMenu_->actions();
+ generalMenu_->insertAction(generalMenuActions.at(generalMenuActions.count()-2), toggleNotificationsAction_);
+ }
+ else {
+ generalMenu_->removeAction(toggleNotificationsAction_);
+ }
}
bool QtLoginWindow::eventFilter(QObject *obj, QEvent *event) {
- if (obj == username_->view() && event->type() == QEvent::KeyPress) {
- QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
- if (keyEvent->key() == Qt::Key_Delete || keyEvent->key() == Qt::Key_Backspace) {
- QString jid(username_->view()->currentIndex().data().toString());
- int result = QMessageBox::question(this, tr("Remove profile"), tr("Remove the profile '%1'?").arg(jid), QMessageBox::Yes | QMessageBox::No);
- if (result == QMessageBox::Yes) {
- onPurgeSavedLoginRequest(Q2PSTRING(jid));
- }
- return true;
- }
- }
+ if (obj == username_->view() && event->type() == QEvent::KeyPress) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
+ if (keyEvent->key() == Qt::Key_Delete || keyEvent->key() == Qt::Key_Backspace) {
+ QString jid(username_->view()->currentIndex().data().toString());
+ int result = QMessageBox::question(this, tr("Remove profile"), tr("Remove the profile '%1'?").arg(jid), QMessageBox::Yes | QMessageBox::No);
+ if (result == QMessageBox::Yes) {
+ onPurgeSavedLoginRequest(Q2PSTRING(jid));
+ }
+ return true;
+ }
+ }
#ifdef SWIFTEN_PLATFORM_MACOSX
- // Dock clicked
- // Temporary workaround for case 501. Could be that this code is still
- // needed when Qt provides a proper fix
- if (obj == qApp && event->type() == QEvent::ApplicationActivate && !isVisible()) {
- bringToFront();
- }
+ // Dock clicked
+ // Temporary workaround for case 501. Could be that this code is still
+ // needed when Qt provides a proper fix
+ if (obj == qApp && event->type() == QEvent::ApplicationActivate && !isVisible()) {
+ bringToFront();
+ }
#endif
- return QObject::eventFilter(obj, event);
+ return QObject::eventFilter(obj, event);
}
void QtLoginWindow::handleSettingChanged(const std::string& settingPath) {
- if (settingPath == SettingConstants::PLAY_SOUNDS.getKey()) {
- toggleSoundsAction_->setChecked(settings_->getSetting(SettingConstants::PLAY_SOUNDS));
- }
- if (settingPath == SettingConstants::SHOW_NOTIFICATIONS.getKey()) {
- toggleNotificationsAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
- }
+ if (settingPath == SettingConstants::PLAY_SOUNDS.getKey()) {
+ toggleSoundsAction_->setChecked(settings_->getSetting(SettingConstants::PLAY_SOUNDS));
+ }
+ if (settingPath == SettingConstants::SHOW_NOTIFICATIONS.getKey()) {
+ toggleNotificationsAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS));
+ }
}
void QtLoginWindow::selectUser(const std::string& username) {
- for (int i = 0; i < usernames_.count(); i++) {
- if (P2QSTRING(username) == usernames_[i]) {
- username_->setCurrentIndex(i);
- password_->setFocus();
- break;
- }
- }
+ for (int i = 0; i < usernames_.count(); i++) {
+ if (P2QSTRING(username) == usernames_[i]) {
+ username_->setCurrentIndex(i);
+ password_->setFocus();
+ break;
+ }
+ }
}
void QtLoginWindow::removeAvailableAccount(const std::string& jid) {
- QString username = P2QSTRING(jid);
- int index = -1;
- for (int i = 0; i < usernames_.count(); i++) {
- if (username == usernames_[i]) {
- index = i;
- }
- }
- if (index >= 0) {
- usernames_.removeAt(index);
- passwords_.removeAt(index);
- certificateFiles_.removeAt(index);
- username_->removeItem(index);
- }
+ QString username = P2QSTRING(jid);
+ int index = -1;
+ for (int i = 0; i < usernames_.count(); i++) {
+ if (username == usernames_[i]) {
+ index = i;
+ }
+ }
+ if (index >= 0) {
+ usernames_.removeAt(index);
+ passwords_.removeAt(index);
+ certificateFiles_.removeAt(index);
+ username_->removeItem(index);
+ }
}
void QtLoginWindow::addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate, const ClientOptions& options) {
- QString username = P2QSTRING(defaultJID);
- int index = -1;
- for (int i = 0; i < usernames_.count(); i++) {
- if (username == usernames_[i]) {
- index = i;
- }
- }
- if (index == -1) {
- usernames_.append(username);
- passwords_.append(P2QSTRING(defaultPassword));
- certificateFiles_.append(P2QSTRING(defaultCertificate));
- options_.push_back(options);
- username_->addItem(username);
- } else {
- usernames_[index] = username;
- passwords_[index] = P2QSTRING(defaultPassword);
- certificateFiles_[index] = P2QSTRING(defaultCertificate);
- options_[index] = options;
- }
+ QString username = P2QSTRING(defaultJID);
+ int index = -1;
+ for (int i = 0; i < usernames_.count(); i++) {
+ if (username == usernames_[i]) {
+ index = i;
+ }
+ }
+ if (index == -1) {
+ usernames_.append(username);
+ passwords_.append(P2QSTRING(defaultPassword));
+ certificateFiles_.append(P2QSTRING(defaultCertificate));
+ options_.push_back(options);
+ username_->addItem(username);
+ } else {
+ usernames_[index] = username;
+ passwords_[index] = P2QSTRING(defaultPassword);
+ certificateFiles_[index] = P2QSTRING(defaultCertificate);
+ options_[index] = options;
+ }
}
void QtLoginWindow::handleUsernameTextChanged() {
- QString username = username_->currentText();
- for (int i = 0; i < usernames_.count(); i++) {
- if (username_->currentText() == usernames_[i]) {
- certificateFile_ = certificateFiles_[i];
- password_->setText(passwords_[i]);
- remember_->setChecked(password_->text() != "");
- currentOptions_ = options_[i];
- }
- }
- certificateButton_->setChecked(!certificateFile_.isEmpty());
+ QString username = username_->currentText();
+ for (int i = 0; i < usernames_.count(); i++) {
+ if (username_->currentText() == usernames_[i]) {
+ certificateFile_ = certificateFiles_[i];
+ password_->setText(passwords_[i]);
+ remember_->setChecked(password_->text() != "");
+ currentOptions_ = options_[i];
+ }
+ }
+ certificateButton_->setChecked(!certificateFile_.isEmpty());
}
void QtLoginWindow::loggedOut() {
- stack_->removeWidget(stack_->currentWidget());
- stack_->addWidget(loginWidgetWrapper_);
- stack_->setCurrentWidget(loginWidgetWrapper_);
- setInitialMenus();
- setIsLoggingIn(false);
+ stack_->removeWidget(stack_->currentWidget());
+ stack_->addWidget(loginWidgetWrapper_);
+ stack_->setCurrentWidget(loginWidgetWrapper_);
+ setInitialMenus();
+ setIsLoggingIn(false);
}
void QtLoginWindow::setIsLoggingIn(bool loggingIn) {
- /* Change the for loop as well if you add to this.*/
- QWidget* widgets[5] = {username_, password_, remember_, loginAutomatically_, certificateButton_};
- loginButton_->setText(loggingIn ? tr("Cancel") : tr("Connect"));
- for (int i = 0; i < 5; i++) {
- widgets[i]->setEnabled(!loggingIn);
- }
- bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);
- remember_->setEnabled(!eagle);
- loginAutomatically_->setEnabled(!eagle);
+ /* Change the for loop as well if you add to this.*/
+ QWidget* widgets[5] = {username_, password_, remember_, loginAutomatically_, certificateButton_};
+ loginButton_->setText(loggingIn ? tr("Cancel") : tr("Connect"));
+ for (int i = 0; i < 5; i++) {
+ widgets[i]->setEnabled(!loggingIn);
+ }
+ bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);
+ remember_->setEnabled(!eagle);
+ loginAutomatically_->setEnabled(!eagle);
}
void QtLoginWindow::loginClicked() {
- if (username_->isEnabled()) {
- std::string banner = settings_->getSetting(QtUISettingConstants::CLICKTHROUGH_BANNER);
- if (!banner.empty()) {
- QMessageBox msgBox;
- msgBox.setWindowTitle(tr("Confirm terms of use"));
- msgBox.setText("");
- msgBox.setInformativeText(P2QSTRING(banner));
- msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- msgBox.setDefaultButton(QMessageBox::No);
- if (msgBox.exec() != QMessageBox::Yes) {
- return;
- }
- }
- CertificateWithKey::ref certificate;
- std::string certificateString = Q2PSTRING(certificateFile_);
- if (!certificateString.empty()) {
+ if (username_->isEnabled()) {
+ std::string banner = settings_->getSetting(QtUISettingConstants::CLICKTHROUGH_BANNER);
+ if (!banner.empty()) {
+ QMessageBox msgBox;
+ msgBox.setWindowTitle(tr("Confirm terms of use"));
+ msgBox.setText("");
+ msgBox.setInformativeText(P2QSTRING(banner));
+ msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ msgBox.setDefaultButton(QMessageBox::No);
+ if (msgBox.exec() != QMessageBox::Yes) {
+ return;
+ }
+ }
+ CertificateWithKey::ref certificate;
+ std::string certificateString = Q2PSTRING(certificateFile_);
+ if (!certificateString.empty()) {
#if defined(HAVE_SCHANNEL)
- if (isCAPIURI(certificateString)) {
- certificate = boost::make_shared<CAPICertificate>(certificateString, timerFactory_);
- } else {
- certificate = boost::make_shared<PKCS12Certificate>(certificateString, createSafeByteArray(Q2PSTRING(password_->text())));
- }
+ if (isCAPIURI(certificateString)) {
+ certificate = boost::make_shared<CAPICertificate>(certificateString, timerFactory_);
+ } else {
+ certificate = boost::make_shared<PKCS12Certificate>(certificateString, createSafeByteArray(Q2PSTRING(password_->text())));
+ }
#else
- certificate = boost::make_shared<PKCS12Certificate>(certificateString, createSafeByteArray(Q2PSTRING(password_->text())));
+ certificate = boost::make_shared<PKCS12Certificate>(certificateString, createSafeByteArray(Q2PSTRING(password_->text())));
#endif
- }
+ }
- onLoginRequest(Q2PSTRING(username_->currentText()), Q2PSTRING(password_->text()), certificateString, certificate, currentOptions_, remember_->isChecked(), loginAutomatically_->isChecked());
- if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { /* Mustn't remember logins */
- username_->clearEditText();
- password_->setText("");
- }
- } else {
- onCancelLoginRequest();
- }
+ onLoginRequest(Q2PSTRING(username_->currentText()), Q2PSTRING(password_->text()), certificateString, certificate, currentOptions_, remember_->isChecked(), loginAutomatically_->isChecked());
+ if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { /* Mustn't remember logins */
+ username_->clearEditText();
+ password_->setText("");
+ }
+ } else {
+ onCancelLoginRequest();
+ }
}
void QtLoginWindow::setLoginAutomatically(bool loginAutomatically) {
- loginAutomatically_->setChecked(loginAutomatically);
+ loginAutomatically_->setChecked(loginAutomatically);
}
void QtLoginWindow::handleCertficateChecked(bool checked) {
- if (checked) {
+ if (checked) {
#ifdef HAVE_SCHANNEL
- certificateFile_ = P2QSTRING(selectCAPICertificate());
- if (certificateFile_.isEmpty()) {
- certificateButton_->setChecked(false);
- }
+ certificateFile_ = P2QSTRING(selectCAPICertificate());
+ if (certificateFile_.isEmpty()) {
+ certificateButton_->setChecked(false);
+ }
#else
- certificateFile_ = QFileDialog::getOpenFileName(this, tr("Select an authentication certificate"), QString(), tr("P12 files (*.cert *.p12 *.pfx);;All files (*.*)"));
- if (certificateFile_.isEmpty()) {
- certificateButton_->setChecked(false);
- }
+ certificateFile_ = QFileDialog::getOpenFileName(this, tr("Select an authentication certificate"), QString(), tr("P12 files (*.cert *.p12 *.pfx);;All files (*.*)"));
+ if (certificateFile_.isEmpty()) {
+ certificateButton_->setChecked(false);
+ }
#endif
- }
- else {
- certificateFile_ = "";
- }
+ }
+ else {
+ certificateFile_ = "";
+ }
}
void QtLoginWindow::handleAbout() {
- if (!aboutDialog_) {
- aboutDialog_ = new QtAboutWidget();
- aboutDialog_->show();
- }
- else {
- aboutDialog_->show();
- aboutDialog_->raise();
- aboutDialog_->activateWindow();
- }
+ if (!aboutDialog_) {
+ aboutDialog_ = new QtAboutWidget();
+ aboutDialog_->show();
+ }
+ else {
+ aboutDialog_->show();
+ aboutDialog_->raise();
+ aboutDialog_->activateWindow();
+ }
}
void QtLoginWindow::handleShowXMLConsole() {
- uiEventStream_->send(boost::make_shared<RequestXMLConsoleUIEvent>());
+ uiEventStream_->send(boost::make_shared<RequestXMLConsoleUIEvent>());
}
void QtLoginWindow::handleShowFileTransferOverview() {
- uiEventStream_->send(boost::make_shared<RequestFileTransferListUIEvent>());
+ uiEventStream_->send(boost::make_shared<RequestFileTransferListUIEvent>());
}
void QtLoginWindow::handleShowHighlightEditor() {
- uiEventStream_->send(boost::make_shared<RequestHighlightEditorUIEvent>());
+ uiEventStream_->send(boost::make_shared<RequestHighlightEditorUIEvent>());
}
void QtLoginWindow::handleToggleSounds(bool enabled) {
- settings_->storeSetting(SettingConstants::PLAY_SOUNDS, enabled);
+ settings_->storeSetting(SettingConstants::PLAY_SOUNDS, enabled);
}
void QtLoginWindow::handleToggleNotifications(bool enabled) {
- settings_->storeSetting(SettingConstants::SHOW_NOTIFICATIONS, enabled);
+ settings_->storeSetting(SettingConstants::SHOW_NOTIFICATIONS, enabled);
}
void QtLoginWindow::handleQuit() {
- onQuitRequest();
+ onQuitRequest();
}
void QtLoginWindow::quit() {
- QApplication::quit();
+ QApplication::quit();
}
void QtLoginWindow::setInitialMenus() {
- menuBar_->clear();
- menuBar_->addMenu(swiftMenu_);
+ menuBar_->clear();
+ menuBar_->addMenu(swiftMenu_);
#ifdef SWIFTEN_PLATFORM_MACOSX
- menuBar_->addMenu(generalMenu_);
+ menuBar_->addMenu(generalMenu_);
#endif
}
void QtLoginWindow::morphInto(MainWindow *mainWindow) {
- setEnabled(false);
- QtMainWindow *qtMainWindow = dynamic_cast<QtMainWindow*>(mainWindow);
- assert(qtMainWindow);
- stack_->removeWidget(loginWidgetWrapper_);
- stack_->addWidget(qtMainWindow);
- stack_->setCurrentWidget(qtMainWindow);
- setEnabled(true);
- setInitialMenus();
- std::vector<QMenu*> mainWindowMenus = qtMainWindow->getMenus();
- viewMenu_ = mainWindowMenus[0];
- foreach (QMenu* menu, mainWindowMenus) {
- menuBar_->addMenu(menu);
- }
- setFocus();
+ setEnabled(false);
+ QtMainWindow *qtMainWindow = dynamic_cast<QtMainWindow*>(mainWindow);
+ assert(qtMainWindow);
+ stack_->removeWidget(loginWidgetWrapper_);
+ stack_->addWidget(qtMainWindow);
+ stack_->setCurrentWidget(qtMainWindow);
+ setEnabled(true);
+ setInitialMenus();
+ std::vector<QMenu*> mainWindowMenus = qtMainWindow->getMenus();
+ viewMenu_ = mainWindowMenus[0];
+ foreach (QMenu* menu, mainWindowMenus) {
+ menuBar_->addMenu(menu);
+ }
+ setFocus();
}
void QtLoginWindow::setMessage(const std::string& message) {
- if (!message.empty()) {
- message_->setText("<center><font color=\"red\">" + P2QSTRING(message) + "</font></center>");
- }
- else {
- message_->setText("");
- }
+ if (!message.empty()) {
+ message_->setText("<center><font color=\"red\">" + P2QSTRING(message) + "</font></center>");
+ }
+ else {
+ message_->setText("");
+ }
}
void QtLoginWindow::toggleBringToFront() {
- if (!isVisible()) {
- bringToFront();
- }
- else {
- window()->hide();
- }
+ if (!isVisible()) {
+ bringToFront();
+ }
+ else {
+ window()->hide();
+ }
}
void QtLoginWindow::bringToFront() {
- window()->showNormal();
- window()->raise();
- window()->activateWindow();
+ window()->showNormal();
+ window()->raise();
+ window()->activateWindow();
}
void QtLoginWindow::hide() {
- window()->hide();
+ window()->hide();
}
QtLoginWindow::QtMenus QtLoginWindow::getMenus() const {
- return QtMenus(swiftMenu_, generalMenu_);
+ return QtMenus(swiftMenu_, generalMenu_);
}
void QtLoginWindow::resizeEvent(QResizeEvent*) {
- emit geometryChanged();
+ emit geometryChanged();
}
void QtLoginWindow::moveEvent(QMoveEvent*) {
- emit geometryChanged();
+ emit geometryChanged();
}
bool QtLoginWindow::askUserToTrustCertificatePermanently(const std::string& message, const std::vector<Certificate::ref>& certificates) {
- QMessageBox dialog(this);
-
- dialog.setText(tr("The certificate presented by the server is not valid."));
- dialog.setInformativeText(P2QSTRING(message) + "\n\n" + tr("Would you like to permanently trust this certificate? This must only be done if you know it is correct."));
-
- dialog.addButton(tr("Show Certificate"), QMessageBox::HelpRole);
- dialog.addButton(QMessageBox::Yes);
- dialog.addButton(QMessageBox::No);
- dialog.setDefaultButton(QMessageBox::No);
- while (true) {
- int result = dialog.exec();
- if (result == QMessageBox::Yes || result == QMessageBox::No) {
- return result == QMessageBox::Yes;
- }
- // FIXME: This isn't very nice, because the dialog disappears every time. We actually need a real
- // dialog with a custom button.
- QtMainWindow::openCertificateDialog(certificates, &dialog);
- }
+ QMessageBox dialog(this);
+
+ dialog.setText(tr("The certificate presented by the server is not valid."));
+ dialog.setInformativeText(P2QSTRING(message) + "\n\n" + tr("Would you like to permanently trust this certificate? This must only be done if you know it is correct."));
+
+ dialog.addButton(tr("Show Certificate"), QMessageBox::HelpRole);
+ dialog.addButton(QMessageBox::Yes);
+ dialog.addButton(QMessageBox::No);
+ dialog.setDefaultButton(QMessageBox::No);
+ while (true) {
+ int result = dialog.exec();
+ if (result == QMessageBox::Yes || result == QMessageBox::No) {
+ return result == QMessageBox::Yes;
+ }
+ // FIXME: This isn't very nice, because the dialog disappears every time. We actually need a real
+ // dialog with a custom button.
+ QtMainWindow::openCertificateDialog(certificates, &dialog);
+ }
}
void QtLoginWindow::handleOpenConnectionOptions() {
- QtConnectionSettingsWindow connectionSettings(currentOptions_);
- if (connectionSettings.exec() == QDialog::Accepted) {
- currentOptions_ = connectionSettings.getOptions();
- }
+ QtConnectionSettingsWindow connectionSettings(currentOptions_);
+ if (connectionSettings.exec() == QDialog::Accepted) {
+ currentOptions_ = connectionSettings.getOptions();
+ }
}
}
diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h
index e8e2e20..91b21f6 100644
--- a/Swift/QtUI/QtLoginWindow.h
+++ b/Swift/QtUI/QtLoginWindow.h
@@ -25,89 +25,89 @@ class QToolButton;
class QComboBox;
namespace Swift {
- class SettingsProvider;
- class TimerFactory;
+ class SettingsProvider;
+ class TimerFactory;
- class QtLoginWindow : public QMainWindow, public LoginWindow {
- Q_OBJECT
- public:
- struct QtMenus {
- QtMenus(QMenu* swiftMenu, QMenu* generalMenu) : swiftMenu(swiftMenu), generalMenu(generalMenu) {}
- QMenu* swiftMenu;
- QMenu* generalMenu;
- };
+ class QtLoginWindow : public QMainWindow, public LoginWindow {
+ Q_OBJECT
+ public:
+ struct QtMenus {
+ QtMenus(QMenu* swiftMenu, QMenu* generalMenu) : swiftMenu(swiftMenu), generalMenu(generalMenu) {}
+ QMenu* swiftMenu;
+ QMenu* generalMenu;
+ };
- public:
- QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* settings, TimerFactory* timerFactory);
+ public:
+ QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* settings, TimerFactory* timerFactory);
- void morphInto(MainWindow *mainWindow);
- virtual void loggedOut();
- virtual void setShowNotificationToggle(bool);
- virtual void setMessage(const std::string& message);
- virtual void addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate, const ClientOptions& options);
- virtual void removeAvailableAccount(const std::string& jid);
- virtual void setLoginAutomatically(bool loginAutomatically);
- virtual void setIsLoggingIn(bool loggingIn);
- void selectUser(const std::string& user);
- bool askUserToTrustCertificatePermanently(const std::string& message, const std::vector<Certificate::ref>& certificate);
- void hide();
- QtMenus getMenus() const;
- virtual void quit();
+ void morphInto(MainWindow *mainWindow);
+ virtual void loggedOut();
+ virtual void setShowNotificationToggle(bool);
+ virtual void setMessage(const std::string& message);
+ virtual void addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate, const ClientOptions& options);
+ virtual void removeAvailableAccount(const std::string& jid);
+ virtual void setLoginAutomatically(bool loginAutomatically);
+ virtual void setIsLoggingIn(bool loggingIn);
+ void selectUser(const std::string& user);
+ bool askUserToTrustCertificatePermanently(const std::string& message, const std::vector<Certificate::ref>& certificate);
+ void hide();
+ QtMenus getMenus() const;
+ virtual void quit();
- signals:
- void geometryChanged();
+ signals:
+ void geometryChanged();
- private slots:
- void loginClicked();
- void handleCertficateChecked(bool);
- void handleQuit();
- void handleShowXMLConsole();
- void handleShowFileTransferOverview();
- void handleShowHighlightEditor();
- void handleToggleSounds(bool enabled);
- void handleToggleNotifications(bool enabled);
- void handleAbout();
- void bringToFront();
- void toggleBringToFront();
- void handleUsernameTextChanged();
- void resizeEvent(QResizeEvent* event);
- void moveEvent(QMoveEvent* event);
- void handleSettingChanged(const std::string& settingPath);
- void handleOpenConnectionOptions();
+ private slots:
+ void loginClicked();
+ void handleCertficateChecked(bool);
+ void handleQuit();
+ void handleShowXMLConsole();
+ void handleShowFileTransferOverview();
+ void handleShowHighlightEditor();
+ void handleToggleSounds(bool enabled);
+ void handleToggleNotifications(bool enabled);
+ void handleAbout();
+ void bringToFront();
+ void toggleBringToFront();
+ void handleUsernameTextChanged();
+ void resizeEvent(QResizeEvent* event);
+ void moveEvent(QMoveEvent* event);
+ void handleSettingChanged(const std::string& settingPath);
+ void handleOpenConnectionOptions();
- protected:
- bool eventFilter(QObject *obj, QEvent *event);
+ protected:
+ bool eventFilter(QObject *obj, QEvent *event);
- private:
- void setInitialMenus();
- QWidget* loginWidgetWrapper_;
- QStringList usernames_;
- QStringList passwords_;
- QStringList certificateFiles_;
- std::vector<ClientOptions> options_;
- QComboBox* username_;
- QLineEdit* password_;
- QPushButton* loginButton_;
- /* If you add a widget here, change setLoggingIn as well.*/
- QCheckBox* remember_;
- QCheckBox* loginAutomatically_;
- QStackedWidget* stack_;
- QLabel* message_;
- QString certificateFile_;
- QToolButton* certificateButton_;
- QMenuBar* menuBar_;
- QMenu* swiftMenu_;
- QMenu* generalMenu_;
- QMenu* viewMenu_;
- QAction* toggleSoundsAction_;
- QAction* toggleNotificationsAction_;
- UIEventStream* uiEventStream_;
- QPointer<QtAboutWidget> aboutDialog_;
- SettingsProvider* settings_;
- QAction* xmlConsoleAction_;
- QAction* fileTransferOverviewAction_;
- QAction* highlightEditorAction_;
- TimerFactory* timerFactory_;
- ClientOptions currentOptions_;
- };
+ private:
+ void setInitialMenus();
+ QWidget* loginWidgetWrapper_;
+ QStringList usernames_;
+ QStringList passwords_;
+ QStringList certificateFiles_;
+ std::vector<ClientOptions> options_;
+ QComboBox* username_;
+ QLineEdit* password_;
+ QPushButton* loginButton_;
+ /* If you add a widget here, change setLoggingIn as well.*/
+ QCheckBox* remember_;
+ QCheckBox* loginAutomatically_;
+ QStackedWidget* stack_;
+ QLabel* message_;
+ QString certificateFile_;
+ QToolButton* certificateButton_;
+ QMenuBar* menuBar_;
+ QMenu* swiftMenu_;
+ QMenu* generalMenu_;
+ QMenu* viewMenu_;
+ QAction* toggleSoundsAction_;
+ QAction* toggleNotificationsAction_;
+ UIEventStream* uiEventStream_;
+ QPointer<QtAboutWidget> aboutDialog_;
+ SettingsProvider* settings_;
+ QAction* xmlConsoleAction_;
+ QAction* fileTransferOverviewAction_;
+ QAction* highlightEditorAction_;
+ TimerFactory* timerFactory_;
+ ClientOptions currentOptions_;
+ };
}
diff --git a/Swift/QtUI/QtMUCConfigurationWindow.cpp b/Swift/QtUI/QtMUCConfigurationWindow.cpp
index a4ef9e3..629e94f 100644
--- a/Swift/QtUI/QtMUCConfigurationWindow.cpp
+++ b/Swift/QtUI/QtMUCConfigurationWindow.cpp
@@ -16,30 +16,30 @@
namespace Swift {
QtMUCConfigurationWindow::QtMUCConfigurationWindow(Form::ref form) : closed_(false) {
- setAttribute(Qt::WA_DeleteOnClose);
-
- QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
- layout->setContentsMargins(0,0,0,0);
- layout->setSpacing(2);
- //QLabel* label = new QLabel(this);
- //label->setText(tr("Room configuration"));
- //layout->addWidget(label);
-
- formWidget_ = NULL;
- formWidget_ = new QtFormWidget(form, this);
- layout->addWidget(formWidget_);
-
- QWidget* buttonsWidget = new QWidget(this);
- layout->addWidget(buttonsWidget);
-
- QBoxLayout* buttonsLayout = new QBoxLayout(QBoxLayout::LeftToRight, buttonsWidget);
- cancelButton_ = new QPushButton(tr("Cancel"), buttonsWidget);
- buttonsLayout->addWidget(cancelButton_);
- connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked()));
- okButton_ = new QPushButton(tr("OK"), buttonsWidget);
- buttonsLayout->addWidget(okButton_);
- connect(okButton_, SIGNAL(clicked()), this, SLOT(handleOKClicked()));
- show();
+ setAttribute(Qt::WA_DeleteOnClose);
+
+ QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+ layout->setContentsMargins(0,0,0,0);
+ layout->setSpacing(2);
+ //QLabel* label = new QLabel(this);
+ //label->setText(tr("Room configuration"));
+ //layout->addWidget(label);
+
+ formWidget_ = NULL;
+ formWidget_ = new QtFormWidget(form, this);
+ layout->addWidget(formWidget_);
+
+ QWidget* buttonsWidget = new QWidget(this);
+ layout->addWidget(buttonsWidget);
+
+ QBoxLayout* buttonsLayout = new QBoxLayout(QBoxLayout::LeftToRight, buttonsWidget);
+ cancelButton_ = new QPushButton(tr("Cancel"), buttonsWidget);
+ buttonsLayout->addWidget(cancelButton_);
+ connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked()));
+ okButton_ = new QPushButton(tr("OK"), buttonsWidget);
+ buttonsLayout->addWidget(okButton_);
+ connect(okButton_, SIGNAL(clicked()), this, SLOT(handleOKClicked()));
+ show();
}
QtMUCConfigurationWindow::~QtMUCConfigurationWindow() {
@@ -47,19 +47,19 @@ QtMUCConfigurationWindow::~QtMUCConfigurationWindow() {
}
void QtMUCConfigurationWindow::closeEvent(QCloseEvent* /*event*/) {
- if (!closed_) {
- onFormCancelled();
- }
+ if (!closed_) {
+ onFormCancelled();
+ }
}
void QtMUCConfigurationWindow::handleCancelClicked() {
- close();
+ close();
}
void QtMUCConfigurationWindow::handleOKClicked() {
- onFormComplete(formWidget_->getCompletedForm());
- closed_ = true;
- close();
+ onFormComplete(formWidget_->getCompletedForm());
+ closed_ = true;
+ close();
}
diff --git a/Swift/QtUI/QtMUCConfigurationWindow.h b/Swift/QtUI/QtMUCConfigurationWindow.h
index bae7556..c8835e4 100644
--- a/Swift/QtUI/QtMUCConfigurationWindow.h
+++ b/Swift/QtUI/QtMUCConfigurationWindow.h
@@ -17,23 +17,23 @@ class QBoxLayout;
class QCloseEvent;
namespace Swift {
- class QtFormWidget;
- class QtMUCConfigurationWindow : public QWidget {
- Q_OBJECT
- public:
- QtMUCConfigurationWindow(Form::ref form);
- virtual ~QtMUCConfigurationWindow();
- boost::signal<void (Form::ref)> onFormComplete;
- boost::signal<void ()> onFormCancelled;
- private slots:
- void handleCancelClicked();
- void handleOKClicked();
- protected:
- virtual void closeEvent(QCloseEvent* event);
- private:
- QtFormWidget* formWidget_;
- QPushButton* okButton_;
- QPushButton* cancelButton_;
- bool closed_;
- };
+ class QtFormWidget;
+ class QtMUCConfigurationWindow : public QWidget {
+ Q_OBJECT
+ public:
+ QtMUCConfigurationWindow(Form::ref form);
+ virtual ~QtMUCConfigurationWindow();
+ boost::signal<void (Form::ref)> onFormComplete;
+ boost::signal<void ()> onFormCancelled;
+ private slots:
+ void handleCancelClicked();
+ void handleOKClicked();
+ protected:
+ virtual void closeEvent(QCloseEvent* event);
+ private:
+ QtFormWidget* formWidget_;
+ QPushButton* okButton_;
+ QPushButton* cancelButton_;
+ bool closed_;
+ };
}
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index e2092f6..d61026a 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -52,373 +52,373 @@
namespace Swift {
QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStream, QtLoginWindow::QtMenus loginMenus, StatusCache* statusCache, bool emoticonsExist, bool enableAdHocCommandOnJID) : QWidget(), MainWindow(false), loginMenus_(loginMenus) {
- uiEventStream_ = uiEventStream;
- settings_ = settings;
- setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
- QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
- mainLayout->setContentsMargins(0,0,0,0);
- mainLayout->setSpacing(0);
- meView_ = new QtRosterHeader(settings, statusCache, this);
- mainLayout->addWidget(meView_);
- connect(meView_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleStatusChanged(StatusShow::Type, const QString&)));
- connect(meView_, SIGNAL(onEditProfileRequest()), this, SLOT(handleEditProfileRequest()));
- connect(meView_, SIGNAL(onShowCertificateInfo()), this, SLOT(handleShowCertificateInfo()));
-
- tabs_ = new QtTabWidget(this);
+ uiEventStream_ = uiEventStream;
+ settings_ = settings;
+ setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
+ QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+ mainLayout->setContentsMargins(0,0,0,0);
+ mainLayout->setSpacing(0);
+ meView_ = new QtRosterHeader(settings, statusCache, this);
+ mainLayout->addWidget(meView_);
+ connect(meView_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleStatusChanged(StatusShow::Type, const QString&)));
+ connect(meView_, SIGNAL(onEditProfileRequest()), this, SLOT(handleEditProfileRequest()));
+ connect(meView_, SIGNAL(onShowCertificateInfo()), this, SLOT(handleShowCertificateInfo()));
+
+ tabs_ = new QtTabWidget(this);
#if QT_VERSION >= 0x040500
- tabs_->setDocumentMode(true);
+ tabs_->setDocumentMode(true);
#endif
- tabs_->setTabPosition(QTabWidget::South);
- mainLayout->addWidget(tabs_);
- contactsTabWidget_ = new QWidget(this);
- contactsTabWidget_->setContentsMargins(0, 0, 0, 0);
- QBoxLayout *contactTabLayout = new QBoxLayout(QBoxLayout::TopToBottom, contactsTabWidget_);
- contactsTabWidget_->setLayout(contactTabLayout);
- contactTabLayout->setSpacing(0);
- contactTabLayout->setContentsMargins(0, 0, 0, 0);
-
- treeWidget_ = new QtRosterWidget(uiEventStream_, settings_, this);
-
- contactTabLayout->addWidget(treeWidget_);
- new QtFilterWidget(this, treeWidget_, uiEventStream_, contactTabLayout);
-
- tabs_->addTab(contactsTabWidget_, tr("&Contacts"));
-
- eventWindow_ = new QtEventWindow(uiEventStream_);
- connect(eventWindow_, SIGNAL(onNewEventCountUpdated(int)), this, SLOT(handleEventCountUpdated(int)));
-
- chatListWindow_ = new QtChatListWindow(uiEventStream_, settings_);
- connect(chatListWindow_, SIGNAL(onCountUpdated(int)), this, SLOT(handleChatCountUpdated(int)));
-
- tabs_->addTab(chatListWindow_, tr("C&hats"));
- tabs_->addTab(eventWindow_, tr("&Notices"));
-
- tabs_->setCurrentIndex(settings_->getSetting(QtUISettingConstants::CURRENT_ROSTER_TAB));
-
- connect(tabs_, SIGNAL(currentChanged(int)), this, SLOT(handleTabChanged(int)));
-
- tabBarCombo_ = NULL;
- if (settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)) {
- tabs_->tabBar()->hide();
- tabBarCombo_ = new QComboBox(this);
- tabBarCombo_->setAccessibleName("Current View");
- tabBarCombo_->addItem(tr("Contacts"));
- tabBarCombo_->addItem(tr("Chats"));
- tabBarCombo_->addItem(tr("Notices"));
- tabBarCombo_->setCurrentIndex(tabs_->currentIndex());
- mainLayout->addWidget(tabBarCombo_);
- connect(tabBarCombo_, SIGNAL(currentIndexChanged(int)), tabs_, SLOT(setCurrentIndex(int)));
- }
-
-
- this->setLayout(mainLayout);
-
- QMenu* viewMenu = new QMenu(tr("&View"), this);
- menus_.push_back(viewMenu);
-
- compactRosterAction_ = new QAction(tr("&Compact Roster"), this);
- compactRosterAction_->setCheckable(true);
- compactRosterAction_->setChecked(false);
- connect(compactRosterAction_, SIGNAL(toggled(bool)), SLOT(handleCompactRosterToggled(bool)));
- viewMenu->addAction(compactRosterAction_);
- handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
-
- showOfflineAction_ = new QAction(tr("&Show offline contacts"), this);
- showOfflineAction_->setCheckable(true);
- showOfflineAction_->setChecked(false);
- connect(showOfflineAction_, SIGNAL(toggled(bool)), SLOT(handleShowOfflineToggled(bool)));
- viewMenu->addAction(showOfflineAction_);
- handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
-
- if (emoticonsExist) {
- showEmoticonsAction_ = new QAction(tr("&Show Emoticons"), this);
- showEmoticonsAction_->setCheckable(true);
- showEmoticonsAction_->setChecked(false);
- connect(showEmoticonsAction_, SIGNAL(toggled(bool)), SLOT(handleShowEmoticonsToggled(bool)));
- viewMenu->addAction(showEmoticonsAction_);
- handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
- }
-
- QMenu* actionsMenu = new QMenu(tr("&Actions"), this);
- menus_.push_back(actionsMenu);
- QAction* editProfileAction = new QAction(tr("Edit &Profile…"), this);
- connect(editProfileAction, SIGNAL(triggered()), SLOT(handleEditProfileAction()));
- actionsMenu->addAction(editProfileAction);
- onlineOnlyActions_ << editProfileAction;
- QAction* joinMUCAction = new QAction(tr("Enter &Room…"), this);
- connect(joinMUCAction, SIGNAL(triggered()), SLOT(handleJoinMUCAction()));
- actionsMenu->addAction(joinMUCAction);
- onlineOnlyActions_ << joinMUCAction;
+ tabs_->setTabPosition(QTabWidget::South);
+ mainLayout->addWidget(tabs_);
+ contactsTabWidget_ = new QWidget(this);
+ contactsTabWidget_->setContentsMargins(0, 0, 0, 0);
+ QBoxLayout *contactTabLayout = new QBoxLayout(QBoxLayout::TopToBottom, contactsTabWidget_);
+ contactsTabWidget_->setLayout(contactTabLayout);
+ contactTabLayout->setSpacing(0);
+ contactTabLayout->setContentsMargins(0, 0, 0, 0);
+
+ treeWidget_ = new QtRosterWidget(uiEventStream_, settings_, this);
+
+ contactTabLayout->addWidget(treeWidget_);
+ new QtFilterWidget(this, treeWidget_, uiEventStream_, contactTabLayout);
+
+ tabs_->addTab(contactsTabWidget_, tr("&Contacts"));
+
+ eventWindow_ = new QtEventWindow(uiEventStream_);
+ connect(eventWindow_, SIGNAL(onNewEventCountUpdated(int)), this, SLOT(handleEventCountUpdated(int)));
+
+ chatListWindow_ = new QtChatListWindow(uiEventStream_, settings_);
+ connect(chatListWindow_, SIGNAL(onCountUpdated(int)), this, SLOT(handleChatCountUpdated(int)));
+
+ tabs_->addTab(chatListWindow_, tr("C&hats"));
+ tabs_->addTab(eventWindow_, tr("&Notices"));
+
+ tabs_->setCurrentIndex(settings_->getSetting(QtUISettingConstants::CURRENT_ROSTER_TAB));
+
+ connect(tabs_, SIGNAL(currentChanged(int)), this, SLOT(handleTabChanged(int)));
+
+ tabBarCombo_ = NULL;
+ if (settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)) {
+ tabs_->tabBar()->hide();
+ tabBarCombo_ = new QComboBox(this);
+ tabBarCombo_->setAccessibleName("Current View");
+ tabBarCombo_->addItem(tr("Contacts"));
+ tabBarCombo_->addItem(tr("Chats"));
+ tabBarCombo_->addItem(tr("Notices"));
+ tabBarCombo_->setCurrentIndex(tabs_->currentIndex());
+ mainLayout->addWidget(tabBarCombo_);
+ connect(tabBarCombo_, SIGNAL(currentIndexChanged(int)), tabs_, SLOT(setCurrentIndex(int)));
+ }
+
+
+ this->setLayout(mainLayout);
+
+ QMenu* viewMenu = new QMenu(tr("&View"), this);
+ menus_.push_back(viewMenu);
+
+ compactRosterAction_ = new QAction(tr("&Compact Roster"), this);
+ compactRosterAction_->setCheckable(true);
+ compactRosterAction_->setChecked(false);
+ connect(compactRosterAction_, SIGNAL(toggled(bool)), SLOT(handleCompactRosterToggled(bool)));
+ viewMenu->addAction(compactRosterAction_);
+ handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+
+ showOfflineAction_ = new QAction(tr("&Show offline contacts"), this);
+ showOfflineAction_->setCheckable(true);
+ showOfflineAction_->setChecked(false);
+ connect(showOfflineAction_, SIGNAL(toggled(bool)), SLOT(handleShowOfflineToggled(bool)));
+ viewMenu->addAction(showOfflineAction_);
+ handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
+
+ if (emoticonsExist) {
+ showEmoticonsAction_ = new QAction(tr("&Show Emoticons"), this);
+ showEmoticonsAction_->setCheckable(true);
+ showEmoticonsAction_->setChecked(false);
+ connect(showEmoticonsAction_, SIGNAL(toggled(bool)), SLOT(handleShowEmoticonsToggled(bool)));
+ viewMenu->addAction(showEmoticonsAction_);
+ handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
+ }
+
+ QMenu* actionsMenu = new QMenu(tr("&Actions"), this);
+ menus_.push_back(actionsMenu);
+ QAction* editProfileAction = new QAction(tr("Edit &Profile…"), this);
+ connect(editProfileAction, SIGNAL(triggered()), SLOT(handleEditProfileAction()));
+ actionsMenu->addAction(editProfileAction);
+ onlineOnlyActions_ << editProfileAction;
+ QAction* joinMUCAction = new QAction(tr("Enter &Room…"), this);
+ connect(joinMUCAction, SIGNAL(triggered()), SLOT(handleJoinMUCAction()));
+ actionsMenu->addAction(joinMUCAction);
+ onlineOnlyActions_ << joinMUCAction;
#ifdef SWIFT_EXPERIMENTAL_HISTORY
- QAction* viewLogsAction = new QAction(tr("&View History…"), this);
- connect(viewLogsAction, SIGNAL(triggered()), SLOT(handleViewLogsAction()));
- actionsMenu->addAction(viewLogsAction);
+ QAction* viewLogsAction = new QAction(tr("&View History…"), this);
+ connect(viewLogsAction, SIGNAL(triggered()), SLOT(handleViewLogsAction()));
+ actionsMenu->addAction(viewLogsAction);
#endif
- openBlockingListEditor_ = new QAction(tr("Edit &Blocking List…"), this);
- connect(openBlockingListEditor_, SIGNAL(triggered()), SLOT(handleEditBlockingList()));
- actionsMenu->addAction(openBlockingListEditor_);
- onlineOnlyActions_ << openBlockingListEditor_;
- openBlockingListEditor_->setVisible(false);
- addUserAction_ = new QAction(tr("&Add Contact…"), this);
- addUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
- addUserAction_->setShortcutContext(Qt::ApplicationShortcut);
- connect(addUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleAddUserActionTriggered(bool)));
- actionsMenu->addAction(addUserAction_);
- onlineOnlyActions_ << addUserAction_;
- editUserAction_ = new QAction(tr("&Edit Selected Contact…"), this);
- connect(editUserAction_, SIGNAL(triggered(bool)), treeWidget_, SLOT(handleEditUserActionTriggered(bool)));
- actionsMenu->addAction(editUserAction_);
- onlineOnlyActions_ << editUserAction_;
- editUserAction_->setEnabled(false);
- chatUserAction_ = new QAction(tr("Start &Chat…"), this);
- chatUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
- chatUserAction_->setShortcutContext(Qt::ApplicationShortcut);
- connect(chatUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleChatUserActionTriggered(bool)));
- actionsMenu->addAction(chatUserAction_);
- onlineOnlyActions_ << chatUserAction_;
- if (enableAdHocCommandOnJID) {
- otherAdHocAction_ = new QAction(tr("Run Other Command"), this);
- connect(otherAdHocAction_, SIGNAL(triggered()), this, SLOT(handleOtherAdHocActionTriggered()));
- actionsMenu->addAction(otherAdHocAction_);
- onlineOnlyActions_ << otherAdHocAction_;
- }
- serverAdHocMenu_ = new QMenu(tr("Run Server Command"), this);
- actionsMenu->addMenu(serverAdHocMenu_);
- actionsMenu->addSeparator();
- QAction* signOutAction = new QAction(tr("&Sign Out"), this);
- connect(signOutAction, SIGNAL(triggered()), SLOT(handleSignOutAction()));
- actionsMenu->addAction(signOutAction);
-
- toggleRequestDeliveryReceipts_ = new QAction(tr("&Request Delivery Receipts"), this);
- toggleRequestDeliveryReceipts_->setCheckable(true);
- toggleRequestDeliveryReceipts_->setChecked(settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS));
- connect(toggleRequestDeliveryReceipts_, SIGNAL(toggled(bool)), SLOT(handleToggleRequestDeliveryReceipts(bool)));
-
- QList< QAction* > generalMenuActions = loginMenus_.generalMenu->actions();
- loginMenus_.generalMenu->insertAction(generalMenuActions.at(generalMenuActions.count()-2),toggleRequestDeliveryReceipts_);
-
- treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QtMainWindow::handleSomethingSelectedChanged, this, _1));
-
- setAvailableAdHocCommands(std::vector<DiscoItems::Item>());
- QAction* adHocAction = new QAction(tr("Collecting commands..."), this);
- adHocAction->setEnabled(false);
- serverAdHocMenu_->addAction(adHocAction);
- serverAdHocCommandActions_.append(adHocAction);
-
- settings_->onSettingChanged.connect(boost::bind(&QtMainWindow::handleSettingChanged, this, _1));
+ openBlockingListEditor_ = new QAction(tr("Edit &Blocking List…"), this);
+ connect(openBlockingListEditor_, SIGNAL(triggered()), SLOT(handleEditBlockingList()));
+ actionsMenu->addAction(openBlockingListEditor_);
+ onlineOnlyActions_ << openBlockingListEditor_;
+ openBlockingListEditor_->setVisible(false);
+ addUserAction_ = new QAction(tr("&Add Contact…"), this);
+ addUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
+ addUserAction_->setShortcutContext(Qt::ApplicationShortcut);
+ connect(addUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleAddUserActionTriggered(bool)));
+ actionsMenu->addAction(addUserAction_);
+ onlineOnlyActions_ << addUserAction_;
+ editUserAction_ = new QAction(tr("&Edit Selected Contact…"), this);
+ connect(editUserAction_, SIGNAL(triggered(bool)), treeWidget_, SLOT(handleEditUserActionTriggered(bool)));
+ actionsMenu->addAction(editUserAction_);
+ onlineOnlyActions_ << editUserAction_;
+ editUserAction_->setEnabled(false);
+ chatUserAction_ = new QAction(tr("Start &Chat…"), this);
+ chatUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
+ chatUserAction_->setShortcutContext(Qt::ApplicationShortcut);
+ connect(chatUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleChatUserActionTriggered(bool)));
+ actionsMenu->addAction(chatUserAction_);
+ onlineOnlyActions_ << chatUserAction_;
+ if (enableAdHocCommandOnJID) {
+ otherAdHocAction_ = new QAction(tr("Run Other Command"), this);
+ connect(otherAdHocAction_, SIGNAL(triggered()), this, SLOT(handleOtherAdHocActionTriggered()));
+ actionsMenu->addAction(otherAdHocAction_);
+ onlineOnlyActions_ << otherAdHocAction_;
+ }
+ serverAdHocMenu_ = new QMenu(tr("Run Server Command"), this);
+ actionsMenu->addMenu(serverAdHocMenu_);
+ actionsMenu->addSeparator();
+ QAction* signOutAction = new QAction(tr("&Sign Out"), this);
+ connect(signOutAction, SIGNAL(triggered()), SLOT(handleSignOutAction()));
+ actionsMenu->addAction(signOutAction);
+
+ toggleRequestDeliveryReceipts_ = new QAction(tr("&Request Delivery Receipts"), this);
+ toggleRequestDeliveryReceipts_->setCheckable(true);
+ toggleRequestDeliveryReceipts_->setChecked(settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS));
+ connect(toggleRequestDeliveryReceipts_, SIGNAL(toggled(bool)), SLOT(handleToggleRequestDeliveryReceipts(bool)));
+
+ QList< QAction* > generalMenuActions = loginMenus_.generalMenu->actions();
+ loginMenus_.generalMenu->insertAction(generalMenuActions.at(generalMenuActions.count()-2),toggleRequestDeliveryReceipts_);
+
+ treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QtMainWindow::handleSomethingSelectedChanged, this, _1));
+
+ setAvailableAdHocCommands(std::vector<DiscoItems::Item>());
+ QAction* adHocAction = new QAction(tr("Collecting commands..."), this);
+ adHocAction->setEnabled(false);
+ serverAdHocMenu_->addAction(adHocAction);
+ serverAdHocCommandActions_.append(adHocAction);
+
+ settings_->onSettingChanged.connect(boost::bind(&QtMainWindow::handleSettingChanged, this, _1));
}
QtMainWindow::~QtMainWindow() {
- settings_->onSettingChanged.disconnect(boost::bind(&QtMainWindow::handleSettingChanged, this, _1));
+ settings_->onSettingChanged.disconnect(boost::bind(&QtMainWindow::handleSettingChanged, this, _1));
}
void QtMainWindow::handleTabChanged(int index) {
- settings_->storeSetting(QtUISettingConstants::CURRENT_ROSTER_TAB, index);
+ settings_->storeSetting(QtUISettingConstants::CURRENT_ROSTER_TAB, index);
}
void QtMainWindow::handleToggleRequestDeliveryReceipts(bool enabled) {
- settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, enabled);
+ settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, enabled);
}
void QtMainWindow::handleShowCertificateInfo() {
- onShowCertificateRequest();
+ onShowCertificateRequest();
}
void QtMainWindow::handleEditBlockingList() {
- uiEventStream_->send(boost::make_shared<RequestBlockListDialogUIEvent>());
+ uiEventStream_->send(boost::make_shared<RequestBlockListDialogUIEvent>());
}
void QtMainWindow::handleSomethingSelectedChanged(bool itemSelected) {
- bool isOnline = addUserAction_->isEnabled();
- editUserAction_->setEnabled(isOnline && itemSelected);
+ bool isOnline = addUserAction_->isEnabled();
+ editUserAction_->setEnabled(isOnline && itemSelected);
}
QtEventWindow* QtMainWindow::getEventWindow() {
- return eventWindow_;
+ return eventWindow_;
}
QtChatListWindow* QtMainWindow::getChatListWindow() {
- return chatListWindow_;
+ return chatListWindow_;
}
void QtMainWindow::setRosterModel(Roster* roster) {
- treeWidget_->setRosterModel(roster);
+ treeWidget_->setRosterModel(roster);
}
void QtMainWindow::handleEditProfileRequest() {
- uiEventStream_->send(boost::make_shared<RequestProfileEditorUIEvent>());
+ uiEventStream_->send(boost::make_shared<RequestProfileEditorUIEvent>());
}
void QtMainWindow::handleEventCountUpdated(int count) {
- QColor eventTabColor = (count == 0) ? QColor() : QColor(255, 0, 0); // invalid resets to default
- int eventIndex = 2;
- tabs_->tabBar()->setTabTextColor(eventIndex, eventTabColor);
- QString text = tr("&Notices");
- if (count > 0) {
- text += QString(" (%1)").arg(count);
- }
- tabs_->setTabText(eventIndex, text);
+ QColor eventTabColor = (count == 0) ? QColor() : QColor(255, 0, 0); // invalid resets to default
+ int eventIndex = 2;
+ tabs_->tabBar()->setTabTextColor(eventIndex, eventTabColor);
+ QString text = tr("&Notices");
+ if (count > 0) {
+ text += QString(" (%1)").arg(count);
+ }
+ tabs_->setTabText(eventIndex, text);
}
void QtMainWindow::handleChatCountUpdated(int count) {
- QColor chatTabColor = (count == 0) ? QColor() : QColor(255, 0, 0); // invalid resets to default
- int chatIndex = 1;
- tabs_->tabBar()->setTabTextColor(chatIndex, chatTabColor);
- QString text = tr("C&hats");
- if (count > 0) {
- text += QString(" (%1)").arg(count);
- }
- tabs_->setTabText(chatIndex, text);
+ QColor chatTabColor = (count == 0) ? QColor() : QColor(255, 0, 0); // invalid resets to default
+ int chatIndex = 1;
+ tabs_->tabBar()->setTabTextColor(chatIndex, chatTabColor);
+ QString text = tr("C&hats");
+ if (count > 0) {
+ text += QString(" (%1)").arg(count);
+ }
+ tabs_->setTabText(chatIndex, text);
}
void QtMainWindow::handleAddUserActionTriggered(bool /*checked*/) {
- boost::shared_ptr<UIEvent> event(new RequestAddUserDialogUIEvent());
- uiEventStream_->send(event);
+ boost::shared_ptr<UIEvent> event(new RequestAddUserDialogUIEvent());
+ uiEventStream_->send(event);
}
void QtMainWindow::handleChatUserActionTriggered(bool /*checked*/) {
- boost::shared_ptr<UIEvent> event(new RequestChatWithUserDialogUIEvent());
- uiEventStream_->send(event);
+ boost::shared_ptr<UIEvent> event(new RequestChatWithUserDialogUIEvent());
+ uiEventStream_->send(event);
}
void QtMainWindow::handleOtherAdHocActionTriggered() {
- new QtAdHocCommandWithJIDWindow(uiEventStream_);
+ new QtAdHocCommandWithJIDWindow(uiEventStream_);
}
void QtMainWindow::handleSignOutAction() {
- loginMenus_.generalMenu->removeAction(toggleRequestDeliveryReceipts_);
- onSignOutRequest();
+ loginMenus_.generalMenu->removeAction(toggleRequestDeliveryReceipts_);
+ onSignOutRequest();
}
void QtMainWindow::handleEditProfileAction() {
- uiEventStream_->send(boost::make_shared<RequestProfileEditorUIEvent>());
+ uiEventStream_->send(boost::make_shared<RequestProfileEditorUIEvent>());
}
void QtMainWindow::handleJoinMUCAction() {
- uiEventStream_->send(boost::make_shared<RequestJoinMUCUIEvent>());
+ uiEventStream_->send(boost::make_shared<RequestJoinMUCUIEvent>());
}
void QtMainWindow::handleViewLogsAction() {
- uiEventStream_->send(boost::make_shared<RequestHistoryUIEvent>());
+ uiEventStream_->send(boost::make_shared<RequestHistoryUIEvent>());
}
void QtMainWindow::handleStatusChanged(StatusShow::Type showType, const QString &statusMessage) {
- onChangeStatusRequest(showType, Q2PSTRING(statusMessage));
+ onChangeStatusRequest(showType, Q2PSTRING(statusMessage));
}
void QtMainWindow::handleSettingChanged(const std::string& settingPath) {
- if (settingPath == SettingConstants::SHOW_OFFLINE.getKey()) {
- handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
- }
- if (settingPath == QtUISettingConstants::SHOW_EMOTICONS.getKey()) {
- handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
- }
- if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) {
- toggleRequestDeliveryReceipts_->setChecked(settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS));
- }
- if (settingPath == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
- handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
- }
+ if (settingPath == SettingConstants::SHOW_OFFLINE.getKey()) {
+ handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
+ }
+ if (settingPath == QtUISettingConstants::SHOW_EMOTICONS.getKey()) {
+ handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
+ }
+ if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) {
+ toggleRequestDeliveryReceipts_->setChecked(settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS));
+ }
+ if (settingPath == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
+ handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ }
}
void QtMainWindow::handleCompactRosterToggled(bool state) {
- settings_->storeSetting(QtUISettingConstants::COMPACT_ROSTER, state);
- compactRosterAction_->setChecked(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ settings_->storeSetting(QtUISettingConstants::COMPACT_ROSTER, state);
+ compactRosterAction_->setChecked(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
}
void QtMainWindow::handleShowOfflineToggled(bool state) {
- settings_->storeSetting(SettingConstants::SHOW_OFFLINE, state);
- showOfflineAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
+ settings_->storeSetting(SettingConstants::SHOW_OFFLINE, state);
+ showOfflineAction_->setChecked(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
}
void QtMainWindow::handleShowEmoticonsToggled(bool state) {
- settings_->storeSetting(QtUISettingConstants::SHOW_EMOTICONS, state);
- showEmoticonsAction_->setChecked(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
+ settings_->storeSetting(QtUISettingConstants::SHOW_EMOTICONS, state);
+ showEmoticonsAction_->setChecked(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
}
void QtMainWindow::setMyNick(const std::string& nick) {
- meView_->setNick(P2QSTRING(nick));
+ meView_->setNick(P2QSTRING(nick));
}
void QtMainWindow::setMyJID(const JID& jid) {
- meView_->setJID(P2QSTRING(jid.toBare().toString()));
+ meView_->setJID(P2QSTRING(jid.toBare().toString()));
}
void QtMainWindow::setMyAvatarPath(const std::string& path) {
- meView_->setAvatar(P2QSTRING(path));
+ meView_->setAvatar(P2QSTRING(path));
}
void QtMainWindow::setMyStatusText(const std::string& status) {
- meView_->setStatusText(P2QSTRING(status));
+ meView_->setStatusText(P2QSTRING(status));
}
void QtMainWindow::setMyStatusType(StatusShow::Type type) {
- meView_->setStatusType(type);
- const bool online = (type != StatusShow::None);
- treeWidget_->setOnline(online);
- chatListWindow_->setOnline(online);
- foreach (QAction *action, onlineOnlyActions_) {
- action->setEnabled(online);
- }
- serverAdHocMenu_->setEnabled(online);
+ meView_->setStatusType(type);
+ const bool online = (type != StatusShow::None);
+ treeWidget_->setOnline(online);
+ chatListWindow_->setOnline(online);
+ foreach (QAction *action, onlineOnlyActions_) {
+ action->setEnabled(online);
+ }
+ serverAdHocMenu_->setEnabled(online);
}
void QtMainWindow::setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) {
- meView_->setContactRosterItem(contact);
+ meView_->setContactRosterItem(contact);
}
void QtMainWindow::setConnecting() {
- meView_->setConnecting();
+ meView_->setConnecting();
}
void QtMainWindow::setStreamEncryptionStatus(bool tlsInPlaceAndValid) {
- meView_->setStreamEncryptionStatus(tlsInPlaceAndValid);
+ meView_->setStreamEncryptionStatus(tlsInPlaceAndValid);
}
void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain) {
- openCertificateDialog(chain, this);
+ openCertificateDialog(chain, this);
}
void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent) {
#if defined(SWIFTEN_PLATFORM_MACOSX)
- CocoaUIHelpers::displayCertificateChainAsSheet(parent, chain);
+ CocoaUIHelpers::displayCertificateChainAsSheet(parent, chain);
#elif defined(SWIFTEN_PLATFORM_WINDOWS)
- WinUIHelpers::displayCertificateChainAsSheet(parent, chain);
+ WinUIHelpers::displayCertificateChainAsSheet(parent, chain);
#else
- QtCertificateViewerDialog::displayCertificateChainAsSheet(parent, chain);
+ QtCertificateViewerDialog::displayCertificateChainAsSheet(parent, chain);
#endif
}
void QtMainWindow::handleAdHocActionTriggered(bool /*checked*/) {
- QAction* action = qobject_cast<QAction*>(sender());
- assert(action);
- DiscoItems::Item command = serverAdHocCommands_[serverAdHocCommandActions_.indexOf(action)];
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestAdHocUIEvent(command)));
+ QAction* action = qobject_cast<QAction*>(sender());
+ assert(action);
+ DiscoItems::Item command = serverAdHocCommands_[serverAdHocCommandActions_.indexOf(action)];
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestAdHocUIEvent(command)));
}
void QtMainWindow::setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands) {
- serverAdHocCommands_ = commands;
- foreach (QAction* action, serverAdHocCommandActions_) {
- delete action;
- }
- serverAdHocMenu_->clear();
- serverAdHocCommandActions_.clear();
- foreach (DiscoItems::Item command, commands) {
- QAction* action = new QAction(P2QSTRING(command.getName()), this);
- connect(action, SIGNAL(triggered(bool)), this, SLOT(handleAdHocActionTriggered(bool)));
- serverAdHocMenu_->addAction(action);
- serverAdHocCommandActions_.append(action);
- }
- if (serverAdHocCommandActions_.isEmpty()) {
- QAction* action = new QAction(tr("No Available Commands"), this);
- action->setEnabled(false);
- serverAdHocMenu_->addAction(action);
- serverAdHocCommandActions_.append(action);
- }
+ serverAdHocCommands_ = commands;
+ foreach (QAction* action, serverAdHocCommandActions_) {
+ delete action;
+ }
+ serverAdHocMenu_->clear();
+ serverAdHocCommandActions_.clear();
+ foreach (DiscoItems::Item command, commands) {
+ QAction* action = new QAction(P2QSTRING(command.getName()), this);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(handleAdHocActionTriggered(bool)));
+ serverAdHocMenu_->addAction(action);
+ serverAdHocCommandActions_.append(action);
+ }
+ if (serverAdHocCommandActions_.isEmpty()) {
+ QAction* action = new QAction(tr("No Available Commands"), this);
+ action->setEnabled(false);
+ serverAdHocMenu_->addAction(action);
+ serverAdHocCommandActions_.append(action);
+ }
}
void QtMainWindow::setBlockingCommandAvailable(bool isAvailable) {
- openBlockingListEditor_->setVisible(isAvailable);
+ openBlockingListEditor_->setVisible(isAvailable);
}
}
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index 71a5783..d90dade 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -28,83 +28,83 @@ class QMenu;
class QTabWidget;
namespace Swift {
- class QtRosterWidget;
- class TreeWidget;
- class UIEventStream;
- class QtTabWidget;
- class SettingsProvider;
- class QtUIPreferences;
- class StatusCache;
+ class QtRosterWidget;
+ class TreeWidget;
+ class UIEventStream;
+ class QtTabWidget;
+ class SettingsProvider;
+ class QtUIPreferences;
+ class StatusCache;
- class QtMainWindow : public QWidget, public MainWindow {
- Q_OBJECT
- public:
- QtMainWindow(SettingsProvider*, UIEventStream* eventStream, QtLoginWindow::QtMenus loginMenus, StatusCache* statusCache, bool emoticonsExist, bool enableAdHocCommandOnJID);
- virtual ~QtMainWindow();
- std::vector<QMenu*> getMenus() {return menus_;}
- void setMyNick(const std::string& name);
- void setMyJID(const JID& jid);
- void setMyAvatarPath(const std::string& path);
- void setMyStatusText(const std::string& status);
- void setMyStatusType(StatusShow::Type type);
- void setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact);
- void setConnecting();
- void setStreamEncryptionStatus(bool tlsInPlaceAndValid);
- void openCertificateDialog(const std::vector<Certificate::ref>& chain);
- static void openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent);
- QtEventWindow* getEventWindow();
- QtChatListWindow* getChatListWindow();
- void setRosterModel(Roster* roster);
- void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands);
- void setBlockingCommandAvailable(bool isAvailable);
- private slots:
- void handleStatusChanged(StatusShow::Type showType, const QString &statusMessage);
- void handleSettingChanged(const std::string& settingPath);
- void handleCompactRosterToggled(bool);
- void handleShowOfflineToggled(bool);
- void handleShowEmoticonsToggled(bool);
- void handleJoinMUCAction();
- void handleViewLogsAction();
- void handleSignOutAction();
- void handleEditProfileAction();
- void handleAddUserActionTriggered(bool checked);
- void handleChatUserActionTriggered(bool checked);
- void handleOtherAdHocActionTriggered();
- void handleAdHocActionTriggered(bool checked);
- void handleEventCountUpdated(int count);
- void handleChatCountUpdated(int count);
- void handleEditProfileRequest();
- void handleTabChanged(int index);
- void handleToggleRequestDeliveryReceipts(bool enabled);
- void handleShowCertificateInfo();
- void handleEditBlockingList();
- void handleSomethingSelectedChanged(bool itemSelected);
+ class QtMainWindow : public QWidget, public MainWindow {
+ Q_OBJECT
+ public:
+ QtMainWindow(SettingsProvider*, UIEventStream* eventStream, QtLoginWindow::QtMenus loginMenus, StatusCache* statusCache, bool emoticonsExist, bool enableAdHocCommandOnJID);
+ virtual ~QtMainWindow();
+ std::vector<QMenu*> getMenus() {return menus_;}
+ void setMyNick(const std::string& name);
+ void setMyJID(const JID& jid);
+ void setMyAvatarPath(const std::string& path);
+ void setMyStatusText(const std::string& status);
+ void setMyStatusType(StatusShow::Type type);
+ void setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact);
+ void setConnecting();
+ void setStreamEncryptionStatus(bool tlsInPlaceAndValid);
+ void openCertificateDialog(const std::vector<Certificate::ref>& chain);
+ static void openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent);
+ QtEventWindow* getEventWindow();
+ QtChatListWindow* getChatListWindow();
+ void setRosterModel(Roster* roster);
+ void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands);
+ void setBlockingCommandAvailable(bool isAvailable);
+ private slots:
+ void handleStatusChanged(StatusShow::Type showType, const QString &statusMessage);
+ void handleSettingChanged(const std::string& settingPath);
+ void handleCompactRosterToggled(bool);
+ void handleShowOfflineToggled(bool);
+ void handleShowEmoticonsToggled(bool);
+ void handleJoinMUCAction();
+ void handleViewLogsAction();
+ void handleSignOutAction();
+ void handleEditProfileAction();
+ void handleAddUserActionTriggered(bool checked);
+ void handleChatUserActionTriggered(bool checked);
+ void handleOtherAdHocActionTriggered();
+ void handleAdHocActionTriggered(bool checked);
+ void handleEventCountUpdated(int count);
+ void handleChatCountUpdated(int count);
+ void handleEditProfileRequest();
+ void handleTabChanged(int index);
+ void handleToggleRequestDeliveryReceipts(bool enabled);
+ void handleShowCertificateInfo();
+ void handleEditBlockingList();
+ void handleSomethingSelectedChanged(bool itemSelected);
- private:
- SettingsProvider* settings_;
- QtLoginWindow::QtMenus loginMenus_;
- std::vector<QMenu*> menus_;
- QtRosterWidget* treeWidget_;
- QtRosterHeader* meView_;
- QAction* addUserAction_;
- QAction* editUserAction_;
- QAction* chatUserAction_;
- QAction* otherAdHocAction_;
- QAction* showOfflineAction_;
- QAction* compactRosterAction_;
- QAction* showEmoticonsAction_;
- QAction* openBlockingListEditor_;
- QAction* toggleRequestDeliveryReceipts_;
- QMenu* serverAdHocMenu_;
- QtTabWidget* tabs_;
- QComboBox* tabBarCombo_;
- QWidget* contactsTabWidget_;
- QWidget* eventsTabWidget_;
- QtEventWindow* eventWindow_;
- QtChatListWindow* chatListWindow_;
- UIEventStream* uiEventStream_;
- std::vector<DiscoItems::Item> serverAdHocCommands_;
- QList<QAction*> serverAdHocCommandActions_;
- QList<QAction*> onlineOnlyActions_;
- };
+ private:
+ SettingsProvider* settings_;
+ QtLoginWindow::QtMenus loginMenus_;
+ std::vector<QMenu*> menus_;
+ QtRosterWidget* treeWidget_;
+ QtRosterHeader* meView_;
+ QAction* addUserAction_;
+ QAction* editUserAction_;
+ QAction* chatUserAction_;
+ QAction* otherAdHocAction_;
+ QAction* showOfflineAction_;
+ QAction* compactRosterAction_;
+ QAction* showEmoticonsAction_;
+ QAction* openBlockingListEditor_;
+ QAction* toggleRequestDeliveryReceipts_;
+ QMenu* serverAdHocMenu_;
+ QtTabWidget* tabs_;
+ QComboBox* tabBarCombo_;
+ QWidget* contactsTabWidget_;
+ QWidget* eventsTabWidget_;
+ QtEventWindow* eventWindow_;
+ QtChatListWindow* chatListWindow_;
+ UIEventStream* uiEventStream_;
+ std::vector<DiscoItems::Item> serverAdHocCommands_;
+ QList<QAction*> serverAdHocCommandActions_;
+ QList<QAction*> onlineOnlyActions_;
+ };
}
diff --git a/Swift/QtUI/QtNameWidget.cpp b/Swift/QtUI/QtNameWidget.cpp
index cf668c8..0610a00 100644
--- a/Swift/QtUI/QtNameWidget.cpp
+++ b/Swift/QtUI/QtNameWidget.cpp
@@ -18,80 +18,80 @@
namespace Swift {
QtNameWidget::QtNameWidget(SettingsProvider* settings, QWidget *parent) : QWidget(parent), settings(settings), isOnline_(false) {
- QHBoxLayout* mainLayout = new QHBoxLayout(this);
- mainLayout->setSpacing(0);
- mainLayout->setContentsMargins(0,0,0,0);
+ QHBoxLayout* mainLayout = new QHBoxLayout(this);
+ mainLayout->setSpacing(0);
+ mainLayout->setContentsMargins(0,0,0,0);
- mode = settings->getSetting(QtUISettingConstants::SHOW_NICK_IN_ROSTER_HEADER) ? ShowNick : ShowJID;
+ mode = settings->getSetting(QtUISettingConstants::SHOW_NICK_IN_ROSTER_HEADER) ? ShowNick : ShowJID;
- textLabel = new QtElidingLabel(this);
- QFont font = textLabel->font();
- font.setBold(true);
- textLabel->setFont(font);
- mainLayout->addWidget(textLabel);
+ textLabel = new QtElidingLabel(this);
+ QFont font = textLabel->font();
+ font.setBold(true);
+ textLabel->setFont(font);
+ mainLayout->addWidget(textLabel);
}
void QtNameWidget::setNick(const QString& nick) {
- this->nick = nick;
- updateText();
+ this->nick = nick;
+ updateText();
}
void QtNameWidget::setJID(const QString& jid) {
- this->jid = jid;
- updateText();
+ this->jid = jid;
+ updateText();
}
void QtNameWidget::setOnline(const bool isOnline) {
- isOnline_ = isOnline;
+ isOnline_ = isOnline;
}
void QtNameWidget::mousePressEvent(QMouseEvent* event) {
- QMenu menu;
- bool hasNick = !nick.isEmpty();
-
- QAction* showAsNick = new QAction(hasNick ? tr("Show Nickname") : tr("(No Nickname Set)"), this);
- showAsNick->setCheckable(true);
- showAsNick->setEnabled(hasNick);
- if (mode == ShowNick && hasNick) {
- showAsNick->setChecked(true);
- }
- menu.addAction(showAsNick);
-
- QAction* showAsJID = new QAction(tr("Show Address"), this);
- showAsJID->setCheckable(true);
- if (mode == ShowJID || !hasNick) {
- showAsJID->setChecked(true);
- }
- menu.addAction(showAsJID);
-
- QAction* editProfile = new QAction(tr("Edit Profile"), this);
- menu.addAction(editProfile);
- editProfile->setEnabled(isOnline_);
-
- QAction* result = menu.exec(event->globalPos());
- if (result == showAsJID) {
- mode = ShowJID;
- }
- else if (result == showAsNick) {
- mode = ShowNick;
- }
- else if (result == editProfile) {
- emit onChangeNickRequest();
- }
- settings->storeSetting(QtUISettingConstants::SHOW_NICK_IN_ROSTER_HEADER, mode == ShowNick);
- updateText();
+ QMenu menu;
+ bool hasNick = !nick.isEmpty();
+
+ QAction* showAsNick = new QAction(hasNick ? tr("Show Nickname") : tr("(No Nickname Set)"), this);
+ showAsNick->setCheckable(true);
+ showAsNick->setEnabled(hasNick);
+ if (mode == ShowNick && hasNick) {
+ showAsNick->setChecked(true);
+ }
+ menu.addAction(showAsNick);
+
+ QAction* showAsJID = new QAction(tr("Show Address"), this);
+ showAsJID->setCheckable(true);
+ if (mode == ShowJID || !hasNick) {
+ showAsJID->setChecked(true);
+ }
+ menu.addAction(showAsJID);
+
+ QAction* editProfile = new QAction(tr("Edit Profile"), this);
+ menu.addAction(editProfile);
+ editProfile->setEnabled(isOnline_);
+
+ QAction* result = menu.exec(event->globalPos());
+ if (result == showAsJID) {
+ mode = ShowJID;
+ }
+ else if (result == showAsNick) {
+ mode = ShowNick;
+ }
+ else if (result == editProfile) {
+ emit onChangeNickRequest();
+ }
+ settings->storeSetting(QtUISettingConstants::SHOW_NICK_IN_ROSTER_HEADER, mode == ShowNick);
+ updateText();
}
void QtNameWidget::updateText() {
- QString text;
- if (mode == ShowNick && !nick.isEmpty()) {
- text = nick;
- }
- else {
- text = jid;
- }
- text.replace("<","&lt;");
- textLabel->setText(text);
+ QString text;
+ if (mode == ShowNick && !nick.isEmpty()) {
+ text = nick;
+ }
+ else {
+ text = jid;
+ }
+ text.replace("<","&lt;");
+ textLabel->setText(text);
}
}
diff --git a/Swift/QtUI/QtNameWidget.h b/Swift/QtUI/QtNameWidget.h
index 5f9962b..0da0ff6 100644
--- a/Swift/QtUI/QtNameWidget.h
+++ b/Swift/QtUI/QtNameWidget.h
@@ -9,38 +9,38 @@
#include <QWidget>
namespace Swift {
- class QtElidingLabel;
- class SettingsProvider;
-
- class QtNameWidget : public QWidget {
- Q_OBJECT
-
- public:
- QtNameWidget(SettingsProvider* settings, QWidget *parent);
-
- void setNick(const QString& text);
- void setJID(const QString& jid);
- void setOnline(const bool isOnline);
-
- signals:
- void onChangeNickRequest();
-
- private:
- void updateText();
- virtual void mousePressEvent(QMouseEvent* event);
-
- private:
- enum Mode {
- ShowNick,
- ShowJID
- };
-
- SettingsProvider* settings;
- Mode mode;
- QtElidingLabel* textLabel;
- QString jid;
- QString nick;
- bool isOnline_;
- };
+ class QtElidingLabel;
+ class SettingsProvider;
+
+ class QtNameWidget : public QWidget {
+ Q_OBJECT
+
+ public:
+ QtNameWidget(SettingsProvider* settings, QWidget *parent);
+
+ void setNick(const QString& text);
+ void setJID(const QString& jid);
+ void setOnline(const bool isOnline);
+
+ signals:
+ void onChangeNickRequest();
+
+ private:
+ void updateText();
+ virtual void mousePressEvent(QMouseEvent* event);
+
+ private:
+ enum Mode {
+ ShowNick,
+ ShowJID
+ };
+
+ SettingsProvider* settings;
+ Mode mode;
+ QtElidingLabel* textLabel;
+ QString jid;
+ QString nick;
+ bool isOnline_;
+ };
}
diff --git a/Swift/QtUI/QtPlainChatView.cpp b/Swift/QtUI/QtPlainChatView.cpp
index 3144080..9dc815a 100644
--- a/Swift/QtUI/QtPlainChatView.cpp
+++ b/Swift/QtUI/QtPlainChatView.cpp
@@ -31,402 +31,402 @@ namespace Swift {
QtPlainChatView::QtPlainChatView(QtChatWindow *window, UIEventStream* eventStream)
: QtChatView(window), window_(window), eventStream_(eventStream), idGenerator_(0) {
- QVBoxLayout* mainLayout = new QVBoxLayout(this);
- mainLayout->setSpacing(0);
- mainLayout->setContentsMargins(0,0,0,0);
- log_ = new LogTextEdit(this);
- log_->setReadOnly(true);
- log_->setAccessibleName(tr("Chat Messages"));
- mainLayout->addWidget(log_);
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
+ mainLayout->setSpacing(0);
+ mainLayout->setContentsMargins(0,0,0,0);
+ log_ = new LogTextEdit(this);
+ log_->setReadOnly(true);
+ log_->setAccessibleName(tr("Chat Messages"));
+ mainLayout->addWidget(log_);
}
QtPlainChatView::~QtPlainChatView() {
}
QString chatMessageToString(const ChatWindow::ChatMessage& message) {
- QString result;
- foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
- boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
- boost::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart;
- boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart;
- boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart;
-
- if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
- QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text));
- text.replace("\n","<br/>");
- result += text;
- continue;
- }
- if ((uriPart = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) {
- QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target));
- result += "<a href='" + uri + "' >" + uri + "</a>";
- continue;
- }
- if ((emoticonPart = boost::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) {
- result += P2QSTRING(emoticonPart->alternativeText);
- continue;
- }
- if ((highlightPart = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) {
- //FIXME: Maybe do something here. Anything, really.
- continue;
- }
- }
- return result;
+ QString result;
+ foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
+ boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
+ boost::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart;
+ boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart;
+ boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart;
+
+ if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
+ QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text));
+ text.replace("\n","<br/>");
+ result += text;
+ continue;
+ }
+ if ((uriPart = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) {
+ QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target));
+ result += "<a href='" + uri + "' >" + uri + "</a>";
+ continue;
+ }
+ if ((emoticonPart = boost::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) {
+ result += P2QSTRING(emoticonPart->alternativeText);
+ continue;
+ }
+ if ((highlightPart = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) {
+ //FIXME: Maybe do something here. Anything, really.
+ continue;
+ }
+ }
+ return result;
}
std::string QtPlainChatView::addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time) {
- QString text = "<p>";
- if (label) {
- text += P2QSTRING(label->getLabel()) + "<br/>";
- }
- QString name = senderIsSelf ? "you" : P2QSTRING(senderName);
- text += QString(tr("At %1 %2 said:")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name) + "<br/>";
- text += chatMessageToString(message);
- text += "</p>";
- log_->append(text);
- const std::string idx = senderIsSelf ? "" : senderName;
- lastMessageLabel_[idx] = label;
- return idx;
+ QString text = "<p>";
+ if (label) {
+ text += P2QSTRING(label->getLabel()) + "<br/>";
+ }
+ QString name = senderIsSelf ? "you" : P2QSTRING(senderName);
+ text += QString(tr("At %1 %2 said:")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name) + "<br/>";
+ text += chatMessageToString(message);
+ text += "</p>";
+ log_->append(text);
+ const std::string idx = senderIsSelf ? "" : senderName;
+ lastMessageLabel_[idx] = label;
+ return idx;
}
std::string QtPlainChatView::addAction(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time) {
- QString text = "<p>";
- if (label) {
- text += P2QSTRING(label->getLabel()) + "<br/>";
- }
- QString name = senderIsSelf ? "you" : P2QSTRING(senderName);
- text += QString(tr("At %1 <i>%2 ")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name);
- text += chatMessageToString(message);
- text += "</i></p>";
- log_->append(text);
- const std::string idx = senderIsSelf ? "" : senderName;
- lastMessageLabel_[idx] = label;
- return idx;
+ QString text = "<p>";
+ if (label) {
+ text += P2QSTRING(label->getLabel()) + "<br/>";
+ }
+ QString name = senderIsSelf ? "you" : P2QSTRING(senderName);
+ text += QString(tr("At %1 <i>%2 ")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name);
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
+ const std::string idx = senderIsSelf ? "" : senderName;
+ lastMessageLabel_[idx] = label;
+ return idx;
}
std::string QtPlainChatView::addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction /*direction*/)
{
- QString text = "<p><i>";
- text += chatMessageToString(message);
- text += "</i></p>";
- log_->append(text);
- return "";
+ QString text = "<p><i>";
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
+ return "";
}
void QtPlainChatView::addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction /*direction*/)
{
- QString text = "<p><i>";
- text += chatMessageToString(message);
- text += "</i></p>";
- log_->append(text);
+ QString text = "<p><i>";
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
}
void QtPlainChatView::addErrorMessage(const ChatWindow::ChatMessage& message)
{
- QString text = "<p><i>";
- text += chatMessageToString(message);
- text += "</i></p>";
- log_->append(text);
+ QString text = "<p><i>";
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
}
void QtPlainChatView::replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time)
{
- QString text = "<p>";
- if (lastMessageLabel_[id]) {
- text += P2QSTRING(lastMessageLabel_[id]->getLabel()) + "<br/>";
- }
- QString name = id.empty() ? "you" : P2QSTRING(id);
- text += QString(tr("At %1 %2 corrected the last message to:")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name) + "<br/>";
- text += chatMessageToString(message);
- text += "</p>";
- log_->append(text);
+ QString text = "<p>";
+ if (lastMessageLabel_[id]) {
+ text += P2QSTRING(lastMessageLabel_[id]->getLabel()) + "<br/>";
+ }
+ QString name = id.empty() ? "you" : P2QSTRING(id);
+ text += QString(tr("At %1 %2 corrected the last message to:")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name) + "<br/>";
+ text += chatMessageToString(message);
+ text += "</p>";
+ log_->append(text);
}
void QtPlainChatView::replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time)
{
- QString text = "<p>";
- if (lastMessageLabel_[id]) {
- text += P2QSTRING(lastMessageLabel_[id]->getLabel()) + "<br/>";
- }
- QString name = id.empty() ? "you" : P2QSTRING(id);
- text += QString(tr("At %1 %2 corrected the last action to: <i>")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name);
- text += chatMessageToString(message);
- text += "</i></p>";
- log_->append(text);
+ QString text = "<p>";
+ if (lastMessageLabel_[id]) {
+ text += P2QSTRING(lastMessageLabel_[id]->getLabel()) + "<br/>";
+ }
+ QString name = id.empty() ? "you" : P2QSTRING(id);
+ text += QString(tr("At %1 %2 corrected the last action to: <i>")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name);
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
}
void QtPlainChatView::replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/)
{
- QString text = "<p>The last message was corrected to:<br/>";
- text += chatMessageToString(message);
- text += "</p>";
- log_->append(text);
+ QString text = "<p>The last message was corrected to:<br/>";
+ text += chatMessageToString(message);
+ text += "</p>";
+ log_->append(text);
}
void QtPlainChatView::replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& /*id*/, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/) {
- QString text = "<p><i>";
- text += chatMessageToString(message);
- text += "</i></p>";
- log_->append(text);
+ QString text = "<p><i>";
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
}
void QtPlainChatView::setAckState(const std::string& /*id*/, ChatWindow::AckState state)
{
- if (state == ChatWindow::Failed) {
- addSystemMessage(ChatWindow::ChatMessage("Message delivery failed due to disconnection from server."), ChatWindow::DefaultDirection);
- }
+ if (state == ChatWindow::Failed) {
+ addSystemMessage(ChatWindow::ChatMessage("Message delivery failed due to disconnection from server."), ChatWindow::DefaultDirection);
+ }
}
std::string QtPlainChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description)
{
- const std::string ftId = "ft" + boost::lexical_cast<std::string>(idGenerator_++);
- const std::string sizeString = formatSize(sizeInBytes);
-
- FileTransfer* transfer;
- if (senderIsSelf) {
- QString description = QInputDialog::getText(this, tr("File transfer description"),
- tr("Description:"), QLineEdit::Normal, "");
- /* NOTE: it is not possible to abort if description is not provided, since we must always return a valid transfer id */
- const std::string descriptionMessage = description.isEmpty() ? "" : (" \"" + Q2PSTRING(description) + "\"");
- const std::string message = std::string() + "Confirm file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>" + descriptionMessage;
- transfer = new FileTransfer(this, senderIsSelf, ftId, filename, ChatWindow::WaitingForAccept, Q2PSTRING(description), message, true);
- addSystemMessage(ChatWindow::ChatMessage("Preparing to start file transfer..."), ChatWindow::DefaultDirection);
- } else { /* incoming transfer */
- const std::string descriptionMessage = description.empty() ? "" : (" \"" + description + "\"");
- const std::string message = std::string() + "Incoming file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>" + descriptionMessage;
- transfer = new FileTransfer(this, senderIsSelf, ftId, filename, ChatWindow::WaitingForAccept, "", message, true);
- addSystemMessage("Incoming file transfer from " + senderName + "...", ChatWindow::DefaultDirection);
- }
-
- fileTransfers_[ftId] = transfer;
- layout()->addWidget(transfer->dialog_);
-
- return ftId;
+ const std::string ftId = "ft" + boost::lexical_cast<std::string>(idGenerator_++);
+ const std::string sizeString = formatSize(sizeInBytes);
+
+ FileTransfer* transfer;
+ if (senderIsSelf) {
+ QString description = QInputDialog::getText(this, tr("File transfer description"),
+ tr("Description:"), QLineEdit::Normal, "");
+ /* NOTE: it is not possible to abort if description is not provided, since we must always return a valid transfer id */
+ const std::string descriptionMessage = description.isEmpty() ? "" : (" \"" + Q2PSTRING(description) + "\"");
+ const std::string message = std::string() + "Confirm file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>" + descriptionMessage;
+ transfer = new FileTransfer(this, senderIsSelf, ftId, filename, ChatWindow::WaitingForAccept, Q2PSTRING(description), message, true);
+ addSystemMessage(ChatWindow::ChatMessage("Preparing to start file transfer..."), ChatWindow::DefaultDirection);
+ } else { /* incoming transfer */
+ const std::string descriptionMessage = description.empty() ? "" : (" \"" + description + "\"");
+ const std::string message = std::string() + "Incoming file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>" + descriptionMessage;
+ transfer = new FileTransfer(this, senderIsSelf, ftId, filename, ChatWindow::WaitingForAccept, "", message, true);
+ addSystemMessage("Incoming file transfer from " + senderName + "...", ChatWindow::DefaultDirection);
+ }
+
+ fileTransfers_[ftId] = transfer;
+ layout()->addWidget(transfer->dialog_);
+
+ return ftId;
}
void QtPlainChatView::setFileTransferProgress(std::string id, const int percentageDone)
{
- FileTransferMap::iterator transfer = fileTransfers_.find(id);
- if (transfer != fileTransfers_.end()) {
- transfer->second->bar_->setValue(percentageDone);
- }
+ FileTransferMap::iterator transfer = fileTransfers_.find(id);
+ if (transfer != fileTransfers_.end()) {
+ transfer->second->bar_->setValue(percentageDone);
+ }
}
void QtPlainChatView::setFileTransferStatus(std::string id, const ChatWindow::FileTransferState state, const std::string& msg)
{
- FileTransferMap::iterator transferIter = fileTransfers_.find(id);
- if (transferIter == fileTransfers_.end()) {
- return;
- }
-
- /* store the layout index so we can restore it to the same location */
- FileTransfer* oldTransfer = transferIter->second;
- const int layoutIndex = layout()->indexOf(oldTransfer->dialog_);
- layout()->removeWidget(oldTransfer->dialog_);
- const std::string &label = (!msg.empty() ? msg : oldTransfer->message_);
- FileTransfer* transfer = new FileTransfer(this, oldTransfer->senderIsSelf_, oldTransfer->ftId_, oldTransfer->filename_, state, oldTransfer->description_, label, false);
- fileTransfers_[oldTransfer->ftId_] = transfer; /* replace the transfer object for this file id */
- delete oldTransfer;
-
- /* insert the new dialog at the old position in the layout list */
- QBoxLayout* parentLayout = dynamic_cast<QBoxLayout*>(layout());
- assert(parentLayout);
- parentLayout->insertWidget(layoutIndex, transfer->dialog_);
-
- /* log the transfer end result as a system message */
- if (state == ChatWindow::Finished) {
- addSystemMessage(ChatWindow::ChatMessage("The file transfer completed successfully."), ChatWindow::DefaultDirection);
- } else if (state == ChatWindow::Canceled) {
- addSystemMessage(ChatWindow::ChatMessage("The file transfer was canceled."), ChatWindow::DefaultDirection);
- } else if (state == ChatWindow::FTFailed) {
- addSystemMessage(ChatWindow::ChatMessage("The file transfer failed."), ChatWindow::DefaultDirection);
- }
+ FileTransferMap::iterator transferIter = fileTransfers_.find(id);
+ if (transferIter == fileTransfers_.end()) {
+ return;
+ }
+
+ /* store the layout index so we can restore it to the same location */
+ FileTransfer* oldTransfer = transferIter->second;
+ const int layoutIndex = layout()->indexOf(oldTransfer->dialog_);
+ layout()->removeWidget(oldTransfer->dialog_);
+ const std::string &label = (!msg.empty() ? msg : oldTransfer->message_);
+ FileTransfer* transfer = new FileTransfer(this, oldTransfer->senderIsSelf_, oldTransfer->ftId_, oldTransfer->filename_, state, oldTransfer->description_, label, false);
+ fileTransfers_[oldTransfer->ftId_] = transfer; /* replace the transfer object for this file id */
+ delete oldTransfer;
+
+ /* insert the new dialog at the old position in the layout list */
+ QBoxLayout* parentLayout = dynamic_cast<QBoxLayout*>(layout());
+ assert(parentLayout);
+ parentLayout->insertWidget(layoutIndex, transfer->dialog_);
+
+ /* log the transfer end result as a system message */
+ if (state == ChatWindow::Finished) {
+ addSystemMessage(ChatWindow::ChatMessage("The file transfer completed successfully."), ChatWindow::DefaultDirection);
+ } else if (state == ChatWindow::Canceled) {
+ addSystemMessage(ChatWindow::ChatMessage("The file transfer was canceled."), ChatWindow::DefaultDirection);
+ } else if (state == ChatWindow::FTFailed) {
+ addSystemMessage(ChatWindow::ChatMessage("The file transfer failed."), ChatWindow::DefaultDirection);
+ }
}
void QtPlainChatView::addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& /*reason*/, const std::string& password, bool /*direct*/, bool isImpromptu, bool isContinuation)
{
- PopupDialog *invite = new PopupDialog(this);
+ PopupDialog *invite = new PopupDialog(this);
- QLabel* statusLabel = new QLabel;
- std::string msg = senderName + " has invited you to join " + jid.toString() + "...";
- statusLabel->setText(P2QSTRING(msg));
- invite->layout_->addWidget(statusLabel);
- invite->layout_->addWidget(new QLabel); /* padding */
+ QLabel* statusLabel = new QLabel;
+ std::string msg = senderName + " has invited you to join " + jid.toString() + "...";
+ statusLabel->setText(P2QSTRING(msg));
+ invite->layout_->addWidget(statusLabel);
+ invite->layout_->addWidget(new QLabel); /* padding */
- AcceptMUCInviteAction* accept = new AcceptMUCInviteAction(invite, "Accept", jid, senderName, password, isImpromptu, isContinuation);
- connect(accept, SIGNAL(clicked()), SLOT(acceptMUCInvite()));
- invite->layout_->addWidget(accept);
+ AcceptMUCInviteAction* accept = new AcceptMUCInviteAction(invite, "Accept", jid, senderName, password, isImpromptu, isContinuation);
+ connect(accept, SIGNAL(clicked()), SLOT(acceptMUCInvite()));
+ invite->layout_->addWidget(accept);
- AcceptMUCInviteAction* reject = new AcceptMUCInviteAction(invite, "Reject", jid, senderName, password, isImpromptu, isContinuation);
- connect(reject, SIGNAL(clicked()), SLOT(rejectMUCInvite()));
- invite->layout_->addWidget(reject);
- statusLabel->setText(P2QSTRING(msg));
+ AcceptMUCInviteAction* reject = new AcceptMUCInviteAction(invite, "Reject", jid, senderName, password, isImpromptu, isContinuation);
+ connect(reject, SIGNAL(clicked()), SLOT(rejectMUCInvite()));
+ invite->layout_->addWidget(reject);
+ statusLabel->setText(P2QSTRING(msg));
- layout()->addWidget(invite->dialog_);
+ layout()->addWidget(invite->dialog_);
- addSystemMessage(ChatWindow::ChatMessage(msg), ChatWindow::DefaultDirection);
+ addSystemMessage(ChatWindow::ChatMessage(msg), ChatWindow::DefaultDirection);
}
void QtPlainChatView::scrollToBottom()
{
- log_->ensureCursorVisible();
- log_->verticalScrollBar()->setValue(log_->verticalScrollBar()->maximum());
+ log_->ensureCursorVisible();
+ log_->verticalScrollBar()->setValue(log_->verticalScrollBar()->maximum());
}
void QtPlainChatView::fileTransferAccept()
{
- FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
- if (!action) {
- return;
- }
-
- FileTransferMap::iterator transferIter = fileTransfers_.find(action->id_);
- if (transferIter == fileTransfers_.end()) {
- return;
- }
-
- FileTransfer* transfer = transferIter->second;
-
- const std::string message = transfer->message_;
-
- if (transfer->senderIsSelf_) { /* if we are the sender, kick of the transfer */
- window_->onFileTransferStart(transfer->ftId_, transfer->description_);
- } else { /* ask the user where to save the file first */
- QString path = QFileDialog::getSaveFileName(this, tr("Save File"), P2QSTRING(transfer->filename_));
- if (path.isEmpty()) {
- fileTransferReject(); /* because the user did not select a desintation path */
- return;
- }
- window_->onFileTransferAccept(transfer->ftId_, Q2PSTRING(path));
- }
-
- setFileTransferStatus(transfer->ftId_, ChatWindow::Negotiating, message);
+ FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
+ if (!action) {
+ return;
+ }
+
+ FileTransferMap::iterator transferIter = fileTransfers_.find(action->id_);
+ if (transferIter == fileTransfers_.end()) {
+ return;
+ }
+
+ FileTransfer* transfer = transferIter->second;
+
+ const std::string message = transfer->message_;
+
+ if (transfer->senderIsSelf_) { /* if we are the sender, kick of the transfer */
+ window_->onFileTransferStart(transfer->ftId_, transfer->description_);
+ } else { /* ask the user where to save the file first */
+ QString path = QFileDialog::getSaveFileName(this, tr("Save File"), P2QSTRING(transfer->filename_));
+ if (path.isEmpty()) {
+ fileTransferReject(); /* because the user did not select a desintation path */
+ return;
+ }
+ window_->onFileTransferAccept(transfer->ftId_, Q2PSTRING(path));
+ }
+
+ setFileTransferStatus(transfer->ftId_, ChatWindow::Negotiating, message);
}
void QtPlainChatView::fileTransferReject()
{
- FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
- if (action) {
- window_->onFileTransferCancel(action->id_);
- fileTransferFinish();
- }
+ FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
+ if (action) {
+ window_->onFileTransferCancel(action->id_);
+ fileTransferFinish();
+ }
}
void QtPlainChatView::fileTransferFinish()
{
- FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
- if (action) {
- FileTransferMap::iterator transferIter = fileTransfers_.find(action->id_);
- if (transferIter != fileTransfers_.end()) {
- delete transferIter->second; /* cause the dialog to close */
- fileTransfers_.erase(transferIter);
- }
- }
+ FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
+ if (action) {
+ FileTransferMap::iterator transferIter = fileTransfers_.find(action->id_);
+ if (transferIter != fileTransfers_.end()) {
+ delete transferIter->second; /* cause the dialog to close */
+ fileTransfers_.erase(transferIter);
+ }
+ }
}
void QtPlainChatView::acceptMUCInvite()
{
- AcceptMUCInviteAction *action = dynamic_cast<AcceptMUCInviteAction*>(sender());
- if (action) {
- eventStream_->send(boost::make_shared<JoinMUCUIEvent>(action->jid_.toString(), action->password_, boost::optional<std::string>(), false, false, action->isImpromptu_, action->isContinuation_));
- delete action->parent_;
- }
+ AcceptMUCInviteAction *action = dynamic_cast<AcceptMUCInviteAction*>(sender());
+ if (action) {
+ eventStream_->send(boost::make_shared<JoinMUCUIEvent>(action->jid_.toString(), action->password_, boost::optional<std::string>(), false, false, action->isImpromptu_, action->isContinuation_));
+ delete action->parent_;
+ }
}
void QtPlainChatView::rejectMUCInvite()
{
- AcceptMUCInviteAction *action = dynamic_cast<AcceptMUCInviteAction*>(sender());
- if (action) {
- /* NOTE: no action required to reject an invite? */
- delete action->parent_;
- }
+ AcceptMUCInviteAction *action = dynamic_cast<AcceptMUCInviteAction*>(sender());
+ if (action) {
+ /* NOTE: no action required to reject an invite? */
+ delete action->parent_;
+ }
}
QtPlainChatView::FileTransfer::FileTransfer(QtPlainChatView* parent, bool senderIsSelf, const std::string& ftId, const std::string& filename, const ChatWindow::FileTransferState state, const std::string &desc, const std::string& msg, bool initializing)
: PopupDialog(parent), bar_(0), senderIsSelf_(senderIsSelf), ftId_(ftId), filename_(filename), description_(desc), message_(msg), initializing_(initializing)
{
- QHBoxLayout* layout = new QHBoxLayout;
- QLabel* statusLabel = new QLabel;
- layout_->addWidget(statusLabel);
- layout_->addWidget(new QLabel); /* padding */
-
- if (initializing_) {
- FileTransfer::Action* accept = new FileTransfer::Action(senderIsSelf?"Confirm":"Accept", ftId);
- parent->connect(accept, SIGNAL(clicked()), SLOT(fileTransferAccept()));
- layout_->addWidget(accept);
- FileTransfer::Action* reject = new FileTransfer::Action(senderIsSelf?"Cancel":"Reject", ftId);
- parent->connect(reject, SIGNAL(clicked()), SLOT(fileTransferReject()));
- layout_->addWidget(reject);
- statusLabel->setText(P2QSTRING(msg));
- return;
- }
-
- std::string status = msg;
-
- switch (state) {
- case ChatWindow::Initialisation: {
- status = "Preparing to send <i>"+ filename + "</i>...";
- FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
- parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
- layout_->addWidget(cancel);
- break;
- }
- case ChatWindow::WaitingForAccept: {
- status = "Waiting for user to accept <i>" + filename + "</i>...";
- FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
- parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
- layout_->addWidget(cancel);
- break;
- }
- case ChatWindow::Negotiating: {
- status = "Preparing to transfer <i>" + filename + "</i>...";
- FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
- parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
- layout_->addWidget(cancel);
- break;
- }
- case ChatWindow::Transferring: {
- status = "Transferring <i>" + filename + "</i>...";
- bar_ = new QProgressBar;
- bar_->setRange(0, 100);
- bar_->setValue(0);
- layout->addWidget(bar_);
- FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
- parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
- layout_->addWidget(cancel);
- break;
- }
- case ChatWindow::Canceled: {
- status = "File <i>" + filename + "</i> was canceled.";
- FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
- parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
- layout_->addWidget(finish);
- break;
- }
- case ChatWindow::Finished: {
- status = "File <i>" + filename + "</i> was transfered successfully.";
- FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
- parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
- layout_->addWidget(finish);
- break;
- }
- case ChatWindow::FTFailed: {
- status = "File transfer failed: <i>" + filename + "</i>";
- FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
- parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
- layout_->addWidget(finish);
- break;
- }
- }
-
- statusLabel->setText(P2QSTRING(status));
+ QHBoxLayout* layout = new QHBoxLayout;
+ QLabel* statusLabel = new QLabel;
+ layout_->addWidget(statusLabel);
+ layout_->addWidget(new QLabel); /* padding */
+
+ if (initializing_) {
+ FileTransfer::Action* accept = new FileTransfer::Action(senderIsSelf?"Confirm":"Accept", ftId);
+ parent->connect(accept, SIGNAL(clicked()), SLOT(fileTransferAccept()));
+ layout_->addWidget(accept);
+ FileTransfer::Action* reject = new FileTransfer::Action(senderIsSelf?"Cancel":"Reject", ftId);
+ parent->connect(reject, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(reject);
+ statusLabel->setText(P2QSTRING(msg));
+ return;
+ }
+
+ std::string status = msg;
+
+ switch (state) {
+ case ChatWindow::Initialisation: {
+ status = "Preparing to send <i>"+ filename + "</i>...";
+ FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
+ parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(cancel);
+ break;
+ }
+ case ChatWindow::WaitingForAccept: {
+ status = "Waiting for user to accept <i>" + filename + "</i>...";
+ FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
+ parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(cancel);
+ break;
+ }
+ case ChatWindow::Negotiating: {
+ status = "Preparing to transfer <i>" + filename + "</i>...";
+ FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
+ parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(cancel);
+ break;
+ }
+ case ChatWindow::Transferring: {
+ status = "Transferring <i>" + filename + "</i>...";
+ bar_ = new QProgressBar;
+ bar_->setRange(0, 100);
+ bar_->setValue(0);
+ layout->addWidget(bar_);
+ FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
+ parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(cancel);
+ break;
+ }
+ case ChatWindow::Canceled: {
+ status = "File <i>" + filename + "</i> was canceled.";
+ FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
+ parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
+ layout_->addWidget(finish);
+ break;
+ }
+ case ChatWindow::Finished: {
+ status = "File <i>" + filename + "</i> was transfered successfully.";
+ FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
+ parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
+ layout_->addWidget(finish);
+ break;
+ }
+ case ChatWindow::FTFailed: {
+ status = "File transfer failed: <i>" + filename + "</i>";
+ FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
+ parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
+ layout_->addWidget(finish);
+ break;
+ }
+ }
+
+ statusLabel->setText(P2QSTRING(status));
}
void QtPlainChatView::LogTextEdit::contextMenuEvent(QContextMenuEvent *event)
{
- QMenu *menu = createStandardContextMenu();
- menu->exec(event->globalPos());
- delete menu;
+ QMenu *menu = createStandardContextMenu();
+ menu->exec(event->globalPos());
+ delete menu;
}
}
diff --git a/Swift/QtUI/QtPlainChatView.h b/Swift/QtUI/QtPlainChatView.h
index fc293ff..cd6ab7e 100644
--- a/Swift/QtUI/QtPlainChatView.h
+++ b/Swift/QtUI/QtPlainChatView.h
@@ -23,112 +23,112 @@ class QTextEdit;
class QProgressBar;
namespace Swift {
- class HighlightAction;
- class SecurityLabel;
-
- class QtPlainChatView : public QtChatView {
- Q_OBJECT
- public:
- QtPlainChatView(QtChatWindow *window, UIEventStream* eventStream);
- virtual ~QtPlainChatView();
-
- /** Add message to window.
- * @return id of added message (for acks).
- */
- virtual std::string addMessage(const ChatWindow::ChatMessage& /*message*/, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/);
- /** Adds action to window.
- * @return id of added message (for acks);
- */
- virtual std::string addAction(const ChatWindow::ChatMessage& /*message*/, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/);
-
- virtual std::string addSystemMessage(const ChatWindow::ChatMessage& /*message*/, ChatWindow::Direction /*direction*/);
- virtual void addPresenceMessage(const ChatWindow::ChatMessage& /*message*/, ChatWindow::Direction /*direction*/);
- virtual void addErrorMessage(const ChatWindow::ChatMessage& /*message*/);
-
- virtual void replaceMessage(const ChatWindow::ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/);
- virtual void replaceWithAction(const ChatWindow::ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/);
- virtual void replaceLastMessage(const ChatWindow::ChatMessage& /*message*/, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/);
- virtual void replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/);
- virtual void setAckState(const std::string& /*id*/, ChatWindow::AckState /*state*/);
-
- virtual std::string addFileTransfer(const std::string& /*senderName*/, bool /*senderIsSelf*/, const std::string& /*filename*/, const boost::uintmax_t /*sizeInBytes*/, const std::string& /*description*/);
- virtual void setFileTransferProgress(std::string, const int /*percentageDone*/);
- virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState /*state*/, const std::string& /*msg*/ = "");
- virtual void addMUCInvitation(const std::string& /*senderName*/, const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/, bool /*direct*/, bool /*isImpromptu*/, bool /*isContinuation*/);
- virtual std::string addWhiteboardRequest(const QString& /*contact*/, bool /*senderIsSelf*/) {return "";};
- virtual void setWhiteboardSessionStatus(const std::string& /*id*/, const ChatWindow::WhiteboardSessionState /*state*/) {};
- virtual void setMessageReceiptState(const std::string& /*id*/, ChatWindow::ReceiptState /*state*/) {};
-
- virtual void showEmoticons(bool /*show*/) {};
- virtual void addLastSeenLine() {};
-
- public slots:
- virtual void resizeFont(int /*fontSizeSteps*/) {};
- virtual void scrollToBottom();
- virtual void handleKeyPressEvent(QKeyEvent* /*event*/) {};
- virtual void fileTransferAccept();
- virtual void fileTransferReject();
- virtual void fileTransferFinish();
- virtual void acceptMUCInvite();
- virtual void rejectMUCInvite();
-
- private:
- struct PopupDialog {
- PopupDialog(QtPlainChatView* parent) {
- dialog_ = new QFrame(parent);
- dialog_->setFrameShape(QFrame::Panel);
- dialog_->setFrameShadow(QFrame::Raised);
- layout_ = new QHBoxLayout;
- dialog_->setLayout(layout_);
- }
- virtual ~PopupDialog() {
- delete dialog_;
- }
- QFrame* dialog_;
- QHBoxLayout* layout_;
- };
-
- struct AcceptMUCInviteAction : public QPushButton {
- AcceptMUCInviteAction(PopupDialog* parent, const std::string& text, const JID& jid, const std::string& senderName, const std::string& password, bool isImpromptu, bool isContinuation)
- : QPushButton(P2QSTRING(text)), parent_(parent), jid_(jid), senderName_(senderName), password_(password), isImpromptu_(isImpromptu), isContinuation_(isContinuation) {}
- PopupDialog *parent_;
- JID jid_;
- std::string senderName_;
- std::string password_;
- bool isImpromptu_;
- bool isContinuation_;
- };
-
- struct FileTransfer : public PopupDialog {
- struct Action : QPushButton {
- Action(const std::string& text, const std::string& id)
- : QPushButton(P2QSTRING(text)), id_(id) {}
- std::string id_;
- };
- FileTransfer(QtPlainChatView* parent, bool senderIsSelf, const std::string& ftId, const std::string& filename, const ChatWindow::FileTransferState state, const std::string& desc, const std::string& msg, bool initializing);
- QProgressBar* bar_;
- bool senderIsSelf_;
- std::string ftId_;
- std::string filename_;
- std::string description_;
- std::string message_;
- bool initializing_;
- };
-
- class LogTextEdit : public QTextEdit {
- public:
- LogTextEdit(QWidget* parent) : QTextEdit(parent) {}
- virtual ~LogTextEdit() {}
- virtual void contextMenuEvent(QContextMenuEvent *event);
- };
-
- typedef std::map<std::string, FileTransfer*> FileTransferMap;
- QtChatWindow* window_;
- UIEventStream* eventStream_;
- LogTextEdit* log_;
- FileTransferMap fileTransfers_;
- std::map<std::string, boost::shared_ptr<SecurityLabel> > lastMessageLabel_;
- int idGenerator_;
-
- };
+ class HighlightAction;
+ class SecurityLabel;
+
+ class QtPlainChatView : public QtChatView {
+ Q_OBJECT
+ public:
+ QtPlainChatView(QtChatWindow *window, UIEventStream* eventStream);
+ virtual ~QtPlainChatView();
+
+ /** Add message to window.
+ * @return id of added message (for acks).
+ */
+ virtual std::string addMessage(const ChatWindow::ChatMessage& /*message*/, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/);
+ /** Adds action to window.
+ * @return id of added message (for acks);
+ */
+ virtual std::string addAction(const ChatWindow::ChatMessage& /*message*/, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/);
+
+ virtual std::string addSystemMessage(const ChatWindow::ChatMessage& /*message*/, ChatWindow::Direction /*direction*/);
+ virtual void addPresenceMessage(const ChatWindow::ChatMessage& /*message*/, ChatWindow::Direction /*direction*/);
+ virtual void addErrorMessage(const ChatWindow::ChatMessage& /*message*/);
+
+ virtual void replaceMessage(const ChatWindow::ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/);
+ virtual void replaceWithAction(const ChatWindow::ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/);
+ virtual void replaceLastMessage(const ChatWindow::ChatMessage& /*message*/, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/);
+ virtual void replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/);
+ virtual void setAckState(const std::string& /*id*/, ChatWindow::AckState /*state*/);
+
+ virtual std::string addFileTransfer(const std::string& /*senderName*/, bool /*senderIsSelf*/, const std::string& /*filename*/, const boost::uintmax_t /*sizeInBytes*/, const std::string& /*description*/);
+ virtual void setFileTransferProgress(std::string, const int /*percentageDone*/);
+ virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState /*state*/, const std::string& /*msg*/ = "");
+ virtual void addMUCInvitation(const std::string& /*senderName*/, const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/, bool /*direct*/, bool /*isImpromptu*/, bool /*isContinuation*/);
+ virtual std::string addWhiteboardRequest(const QString& /*contact*/, bool /*senderIsSelf*/) {return "";};
+ virtual void setWhiteboardSessionStatus(const std::string& /*id*/, const ChatWindow::WhiteboardSessionState /*state*/) {};
+ virtual void setMessageReceiptState(const std::string& /*id*/, ChatWindow::ReceiptState /*state*/) {};
+
+ virtual void showEmoticons(bool /*show*/) {};
+ virtual void addLastSeenLine() {};
+
+ public slots:
+ virtual void resizeFont(int /*fontSizeSteps*/) {};
+ virtual void scrollToBottom();
+ virtual void handleKeyPressEvent(QKeyEvent* /*event*/) {};
+ virtual void fileTransferAccept();
+ virtual void fileTransferReject();
+ virtual void fileTransferFinish();
+ virtual void acceptMUCInvite();
+ virtual void rejectMUCInvite();
+
+ private:
+ struct PopupDialog {
+ PopupDialog(QtPlainChatView* parent) {
+ dialog_ = new QFrame(parent);
+ dialog_->setFrameShape(QFrame::Panel);
+ dialog_->setFrameShadow(QFrame::Raised);
+ layout_ = new QHBoxLayout;
+ dialog_->setLayout(layout_);
+ }
+ virtual ~PopupDialog() {
+ delete dialog_;
+ }
+ QFrame* dialog_;
+ QHBoxLayout* layout_;
+ };
+
+ struct AcceptMUCInviteAction : public QPushButton {
+ AcceptMUCInviteAction(PopupDialog* parent, const std::string& text, const JID& jid, const std::string& senderName, const std::string& password, bool isImpromptu, bool isContinuation)
+ : QPushButton(P2QSTRING(text)), parent_(parent), jid_(jid), senderName_(senderName), password_(password), isImpromptu_(isImpromptu), isContinuation_(isContinuation) {}
+ PopupDialog *parent_;
+ JID jid_;
+ std::string senderName_;
+ std::string password_;
+ bool isImpromptu_;
+ bool isContinuation_;
+ };
+
+ struct FileTransfer : public PopupDialog {
+ struct Action : QPushButton {
+ Action(const std::string& text, const std::string& id)
+ : QPushButton(P2QSTRING(text)), id_(id) {}
+ std::string id_;
+ };
+ FileTransfer(QtPlainChatView* parent, bool senderIsSelf, const std::string& ftId, const std::string& filename, const ChatWindow::FileTransferState state, const std::string& desc, const std::string& msg, bool initializing);
+ QProgressBar* bar_;
+ bool senderIsSelf_;
+ std::string ftId_;
+ std::string filename_;
+ std::string description_;
+ std::string message_;
+ bool initializing_;
+ };
+
+ class LogTextEdit : public QTextEdit {
+ public:
+ LogTextEdit(QWidget* parent) : QTextEdit(parent) {}
+ virtual ~LogTextEdit() {}
+ virtual void contextMenuEvent(QContextMenuEvent *event);
+ };
+
+ typedef std::map<std::string, FileTransfer*> FileTransferMap;
+ QtChatWindow* window_;
+ UIEventStream* eventStream_;
+ LogTextEdit* log_;
+ FileTransferMap fileTransfers_;
+ std::map<std::string, boost::shared_ptr<SecurityLabel> > lastMessageLabel_;
+ int idGenerator_;
+
+ };
}
diff --git a/Swift/QtUI/QtProfileWindow.cpp b/Swift/QtUI/QtProfileWindow.cpp
index 8b4b044..461ea38 100644
--- a/Swift/QtUI/QtProfileWindow.cpp
+++ b/Swift/QtUI/QtProfileWindow.cpp
@@ -25,143 +25,143 @@
namespace Swift {
QtProfileWindow::QtProfileWindow() :
- QWidget(),
- ui(new Ui::QtProfileWindow) {
- ui->setupUi(this);
+ QWidget(),
+ ui(new Ui::QtProfileWindow) {
+ ui->setupUi(this);
- ui->statusLabel->setText(tr("Retrieving profile information for this user."));
- ui->statusLabel->setVisible(false);
+ ui->statusLabel->setText(tr("Retrieving profile information for this user."));
+ ui->statusLabel->setVisible(false);
- ui->emptyLabel->setText(tr("No profile information is available for this user."));
- ui->emptyLabel->setVisible(false);
+ ui->emptyLabel->setText(tr("No profile information is available for this user."));
+ ui->emptyLabel->setVisible(false);
- new QShortcut(QKeySequence::Close, this, SLOT(close()));
- ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
- connect(ui->savePushButton, SIGNAL(clicked()), SLOT(handleSave()));
- setEditable(false);
- setAttribute(Qt::WA_DeleteOnClose);
- setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
+ new QShortcut(QKeySequence::Close, this, SLOT(close()));
+ ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
+ connect(ui->savePushButton, SIGNAL(clicked()), SLOT(handleSave()));
+ setEditable(false);
+ setAttribute(Qt::WA_DeleteOnClose);
+ setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
- adjustSizeTimer.setSingleShot(true);
- connect(&adjustSizeTimer, SIGNAL(timeout()), SLOT(handleAdjustSizeTimeout()));
+ adjustSizeTimer.setSingleShot(true);
+ connect(&adjustSizeTimer, SIGNAL(timeout()), SLOT(handleAdjustSizeTimeout()));
}
QtProfileWindow::~QtProfileWindow() {
- delete ui;
+ delete ui;
}
void QtProfileWindow::setJID(const JID& jid) {
- this->jid = jid;
- updateTitle();
+ this->jid = jid;
+ updateTitle();
}
void QtProfileWindow::setVCard(VCard::ref vcard) {
- ui->vcard->setVCard(vcard);
- if (vcard->isEmpty()) {
- ui->vcard->setVisible(false);
- ui->emptyLabel->setVisible(true);
- } else {
- ui->vcard->setVisible(true);
- ui->emptyLabel->setVisible(false);
- }
- updateWindowSize();
+ ui->vcard->setVCard(vcard);
+ if (vcard->isEmpty()) {
+ ui->vcard->setVisible(false);
+ ui->emptyLabel->setVisible(true);
+ } else {
+ ui->vcard->setVisible(true);
+ ui->emptyLabel->setVisible(false);
+ }
+ updateWindowSize();
}
void QtProfileWindow::setEnabled(bool b) {
- ui->vcard->setEnabled(b);
- ui->savePushButton->setEnabled(b);
+ ui->vcard->setEnabled(b);
+ ui->savePushButton->setEnabled(b);
}
void QtProfileWindow::setEditable(bool b) {
- ui->throbberLabel->setVisible(b);
- ui->errorLabel->setVisible(b);
- ui->savePushButton->setVisible(b);
- ui->vcard->setEditable(b);
- updateTitle();
- updateWindowSize();
+ ui->throbberLabel->setVisible(b);
+ ui->errorLabel->setVisible(b);
+ ui->savePushButton->setVisible(b);
+ ui->vcard->setEditable(b);
+ updateTitle();
+ updateWindowSize();
}
void QtProfileWindow::setProcessing(bool processing) {
- if (processing) {
- ui->throbberLabel->movie()->start();
- ui->throbberLabel->show();
- ui->statusLabel->setVisible(true);
- ui->vcard->setVisible(false);
- }
- else {
- ui->throbberLabel->hide();
- ui->throbberLabel->movie()->stop();
- ui->statusLabel->setVisible(false);
- ui->vcard->setVisible(true);
- }
+ if (processing) {
+ ui->throbberLabel->movie()->start();
+ ui->throbberLabel->show();
+ ui->statusLabel->setVisible(true);
+ ui->vcard->setVisible(false);
+ }
+ else {
+ ui->throbberLabel->hide();
+ ui->throbberLabel->movie()->stop();
+ ui->statusLabel->setVisible(false);
+ ui->vcard->setVisible(true);
+ }
}
void QtProfileWindow::setError(const std::string& error) {
- if (!error.empty()) {
- ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
- }
- else {
- ui->errorLabel->setText("");
- }
+ if (!error.empty()) {
+ ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
+ }
+ else {
+ ui->errorLabel->setText("");
+ }
}
void QtProfileWindow::show() {
- QWidget::showNormal();
- QWidget::activateWindow();
- QWidget::raise();
+ QWidget::showNormal();
+ QWidget::activateWindow();
+ QWidget::raise();
}
void QtProfileWindow::hide() {
- QWidget::hide();
+ QWidget::hide();
}
QSize QtProfileWindow::sizeHint() const {
- return QWidget::sizeHint();
+ return QWidget::sizeHint();
}
void QtProfileWindow::updateTitle() {
- QString jidString;
- if (jid.isValid()) {
- jidString = QString(" ( %1 )").arg(P2QSTRING(jid.toString()));
- }
+ QString jidString;
+ if (jid.isValid()) {
+ jidString = QString(" ( %1 )").arg(P2QSTRING(jid.toString()));
+ }
- if (ui->vcard->isEditable()) {
- setWindowTitle(tr("Edit Profile") + jidString);
- } else {
- setWindowTitle(tr("Show Profile") + jidString);
- }
+ if (ui->vcard->isEditable()) {
+ setWindowTitle(tr("Edit Profile") + jidString);
+ } else {
+ setWindowTitle(tr("Show Profile") + jidString);
+ }
}
void QtProfileWindow::updateWindowSize() {
- // Delay resizing to the end of the event loop, because Qt calculates the correct layout asynchronously.
- // Qt will post LayoutRequests for widgets on the event loop on show and widgets will recaluclate their
- // layout as they process these events.
- // We use the complete and correct size hint from the freshly calculated layout by delaying execution of
- // the resize code to the end of Qt's event loop.
- if (!adjustSizeTimer.isActive()) {
- adjustSizeTimer.start(0);
- }
+ // Delay resizing to the end of the event loop, because Qt calculates the correct layout asynchronously.
+ // Qt will post LayoutRequests for widgets on the event loop on show and widgets will recaluclate their
+ // layout as they process these events.
+ // We use the complete and correct size hint from the freshly calculated layout by delaying execution of
+ // the resize code to the end of Qt's event loop.
+ if (!adjustSizeTimer.isActive()) {
+ adjustSizeTimer.start(0);
+ }
}
void QtProfileWindow::closeEvent(QCloseEvent* event) {
- event->accept();
- onWindowAboutToBeClosed(jid);
+ event->accept();
+ onWindowAboutToBeClosed(jid);
}
void QtProfileWindow::handleSave() {
- onVCardChangeRequest(ui->vcard->getVCard());
+ onVCardChangeRequest(ui->vcard->getVCard());
}
void QtProfileWindow::handleAdjustSizeTimeout() {
- // Force recaluclation of all layout geometry in children widgets.
- // This is required on Windows to have the correct size even on first show.
- QList<QWidget *> children = findChildren<QWidget*>();
- foreach(QWidget* child, children) {
- child->updateGeometry();
- }
-
- updateGeometry();
- adjustSize();
+ // Force recaluclation of all layout geometry in children widgets.
+ // This is required on Windows to have the correct size even on first show.
+ QList<QWidget *> children = findChildren<QWidget*>();
+ foreach(QWidget* child, children) {
+ child->updateGeometry();
+ }
+
+ updateGeometry();
+ adjustSize();
}
}
diff --git a/Swift/QtUI/QtProfileWindow.h b/Swift/QtUI/QtProfileWindow.h
index 0821444..7315807 100644
--- a/Swift/QtUI/QtProfileWindow.h
+++ b/Swift/QtUI/QtProfileWindow.h
@@ -20,44 +20,44 @@
#include <Swift/Controllers/UIInterfaces/ProfileWindow.h>
namespace Ui {
- class QtProfileWindow;
+ class QtProfileWindow;
}
namespace Swift {
class QtProfileWindow : public QWidget, public ProfileWindow {
- Q_OBJECT
+ Q_OBJECT
- public:
- QtProfileWindow();
- virtual ~QtProfileWindow();
+ public:
+ QtProfileWindow();
+ virtual ~QtProfileWindow();
- virtual void setJID(const JID& jid);
- virtual void setVCard(VCard::ref vcard);
+ virtual void setJID(const JID& jid);
+ virtual void setVCard(VCard::ref vcard);
- virtual void setEnabled(bool b);
- virtual void setProcessing(bool processing);
- virtual void setError(const std::string& error);
- virtual void setEditable(bool b);
+ virtual void setEnabled(bool b);
+ virtual void setProcessing(bool processing);
+ virtual void setError(const std::string& error);
+ virtual void setEditable(bool b);
- virtual void show();
- virtual void hide();
+ virtual void show();
+ virtual void hide();
- virtual QSize sizeHint() const;
+ virtual QSize sizeHint() const;
- private:
- void updateTitle();
- void updateWindowSize();
- virtual void closeEvent(QCloseEvent* event);
+ private:
+ void updateTitle();
+ void updateWindowSize();
+ virtual void closeEvent(QCloseEvent* event);
- private slots:
- void handleSave();
- void handleAdjustSizeTimeout();
+ private slots:
+ void handleSave();
+ void handleAdjustSizeTimeout();
- private:
- Ui::QtProfileWindow* ui;
- JID jid;
- QTimer adjustSizeTimer;
+ private:
+ Ui::QtProfileWindow* ui;
+ JID jid;
+ QTimer adjustSizeTimer;
};
}
diff --git a/Swift/QtUI/QtResourceHelper.cpp b/Swift/QtUI/QtResourceHelper.cpp
index f76c438..a802b19 100644
--- a/Swift/QtUI/QtResourceHelper.cpp
+++ b/Swift/QtUI/QtResourceHelper.cpp
@@ -9,16 +9,16 @@
namespace Swift {
QString statusShowTypeToIconPath(StatusShow::Type type) {
- QString iconString;
- switch (type) {
- case StatusShow::Online: iconString = "online";break;
- case StatusShow::Away: iconString = "away";break;
- case StatusShow::XA: iconString = "away";break;
- case StatusShow::FFC: iconString = "online";break;
- case StatusShow::DND: iconString = "dnd";break;
- case StatusShow::None: iconString = "offline";break;
- }
- return QString(":/icons/%1.png").arg(iconString);
+ QString iconString;
+ switch (type) {
+ case StatusShow::Online: iconString = "online";break;
+ case StatusShow::Away: iconString = "away";break;
+ case StatusShow::XA: iconString = "away";break;
+ case StatusShow::FFC: iconString = "online";break;
+ case StatusShow::DND: iconString = "dnd";break;
+ case StatusShow::None: iconString = "offline";break;
+ }
+ return QString(":/icons/%1.png").arg(iconString);
}
}
diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp
index 4783a64..f8a4cdb 100644
--- a/Swift/QtUI/QtRosterHeader.cpp
+++ b/Swift/QtUI/QtRosterHeader.cpp
@@ -28,112 +28,112 @@
namespace Swift {
QtRosterHeader::QtRosterHeader(SettingsProvider* settings, StatusCache* statusCache, QWidget* parent) : QWidget(parent), statusEdit_(NULL) {
- QHBoxLayout* topLayout = new QHBoxLayout();
- topLayout->setSpacing(3);
- topLayout->setContentsMargins(4,4,4,4);
- setLayout(topLayout);
- setMinimumHeight(50);
- setMaximumHeight(50);
-
- avatarLabel_ = new QtClickableLabel(this);
- avatarLabel_->setMinimumSize(avatarSize_, avatarSize_);
- avatarLabel_->setMaximumSize(avatarSize_, avatarSize_);
- avatarLabel_->setAlignment(Qt::AlignCenter);
- setAvatar(":/icons/avatar.png");
- avatarLabel_->setScaledContents(false);
- topLayout->addWidget(avatarLabel_);
- connect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest()));
-
- QVBoxLayout* rightLayout = new QVBoxLayout();
- rightLayout->setSpacing(4);
- rightLayout->setContentsMargins(4,0,0,0);
- topLayout->addLayout(rightLayout);
-
- QHBoxLayout* nameAndSecurityLayout = new QHBoxLayout();
- nameAndSecurityLayout->setContentsMargins(4,0,0,0);
-
- nameWidget_ = new QtNameWidget(settings, this);
- connect(nameWidget_, SIGNAL(onChangeNickRequest()), this, SIGNAL(onEditProfileRequest()));
- nameAndSecurityLayout->addWidget(nameWidget_);
-
- securityInfoButton_ = new QToolButton(this);
- securityInfoButton_->setStyleSheet("QToolButton { border: none; } QToolButton:hover { border: 1px solid #bebebe; } QToolButton:pressed { border: 1px solid #757575; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #777777, stop: 1 #d4d4d4);}");
- //securityInfoButton_->setAutoRaise(true);
- securityInfoButton_->setIcon(QIcon(":/icons/lock.png"));
- securityInfoButton_->setToolTip(tr("Connection is secured"));
- connect(securityInfoButton_, SIGNAL(clicked()), this, SIGNAL(onShowCertificateInfo()));
- nameAndSecurityLayout->addWidget(securityInfoButton_);
-
- rightLayout->addLayout(nameAndSecurityLayout);
-
- statusWidget_ = new QtStatusWidget(statusCache, this);
- connect(statusWidget_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleChangeStatusRequest(StatusShow::Type, const QString&)));
- rightLayout->addWidget(statusWidget_);
-
- show();
+ QHBoxLayout* topLayout = new QHBoxLayout();
+ topLayout->setSpacing(3);
+ topLayout->setContentsMargins(4,4,4,4);
+ setLayout(topLayout);
+ setMinimumHeight(50);
+ setMaximumHeight(50);
+
+ avatarLabel_ = new QtClickableLabel(this);
+ avatarLabel_->setMinimumSize(avatarSize_, avatarSize_);
+ avatarLabel_->setMaximumSize(avatarSize_, avatarSize_);
+ avatarLabel_->setAlignment(Qt::AlignCenter);
+ setAvatar(":/icons/avatar.png");
+ avatarLabel_->setScaledContents(false);
+ topLayout->addWidget(avatarLabel_);
+ connect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest()));
+
+ QVBoxLayout* rightLayout = new QVBoxLayout();
+ rightLayout->setSpacing(4);
+ rightLayout->setContentsMargins(4,0,0,0);
+ topLayout->addLayout(rightLayout);
+
+ QHBoxLayout* nameAndSecurityLayout = new QHBoxLayout();
+ nameAndSecurityLayout->setContentsMargins(4,0,0,0);
+
+ nameWidget_ = new QtNameWidget(settings, this);
+ connect(nameWidget_, SIGNAL(onChangeNickRequest()), this, SIGNAL(onEditProfileRequest()));
+ nameAndSecurityLayout->addWidget(nameWidget_);
+
+ securityInfoButton_ = new QToolButton(this);
+ securityInfoButton_->setStyleSheet("QToolButton { border: none; } QToolButton:hover { border: 1px solid #bebebe; } QToolButton:pressed { border: 1px solid #757575; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #777777, stop: 1 #d4d4d4);}");
+ //securityInfoButton_->setAutoRaise(true);
+ securityInfoButton_->setIcon(QIcon(":/icons/lock.png"));
+ securityInfoButton_->setToolTip(tr("Connection is secured"));
+ connect(securityInfoButton_, SIGNAL(clicked()), this, SIGNAL(onShowCertificateInfo()));
+ nameAndSecurityLayout->addWidget(securityInfoButton_);
+
+ rightLayout->addLayout(nameAndSecurityLayout);
+
+ statusWidget_ = new QtStatusWidget(statusCache, this);
+ connect(statusWidget_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleChangeStatusRequest(StatusShow::Type, const QString&)));
+ rightLayout->addWidget(statusWidget_);
+
+ show();
}
void QtRosterHeader::handleChangeStatusRequest(StatusShow::Type type, const QString& text) {
- emit onChangeStatusRequest(type, text);
+ emit onChangeStatusRequest(type, text);
}
void QtRosterHeader::setStatusText(const QString& statusMessage) {
- statusWidget_->setStatusText(statusMessage);
+ statusWidget_->setStatusText(statusMessage);
}
void QtRosterHeader::setStatusType(StatusShow::Type type) {
- statusWidget_->setStatusType(type);
- if (type == StatusShow::None) {
- nameWidget_->setOnline(false);
- disconnect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest()));
- }
- else {
- nameWidget_->setOnline(true);
- connect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest()), Qt::UniqueConnection);
- }
+ statusWidget_->setStatusType(type);
+ if (type == StatusShow::None) {
+ nameWidget_->setOnline(false);
+ disconnect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest()));
+ }
+ else {
+ nameWidget_->setOnline(true);
+ connect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest()), Qt::UniqueConnection);
+ }
}
void QtRosterHeader::setConnecting() {
- statusWidget_->setConnecting();
+ statusWidget_->setConnecting();
}
void QtRosterHeader::setStreamEncryptionStatus(bool tlsInPlace) {
- securityInfoButton_->setVisible(tlsInPlace);
+ securityInfoButton_->setVisible(tlsInPlace);
}
bool QtRosterHeader::event(QEvent* event) {
- if (event->type() == QEvent::ToolTip) {
- QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
- QtScaledAvatarCache scaledAvatarCache(avatarSize_);
- QString text = RosterTooltip::buildDetailedTooltip(contact_.get(), &scaledAvatarCache);
- QToolTip::showText(helpEvent->globalPos(), text);
- return true;
- }
- return QWidget::event(event);
+ if (event->type() == QEvent::ToolTip) {
+ QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
+ QtScaledAvatarCache scaledAvatarCache(avatarSize_);
+ QString text = RosterTooltip::buildDetailedTooltip(contact_.get(), &scaledAvatarCache);
+ QToolTip::showText(helpEvent->globalPos(), text);
+ return true;
+ }
+ return QWidget::event(event);
}
void QtRosterHeader::setAvatar(const QString& path) {
- QString scaledAvatarPath = QtScaledAvatarCache(avatarSize_).getScaledAvatarPath(path);
- QPixmap avatar;
- if (QFileInfo(scaledAvatarPath).exists()) {
- avatar.load(scaledAvatarPath);
- }
- else {
- avatar = QPixmap(":/icons/avatar.png").scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- }
- avatarLabel_->setPixmap(avatar);
+ QString scaledAvatarPath = QtScaledAvatarCache(avatarSize_).getScaledAvatarPath(path);
+ QPixmap avatar;
+ if (QFileInfo(scaledAvatarPath).exists()) {
+ avatar.load(scaledAvatarPath);
+ }
+ else {
+ avatar = QPixmap(":/icons/avatar.png").scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ }
+ avatarLabel_->setPixmap(avatar);
}
void QtRosterHeader::setNick(const QString& nick) {
- nameWidget_->setNick(nick);
+ nameWidget_->setNick(nick);
}
void QtRosterHeader::setContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) {
- contact_ = contact;
+ contact_ = contact;
}
void QtRosterHeader::setJID(const QString& jid) {
- nameWidget_->setJID(jid);
+ nameWidget_->setJID(jid);
}
diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h
index 49c3338..b556504 100644
--- a/Swift/QtUI/QtRosterHeader.h
+++ b/Swift/QtUI/QtRosterHeader.h
@@ -24,43 +24,43 @@
class QHBoxLayout;
namespace Swift {
- class QtClickableLabel;
- class QtStatusWidget;
- class QtNameWidget;
- class SettingsProvider;
- class StatusCache;
-
- class QtRosterHeader : public QWidget {
- Q_OBJECT
- public:
- QtRosterHeader(SettingsProvider* settings, StatusCache* statusCache, QWidget* parent = NULL);
- void setAvatar(const QString& path);
+ class QtClickableLabel;
+ class QtStatusWidget;
+ class QtNameWidget;
+ class SettingsProvider;
+ class StatusCache;
- void setJID(const QString& jid);
- void setNick(const QString& nick);
- void setContactRosterItem(boost::shared_ptr<ContactRosterItem> contact);
+ class QtRosterHeader : public QWidget {
+ Q_OBJECT
+ public:
+ QtRosterHeader(SettingsProvider* settings, StatusCache* statusCache, QWidget* parent = NULL);
+ void setAvatar(const QString& path);
- void setStatusText(const QString& statusMessage);
- void setStatusType(StatusShow::Type type);
- void setConnecting();
- void setStreamEncryptionStatus(bool tlsInPlace);
- private:
- bool event(QEvent* event);
- signals:
- void onChangeStatusRequest(StatusShow::Type showType, const QString &statusMessage);
- void onEditProfileRequest();
- void onShowCertificateInfo();
+ void setJID(const QString& jid);
+ void setNick(const QString& nick);
+ void setContactRosterItem(boost::shared_ptr<ContactRosterItem> contact);
- private slots:
- void handleChangeStatusRequest(StatusShow::Type type, const QString &statusMessage);
- private:
- QString name_;
- QtClickableLabel* avatarLabel_;
- QtNameWidget* nameWidget_;
- QtTextEdit* statusEdit_;
- QtStatusWidget* statusWidget_;
- QToolButton* securityInfoButton_;
- static const int avatarSize_;
- boost::shared_ptr<ContactRosterItem> contact_;
- };
+ void setStatusText(const QString& statusMessage);
+ void setStatusType(StatusShow::Type type);
+ void setConnecting();
+ void setStreamEncryptionStatus(bool tlsInPlace);
+ private:
+ bool event(QEvent* event);
+ signals:
+ void onChangeStatusRequest(StatusShow::Type showType, const QString &statusMessage);
+ void onEditProfileRequest();
+ void onShowCertificateInfo();
+
+ private slots:
+ void handleChangeStatusRequest(StatusShow::Type type, const QString &statusMessage);
+ private:
+ QString name_;
+ QtClickableLabel* avatarLabel_;
+ QtNameWidget* nameWidget_;
+ QtTextEdit* statusEdit_;
+ QtStatusWidget* statusWidget_;
+ QToolButton* securityInfoButton_;
+ static const int avatarSize_;
+ boost::shared_ptr<ContactRosterItem> contact_;
+ };
}
diff --git a/Swift/QtUI/QtScaledAvatarCache.cpp b/Swift/QtUI/QtScaledAvatarCache.cpp
index 9668336..6d683bd 100644
--- a/Swift/QtUI/QtScaledAvatarCache.cpp
+++ b/Swift/QtUI/QtScaledAvatarCache.cpp
@@ -24,39 +24,39 @@ QtScaledAvatarCache::QtScaledAvatarCache(int size) : size(size) {
}
QString QtScaledAvatarCache::getScaledAvatarPath(const QString& path) {
- QFileInfo avatarFile(path);
- if (avatarFile.exists()) {
- if (!avatarFile.dir().exists(QString::number(size))) {
- if (!avatarFile.dir().mkdir(QString::number(size))) {
- return path;
- }
- }
- QDir targetDir(avatarFile.dir().absoluteFilePath(QString::number(size)));
- QString targetFile = targetDir.absoluteFilePath(avatarFile.baseName());
- if (!QFileInfo(targetFile).exists()) {
- QPixmap avatarPixmap;
- if (avatarPixmap.load(path)) {
- QPixmap maskedAvatar(avatarPixmap.size());
- maskedAvatar.fill(QColor(0, 0, 0, 0));
- QPainter maskPainter(&maskedAvatar);
- maskPainter.setBrush(Qt::black);
- maskPainter.drawRoundedRect(maskedAvatar.rect(), 25.0, 25.0, Qt::RelativeSize);
- maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
- maskPainter.drawPixmap(0, 0, avatarPixmap);
- maskPainter.end();
-
- if (!maskedAvatar.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(targetFile, "PNG")) {
- return path;
- }
- } else {
- SWIFT_LOG(debug) << "Failed to load " << Q2PSTRING(path) << std::endl;
- }
- }
- return targetFile;
- }
- else {
- return path;
- }
+ QFileInfo avatarFile(path);
+ if (avatarFile.exists()) {
+ if (!avatarFile.dir().exists(QString::number(size))) {
+ if (!avatarFile.dir().mkdir(QString::number(size))) {
+ return path;
+ }
+ }
+ QDir targetDir(avatarFile.dir().absoluteFilePath(QString::number(size)));
+ QString targetFile = targetDir.absoluteFilePath(avatarFile.baseName());
+ if (!QFileInfo(targetFile).exists()) {
+ QPixmap avatarPixmap;
+ if (avatarPixmap.load(path)) {
+ QPixmap maskedAvatar(avatarPixmap.size());
+ maskedAvatar.fill(QColor(0, 0, 0, 0));
+ QPainter maskPainter(&maskedAvatar);
+ maskPainter.setBrush(Qt::black);
+ maskPainter.drawRoundedRect(maskedAvatar.rect(), 25.0, 25.0, Qt::RelativeSize);
+ maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ maskPainter.drawPixmap(0, 0, avatarPixmap);
+ maskPainter.end();
+
+ if (!maskedAvatar.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(targetFile, "PNG")) {
+ return path;
+ }
+ } else {
+ SWIFT_LOG(debug) << "Failed to load " << Q2PSTRING(path) << std::endl;
+ }
+ }
+ return targetFile;
+ }
+ else {
+ return path;
+ }
}
diff --git a/Swift/QtUI/QtScaledAvatarCache.h b/Swift/QtUI/QtScaledAvatarCache.h
index 4ee583d..748fb40 100644
--- a/Swift/QtUI/QtScaledAvatarCache.h
+++ b/Swift/QtUI/QtScaledAvatarCache.h
@@ -11,13 +11,13 @@
#include <QString>
namespace Swift {
- class QtScaledAvatarCache {
- public:
- QtScaledAvatarCache(int size);
+ class QtScaledAvatarCache {
+ public:
+ QtScaledAvatarCache(int size);
- QString getScaledAvatarPath(const QString& path);
+ QString getScaledAvatarPath(const QString& path);
- private:
- int size;
- };
+ private:
+ int size;
+ };
}
diff --git a/Swift/QtUI/QtSettingsProvider.cpp b/Swift/QtUI/QtSettingsProvider.cpp
index d60fa2b..3c32dc8 100644
--- a/Swift/QtUI/QtSettingsProvider.cpp
+++ b/Swift/QtUI/QtSettingsProvider.cpp
@@ -19,105 +19,105 @@ QtSettingsProvider::~QtSettingsProvider() {
}
bool QtSettingsProvider::hasSetting(const std::string& key) {
- return !settings_.value(key.c_str()).isNull();
+ return !settings_.value(key.c_str()).isNull();
}
std::string QtSettingsProvider::getSetting(const Setting<std::string>& setting) {
- QVariant variant = settings_.value(setting.getKey().c_str());
- return variant.isNull() ? setting.getDefaultValue() : std::string(variant.toString().toUtf8());
+ QVariant variant = settings_.value(setting.getKey().c_str());
+ return variant.isNull() ? setting.getDefaultValue() : std::string(variant.toString().toUtf8());
}
void QtSettingsProvider::storeSetting(const Setting<std::string>& setting, const std::string& settingValue) {
- bool changed = false;
- if (getSetting(setting) != settingValue) {
- changed = true;
- }
- settings_.setValue(setting.getKey().c_str(), settingValue.c_str());
- if (changed) {
- onSettingChanged(setting.getKey());
- }
- updatePermissions();
+ bool changed = false;
+ if (getSetting(setting) != settingValue) {
+ changed = true;
+ }
+ settings_.setValue(setting.getKey().c_str(), settingValue.c_str());
+ if (changed) {
+ onSettingChanged(setting.getKey());
+ }
+ updatePermissions();
}
bool QtSettingsProvider::getSetting(const Setting<bool>& setting) {
- QVariant variant = settings_.value(setting.getKey().c_str());
- return variant.isNull() ? setting.getDefaultValue() : variant.toBool();
+ QVariant variant = settings_.value(setting.getKey().c_str());
+ return variant.isNull() ? setting.getDefaultValue() : variant.toBool();
}
void QtSettingsProvider::storeSetting(const Setting<bool>& setting, const bool& settingValue) {
- bool changed = false;
- if (getSetting(setting) != settingValue) {
- changed = true;
- }
- settings_.setValue(setting.getKey().c_str(), settingValue);
- if (changed) {
- onSettingChanged(setting.getKey());
- }
- updatePermissions();
+ bool changed = false;
+ if (getSetting(setting) != settingValue) {
+ changed = true;
+ }
+ settings_.setValue(setting.getKey().c_str(), settingValue);
+ if (changed) {
+ onSettingChanged(setting.getKey());
+ }
+ updatePermissions();
}
int QtSettingsProvider::getSetting(const Setting<int>& setting) {
- QVariant variant = settings_.value(setting.getKey().c_str());
- return variant.isNull() ? setting.getDefaultValue() : variant.toInt();
+ QVariant variant = settings_.value(setting.getKey().c_str());
+ return variant.isNull() ? setting.getDefaultValue() : variant.toInt();
}
void QtSettingsProvider::storeSetting(const Setting<int>& setting, const int& settingValue) {
- bool changed = false;
- if (getSetting(setting) != settingValue) {
- changed = true;
- }
- settings_.setValue(setting.getKey().c_str(), settingValue);
- if (changed) {
- onSettingChanged(setting.getKey());
- }
- updatePermissions();
+ bool changed = false;
+ if (getSetting(setting) != settingValue) {
+ changed = true;
+ }
+ settings_.setValue(setting.getKey().c_str(), settingValue);
+ if (changed) {
+ onSettingChanged(setting.getKey());
+ }
+ updatePermissions();
}
std::vector<std::string> QtSettingsProvider::getAvailableProfiles() {
- std::vector<std::string> profiles;
- QVariant profilesVariant = settings_.value("profileList");
- foreach(QString profileQString, profilesVariant.toStringList()) {
- profiles.push_back(std::string(profileQString.toUtf8()));
- }
- return profiles;
+ std::vector<std::string> profiles;
+ QVariant profilesVariant = settings_.value("profileList");
+ foreach(QString profileQString, profilesVariant.toStringList()) {
+ profiles.push_back(std::string(profileQString.toUtf8()));
+ }
+ return profiles;
}
void QtSettingsProvider::createProfile(const std::string& profile) {
- QStringList stringList = settings_.value("profileList").toStringList();
- stringList.append(profile.c_str());
- settings_.setValue("profileList", stringList);
- updatePermissions();
+ QStringList stringList = settings_.value("profileList").toStringList();
+ stringList.append(profile.c_str());
+ settings_.setValue("profileList", stringList);
+ updatePermissions();
}
void QtSettingsProvider::removeProfile(const std::string& profile) {
- QString profileStart(QString(profile.c_str()) + ":");
- foreach (QString key, settings_.allKeys()) {
- if (key.startsWith(profileStart)) {
- settings_.remove(key);
- }
- }
- QStringList stringList = settings_.value("profileList").toStringList();
- stringList.removeAll(profile.c_str());
- settings_.setValue("profileList", stringList);
- updatePermissions();
+ QString profileStart(QString(profile.c_str()) + ":");
+ foreach (QString key, settings_.allKeys()) {
+ if (key.startsWith(profileStart)) {
+ settings_.remove(key);
+ }
+ }
+ QStringList stringList = settings_.value("profileList").toStringList();
+ stringList.removeAll(profile.c_str());
+ settings_.setValue("profileList", stringList);
+ updatePermissions();
}
QSettings* QtSettingsProvider::getQSettings() {
- return &settings_;
+ return &settings_;
}
void QtSettingsProvider::updatePermissions() {
#if !defined(Q_OS_WIN) && !defined(Q_OS_MAC)
- QFile file(settings_.fileName());
- if (file.exists()) {
- file.setPermissions(QFile::ReadOwner|QFile::WriteOwner);
- }
+ QFile file(settings_.fileName());
+ if (file.exists()) {
+ file.setPermissions(QFile::ReadOwner|QFile::WriteOwner);
+ }
#endif
}
bool QtSettingsProvider::getIsSettingFinal(const std::string& /*settingPath*/) {
- return false;
+ return false;
}
}
diff --git a/Swift/QtUI/QtSettingsProvider.h b/Swift/QtUI/QtSettingsProvider.h
index 06984f5..21e9211 100644
--- a/Swift/QtUI/QtSettingsProvider.h
+++ b/Swift/QtUI/QtSettingsProvider.h
@@ -13,28 +13,28 @@
namespace Swift {
class QtSettingsProvider : public SettingsProvider {
- public:
- QtSettingsProvider();
- virtual ~QtSettingsProvider();
- virtual std::string getSetting(const Setting<std::string>& setting);
- virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
- virtual bool getSetting(const Setting<bool>& setting);
- virtual void storeSetting(const Setting<bool>& setting, const bool& value);
- virtual int getSetting(const Setting<int>& setting);
- virtual void storeSetting(const Setting<int>& setting, const int& value);
- virtual std::vector<std::string> getAvailableProfiles();
- virtual void createProfile(const std::string& profile);
- virtual void removeProfile(const std::string& profile);
- virtual bool hasSetting(const std::string& key);
- QSettings* getQSettings();
- protected:
- virtual bool getIsSettingFinal(const std::string& settingPath);
-
- private:
- void updatePermissions();
-
- private:
- QSettings settings_;
+ public:
+ QtSettingsProvider();
+ virtual ~QtSettingsProvider();
+ virtual std::string getSetting(const Setting<std::string>& setting);
+ virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
+ virtual bool getSetting(const Setting<bool>& setting);
+ virtual void storeSetting(const Setting<bool>& setting, const bool& value);
+ virtual int getSetting(const Setting<int>& setting);
+ virtual void storeSetting(const Setting<int>& setting, const int& value);
+ virtual std::vector<std::string> getAvailableProfiles();
+ virtual void createProfile(const std::string& profile);
+ virtual void removeProfile(const std::string& profile);
+ virtual bool hasSetting(const std::string& key);
+ QSettings* getQSettings();
+ protected:
+ virtual bool getIsSettingFinal(const std::string& settingPath);
+
+ private:
+ void updatePermissions();
+
+ private:
+ QSettings settings_;
};
}
diff --git a/Swift/QtUI/QtSingleWindow.cpp b/Swift/QtUI/QtSingleWindow.cpp
index 8613d62..db7f7dc 100644
--- a/Swift/QtUI/QtSingleWindow.cpp
+++ b/Swift/QtUI/QtSingleWindow.cpp
@@ -17,13 +17,13 @@ static const QString SINGLE_WINDOW_GEOMETRY = QString("SINGLE_WINDOW_GEOMETRY");
static const QString SINGLE_WINDOW_SPLITS = QString("SINGLE_WINDOW_SPLITS");
QtSingleWindow::QtSingleWindow(QtSettingsProvider* settings) : QSplitter() {
- settings_ = settings;
- QVariant geometryVariant = settings_->getQSettings()->value(SINGLE_WINDOW_GEOMETRY);
- if (geometryVariant.isValid()) {
- restoreGeometry(geometryVariant.toByteArray());
- }
- connect(this, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int)));
- restoreSplitters();
+ settings_ = settings;
+ QVariant geometryVariant = settings_->getQSettings()->value(SINGLE_WINDOW_GEOMETRY);
+ if (geometryVariant.isValid()) {
+ restoreGeometry(geometryVariant.toByteArray());
+ }
+ connect(this, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int)));
+ restoreSplitters();
}
QtSingleWindow::~QtSingleWindow() {
@@ -31,51 +31,51 @@ QtSingleWindow::~QtSingleWindow() {
}
void QtSingleWindow::addWidget(QWidget* widget) {
- QtChatTabs* tabs = dynamic_cast<QtChatTabs*>(widget);
- if (tabs) {
- connect(tabs, SIGNAL(onTitleChanged(const QString&)), this, SLOT(handleTabsTitleChanged(const QString&)));
- }
- QSplitter::addWidget(widget);
+ QtChatTabs* tabs = dynamic_cast<QtChatTabs*>(widget);
+ if (tabs) {
+ connect(tabs, SIGNAL(onTitleChanged(const QString&)), this, SLOT(handleTabsTitleChanged(const QString&)));
+ }
+ QSplitter::addWidget(widget);
}
void QtSingleWindow::handleTabsTitleChanged(const QString& title) {
- setWindowTitle(title);
+ setWindowTitle(title);
}
void QtSingleWindow::handleSplitterMoved(int, int) {
- QList<QVariant> variantValues;
- QList<int> intValues = sizes();
- foreach (int value, intValues) {
- variantValues.append(QVariant(value));
- }
- settings_->getQSettings()->setValue(SINGLE_WINDOW_SPLITS, QVariant(variantValues));
+ QList<QVariant> variantValues;
+ QList<int> intValues = sizes();
+ foreach (int value, intValues) {
+ variantValues.append(QVariant(value));
+ }
+ settings_->getQSettings()->setValue(SINGLE_WINDOW_SPLITS, QVariant(variantValues));
}
void QtSingleWindow::restoreSplitters() {
- QList<QVariant> variantValues = settings_->getQSettings()->value(SINGLE_WINDOW_SPLITS).toList();
- QList<int> intValues;
- foreach (QVariant value, variantValues) {
- intValues.append(value.toInt());
- }
- setSizes(intValues);
+ QList<QVariant> variantValues = settings_->getQSettings()->value(SINGLE_WINDOW_SPLITS).toList();
+ QList<int> intValues;
+ foreach (QVariant value, variantValues) {
+ intValues.append(value.toInt());
+ }
+ setSizes(intValues);
}
void QtSingleWindow::insertAtFront(QWidget* widget) {
- insertWidget(0, widget);
- restoreSplitters();
+ insertWidget(0, widget);
+ restoreSplitters();
}
void QtSingleWindow::handleGeometryChanged() {
- settings_->getQSettings()->setValue(SINGLE_WINDOW_GEOMETRY, saveGeometry());
+ settings_->getQSettings()->setValue(SINGLE_WINDOW_GEOMETRY, saveGeometry());
}
void QtSingleWindow::resizeEvent(QResizeEvent*) {
- handleGeometryChanged();
+ handleGeometryChanged();
}
void QtSingleWindow::moveEvent(QMoveEvent*) {
- handleGeometryChanged();
+ handleGeometryChanged();
}
}
diff --git a/Swift/QtUI/QtSingleWindow.h b/Swift/QtUI/QtSingleWindow.h
index e430c56..804be65 100644
--- a/Swift/QtUI/QtSingleWindow.h
+++ b/Swift/QtUI/QtSingleWindow.h
@@ -9,29 +9,29 @@
#include <QSplitter>
namespace Swift {
- class QtSettingsProvider;
-
- class QtSingleWindow : public QSplitter {
- Q_OBJECT
- public:
- QtSingleWindow(QtSettingsProvider* settings);
- virtual ~QtSingleWindow();
- void insertAtFront(QWidget* widget);
- void addWidget(QWidget* widget);
- protected:
- void resizeEvent(QResizeEvent*);
- void moveEvent(QMoveEvent*);
- private slots:
- void handleSplitterMoved(int, int);
- void handleTabsTitleChanged(const QString& title);
- private:
- void handleGeometryChanged();
- void restoreSplitters();
-
- private:
-
- QtSettingsProvider* settings_;
- };
+ class QtSettingsProvider;
+
+ class QtSingleWindow : public QSplitter {
+ Q_OBJECT
+ public:
+ QtSingleWindow(QtSettingsProvider* settings);
+ virtual ~QtSingleWindow();
+ void insertAtFront(QWidget* widget);
+ void addWidget(QWidget* widget);
+ protected:
+ void resizeEvent(QResizeEvent*);
+ void moveEvent(QMoveEvent*);
+ private slots:
+ void handleSplitterMoved(int, int);
+ void handleTabsTitleChanged(const QString& title);
+ private:
+ void handleGeometryChanged();
+ void restoreSplitters();
+
+ private:
+
+ QtSettingsProvider* settings_;
+ };
}
diff --git a/Swift/QtUI/QtSoundPlayer.cpp b/Swift/QtUI/QtSoundPlayer.cpp
index f047427..22f544d 100644
--- a/Swift/QtUI/QtSoundPlayer.cpp
+++ b/Swift/QtUI/QtSoundPlayer.cpp
@@ -17,30 +17,30 @@
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
-
+
QtSoundPlayer::QtSoundPlayer(ApplicationPathProvider* applicationPathProvider) : applicationPathProvider(applicationPathProvider) {
}
void QtSoundPlayer::playSound(SoundEffect sound, const std::string& soundResource) {
- switch (sound) {
- case MessageReceived:
- playSound(soundResource.empty() ? "/sounds/message-received.wav" : soundResource);
- break;
- }
+ switch (sound) {
+ case MessageReceived:
+ playSound(soundResource.empty() ? "/sounds/message-received.wav" : soundResource);
+ break;
+ }
}
void QtSoundPlayer::playSound(const std::string& soundResource) {
- boost::filesystem::path resourcePath = applicationPathProvider->getResourcePath(soundResource);
- if (boost::filesystem::exists(resourcePath)) {
- QSound::play(P2QSTRING(pathToString(resourcePath)));
- }
- else if (boost::filesystem::exists(soundResource)) {
- QSound::play(P2QSTRING(soundResource));
- }
- else {
- std::cerr << "Unable to find sound: " << soundResource << std::endl;
- }
+ boost::filesystem::path resourcePath = applicationPathProvider->getResourcePath(soundResource);
+ if (boost::filesystem::exists(resourcePath)) {
+ QSound::play(P2QSTRING(pathToString(resourcePath)));
+ }
+ else if (boost::filesystem::exists(soundResource)) {
+ QSound::play(P2QSTRING(soundResource));
+ }
+ else {
+ std::cerr << "Unable to find sound: " << soundResource << std::endl;
+ }
}
}
diff --git a/Swift/QtUI/QtSoundPlayer.h b/Swift/QtUI/QtSoundPlayer.h
index e34529e..8a0b8fe 100644
--- a/Swift/QtUI/QtSoundPlayer.h
+++ b/Swift/QtUI/QtSoundPlayer.h
@@ -11,20 +11,20 @@
#include <Swift/Controllers/SoundPlayer.h>
namespace Swift {
- class ApplicationPathProvider;
-
+ class ApplicationPathProvider;
- class QtSoundPlayer : public QObject, public SoundPlayer {
- Q_OBJECT
- public:
- QtSoundPlayer(ApplicationPathProvider* applicationPathProvider);
- void playSound(SoundEffect sound, const std::string& soundResource);
+ class QtSoundPlayer : public QObject, public SoundPlayer {
+ Q_OBJECT
+ public:
+ QtSoundPlayer(ApplicationPathProvider* applicationPathProvider);
- private:
- void playSound(const std::string& soundResource);
+ void playSound(SoundEffect sound, const std::string& soundResource);
- private:
- ApplicationPathProvider* applicationPathProvider;
- };
+ private:
+ void playSound(const std::string& soundResource);
+
+ private:
+ ApplicationPathProvider* applicationPathProvider;
+ };
}
diff --git a/Swift/QtUI/QtSpellCheckHighlighter.cpp b/Swift/QtUI/QtSpellCheckHighlighter.cpp
index 0112d7a..6565b06 100644
--- a/Swift/QtUI/QtSpellCheckHighlighter.cpp
+++ b/Swift/QtUI/QtSpellCheckHighlighter.cpp
@@ -21,21 +21,21 @@ QtSpellCheckHighlighter::~QtSpellCheckHighlighter() {
}
void QtSpellCheckHighlighter::highlightBlock(const QString& text) {
- misspelledPositions_.clear();
- std::string fragment = Q2PSTRING(text);
- checker_->checkFragment(fragment, misspelledPositions_);
+ misspelledPositions_.clear();
+ std::string fragment = Q2PSTRING(text);
+ checker_->checkFragment(fragment, misspelledPositions_);
- QTextCharFormat spellingErrorFormat;
- spellingErrorFormat.setUnderlineColor(QColor(Qt::red));
- spellingErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
+ QTextCharFormat spellingErrorFormat;
+ spellingErrorFormat.setUnderlineColor(QColor(Qt::red));
+ spellingErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
- foreach (PositionPair position, misspelledPositions_) {
- setFormat(boost::get<0>(position), boost::get<1>(position) - boost::get<0>(position), spellingErrorFormat);
- };
+ foreach (PositionPair position, misspelledPositions_) {
+ setFormat(boost::get<0>(position), boost::get<1>(position) - boost::get<0>(position), spellingErrorFormat);
+ };
}
PositionPairList QtSpellCheckHighlighter::getMisspelledPositions() const {
- return misspelledPositions_;
+ return misspelledPositions_;
}
}
diff --git a/Swift/QtUI/QtSpellCheckHighlighter.h b/Swift/QtUI/QtSpellCheckHighlighter.h
index 7fa48de..5519a1d 100644
--- a/Swift/QtUI/QtSpellCheckHighlighter.h
+++ b/Swift/QtUI/QtSpellCheckHighlighter.h
@@ -18,20 +18,20 @@ namespace Swift {
class SpellChecker;
class QtSpellCheckHighlighter : public QSyntaxHighlighter {
- Q_OBJECT
+ Q_OBJECT
public:
- QtSpellCheckHighlighter(QTextDocument* parent, SpellChecker* spellChecker);
- virtual ~QtSpellCheckHighlighter();
+ QtSpellCheckHighlighter(QTextDocument* parent, SpellChecker* spellChecker);
+ virtual ~QtSpellCheckHighlighter();
- PositionPairList getMisspelledPositions() const;
+ PositionPairList getMisspelledPositions() const;
protected:
- virtual void highlightBlock(const QString& text);
+ virtual void highlightBlock(const QString& text);
private:
- SpellChecker* checker_;
- PositionPairList misspelledPositions_;
+ SpellChecker* checker_;
+ PositionPairList misspelledPositions_;
};
diff --git a/Swift/QtUI/QtSpellCheckerWindow.cpp b/Swift/QtUI/QtSpellCheckerWindow.cpp
index ba4dbd3..9232b19 100644
--- a/Swift/QtUI/QtSpellCheckerWindow.cpp
+++ b/Swift/QtUI/QtSpellCheckerWindow.cpp
@@ -27,96 +27,96 @@
namespace Swift {
QtSpellCheckerWindow::QtSpellCheckerWindow(SettingsProvider* settings, QWidget* parent) : QDialog(parent) {
- settings_ = settings;
- ui_.setupUi(this);
+ settings_ = settings;
+ ui_.setupUi(this);
#ifdef HAVE_HUNSPELL
- ui_.hunspellOptions->show();
+ ui_.hunspellOptions->show();
#else
- ui_.hunspellOptions->hide();
- QTimer::singleShot(0, this, SLOT(shrinkWindow()));
+ ui_.hunspellOptions->hide();
+ QTimer::singleShot(0, this, SLOT(shrinkWindow()));
#endif
- connect(ui_.spellChecker, SIGNAL(toggled(bool)), this, SLOT(handleChecker(bool)));
- connect(ui_.cancel, SIGNAL(clicked()), this, SLOT(handleCancel()));
- connect(ui_.apply, SIGNAL(clicked()), this, SLOT(handleApply()));
- connect(ui_.pathButton, SIGNAL(clicked()), this, SLOT(handlePathButton()));
- setFromSettings();
+ connect(ui_.spellChecker, SIGNAL(toggled(bool)), this, SLOT(handleChecker(bool)));
+ connect(ui_.cancel, SIGNAL(clicked()), this, SLOT(handleCancel()));
+ connect(ui_.apply, SIGNAL(clicked()), this, SLOT(handleApply()));
+ connect(ui_.pathButton, SIGNAL(clicked()), this, SLOT(handlePathButton()));
+ setFromSettings();
}
void QtSpellCheckerWindow::shrinkWindow() {
- resize(0,0);
+ resize(0,0);
}
void QtSpellCheckerWindow::setFromSettings() {
- ui_.spellChecker->setChecked(settings_->getSetting(SettingConstants::SPELL_CHECKER));
- ui_.pathContent->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_PATH)));
- ui_.currentLanguageValue->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_FILE)));
- std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
- QString filename = "*.dic";
- QDir dictDirectory = QDir(P2QSTRING(currentPath));
- QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
- showFiles(files);
- setEnabled(settings_->getSetting(SettingConstants::SPELL_CHECKER));
+ ui_.spellChecker->setChecked(settings_->getSetting(SettingConstants::SPELL_CHECKER));
+ ui_.pathContent->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_PATH)));
+ ui_.currentLanguageValue->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_FILE)));
+ std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
+ QString filename = "*.dic";
+ QDir dictDirectory = QDir(P2QSTRING(currentPath));
+ QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
+ showFiles(files);
+ setEnabled(settings_->getSetting(SettingConstants::SPELL_CHECKER));
}
void QtSpellCheckerWindow::handleChecker(bool state) {
- setEnabled(state);
+ setEnabled(state);
}
void QtSpellCheckerWindow::setEnabled(bool state) {
- ui_.pathContent->setEnabled(state);
- ui_.languageView->setEnabled(state);
- ui_.pathButton->setEnabled(state);
- ui_.pathLabel->setEnabled(state);
- ui_.currentLanguage->setEnabled(state);
- ui_.currentLanguageValue->setEnabled(state);
- ui_.language->setEnabled(state);
+ ui_.pathContent->setEnabled(state);
+ ui_.languageView->setEnabled(state);
+ ui_.pathButton->setEnabled(state);
+ ui_.pathLabel->setEnabled(state);
+ ui_.currentLanguage->setEnabled(state);
+ ui_.currentLanguageValue->setEnabled(state);
+ ui_.language->setEnabled(state);
}
void QtSpellCheckerWindow::handleApply() {
- settings_->storeSetting(SettingConstants::SPELL_CHECKER, ui_.spellChecker->isChecked());
- QList<QListWidgetItem* > selectedLanguage = ui_.languageView->selectedItems();
- if (!selectedLanguage.empty()) {
- settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING((selectedLanguage.first())->text()));
- }
- this->done(0);
+ settings_->storeSetting(SettingConstants::SPELL_CHECKER, ui_.spellChecker->isChecked());
+ QList<QListWidgetItem* > selectedLanguage = ui_.languageView->selectedItems();
+ if (!selectedLanguage.empty()) {
+ settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING((selectedLanguage.first())->text()));
+ }
+ this->done(0);
}
void QtSpellCheckerWindow::handleCancel() {
- this->done(0);
+ this->done(0);
}
void QtSpellCheckerWindow::handlePathButton() {
- std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
- QString dirpath = QFileDialog::getExistingDirectory(this, tr("Dictionary Path"), P2QSTRING(currentPath));
- if (dirpath != P2QSTRING(currentPath)) {
- ui_.languageView->clear();
- settings_->storeSetting(SettingConstants::DICT_FILE, "");
- ui_.currentLanguageValue->setText(" ");
- }
- if (!dirpath.isEmpty()) {
- if (!dirpath.endsWith("/")) {
- dirpath.append("/");
- }
- settings_->storeSetting(SettingConstants::DICT_PATH, Q2PSTRING(dirpath));
- QDir dictDirectory = QDir(dirpath);
- ui_.pathContent->setText(dirpath);
- QString filename = "*.dic";
- QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
- showFiles(files);
- }
+ std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
+ QString dirpath = QFileDialog::getExistingDirectory(this, tr("Dictionary Path"), P2QSTRING(currentPath));
+ if (dirpath != P2QSTRING(currentPath)) {
+ ui_.languageView->clear();
+ settings_->storeSetting(SettingConstants::DICT_FILE, "");
+ ui_.currentLanguageValue->setText(" ");
+ }
+ if (!dirpath.isEmpty()) {
+ if (!dirpath.endsWith("/")) {
+ dirpath.append("/");
+ }
+ settings_->storeSetting(SettingConstants::DICT_PATH, Q2PSTRING(dirpath));
+ QDir dictDirectory = QDir(dirpath);
+ ui_.pathContent->setText(dirpath);
+ QString filename = "*.dic";
+ QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
+ showFiles(files);
+ }
}
void QtSpellCheckerWindow::handlePersonalPathButton() {
- std::string currentPath = settings_->getSetting(SettingConstants::PERSONAL_DICT_PATH);
- QString filename = QFileDialog::getOpenFileName(this, tr("Select Personal Dictionary"), P2QSTRING(currentPath), tr("(*.dic"));
- settings_->storeSetting(SettingConstants::PERSONAL_DICT_PATH, Q2PSTRING(filename));
+ std::string currentPath = settings_->getSetting(SettingConstants::PERSONAL_DICT_PATH);
+ QString filename = QFileDialog::getOpenFileName(this, tr("Select Personal Dictionary"), P2QSTRING(currentPath), tr("(*.dic"));
+ settings_->storeSetting(SettingConstants::PERSONAL_DICT_PATH, Q2PSTRING(filename));
}
void QtSpellCheckerWindow::showFiles(const QStringList& files) {
- ui_.languageView->clear();
- for (int i = 0; i < files.size(); ++i) {
- ui_.languageView->insertItem(i, files[i]);
- }
+ ui_.languageView->clear();
+ for (int i = 0; i < files.size(); ++i) {
+ ui_.languageView->insertItem(i, files[i]);
+ }
}
}
diff --git a/Swift/QtUI/QtSpellCheckerWindow.h b/Swift/QtUI/QtSpellCheckerWindow.h
index 0e43ddd..95e0725 100644
--- a/Swift/QtUI/QtSpellCheckerWindow.h
+++ b/Swift/QtUI/QtSpellCheckerWindow.h
@@ -17,24 +17,24 @@
#include <Swift/QtUI/ui_QtSpellCheckerWindow.h>
namespace Swift {
- class SettingsProvider;
- class QtSpellCheckerWindow : public QDialog, protected Ui::QtSpellCheckerWindow {
- Q_OBJECT
- public:
- QtSpellCheckerWindow(SettingsProvider* settings, QWidget* parent = NULL);
- public slots:
- void handleChecker(bool state);
- void handleCancel();
- void handlePathButton();
- void handlePersonalPathButton();
- void handleApply();
- private slots:
- void shrinkWindow();
- private:
- void setEnabled(bool state);
- void setFromSettings();
- void showFiles(const QStringList& files);
- SettingsProvider* settings_;
- Ui::QtSpellCheckerWindow ui_;
- };
+ class SettingsProvider;
+ class QtSpellCheckerWindow : public QDialog, protected Ui::QtSpellCheckerWindow {
+ Q_OBJECT
+ public:
+ QtSpellCheckerWindow(SettingsProvider* settings, QWidget* parent = NULL);
+ public slots:
+ void handleChecker(bool state);
+ void handleCancel();
+ void handlePathButton();
+ void handlePersonalPathButton();
+ void handleApply();
+ private slots:
+ void shrinkWindow();
+ private:
+ void setEnabled(bool state);
+ void setFromSettings();
+ void showFiles(const QStringList& files);
+ SettingsProvider* settings_;
+ Ui::QtSpellCheckerWindow ui_;
+ };
}
diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp
index 78b2c5a..2e9e4cc 100644
--- a/Swift/QtUI/QtStatusWidget.cpp
+++ b/Swift/QtUI/QtStatusWidget.cpp
@@ -37,266 +37,266 @@ namespace lambda = boost::lambda;
namespace Swift {
QtStatusWidget::QtStatusWidget(StatusCache* statusCache, QWidget *parent) : QWidget(parent), statusCache_(statusCache), editCursor_(Qt::IBeamCursor), viewCursor_(Qt::PointingHandCursor) {
- allTypes_.push_back(StatusShow::Online);
- allTypes_.push_back(StatusShow::FFC);
- allTypes_.push_back(StatusShow::Away);
- allTypes_.push_back(StatusShow::XA);
- allTypes_.push_back(StatusShow::DND);
- allTypes_.push_back(StatusShow::None);
-
- isClicking_ = false;
- connecting_ = false;
- setMaximumHeight(24);
-
- connectingMovie_ = new QMovie(":/icons/connecting.mng");
-
- QHBoxLayout* mainLayout = new QHBoxLayout(this);
- mainLayout->setSpacing(0);
- mainLayout->setContentsMargins(0,0,0,0);
-
- stack_ = new QStackedWidget(this);
- stack_->setLineWidth(2);
- stack_->setFrameShape(QFrame::StyledPanel);
- mainLayout->addWidget(stack_);
-
- QWidget* page1 = new QWidget(this);
- stack_->addWidget(page1);
- QHBoxLayout* page1Layout = new QHBoxLayout(page1);
- page1Layout->setSpacing(0);
- page1Layout->setContentsMargins(0,0,0,0);
- page1->setCursor(viewCursor_);
-
- statusIcon_ = new QLabel(this);
- statusIcon_->setMinimumSize(16, 16);
- statusIcon_->setMaximumSize(16, 16);
- page1Layout->addWidget(statusIcon_);
-
- statusTextLabel_ = new QtElidingLabel(this);
- QFont font = statusTextLabel_->font();
- font.setItalic(true);
- statusTextLabel_->setFont(font);
- page1Layout->addWidget(statusTextLabel_);
-
- icons_[StatusShow::Online] = QIcon(":/icons/online.png");
- icons_[StatusShow::Away] = QIcon(":/icons/away.png");
- icons_[StatusShow::DND] = QIcon(":/icons/dnd.png");
- icons_[StatusShow::None] = QIcon(":/icons/offline.png");
-
- setStatusType(StatusShow::None);
-
- QWidget* page2 = new QWidget(this);
- QHBoxLayout* page2Layout = new QHBoxLayout(page2);
- page2Layout->setSpacing(0);
- page2Layout->setContentsMargins(0,0,0,0);
- stack_->addWidget(page2);
-
- statusEdit_ = new QtLineEdit(this);
- page2Layout->addWidget(statusEdit_);
- connect(statusEdit_, SIGNAL(returnPressed()), this, SLOT(handleEditComplete()));
- connect(statusEdit_, SIGNAL(escapePressed()), this, SLOT(handleEditCancelled()));
- connect(statusEdit_, SIGNAL(textChanged(const QString&)), this, SLOT(generateList()));
-
- setStatusText("");
-
-
- menu_ = new QListWidget();
- menu_->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint );
- menu_->setAlternatingRowColors(true);
- menu_->setFocusProxy(statusEdit_);
- menu_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- menu_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- QSizePolicy policy(menu_->sizePolicy());
- policy.setVerticalPolicy(QSizePolicy::Expanding);
- menu_->setSizePolicy(policy);
-
-
- connect(menu_, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(handleItemClicked(QListWidgetItem*)));
-
- viewMode();
+ allTypes_.push_back(StatusShow::Online);
+ allTypes_.push_back(StatusShow::FFC);
+ allTypes_.push_back(StatusShow::Away);
+ allTypes_.push_back(StatusShow::XA);
+ allTypes_.push_back(StatusShow::DND);
+ allTypes_.push_back(StatusShow::None);
+
+ isClicking_ = false;
+ connecting_ = false;
+ setMaximumHeight(24);
+
+ connectingMovie_ = new QMovie(":/icons/connecting.mng");
+
+ QHBoxLayout* mainLayout = new QHBoxLayout(this);
+ mainLayout->setSpacing(0);
+ mainLayout->setContentsMargins(0,0,0,0);
+
+ stack_ = new QStackedWidget(this);
+ stack_->setLineWidth(2);
+ stack_->setFrameShape(QFrame::StyledPanel);
+ mainLayout->addWidget(stack_);
+
+ QWidget* page1 = new QWidget(this);
+ stack_->addWidget(page1);
+ QHBoxLayout* page1Layout = new QHBoxLayout(page1);
+ page1Layout->setSpacing(0);
+ page1Layout->setContentsMargins(0,0,0,0);
+ page1->setCursor(viewCursor_);
+
+ statusIcon_ = new QLabel(this);
+ statusIcon_->setMinimumSize(16, 16);
+ statusIcon_->setMaximumSize(16, 16);
+ page1Layout->addWidget(statusIcon_);
+
+ statusTextLabel_ = new QtElidingLabel(this);
+ QFont font = statusTextLabel_->font();
+ font.setItalic(true);
+ statusTextLabel_->setFont(font);
+ page1Layout->addWidget(statusTextLabel_);
+
+ icons_[StatusShow::Online] = QIcon(":/icons/online.png");
+ icons_[StatusShow::Away] = QIcon(":/icons/away.png");
+ icons_[StatusShow::DND] = QIcon(":/icons/dnd.png");
+ icons_[StatusShow::None] = QIcon(":/icons/offline.png");
+
+ setStatusType(StatusShow::None);
+
+ QWidget* page2 = new QWidget(this);
+ QHBoxLayout* page2Layout = new QHBoxLayout(page2);
+ page2Layout->setSpacing(0);
+ page2Layout->setContentsMargins(0,0,0,0);
+ stack_->addWidget(page2);
+
+ statusEdit_ = new QtLineEdit(this);
+ page2Layout->addWidget(statusEdit_);
+ connect(statusEdit_, SIGNAL(returnPressed()), this, SLOT(handleEditComplete()));
+ connect(statusEdit_, SIGNAL(escapePressed()), this, SLOT(handleEditCancelled()));
+ connect(statusEdit_, SIGNAL(textChanged(const QString&)), this, SLOT(generateList()));
+
+ setStatusText("");
+
+
+ menu_ = new QListWidget();
+ menu_->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint );
+ menu_->setAlternatingRowColors(true);
+ menu_->setFocusProxy(statusEdit_);
+ menu_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ menu_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ QSizePolicy policy(menu_->sizePolicy());
+ policy.setVerticalPolicy(QSizePolicy::Expanding);
+ menu_->setSizePolicy(policy);
+
+
+ connect(menu_, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(handleItemClicked(QListWidgetItem*)));
+
+ viewMode();
}
QtStatusWidget::~QtStatusWidget() {
- delete menu_;
- delete connectingMovie_;
+ delete menu_;
+ delete connectingMovie_;
}
void QtStatusWidget::handleApplicationFocusChanged(QWidget* /*old*/, QWidget* /*now*/) {
- QWidget* now = qApp->focusWidget();
- if (!editing_ || stack_->currentIndex() == 0) {
- return;
- }
- if (!now || (now != menu_ && now != statusEdit_ && !now->isAncestorOf(statusEdit_) && !now->isAncestorOf(menu_) && !statusEdit_->isAncestorOf(now) && !menu_->isAncestorOf(now))) {
- handleEditCancelled();
- }
-
+ QWidget* now = qApp->focusWidget();
+ if (!editing_ || stack_->currentIndex() == 0) {
+ return;
+ }
+ if (!now || (now != menu_ && now != statusEdit_ && !now->isAncestorOf(statusEdit_) && !now->isAncestorOf(menu_) && !statusEdit_->isAncestorOf(now) && !menu_->isAncestorOf(now))) {
+ handleEditCancelled();
+ }
+
}
void QtStatusWidget::mousePressEvent(QMouseEvent*) {
- if (stack_->currentIndex() == 0) {
- handleClicked();
- }
+ if (stack_->currentIndex() == 0) {
+ handleClicked();
+ }
}
void QtStatusWidget::generateList() {
- if (!editing_) {
- return;
- }
- QString text = statusEdit_->text();
- newStatusText_ = text;
- menu_->clear();
- foreach (StatusShow::Type type, icons_.keys()) {
- QListWidgetItem* item = new QListWidgetItem(text == "" ? getNoMessage() : text, menu_);
- item->setIcon(icons_[type]);
- item->setToolTip(P2QSTRING(statusShowTypeToFriendlyName(type)) + ": " + item->text());
- item->setStatusTip(item->toolTip());
- item->setData(Qt::UserRole, QVariant(type));
- }
- std::vector<StatusCache::PreviousStatus> previousStatuses = statusCache_->getMatches(Q2PSTRING(text), 8);
- foreach (StatusCache::PreviousStatus savedStatus, previousStatuses) {
- if (savedStatus.first.empty() || std::find_if(allTypes_.begin(), allTypes_.end(),
- savedStatus.second == lambda::_1 && savedStatus.first == lambda::bind(&statusShowTypeToFriendlyName, lambda::_1)) != allTypes_.end()) {
- continue;
- }
- QListWidgetItem* item = new QListWidgetItem(P2QSTRING(savedStatus.first), menu_);
- item->setIcon(icons_[savedStatus.second]);
- item->setToolTip(item->text());
- item->setStatusTip(item->toolTip());
- item->setData(Qt::UserRole, QVariant(savedStatus.second));
- }
- foreach (StatusShow::Type type, icons_.keys()) {
- if (Q2PSTRING(text) == statusShowTypeToFriendlyName(type)) {
- continue;
- }
- QListWidgetItem* item = new QListWidgetItem(P2QSTRING(statusShowTypeToFriendlyName(type)), menu_);
- item->setIcon(icons_[type]);
- item->setToolTip(item->text());
- item->setStatusTip(item->toolTip());
- item->setData(Qt::UserRole, QVariant(type));
- }
- resizeMenu();
+ if (!editing_) {
+ return;
+ }
+ QString text = statusEdit_->text();
+ newStatusText_ = text;
+ menu_->clear();
+ foreach (StatusShow::Type type, icons_.keys()) {
+ QListWidgetItem* item = new QListWidgetItem(text == "" ? getNoMessage() : text, menu_);
+ item->setIcon(icons_[type]);
+ item->setToolTip(P2QSTRING(statusShowTypeToFriendlyName(type)) + ": " + item->text());
+ item->setStatusTip(item->toolTip());
+ item->setData(Qt::UserRole, QVariant(type));
+ }
+ std::vector<StatusCache::PreviousStatus> previousStatuses = statusCache_->getMatches(Q2PSTRING(text), 8);
+ foreach (StatusCache::PreviousStatus savedStatus, previousStatuses) {
+ if (savedStatus.first.empty() || std::find_if(allTypes_.begin(), allTypes_.end(),
+ savedStatus.second == lambda::_1 && savedStatus.first == lambda::bind(&statusShowTypeToFriendlyName, lambda::_1)) != allTypes_.end()) {
+ continue;
+ }
+ QListWidgetItem* item = new QListWidgetItem(P2QSTRING(savedStatus.first), menu_);
+ item->setIcon(icons_[savedStatus.second]);
+ item->setToolTip(item->text());
+ item->setStatusTip(item->toolTip());
+ item->setData(Qt::UserRole, QVariant(savedStatus.second));
+ }
+ foreach (StatusShow::Type type, icons_.keys()) {
+ if (Q2PSTRING(text) == statusShowTypeToFriendlyName(type)) {
+ continue;
+ }
+ QListWidgetItem* item = new QListWidgetItem(P2QSTRING(statusShowTypeToFriendlyName(type)), menu_);
+ item->setIcon(icons_[type]);
+ item->setToolTip(item->text());
+ item->setStatusTip(item->toolTip());
+ item->setData(Qt::UserRole, QVariant(type));
+ }
+ resizeMenu();
}
void QtStatusWidget::resizeMenu() {
- int height = menu_->sizeHintForRow(0) * menu_->count();
- int marginLeft;
- int marginTop;
- int marginRight;
- int marginBottom;
- menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
- height += marginTop + marginBottom;
-
- menu_->setGeometry(menu_->x(), menu_->y(), menu_->width(), height);
+ int height = menu_->sizeHintForRow(0) * menu_->count();
+ int marginLeft;
+ int marginTop;
+ int marginRight;
+ int marginBottom;
+ menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
+ height += marginTop + marginBottom;
+
+ menu_->setGeometry(menu_->x(), menu_->y(), menu_->width(), height);
}
void QtStatusWidget::handleClicked() {
- editing_ = true;
- QDesktopWidget* desktop = QApplication::desktop();
- int screen = desktop->screenNumber(this);
- QPoint point = mapToGlobal(QPoint(0, height()));
- QRect geometry = desktop->availableGeometry(screen);
- int x = point.x();
- int y = point.y();
- int width = 200;
- int height = 80;
-
- int screenWidth = geometry.x() + geometry.width();
- if (x + width > screenWidth) {
- x = screenWidth - width;
- }
- //foreach (StatusShow::Type type, allTypes_) {
- // if (statusEdit_->text() == P2QSTRING(statusShowTypeToFriendlyName(type))) {
- statusEdit_->setText("");
- // }
- //}
- generateList();
-
- height = menu_->sizeHintForRow(0) * menu_->count();
- int marginLeft;
- int marginTop;
- int marginRight;
- int marginBottom;
- menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
- height += marginTop + marginBottom;
- width += marginLeft + marginRight;
-
- menu_->setGeometry(x, y, width, height);
- menu_->move(x, y);
- menu_->setMaximumWidth(width);
- menu_->show();
- activateWindow();
- statusEdit_->selectAll();
- stack_->setCurrentIndex(1);
- statusEdit_->setFocus();
- connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)), Qt::QueuedConnection);
+ editing_ = true;
+ QDesktopWidget* desktop = QApplication::desktop();
+ int screen = desktop->screenNumber(this);
+ QPoint point = mapToGlobal(QPoint(0, height()));
+ QRect geometry = desktop->availableGeometry(screen);
+ int x = point.x();
+ int y = point.y();
+ int width = 200;
+ int height = 80;
+
+ int screenWidth = geometry.x() + geometry.width();
+ if (x + width > screenWidth) {
+ x = screenWidth - width;
+ }
+ //foreach (StatusShow::Type type, allTypes_) {
+ // if (statusEdit_->text() == P2QSTRING(statusShowTypeToFriendlyName(type))) {
+ statusEdit_->setText("");
+ // }
+ //}
+ generateList();
+
+ height = menu_->sizeHintForRow(0) * menu_->count();
+ int marginLeft;
+ int marginTop;
+ int marginRight;
+ int marginBottom;
+ menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
+ height += marginTop + marginBottom;
+ width += marginLeft + marginRight;
+
+ menu_->setGeometry(x, y, width, height);
+ menu_->move(x, y);
+ menu_->setMaximumWidth(width);
+ menu_->show();
+ activateWindow();
+ statusEdit_->selectAll();
+ stack_->setCurrentIndex(1);
+ statusEdit_->setFocus();
+ connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)), Qt::QueuedConnection);
}
void QtStatusWidget::viewMode() {
- disconnect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)));
- editing_ = false;
- menu_->hide();
- stack_->setCurrentIndex(0);
+ disconnect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)));
+ editing_ = false;
+ menu_->hide();
+ stack_->setCurrentIndex(0);
}
void QtStatusWidget::handleEditComplete() {
- editing_ = false;
- statusText_ = newStatusText_;
- viewMode();
- emit onChangeStatusRequest(selectedStatusType_, statusText_);
- statusCache_->addRecent(Q2PSTRING(statusText_), selectedStatusType_);
+ editing_ = false;
+ statusText_ = newStatusText_;
+ viewMode();
+ emit onChangeStatusRequest(selectedStatusType_, statusText_);
+ statusCache_->addRecent(Q2PSTRING(statusText_), selectedStatusType_);
}
void QtStatusWidget::handleEditCancelled() {
- editing_ = false;
- setStatusText(statusText_);
- viewMode();
+ editing_ = false;
+ setStatusText(statusText_);
+ viewMode();
}
StatusShow::Type QtStatusWidget::getSelectedStatusShow() {
- return selectedStatusType_;
+ return selectedStatusType_;
}
void QtStatusWidget::handleItemClicked(QListWidgetItem* item) {
- editing_ = false;
- selectedStatusType_ = static_cast<StatusShow::Type>(item->data(Qt::UserRole).toInt());
- QString message = item->data(Qt::DisplayRole).toString();
- newStatusText_ = message == getNoMessage() ? "" : message;
- statusEdit_->setText(newStatusText_);
- handleEditComplete();
+ editing_ = false;
+ selectedStatusType_ = static_cast<StatusShow::Type>(item->data(Qt::UserRole).toInt());
+ QString message = item->data(Qt::DisplayRole).toString();
+ newStatusText_ = message == getNoMessage() ? "" : message;
+ statusEdit_->setText(newStatusText_);
+ handleEditComplete();
}
void QtStatusWidget::setNewToolTip() {
- if (connecting_) {
- statusTextLabel_->setToolTip(tr("Connecting"));
- } else {
- statusTextLabel_->setToolTip(P2QSTRING(statusShowTypeToFriendlyName(selectedStatusType_)) + ": " + statusTextLabel_->text());
- }
+ if (connecting_) {
+ statusTextLabel_->setToolTip(tr("Connecting"));
+ } else {
+ statusTextLabel_->setToolTip(P2QSTRING(statusShowTypeToFriendlyName(selectedStatusType_)) + ": " + statusTextLabel_->text());
+ }
}
void QtStatusWidget::setStatusText(const QString& text) {
- connectingMovie_->stop();
- statusText_ = text;
- statusEdit_->setText(text);
- QString escapedText(text.isEmpty() ? getNoMessage() : text);
- statusTextLabel_->setText(escapedText);
- setNewToolTip();
+ connectingMovie_->stop();
+ statusText_ = text;
+ statusEdit_->setText(text);
+ QString escapedText(text.isEmpty() ? getNoMessage() : text);
+ statusTextLabel_->setText(escapedText);
+ setNewToolTip();
}
void QtStatusWidget::setConnecting() {
- connecting_ = true;
- statusIcon_->setMovie(connectingMovie_);
- connectingMovie_->start();
- setNewToolTip();
+ connecting_ = true;
+ statusIcon_->setMovie(connectingMovie_);
+ connectingMovie_->start();
+ setNewToolTip();
}
void QtStatusWidget::setStatusType(StatusShow::Type type) {
- connecting_ = false;
- selectedStatusType_ = icons_.contains(type) ? type : StatusShow::Online;
- statusIcon_->setPixmap(icons_[selectedStatusType_].pixmap(16, 16));
- setNewToolTip();
+ connecting_ = false;
+ selectedStatusType_ = icons_.contains(type) ? type : StatusShow::Online;
+ statusIcon_->setPixmap(icons_[selectedStatusType_].pixmap(16, 16));
+ setNewToolTip();
}
QString QtStatusWidget::getNoMessage() {
- return QString(tr("(No message)"));
+ return QString(tr("(No message)"));
}
}
diff --git a/Swift/QtUI/QtStatusWidget.h b/Swift/QtUI/QtStatusWidget.h
index b835490..f346868 100644
--- a/Swift/QtUI/QtStatusWidget.h
+++ b/Swift/QtUI/QtStatusWidget.h
@@ -20,55 +20,55 @@ class QListWidgetItem;
class QMovie;
namespace Swift {
- class QtLineEdit;
- class QtElidingLabel;
- class StatusCache;
+ class QtLineEdit;
+ class QtElidingLabel;
+ class StatusCache;
- class QtStatusWidget : public QWidget {
- Q_OBJECT
- public:
- QtStatusWidget(StatusCache* statusCache, QWidget *parent);
- ~QtStatusWidget();
- StatusShow::Type getSelectedStatusShow();
- void setStatusType(StatusShow::Type type);
- void setConnecting();
- signals:
- void onChangeStatusRequest(StatusShow::Type showType, const QString& text);
- public slots:
- void setStatusText(const QString& text);
- private slots:
- void generateList();
- void handleClicked();
- void handleEditComplete();
- void handleEditCancelled();
- void handleApplicationFocusChanged(QWidget* old, QWidget* now);
- protected slots:
- virtual void mousePressEvent(QMouseEvent* event);
- void handleItemClicked(QListWidgetItem* item);
- static QString getNoMessage();
- private:
- void resizeMenu();
- void viewMode();
- void setNewToolTip();
- //QComboBox *types_;
- StatusCache* statusCache_;
- QStackedWidget* stack_;
- QLabel* statusIcon_;
- QtElidingLabel* statusTextLabel_;
- QtLineEdit* statusEdit_;
- QString statusText_;
- QString newStatusText_;
- QMap<StatusShow::Type, QIcon> icons_;
- StatusShow::Type selectedStatusType_;
- bool isClicking_;
- QListWidget* menu_;
- QCursor editCursor_;
- QCursor viewCursor_;
- bool editing_;
- QMovie* connectingMovie_;
- bool connecting_;
- static const QString NO_MESSAGE;
- std::vector<StatusShow::Type> allTypes_;
- };
+ class QtStatusWidget : public QWidget {
+ Q_OBJECT
+ public:
+ QtStatusWidget(StatusCache* statusCache, QWidget *parent);
+ ~QtStatusWidget();
+ StatusShow::Type getSelectedStatusShow();
+ void setStatusType(StatusShow::Type type);
+ void setConnecting();
+ signals:
+ void onChangeStatusRequest(StatusShow::Type showType, const QString& text);
+ public slots:
+ void setStatusText(const QString& text);
+ private slots:
+ void generateList();
+ void handleClicked();
+ void handleEditComplete();
+ void handleEditCancelled();
+ void handleApplicationFocusChanged(QWidget* old, QWidget* now);
+ protected slots:
+ virtual void mousePressEvent(QMouseEvent* event);
+ void handleItemClicked(QListWidgetItem* item);
+ static QString getNoMessage();
+ private:
+ void resizeMenu();
+ void viewMode();
+ void setNewToolTip();
+ //QComboBox *types_;
+ StatusCache* statusCache_;
+ QStackedWidget* stack_;
+ QLabel* statusIcon_;
+ QtElidingLabel* statusTextLabel_;
+ QtLineEdit* statusEdit_;
+ QString statusText_;
+ QString newStatusText_;
+ QMap<StatusShow::Type, QIcon> icons_;
+ StatusShow::Type selectedStatusType_;
+ bool isClicking_;
+ QListWidget* menu_;
+ QCursor editCursor_;
+ QCursor viewCursor_;
+ bool editing_;
+ QMovie* connectingMovie_;
+ bool connecting_;
+ static const QString NO_MESSAGE;
+ std::vector<StatusShow::Type> allTypes_;
+ };
}
diff --git a/Swift/QtUI/QtSubscriptionRequestWindow.cpp b/Swift/QtUI/QtSubscriptionRequestWindow.cpp
index 43cdb50..9e1fc37 100644
--- a/Swift/QtUI/QtSubscriptionRequestWindow.cpp
+++ b/Swift/QtUI/QtSubscriptionRequestWindow.cpp
@@ -15,76 +15,76 @@
namespace Swift {
QtSubscriptionRequestWindow::QtSubscriptionRequestWindow(boost::shared_ptr<SubscriptionRequestEvent> event, QWidget* parent) : QDialog(parent), event_(event) {
- QString text = QString(tr("%1 would like to add you to their contact list.")).arg(P2QSTRING(event->getJID().toString()));
- QVBoxLayout* layout = new QVBoxLayout();
- QLabel* label = new QLabel(text, this);
- layout->addWidget(label);
- label = new QLabel(tr("Would you like to add them to your contact list and share your status when you're online?"));
- //layout->addWidget(new QLabel);
- layout->addWidget(label);
+ QString text = QString(tr("%1 would like to add you to their contact list.")).arg(P2QSTRING(event->getJID().toString()));
+ QVBoxLayout* layout = new QVBoxLayout();
+ QLabel* label = new QLabel(text, this);
+ layout->addWidget(label);
+ label = new QLabel(tr("Would you like to add them to your contact list and share your status when you're online?"));
+ //layout->addWidget(new QLabel);
+ layout->addWidget(label);
- if (event_->getConcluded()) {
- QLabel* doneLabel = new QLabel(tr("You have already replied to this request"));
- QPushButton* okButton = new QPushButton(tr("OK"), this);
- connect(okButton, SIGNAL(clicked()), this, SLOT(handleDefer()));
- layout->addWidget(doneLabel);
- layout->addWidget(okButton);
- } else {
- QPushButton* yesButton = new QPushButton(tr("Accept"), this);
- yesButton->setDefault(true);
- connect(yesButton, SIGNAL(clicked()), this, SLOT(handleYes()));
- QPushButton* noButton = new QPushButton(tr("Reject"), this);
- connect(noButton, SIGNAL(clicked()), this, SLOT(handleNo()));
- QPushButton* deferButton = new QPushButton(tr("Defer"), this);
- deferButton->setShortcut(QKeySequence(Qt::Key_Escape));
- connect(deferButton, SIGNAL(clicked()), this, SLOT(handleDefer()));
+ if (event_->getConcluded()) {
+ QLabel* doneLabel = new QLabel(tr("You have already replied to this request"));
+ QPushButton* okButton = new QPushButton(tr("OK"), this);
+ connect(okButton, SIGNAL(clicked()), this, SLOT(handleDefer()));
+ layout->addWidget(doneLabel);
+ layout->addWidget(okButton);
+ } else {
+ QPushButton* yesButton = new QPushButton(tr("Accept"), this);
+ yesButton->setDefault(true);
+ connect(yesButton, SIGNAL(clicked()), this, SLOT(handleYes()));
+ QPushButton* noButton = new QPushButton(tr("Reject"), this);
+ connect(noButton, SIGNAL(clicked()), this, SLOT(handleNo()));
+ QPushButton* deferButton = new QPushButton(tr("Defer"), this);
+ deferButton->setShortcut(QKeySequence(Qt::Key_Escape));
+ connect(deferButton, SIGNAL(clicked()), this, SLOT(handleDefer()));
- QHBoxLayout* buttonLayout = new QHBoxLayout();
- buttonLayout->addWidget(yesButton);
- buttonLayout->addWidget(noButton);
- buttonLayout->addWidget(deferButton);
- layout->addWidget(new QLabel);
- layout->addLayout(buttonLayout);
- layout->addWidget(new QLabel);
- QLabel* footer = new QLabel(tr("(If you choose to defer this choice, you will be asked again when you next login.)"));
- layout->addWidget(footer);
- }
+ QHBoxLayout* buttonLayout = new QHBoxLayout();
+ buttonLayout->addWidget(yesButton);
+ buttonLayout->addWidget(noButton);
+ buttonLayout->addWidget(deferButton);
+ layout->addWidget(new QLabel);
+ layout->addLayout(buttonLayout);
+ layout->addWidget(new QLabel);
+ QLabel* footer = new QLabel(tr("(If you choose to defer this choice, you will be asked again when you next login.)"));
+ layout->addWidget(footer);
+ }
- setLayout(layout);
+ setLayout(layout);
}
void QtSubscriptionRequestWindow::handleYes() {
- event_->accept();
- delete this;
+ event_->accept();
+ delete this;
}
void QtSubscriptionRequestWindow::handleNo() {
- event_->decline();
- delete this;
+ event_->decline();
+ delete this;
}
void QtSubscriptionRequestWindow::handleDefer() {
- event_->defer();
- delete this;
+ event_->defer();
+ delete this;
}
QtSubscriptionRequestWindow::~QtSubscriptionRequestWindow() {
- windows_.removeOne(this);
+ windows_.removeOne(this);
}
QtSubscriptionRequestWindow* QtSubscriptionRequestWindow::getWindow(boost::shared_ptr<SubscriptionRequestEvent> event, QWidget* parent) {
- foreach (QtSubscriptionRequestWindow* window, windows_) {
- if (window->getEvent() == event) {
- return window;
- }
- }
- QtSubscriptionRequestWindow* window = new QtSubscriptionRequestWindow(event, parent);
- windows_.append(window);
- return window;
+ foreach (QtSubscriptionRequestWindow* window, windows_) {
+ if (window->getEvent() == event) {
+ return window;
+ }
+ }
+ QtSubscriptionRequestWindow* window = new QtSubscriptionRequestWindow(event, parent);
+ windows_.append(window);
+ return window;
}
boost::shared_ptr<SubscriptionRequestEvent> QtSubscriptionRequestWindow::getEvent() {
- return event_;
+ return event_;
}
QList<QtSubscriptionRequestWindow*> QtSubscriptionRequestWindow::windows_;
diff --git a/Swift/QtUI/QtSubscriptionRequestWindow.h b/Swift/QtUI/QtSubscriptionRequestWindow.h
index 02932af..1a36e19 100644
--- a/Swift/QtUI/QtSubscriptionRequestWindow.h
+++ b/Swift/QtUI/QtSubscriptionRequestWindow.h
@@ -13,22 +13,22 @@
#include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h>
namespace Swift {
- class QtSubscriptionRequestWindow : public QDialog {
- Q_OBJECT
- public:
- static QtSubscriptionRequestWindow* getWindow(boost::shared_ptr<SubscriptionRequestEvent> event, QWidget* parent = 0);
- ~QtSubscriptionRequestWindow();
- boost::shared_ptr<SubscriptionRequestEvent> getEvent();
- private slots:
- void handleYes();
- void handleNo();
- void handleDefer();
- private:
- QtSubscriptionRequestWindow(boost::shared_ptr<SubscriptionRequestEvent> event, QWidget* parent = 0);
- static QList<QtSubscriptionRequestWindow*> windows_;
- boost::shared_ptr<SubscriptionRequestEvent> event_;
- /*QPushButton* yesButton_;
- QPushButton* noButton_;
- QPushButton* deferButton_;*/
- };
+ class QtSubscriptionRequestWindow : public QDialog {
+ Q_OBJECT
+ public:
+ static QtSubscriptionRequestWindow* getWindow(boost::shared_ptr<SubscriptionRequestEvent> event, QWidget* parent = 0);
+ ~QtSubscriptionRequestWindow();
+ boost::shared_ptr<SubscriptionRequestEvent> getEvent();
+ private slots:
+ void handleYes();
+ void handleNo();
+ void handleDefer();
+ private:
+ QtSubscriptionRequestWindow(boost::shared_ptr<SubscriptionRequestEvent> event, QWidget* parent = 0);
+ static QList<QtSubscriptionRequestWindow*> windows_;
+ boost::shared_ptr<SubscriptionRequestEvent> event_;
+ /*QPushButton* yesButton_;
+ QPushButton* noButton_;
+ QPushButton* deferButton_;*/
+ };
}
diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp
index 6444e0c..5e8d61c 100644
--- a/Swift/QtUI/QtSwift.cpp
+++ b/Swift/QtUI/QtSwift.cpp
@@ -85,203 +85,203 @@ namespace Swift{
#endif
po::options_description QtSwift::getOptionsDescription() {
- po::options_description result("Options");
- result.add_options()
- ("debug", "Turn on debug logging")
- ("help", "Show this help message")
- ("version", "Show version information")
- ("netbook-mode", "Use netbook mode display (unsupported)")
- ("no-tabs", "Don't manage chat windows in tabs (unsupported)")
- ("latency-debug", "Use latency debugging (unsupported)")
- ("multi-account", po::value<int>()->default_value(1), "Number of accounts to open windows for (unsupported)")
- ("start-minimized", "Don't show the login/roster window at startup")
- ("enable-jid-adhocs", "Enable AdHoc commands to custom JID's.")
- ("trellis", "Enable support for trellis layout")
+ po::options_description result("Options");
+ result.add_options()
+ ("debug", "Turn on debug logging")
+ ("help", "Show this help message")
+ ("version", "Show version information")
+ ("netbook-mode", "Use netbook mode display (unsupported)")
+ ("no-tabs", "Don't manage chat windows in tabs (unsupported)")
+ ("latency-debug", "Use latency debugging (unsupported)")
+ ("multi-account", po::value<int>()->default_value(1), "Number of accounts to open windows for (unsupported)")
+ ("start-minimized", "Don't show the login/roster window at startup")
+ ("enable-jid-adhocs", "Enable AdHoc commands to custom JID's.")
+ ("trellis", "Enable support for trellis layout")
#if QT_VERSION >= 0x040800
- ("language", po::value<std::string>(), "Use a specific language, instead of the system-wide one")
+ ("language", po::value<std::string>(), "Use a specific language, instead of the system-wide one")
#endif
- ;
- return result;
+ ;
+ return result;
}
XMLSettingsProvider* QtSwift::loadSettingsFile(const QString& fileName) {
- QFile configFile(fileName);
- if (configFile.exists() && configFile.open(QIODevice::ReadOnly)) {
- QString xmlString;
- while (!configFile.atEnd()) {
- QByteArray line = configFile.readLine();
- xmlString += line + "\n";
- }
- return new XMLSettingsProvider(Q2PSTRING(xmlString));
- }
- return new XMLSettingsProvider("");
+ QFile configFile(fileName);
+ if (configFile.exists() && configFile.open(QIODevice::ReadOnly)) {
+ QString xmlString;
+ while (!configFile.atEnd()) {
+ QByteArray line = configFile.readLine();
+ xmlString += line + "\n";
+ }
+ return new XMLSettingsProvider(Q2PSTRING(xmlString));
+ }
+ return new XMLSettingsProvider("");
}
void QtSwift::loadEmoticonsFile(const QString& fileName, std::map<std::string, std::string>& emoticons) {
- QFile file(fileName);
- if (file.exists() && file.open(QIODevice::ReadOnly)) {
- while (!file.atEnd()) {
- QString line = file.readLine();
- line.replace("\n", "");
- line.replace("\r", "");
- QStringList tokens = line.split(" ");
- if (tokens.size() == 2) {
- QString emoticonFile = tokens[1];
- if (!emoticonFile.startsWith(":/") && !emoticonFile.startsWith("qrc:/")) {
- emoticonFile = "file://" + emoticonFile;
- }
- emoticons[Q2PSTRING(tokens[0])] = Q2PSTRING(emoticonFile);
- }
- }
- }
+ QFile file(fileName);
+ if (file.exists() && file.open(QIODevice::ReadOnly)) {
+ while (!file.atEnd()) {
+ QString line = file.readLine();
+ line.replace("\n", "");
+ line.replace("\r", "");
+ QStringList tokens = line.split(" ");
+ if (tokens.size() == 2) {
+ QString emoticonFile = tokens[1];
+ if (!emoticonFile.startsWith(":/") && !emoticonFile.startsWith("qrc:/")) {
+ emoticonFile = "file://" + emoticonFile;
+ }
+ emoticons[Q2PSTRING(tokens[0])] = Q2PSTRING(emoticonFile);
+ }
+ }
+ }
}
QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMainThreadCaller_), autoUpdater_(NULL), idleDetector_(&idleQuerier_, networkFactories_.getTimerFactory(), 1000) {
- QCoreApplication::setApplicationName(SWIFT_APPLICATION_NAME);
- QCoreApplication::setOrganizationName(SWIFT_ORGANIZATION_NAME);
- QCoreApplication::setOrganizationDomain(SWIFT_ORGANIZATION_DOMAIN);
- QCoreApplication::setApplicationVersion(buildVersion);
-
- qtSettings_ = new QtSettingsProvider();
- xmlSettings_ = loadSettingsFile(P2QSTRING(pathToString(Paths::getExecutablePath() / "system-settings.xml")));
- settingsHierachy_ = new SettingsProviderHierachy();
- settingsHierachy_->addProviderToTopOfStack(xmlSettings_);
- settingsHierachy_->addProviderToTopOfStack(qtSettings_);
-
- networkFactories_.getTLSContextFactory()->setDisconnectOnCardRemoval(settingsHierachy_->getSetting(SettingConstants::DISCONNECT_ON_CARD_REMOVAL));
-
- std::map<std::string, std::string> emoticons;
- loadEmoticonsFile(":/emoticons/emoticons.txt", emoticons);
- loadEmoticonsFile(P2QSTRING(pathToString(Paths::getExecutablePath() / "emoticons.txt")), emoticons);
-
- if (options.count("netbook-mode")) {
- splitter_ = new QtSingleWindow(qtSettings_);
- } else {
- splitter_ = NULL;
- }
-
- int numberOfAccounts = 1;
- try {
- numberOfAccounts = options["multi-account"].as<int>();
- } catch (...) {
- /* This seems to fail on a Mac when the .app is launched directly (the usual path).*/
- numberOfAccounts = 1;
- }
-
- if (options.count("debug")) {
- Log::setLogLevel(Swift::Log::debug);
- }
-
- bool enableAdHocCommandOnJID = options.count("enable-jid-adhocs") > 0;
- tabs_ = NULL;
- if (options.count("no-tabs") && !splitter_) {
- tabs_ = new QtChatTabsShortcutOnlySubstitute();
- }
- else {
- tabs_ = new QtChatTabs(splitter_ != NULL, settingsHierachy_, options.count("trellis"));
- }
- bool startMinimized = options.count("start-minimized") > 0;
- applicationPathProvider_ = new PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME);
- storagesFactory_ = new FileStoragesFactory(applicationPathProvider_->getDataDir(), networkFactories_.getCryptoProvider());
- certificateStorageFactory_ = new CertificateFileStorageFactory(applicationPathProvider_->getDataDir(), tlsFactories_.getCertificateFactory(), networkFactories_.getCryptoProvider());
- chatWindowFactory_ = new QtChatWindowFactory(splitter_, settingsHierachy_, qtSettings_, tabs_, ":/themes/Default/", emoticons);
- soundPlayer_ = new QtSoundPlayer(applicationPathProvider_);
-
- // Ugly, because the dock depends on the tray, but the temporary
- // multi-account hack creates one tray per account.
- QtSystemTray* systemTray = new QtSystemTray();
- systemTrays_.push_back(systemTray);
+ QCoreApplication::setApplicationName(SWIFT_APPLICATION_NAME);
+ QCoreApplication::setOrganizationName(SWIFT_ORGANIZATION_NAME);
+ QCoreApplication::setOrganizationDomain(SWIFT_ORGANIZATION_DOMAIN);
+ QCoreApplication::setApplicationVersion(buildVersion);
+
+ qtSettings_ = new QtSettingsProvider();
+ xmlSettings_ = loadSettingsFile(P2QSTRING(pathToString(Paths::getExecutablePath() / "system-settings.xml")));
+ settingsHierachy_ = new SettingsProviderHierachy();
+ settingsHierachy_->addProviderToTopOfStack(xmlSettings_);
+ settingsHierachy_->addProviderToTopOfStack(qtSettings_);
+
+ networkFactories_.getTLSContextFactory()->setDisconnectOnCardRemoval(settingsHierachy_->getSetting(SettingConstants::DISCONNECT_ON_CARD_REMOVAL));
+
+ std::map<std::string, std::string> emoticons;
+ loadEmoticonsFile(":/emoticons/emoticons.txt", emoticons);
+ loadEmoticonsFile(P2QSTRING(pathToString(Paths::getExecutablePath() / "emoticons.txt")), emoticons);
+
+ if (options.count("netbook-mode")) {
+ splitter_ = new QtSingleWindow(qtSettings_);
+ } else {
+ splitter_ = NULL;
+ }
+
+ int numberOfAccounts = 1;
+ try {
+ numberOfAccounts = options["multi-account"].as<int>();
+ } catch (...) {
+ /* This seems to fail on a Mac when the .app is launched directly (the usual path).*/
+ numberOfAccounts = 1;
+ }
+
+ if (options.count("debug")) {
+ Log::setLogLevel(Swift::Log::debug);
+ }
+
+ bool enableAdHocCommandOnJID = options.count("enable-jid-adhocs") > 0;
+ tabs_ = NULL;
+ if (options.count("no-tabs") && !splitter_) {
+ tabs_ = new QtChatTabsShortcutOnlySubstitute();
+ }
+ else {
+ tabs_ = new QtChatTabs(splitter_ != NULL, settingsHierachy_, options.count("trellis"));
+ }
+ bool startMinimized = options.count("start-minimized") > 0;
+ applicationPathProvider_ = new PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME);
+ storagesFactory_ = new FileStoragesFactory(applicationPathProvider_->getDataDir(), networkFactories_.getCryptoProvider());
+ certificateStorageFactory_ = new CertificateFileStorageFactory(applicationPathProvider_->getDataDir(), tlsFactories_.getCertificateFactory(), networkFactories_.getCryptoProvider());
+ chatWindowFactory_ = new QtChatWindowFactory(splitter_, settingsHierachy_, qtSettings_, tabs_, ":/themes/Default/", emoticons);
+ soundPlayer_ = new QtSoundPlayer(applicationPathProvider_);
+
+ // Ugly, because the dock depends on the tray, but the temporary
+ // multi-account hack creates one tray per account.
+ QtSystemTray* systemTray = new QtSystemTray();
+ systemTrays_.push_back(systemTray);
#if defined(HAVE_GROWL)
- notifier_ = new GrowlNotifier(SWIFT_APPLICATION_NAME);
+ notifier_ = new GrowlNotifier(SWIFT_APPLICATION_NAME);
#elif defined(SWIFTEN_PLATFORM_WINDOWS)
- notifier_ = new WindowsNotifier(SWIFT_APPLICATION_NAME, applicationPathProvider_->getResourcePath("/images/logo-icon-32.png"), systemTray->getQSystemTrayIcon());
+ notifier_ = new WindowsNotifier(SWIFT_APPLICATION_NAME, applicationPathProvider_->getResourcePath("/images/logo-icon-32.png"), systemTray->getQSystemTrayIcon());
#elif defined(SWIFTEN_PLATFORM_LINUX)
- notifier_ = new FreeDesktopNotifier(SWIFT_APPLICATION_NAME);
+ notifier_ = new FreeDesktopNotifier(SWIFT_APPLICATION_NAME);
#elif defined(SWIFTEN_PLATFORM_MACOSX)
- notifier_ = new NotificationCenterNotifier();
+ notifier_ = new NotificationCenterNotifier();
#else
- notifier_ = new NullNotifier();
+ notifier_ = new NullNotifier();
#endif
#if defined(SWIFTEN_PLATFORM_MACOSX)
- dock_ = new MacOSXDock(&cocoaApplication_);
+ dock_ = new MacOSXDock(&cocoaApplication_);
#else
- dock_ = new NullDock();
+ dock_ = new NullDock();
#endif
#if defined(SWIFTEN_PLATFORM_MACOSX)
- uriHandler_ = new QtURIHandler();
+ uriHandler_ = new QtURIHandler();
#elif defined(SWIFTEN_PLATFORM_WIN32)
- uriHandler_ = new NullURIHandler();
+ uriHandler_ = new NullURIHandler();
#else
- uriHandler_ = new QtDBUSURIHandler();
+ uriHandler_ = new QtDBUSURIHandler();
#endif
- statusCache_ = new StatusCache(applicationPathProvider_);
-
- if (splitter_) {
- splitter_->show();
- }
-
- for (int i = 0; i < numberOfAccounts; i++) {
- if (i > 0) {
- // Don't add the first tray (see note above)
- systemTrays_.push_back(new QtSystemTray());
- }
- QtUIFactory* uiFactory = new QtUIFactory(settingsHierachy_, qtSettings_, tabs_, splitter_, systemTrays_[i], chatWindowFactory_, networkFactories_.getTimerFactory(), statusCache_, startMinimized, !emoticons.empty(), enableAdHocCommandOnJID);
- uiFactories_.push_back(uiFactory);
- MainController* mainController = new MainController(
- &clientMainThreadCaller_,
- &networkFactories_,
- uiFactory,
- settingsHierachy_,
- systemTrays_[i],
- soundPlayer_,
- storagesFactory_,
- certificateStorageFactory_,
- dock_,
- notifier_,
- uriHandler_,
- &idleDetector_,
- emoticons,
- options.count("latency-debug") > 0);
- mainControllers_.push_back(mainController);
- }
-
-
- // PlatformAutoUpdaterFactory autoUpdaterFactory;
- // if (autoUpdaterFactory.isSupported()) {
- // autoUpdater_ = autoUpdaterFactory.createAutoUpdater(SWIFT_APPCAST_URL);
- // autoUpdater_->checkForUpdates();
- // }
+ statusCache_ = new StatusCache(applicationPathProvider_);
+
+ if (splitter_) {
+ splitter_->show();
+ }
+
+ for (int i = 0; i < numberOfAccounts; i++) {
+ if (i > 0) {
+ // Don't add the first tray (see note above)
+ systemTrays_.push_back(new QtSystemTray());
+ }
+ QtUIFactory* uiFactory = new QtUIFactory(settingsHierachy_, qtSettings_, tabs_, splitter_, systemTrays_[i], chatWindowFactory_, networkFactories_.getTimerFactory(), statusCache_, startMinimized, !emoticons.empty(), enableAdHocCommandOnJID);
+ uiFactories_.push_back(uiFactory);
+ MainController* mainController = new MainController(
+ &clientMainThreadCaller_,
+ &networkFactories_,
+ uiFactory,
+ settingsHierachy_,
+ systemTrays_[i],
+ soundPlayer_,
+ storagesFactory_,
+ certificateStorageFactory_,
+ dock_,
+ notifier_,
+ uriHandler_,
+ &idleDetector_,
+ emoticons,
+ options.count("latency-debug") > 0);
+ mainControllers_.push_back(mainController);
+ }
+
+
+ // PlatformAutoUpdaterFactory autoUpdaterFactory;
+ // if (autoUpdaterFactory.isSupported()) {
+ // autoUpdater_ = autoUpdaterFactory.createAutoUpdater(SWIFT_APPCAST_URL);
+ // autoUpdater_->checkForUpdates();
+ // }
}
QtSwift::~QtSwift() {
- delete autoUpdater_;
- foreach (QtUIFactory* factory, uiFactories_) {
- delete factory;
- }
- foreach (MainController* controller, mainControllers_) {
- delete controller;
- }
- delete notifier_;
- foreach (QtSystemTray* tray, systemTrays_) {
- delete tray;
- }
- delete tabs_;
- delete splitter_;
- delete settingsHierachy_;
- delete qtSettings_;
- delete xmlSettings_;
- delete statusCache_;
- delete uriHandler_;
- delete dock_;
- delete soundPlayer_;
- delete chatWindowFactory_;
- delete certificateStorageFactory_;
- delete storagesFactory_;
- delete applicationPathProvider_;
+ delete autoUpdater_;
+ foreach (QtUIFactory* factory, uiFactories_) {
+ delete factory;
+ }
+ foreach (MainController* controller, mainControllers_) {
+ delete controller;
+ }
+ delete notifier_;
+ foreach (QtSystemTray* tray, systemTrays_) {
+ delete tray;
+ }
+ delete tabs_;
+ delete splitter_;
+ delete settingsHierachy_;
+ delete qtSettings_;
+ delete xmlSettings_;
+ delete statusCache_;
+ delete uriHandler_;
+ delete dock_;
+ delete soundPlayer_;
+ delete chatWindowFactory_;
+ delete certificateStorageFactory_;
+ delete storagesFactory_;
+ delete applicationPathProvider_;
}
}
diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h
index a971324..9932545 100644
--- a/Swift/QtUI/QtSwift.h
+++ b/Swift/QtUI/QtSwift.h
@@ -30,65 +30,65 @@ namespace po = boost::program_options;
class QSplitter;
namespace Swift {
- class QtUIFactory;
- class CertificateStorageFactory;
- class Dock;
- class Notifier;
- class StoragesFactory;
- class AutoUpdater;
- class ApplicationPathProvider;
- class AvatarStorage;
- class CapsStorage;
- class MainController;
- class QtSystemTray;
- class QtChatTabsBase;
- class QtChatWindowFactory;
- class QtSoundPlayer;
- class QtMUCSearchWindowFactory;
- class QtUserSearchWindowFactory;
- class EventLoop;
- class URIHandler;
- class SettingsProviderHierachy;
- class XMLSettingsProvider;
- class StatusCache;
- class QtSingleWindow;
-
- class QtSwift : public QObject {
- Q_OBJECT
- public:
- QtSwift(const po::variables_map& options);
- static po::options_description getOptionsDescription();
- ~QtSwift();
- private:
- XMLSettingsProvider* loadSettingsFile(const QString& fileName);
- void loadEmoticonsFile(const QString& fileName, std::map<std::string, std::string>& emoticons);
- private:
- QtEventLoop clientMainThreadCaller_;
- PlatformTLSFactories tlsFactories_;
- BoostNetworkFactories networkFactories_;
- QtChatWindowFactory* chatWindowFactory_;
- std::vector<MainController*> mainControllers_;
- std::vector<QtSystemTray*> systemTrays_;
- std::vector<QtUIFactory*> uiFactories_;
- QtSettingsProvider* qtSettings_;
- XMLSettingsProvider* xmlSettings_;
- SettingsProviderHierachy* settingsHierachy_;
- QtSingleWindow* splitter_;
- QtSoundPlayer* soundPlayer_;
- Dock* dock_;
- URIHandler* uriHandler_;
- QtChatTabsBase* tabs_;
- ApplicationPathProvider* applicationPathProvider_;
- StoragesFactory* storagesFactory_;
- CertificateStorageFactory* certificateStorageFactory_;
- AutoUpdater* autoUpdater_;
- Notifier* notifier_;
- StatusCache* statusCache_;
- PlatformIdleQuerier idleQuerier_;
- ActualIdleDetector idleDetector_;
+ class QtUIFactory;
+ class CertificateStorageFactory;
+ class Dock;
+ class Notifier;
+ class StoragesFactory;
+ class AutoUpdater;
+ class ApplicationPathProvider;
+ class AvatarStorage;
+ class CapsStorage;
+ class MainController;
+ class QtSystemTray;
+ class QtChatTabsBase;
+ class QtChatWindowFactory;
+ class QtSoundPlayer;
+ class QtMUCSearchWindowFactory;
+ class QtUserSearchWindowFactory;
+ class EventLoop;
+ class URIHandler;
+ class SettingsProviderHierachy;
+ class XMLSettingsProvider;
+ class StatusCache;
+ class QtSingleWindow;
+
+ class QtSwift : public QObject {
+ Q_OBJECT
+ public:
+ QtSwift(const po::variables_map& options);
+ static po::options_description getOptionsDescription();
+ ~QtSwift();
+ private:
+ XMLSettingsProvider* loadSettingsFile(const QString& fileName);
+ void loadEmoticonsFile(const QString& fileName, std::map<std::string, std::string>& emoticons);
+ private:
+ QtEventLoop clientMainThreadCaller_;
+ PlatformTLSFactories tlsFactories_;
+ BoostNetworkFactories networkFactories_;
+ QtChatWindowFactory* chatWindowFactory_;
+ std::vector<MainController*> mainControllers_;
+ std::vector<QtSystemTray*> systemTrays_;
+ std::vector<QtUIFactory*> uiFactories_;
+ QtSettingsProvider* qtSettings_;
+ XMLSettingsProvider* xmlSettings_;
+ SettingsProviderHierachy* settingsHierachy_;
+ QtSingleWindow* splitter_;
+ QtSoundPlayer* soundPlayer_;
+ Dock* dock_;
+ URIHandler* uriHandler_;
+ QtChatTabsBase* tabs_;
+ ApplicationPathProvider* applicationPathProvider_;
+ StoragesFactory* storagesFactory_;
+ CertificateStorageFactory* certificateStorageFactory_;
+ AutoUpdater* autoUpdater_;
+ Notifier* notifier_;
+ StatusCache* statusCache_;
+ PlatformIdleQuerier idleQuerier_;
+ ActualIdleDetector idleDetector_;
#if defined(SWIFTEN_PLATFORM_MACOSX)
- CocoaApplication cocoaApplication_;
- CocoaApplicationActivateHelper cocoaApplicationActivateHelper_;
+ CocoaApplication cocoaApplication_;
+ CocoaApplicationActivateHelper cocoaApplicationActivateHelper_;
#endif
- };
+ };
}
diff --git a/Swift/QtUI/QtSystemTray.cpp b/Swift/QtUI/QtSystemTray.cpp
index d268d16..55a7d43 100644
--- a/Swift/QtUI/QtSystemTray.cpp
+++ b/Swift/QtUI/QtSystemTray.cpp
@@ -20,71 +20,71 @@
namespace Swift {
QtSystemTray::QtSystemTray() : QObject(), statusType_(StatusShow::None), trayMenu_(0), onlineIcon_(":icons/online.png"), awayIcon_(":icons/away.png"), dndIcon_(":icons/dnd.png"), offlineIcon_(":icons/offline.png"), newMessageIcon_(":icons/new-chat.png"), throbberMovie_(":/icons/connecting.mng"), unreadMessages_(false), connecting_(false) {
- trayIcon_ = new QSystemTrayIcon(offlineIcon_);
- trayIcon_->setToolTip("Swift");
- connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(handleIconActivated(QSystemTrayIcon::ActivationReason)));
- connect(&throbberMovie_, SIGNAL(frameChanged(int)), this, SLOT(handleThrobberFrameChanged(int)));
+ trayIcon_ = new QSystemTrayIcon(offlineIcon_);
+ trayIcon_->setToolTip("Swift");
+ connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(handleIconActivated(QSystemTrayIcon::ActivationReason)));
+ connect(&throbberMovie_, SIGNAL(frameChanged(int)), this, SLOT(handleThrobberFrameChanged(int)));
#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
- bool isUnity = QDBusInterface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher").isValid();
- if (isUnity) {
- // Add an activation menu, because this is the only way to get the application to the
- // front on Unity. See the README for sni-qt (which handles Qt tray icons for Unity)
- trayMenu_ = new QMenu();
- QAction* showAction = new QAction(QString("Show/Hide"), this);
- connect(showAction, SIGNAL(triggered()), SIGNAL(clicked()));
- trayMenu_->addAction(showAction);
- trayIcon_->setContextMenu(trayMenu_);
- }
+ bool isUnity = QDBusInterface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher").isValid();
+ if (isUnity) {
+ // Add an activation menu, because this is the only way to get the application to the
+ // front on Unity. See the README for sni-qt (which handles Qt tray icons for Unity)
+ trayMenu_ = new QMenu();
+ QAction* showAction = new QAction(QString("Show/Hide"), this);
+ connect(showAction, SIGNAL(triggered()), SIGNAL(clicked()));
+ trayMenu_->addAction(showAction);
+ trayIcon_->setContextMenu(trayMenu_);
+ }
#endif
- trayIcon_->show();
+ trayIcon_->show();
}
QtSystemTray::~QtSystemTray() {
- delete trayMenu_;
- delete trayIcon_;
+ delete trayMenu_;
+ delete trayIcon_;
}
void QtSystemTray::setUnreadMessages(bool some) {
- unreadMessages_ = some;
- updateStatusIcon();
+ unreadMessages_ = some;
+ updateStatusIcon();
}
void QtSystemTray::handleThrobberFrameChanged(int /*frameNumber*/) {
- trayIcon_->setIcon(QIcon(throbberMovie_.currentPixmap()));
+ trayIcon_->setIcon(QIcon(throbberMovie_.currentPixmap()));
}
void QtSystemTray::setConnecting() {
- connecting_ = true;
- updateStatusIcon();
+ connecting_ = true;
+ updateStatusIcon();
}
void QtSystemTray::handleIconActivated(QSystemTrayIcon::ActivationReason reason) {
- if (reason == QSystemTrayIcon::Trigger) {
- emit clicked();
- }
+ if (reason == QSystemTrayIcon::Trigger) {
+ emit clicked();
+ }
}
void QtSystemTray::setStatusType(StatusShow::Type type) {
- connecting_ = false;
- statusType_ = type;
- updateStatusIcon();
+ connecting_ = false;
+ statusType_ = type;
+ updateStatusIcon();
}
void QtSystemTray::updateStatusIcon() {
- throbberMovie_.stop();
- if (unreadMessages_) {
- trayIcon_->setIcon(newMessageIcon_);
- } else if (connecting_) {
- throbberMovie_.start();
- } else {
- switch (statusType_) {
- case StatusShow::Online : trayIcon_->setIcon(onlineIcon_);break;
- case StatusShow::FFC : trayIcon_->setIcon(onlineIcon_);break;
- case StatusShow::Away : trayIcon_->setIcon(awayIcon_);break;
- case StatusShow::XA : trayIcon_->setIcon(awayIcon_);break;
- case StatusShow::DND : trayIcon_->setIcon(dndIcon_);break;
- case StatusShow::None : trayIcon_->setIcon(offlineIcon_);break;
- }
- }
+ throbberMovie_.stop();
+ if (unreadMessages_) {
+ trayIcon_->setIcon(newMessageIcon_);
+ } else if (connecting_) {
+ throbberMovie_.start();
+ } else {
+ switch (statusType_) {
+ case StatusShow::Online : trayIcon_->setIcon(onlineIcon_);break;
+ case StatusShow::FFC : trayIcon_->setIcon(onlineIcon_);break;
+ case StatusShow::Away : trayIcon_->setIcon(awayIcon_);break;
+ case StatusShow::XA : trayIcon_->setIcon(awayIcon_);break;
+ case StatusShow::DND : trayIcon_->setIcon(dndIcon_);break;
+ case StatusShow::None : trayIcon_->setIcon(offlineIcon_);break;
+ }
+ }
}
}
diff --git a/Swift/QtUI/QtSystemTray.h b/Swift/QtUI/QtSystemTray.h
index b1dffd0..ba2c5cb 100644
--- a/Swift/QtUI/QtSystemTray.h
+++ b/Swift/QtUI/QtSystemTray.h
@@ -16,35 +16,35 @@ class QMenu;
namespace Swift {
- class QtSystemTray : public QObject, public SystemTray {
- Q_OBJECT
- public:
- QtSystemTray();
- ~QtSystemTray();
- void setUnreadMessages(bool some);
- void setStatusType(StatusShow::Type type);
- void setConnecting();
- QSystemTrayIcon* getQSystemTrayIcon() {
- return trayIcon_;
- }
+ class QtSystemTray : public QObject, public SystemTray {
+ Q_OBJECT
+ public:
+ QtSystemTray();
+ ~QtSystemTray();
+ void setUnreadMessages(bool some);
+ void setStatusType(StatusShow::Type type);
+ void setConnecting();
+ QSystemTrayIcon* getQSystemTrayIcon() {
+ return trayIcon_;
+ }
- signals:
- void clicked();
- private slots:
- void handleIconActivated(QSystemTrayIcon::ActivationReason reason);
- void handleThrobberFrameChanged(int);
- private:
- void updateStatusIcon();
- StatusShow::Type statusType_;
- QSystemTrayIcon* trayIcon_;
- QMenu* trayMenu_;
- QIcon onlineIcon_;
- QIcon awayIcon_;
- QIcon dndIcon_;
- QIcon offlineIcon_;
- QIcon newMessageIcon_;
- QMovie throbberMovie_;
- bool unreadMessages_;
- bool connecting_;
- };
+ signals:
+ void clicked();
+ private slots:
+ void handleIconActivated(QSystemTrayIcon::ActivationReason reason);
+ void handleThrobberFrameChanged(int);
+ private:
+ void updateStatusIcon();
+ StatusShow::Type statusType_;
+ QSystemTrayIcon* trayIcon_;
+ QMenu* trayMenu_;
+ QIcon onlineIcon_;
+ QIcon awayIcon_;
+ QIcon dndIcon_;
+ QIcon offlineIcon_;
+ QIcon newMessageIcon_;
+ QMovie throbberMovie_;
+ bool unreadMessages_;
+ bool connecting_;
+ };
}
diff --git a/Swift/QtUI/QtTabWidget.cpp b/Swift/QtUI/QtTabWidget.cpp
index ca9ea5d..9f353d7 100644
--- a/Swift/QtUI/QtTabWidget.cpp
+++ b/Swift/QtUI/QtTabWidget.cpp
@@ -17,10 +17,10 @@ QtTabWidget::~QtTabWidget() {
}
QTabBar* QtTabWidget::tabBar() {
- return QTabWidget::tabBar();
+ return QTabWidget::tabBar();
}
void QtTabWidget::setTabBar(QTabBar* tabBar) {
- QTabWidget::setTabBar(tabBar);
+ QTabWidget::setTabBar(tabBar);
}
}
diff --git a/Swift/QtUI/QtTabWidget.h b/Swift/QtUI/QtTabWidget.h
index 0a723e2..de1a846 100644
--- a/Swift/QtUI/QtTabWidget.h
+++ b/Swift/QtUI/QtTabWidget.h
@@ -9,13 +9,13 @@
#include <QTabWidget>
namespace Swift {
- class QtTabWidget : public QTabWidget {
- Q_OBJECT
- public:
- QtTabWidget(QWidget* parent);
- virtual ~QtTabWidget();
+ class QtTabWidget : public QTabWidget {
+ Q_OBJECT
+ public:
+ QtTabWidget(QWidget* parent);
+ virtual ~QtTabWidget();
- QTabBar* tabBar();
- void setTabBar(QTabBar* tabBar);
- };
+ QTabBar* tabBar();
+ void setTabBar(QTabBar* tabBar);
+ };
}
diff --git a/Swift/QtUI/QtTabbable.cpp b/Swift/QtUI/QtTabbable.cpp
index 0e08343..bad6315 100644
--- a/Swift/QtUI/QtTabbable.cpp
+++ b/Swift/QtUI/QtTabbable.cpp
@@ -23,47 +23,47 @@ QtTabbable::QtTabbable() : QWidget() {
}
QtTabbable::~QtTabbable() {
- emit windowClosing();
+ emit windowClosing();
}
bool QtTabbable::isWidgetSelected() {
- /*isActiveWindow() shouldn't be necessary, but I don't trust it as far as I can throw it*/
- if (!isActiveWindow()) {
- return false;
- }
- QtChatTabs* parent = qobject_cast<QtChatTabs*>(window());
- return parent ? parent->getCurrentTab() == this : isAncestorOf(QApplication::focusWidget());
+ /*isActiveWindow() shouldn't be necessary, but I don't trust it as far as I can throw it*/
+ if (!isActiveWindow()) {
+ return false;
+ }
+ QtChatTabs* parent = qobject_cast<QtChatTabs*>(window());
+ return parent ? parent->getCurrentTab() == this : isAncestorOf(QApplication::focusWidget());
}
bool QtTabbable::event(QEvent* event) {
- QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
- if (keyEvent) {
- // According to Qt's focus documentation, one can only override CTRL+TAB via reimplementing QWidget::event().
- if (keyEvent->modifiers().testFlag(QtUtilities::ctrlHardwareKeyModifier) && keyEvent->key() == Qt::Key_Tab) {
- // Only handle KeyRelease event as Linux also generate KeyPress event in case of CTRL+TAB being pressed
- // in the roster of a MUC.
- if (keyEvent->type() == QEvent::KeyRelease) {
- emit requestNextTab();
- }
- return true;
- }
+ QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
+ if (keyEvent) {
+ // According to Qt's focus documentation, one can only override CTRL+TAB via reimplementing QWidget::event().
+ if (keyEvent->modifiers().testFlag(QtUtilities::ctrlHardwareKeyModifier) && keyEvent->key() == Qt::Key_Tab) {
+ // Only handle KeyRelease event as Linux also generate KeyPress event in case of CTRL+TAB being pressed
+ // in the roster of a MUC.
+ if (keyEvent->type() == QEvent::KeyRelease) {
+ emit requestNextTab();
+ }
+ return true;
+ }
#ifdef SWIFTEN_PLATFORM_LINUX
- else if (keyEvent->modifiers().testFlag(QtUtilities::ctrlHardwareKeyModifier) && keyEvent->key() == Qt::Key_Backtab && keyEvent->type() != QEvent::KeyRelease) {
+ else if (keyEvent->modifiers().testFlag(QtUtilities::ctrlHardwareKeyModifier) && keyEvent->key() == Qt::Key_Backtab && keyEvent->type() != QEvent::KeyRelease) {
#else
- else if (keyEvent->modifiers().testFlag(QtUtilities::ctrlHardwareKeyModifier) && keyEvent->key() == Qt::Key_Backtab) {
+ else if (keyEvent->modifiers().testFlag(QtUtilities::ctrlHardwareKeyModifier) && keyEvent->key() == Qt::Key_Backtab) {
#endif
#ifdef SWIFTEN_PLATFORM_WINDOWS
- // Windows emits both the KeyPress and KeyRelease events.
- if (keyEvent->type() == QEvent::KeyPress) {
+ // Windows emits both the KeyPress and KeyRelease events.
+ if (keyEvent->type() == QEvent::KeyPress) {
#else
- if (keyEvent->type() != QEvent::ShortcutOverride) {
+ if (keyEvent->type() != QEvent::ShortcutOverride) {
#endif
- emit requestPreviousTab();
- }
- return true;
- }
- }
- return QWidget::event(event);
+ emit requestPreviousTab();
+ }
+ return true;
+ }
+ }
+ return QWidget::event(event);
}
}
diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h
index db83ba9..c2d0961 100644
--- a/Swift/QtUI/QtTabbable.h
+++ b/Swift/QtUI/QtTabbable.h
@@ -11,29 +11,29 @@
#include <QWidget>
namespace Swift {
- class QtTabbable : public QWidget {
- Q_OBJECT
- public:
- enum AlertType {NoActivity, WaitingActivity, ImpendingActivity};
- virtual ~QtTabbable();
- bool isWidgetSelected();
- virtual AlertType getWidgetAlertState() {return NoActivity;}
- virtual int getCount() {return 0;}
- virtual std::string getID() const = 0;
+ class QtTabbable : public QWidget {
+ Q_OBJECT
+ public:
+ enum AlertType {NoActivity, WaitingActivity, ImpendingActivity};
+ virtual ~QtTabbable();
+ bool isWidgetSelected();
+ virtual AlertType getWidgetAlertState() {return NoActivity;}
+ virtual int getCount() {return 0;}
+ virtual std::string getID() const = 0;
- protected:
- QtTabbable();
- bool event(QEvent* event);
+ protected:
+ QtTabbable();
+ bool event(QEvent* event);
- signals:
- void titleUpdated();
- void countUpdated();
- void windowClosing();
- void windowOpening();
- void wantsToActivate();
- void requestPreviousTab();
- void requestNextTab();
- void requestActiveTab();
- void requestFlash();
- };
+ signals:
+ void titleUpdated();
+ void countUpdated();
+ void windowClosing();
+ void windowOpening();
+ void wantsToActivate();
+ void requestPreviousTab();
+ void requestNextTab();
+ void requestActiveTab();
+ void requestFlash();
+ };
}
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp
index adf3878..d3ba914 100644
--- a/Swift/QtUI/QtTextEdit.cpp
+++ b/Swift/QtUI/QtTextEdit.cpp
@@ -30,202 +30,202 @@
namespace Swift {
QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit(parent), checker_(NULL), highlighter_(NULL) {
- connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged()));
- settings_ = settings;
+ connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged()));
+ settings_ = settings;
#ifdef HAVE_SPELLCHECKER
- setUpSpellChecker();
+ setUpSpellChecker();
#endif
- handleTextChanged();
- QTextOption textOption = document()->defaultTextOption();
- textOption.setWrapMode(QTextOption::WordWrap);
- document()->setDefaultTextOption(textOption);
+ handleTextChanged();
+ QTextOption textOption = document()->defaultTextOption();
+ textOption.setWrapMode(QTextOption::WordWrap);
+ document()->setDefaultTextOption(textOption);
}
QtTextEdit::~QtTextEdit() {
- delete checker_;
+ delete checker_;
}
void QtTextEdit::keyPressEvent(QKeyEvent* event) {
- int key = event->key();
- Qt::KeyboardModifiers modifiers = event->modifiers();
- if ((key == Qt::Key_Enter || key == Qt::Key_Return)
- && (modifiers == Qt::NoModifier || modifiers == Qt::KeypadModifier)) {
- emit returnPressed();
- }
- else if (((key == Qt::Key_PageUp || key == Qt::Key_PageDown) && modifiers == Qt::ShiftModifier)
- || (key == Qt::Key_C && modifiers == Qt::ControlModifier && textCursor().selectedText().isEmpty())
- || (key == Qt::Key_W && modifiers == Qt::ControlModifier)
- || (key == Qt::Key_PageUp && modifiers == Qt::ControlModifier)
- || (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier)
- || (key == Qt::Key_Tab && modifiers == Qt::ControlModifier)
- || (key == Qt::Key_A && modifiers == Qt::AltModifier)
- || (key == Qt::Key_Tab)
- ) {
- emit unhandledKeyPressEvent(event);
- }
- else if ((key == Qt::Key_Up)
- || (key == Qt::Key_Down)) {
- emit unhandledKeyPressEvent(event);
- QTextEdit::keyPressEvent(event);
- }
- else if ((key == Qt::Key_K && modifiers == QtUtilities::ctrlHardwareKeyModifier)) {
- QTextCursor cursor = textCursor();
- cursor.setPosition(toPlainText().size(), QTextCursor::KeepAnchor);
- cursor.removeSelectedText();
- }
- else {
- QTextEdit::keyPressEvent(event);
- }
+ int key = event->key();
+ Qt::KeyboardModifiers modifiers = event->modifiers();
+ if ((key == Qt::Key_Enter || key == Qt::Key_Return)
+ && (modifiers == Qt::NoModifier || modifiers == Qt::KeypadModifier)) {
+ emit returnPressed();
+ }
+ else if (((key == Qt::Key_PageUp || key == Qt::Key_PageDown) && modifiers == Qt::ShiftModifier)
+ || (key == Qt::Key_C && modifiers == Qt::ControlModifier && textCursor().selectedText().isEmpty())
+ || (key == Qt::Key_W && modifiers == Qt::ControlModifier)
+ || (key == Qt::Key_PageUp && modifiers == Qt::ControlModifier)
+ || (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier)
+ || (key == Qt::Key_Tab && modifiers == Qt::ControlModifier)
+ || (key == Qt::Key_A && modifiers == Qt::AltModifier)
+ || (key == Qt::Key_Tab)
+ ) {
+ emit unhandledKeyPressEvent(event);
+ }
+ else if ((key == Qt::Key_Up)
+ || (key == Qt::Key_Down)) {
+ emit unhandledKeyPressEvent(event);
+ QTextEdit::keyPressEvent(event);
+ }
+ else if ((key == Qt::Key_K && modifiers == QtUtilities::ctrlHardwareKeyModifier)) {
+ QTextCursor cursor = textCursor();
+ cursor.setPosition(toPlainText().size(), QTextCursor::KeepAnchor);
+ cursor.removeSelectedText();
+ }
+ else {
+ QTextEdit::keyPressEvent(event);
+ }
}
void QtTextEdit::focusInEvent(QFocusEvent* event) {
- receivedFocus();
- QTextEdit::focusInEvent(event);
+ receivedFocus();
+ QTextEdit::focusInEvent(event);
}
void QtTextEdit::focusOutEvent(QFocusEvent* event) {
- lostFocus();
- QTextEdit::focusOutEvent(event);
+ lostFocus();
+ QTextEdit::focusOutEvent(event);
}
void QtTextEdit::handleTextChanged() {
- QSize previous(maximumSize());
- setMaximumSize(QSize(maximumWidth(), sizeHint().height()));
- if (previous != maximumSize()) {
- updateGeometry();
- }
+ QSize previous(maximumSize());
+ setMaximumSize(QSize(maximumWidth(), sizeHint().height()));
+ if (previous != maximumSize()) {
+ updateGeometry();
+ }
}
void QtTextEdit::replaceMisspelledWord(const QString& word, int cursorPosition) {
- QTextCursor cursor = textCursor();
- PositionPair wordPosition = getWordFromCursor(cursorPosition);
- cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
- cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
- QTextCharFormat normalFormat;
- cursor.insertText(word, normalFormat);
+ QTextCursor cursor = textCursor();
+ PositionPair wordPosition = getWordFromCursor(cursorPosition);
+ cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
+ cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
+ QTextCharFormat normalFormat;
+ cursor.insertText(word, normalFormat);
}
PositionPair QtTextEdit::getWordFromCursor(int cursorPosition) {
- PositionPairList misspelledPositions = highlighter_->getMisspelledPositions();
- for (PositionPairList::iterator it = misspelledPositions.begin(); it != misspelledPositions.end(); ++it) {
- if (cursorPosition >= boost::get<0>(*it) && cursorPosition <= boost::get<1>(*it)) {
- return *it;
- }
- }
- return boost::make_tuple(-1,-1);
+ PositionPairList misspelledPositions = highlighter_->getMisspelledPositions();
+ for (PositionPairList::iterator it = misspelledPositions.begin(); it != misspelledPositions.end(); ++it) {
+ if (cursorPosition >= boost::get<0>(*it) && cursorPosition <= boost::get<1>(*it)) {
+ return *it;
+ }
+ }
+ return boost::make_tuple(-1,-1);
}
QSize QtTextEdit::sizeHint() const {
- QSize hint = document()->size().toSize();
- QMargins margins = contentsMargins();
- return hint + QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
+ QSize hint = document()->size().toSize();
+ QMargins margins = contentsMargins();
+ return hint + QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
}
void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) {
- QMenu* menu = createStandardContextMenu();
- QTextCursor cursor = cursorForPosition(event->pos());
+ QMenu* menu = createStandardContextMenu();
+ QTextCursor cursor = cursorForPosition(event->pos());
#ifdef HAVE_SPELLCHECKER
- QAction* insertPoint = menu->actions().first();
- QAction* settingsAction = new QAction(tr("Spell Checker Options"), menu);
- menu->insertAction(insertPoint, settingsAction);
- menu->insertAction(insertPoint, menu->addSeparator());
- addSuggestions(menu, event);
- QAction* result = menu->exec(event->globalPos());
- if (result == settingsAction) {
- spellCheckerSettingsWindow();
- }
- for (std::vector<QAction*>::iterator it = replaceWordActions_.begin(); it != replaceWordActions_.end(); ++it) {
- if (*it == result) {
- replaceMisspelledWord((*it)->text(), cursor.position());
- }
- }
+ QAction* insertPoint = menu->actions().first();
+ QAction* settingsAction = new QAction(tr("Spell Checker Options"), menu);
+ menu->insertAction(insertPoint, settingsAction);
+ menu->insertAction(insertPoint, menu->addSeparator());
+ addSuggestions(menu, event);
+ QAction* result = menu->exec(event->globalPos());
+ if (result == settingsAction) {
+ spellCheckerSettingsWindow();
+ }
+ for (std::vector<QAction*>::iterator it = replaceWordActions_.begin(); it != replaceWordActions_.end(); ++it) {
+ if (*it == result) {
+ replaceMisspelledWord((*it)->text(), cursor.position());
+ }
+ }
#else
- menu->exec(event->globalPos());
+ menu->exec(event->globalPos());
#endif
- delete menu;
+ delete menu;
}
void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event)
{
- replaceWordActions_.clear();
- if (checker_ && highlighter_) {
- QAction* insertPoint = menu->actions().first();
- QTextCursor cursor = cursorForPosition(event->pos());
- PositionPair wordPosition = getWordFromCursor(cursor.position());
- if (boost::get<0>(wordPosition) < 0) {
- // The click was executed outside a spellable word so no
- // suggestions are necessary
- return;
- }
- cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
- cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
- std::vector<std::string> wordList;
- checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList);
- if (wordList.size() == 0) {
- QAction* noSuggestions = new QAction(tr("No Suggestions"), menu);
- noSuggestions->setDisabled(true);
- menu->insertAction(insertPoint, noSuggestions);
- }
- else {
- for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) {
- QAction* wordAction = new QAction(it->c_str(), menu);
- menu->insertAction(insertPoint, wordAction);
- replaceWordActions_.push_back(wordAction);
- }
- }
- menu->insertAction(insertPoint, menu->addSeparator());
- }
+ replaceWordActions_.clear();
+ if (checker_ && highlighter_) {
+ QAction* insertPoint = menu->actions().first();
+ QTextCursor cursor = cursorForPosition(event->pos());
+ PositionPair wordPosition = getWordFromCursor(cursor.position());
+ if (boost::get<0>(wordPosition) < 0) {
+ // The click was executed outside a spellable word so no
+ // suggestions are necessary
+ return;
+ }
+ cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
+ cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
+ std::vector<std::string> wordList;
+ checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList);
+ if (wordList.size() == 0) {
+ QAction* noSuggestions = new QAction(tr("No Suggestions"), menu);
+ noSuggestions->setDisabled(true);
+ menu->insertAction(insertPoint, noSuggestions);
+ }
+ else {
+ for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) {
+ QAction* wordAction = new QAction(it->c_str(), menu);
+ menu->insertAction(insertPoint, wordAction);
+ replaceWordActions_.push_back(wordAction);
+ }
+ }
+ menu->insertAction(insertPoint, menu->addSeparator());
+ }
}
#ifdef HAVE_SPELLCHECKER
void QtTextEdit::setUpSpellChecker()
{
- delete highlighter_;
- highlighter_ = NULL;
- delete checker_;
- checker_ = NULL;
- if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) {
- std::string dictPath = settings_->getSetting(SettingConstants::DICT_PATH);
- std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE);
- checker_ = SpellCheckerFactory().createSpellChecker(dictPath + dictFile);
- if (checker_) {
- highlighter_ = new QtSpellCheckHighlighter(document(), checker_);
- }
- else {
- // Spellchecking is not working, as we did not get a valid checker from the factory. Disable spellchecking.
- SWIFT_LOG(warning) << "Spellchecking is currently misconfigured in Swift (e.g. missing dictionary or broken dictionary file). Disable spellchecking." << std::endl;
- settings_->storeSetting(SettingConstants::SPELL_CHECKER, false);
- }
-
- }
+ delete highlighter_;
+ highlighter_ = NULL;
+ delete checker_;
+ checker_ = NULL;
+ if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) {
+ std::string dictPath = settings_->getSetting(SettingConstants::DICT_PATH);
+ std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE);
+ checker_ = SpellCheckerFactory().createSpellChecker(dictPath + dictFile);
+ if (checker_) {
+ highlighter_ = new QtSpellCheckHighlighter(document(), checker_);
+ }
+ else {
+ // Spellchecking is not working, as we did not get a valid checker from the factory. Disable spellchecking.
+ SWIFT_LOG(warning) << "Spellchecking is currently misconfigured in Swift (e.g. missing dictionary or broken dictionary file). Disable spellchecking." << std::endl;
+ settings_->storeSetting(SettingConstants::SPELL_CHECKER, false);
+ }
+
+ }
}
#endif
void QtTextEdit::spellCheckerSettingsWindow() {
- if (!spellCheckerWindow_) {
- spellCheckerWindow_ = new QtSpellCheckerWindow(settings_);
- settings_->onSettingChanged.connect(boost::bind(&QtTextEdit::handleSettingChanged, this, _1));
- spellCheckerWindow_->show();
- }
- else {
- spellCheckerWindow_->show();
- spellCheckerWindow_->raise();
- spellCheckerWindow_->activateWindow();
- }
+ if (!spellCheckerWindow_) {
+ spellCheckerWindow_ = new QtSpellCheckerWindow(settings_);
+ settings_->onSettingChanged.connect(boost::bind(&QtTextEdit::handleSettingChanged, this, _1));
+ spellCheckerWindow_->show();
+ }
+ else {
+ spellCheckerWindow_->show();
+ spellCheckerWindow_->raise();
+ spellCheckerWindow_->activateWindow();
+ }
}
void QtTextEdit::handleSettingChanged(const std::string& settings) {
- if (settings == SettingConstants::SPELL_CHECKER.getKey()
- || settings == SettingConstants::DICT_PATH.getKey()
- || settings == SettingConstants::DICT_FILE.getKey()) {
+ if (settings == SettingConstants::SPELL_CHECKER.getKey()
+ || settings == SettingConstants::DICT_PATH.getKey()
+ || settings == SettingConstants::DICT_FILE.getKey()) {
#ifdef HAVE_SPELLCHECKER
- setUpSpellChecker();
- if (highlighter_) {
- highlighter_->rehighlight();
- }
+ setUpSpellChecker();
+ if (highlighter_) {
+ highlighter_->rehighlight();
+ }
#endif
- }
+ }
}
}
diff --git a/Swift/QtUI/QtTextEdit.h b/Swift/QtUI/QtTextEdit.h
index 67826ba..f03699b 100644
--- a/Swift/QtUI/QtTextEdit.h
+++ b/Swift/QtUI/QtTextEdit.h
@@ -17,47 +17,47 @@
#include <Swift/QtUI/QtSpellCheckHighlighter.h>
namespace Swift {
- class SpellChecker;
- class QtSpellCheckerWindow;
-
- class QtTextEdit : public QTextEdit {
- Q_OBJECT
- public:
- QtTextEdit(SettingsProvider* settings, QWidget* parent = 0);
- virtual ~QtTextEdit();
- virtual QSize sizeHint() const;
-
- signals:
- void wordCorrected(QString& word);
- void returnPressed();
- void unhandledKeyPressEvent(QKeyEvent* event);
- void receivedFocus();
- void lostFocus();
-
- public slots:
- void handleSettingChanged(const std::string& settings);
-
- protected:
- virtual void keyPressEvent(QKeyEvent* event);
- virtual void focusInEvent(QFocusEvent* event);
- virtual void focusOutEvent(QFocusEvent* event);
- virtual void contextMenuEvent(QContextMenuEvent* event);
-
- private slots:
- void handleTextChanged();
-
- private:
- void addSuggestions(QMenu* menu, QContextMenuEvent* event);
- void replaceMisspelledWord(const QString& word, int cursorPosition);
- void setUpSpellChecker();
- void spellCheckerSettingsWindow();
- PositionPair getWordFromCursor(int cursorPosition);
-
- private:
- SpellChecker* checker_;
- QtSpellCheckHighlighter* highlighter_;
- std::vector<QAction*> replaceWordActions_;
- SettingsProvider* settings_;
- QPointer<QtSpellCheckerWindow> spellCheckerWindow_;
- };
+ class SpellChecker;
+ class QtSpellCheckerWindow;
+
+ class QtTextEdit : public QTextEdit {
+ Q_OBJECT
+ public:
+ QtTextEdit(SettingsProvider* settings, QWidget* parent = 0);
+ virtual ~QtTextEdit();
+ virtual QSize sizeHint() const;
+
+ signals:
+ void wordCorrected(QString& word);
+ void returnPressed();
+ void unhandledKeyPressEvent(QKeyEvent* event);
+ void receivedFocus();
+ void lostFocus();
+
+ public slots:
+ void handleSettingChanged(const std::string& settings);
+
+ protected:
+ virtual void keyPressEvent(QKeyEvent* event);
+ virtual void focusInEvent(QFocusEvent* event);
+ virtual void focusOutEvent(QFocusEvent* event);
+ virtual void contextMenuEvent(QContextMenuEvent* event);
+
+ private slots:
+ void handleTextChanged();
+
+ private:
+ void addSuggestions(QMenu* menu, QContextMenuEvent* event);
+ void replaceMisspelledWord(const QString& word, int cursorPosition);
+ void setUpSpellChecker();
+ void spellCheckerSettingsWindow();
+ PositionPair getWordFromCursor(int cursorPosition);
+
+ private:
+ SpellChecker* checker_;
+ QtSpellCheckHighlighter* highlighter_;
+ std::vector<QAction*> replaceWordActions_;
+ SettingsProvider* settings_;
+ QPointer<QtSpellCheckerWindow> spellCheckerWindow_;
+ };
}
diff --git a/Swift/QtUI/QtTranslator.h b/Swift/QtUI/QtTranslator.h
index b74ea3e..4254324 100644
--- a/Swift/QtUI/QtTranslator.h
+++ b/Swift/QtUI/QtTranslator.h
@@ -11,15 +11,15 @@
#include <Swift/Controllers/Translator.h>
class QtTranslator : public Swift::Translator {
- public:
- QtTranslator() {
- }
+ public:
+ QtTranslator() {
+ }
- virtual std::string translate(const std::string& text, const std::string& context) {
+ virtual std::string translate(const std::string& text, const std::string& context) {
#if QT_VERSION >= 0x050000
- return std::string(QCoreApplication::translate(context.c_str(), text.c_str(), 0).toUtf8());
+ return std::string(QCoreApplication::translate(context.c_str(), text.c_str(), 0).toUtf8());
#else
- return std::string(QCoreApplication::translate(context.c_str(), text.c_str(), 0, QCoreApplication::UnicodeUTF8).toUtf8());
+ return std::string(QCoreApplication::translate(context.c_str(), text.c_str(), 0, QCoreApplication::UnicodeUTF8).toUtf8());
#endif
- }
+ }
};
diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp
index 0cde4e1..a1321bd 100644
--- a/Swift/QtUI/QtUIFactory.cpp
+++ b/Swift/QtUI/QtUIFactory.cpp
@@ -39,148 +39,148 @@
namespace Swift {
QtUIFactory::QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabsBase* tabs, QtSingleWindow* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, StatusCache* statusCache, bool startMinimized, bool emoticonsExist, bool enableAdHocCommandOnJID) : settings(settings), qtOnlySettings(qtOnlySettings), tabsBase(tabs), netbookSplitter(netbookSplitter), systemTray(systemTray), chatWindowFactory(chatWindowFactory), timerFactory_(timerFactory), lastMainWindow(NULL), loginWindow(NULL), statusCache(statusCache), startMinimized(startMinimized), emoticonsExist_(emoticonsExist), enableAdHocCommandOnJID_(enableAdHocCommandOnJID) {
- chatFontSize = settings->getSetting(QtUISettingConstants::CHATWINDOW_FONT_SIZE);
- historyFontSize_ = settings->getSetting(QtUISettingConstants::HISTORYWINDOW_FONT_SIZE);
- this->tabs = dynamic_cast<QtChatTabs*>(tabsBase);
+ chatFontSize = settings->getSetting(QtUISettingConstants::CHATWINDOW_FONT_SIZE);
+ historyFontSize_ = settings->getSetting(QtUISettingConstants::HISTORYWINDOW_FONT_SIZE);
+ this->tabs = dynamic_cast<QtChatTabs*>(tabsBase);
}
XMLConsoleWidget* QtUIFactory::createXMLConsoleWidget() {
- QtXMLConsoleWidget* widget = new QtXMLConsoleWidget();
- tabsBase->addTab(widget);
- showTabs();
- widget->show();
- return widget;
+ QtXMLConsoleWidget* widget = new QtXMLConsoleWidget();
+ tabsBase->addTab(widget);
+ showTabs();
+ widget->show();
+ return widget;
}
HistoryWindow* QtUIFactory::createHistoryWindow(UIEventStream* uiEventStream) {
- QtHistoryWindow* window = new QtHistoryWindow(settings, uiEventStream);
- tabsBase->addTab(window);
- showTabs();
- connect(window, SIGNAL(fontResized(int)), this, SLOT(handleHistoryWindowFontResized(int)));
+ QtHistoryWindow* window = new QtHistoryWindow(settings, uiEventStream);
+ tabsBase->addTab(window);
+ showTabs();
+ connect(window, SIGNAL(fontResized(int)), this, SLOT(handleHistoryWindowFontResized(int)));
- window->handleFontResized(historyFontSize_);
- window->show();
- return window;
+ window->handleFontResized(historyFontSize_);
+ window->show();
+ return window;
}
void QtUIFactory::handleHistoryWindowFontResized(int size) {
- historyFontSize_ = size;
- settings->storeSetting(QtUISettingConstants::HISTORYWINDOW_FONT_SIZE, size);
+ historyFontSize_ = size;
+ settings->storeSetting(QtUISettingConstants::HISTORYWINDOW_FONT_SIZE, size);
}
FileTransferListWidget* QtUIFactory::createFileTransferListWidget() {
- QtFileTransferListWidget* widget = new QtFileTransferListWidget();
- tabsBase->addTab(widget);
- showTabs();
- widget->show();
- return widget;
+ QtFileTransferListWidget* widget = new QtFileTransferListWidget();
+ tabsBase->addTab(widget);
+ showTabs();
+ widget->show();
+ return widget;
}
MainWindow* QtUIFactory::createMainWindow(UIEventStream* eventStream) {
- lastMainWindow = new QtMainWindow(settings, eventStream, loginWindow->getMenus(), statusCache, emoticonsExist_, enableAdHocCommandOnJID_);
- if (tabs) {
- tabs->setViewMenu(lastMainWindow->getMenus()[0]);
- }
- return lastMainWindow;
+ lastMainWindow = new QtMainWindow(settings, eventStream, loginWindow->getMenus(), statusCache, emoticonsExist_, enableAdHocCommandOnJID_);
+ if (tabs) {
+ tabs->setViewMenu(lastMainWindow->getMenus()[0]);
+ }
+ return lastMainWindow;
}
LoginWindow* QtUIFactory::createLoginWindow(UIEventStream* eventStream) {
- loginWindow = new QtLoginWindow(eventStream, settings, timerFactory_);
- if (netbookSplitter) {
- netbookSplitter->insertAtFront(loginWindow);
- }
- connect(systemTray, SIGNAL(clicked()), loginWindow, SLOT(toggleBringToFront()));
+ loginWindow = new QtLoginWindow(eventStream, settings, timerFactory_);
+ if (netbookSplitter) {
+ netbookSplitter->insertAtFront(loginWindow);
+ }
+ connect(systemTray, SIGNAL(clicked()), loginWindow, SLOT(toggleBringToFront()));
#ifndef SWIFT_MOBILE
- QVariant loginWindowGeometryVariant = qtOnlySettings->getQSettings()->value("loginWindowGeometry");
- if (loginWindowGeometryVariant.isValid()) {
- loginWindow->restoreGeometry(loginWindowGeometryVariant.toByteArray());
- }
- connect(loginWindow, SIGNAL(geometryChanged()), this, SLOT(handleLoginWindowGeometryChanged()));
- if (startMinimized) loginWindow->hide();
+ QVariant loginWindowGeometryVariant = qtOnlySettings->getQSettings()->value("loginWindowGeometry");
+ if (loginWindowGeometryVariant.isValid()) {
+ loginWindow->restoreGeometry(loginWindowGeometryVariant.toByteArray());
+ }
+ connect(loginWindow, SIGNAL(geometryChanged()), this, SLOT(handleLoginWindowGeometryChanged()));
+ if (startMinimized) loginWindow->hide();
#endif
- return loginWindow;
+ return loginWindow;
}
void QtUIFactory::handleLoginWindowGeometryChanged() {
- qtOnlySettings->getQSettings()->setValue("loginWindowGeometry", loginWindow->saveGeometry());
+ qtOnlySettings->getQSettings()->setValue("loginWindowGeometry", loginWindow->saveGeometry());
}
EventWindow* QtUIFactory::createEventWindow() {
- return lastMainWindow->getEventWindow();
+ return lastMainWindow->getEventWindow();
}
ChatListWindow* QtUIFactory::createChatListWindow(UIEventStream*) {
- return lastMainWindow->getChatListWindow();
+ return lastMainWindow->getChatListWindow();
}
MUCSearchWindow* QtUIFactory::createMUCSearchWindow() {
- return new QtMUCSearchWindow();
+ return new QtMUCSearchWindow();
}
ChatWindow* QtUIFactory::createChatWindow(const JID& contact, UIEventStream* eventStream) {
- QtChatWindow* window = dynamic_cast<QtChatWindow*>(chatWindowFactory->createChatWindow(contact, eventStream));
- chatWindows.push_back(window);
- std::vector<QPointer<QtChatWindow> > deletions;
- foreach (QPointer<QtChatWindow> existingWindow, chatWindows) {
- if (existingWindow.isNull()) {
- deletions.push_back(existingWindow);
- } else {
- connect(window, SIGNAL(fontResized(int)), existingWindow, SLOT(handleFontResized(int)));
- connect(existingWindow, SIGNAL(fontResized(int)), window, SLOT(handleFontResized(int)));
- }
- }
- foreach (QPointer<QtChatWindow> deletedWindow, deletions) {
- chatWindows.erase(std::remove(chatWindows.begin(), chatWindows.end(), deletedWindow), chatWindows.end());
- }
- connect(window, SIGNAL(fontResized(int)), this, SLOT(handleChatWindowFontResized(int)));
- window->handleFontResized(chatFontSize);
- return window;
+ QtChatWindow* window = dynamic_cast<QtChatWindow*>(chatWindowFactory->createChatWindow(contact, eventStream));
+ chatWindows.push_back(window);
+ std::vector<QPointer<QtChatWindow> > deletions;
+ foreach (QPointer<QtChatWindow> existingWindow, chatWindows) {
+ if (existingWindow.isNull()) {
+ deletions.push_back(existingWindow);
+ } else {
+ connect(window, SIGNAL(fontResized(int)), existingWindow, SLOT(handleFontResized(int)));
+ connect(existingWindow, SIGNAL(fontResized(int)), window, SLOT(handleFontResized(int)));
+ }
+ }
+ foreach (QPointer<QtChatWindow> deletedWindow, deletions) {
+ chatWindows.erase(std::remove(chatWindows.begin(), chatWindows.end(), deletedWindow), chatWindows.end());
+ }
+ connect(window, SIGNAL(fontResized(int)), this, SLOT(handleChatWindowFontResized(int)));
+ window->handleFontResized(chatFontSize);
+ return window;
}
void QtUIFactory::handleChatWindowFontResized(int size) {
- chatFontSize = size;
- settings->storeSetting(QtUISettingConstants::CHATWINDOW_FONT_SIZE, size);
+ chatFontSize = size;
+ settings->storeSetting(QtUISettingConstants::CHATWINDOW_FONT_SIZE, size);
}
UserSearchWindow* QtUIFactory::createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups) {
- return new QtUserSearchWindow(eventStream, type, groups, qtOnlySettings);
+ return new QtUserSearchWindow(eventStream, type, groups, qtOnlySettings);
}
JoinMUCWindow* QtUIFactory::createJoinMUCWindow(UIEventStream* uiEventStream) {
- return new QtJoinMUCWindow(uiEventStream);
+ return new QtJoinMUCWindow(uiEventStream);
}
ProfileWindow* QtUIFactory::createProfileWindow() {
- return new QtProfileWindow();
+ return new QtProfileWindow();
}
ContactEditWindow* QtUIFactory::createContactEditWindow() {
- return new QtContactEditWindow();
+ return new QtContactEditWindow();
}
WhiteboardWindow* QtUIFactory::createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession) {
- return new QtWhiteboardWindow(whiteboardSession);
+ return new QtWhiteboardWindow(whiteboardSession);
}
HighlightEditorWindow* QtUIFactory::createHighlightEditorWindow() {
- return new QtHighlightEditor(qtOnlySettings);
+ return new QtHighlightEditor(qtOnlySettings);
}
BlockListEditorWidget *QtUIFactory::createBlockListEditorWidget() {
- return new QtBlockListEditorWindow();
+ return new QtBlockListEditorWindow();
}
AdHocCommandWindow* QtUIFactory::createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) {
- return new QtAdHocCommandWindow(command);
+ return new QtAdHocCommandWindow(command);
}
void QtUIFactory::showTabs() {
- if (tabs) {
- if (!tabs->isVisible()) {
- tabs->show();
- }
- }
+ if (tabs) {
+ if (!tabs->isVisible()) {
+ tabs->show();
+ }
+ }
}
}
diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h
index 1d935bc..c72bf63 100644
--- a/Swift/QtUI/QtUIFactory.h
+++ b/Swift/QtUI/QtUIFactory.h
@@ -14,70 +14,70 @@
class QSplitter;
namespace Swift {
- class QtSettingsProvider;
- class SettingsProviderHierachy;
- class QtChatTabsBase;
- class QtChatTabs;
- class QtSystemTray;
- class QtLoginWindow;
- class QtMainWindow;
- class QtChatTheme;
- class QtChatWindowFactory;
- class QtChatWindow;
- class TimerFactory;
- class historyWindow_;
- class WhiteboardSession;
- class StatusCache;
- class QtSingleWindow;
+ class QtSettingsProvider;
+ class SettingsProviderHierachy;
+ class QtChatTabsBase;
+ class QtChatTabs;
+ class QtSystemTray;
+ class QtLoginWindow;
+ class QtMainWindow;
+ class QtChatTheme;
+ class QtChatWindowFactory;
+ class QtChatWindow;
+ class TimerFactory;
+ class historyWindow_;
+ class WhiteboardSession;
+ class StatusCache;
+ class QtSingleWindow;
- class QtUIFactory : public QObject, public UIFactory {
- Q_OBJECT
- public:
- QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabsBase* tabs, QtSingleWindow* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, StatusCache* statusCache, bool startMinimized, bool emoticonsExist, bool enableAdHocCommandOnJID);
+ class QtUIFactory : public QObject, public UIFactory {
+ Q_OBJECT
+ public:
+ QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabsBase* tabs, QtSingleWindow* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, StatusCache* statusCache, bool startMinimized, bool emoticonsExist, bool enableAdHocCommandOnJID);
- virtual XMLConsoleWidget* createXMLConsoleWidget();
- virtual HistoryWindow* createHistoryWindow(UIEventStream*);
- virtual MainWindow* createMainWindow(UIEventStream* eventStream);
- virtual LoginWindow* createLoginWindow(UIEventStream* eventStream);
- virtual EventWindow* createEventWindow();
- virtual ChatListWindow* createChatListWindow(UIEventStream*);
- virtual MUCSearchWindow* createMUCSearchWindow();
- virtual ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream);
- virtual UserSearchWindow* createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups);
- virtual JoinMUCWindow* createJoinMUCWindow(UIEventStream* uiEventStream);
- virtual ProfileWindow* createProfileWindow();
- virtual ContactEditWindow* createContactEditWindow();
- virtual FileTransferListWidget* createFileTransferListWidget();
- virtual WhiteboardWindow* createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession);
- virtual HighlightEditorWindow* createHighlightEditorWindow();
- virtual BlockListEditorWidget* createBlockListEditorWidget();
- virtual AdHocCommandWindow* createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command);
+ virtual XMLConsoleWidget* createXMLConsoleWidget();
+ virtual HistoryWindow* createHistoryWindow(UIEventStream*);
+ virtual MainWindow* createMainWindow(UIEventStream* eventStream);
+ virtual LoginWindow* createLoginWindow(UIEventStream* eventStream);
+ virtual EventWindow* createEventWindow();
+ virtual ChatListWindow* createChatListWindow(UIEventStream*);
+ virtual MUCSearchWindow* createMUCSearchWindow();
+ virtual ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream);
+ virtual UserSearchWindow* createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups);
+ virtual JoinMUCWindow* createJoinMUCWindow(UIEventStream* uiEventStream);
+ virtual ProfileWindow* createProfileWindow();
+ virtual ContactEditWindow* createContactEditWindow();
+ virtual FileTransferListWidget* createFileTransferListWidget();
+ virtual WhiteboardWindow* createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession);
+ virtual HighlightEditorWindow* createHighlightEditorWindow();
+ virtual BlockListEditorWidget* createBlockListEditorWidget();
+ virtual AdHocCommandWindow* createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command);
- private slots:
- void handleLoginWindowGeometryChanged();
- void handleChatWindowFontResized(int);
- void handleHistoryWindowFontResized(int);
+ private slots:
+ void handleLoginWindowGeometryChanged();
+ void handleChatWindowFontResized(int);
+ void handleHistoryWindowFontResized(int);
- private:
- void showTabs();
+ private:
+ void showTabs();
- private:
- SettingsProviderHierachy* settings;
- QtSettingsProvider* qtOnlySettings;
- QtChatTabsBase* tabsBase;
- QtChatTabs* tabs;
- QtSingleWindow* netbookSplitter;
- QtSystemTray* systemTray;
- QtChatWindowFactory* chatWindowFactory;
- TimerFactory* timerFactory_;
- QtMainWindow* lastMainWindow;
- QtLoginWindow* loginWindow;
- StatusCache* statusCache;
- std::vector<QPointer<QtChatWindow> > chatWindows;
- bool startMinimized;
- int chatFontSize;
- int historyFontSize_;
- bool emoticonsExist_;
- bool enableAdHocCommandOnJID_;
- };
+ private:
+ SettingsProviderHierachy* settings;
+ QtSettingsProvider* qtOnlySettings;
+ QtChatTabsBase* tabsBase;
+ QtChatTabs* tabs;
+ QtSingleWindow* netbookSplitter;
+ QtSystemTray* systemTray;
+ QtChatWindowFactory* chatWindowFactory;
+ TimerFactory* timerFactory_;
+ QtMainWindow* lastMainWindow;
+ QtLoginWindow* loginWindow;
+ StatusCache* statusCache;
+ std::vector<QPointer<QtChatWindow> > chatWindows;
+ bool startMinimized;
+ int chatFontSize;
+ int historyFontSize_;
+ bool emoticonsExist_;
+ bool enableAdHocCommandOnJID_;
+ };
}
diff --git a/Swift/QtUI/QtUISettingConstants.h b/Swift/QtUI/QtUISettingConstants.h
index 4c17c0d..3e7291f 100644
--- a/Swift/QtUI/QtUISettingConstants.h
+++ b/Swift/QtUI/QtUISettingConstants.h
@@ -9,16 +9,16 @@
#include <Swift/Controllers/Settings/SettingsProvider.h>
namespace Swift {
- class QtUISettingConstants {
- public:
- static const SettingsProvider::Setting<bool> COMPACT_ROSTER;
- static const SettingsProvider::Setting<std::string> CLICKTHROUGH_BANNER;
- static const SettingsProvider::Setting<int> CURRENT_ROSTER_TAB;
- static const SettingsProvider::Setting<bool> SHOW_NICK_IN_ROSTER_HEADER;
- static const SettingsProvider::Setting<int> CHATWINDOW_FONT_SIZE;
- static const SettingsProvider::Setting<int> HISTORYWINDOW_FONT_SIZE;
- static const SettingsProvider::Setting<bool> SHOW_EMOTICONS;
- static const SettingsProvider::Setting<bool> USE_PLAIN_CHATS;
- static const SettingsProvider::Setting<bool> USE_SCREENREADER;
- };
+ class QtUISettingConstants {
+ public:
+ static const SettingsProvider::Setting<bool> COMPACT_ROSTER;
+ static const SettingsProvider::Setting<std::string> CLICKTHROUGH_BANNER;
+ static const SettingsProvider::Setting<int> CURRENT_ROSTER_TAB;
+ static const SettingsProvider::Setting<bool> SHOW_NICK_IN_ROSTER_HEADER;
+ static const SettingsProvider::Setting<int> CHATWINDOW_FONT_SIZE;
+ static const SettingsProvider::Setting<int> HISTORYWINDOW_FONT_SIZE;
+ static const SettingsProvider::Setting<bool> SHOW_EMOTICONS;
+ static const SettingsProvider::Setting<bool> USE_PLAIN_CHATS;
+ static const SettingsProvider::Setting<bool> USE_SCREENREADER;
+ };
}
diff --git a/Swift/QtUI/QtURIHandler.cpp b/Swift/QtUI/QtURIHandler.cpp
index e3b9a53..24bd328 100644
--- a/Swift/QtUI/QtURIHandler.cpp
+++ b/Swift/QtUI/QtURIHandler.cpp
@@ -15,16 +15,16 @@
using namespace Swift;
QtURIHandler::QtURIHandler() {
- qApp->installEventFilter(this);
+ qApp->installEventFilter(this);
}
bool QtURIHandler::eventFilter(QObject*, QEvent* event) {
- if (event->type() == QEvent::FileOpen) {
- QFileOpenEvent* fileOpenEvent = static_cast<QFileOpenEvent*>(event);
- if (fileOpenEvent->url().scheme() == "xmpp") {
- onURI(Q2PSTRING(fileOpenEvent->url().toString()));
- return true;
- }
- }
- return false;
+ if (event->type() == QEvent::FileOpen) {
+ QFileOpenEvent* fileOpenEvent = static_cast<QFileOpenEvent*>(event);
+ if (fileOpenEvent->url().scheme() == "xmpp") {
+ onURI(Q2PSTRING(fileOpenEvent->url().toString()));
+ return true;
+ }
+ }
+ return false;
}
diff --git a/Swift/QtUI/QtURIHandler.h b/Swift/QtUI/QtURIHandler.h
index 1abcac6..309e55b 100644
--- a/Swift/QtUI/QtURIHandler.h
+++ b/Swift/QtUI/QtURIHandler.h
@@ -13,11 +13,11 @@
class QUrl;
namespace Swift {
- class QtURIHandler : public QObject, public URIHandler {
- public:
- QtURIHandler();
+ class QtURIHandler : public QObject, public URIHandler {
+ public:
+ QtURIHandler();
- private:
- bool eventFilter(QObject* obj, QEvent* event);
- };
+ private:
+ bool eventFilter(QObject* obj, QEvent* event);
+ };
}
diff --git a/Swift/QtUI/QtURLValidator.cpp b/Swift/QtUI/QtURLValidator.cpp
index 45bf528..8017710 100644
--- a/Swift/QtUI/QtURLValidator.cpp
+++ b/Swift/QtUI/QtURLValidator.cpp
@@ -16,10 +16,10 @@ QtURLValidator::QtURLValidator(QObject* parent) : QValidator(parent) {
}
QValidator::State QtURLValidator::validate(QString& input, int&) const {
- URL url = URL::fromString(Q2PSTRING(input));
- bool valid = !url.isEmpty();
- valid &= (url.getScheme() == "http" || url.getScheme() == "https");
- return valid ? Acceptable : Intermediate;
+ URL url = URL::fromString(Q2PSTRING(input));
+ bool valid = !url.isEmpty();
+ valid &= (url.getScheme() == "http" || url.getScheme() == "https");
+ return valid ? Acceptable : Intermediate;
}
}
diff --git a/Swift/QtUI/QtURLValidator.h b/Swift/QtUI/QtURLValidator.h
index b374ef4..887828a 100644
--- a/Swift/QtUI/QtURLValidator.h
+++ b/Swift/QtUI/QtURLValidator.h
@@ -7,11 +7,11 @@
#include <QValidator>
namespace Swift {
- class QtURLValidator : public QValidator {
- Q_OBJECT
- public:
- QtURLValidator(QObject* parent);
- virtual QValidator::State validate(QString& input, int& pos) const;
- };
+ class QtURLValidator : public QValidator {
+ Q_OBJECT
+ public:
+ QtURLValidator(QObject* parent);
+ virtual QValidator::State validate(QString& input, int& pos) const;
+ };
}
diff --git a/Swift/QtUI/QtUtilities.cpp b/Swift/QtUI/QtUtilities.cpp
index b4b1b09..401af17 100644
--- a/Swift/QtUI/QtUtilities.cpp
+++ b/Swift/QtUI/QtUtilities.cpp
@@ -22,23 +22,23 @@ namespace QtUtilities {
void setX11Resource(QWidget* widget, const QString& c) {
#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC) && QT_VERSION < 0x050000
- char res_class[] = SWIFT_APPLICATION_NAME;
- XClassHint hint;
- QByteArray resName = (QString(SWIFT_APPLICATION_NAME) + "-" + c).toUtf8();
- hint.res_name = resName.data();
- hint.res_class = res_class;
- XSetClassHint(widget->x11Info().display(), widget->winId(), &hint);
+ char res_class[] = SWIFT_APPLICATION_NAME;
+ XClassHint hint;
+ QByteArray resName = (QString(SWIFT_APPLICATION_NAME) + "-" + c).toUtf8();
+ hint.res_name = resName.data();
+ hint.res_class = res_class;
+ XSetClassHint(widget->x11Info().display(), widget->winId(), &hint);
#else
- (void) widget;
- (void) c;
+ (void) widget;
+ (void) c;
#endif
}
QString htmlEscape(const QString& s) {
#if QT_VERSION >= 0x050000
- return s.toHtmlEscaped();
+ return s.toHtmlEscaped();
#else
- return Qt::escape(s);
+ return Qt::escape(s);
#endif
}
diff --git a/Swift/QtUI/QtUtilities.h b/Swift/QtUI/QtUtilities.h
index 4d71d7c..ad58499 100644
--- a/Swift/QtUI/QtUtilities.h
+++ b/Swift/QtUI/QtUtilities.h
@@ -12,11 +12,11 @@ class QString;
#include <QKeyEvent>
namespace QtUtilities {
- void setX11Resource(QWidget* widget, const QString& c);
- QString htmlEscape(const QString& s);
- #ifdef SWIFTEN_PLATFORM_MACOSX
- const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::MetaModifier;
- #else
- const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::ControlModifier;
- #endif
+ void setX11Resource(QWidget* widget, const QString& c);
+ QString htmlEscape(const QString& s);
+ #ifdef SWIFTEN_PLATFORM_MACOSX
+ const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::MetaModifier;
+ #else
+ const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::ControlModifier;
+ #endif
}
diff --git a/Swift/QtUI/QtVCardWidget/QtCloseButton.cpp b/Swift/QtUI/QtVCardWidget/QtCloseButton.cpp
index 9d79859..ec7941c 100644
--- a/Swift/QtUI/QtVCardWidget/QtCloseButton.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtCloseButton.cpp
@@ -24,28 +24,28 @@ QtCloseButton::QtCloseButton(QWidget *parent) : QAbstractButton(parent) {
}
QSize QtCloseButton::sizeHint() const {
- return QSize(style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0), style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, 0));
+ return QSize(style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0), style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, 0));
}
bool QtCloseButton::event(QEvent *e) {
- if (e->type() == QEvent::Enter || e->type() == QEvent::Leave) {
- update();
- }
- return QAbstractButton::event(e);
+ if (e->type() == QEvent::Enter || e->type() == QEvent::Leave) {
+ update();
+ }
+ return QAbstractButton::event(e);
}
void QtCloseButton::paintEvent(QPaintEvent *) {
- QPainter painter(this);
- painter.setRenderHint(QPainter::HighQualityAntialiasing);
- QStyleOption opt;
- opt.init(this);
- opt.state |= QStyle::State_AutoRaise;
- if (underMouse() && !isDown()) {
- opt.state |= QStyle::State_Raised;
- } else if (isDown()) {
- opt.state |= QStyle::State_Sunken;
- }
- style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &painter, this);
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::HighQualityAntialiasing);
+ QStyleOption opt;
+ opt.init(this);
+ opt.state |= QStyle::State_AutoRaise;
+ if (underMouse() && !isDown()) {
+ opt.state |= QStyle::State_Raised;
+ } else if (isDown()) {
+ opt.state |= QStyle::State_Sunken;
+ }
+ style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &painter, this);
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtCloseButton.h b/Swift/QtUI/QtVCardWidget/QtCloseButton.h
index cb92e12..1ba31a0 100644
--- a/Swift/QtUI/QtVCardWidget/QtCloseButton.h
+++ b/Swift/QtUI/QtVCardWidget/QtCloseButton.h
@@ -10,15 +10,15 @@
namespace Swift {
- class QtCloseButton : public QAbstractButton {
- Q_OBJECT
- public:
- explicit QtCloseButton(QWidget *parent = 0);
- virtual QSize sizeHint() const;
+ class QtCloseButton : public QAbstractButton {
+ Q_OBJECT
+ public:
+ explicit QtCloseButton(QWidget *parent = 0);
+ virtual QSize sizeHint() const;
- protected:
- virtual bool event(QEvent *e);
- virtual void paintEvent(QPaintEvent* );
- };
+ protected:
+ virtual bool event(QEvent *e);
+ virtual void paintEvent(QPaintEvent* );
+ };
}
diff --git a/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp
index 73575f6..67c79a9 100644
--- a/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp
@@ -24,42 +24,42 @@ QtRemovableItemDelegate::QtRemovableItemDelegate(const QStyle* style) : style(st
}
void QtRemovableItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- QStyleOption opt;
- opt.state = option.state;
- opt.state |= QStyle::State_AutoRaise;
- if (option.state.testFlag(QStyle::State_MouseOver)) {
- opt.state |= QStyle::State_Raised;
- }
- opt.rect = option.rect;
- painter->save();
- painter->fillRect(option.rect, option.state & QStyle::State_Selected ? option.palette.highlight() : option.palette.base());
- if (index.data().toString().isEmpty()) {
+ QStyleOption opt;
+ opt.state = option.state;
+ opt.state |= QStyle::State_AutoRaise;
+ if (option.state.testFlag(QStyle::State_MouseOver)) {
+ opt.state |= QStyle::State_Raised;
+ }
+ opt.rect = option.rect;
+ painter->save();
+ painter->fillRect(option.rect, option.state & QStyle::State_Selected ? option.palette.highlight() : option.palette.base());
+ if (index.data().toString().isEmpty()) {
#ifdef SWIFTEN_PLATFORM_MACOSX
- // workaround for Qt not painting relative to the cell we're in, on OS X
- int height = style->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0);
- painter->translate(option.rect.x(), option.rect.y() + (option.rect.height() - height)/2);
+ // workaround for Qt not painting relative to the cell we're in, on OS X
+ int height = style->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0);
+ painter->translate(option.rect.x(), option.rect.y() + (option.rect.height() - height)/2);
#endif
- style->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, painter);
- }
- painter->restore();
+ style->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, painter);
+ }
+ painter->restore();
}
QWidget* QtRemovableItemDelegate::createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const {
- return NULL;
+ return NULL;
}
bool QtRemovableItemDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) {
- if (index.data().toString().isEmpty() && event->type() == QEvent::MouseButtonRelease) {
- model->removeRow(index.row());
- return true;
- } else {
- return QItemDelegate::editorEvent(event, model, option, index);
- }
+ if (index.data().toString().isEmpty() && event->type() == QEvent::MouseButtonRelease) {
+ model->removeRow(index.row());
+ return true;
+ } else {
+ return QItemDelegate::editorEvent(event, model, option, index);
+ }
}
QSize QtRemovableItemDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const {
- QSize size(style->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0) + 2, style->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, 0) + 2);
- return size;
+ QSize size(style->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0) + 2, style->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, 0) + 2);
+ return size;
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h
index 75137e1..ea9e0b2 100644
--- a/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h
+++ b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h
@@ -11,18 +11,18 @@
namespace Swift {
class QtRemovableItemDelegate : public QItemDelegate {
- public:
- QtRemovableItemDelegate(const QStyle* style);
+ public:
+ QtRemovableItemDelegate(const QStyle* style);
- virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex&) const;
- virtual QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const;
- virtual QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const;
+ virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex&) const;
+ virtual QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const;
+ virtual QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const;
- protected:
- virtual bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index);
+ protected:
+ virtual bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index);
- private:
- const QStyle* style;
+ private:
+ const QStyle* style;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp
index 3492cb9..9eef970 100644
--- a/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp
@@ -16,43 +16,43 @@
namespace Swift {
QtResizableLineEdit::QtResizableLineEdit(QWidget* parent) :
- QLineEdit(parent), editable(false) {
- connect(this, SIGNAL(textChanged(QString)), SLOT(textChanged(QString)));
- setMinimumWidth(30);
+ QLineEdit(parent), editable(false) {
+ connect(this, SIGNAL(textChanged(QString)), SLOT(textChanged(QString)));
+ setMinimumWidth(30);
}
QtResizableLineEdit::~QtResizableLineEdit() {
}
bool QtResizableLineEdit::isEditable() const {
- return editable;
+ return editable;
}
void QtResizableLineEdit::setEditable(const bool editable) {
- this->editable = editable;
- if (editable) {
- setReadOnly(false);
- } else {
- setReadOnly(true);
- }
+ this->editable = editable;
+ if (editable) {
+ setReadOnly(false);
+ } else {
+ setReadOnly(true);
+ }
}
QSize QtResizableLineEdit::sizeHint() const {
- int horizontalMargin = 10;
- int verticalMargin = 6;
- QSize textDimensions;
+ int horizontalMargin = 10;
+ int verticalMargin = 6;
+ QSize textDimensions;
#if QT_VERSION >= 0x040700
- textDimensions = fontMetrics().boundingRect(text().isEmpty() ? placeholderText() : text()).size();
+ textDimensions = fontMetrics().boundingRect(text().isEmpty() ? placeholderText() : text()).size();
#else
- textDimensions = fontMetrics().boundingRect(text().isEmpty() ? QString(" ") : text()).size();
+ textDimensions = fontMetrics().boundingRect(text().isEmpty() ? QString(" ") : text()).size();
#endif
- textDimensions.setWidth(textDimensions.width() + horizontalMargin);
- textDimensions.setHeight(textDimensions.height() + verticalMargin);
- return textDimensions;
+ textDimensions.setWidth(textDimensions.width() + horizontalMargin);
+ textDimensions.setHeight(textDimensions.height() + verticalMargin);
+ return textDimensions;
}
void QtResizableLineEdit::textChanged(QString) {
- updateGeometry();
+ updateGeometry();
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h
index 9022d38..47c6f3e 100644
--- a/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h
+++ b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h
@@ -10,24 +10,24 @@
namespace Swift {
- class QtResizableLineEdit : public QLineEdit {
- Q_OBJECT
- Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+ class QtResizableLineEdit : public QLineEdit {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
- public:
- explicit QtResizableLineEdit(QWidget* parent = 0);
- ~QtResizableLineEdit();
+ public:
+ explicit QtResizableLineEdit(QWidget* parent = 0);
+ ~QtResizableLineEdit();
- bool isEditable() const;
- void setEditable(const bool);
+ bool isEditable() const;
+ void setEditable(const bool);
- virtual QSize sizeHint() const;
+ virtual QSize sizeHint() const;
- private slots:
- void textChanged(QString);
+ private slots:
+ void textChanged(QString);
- private:
- bool editable;
- };
+ private:
+ bool editable;
+ };
}
diff --git a/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp b/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
index 7036f84..ed36580 100644
--- a/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
@@ -18,14 +18,14 @@
namespace Swift {
QtTagComboBox::QtTagComboBox(QWidget* parent) : QComboBox(parent) {
- setEditable(false);
- displayModel = new QStandardItemModel(this);
- displayItem = new QStandardItem();
- displayItem->setText("");
- displayModel->insertRow(0, displayItem);
- editMenu = new QMenu(this);
- this->setModel(displayModel);
- editable = true;
+ setEditable(false);
+ displayModel = new QStandardItemModel(this);
+ displayItem = new QStandardItem();
+ displayItem->setText("");
+ displayModel->insertRow(0, displayItem);
+ editMenu = new QMenu(this);
+ this->setModel(displayModel);
+ editable = true;
}
QtTagComboBox::~QtTagComboBox() {
@@ -33,40 +33,40 @@ QtTagComboBox::~QtTagComboBox() {
}
bool QtTagComboBox::isEditable() const {
- return editable;
+ return editable;
}
void QtTagComboBox::setEditable(const bool editable) {
- this->editable = editable;
+ this->editable = editable;
}
void QtTagComboBox::addTag(const QString &id, const QString &label) {
- QAction* tagAction = new QAction(editMenu);
- tagAction->setText(label);
- tagAction->setCheckable(true);
- tagAction->setData(QString(id));
- editMenu->addAction(tagAction);
+ QAction* tagAction = new QAction(editMenu);
+ tagAction->setText(label);
+ tagAction->setCheckable(true);
+ tagAction->setData(QString(id));
+ editMenu->addAction(tagAction);
}
void QtTagComboBox::setTag(const QString &id, bool value) {
- QList<QAction*> tagActions = editMenu->actions();
- foreach(QAction* action, tagActions) {
- if (action->data() == id) {
- action->setChecked(value);
- updateDisplayItem();
- return;
- }
- }
+ QList<QAction*> tagActions = editMenu->actions();
+ foreach(QAction* action, tagActions) {
+ if (action->data() == id) {
+ action->setChecked(value);
+ updateDisplayItem();
+ return;
+ }
+ }
}
bool QtTagComboBox::isTagSet(const QString &id) const {
- QList<QAction*> tagActions = editMenu->actions();
- foreach(QAction* action, tagActions) {
- if (action->data() == id) {
- return action->isChecked();
- }
- }
- return false;
+ QList<QAction*> tagActions = editMenu->actions();
+ foreach(QAction* action, tagActions) {
+ if (action->data() == id) {
+ return action->isChecked();
+ }
+ }
+ return false;
}
void QtTagComboBox::showPopup() {
@@ -78,31 +78,31 @@ void QtTagComboBox::hidePopup() {
}
bool QtTagComboBox::event(QEvent* event) {
- if (event->type() == QEvent::MouseButtonPress ||
- event->type() == QEvent::KeyRelease) {
- if (!editable) return true;
-
- QPoint p = mapToGlobal(QPoint(0,0));
- p += QPoint(0, height());
- editMenu->exec(p);
- updateDisplayItem();
- return true;
- }
- return QComboBox::event(event);
+ if (event->type() == QEvent::MouseButtonPress ||
+ event->type() == QEvent::KeyRelease) {
+ if (!editable) return true;
+
+ QPoint p = mapToGlobal(QPoint(0,0));
+ p += QPoint(0, height());
+ editMenu->exec(p);
+ updateDisplayItem();
+ return true;
+ }
+ return QComboBox::event(event);
}
void QtTagComboBox::updateDisplayItem() {
- QList<QAction*> tagActions = editMenu->actions();
- QString text = "";
- foreach(QAction* action, tagActions) {
- if (action->isChecked()) {
- if (text != "") {
- text += ", ";
- }
- text += action->text();
- }
- }
- setItemText(0, text);
+ QList<QAction*> tagActions = editMenu->actions();
+ QString text = "";
+ foreach(QAction* action, tagActions) {
+ if (action->isChecked()) {
+ if (text != "") {
+ text += ", ";
+ }
+ text += action->text();
+ }
+ }
+ setItemText(0, text);
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtTagComboBox.h b/Swift/QtUI/QtVCardWidget/QtTagComboBox.h
index 37a60af..f08f136 100644
--- a/Swift/QtUI/QtVCardWidget/QtTagComboBox.h
+++ b/Swift/QtUI/QtVCardWidget/QtTagComboBox.h
@@ -14,33 +14,33 @@
namespace Swift {
class QtTagComboBox : public QComboBox {
- Q_OBJECT
- Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
- public:
- explicit QtTagComboBox(QWidget* parent = 0);
- ~QtTagComboBox();
+ public:
+ explicit QtTagComboBox(QWidget* parent = 0);
+ ~QtTagComboBox();
- bool isEditable() const;
- void setEditable(const bool);
+ bool isEditable() const;
+ void setEditable(const bool);
- void addTag(const QString& id, const QString& label);
- void setTag(const QString& id, bool value);
- bool isTagSet(const QString& id) const;
+ void addTag(const QString& id, const QString& label);
+ void setTag(const QString& id, bool value);
+ bool isTagSet(const QString& id) const;
- virtual void showPopup();
- virtual void hidePopup();
+ virtual void showPopup();
+ virtual void hidePopup();
- virtual bool event(QEvent* event);
+ virtual bool event(QEvent* event);
- private:
- void updateDisplayItem();
+ private:
+ void updateDisplayItem();
- private:
- bool editable;
- QStandardItemModel* displayModel;
- QStandardItem* displayItem;
- QMenu* editMenu;
+ private:
+ bool editable;
+ QStandardItemModel* displayModel;
+ QStandardItem* displayItem;
+ QMenu* editMenu;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp
index 5f9fddf..57bb2cd 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp
@@ -20,163 +20,163 @@
namespace Swift {
QtVCardAddressField::QtVCardAddressField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Address")), streetLineEdit(NULL), poboxLineEdit(NULL), addressextLineEdit(NULL), cityLineEdit(NULL), pocodeLineEdit(NULL), regionLineEdit(NULL), countryLineEdit(NULL), textFieldGridLayout(NULL), textFieldGridLayoutItem(NULL), deliveryTypeLabel(NULL), domesticRadioButton(NULL), internationalRadioButton(NULL), buttonGroup(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Address")), streetLineEdit(NULL), poboxLineEdit(NULL), addressextLineEdit(NULL), cityLineEdit(NULL), pocodeLineEdit(NULL), regionLineEdit(NULL), countryLineEdit(NULL), textFieldGridLayout(NULL), textFieldGridLayoutItem(NULL), deliveryTypeLabel(NULL), domesticRadioButton(NULL), internationalRadioButton(NULL), buttonGroup(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardAddressField::~QtVCardAddressField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardAddressField::setupContentWidgets() {
- textFieldGridLayout = new QGridLayout();
+ textFieldGridLayout = new QGridLayout();
- streetLineEdit = new QtResizableLineEdit(this);
- textFieldGridLayout->addWidget(streetLineEdit, 0, 0, Qt::AlignVCenter);
+ streetLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(streetLineEdit, 0, 0, Qt::AlignVCenter);
- poboxLineEdit = new QtResizableLineEdit(this);
- textFieldGridLayout->addWidget(poboxLineEdit, 0, 1, Qt::AlignVCenter);
+ poboxLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(poboxLineEdit, 0, 1, Qt::AlignVCenter);
- addressextLineEdit = new QtResizableLineEdit(this);
- textFieldGridLayout->addWidget(addressextLineEdit, 1, 0, Qt::AlignVCenter);
+ addressextLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(addressextLineEdit, 1, 0, Qt::AlignVCenter);
- cityLineEdit = new QtResizableLineEdit(this);
- textFieldGridLayout->addWidget(cityLineEdit, 2, 0, Qt::AlignVCenter);
+ cityLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(cityLineEdit, 2, 0, Qt::AlignVCenter);
- pocodeLineEdit = new QtResizableLineEdit(this);
- textFieldGridLayout->addWidget(pocodeLineEdit, 2, 1, Qt::AlignVCenter);
+ pocodeLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(pocodeLineEdit, 2, 1, Qt::AlignVCenter);
- regionLineEdit = new QtResizableLineEdit(this);
- textFieldGridLayout->addWidget(regionLineEdit, 3, 0, Qt::AlignVCenter);
+ regionLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(regionLineEdit, 3, 0, Qt::AlignVCenter);
- countryLineEdit = new QtResizableLineEdit(this);
- textFieldGridLayout->addWidget(countryLineEdit, 4, 0, Qt::AlignVCenter);
- textFieldGridLayout->setVerticalSpacing(2);
- getGridLayout()->addLayout(textFieldGridLayout, getGridLayout()->rowCount()-1, 2, 5, 2, Qt::AlignVCenter);
- textFieldGridLayoutItem = getGridLayout()->itemAtPosition(getGridLayout()->rowCount()-1, 2);
+ countryLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(countryLineEdit, 4, 0, Qt::AlignVCenter);
+ textFieldGridLayout->setVerticalSpacing(2);
+ getGridLayout()->addLayout(textFieldGridLayout, getGridLayout()->rowCount()-1, 2, 5, 2, Qt::AlignVCenter);
+ textFieldGridLayoutItem = getGridLayout()->itemAtPosition(getGridLayout()->rowCount()-1, 2);
#if QT_VERSION >= 0x040700
- streetLineEdit->setPlaceholderText(tr("Street"));
- poboxLineEdit->setPlaceholderText(tr("PO Box"));
- addressextLineEdit->setPlaceholderText(tr("Address Extension"));
- cityLineEdit->setPlaceholderText(tr("City"));
- pocodeLineEdit->setPlaceholderText(tr("Postal Code"));
- regionLineEdit->setPlaceholderText(tr("Region"));
- countryLineEdit->setPlaceholderText(tr("Country"));
+ streetLineEdit->setPlaceholderText(tr("Street"));
+ poboxLineEdit->setPlaceholderText(tr("PO Box"));
+ addressextLineEdit->setPlaceholderText(tr("Address Extension"));
+ cityLineEdit->setPlaceholderText(tr("City"));
+ pocodeLineEdit->setPlaceholderText(tr("Postal Code"));
+ regionLineEdit->setPlaceholderText(tr("Region"));
+ countryLineEdit->setPlaceholderText(tr("Country"));
#endif
- deliveryTypeLabel = new QtElidingLabel(this);
- deliveryTypeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
- getGridLayout()->addWidget(deliveryTypeLabel, getGridLayout()->rowCount()-3, 4, Qt::AlignVCenter);
+ deliveryTypeLabel = new QtElidingLabel(this);
+ deliveryTypeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ getGridLayout()->addWidget(deliveryTypeLabel, getGridLayout()->rowCount()-3, 4, Qt::AlignVCenter);
- domesticRadioButton = new QRadioButton(tr("Domestic Delivery"), this);
- getGridLayout()->addWidget(domesticRadioButton, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
+ domesticRadioButton = new QRadioButton(tr("Domestic Delivery"), this);
+ getGridLayout()->addWidget(domesticRadioButton, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
- internationalRadioButton = new QRadioButton(tr("International Delivery"), this);
- getGridLayout()->addWidget(internationalRadioButton, getGridLayout()->rowCount()-1, 4, Qt::AlignVCenter);
+ internationalRadioButton = new QRadioButton(tr("International Delivery"), this);
+ getGridLayout()->addWidget(internationalRadioButton, getGridLayout()->rowCount()-1, 4, Qt::AlignVCenter);
- buttonGroup = new QButtonGroup(this);
- buttonGroup->addButton(domesticRadioButton);
- buttonGroup->addButton(internationalRadioButton);
+ buttonGroup = new QButtonGroup(this);
+ buttonGroup->addButton(domesticRadioButton);
+ buttonGroup->addButton(internationalRadioButton);
- setTabOrder(internationalRadioButton, getTagComboBox());
- getTagComboBox()->addTag("postal", tr("Postal"));
- getTagComboBox()->addTag("parcel", tr("Parcel"));
+ setTabOrder(internationalRadioButton, getTagComboBox());
+ getTagComboBox()->addTag("postal", tr("Postal"));
+ getTagComboBox()->addTag("parcel", tr("Parcel"));
- QtVCardHomeWork::setTagComboBox(getTagComboBox());
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
- textFields << streetLineEdit << poboxLineEdit << addressextLineEdit << cityLineEdit << pocodeLineEdit << regionLineEdit << countryLineEdit;
- childWidgets << deliveryTypeLabel << domesticRadioButton << internationalRadioButton;
+ textFields << streetLineEdit << poboxLineEdit << addressextLineEdit << cityLineEdit << pocodeLineEdit << regionLineEdit << countryLineEdit;
+ childWidgets << deliveryTypeLabel << domesticRadioButton << internationalRadioButton;
}
void QtVCardAddressField::customCleanup() {
- foreach(QWidget* widget, textFields) {
- widget->hide();
- textFieldGridLayout->removeWidget(widget);
- }
- getGridLayout()->removeItem(textFieldGridLayoutItem);
+ foreach(QWidget* widget, textFields) {
+ widget->hide();
+ textFieldGridLayout->removeWidget(widget);
+ }
+ getGridLayout()->removeItem(textFieldGridLayoutItem);
}
bool QtVCardAddressField::isEmpty() const {
- return streetLineEdit->text().isEmpty() &&
- poboxLineEdit->text().isEmpty() &&
- addressextLineEdit->text().isEmpty() &&
- cityLineEdit->text().isEmpty() &&
- pocodeLineEdit->text().isEmpty() &&
- regionLineEdit->text().isEmpty() &&
- countryLineEdit->text().isEmpty();
+ return streetLineEdit->text().isEmpty() &&
+ poboxLineEdit->text().isEmpty() &&
+ addressextLineEdit->text().isEmpty() &&
+ cityLineEdit->text().isEmpty() &&
+ pocodeLineEdit->text().isEmpty() &&
+ regionLineEdit->text().isEmpty() &&
+ countryLineEdit->text().isEmpty();
}
void QtVCardAddressField::setAddress(const VCard::Address& address) {
- setPreferred(address.isPreferred);
- setHome(address.isHome);
- setWork(address.isWork);
- getTagComboBox()->setTag("postal", address.isPostal);
- getTagComboBox()->setTag("parcel", address.isParcel);
- domesticRadioButton->setChecked(address.deliveryType == VCard::DomesticDelivery);
- internationalRadioButton->setChecked(address.deliveryType == VCard::InternationalDelivery);
- streetLineEdit->setText(P2QSTRING(address.street));
- poboxLineEdit->setText(P2QSTRING(address.poBox));
- addressextLineEdit->setText(P2QSTRING(address.addressExtension));
- cityLineEdit->setText(P2QSTRING(address.locality));
- pocodeLineEdit->setText(P2QSTRING(address.postalCode));
- regionLineEdit->setText(P2QSTRING(address.region));
- countryLineEdit->setText(P2QSTRING(address.country));
+ setPreferred(address.isPreferred);
+ setHome(address.isHome);
+ setWork(address.isWork);
+ getTagComboBox()->setTag("postal", address.isPostal);
+ getTagComboBox()->setTag("parcel", address.isParcel);
+ domesticRadioButton->setChecked(address.deliveryType == VCard::DomesticDelivery);
+ internationalRadioButton->setChecked(address.deliveryType == VCard::InternationalDelivery);
+ streetLineEdit->setText(P2QSTRING(address.street));
+ poboxLineEdit->setText(P2QSTRING(address.poBox));
+ addressextLineEdit->setText(P2QSTRING(address.addressExtension));
+ cityLineEdit->setText(P2QSTRING(address.locality));
+ pocodeLineEdit->setText(P2QSTRING(address.postalCode));
+ regionLineEdit->setText(P2QSTRING(address.region));
+ countryLineEdit->setText(P2QSTRING(address.country));
}
VCard::Address QtVCardAddressField::getAddress() const {
- VCard::Address address;
- address.isPreferred = getPreferred();
- address.isHome = getHome();
- address.isWork = getWork();
- address.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None);
- address.isPostal = getTagComboBox()->isTagSet("postal");
- address.isParcel = getTagComboBox()->isTagSet("parcel");
- address.street = Q2PSTRING(streetLineEdit->text());
- address.poBox = Q2PSTRING(poboxLineEdit->text());
- address.addressExtension = Q2PSTRING(addressextLineEdit->text());
- address.locality = Q2PSTRING(cityLineEdit->text());
- address.postalCode = Q2PSTRING(pocodeLineEdit->text());
- address.region = Q2PSTRING(regionLineEdit->text());
- address.country = Q2PSTRING(countryLineEdit->text());
- return address;
+ VCard::Address address;
+ address.isPreferred = getPreferred();
+ address.isHome = getHome();
+ address.isWork = getWork();
+ address.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None);
+ address.isPostal = getTagComboBox()->isTagSet("postal");
+ address.isParcel = getTagComboBox()->isTagSet("parcel");
+ address.street = Q2PSTRING(streetLineEdit->text());
+ address.poBox = Q2PSTRING(poboxLineEdit->text());
+ address.addressExtension = Q2PSTRING(addressextLineEdit->text());
+ address.locality = Q2PSTRING(cityLineEdit->text());
+ address.postalCode = Q2PSTRING(pocodeLineEdit->text());
+ address.region = Q2PSTRING(regionLineEdit->text());
+ address.country = Q2PSTRING(countryLineEdit->text());
+ return address;
}
void QtVCardAddressField::handleEditibleChanged(bool isEditable) {
- assert(streetLineEdit);
- assert(poboxLineEdit);
- assert(addressextLineEdit);
- assert(cityLineEdit);
- assert(pocodeLineEdit);
- assert(regionLineEdit);
- assert(countryLineEdit);
- assert(deliveryTypeLabel);
- assert(domesticRadioButton);
- assert(internationalRadioButton);
-
- streetLineEdit->setEditable(isEditable);
- poboxLineEdit->setEditable(isEditable);
- addressextLineEdit->setEditable(isEditable);
- cityLineEdit->setEditable(isEditable);
- pocodeLineEdit->setEditable(isEditable);
- regionLineEdit->setEditable(isEditable);
- countryLineEdit->setEditable(isEditable);
-
- deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text());
- deliveryTypeLabel->setVisible(!isEditable);
-
- domesticRadioButton->setVisible(isEditable);
- internationalRadioButton->setVisible(isEditable);
-
- foreach (QWidget* widget, textFields) {
- QtResizableLineEdit* lineEdit;
- if ((lineEdit = dynamic_cast<QtResizableLineEdit*>(widget))) {
- lineEdit->setVisible(isEditable ? true : !lineEdit->text().isEmpty());
- lineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
- }
- }
+ assert(streetLineEdit);
+ assert(poboxLineEdit);
+ assert(addressextLineEdit);
+ assert(cityLineEdit);
+ assert(pocodeLineEdit);
+ assert(regionLineEdit);
+ assert(countryLineEdit);
+ assert(deliveryTypeLabel);
+ assert(domesticRadioButton);
+ assert(internationalRadioButton);
+
+ streetLineEdit->setEditable(isEditable);
+ poboxLineEdit->setEditable(isEditable);
+ addressextLineEdit->setEditable(isEditable);
+ cityLineEdit->setEditable(isEditable);
+ pocodeLineEdit->setEditable(isEditable);
+ regionLineEdit->setEditable(isEditable);
+ countryLineEdit->setEditable(isEditable);
+
+ deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text());
+ deliveryTypeLabel->setVisible(!isEditable);
+
+ domesticRadioButton->setVisible(isEditable);
+ internationalRadioButton->setVisible(isEditable);
+
+ foreach (QWidget* widget, textFields) {
+ QtResizableLineEdit* lineEdit;
+ if ((lineEdit = dynamic_cast<QtResizableLineEdit*>(widget))) {
+ lineEdit->setVisible(isEditable ? true : !lineEdit->text().isEmpty());
+ lineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
+ }
+ }
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.h b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.h
index 51bc323..c90628a 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.h
@@ -27,42 +27,42 @@ namespace Swift {
class QtElidingLabel;
class QtVCardAddressField : public QtVCardGeneralField, public QtVCardHomeWork {
- Q_OBJECT
-
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("Address"), UNLIMITED_INSTANCES, QtVCardAddressField)
-
- QtVCardAddressField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardAddressField();
-
- virtual bool isEmpty() const;
-
- void setAddress(const VCard::Address& address);
- VCard::Address getAddress() const;
-
- protected:
- virtual void setupContentWidgets();
- virtual void customCleanup();
-
- public slots:
- void handleEditibleChanged(bool isEditable);
-
- private:
- QList<QWidget*> textFields;
- QtResizableLineEdit* streetLineEdit;
- QtResizableLineEdit* poboxLineEdit;
- QtResizableLineEdit* addressextLineEdit;
- QtResizableLineEdit* cityLineEdit;
- QtResizableLineEdit* pocodeLineEdit;
- QtResizableLineEdit* regionLineEdit;
- QtResizableLineEdit* countryLineEdit;
- QGridLayout* textFieldGridLayout;
- QLayoutItem* textFieldGridLayoutItem;
-
- QtElidingLabel* deliveryTypeLabel;
- QRadioButton* domesticRadioButton;
- QRadioButton* internationalRadioButton;
- QButtonGroup* buttonGroup;
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("Address"), UNLIMITED_INSTANCES, QtVCardAddressField)
+
+ QtVCardAddressField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardAddressField();
+
+ virtual bool isEmpty() const;
+
+ void setAddress(const VCard::Address& address);
+ VCard::Address getAddress() const;
+
+ protected:
+ virtual void setupContentWidgets();
+ virtual void customCleanup();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QList<QWidget*> textFields;
+ QtResizableLineEdit* streetLineEdit;
+ QtResizableLineEdit* poboxLineEdit;
+ QtResizableLineEdit* addressextLineEdit;
+ QtResizableLineEdit* cityLineEdit;
+ QtResizableLineEdit* pocodeLineEdit;
+ QtResizableLineEdit* regionLineEdit;
+ QtResizableLineEdit* countryLineEdit;
+ QGridLayout* textFieldGridLayout;
+ QLayoutItem* textFieldGridLayoutItem;
+
+ QtElidingLabel* deliveryTypeLabel;
+ QRadioButton* domesticRadioButton;
+ QRadioButton* internationalRadioButton;
+ QButtonGroup* buttonGroup;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp
index 64d2533..7f270c5 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp
@@ -22,86 +22,86 @@
namespace Swift {
QtVCardAddressLabelField::QtVCardAddressLabelField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Address Label")), addressLabelPlainTextEdit(NULL), deliveryTypeLabel(NULL), domesticRadioButton(NULL), internationalRadioButton(NULL), buttonGroup(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Address Label")), addressLabelPlainTextEdit(NULL), deliveryTypeLabel(NULL), domesticRadioButton(NULL), internationalRadioButton(NULL), buttonGroup(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardAddressLabelField::~QtVCardAddressLabelField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardAddressLabelField::setupContentWidgets() {
- addressLabelPlainTextEdit = new QPlainTextEdit(this);
- addressLabelPlainTextEdit->setTabChangesFocus(true);
- getGridLayout()->addWidget(addressLabelPlainTextEdit, getGridLayout()->rowCount()-1, 2, 3, 2, Qt::AlignVCenter);
+ addressLabelPlainTextEdit = new QPlainTextEdit(this);
+ addressLabelPlainTextEdit->setTabChangesFocus(true);
+ getGridLayout()->addWidget(addressLabelPlainTextEdit, getGridLayout()->rowCount()-1, 2, 3, 2, Qt::AlignVCenter);
- deliveryTypeLabel = new QtElidingLabel(this);
- deliveryTypeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
- getGridLayout()->addWidget(deliveryTypeLabel, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
+ deliveryTypeLabel = new QtElidingLabel(this);
+ deliveryTypeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ getGridLayout()->addWidget(deliveryTypeLabel, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
- domesticRadioButton = new QRadioButton(tr("Domestic Delivery"), this);
- getGridLayout()->addWidget(domesticRadioButton, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
+ domesticRadioButton = new QRadioButton(tr("Domestic Delivery"), this);
+ getGridLayout()->addWidget(domesticRadioButton, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
- internationalRadioButton = new QRadioButton(tr("International Delivery"), this);
- getGridLayout()->addWidget(internationalRadioButton, getGridLayout()->rowCount()-1, 4, Qt::AlignVCenter);
+ internationalRadioButton = new QRadioButton(tr("International Delivery"), this);
+ getGridLayout()->addWidget(internationalRadioButton, getGridLayout()->rowCount()-1, 4, Qt::AlignVCenter);
- buttonGroup = new QButtonGroup(this);
- buttonGroup->addButton(domesticRadioButton);
- buttonGroup->addButton(internationalRadioButton);
+ buttonGroup = new QButtonGroup(this);
+ buttonGroup->addButton(domesticRadioButton);
+ buttonGroup->addButton(internationalRadioButton);
- setTabOrder(internationalRadioButton, getTagComboBox());
- getTagComboBox()->addTag("postal", tr("Postal"));
- getTagComboBox()->addTag("parcel", tr("Parcel"));
+ setTabOrder(internationalRadioButton, getTagComboBox());
+ getTagComboBox()->addTag("postal", tr("Postal"));
+ getTagComboBox()->addTag("parcel", tr("Parcel"));
- QtVCardHomeWork::setTagComboBox(getTagComboBox());
- deliveryTypeLabel->hide();
- childWidgets << addressLabelPlainTextEdit << deliveryTypeLabel << domesticRadioButton << internationalRadioButton;
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
+ deliveryTypeLabel->hide();
+ childWidgets << addressLabelPlainTextEdit << deliveryTypeLabel << domesticRadioButton << internationalRadioButton;
}
bool QtVCardAddressLabelField::isEmpty() const {
- return addressLabelPlainTextEdit->toPlainText().isEmpty();
+ return addressLabelPlainTextEdit->toPlainText().isEmpty();
}
void QtVCardAddressLabelField::setAddressLabel(const VCard::AddressLabel& addressLabel) {
- setPreferred(addressLabel.isPreferred);
- setHome(addressLabel.isHome);
- setWork(addressLabel.isWork);
- getTagComboBox()->setTag("postal", addressLabel.isPostal);
- getTagComboBox()->setTag("parcel", addressLabel.isParcel);
- domesticRadioButton->setChecked(addressLabel.deliveryType == VCard::DomesticDelivery);
- internationalRadioButton->setChecked(addressLabel.deliveryType == VCard::InternationalDelivery);
- std::string joinedLines = boost::algorithm::join(addressLabel.lines, "\n");
- addressLabelPlainTextEdit->setPlainText(P2QSTRING(joinedLines));
+ setPreferred(addressLabel.isPreferred);
+ setHome(addressLabel.isHome);
+ setWork(addressLabel.isWork);
+ getTagComboBox()->setTag("postal", addressLabel.isPostal);
+ getTagComboBox()->setTag("parcel", addressLabel.isParcel);
+ domesticRadioButton->setChecked(addressLabel.deliveryType == VCard::DomesticDelivery);
+ internationalRadioButton->setChecked(addressLabel.deliveryType == VCard::InternationalDelivery);
+ std::string joinedLines = boost::algorithm::join(addressLabel.lines, "\n");
+ addressLabelPlainTextEdit->setPlainText(P2QSTRING(joinedLines));
}
VCard::AddressLabel QtVCardAddressLabelField::getAddressLabel() const {
- VCard::AddressLabel addressLabel;
- addressLabel.isPreferred = getPreferred();
- addressLabel.isHome = getHome();
- addressLabel.isWork = getWork();
- addressLabel.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None);
- addressLabel.isPostal = getTagComboBox()->isTagSet("postal");
- addressLabel.isParcel = getTagComboBox()->isTagSet("parcel");
-
- std::string lines = Q2PSTRING(addressLabelPlainTextEdit->toPlainText());
- boost::split(addressLabel.lines, lines, boost::is_any_of("\n"));
- return addressLabel;
+ VCard::AddressLabel addressLabel;
+ addressLabel.isPreferred = getPreferred();
+ addressLabel.isHome = getHome();
+ addressLabel.isWork = getWork();
+ addressLabel.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None);
+ addressLabel.isPostal = getTagComboBox()->isTagSet("postal");
+ addressLabel.isParcel = getTagComboBox()->isTagSet("parcel");
+
+ std::string lines = Q2PSTRING(addressLabelPlainTextEdit->toPlainText());
+ boost::split(addressLabel.lines, lines, boost::is_any_of("\n"));
+ return addressLabel;
}
void QtVCardAddressLabelField::handleEditibleChanged(bool isEditable) {
- assert(addressLabelPlainTextEdit);
- assert(deliveryTypeLabel);
- assert(domesticRadioButton);
- assert(internationalRadioButton);
+ assert(addressLabelPlainTextEdit);
+ assert(deliveryTypeLabel);
+ assert(domesticRadioButton);
+ assert(internationalRadioButton);
- addressLabelPlainTextEdit->setReadOnly(!isEditable);
- addressLabelPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }");
+ addressLabelPlainTextEdit->setReadOnly(!isEditable);
+ addressLabelPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }");
- deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text());
- deliveryTypeLabel->setVisible(!isEditable);
+ deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text());
+ deliveryTypeLabel->setVisible(!isEditable);
- domesticRadioButton->setVisible(isEditable);
- internationalRadioButton->setVisible(isEditable);
+ domesticRadioButton->setVisible(isEditable);
+ internationalRadioButton->setVisible(isEditable);
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h
index f59e482..16910b3 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h
@@ -27,32 +27,32 @@ namespace Swift {
class QtElidingLabel;
class QtVCardAddressLabelField : public QtVCardGeneralField, public QtVCardHomeWork {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("Address Label"), UNLIMITED_INSTANCES, QtVCardAddressLabelField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("Address Label"), UNLIMITED_INSTANCES, QtVCardAddressLabelField)
- QtVCardAddressLabelField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardAddressLabelField();
+ QtVCardAddressLabelField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardAddressLabelField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setAddressLabel(const VCard::AddressLabel& addressLabel);
- VCard::AddressLabel getAddressLabel() const;
+ void setAddressLabel(const VCard::AddressLabel& addressLabel);
+ VCard::AddressLabel getAddressLabel() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QPlainTextEdit* addressLabelPlainTextEdit;
+ private:
+ QPlainTextEdit* addressLabelPlainTextEdit;
- QtElidingLabel* deliveryTypeLabel;
- QRadioButton* domesticRadioButton;
- QRadioButton* internationalRadioButton;
- QButtonGroup* buttonGroup;
+ QtElidingLabel* deliveryTypeLabel;
+ QRadioButton* domesticRadioButton;
+ QRadioButton* internationalRadioButton;
+ QButtonGroup* buttonGroup;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp
index 603b8be..53dfc7f 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp
@@ -22,47 +22,47 @@
namespace Swift {
QtVCardBirthdayField::QtVCardBirthdayField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Birthday"), false, false), birthdayLabel(NULL), birthdayDateEdit(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Birthday"), false, false), birthdayLabel(NULL), birthdayDateEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardBirthdayField::~QtVCardBirthdayField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardBirthdayField::setupContentWidgets() {
- birthdayLabel = new QLabel(this);
- birthdayLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
- birthdayDateEdit = new QDateEdit(this);
- birthdayDateEdit->setCalendarPopup(true);
+ birthdayLabel = new QLabel(this);
+ birthdayLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ birthdayDateEdit = new QDateEdit(this);
+ birthdayDateEdit->setCalendarPopup(true);
- QHBoxLayout* birthdayLayout = new QHBoxLayout();
- birthdayLayout->addWidget(birthdayLabel);
- birthdayLayout->addWidget(birthdayDateEdit);
+ QHBoxLayout* birthdayLayout = new QHBoxLayout();
+ birthdayLayout->addWidget(birthdayLabel);
+ birthdayLayout->addWidget(birthdayDateEdit);
- getGridLayout()->addLayout(birthdayLayout, getGridLayout()->rowCount()-1, 2, Qt::AlignVCenter);
+ getGridLayout()->addLayout(birthdayLayout, getGridLayout()->rowCount()-1, 2, Qt::AlignVCenter);
- getTagComboBox()->hide();
- birthdayLabel->hide();
- childWidgets << birthdayLabel << birthdayDateEdit;
+ getTagComboBox()->hide();
+ birthdayLabel->hide();
+ childWidgets << birthdayLabel << birthdayDateEdit;
}
bool QtVCardBirthdayField::isEmpty() const {
- return false;
+ return false;
}
void QtVCardBirthdayField::setBirthday(const boost::posix_time::ptime& birthday) {
- birthdayDateEdit->setDate(B2QDATE(birthday).date());
+ birthdayDateEdit->setDate(B2QDATE(birthday).date());
}
boost::posix_time::ptime QtVCardBirthdayField::getBirthday() const {
- return boost::posix_time::from_time_t(QDateTime(birthdayDateEdit->date()).toTime_t());
+ return boost::posix_time::from_time_t(QDateTime(birthdayDateEdit->date()).toTime_t());
}
void QtVCardBirthdayField::handleEditibleChanged(bool isEditable) {
- birthdayLabel->setText(birthdayDateEdit->date().toString(Qt::DefaultLocaleLongDate));
- birthdayDateEdit->setVisible(isEditable);
- birthdayLabel->setVisible(!isEditable);
+ birthdayLabel->setText(birthdayDateEdit->date().toString(Qt::DefaultLocaleLongDate));
+ birthdayDateEdit->setVisible(isEditable);
+ birthdayLabel->setVisible(!isEditable);
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h b/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h
index bf15a75..431751e 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h
@@ -23,28 +23,28 @@
namespace Swift {
class QtVCardBirthdayField : public QtVCardGeneralField {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("Birthday"), 1, QtVCardBirthdayField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("Birthday"), 1, QtVCardBirthdayField)
- QtVCardBirthdayField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardBirthdayField();
+ QtVCardBirthdayField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardBirthdayField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setBirthday(const boost::posix_time::ptime& addressLabel);
- boost::posix_time::ptime getBirthday() const;
+ void setBirthday(const boost::posix_time::ptime& addressLabel);
+ boost::posix_time::ptime getBirthday() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QLabel* birthdayLabel;
- QDateEdit* birthdayDateEdit;
+ private:
+ QLabel* birthdayLabel;
+ QDateEdit* birthdayDateEdit;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp
index f3c4dbf..9926262 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp
@@ -22,50 +22,50 @@
namespace Swift {
QtVCardDescriptionField::QtVCardDescriptionField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Description"), false, false), descriptionPlainTextEdit(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Description"), false, false), descriptionPlainTextEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardDescriptionField::~QtVCardDescriptionField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardDescriptionField::setupContentWidgets() {
- descriptionPlainTextEdit = new QPlainTextEdit(this);
- descriptionPlainTextEdit->setMinimumHeight(70);
- getGridLayout()->addWidget(descriptionPlainTextEdit, getGridLayout()->rowCount()-1, 2, 2, 2, Qt::AlignVCenter);
- getTagComboBox()->hide();
- childWidgets << descriptionPlainTextEdit;
+ descriptionPlainTextEdit = new QPlainTextEdit(this);
+ descriptionPlainTextEdit->setMinimumHeight(70);
+ getGridLayout()->addWidget(descriptionPlainTextEdit, getGridLayout()->rowCount()-1, 2, 2, 2, Qt::AlignVCenter);
+ getTagComboBox()->hide();
+ childWidgets << descriptionPlainTextEdit;
}
bool QtVCardDescriptionField::isEmpty() const {
- return descriptionPlainTextEdit->toPlainText().isEmpty();
+ return descriptionPlainTextEdit->toPlainText().isEmpty();
}
void QtVCardDescriptionField::setDescription(const std::string& description) {
- descriptionPlainTextEdit->setPlainText(P2QSTRING(description));
+ descriptionPlainTextEdit->setPlainText(P2QSTRING(description));
}
std::string QtVCardDescriptionField::getDescription() const {
- return Q2PSTRING(descriptionPlainTextEdit->toPlainText());
+ return Q2PSTRING(descriptionPlainTextEdit->toPlainText());
}
void QtVCardDescriptionField::handleEditibleChanged(bool isEditable) {
- assert(descriptionPlainTextEdit);
+ assert(descriptionPlainTextEdit);
- if (isEditable) {
- descriptionPlainTextEdit->setMinimumHeight(70);
- } else {
- QFontMetrics inputMetrics(descriptionPlainTextEdit->document()->defaultFont());
- QRect horizontalBounds = contentsRect().adjusted(0,0,0,9999);
- QRect boundingRect = inputMetrics.boundingRect(horizontalBounds, Qt::TextWordWrap, descriptionPlainTextEdit->toPlainText() + "A");
- int left, top, right, bottom;
- getContentsMargins(&left, &top, &right, &bottom);
- int height = boundingRect.height() + top + bottom + inputMetrics.height();
- descriptionPlainTextEdit->setMinimumHeight(height > 70 ? 70 : height);
- }
- descriptionPlainTextEdit->setReadOnly(!isEditable);
- descriptionPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }");
+ if (isEditable) {
+ descriptionPlainTextEdit->setMinimumHeight(70);
+ } else {
+ QFontMetrics inputMetrics(descriptionPlainTextEdit->document()->defaultFont());
+ QRect horizontalBounds = contentsRect().adjusted(0,0,0,9999);
+ QRect boundingRect = inputMetrics.boundingRect(horizontalBounds, Qt::TextWordWrap, descriptionPlainTextEdit->toPlainText() + "A");
+ int left, top, right, bottom;
+ getContentsMargins(&left, &top, &right, &bottom);
+ int height = boundingRect.height() + top + bottom + inputMetrics.height();
+ descriptionPlainTextEdit->setMinimumHeight(height > 70 ? 70 : height);
+ }
+ descriptionPlainTextEdit->setReadOnly(!isEditable);
+ descriptionPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }");
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h
index 8fb6344..489797a 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h
@@ -22,27 +22,27 @@
namespace Swift {
class QtVCardDescriptionField : public QtVCardGeneralField {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("Description"), 1, QtVCardDescriptionField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("Description"), 1, QtVCardDescriptionField)
- QtVCardDescriptionField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardDescriptionField();
+ QtVCardDescriptionField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardDescriptionField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setDescription(const std::string& description);
- std::string getDescription() const;
+ void setDescription(const std::string& description);
+ std::string getDescription() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QPlainTextEdit* descriptionPlainTextEdit;
+ private:
+ QPlainTextEdit* descriptionPlainTextEdit;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h b/Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h
index 12f990a..093357a 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h
@@ -18,41 +18,41 @@
#include <QObject>
#include <QString>
#define GENERIC_QT_VCARD_FIELD_INFO(MENU_NAME, ALLOWED_INSTANCES, FIELD_CLASS) \
- class FieldInfo : public QtVCardFieldInfo { \
- public: \
- virtual ~FieldInfo() { \
- } \
- \
- virtual QString getMenuName() const { \
- return MENU_NAME; \
- } \
- \
- virtual int getAllowedInstances() const { \
- return ALLOWED_INSTANCES; \
- } \
- \
- virtual QWidget* createFieldInstance(QWidget* parent, QGridLayout* layout, bool editable) const { \
- return new FIELD_CLASS(parent, layout, editable); \
- } \
- \
- virtual bool testInstance(QWidget* widget) const { \
- return dynamic_cast<FIELD_CLASS*>(widget) != 0; \
- } \
- };
+ class FieldInfo : public QtVCardFieldInfo { \
+ public: \
+ virtual ~FieldInfo() { \
+ } \
+ \
+ virtual QString getMenuName() const { \
+ return MENU_NAME; \
+ } \
+ \
+ virtual int getAllowedInstances() const { \
+ return ALLOWED_INSTANCES; \
+ } \
+ \
+ virtual QWidget* createFieldInstance(QWidget* parent, QGridLayout* layout, bool editable) const { \
+ return new FIELD_CLASS(parent, layout, editable); \
+ } \
+ \
+ virtual bool testInstance(QWidget* widget) const { \
+ return dynamic_cast<FIELD_CLASS*>(widget) != 0; \
+ } \
+ };
class QWidget;
namespace Swift {
- class QtVCardFieldInfo {
- public:
- static const int UNLIMITED_INSTANCES = -1;
-
- virtual ~QtVCardFieldInfo() {
- }
- virtual QString getMenuName() const = 0;
- virtual int getAllowedInstances() const = 0;
- virtual QWidget* createFieldInstance(QWidget* parent, QGridLayout* layout, bool editable) const = 0;
- virtual bool testInstance(QWidget*) const = 0;
- };
+ class QtVCardFieldInfo {
+ public:
+ static const int UNLIMITED_INSTANCES = -1;
+
+ virtual ~QtVCardFieldInfo() {
+ }
+ virtual QString getMenuName() const = 0;
+ virtual int getAllowedInstances() const = 0;
+ virtual QWidget* createFieldInstance(QWidget* parent, QGridLayout* layout, bool editable) const = 0;
+ virtual bool testInstance(QWidget*) const = 0;
+ };
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
index ed30ae1..44d94d7 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
@@ -22,8 +22,8 @@
namespace Swift {
QtVCardGeneralField::QtVCardGeneralField(QWidget* parent, QGridLayout* layout, bool editable, int row, QString label, bool preferrable, bool taggable) :
- QWidget(parent), editable(editable), preferrable(preferrable), starVisible(false), taggable(taggable), layout(layout), row(row), preferredCheckBox(0), label(0), labelText(label),
- tagComboBox(0), tagLabel(NULL), closeButton(0) {
+ QWidget(parent), editable(editable), preferrable(preferrable), starVisible(false), taggable(taggable), layout(layout), row(row), preferredCheckBox(0), label(0), labelText(label),
+ tagComboBox(0), tagLabel(NULL), closeButton(0) {
}
QtVCardGeneralField::~QtVCardGeneralField() {
@@ -31,126 +31,126 @@ QtVCardGeneralField::~QtVCardGeneralField() {
}
void QtVCardGeneralField::initialize() {
- if (preferrable) {
- preferredCheckBox = new QCheckBox(this);
- preferredCheckBox->setToolTip(tr("Stars can be used to mark preferred contact details."));
- preferredCheckBox->setStyleSheet(
- "QCheckBox::indicator { width: 18px; height: 18px; }"
- "QCheckBox::indicator:checked { image: url(:/icons/star-checked.png); }"
- "QCheckBox::indicator:unchecked { image: url(:/icons/star-unchecked.png); }"
- );
- layout->addWidget(preferredCheckBox, row, 0, Qt::AlignVCenter);
- childWidgets << preferredCheckBox;
- connect(preferredCheckBox, SIGNAL(stateChanged(int)), SLOT(handlePreferredStarStateChanged(int)));
- }
- label = new QLabel(this);
- label->setText(labelText);
- layout->addWidget(label, row, 1, Qt::AlignVCenter | Qt::AlignRight);
-
- tagLabel = new QtElidingLabel(this);
- tagLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
-
- tagComboBox = new QtTagComboBox(this);
- closeButton = new QtCloseButton(this);
- connect(closeButton, SIGNAL(clicked()), SLOT(handleCloseButtonClicked()));
-
- QHBoxLayout* tagLayout = new QHBoxLayout();
- tagLayout->addWidget(tagLabel);
- tagLayout->addWidget(tagComboBox);
-
- setupContentWidgets();
- layout->addLayout(tagLayout, row, 4, Qt::AlignTop);
- layout->addWidget(closeButton, row, 5, Qt::AlignCenter);
- closeButton->resize(12, 12);
- tagLabel->hide();
-
- childWidgets << label << tagComboBox << tagLabel << closeButton;
- setEditable(editable);
+ if (preferrable) {
+ preferredCheckBox = new QCheckBox(this);
+ preferredCheckBox->setToolTip(tr("Stars can be used to mark preferred contact details."));
+ preferredCheckBox->setStyleSheet(
+ "QCheckBox::indicator { width: 18px; height: 18px; }"
+ "QCheckBox::indicator:checked { image: url(:/icons/star-checked.png); }"
+ "QCheckBox::indicator:unchecked { image: url(:/icons/star-unchecked.png); }"
+ );
+ layout->addWidget(preferredCheckBox, row, 0, Qt::AlignVCenter);
+ childWidgets << preferredCheckBox;
+ connect(preferredCheckBox, SIGNAL(stateChanged(int)), SLOT(handlePreferredStarStateChanged(int)));
+ }
+ label = new QLabel(this);
+ label->setText(labelText);
+ layout->addWidget(label, row, 1, Qt::AlignVCenter | Qt::AlignRight);
+
+ tagLabel = new QtElidingLabel(this);
+ tagLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+
+ tagComboBox = new QtTagComboBox(this);
+ closeButton = new QtCloseButton(this);
+ connect(closeButton, SIGNAL(clicked()), SLOT(handleCloseButtonClicked()));
+
+ QHBoxLayout* tagLayout = new QHBoxLayout();
+ tagLayout->addWidget(tagLabel);
+ tagLayout->addWidget(tagComboBox);
+
+ setupContentWidgets();
+ layout->addLayout(tagLayout, row, 4, Qt::AlignTop);
+ layout->addWidget(closeButton, row, 5, Qt::AlignCenter);
+ closeButton->resize(12, 12);
+ tagLabel->hide();
+
+ childWidgets << label << tagComboBox << tagLabel << closeButton;
+ setEditable(editable);
}
bool QtVCardGeneralField::isEditable() const {
- return editable;
+ return editable;
}
void QtVCardGeneralField::setEditable(bool editable) {
- assert(tagComboBox);
- assert(closeButton);
-
- this->editable = editable;
- if (taggable) {
- tagLabel->setText(tagComboBox->itemText(0));
- tagComboBox->setVisible(editable);
- tagLabel->setVisible(!editable);
- } else {
- tagLabel->hide();
- tagComboBox->hide();
- }
- closeButton->setVisible(editable);
- updatePreferredStarVisibility();
- editableChanged(this->editable);
+ assert(tagComboBox);
+ assert(closeButton);
+
+ this->editable = editable;
+ if (taggable) {
+ tagLabel->setText(tagComboBox->itemText(0));
+ tagComboBox->setVisible(editable);
+ tagLabel->setVisible(!editable);
+ } else {
+ tagLabel->hide();
+ tagComboBox->hide();
+ }
+ closeButton->setVisible(editable);
+ updatePreferredStarVisibility();
+ editableChanged(this->editable);
}
void QtVCardGeneralField::setStarVisible(const bool isVisible) {
- starVisible = isVisible;
- updatePreferredStarVisibility();
+ starVisible = isVisible;
+ updatePreferredStarVisibility();
}
bool QtVCardGeneralField::getStarVisible() const {
- return starVisible;
+ return starVisible;
}
void QtVCardGeneralField::setPreferred(const bool preferred) {
- if (preferredCheckBox) preferredCheckBox->setChecked(preferred);
- updatePreferredStarVisibility();
+ if (preferredCheckBox) preferredCheckBox->setChecked(preferred);
+ updatePreferredStarVisibility();
}
bool QtVCardGeneralField::getPreferred() const {
- return preferredCheckBox ? preferredCheckBox->isChecked() : false;
+ return preferredCheckBox ? preferredCheckBox->isChecked() : false;
}
void QtVCardGeneralField::customCleanup() {
}
QtTagComboBox* QtVCardGeneralField::getTagComboBox() const {
- return tagComboBox;
+ return tagComboBox;
}
QGridLayout* QtVCardGeneralField::getGridLayout() const {
- return layout;
+ return layout;
}
void QtVCardGeneralField::handleCloseButtonClicked() {
- customCleanup();
- foreach(QWidget* widget, childWidgets) {
- widget->hide();
- layout->removeWidget(widget);
- }
- deleteField(this);
+ customCleanup();
+ foreach(QWidget* widget, childWidgets) {
+ widget->hide();
+ layout->removeWidget(widget);
+ }
+ deleteField(this);
}
void QtVCardGeneralField::handlePreferredStarStateChanged(int state) {
- if (state == Qt::Checked) {
- QToolTip::showText(QCursor::pos(), tr("Marked as your preferred %1. Click again to undo.").arg(labelText));
- }
+ if (state == Qt::Checked) {
+ QToolTip::showText(QCursor::pos(), tr("Marked as your preferred %1. Click again to undo.").arg(labelText));
+ }
}
void QtVCardGeneralField::updatePreferredStarVisibility() {
- if (preferredCheckBox) {
- bool showStar = false;
- if (editable) {
- if (starVisible) {
- showStar = true;
- }
- else {
- showStar = preferredCheckBox->isChecked();
- }
- }
- else {
- showStar = preferredCheckBox->isChecked();
- }
- preferredCheckBox->setVisible(showStar);
- preferredCheckBox->setEnabled(editable);
- }
+ if (preferredCheckBox) {
+ bool showStar = false;
+ if (editable) {
+ if (starVisible) {
+ showStar = true;
+ }
+ else {
+ showStar = preferredCheckBox->isChecked();
+ }
+ }
+ else {
+ showStar = preferredCheckBox->isChecked();
+ }
+ preferredCheckBox->setVisible(showStar);
+ preferredCheckBox->setEnabled(editable);
+ }
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h
index 6583d12..d907196 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h
@@ -25,69 +25,69 @@ namespace Swift {
class QtElidingLabel;
/*
- * covers features like:
- * - preffered (star ceckbox)
- * - combo check box
- * - label
- * - remove button
+ * covers features like:
+ * - preffered (star ceckbox)
+ * - combo check box
+ * - label
+ * - remove button
*/
class QtVCardGeneralField : public QWidget {
- Q_OBJECT
- Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged)
- Q_PROPERTY(bool empty READ isEmpty)
-
- public:
- explicit QtVCardGeneralField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false, int row = 0, QString label = QString(),
- bool preferrable = true, bool taggable = true);
- virtual ~QtVCardGeneralField();
-
- void initialize();
-
- virtual bool isEditable() const;
- virtual void setEditable(bool);
-
- virtual bool isEmpty() const = 0;
-
- void setStarVisible(const bool isVisible);
- bool getStarVisible() const;
-
- void setPreferred(const bool preferred);
- bool getPreferred() const;
-
- protected:
- virtual void setupContentWidgets() = 0;
- virtual void customCleanup();
-
- QtTagComboBox* getTagComboBox() const;
- QGridLayout* getGridLayout() const;
-
- signals:
- void editableChanged(bool);
- void deleteField(QtVCardGeneralField*);
-
- public slots:
- void handleCloseButtonClicked();
- void handlePreferredStarStateChanged(int statte);
-
- protected:
- QList<QWidget*> childWidgets;
-
- private:
- void updatePreferredStarVisibility();
-
- private:
- bool editable;
- bool preferrable;
- bool starVisible;
- bool taggable;
- QGridLayout* layout;
- int row;
- QCheckBox* preferredCheckBox;
- QLabel* label;
- QString labelText;
- QtTagComboBox* tagComboBox;
- QtElidingLabel* tagLabel;
- QtCloseButton* closeButton;
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged)
+ Q_PROPERTY(bool empty READ isEmpty)
+
+ public:
+ explicit QtVCardGeneralField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false, int row = 0, QString label = QString(),
+ bool preferrable = true, bool taggable = true);
+ virtual ~QtVCardGeneralField();
+
+ void initialize();
+
+ virtual bool isEditable() const;
+ virtual void setEditable(bool);
+
+ virtual bool isEmpty() const = 0;
+
+ void setStarVisible(const bool isVisible);
+ bool getStarVisible() const;
+
+ void setPreferred(const bool preferred);
+ bool getPreferred() const;
+
+ protected:
+ virtual void setupContentWidgets() = 0;
+ virtual void customCleanup();
+
+ QtTagComboBox* getTagComboBox() const;
+ QGridLayout* getGridLayout() const;
+
+ signals:
+ void editableChanged(bool);
+ void deleteField(QtVCardGeneralField*);
+
+ public slots:
+ void handleCloseButtonClicked();
+ void handlePreferredStarStateChanged(int statte);
+
+ protected:
+ QList<QWidget*> childWidgets;
+
+ private:
+ void updatePreferredStarVisibility();
+
+ private:
+ bool editable;
+ bool preferrable;
+ bool starVisible;
+ bool taggable;
+ QGridLayout* layout;
+ int row;
+ QCheckBox* preferredCheckBox;
+ QLabel* label;
+ QString labelText;
+ QtTagComboBox* tagComboBox;
+ QtElidingLabel* tagLabel;
+ QtCloseButton* closeButton;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp b/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp
index 3be6901..c147c68 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp
@@ -21,25 +21,25 @@ QtVCardHomeWork::~QtVCardHomeWork() {
}
void QtVCardHomeWork::setTagComboBox(QtTagComboBox* tagBox) {
- tagComboBox = tagBox;
- tagComboBox->addTag("home", QObject::tr("Home"));
- tagComboBox->addTag("work", QObject::tr("Work"));
+ tagComboBox = tagBox;
+ tagComboBox->addTag("home", QObject::tr("Home"));
+ tagComboBox->addTag("work", QObject::tr("Work"));
}
void QtVCardHomeWork::setHome(const bool home) {
- tagComboBox->setTag("home", home);
+ tagComboBox->setTag("home", home);
}
bool QtVCardHomeWork::getHome() const {
- return tagComboBox->isTagSet("home");
+ return tagComboBox->isTagSet("home");
}
void QtVCardHomeWork::setWork(const bool work) {
- tagComboBox->setTag("work", work);
+ tagComboBox->setTag("work", work);
}
bool QtVCardHomeWork::getWork() const {
- return tagComboBox->isTagSet("work");
+ return tagComboBox->isTagSet("work");
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h b/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h
index aea2ff2..dd1452a 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h
@@ -19,19 +19,19 @@
namespace Swift {
class QtVCardHomeWork {
- public:
- QtVCardHomeWork();
- virtual ~QtVCardHomeWork();
+ public:
+ QtVCardHomeWork();
+ virtual ~QtVCardHomeWork();
- void setTagComboBox(QtTagComboBox* tagBox);
+ void setTagComboBox(QtTagComboBox* tagBox);
- void setHome(const bool home);
- bool getHome() const;
- void setWork(const bool work);
- bool getWork() const;
+ void setHome(const bool home);
+ bool getHome() const;
+ void setWork(const bool work);
+ bool getWork() const;
- private:
- QtTagComboBox* tagComboBox;
+ private:
+ QtTagComboBox* tagComboBox;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp
index 9be9737..e563ca2 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp
@@ -24,66 +24,66 @@
namespace Swift {
QtVCardInternetEMailField::QtVCardInternetEMailField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("E-Mail")), emailLineEdit(NULL), emailLabel(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("E-Mail")), emailLineEdit(NULL), emailLabel(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardInternetEMailField::~QtVCardInternetEMailField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardInternetEMailField::setupContentWidgets() {
- emailLabel = new QLabel(this);
- emailLabel->setOpenExternalLinks(true);
- emailLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
- emailLineEdit = new QtResizableLineEdit(this);
+ emailLabel = new QLabel(this);
+ emailLabel->setOpenExternalLinks(true);
+ emailLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
+ emailLineEdit = new QtResizableLineEdit(this);
#if QT_VERSION >= 0x040700
- emailLineEdit->setPlaceholderText(tr("alice@wonderland.lit"));
+ emailLineEdit->setPlaceholderText(tr("alice@wonderland.lit"));
#endif
- QHBoxLayout* emailLayout = new QHBoxLayout();
- emailLayout->addWidget(emailLabel);
- emailLayout->addWidget(emailLineEdit);
- getGridLayout()->addLayout(emailLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
- setTabOrder(emailLineEdit, getTagComboBox());
- QtVCardHomeWork::setTagComboBox(getTagComboBox());
- emailLabel->hide();
- childWidgets << emailLabel << emailLineEdit;
+ QHBoxLayout* emailLayout = new QHBoxLayout();
+ emailLayout->addWidget(emailLabel);
+ emailLayout->addWidget(emailLineEdit);
+ getGridLayout()->addLayout(emailLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ setTabOrder(emailLineEdit, getTagComboBox());
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
+ emailLabel->hide();
+ childWidgets << emailLabel << emailLineEdit;
}
bool QtVCardInternetEMailField::isEmpty() const {
- return emailLineEdit->text().isEmpty();
+ return emailLineEdit->text().isEmpty();
}
void QtVCardInternetEMailField::setInternetEMailAddress(const VCard::EMailAddress& address) {
- assert(address.isInternet);
- setPreferred(address.isPreferred);
- setHome(address.isHome);
- setWork(address.isWork);
- emailLineEdit->setText(P2QSTRING(address.address));
+ assert(address.isInternet);
+ setPreferred(address.isPreferred);
+ setHome(address.isHome);
+ setWork(address.isWork);
+ emailLineEdit->setText(P2QSTRING(address.address));
}
VCard::EMailAddress QtVCardInternetEMailField::getInternetEMailAddress() const {
- VCard::EMailAddress address;
- address.isInternet = true;
- address.isPreferred = getPreferred();
- address.isHome = getHome();
- address.isWork = getWork();
- address.address = Q2PSTRING(emailLineEdit->text());
- return address;
+ VCard::EMailAddress address;
+ address.isInternet = true;
+ address.isPreferred = getPreferred();
+ address.isHome = getHome();
+ address.isWork = getWork();
+ address.address = Q2PSTRING(emailLineEdit->text());
+ return address;
}
void QtVCardInternetEMailField::handleEditibleChanged(bool isEditable) {
- assert(emailLineEdit);
- assert(emailLabel);
+ assert(emailLineEdit);
+ assert(emailLabel);
- if (isEditable) {
- emailLineEdit->show();
- emailLabel->hide();
- } else {
- emailLineEdit->hide();
- emailLabel->setText(QString("<a href=\"mailto:%1\">%1</a>").arg(QtUtilities::htmlEscape(emailLineEdit->text())));
- emailLabel->show();
- }
+ if (isEditable) {
+ emailLineEdit->show();
+ emailLabel->hide();
+ } else {
+ emailLineEdit->hide();
+ emailLabel->setText(QString("<a href=\"mailto:%1\">%1</a>").arg(QtUtilities::htmlEscape(emailLineEdit->text())));
+ emailLabel->show();
+ }
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h
index e3a5d79..63a83e2 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h
@@ -22,28 +22,28 @@
namespace Swift {
class QtVCardInternetEMailField : public QtVCardGeneralField, public QtVCardHomeWork {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("E-Mail"), UNLIMITED_INSTANCES, QtVCardInternetEMailField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("E-Mail"), UNLIMITED_INSTANCES, QtVCardInternetEMailField)
- QtVCardInternetEMailField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardInternetEMailField();
+ QtVCardInternetEMailField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardInternetEMailField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setInternetEMailAddress(const VCard::EMailAddress& address);
- VCard::EMailAddress getInternetEMailAddress() const;
+ void setInternetEMailAddress(const VCard::EMailAddress& address);
+ VCard::EMailAddress getInternetEMailAddress() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QtResizableLineEdit* emailLineEdit;
- QLabel* emailLabel;
+ private:
+ QtResizableLineEdit* emailLineEdit;
+ QLabel* emailLabel;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp
index 4c23036..705ad6b 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp
@@ -23,58 +23,58 @@
namespace Swift {
QtVCardJIDField::QtVCardJIDField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("JID"), false, false), jidLabel(NULL), jidLineEdit(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("JID"), false, false), jidLabel(NULL), jidLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardJIDField::~QtVCardJIDField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardJIDField::setupContentWidgets() {
- jidLabel = new QLabel(this);
- jidLabel->setOpenExternalLinks(true);
- jidLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
- jidLineEdit = new QtResizableLineEdit(this);
+ jidLabel = new QLabel(this);
+ jidLabel->setOpenExternalLinks(true);
+ jidLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
+ jidLineEdit = new QtResizableLineEdit(this);
#if QT_VERSION >= 0x040700
- jidLineEdit->setPlaceholderText(tr("alice@wonderland.lit"));
+ jidLineEdit->setPlaceholderText(tr("alice@wonderland.lit"));
#endif
- QHBoxLayout* jidLayout = new QHBoxLayout();
- jidLayout->addWidget(jidLabel);
- jidLayout->addWidget(jidLineEdit);
- getGridLayout()->addLayout(jidLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ QHBoxLayout* jidLayout = new QHBoxLayout();
+ jidLayout->addWidget(jidLabel);
+ jidLayout->addWidget(jidLineEdit);
+ getGridLayout()->addLayout(jidLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
- jidLabel->hide();
- getTagComboBox()->hide();
+ jidLabel->hide();
+ getTagComboBox()->hide();
- childWidgets << jidLabel << jidLineEdit;
+ childWidgets << jidLabel << jidLineEdit;
}
bool QtVCardJIDField::isEmpty() const {
- return jidLineEdit->text().isEmpty();
+ return jidLineEdit->text().isEmpty();
}
void QtVCardJIDField::setJID(const JID& jid) {
- std::string jidStr = jid.toBare().toString();
- jidLineEdit->setText(P2QSTRING(jidStr));
+ std::string jidStr = jid.toBare().toString();
+ jidLineEdit->setText(P2QSTRING(jidStr));
}
JID QtVCardJIDField::getJID() const {
- return JID(Q2PSTRING(jidLineEdit->text()));
+ return JID(Q2PSTRING(jidLineEdit->text()));
}
void QtVCardJIDField::handleEditibleChanged(bool isEditable) {
- assert(jidLineEdit);
- assert(jidLabel);
-
- if (isEditable) {
- jidLineEdit->show();
- jidLabel->hide();
- } else {
- jidLineEdit->hide();
- jidLabel->setText(QString("<a href=\"xmpp:%1\">%1</a>").arg(QtUtilities::htmlEscape(jidLineEdit->text())));
- jidLabel->show();
- }
+ assert(jidLineEdit);
+ assert(jidLabel);
+
+ if (isEditable) {
+ jidLineEdit->show();
+ jidLabel->hide();
+ } else {
+ jidLineEdit->hide();
+ jidLabel->setText(QString("<a href=\"xmpp:%1\">%1</a>").arg(QtUtilities::htmlEscape(jidLineEdit->text())));
+ jidLabel->show();
+ }
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardJIDField.h b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.h
index 4e75885..2e9b4ef 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardJIDField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.h
@@ -21,28 +21,28 @@
namespace Swift {
class QtVCardJIDField : public QtVCardGeneralField {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("JID"), UNLIMITED_INSTANCES, QtVCardJIDField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("JID"), UNLIMITED_INSTANCES, QtVCardJIDField)
- QtVCardJIDField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardJIDField();
+ QtVCardJIDField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardJIDField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setJID(const JID& jid);
- JID getJID() const;
+ void setJID(const JID& jid);
+ JID getJID() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QLabel* jidLabel;
- QtResizableLineEdit* jidLineEdit;
+ private:
+ QLabel* jidLabel;
+ QtResizableLineEdit* jidLineEdit;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp
index ba51078..8b94c42 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp
@@ -17,129 +17,129 @@
namespace Swift {
QtVCardOrganizationField::QtVCardOrganizationField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Organization"), false, false), organizationLabel(NULL), organizationLineEdit(NULL), unitsTreeWidget(NULL), itemDelegate(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Organization"), false, false), organizationLabel(NULL), organizationLineEdit(NULL), unitsTreeWidget(NULL), itemDelegate(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardOrganizationField::~QtVCardOrganizationField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardOrganizationField::setupContentWidgets() {
- organizationLabel = new QLabel(this);
- organizationLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
- organizationLineEdit = new QtResizableLineEdit(this);
- QHBoxLayout* organizationLayout = new QHBoxLayout();
- organizationLayout->addWidget(organizationLabel);
- organizationLayout->addWidget(organizationLineEdit);
+ organizationLabel = new QLabel(this);
+ organizationLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ organizationLineEdit = new QtResizableLineEdit(this);
+ QHBoxLayout* organizationLayout = new QHBoxLayout();
+ organizationLayout->addWidget(organizationLabel);
+ organizationLayout->addWidget(organizationLineEdit);
- getGridLayout()->addLayout(organizationLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ getGridLayout()->addLayout(organizationLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
- itemDelegate = new QtRemovableItemDelegate(style());
+ itemDelegate = new QtRemovableItemDelegate(style());
- unitsTreeWidget = new QTreeWidget(this);
- connect(unitsTreeWidget->model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(handleRowsRemoved(QModelIndex,int,int)));
- unitsTreeWidget->setColumnCount(2);
- unitsTreeWidget->header()->setStretchLastSection(false);
- unitsTreeWidget->header()->resizeSection(1, itemDelegate->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
+ unitsTreeWidget = new QTreeWidget(this);
+ connect(unitsTreeWidget->model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(handleRowsRemoved(QModelIndex,int,int)));
+ unitsTreeWidget->setColumnCount(2);
+ unitsTreeWidget->header()->setStretchLastSection(false);
+ unitsTreeWidget->header()->resizeSection(1, itemDelegate->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
#if QT_VERSION >= 0x050000
- unitsTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
+ unitsTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
#else
- unitsTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
+ unitsTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
#endif
- unitsTreeWidget->setHeaderHidden(true);
- unitsTreeWidget->setRootIsDecorated(false);
- unitsTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked);
- unitsTreeWidget->setItemDelegateForColumn(1, itemDelegate);
- connect(unitsTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(handleItemChanged(QTreeWidgetItem*,int)));
- getGridLayout()->addWidget(unitsTreeWidget, getGridLayout()->rowCount()-1, 4, 2, 1);
+ unitsTreeWidget->setHeaderHidden(true);
+ unitsTreeWidget->setRootIsDecorated(false);
+ unitsTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked);
+ unitsTreeWidget->setItemDelegateForColumn(1, itemDelegate);
+ connect(unitsTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(handleItemChanged(QTreeWidgetItem*,int)));
+ getGridLayout()->addWidget(unitsTreeWidget, getGridLayout()->rowCount()-1, 4, 2, 1);
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- unitsTreeWidget->addTopLevelItem(item);
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ unitsTreeWidget->addTopLevelItem(item);
- getTagComboBox()->hide();
- organizationLabel->hide();
- childWidgets << organizationLabel << organizationLineEdit << unitsTreeWidget;
+ getTagComboBox()->hide();
+ organizationLabel->hide();
+ childWidgets << organizationLabel << organizationLineEdit << unitsTreeWidget;
}
bool QtVCardOrganizationField::isEmpty() const {
- return organizationLineEdit->text().isEmpty() && unitsTreeWidget->model()->rowCount() != 0;
+ return organizationLineEdit->text().isEmpty() && unitsTreeWidget->model()->rowCount() != 0;
}
void QtVCardOrganizationField::setOrganization(const VCard::Organization& organization) {
- organizationLineEdit->setText(P2QSTRING(organization.name));
- unitsTreeWidget->clear();
- foreach(std::string unit, organization.units) {
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(unit)) << "");
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- unitsTreeWidget->addTopLevelItem(item);
- }
-
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- unitsTreeWidget->addTopLevelItem(item);
+ organizationLineEdit->setText(P2QSTRING(organization.name));
+ unitsTreeWidget->clear();
+ foreach(std::string unit, organization.units) {
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(unit)) << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ unitsTreeWidget->addTopLevelItem(item);
+ }
+
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ unitsTreeWidget->addTopLevelItem(item);
}
VCard::Organization QtVCardOrganizationField::getOrganization() const {
- VCard::Organization organization;
- organization.name = Q2PSTRING(organizationLineEdit->text());
- for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) {
- QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i);
- if (!row->text(0).isEmpty()) {
- organization.units.push_back(Q2PSTRING(row->text(0)));
- }
- }
-
- return organization;
+ VCard::Organization organization;
+ organization.name = Q2PSTRING(organizationLineEdit->text());
+ for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i);
+ if (!row->text(0).isEmpty()) {
+ organization.units.push_back(Q2PSTRING(row->text(0)));
+ }
+ }
+
+ return organization;
}
void QtVCardOrganizationField::handleEditibleChanged(bool isEditable) {
- assert(organizationLineEdit);
- assert(unitsTreeWidget);
-
- organizationLineEdit->setVisible(isEditable);
- organizationLabel->setVisible(!isEditable);
-
- if (!isEditable) {
- QString label;
- for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) {
- QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i);
- if (!row->text(0).isEmpty()) {
- label += row->text(0) + ", ";
- }
- }
- label += organizationLineEdit->text();
- organizationLabel->setText(label);
- }
- unitsTreeWidget->setVisible(isEditable);
+ assert(organizationLineEdit);
+ assert(unitsTreeWidget);
+
+ organizationLineEdit->setVisible(isEditable);
+ organizationLabel->setVisible(!isEditable);
+
+ if (!isEditable) {
+ QString label;
+ for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i);
+ if (!row->text(0).isEmpty()) {
+ label += row->text(0) + ", ";
+ }
+ }
+ label += organizationLineEdit->text();
+ organizationLabel->setText(label);
+ }
+ unitsTreeWidget->setVisible(isEditable);
}
void QtVCardOrganizationField::handleItemChanged(QTreeWidgetItem *, int) {
- guaranteeEmptyRow();
+ guaranteeEmptyRow();
}
void QtVCardOrganizationField::handleRowsRemoved(const QModelIndex&, int, int) {
- guaranteeEmptyRow();
+ guaranteeEmptyRow();
}
void QtVCardOrganizationField::guaranteeEmptyRow() {
- bool hasEmptyRow = false;
- QList<QTreeWidgetItem*> rows = unitsTreeWidget->findItems("", Qt::MatchFixedString);
- foreach(QTreeWidgetItem* row, rows) {
- if (row->text(0).isEmpty()) {
- hasEmptyRow = true;
- }
- }
-
- if (!hasEmptyRow) {
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- unitsTreeWidget->addTopLevelItem(item);
- unitsTreeWidget->setCurrentItem(item);
- }
+ bool hasEmptyRow = false;
+ QList<QTreeWidgetItem*> rows = unitsTreeWidget->findItems("", Qt::MatchFixedString);
+ foreach(QTreeWidgetItem* row, rows) {
+ if (row->text(0).isEmpty()) {
+ hasEmptyRow = true;
+ }
+ }
+
+ if (!hasEmptyRow) {
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ unitsTreeWidget->addTopLevelItem(item);
+ unitsTreeWidget->setCurrentItem(item);
+ }
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h
index f567e92..6de3167 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h
@@ -24,37 +24,37 @@
namespace Swift {
class QtVCardOrganizationField : public QtVCardGeneralField {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("Organization"), UNLIMITED_INSTANCES, QtVCardOrganizationField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("Organization"), UNLIMITED_INSTANCES, QtVCardOrganizationField)
- QtVCardOrganizationField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardOrganizationField();
+ QtVCardOrganizationField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardOrganizationField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setOrganization(const VCard::Organization& organization);
- VCard::Organization getOrganization() const;
+ void setOrganization(const VCard::Organization& organization);
+ VCard::Organization getOrganization() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private slots:
- void handleItemChanged(QTreeWidgetItem*, int);
- void handleRowsRemoved(const QModelIndex&, int, int);
+ private slots:
+ void handleItemChanged(QTreeWidgetItem*, int);
+ void handleRowsRemoved(const QModelIndex&, int, int);
- private:
- void guaranteeEmptyRow();
+ private:
+ void guaranteeEmptyRow();
- private:
- QLabel* organizationLabel;
- QtResizableLineEdit* organizationLineEdit;
- QTreeWidget* unitsTreeWidget;
- QtRemovableItemDelegate* itemDelegate;
+ private:
+ QLabel* organizationLabel;
+ QtResizableLineEdit* organizationLineEdit;
+ QTreeWidget* unitsTreeWidget;
+ QtRemovableItemDelegate* itemDelegate;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp
index 680fdb5..90d6e5e 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp
@@ -19,134 +19,134 @@
namespace Swift {
QtVCardPhotoAndNameFields::QtVCardPhotoAndNameFields(QWidget* parent) :
- QWidget(parent),
- ui(new Ui::QtVCardPhotoAndNameFields) {
- ui->setupUi(this);
- ui->lineEditPREFIX->hide();
- ui->lineEditMIDDLE->hide();
- ui->lineEditSUFFIX->hide();
- ui->lineEditFN->hide();
- ui->lineEditNICKNAME->hide();
- ui->labelFN->hide();
- ui->labelNICKNAME->hide();
- ui->labelFULLNAME->hide();
+ QWidget(parent),
+ ui(new Ui::QtVCardPhotoAndNameFields) {
+ ui->setupUi(this);
+ ui->lineEditPREFIX->hide();
+ ui->lineEditMIDDLE->hide();
+ ui->lineEditSUFFIX->hide();
+ ui->lineEditFN->hide();
+ ui->lineEditNICKNAME->hide();
+ ui->labelFN->hide();
+ ui->labelNICKNAME->hide();
+ ui->labelFULLNAME->hide();
#if QT_VERSION >= 0x040700
- ui->lineEditFN->setPlaceholderText(tr("Formatted Name"));
- ui->lineEditNICKNAME->setPlaceholderText(tr("Nickname"));
- ui->lineEditPREFIX->setPlaceholderText(tr("Prefix"));
- ui->lineEditGIVEN->setPlaceholderText(tr("Given Name"));
- ui->lineEditMIDDLE->setPlaceholderText(tr("Middle Name"));
- ui->lineEditFAMILY->setPlaceholderText(tr("Last Name"));
- ui->lineEditSUFFIX->setPlaceholderText(tr("Suffix"));
+ ui->lineEditFN->setPlaceholderText(tr("Formatted Name"));
+ ui->lineEditNICKNAME->setPlaceholderText(tr("Nickname"));
+ ui->lineEditPREFIX->setPlaceholderText(tr("Prefix"));
+ ui->lineEditGIVEN->setPlaceholderText(tr("Given Name"));
+ ui->lineEditMIDDLE->setPlaceholderText(tr("Middle Name"));
+ ui->lineEditFAMILY->setPlaceholderText(tr("Last Name"));
+ ui->lineEditSUFFIX->setPlaceholderText(tr("Suffix"));
#endif
- setEditable(false);
+ setEditable(false);
}
QtVCardPhotoAndNameFields::~QtVCardPhotoAndNameFields() {
- delete ui;
+ delete ui;
}
bool QtVCardPhotoAndNameFields::isEditable() const {
- return editable;
+ return editable;
}
void QtVCardPhotoAndNameFields::setEditable(bool editable) {
- this->editable = editable;
+ this->editable = editable;
- ui->avatarWidget->setEditable(editable);
- ui->lineEditFN->setVisible(editable);
- ui->labelFN->setVisible(!editable);
+ ui->avatarWidget->setEditable(editable);
+ ui->lineEditFN->setVisible(editable);
+ ui->labelFN->setVisible(!editable);
- ui->lineEditNICKNAME->setVisible(editable);
- ui->labelNICKNAME->setVisible(!editable);
+ ui->lineEditNICKNAME->setVisible(editable);
+ ui->labelNICKNAME->setVisible(!editable);
- // prefix given middle last suffix
- ui->lineEditPREFIX->setVisible(editable);
- ui->lineEditGIVEN->setVisible(editable);
- ui->lineEditMIDDLE->setVisible(editable);
- ui->lineEditFAMILY->setVisible(editable);
- ui->lineEditSUFFIX->setVisible(editable);
- ui->labelFULLNAME->setVisible(!editable);
+ // prefix given middle last suffix
+ ui->lineEditPREFIX->setVisible(editable);
+ ui->lineEditGIVEN->setVisible(editable);
+ ui->lineEditMIDDLE->setVisible(editable);
+ ui->lineEditFAMILY->setVisible(editable);
+ ui->lineEditSUFFIX->setVisible(editable);
+ ui->labelFULLNAME->setVisible(!editable);
- QStringList fullname;
- fullname << ui->lineEditPREFIX->text() << ui->lineEditGIVEN->text() << ui->lineEditMIDDLE->text();
- fullname << ui->lineEditFAMILY->text() << ui->lineEditSUFFIX->text();
- for (QStringList::iterator i = fullname.begin(); i != fullname.end(); i++) {
- *i = i->trimmed();
- }
- ui->labelFULLNAME->setText((fullname.filter(QRegExp(".+"))).join(" "));
+ QStringList fullname;
+ fullname << ui->lineEditPREFIX->text() << ui->lineEditGIVEN->text() << ui->lineEditMIDDLE->text();
+ fullname << ui->lineEditFAMILY->text() << ui->lineEditSUFFIX->text();
+ for (QStringList::iterator i = fullname.begin(); i != fullname.end(); i++) {
+ *i = i->trimmed();
+ }
+ ui->labelFULLNAME->setText((fullname.filter(QRegExp(".+"))).join(" "));
}
void QtVCardPhotoAndNameFields::setAvatar(const ByteArray &data, const std::string &type) {
- ui->avatarWidget->setAvatar(data, type);
+ ui->avatarWidget->setAvatar(data, type);
}
ByteArray QtVCardPhotoAndNameFields::getAvatarData() const {
- return ui->avatarWidget->getAvatarData();
+ return ui->avatarWidget->getAvatarData();
}
std::string QtVCardPhotoAndNameFields::getAvatarType() const {
- return ui->avatarWidget->getAvatarType();
+ return ui->avatarWidget->getAvatarType();
}
void QtVCardPhotoAndNameFields::setFormattedName(const QString& formattedName) {
- ui->lineEditFN->setText(formattedName);
- ui->labelFN->setText(formattedName);
+ ui->lineEditFN->setText(formattedName);
+ ui->labelFN->setText(formattedName);
}
QString QtVCardPhotoAndNameFields::getFormattedName() const {
- return ui->lineEditFN->text();
+ return ui->lineEditFN->text();
}
void QtVCardPhotoAndNameFields::setNickname(const QString& nickname) {
- ui->lineEditNICKNAME->setText(nickname);
- ui->labelNICKNAME->setText(nickname);
+ ui->lineEditNICKNAME->setText(nickname);
+ ui->labelNICKNAME->setText(nickname);
}
QString QtVCardPhotoAndNameFields::getNickname() const {
- return ui->lineEditNICKNAME->text();
+ return ui->lineEditNICKNAME->text();
}
void QtVCardPhotoAndNameFields::setPrefix(const QString& prefix) {
- ui->lineEditPREFIX->setText(prefix);
+ ui->lineEditPREFIX->setText(prefix);
}
QString QtVCardPhotoAndNameFields::getPrefix() const {
- return ui->lineEditPREFIX->text();
+ return ui->lineEditPREFIX->text();
}
void QtVCardPhotoAndNameFields::setGivenName(const QString& givenName) {
- ui->lineEditGIVEN->setText(givenName);
+ ui->lineEditGIVEN->setText(givenName);
}
QString QtVCardPhotoAndNameFields::getGivenName() const {
- return ui->lineEditGIVEN->text();
+ return ui->lineEditGIVEN->text();
}
void QtVCardPhotoAndNameFields::setMiddleName(const QString& middleName) {
- ui->lineEditMIDDLE->setText(middleName);
+ ui->lineEditMIDDLE->setText(middleName);
}
QString QtVCardPhotoAndNameFields::getMiddleName() const {
- return ui->lineEditMIDDLE->text();
+ return ui->lineEditMIDDLE->text();
}
void QtVCardPhotoAndNameFields::setFamilyName(const QString& familyName) {
- ui->lineEditFAMILY->setText(familyName);
+ ui->lineEditFAMILY->setText(familyName);
}
QString QtVCardPhotoAndNameFields::getFamilyName() const {
- return ui->lineEditFAMILY->text();
+ return ui->lineEditFAMILY->text();
}
void QtVCardPhotoAndNameFields::setSuffix(const QString& suffix) {
- ui->lineEditSUFFIX->setText(suffix);
+ ui->lineEditSUFFIX->setText(suffix);
}
QString QtVCardPhotoAndNameFields::getSuffix() const {
- return ui->lineEditSUFFIX->text();
+ return ui->lineEditSUFFIX->text();
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h
index ac35109..a0bbb24 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h
@@ -12,51 +12,51 @@
#include <Swiften/Base/ByteArray.h>
namespace Ui {
- class QtVCardPhotoAndNameFields;
+ class QtVCardPhotoAndNameFields;
}
namespace Swift {
- class QtVCardPhotoAndNameFields : public QWidget {
- Q_OBJECT
- Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+ class QtVCardPhotoAndNameFields : public QWidget {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
- public:
- explicit QtVCardPhotoAndNameFields(QWidget* parent = 0);
- ~QtVCardPhotoAndNameFields();
+ public:
+ explicit QtVCardPhotoAndNameFields(QWidget* parent = 0);
+ ~QtVCardPhotoAndNameFields();
- bool isEditable() const;
- void setEditable(bool);
+ bool isEditable() const;
+ void setEditable(bool);
- void setAvatar(const ByteArray& data, const std::string& type);
- ByteArray getAvatarData() const;
- std::string getAvatarType() const;
+ void setAvatar(const ByteArray& data, const std::string& type);
+ ByteArray getAvatarData() const;
+ std::string getAvatarType() const;
- void setFormattedName(const QString& formattedName);
- QString getFormattedName() const;
+ void setFormattedName(const QString& formattedName);
+ QString getFormattedName() const;
- void setNickname(const QString& nickname);
- QString getNickname() const;
+ void setNickname(const QString& nickname);
+ QString getNickname() const;
- void setPrefix(const QString& prefix);
- QString getPrefix() const;
+ void setPrefix(const QString& prefix);
+ QString getPrefix() const;
- void setGivenName(const QString& givenName);
- QString getGivenName() const;
+ void setGivenName(const QString& givenName);
+ QString getGivenName() const;
- void setMiddleName(const QString& middleName);
- QString getMiddleName() const;
+ void setMiddleName(const QString& middleName);
+ QString getMiddleName() const;
- void setFamilyName(const QString& familyName);
- QString getFamilyName() const;
+ void setFamilyName(const QString& familyName);
+ QString getFamilyName() const;
- void setSuffix(const QString& suffix);
- QString getSuffix() const;
+ void setSuffix(const QString& suffix);
+ QString getSuffix() const;
- private:
- Ui::QtVCardPhotoAndNameFields* ui;
- bool editable;
- };
+ private:
+ Ui::QtVCardPhotoAndNameFields* ui;
+ bool editable;
+ };
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp
index ce3cc2f..2881932 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp
@@ -21,37 +21,37 @@
namespace Swift {
QtVCardRoleField::QtVCardRoleField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Role"), false, false), roleLineEdit(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Role"), false, false), roleLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardRoleField::~QtVCardRoleField() {
}
void QtVCardRoleField::setupContentWidgets() {
- roleLineEdit = new QtResizableLineEdit(this);
- getGridLayout()->addWidget(roleLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
- getTagComboBox()->hide();
- childWidgets << roleLineEdit;
+ roleLineEdit = new QtResizableLineEdit(this);
+ getGridLayout()->addWidget(roleLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ getTagComboBox()->hide();
+ childWidgets << roleLineEdit;
}
bool QtVCardRoleField::isEmpty() const {
- return roleLineEdit->text().isEmpty();
+ return roleLineEdit->text().isEmpty();
}
void QtVCardRoleField::setRole(const std::string& role) {
- roleLineEdit->setText(P2QSTRING(role));
+ roleLineEdit->setText(P2QSTRING(role));
}
std::string QtVCardRoleField::getRole() const {
- return Q2PSTRING(roleLineEdit->text());
+ return Q2PSTRING(roleLineEdit->text());
}
void QtVCardRoleField::handleEditibleChanged(bool isEditable) {
- assert(roleLineEdit);
+ assert(roleLineEdit);
- roleLineEdit->setEditable(isEditable);
- roleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
+ roleLineEdit->setEditable(isEditable);
+ roleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardRoleField.h b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.h
index f2d5e75..40b5d0b 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardRoleField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.h
@@ -21,27 +21,27 @@
namespace Swift {
class QtVCardRoleField : public QtVCardGeneralField {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("Role"), UNLIMITED_INSTANCES, QtVCardRoleField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("Role"), UNLIMITED_INSTANCES, QtVCardRoleField)
- QtVCardRoleField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardRoleField();
+ QtVCardRoleField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardRoleField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setRole(const std::string& role);
- std::string getRole() const;
+ void setRole(const std::string& role);
+ std::string getRole() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QtResizableLineEdit* roleLineEdit;
+ private:
+ QtResizableLineEdit* roleLineEdit;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp
index 57e2b27..4af2fa3 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp
@@ -19,88 +19,88 @@
namespace Swift {
QtVCardTelephoneField::QtVCardTelephoneField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Telephone")), telephoneLineEdit(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Telephone")), telephoneLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardTelephoneField::~QtVCardTelephoneField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardTelephoneField::setupContentWidgets() {
- telephoneLineEdit = new QtResizableLineEdit(this);
+ telephoneLineEdit = new QtResizableLineEdit(this);
#if QT_VERSION >= 0x040700
- telephoneLineEdit->setPlaceholderText(tr("0118 999 881 999 119 7253"));
+ telephoneLineEdit->setPlaceholderText(tr("0118 999 881 999 119 7253"));
#endif
- getGridLayout()->addWidget(telephoneLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
- setTabOrder(telephoneLineEdit, getTagComboBox());
- QtVCardHomeWork::setTagComboBox(getTagComboBox());
-
- getTagComboBox()->addTag("voice", QObject::tr("Voice"));
- getTagComboBox()->addTag("fax", QObject::tr("Fax"));
- getTagComboBox()->addTag("pager", QObject::tr("Pager"));
- getTagComboBox()->addTag("msg", QObject::tr("Voice Messaging"));
- getTagComboBox()->addTag("cell", QObject::tr("Cell"));
- getTagComboBox()->addTag("video", QObject::tr("Video"));
- getTagComboBox()->addTag("bbs", QObject::tr("Bulletin Board System"));
- getTagComboBox()->addTag("modem", QObject::tr("Modem"));
- getTagComboBox()->addTag("isdn", QObject::tr("ISDN"));
- getTagComboBox()->addTag("pcs", QObject::tr("Personal Communication Services"));
-
- childWidgets << telephoneLineEdit;
+ getGridLayout()->addWidget(telephoneLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ setTabOrder(telephoneLineEdit, getTagComboBox());
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
+
+ getTagComboBox()->addTag("voice", QObject::tr("Voice"));
+ getTagComboBox()->addTag("fax", QObject::tr("Fax"));
+ getTagComboBox()->addTag("pager", QObject::tr("Pager"));
+ getTagComboBox()->addTag("msg", QObject::tr("Voice Messaging"));
+ getTagComboBox()->addTag("cell", QObject::tr("Cell"));
+ getTagComboBox()->addTag("video", QObject::tr("Video"));
+ getTagComboBox()->addTag("bbs", QObject::tr("Bulletin Board System"));
+ getTagComboBox()->addTag("modem", QObject::tr("Modem"));
+ getTagComboBox()->addTag("isdn", QObject::tr("ISDN"));
+ getTagComboBox()->addTag("pcs", QObject::tr("Personal Communication Services"));
+
+ childWidgets << telephoneLineEdit;
}
bool QtVCardTelephoneField::isEmpty() const {
- return telephoneLineEdit->text().isEmpty();
+ return telephoneLineEdit->text().isEmpty();
}
void QtVCardTelephoneField::setTelephone(const VCard::Telephone& telephone) {
- setPreferred(telephone.isPreferred);
- setHome(telephone.isHome);
- setWork(telephone.isWork);
-
- telephoneLineEdit->setText(P2QSTRING(telephone.number));
-
- getTagComboBox()->setTag("voice", telephone.isVoice);
- getTagComboBox()->setTag("fax", telephone.isFax);
- getTagComboBox()->setTag("pager", telephone.isPager);
- getTagComboBox()->setTag("msg", telephone.isMSG);
- getTagComboBox()->setTag("cell", telephone.isCell);
- getTagComboBox()->setTag("video", telephone.isVideo);
- getTagComboBox()->setTag("bbs", telephone.isBBS);
- getTagComboBox()->setTag("modem", telephone.isModem);
- getTagComboBox()->setTag("isdn", telephone.isISDN);
- getTagComboBox()->setTag("pcs", telephone.isPCS);
+ setPreferred(telephone.isPreferred);
+ setHome(telephone.isHome);
+ setWork(telephone.isWork);
+
+ telephoneLineEdit->setText(P2QSTRING(telephone.number));
+
+ getTagComboBox()->setTag("voice", telephone.isVoice);
+ getTagComboBox()->setTag("fax", telephone.isFax);
+ getTagComboBox()->setTag("pager", telephone.isPager);
+ getTagComboBox()->setTag("msg", telephone.isMSG);
+ getTagComboBox()->setTag("cell", telephone.isCell);
+ getTagComboBox()->setTag("video", telephone.isVideo);
+ getTagComboBox()->setTag("bbs", telephone.isBBS);
+ getTagComboBox()->setTag("modem", telephone.isModem);
+ getTagComboBox()->setTag("isdn", telephone.isISDN);
+ getTagComboBox()->setTag("pcs", telephone.isPCS);
}
VCard::Telephone QtVCardTelephoneField::getTelephone() const {
- VCard::Telephone telephone;
-
- telephone.number = Q2PSTRING(telephoneLineEdit->text());
-
- telephone.isPreferred = getPreferred();
- telephone.isHome = getHome();
- telephone.isWork = getWork();
-
- telephone.isVoice = getTagComboBox()->isTagSet("voice");
- telephone.isFax = getTagComboBox()->isTagSet("fax");
- telephone.isPager = getTagComboBox()->isTagSet("pager");
- telephone.isMSG = getTagComboBox()->isTagSet("msg");
- telephone.isCell = getTagComboBox()->isTagSet("cell");
- telephone.isVideo = getTagComboBox()->isTagSet("video");
- telephone.isBBS = getTagComboBox()->isTagSet("bbs");
- telephone.isModem = getTagComboBox()->isTagSet("modem");
- telephone.isISDN = getTagComboBox()->isTagSet("isdn");
- telephone.isPCS = getTagComboBox()->isTagSet("pcs");
-
- return telephone;
+ VCard::Telephone telephone;
+
+ telephone.number = Q2PSTRING(telephoneLineEdit->text());
+
+ telephone.isPreferred = getPreferred();
+ telephone.isHome = getHome();
+ telephone.isWork = getWork();
+
+ telephone.isVoice = getTagComboBox()->isTagSet("voice");
+ telephone.isFax = getTagComboBox()->isTagSet("fax");
+ telephone.isPager = getTagComboBox()->isTagSet("pager");
+ telephone.isMSG = getTagComboBox()->isTagSet("msg");
+ telephone.isCell = getTagComboBox()->isTagSet("cell");
+ telephone.isVideo = getTagComboBox()->isTagSet("video");
+ telephone.isBBS = getTagComboBox()->isTagSet("bbs");
+ telephone.isModem = getTagComboBox()->isTagSet("modem");
+ telephone.isISDN = getTagComboBox()->isTagSet("isdn");
+ telephone.isPCS = getTagComboBox()->isTagSet("pcs");
+
+ return telephone;
}
void QtVCardTelephoneField::handleEditibleChanged(bool isEditable) {
- assert(telephoneLineEdit);
+ assert(telephoneLineEdit);
- telephoneLineEdit->setEditable(isEditable);
- telephoneLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
+ telephoneLineEdit->setEditable(isEditable);
+ telephoneLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h
index a06eb32..1a08a5a 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h
@@ -22,27 +22,27 @@
namespace Swift {
class QtVCardTelephoneField : public QtVCardGeneralField, public QtVCardHomeWork {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("Telephone"), UNLIMITED_INSTANCES, QtVCardTelephoneField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("Telephone"), UNLIMITED_INSTANCES, QtVCardTelephoneField)
- QtVCardTelephoneField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardTelephoneField();
+ QtVCardTelephoneField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardTelephoneField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setTelephone(const VCard::Telephone& telephone);
- VCard::Telephone getTelephone() const;
+ void setTelephone(const VCard::Telephone& telephone);
+ VCard::Telephone getTelephone() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QtResizableLineEdit* telephoneLineEdit;
+ private:
+ QtResizableLineEdit* telephoneLineEdit;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp
index aab7fac..5da5763 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp
@@ -21,38 +21,38 @@
namespace Swift {
QtVCardTitleField::QtVCardTitleField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Title"), false, false), titleLineEdit(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Title"), false, false), titleLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardTitleField::~QtVCardTitleField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardTitleField::setupContentWidgets() {
- titleLineEdit = new QtResizableLineEdit(this);
- getGridLayout()->addWidget(titleLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
- getTagComboBox()->hide();
- childWidgets << titleLineEdit;
+ titleLineEdit = new QtResizableLineEdit(this);
+ getGridLayout()->addWidget(titleLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ getTagComboBox()->hide();
+ childWidgets << titleLineEdit;
}
bool QtVCardTitleField::isEmpty() const {
- return titleLineEdit->text().isEmpty();
+ return titleLineEdit->text().isEmpty();
}
void QtVCardTitleField::setTitle(const std::string& title) {
- titleLineEdit->setText(P2QSTRING(title));
+ titleLineEdit->setText(P2QSTRING(title));
}
std::string QtVCardTitleField::getTitle() const {
- return Q2PSTRING(titleLineEdit->text());
+ return Q2PSTRING(titleLineEdit->text());
}
void QtVCardTitleField::handleEditibleChanged(bool isEditable) {
- assert(titleLineEdit);
+ assert(titleLineEdit);
- titleLineEdit->setEditable(isEditable);
- titleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
+ titleLineEdit->setEditable(isEditable);
+ titleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTitleField.h b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.h
index a7feb81..ff2a04e 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardTitleField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.h
@@ -21,27 +21,27 @@
namespace Swift {
class QtVCardTitleField : public QtVCardGeneralField {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("Title"), UNLIMITED_INSTANCES, QtVCardTitleField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("Title"), UNLIMITED_INSTANCES, QtVCardTitleField)
- QtVCardTitleField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardTitleField();
+ QtVCardTitleField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardTitleField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setTitle(const std::string& title);
- std::string getTitle() const;
+ void setTitle(const std::string& title);
+ std::string getTitle() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QtResizableLineEdit* titleLineEdit;
+ private:
+ QtResizableLineEdit* titleLineEdit;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp
index 262a0e2..8abc46e 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp
@@ -24,54 +24,54 @@
namespace Swift {
QtVCardURLField::QtVCardURLField(QWidget* parent, QGridLayout *layout, bool editable) :
- QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("URL"), false, false), urlLabel(NULL), urlLineEdit(NULL) {
- connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("URL"), false, false), urlLabel(NULL), urlLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}
QtVCardURLField::~QtVCardURLField() {
- disconnect(this, SLOT(handleEditibleChanged(bool)));
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
}
void QtVCardURLField::setupContentWidgets() {
- urlLabel = new QLabel(this);
- urlLabel->setOpenExternalLinks(true);
- urlLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
- urlLineEdit = new QtResizableLineEdit(this);
-
- QHBoxLayout* urlLayout = new QHBoxLayout();
- urlLayout->addWidget(urlLabel);
- urlLayout->addWidget(urlLineEdit);
-
- getGridLayout()->addLayout(urlLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
- getTagComboBox()->hide();
- urlLabel->hide();
- childWidgets << urlLabel << urlLineEdit;
+ urlLabel = new QLabel(this);
+ urlLabel->setOpenExternalLinks(true);
+ urlLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
+ urlLineEdit = new QtResizableLineEdit(this);
+
+ QHBoxLayout* urlLayout = new QHBoxLayout();
+ urlLayout->addWidget(urlLabel);
+ urlLayout->addWidget(urlLineEdit);
+
+ getGridLayout()->addLayout(urlLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ getTagComboBox()->hide();
+ urlLabel->hide();
+ childWidgets << urlLabel << urlLineEdit;
}
bool QtVCardURLField::isEmpty() const {
- return urlLineEdit->text().isEmpty();
+ return urlLineEdit->text().isEmpty();
}
void QtVCardURLField::setURL(const std::string& url) {
- urlLineEdit->setText(P2QSTRING(url));
+ urlLineEdit->setText(P2QSTRING(url));
}
std::string QtVCardURLField::getURL() const {
- return Q2PSTRING(urlLineEdit->text());
+ return Q2PSTRING(urlLineEdit->text());
}
void QtVCardURLField::handleEditibleChanged(bool isEditable) {
- assert(urlLineEdit);
- assert(urlLabel);
-
- if (isEditable) {
- urlLineEdit->show();
- urlLabel->hide();
- } else {
- urlLineEdit->hide();
- urlLabel->setText(QString("<a href=\"%1\">%1</a>").arg(QtUtilities::htmlEscape(urlLineEdit->text())));
- urlLabel->show();
- }
+ assert(urlLineEdit);
+ assert(urlLabel);
+
+ if (isEditable) {
+ urlLineEdit->show();
+ urlLabel->hide();
+ } else {
+ urlLineEdit->hide();
+ urlLabel->setText(QString("<a href=\"%1\">%1</a>").arg(QtUtilities::htmlEscape(urlLineEdit->text())));
+ urlLabel->show();
+ }
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardURLField.h b/Swift/QtUI/QtVCardWidget/QtVCardURLField.h
index 824879a..a1ffacd 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardURLField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardURLField.h
@@ -21,28 +21,28 @@
namespace Swift {
class QtVCardURLField : public QtVCardGeneralField {
- Q_OBJECT
+ Q_OBJECT
- public:
- GENERIC_QT_VCARD_FIELD_INFO(tr("URL"), UNLIMITED_INSTANCES, QtVCardURLField)
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO(tr("URL"), UNLIMITED_INSTANCES, QtVCardURLField)
- QtVCardURLField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
- virtual ~QtVCardURLField();
+ QtVCardURLField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardURLField();
- virtual bool isEmpty() const;
+ virtual bool isEmpty() const;
- void setURL(const std::string& url);
- std::string getURL() const;
+ void setURL(const std::string& url);
+ std::string getURL() const;
- protected:
- virtual void setupContentWidgets();
+ protected:
+ virtual void setupContentWidgets();
- public slots:
- void handleEditibleChanged(bool isEditable);
+ public slots:
+ void handleEditibleChanged(bool isEditable);
- private:
- QLabel* urlLabel;
- QtResizableLineEdit* urlLineEdit;
+ private:
+ QLabel* urlLabel;
+ QtResizableLineEdit* urlLineEdit;
};
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
index f390d30..712cedf 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
@@ -33,394 +33,394 @@
namespace Swift {
QtVCardWidget::QtVCardWidget(QWidget* parent) :
- QWidget(parent),
- ui(new ::Ui::QtVCardWidget) {
- ui->setupUi(this);
-
- ui->cardFields->setColumnStretch(0,0);
- ui->cardFields->setColumnStretch(1,0);
- ui->cardFields->setColumnStretch(2,2);
- ui->cardFields->setColumnStretch(3,1);
- ui->cardFields->setColumnStretch(4,2);
- menu = new QMenu(this);
-
- toolButton = new QToolButton(this);
- toolButton->setText(tr("Add Field"));
- toolButton->setArrowType(Qt::NoArrow);
- toolButton->setAutoRaise(false);
- toolButton->setPopupMode(QToolButton::InstantPopup);
- toolButton->hide();
- toolButton->setMenu(menu);
-
- addFieldType(menu, boost::make_shared<QtVCardInternetEMailField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardTelephoneField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardAddressField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardAddressLabelField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardBirthdayField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardJIDField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardDescriptionField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardRoleField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardTitleField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardOrganizationField::FieldInfo>());
- addFieldType(menu, boost::make_shared<QtVCardURLField::FieldInfo>());
-
- setEditable(false);
- setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ QWidget(parent),
+ ui(new ::Ui::QtVCardWidget) {
+ ui->setupUi(this);
+
+ ui->cardFields->setColumnStretch(0,0);
+ ui->cardFields->setColumnStretch(1,0);
+ ui->cardFields->setColumnStretch(2,2);
+ ui->cardFields->setColumnStretch(3,1);
+ ui->cardFields->setColumnStretch(4,2);
+ menu = new QMenu(this);
+
+ toolButton = new QToolButton(this);
+ toolButton->setText(tr("Add Field"));
+ toolButton->setArrowType(Qt::NoArrow);
+ toolButton->setAutoRaise(false);
+ toolButton->setPopupMode(QToolButton::InstantPopup);
+ toolButton->hide();
+ toolButton->setMenu(menu);
+
+ addFieldType(menu, boost::make_shared<QtVCardInternetEMailField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardTelephoneField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardAddressField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardAddressLabelField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardBirthdayField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardJIDField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardDescriptionField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardRoleField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardTitleField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardOrganizationField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardURLField::FieldInfo>());
+
+ setEditable(false);
+ setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
}
QtVCardWidget::~QtVCardWidget() {
- delete ui;
+ delete ui;
}
QSize QtVCardWidget::sizeHint() const {
- QSize newSizeHint = ui->photoAndName->sizeHint();
+ QSize newSizeHint = ui->photoAndName->sizeHint();
- // use mininmal size that does not require scrolling
- QSize fieldsWidgetSize = ui->scrollArea->widget()->minimumSize();
- fieldsWidgetSize.setWidth(ui->scrollArea->widget()->sizeHint().width());
+ // use mininmal size that does not require scrolling
+ QSize fieldsWidgetSize = ui->scrollArea->widget()->minimumSize();
+ fieldsWidgetSize.setWidth(ui->scrollArea->widget()->sizeHint().width());
- newSizeHint += QSize(0, ui->line->height());
+ newSizeHint += QSize(0, ui->line->height());
- newSizeHint = QSize(std::max(newSizeHint.width(), fieldsWidgetSize.width()), newSizeHint.height() + fieldsWidgetSize.height());
+ newSizeHint = QSize(std::max(newSizeHint.width(), fieldsWidgetSize.width()), newSizeHint.height() + fieldsWidgetSize.height());
- // add layout margin
- newSizeHint += QSize(layout()->contentsMargins().left() + layout()->contentsMargins().right(), layout()->contentsMargins().top() + layout()->contentsMargins().bottom());
+ // add layout margin
+ newSizeHint += QSize(layout()->contentsMargins().left() + layout()->contentsMargins().right(), layout()->contentsMargins().top() + layout()->contentsMargins().bottom());
- // the spaceing before and after the line between the profile header and its fields
- newSizeHint += QSize(0, layout()->spacing() * 2);
+ // the spaceing before and after the line between the profile header and its fields
+ newSizeHint += QSize(0, layout()->spacing() * 2);
- return newSizeHint;
+ return newSizeHint;
}
bool QtVCardWidget::isEditable() const {
- return editable;
+ return editable;
}
void QtVCardWidget::setEditable(bool editable) {
- this->editable = editable;
+ this->editable = editable;
- ui->photoAndName->setProperty("editable", QVariant(editable));
+ ui->photoAndName->setProperty("editable", QVariant(editable));
- foreach(QtVCardGeneralField* field, fields) {
- field->setEditable(editable);
- }
- toolButton->setVisible(editable);
+ foreach(QtVCardGeneralField* field, fields) {
+ field->setEditable(editable);
+ }
+ toolButton->setVisible(editable);
- editableChanged(editable);
+ editableChanged(editable);
}
void QtVCardWidget::setVCard(VCard::ref vcard) {
- clearFields();
- this->vcard = boost::make_shared<VCard>(*vcard);
- ui->photoAndName->setFormattedName(P2QSTRING(vcard->getFullName()));
- ui->photoAndName->setNickname(P2QSTRING(vcard->getNickname()));
- ui->photoAndName->setPrefix(P2QSTRING(vcard->getPrefix()));
- ui->photoAndName->setGivenName(P2QSTRING(vcard->getGivenName()));
- ui->photoAndName->setMiddleName(P2QSTRING(vcard->getMiddleName()));
- ui->photoAndName->setFamilyName(P2QSTRING(vcard->getFamilyName()));
- ui->photoAndName->setSuffix(P2QSTRING(vcard->getSuffix()));
- ui->photoAndName->setAvatar(vcard->getPhoto(), vcard->getPhotoType());
-
- foreach (const VCard::EMailAddress& address, vcard->getEMailAddresses()) {
- if (address.isInternet) {
- QtVCardInternetEMailField* internetEmailField = new QtVCardInternetEMailField(this, ui->cardFields);
- internetEmailField->initialize();
- internetEmailField->setInternetEMailAddress(address);
- appendField(internetEmailField);
- }
- }
-
- foreach (const VCard::Telephone& telephone, vcard->getTelephones()) {
- QtVCardTelephoneField* telField = new QtVCardTelephoneField(this, ui->cardFields);
- telField->initialize();
- telField->setTelephone(telephone);
- appendField(telField);
- }
-
- foreach (const VCard::Address& address, vcard->getAddresses()) {
- QtVCardAddressField* addressField = new QtVCardAddressField(this, ui->cardFields);
- addressField->initialize();
- addressField->setAddress(address);
- appendField(addressField);
- }
-
- foreach (const VCard::AddressLabel& label, vcard->getAddressLabels()) {
- QtVCardAddressLabelField* addressLabelField = new QtVCardAddressLabelField(this, ui->cardFields);
- addressLabelField->initialize();
- addressLabelField->setAddressLabel(label);
- appendField(addressLabelField);
- }
-
- if (!vcard->getBirthday().is_not_a_date_time()) {
- QtVCardBirthdayField* bdayField = new QtVCardBirthdayField(this, ui->cardFields);
- bdayField->initialize();
- bdayField->setBirthday(vcard->getBirthday());
- appendField(bdayField);
- }
-
- foreach (const JID& jid, vcard->getJIDs()) {
- QtVCardJIDField* jidField = new QtVCardJIDField(this, ui->cardFields);
- jidField->initialize();
- jidField->setJID(jid);
- appendField(jidField);
- }
-
- if (!vcard->getDescription().empty()) {
- QtVCardDescriptionField* descField = new QtVCardDescriptionField(this, ui->cardFields);
- descField->initialize();
- descField->setDescription(vcard->getDescription());
- appendField(descField);
- }
-
- foreach (const VCard::Organization& org, vcard->getOrganizations()) {
- QtVCardOrganizationField* orgField = new QtVCardOrganizationField(this, ui->cardFields);
- orgField->initialize();
- orgField->setOrganization(org);
- appendField(orgField);
- }
-
- foreach (const std::string& role, vcard->getRoles()) {
- QtVCardRoleField* roleField = new QtVCardRoleField(this, ui->cardFields);
- roleField->initialize();
- roleField->setRole(role);
- appendField(roleField);
- }
-
- foreach (const std::string& title, vcard->getTitles()) {
- QtVCardTitleField* titleField = new QtVCardTitleField(this, ui->cardFields);
- titleField->initialize();
- titleField->setTitle(title);
- appendField(titleField);
- }
-
- foreach (const std::string& url, vcard->getURLs()) {
- QtVCardURLField* urlField = new QtVCardURLField(this, ui->cardFields);
- urlField->initialize();
- urlField->setURL(url);
- appendField(urlField);
- }
-
- relayoutToolButton();
- setEditable(editable);
+ clearFields();
+ this->vcard = boost::make_shared<VCard>(*vcard);
+ ui->photoAndName->setFormattedName(P2QSTRING(vcard->getFullName()));
+ ui->photoAndName->setNickname(P2QSTRING(vcard->getNickname()));
+ ui->photoAndName->setPrefix(P2QSTRING(vcard->getPrefix()));
+ ui->photoAndName->setGivenName(P2QSTRING(vcard->getGivenName()));
+ ui->photoAndName->setMiddleName(P2QSTRING(vcard->getMiddleName()));
+ ui->photoAndName->setFamilyName(P2QSTRING(vcard->getFamilyName()));
+ ui->photoAndName->setSuffix(P2QSTRING(vcard->getSuffix()));
+ ui->photoAndName->setAvatar(vcard->getPhoto(), vcard->getPhotoType());
+
+ foreach (const VCard::EMailAddress& address, vcard->getEMailAddresses()) {
+ if (address.isInternet) {
+ QtVCardInternetEMailField* internetEmailField = new QtVCardInternetEMailField(this, ui->cardFields);
+ internetEmailField->initialize();
+ internetEmailField->setInternetEMailAddress(address);
+ appendField(internetEmailField);
+ }
+ }
+
+ foreach (const VCard::Telephone& telephone, vcard->getTelephones()) {
+ QtVCardTelephoneField* telField = new QtVCardTelephoneField(this, ui->cardFields);
+ telField->initialize();
+ telField->setTelephone(telephone);
+ appendField(telField);
+ }
+
+ foreach (const VCard::Address& address, vcard->getAddresses()) {
+ QtVCardAddressField* addressField = new QtVCardAddressField(this, ui->cardFields);
+ addressField->initialize();
+ addressField->setAddress(address);
+ appendField(addressField);
+ }
+
+ foreach (const VCard::AddressLabel& label, vcard->getAddressLabels()) {
+ QtVCardAddressLabelField* addressLabelField = new QtVCardAddressLabelField(this, ui->cardFields);
+ addressLabelField->initialize();
+ addressLabelField->setAddressLabel(label);
+ appendField(addressLabelField);
+ }
+
+ if (!vcard->getBirthday().is_not_a_date_time()) {
+ QtVCardBirthdayField* bdayField = new QtVCardBirthdayField(this, ui->cardFields);
+ bdayField->initialize();
+ bdayField->setBirthday(vcard->getBirthday());
+ appendField(bdayField);
+ }
+
+ foreach (const JID& jid, vcard->getJIDs()) {
+ QtVCardJIDField* jidField = new QtVCardJIDField(this, ui->cardFields);
+ jidField->initialize();
+ jidField->setJID(jid);
+ appendField(jidField);
+ }
+
+ if (!vcard->getDescription().empty()) {
+ QtVCardDescriptionField* descField = new QtVCardDescriptionField(this, ui->cardFields);
+ descField->initialize();
+ descField->setDescription(vcard->getDescription());
+ appendField(descField);
+ }
+
+ foreach (const VCard::Organization& org, vcard->getOrganizations()) {
+ QtVCardOrganizationField* orgField = new QtVCardOrganizationField(this, ui->cardFields);
+ orgField->initialize();
+ orgField->setOrganization(org);
+ appendField(orgField);
+ }
+
+ foreach (const std::string& role, vcard->getRoles()) {
+ QtVCardRoleField* roleField = new QtVCardRoleField(this, ui->cardFields);
+ roleField->initialize();
+ roleField->setRole(role);
+ appendField(roleField);
+ }
+
+ foreach (const std::string& title, vcard->getTitles()) {
+ QtVCardTitleField* titleField = new QtVCardTitleField(this, ui->cardFields);
+ titleField->initialize();
+ titleField->setTitle(title);
+ appendField(titleField);
+ }
+
+ foreach (const std::string& url, vcard->getURLs()) {
+ QtVCardURLField* urlField = new QtVCardURLField(this, ui->cardFields);
+ urlField->initialize();
+ urlField->setURL(url);
+ appendField(urlField);
+ }
+
+ relayoutToolButton();
+ setEditable(editable);
}
VCard::ref QtVCardWidget::getVCard() {
- clearEmptyFields();
- vcard->setFullName(Q2PSTRING(ui->photoAndName->getFormattedName()));
- vcard->setNickname(Q2PSTRING(ui->photoAndName->getNickname()));
- vcard->setPrefix(Q2PSTRING(ui->photoAndName->getPrefix()));
- vcard->setGivenName(Q2PSTRING(ui->photoAndName->getGivenName()));
- vcard->setMiddleName(Q2PSTRING(ui->photoAndName->getMiddleName()));
- vcard->setFamilyName(Q2PSTRING(ui->photoAndName->getFamilyName()));
- vcard->setSuffix(Q2PSTRING(ui->photoAndName->getSuffix()));
- vcard->setPhoto(ui->photoAndName->getAvatarData());
- vcard->setPhotoType(ui->photoAndName->getAvatarType());
-
- vcard->clearEMailAddresses();
- vcard->clearJIDs();
- vcard->clearURLs();
- vcard->clearTelephones();
- vcard->clearRoles();
- vcard->clearTitles();
- vcard->clearOrganizations();
- vcard->clearAddresses();
- vcard->clearAddressLabels();
-
-
- QtVCardBirthdayField* bdayField = NULL;
- QtVCardDescriptionField* descriptionField = NULL;
-
- foreach(QtVCardGeneralField* field, fields) {
- QtVCardInternetEMailField* emailField;
- if ((emailField = dynamic_cast<QtVCardInternetEMailField*>(field))) {
- vcard->addEMailAddress(emailField->getInternetEMailAddress());
- continue;
- }
-
- QtVCardTelephoneField* telephoneField;
- if ((telephoneField = dynamic_cast<QtVCardTelephoneField*>(field))) {
- vcard->addTelephone(telephoneField->getTelephone());
- continue;
- }
-
- QtVCardAddressField* addressField;
- if ((addressField = dynamic_cast<QtVCardAddressField*>(field))) {
- vcard->addAddress(addressField->getAddress());
- continue;
- }
-
- QtVCardAddressLabelField* addressLabelField;
- if ((addressLabelField = dynamic_cast<QtVCardAddressLabelField*>(field))) {
- vcard->addAddressLabel(addressLabelField->getAddressLabel());
- continue;
- }
-
- if ((bdayField = dynamic_cast<QtVCardBirthdayField*>(field))) {
- continue;
- }
-
- QtVCardJIDField* jidField;
- if ((jidField = dynamic_cast<QtVCardJIDField*>(field))) {
- vcard->addJID(jidField->getJID());
- continue;
- }
-
- if ((descriptionField = dynamic_cast<QtVCardDescriptionField*>(field))) {
- continue;
- }
-
- QtVCardOrganizationField* orgField;
- if ((orgField = dynamic_cast<QtVCardOrganizationField*>(field))) {
- vcard->addOrganization(orgField->getOrganization());
- continue;
- }
-
- QtVCardRoleField* roleField;
- if ((roleField = dynamic_cast<QtVCardRoleField*>(field))) {
- vcard->addRole(roleField->getRole());
- continue;
- }
-
- QtVCardTitleField* titleField;
- if ((titleField = dynamic_cast<QtVCardTitleField*>(field))) {
- vcard->addTitle(titleField->getTitle());
- continue;
- }
-
- QtVCardURLField* urlField;
- if ((urlField = dynamic_cast<QtVCardURLField*>(field))) {
- vcard->addURL(urlField->getURL());
- continue;
- }
- }
-
- if (bdayField) {
- vcard->setBirthday(bdayField->getBirthday());
- } else {
- vcard->setBirthday(boost::posix_time::ptime());
- }
-
- if (descriptionField) {
- vcard->setDescription(descriptionField->getDescription());
- } else {
- vcard->setDescription("");
- }
-
- return vcard;
+ clearEmptyFields();
+ vcard->setFullName(Q2PSTRING(ui->photoAndName->getFormattedName()));
+ vcard->setNickname(Q2PSTRING(ui->photoAndName->getNickname()));
+ vcard->setPrefix(Q2PSTRING(ui->photoAndName->getPrefix()));
+ vcard->setGivenName(Q2PSTRING(ui->photoAndName->getGivenName()));
+ vcard->setMiddleName(Q2PSTRING(ui->photoAndName->getMiddleName()));
+ vcard->setFamilyName(Q2PSTRING(ui->photoAndName->getFamilyName()));
+ vcard->setSuffix(Q2PSTRING(ui->photoAndName->getSuffix()));
+ vcard->setPhoto(ui->photoAndName->getAvatarData());
+ vcard->setPhotoType(ui->photoAndName->getAvatarType());
+
+ vcard->clearEMailAddresses();
+ vcard->clearJIDs();
+ vcard->clearURLs();
+ vcard->clearTelephones();
+ vcard->clearRoles();
+ vcard->clearTitles();
+ vcard->clearOrganizations();
+ vcard->clearAddresses();
+ vcard->clearAddressLabels();
+
+
+ QtVCardBirthdayField* bdayField = NULL;
+ QtVCardDescriptionField* descriptionField = NULL;
+
+ foreach(QtVCardGeneralField* field, fields) {
+ QtVCardInternetEMailField* emailField;
+ if ((emailField = dynamic_cast<QtVCardInternetEMailField*>(field))) {
+ vcard->addEMailAddress(emailField->getInternetEMailAddress());
+ continue;
+ }
+
+ QtVCardTelephoneField* telephoneField;
+ if ((telephoneField = dynamic_cast<QtVCardTelephoneField*>(field))) {
+ vcard->addTelephone(telephoneField->getTelephone());
+ continue;
+ }
+
+ QtVCardAddressField* addressField;
+ if ((addressField = dynamic_cast<QtVCardAddressField*>(field))) {
+ vcard->addAddress(addressField->getAddress());
+ continue;
+ }
+
+ QtVCardAddressLabelField* addressLabelField;
+ if ((addressLabelField = dynamic_cast<QtVCardAddressLabelField*>(field))) {
+ vcard->addAddressLabel(addressLabelField->getAddressLabel());
+ continue;
+ }
+
+ if ((bdayField = dynamic_cast<QtVCardBirthdayField*>(field))) {
+ continue;
+ }
+
+ QtVCardJIDField* jidField;
+ if ((jidField = dynamic_cast<QtVCardJIDField*>(field))) {
+ vcard->addJID(jidField->getJID());
+ continue;
+ }
+
+ if ((descriptionField = dynamic_cast<QtVCardDescriptionField*>(field))) {
+ continue;
+ }
+
+ QtVCardOrganizationField* orgField;
+ if ((orgField = dynamic_cast<QtVCardOrganizationField*>(field))) {
+ vcard->addOrganization(orgField->getOrganization());
+ continue;
+ }
+
+ QtVCardRoleField* roleField;
+ if ((roleField = dynamic_cast<QtVCardRoleField*>(field))) {
+ vcard->addRole(roleField->getRole());
+ continue;
+ }
+
+ QtVCardTitleField* titleField;
+ if ((titleField = dynamic_cast<QtVCardTitleField*>(field))) {
+ vcard->addTitle(titleField->getTitle());
+ continue;
+ }
+
+ QtVCardURLField* urlField;
+ if ((urlField = dynamic_cast<QtVCardURLField*>(field))) {
+ vcard->addURL(urlField->getURL());
+ continue;
+ }
+ }
+
+ if (bdayField) {
+ vcard->setBirthday(bdayField->getBirthday());
+ } else {
+ vcard->setBirthday(boost::posix_time::ptime());
+ }
+
+ if (descriptionField) {
+ vcard->setDescription(descriptionField->getDescription());
+ } else {
+ vcard->setDescription("");
+ }
+
+ return vcard;
}
void QtVCardWidget::addField() {
- QAction* action = NULL;
- if ((action = dynamic_cast<QAction*>(sender()))) {
- boost::shared_ptr<QtVCardFieldInfo> fieldInfo = actionFieldInfo[action];
- QWidget* newField = fieldInfo->createFieldInstance(this, ui->cardFields, true);
- QtVCardGeneralField* newGeneralField = dynamic_cast<QtVCardGeneralField*>(newField);
- if (newGeneralField) {
- newGeneralField->initialize();
- }
- appendField(newGeneralField);
- relayoutToolButton();
- }
+ QAction* action = NULL;
+ if ((action = dynamic_cast<QAction*>(sender()))) {
+ boost::shared_ptr<QtVCardFieldInfo> fieldInfo = actionFieldInfo[action];
+ QWidget* newField = fieldInfo->createFieldInstance(this, ui->cardFields, true);
+ QtVCardGeneralField* newGeneralField = dynamic_cast<QtVCardGeneralField*>(newField);
+ if (newGeneralField) {
+ newGeneralField->initialize();
+ }
+ appendField(newGeneralField);
+ relayoutToolButton();
+ }
}
void QtVCardWidget::removeField(QtVCardGeneralField *field) {
- int sameFields = 0;
- QtVCardGeneralField* fieldToChange = NULL;
- foreach (QtVCardGeneralField* vcardField, fields) {
- if ((vcardField != field) && (typeid(*vcardField) == typeid(*field))) {
- sameFields++;
- fieldToChange = vcardField;
- }
- }
-
- if ((sameFields == 1) && fieldToChange) {
- fieldToChange->setStarVisible(false);
- }
-
- fields.remove(field);
- delete field;
+ int sameFields = 0;
+ QtVCardGeneralField* fieldToChange = NULL;
+ foreach (QtVCardGeneralField* vcardField, fields) {
+ if ((vcardField != field) && (typeid(*vcardField) == typeid(*field))) {
+ sameFields++;
+ fieldToChange = vcardField;
+ }
+ }
+
+ if ((sameFields == 1) && fieldToChange) {
+ fieldToChange->setStarVisible(false);
+ }
+
+ fields.remove(field);
+ delete field;
}
void QtVCardWidget::addFieldType(QMenu* menu, boost::shared_ptr<QtVCardFieldInfo> fieldType) {
- if (!fieldType->getMenuName().isEmpty()) {
- QAction* action = new QAction(tr("Add %1").arg(fieldType->getMenuName()), this);
- actionFieldInfo[action] = fieldType;
- connect(action, SIGNAL(triggered()), this, SLOT(addField()));
- menu->addAction(action);
- }
+ if (!fieldType->getMenuName().isEmpty()) {
+ QAction* action = new QAction(tr("Add %1").arg(fieldType->getMenuName()), this);
+ actionFieldInfo[action] = fieldType;
+ connect(action, SIGNAL(triggered()), this, SLOT(addField()));
+ menu->addAction(action);
+ }
}
int QtVCardWidget::fieldTypeInstances(boost::shared_ptr<QtVCardFieldInfo> fieldType) {
- int instances = 0;
- for (int n = 0; n < ui->cardFields->count(); n++) {
- if (fieldType->testInstance(ui->cardFields->itemAt(n)->widget())) instances++;
- }
- return instances;
+ int instances = 0;
+ for (int n = 0; n < ui->cardFields->count(); n++) {
+ if (fieldType->testInstance(ui->cardFields->itemAt(n)->widget())) instances++;
+ }
+ return instances;
}
void layoutDeleteChildren(QLayout *layout) {
- while(layout->count() > 0) {
- QLayoutItem* child;
- if ((child = layout->takeAt(0)) != 0) {
- if (child->layout()) {
- layoutDeleteChildren(child->layout());
- }
- if (dynamic_cast<QToolButton*>(child->widget())) {
- delete child;
- break;
- }
- delete child->widget();
- delete child;
- }
- }
+ while(layout->count() > 0) {
+ QLayoutItem* child;
+ if ((child = layout->takeAt(0)) != 0) {
+ if (child->layout()) {
+ layoutDeleteChildren(child->layout());
+ }
+ if (dynamic_cast<QToolButton*>(child->widget())) {
+ delete child;
+ break;
+ }
+ delete child->widget();
+ delete child;
+ }
+ }
}
void QtVCardWidget::clearFields() {
- foreach(QtVCardGeneralField* field, fields) {
- delete field;
- }
- fields.clear();
+ foreach(QtVCardGeneralField* field, fields) {
+ delete field;
+ }
+ fields.clear();
- assert(ui->cardFields->count() >= 0);
- layoutDeleteChildren(ui->cardFields);
+ assert(ui->cardFields->count() >= 0);
+ layoutDeleteChildren(ui->cardFields);
}
void QtVCardWidget::clearEmptyFields() {
- std::vector<QtVCardGeneralField*> items_to_remove;
- foreach (QtVCardGeneralField* field, fields) {
- if (field->property("empty").isValid() && field->property("empty").toBool()) {
- ui->cardFields->removeWidget(field);
- items_to_remove.push_back(field);
- delete field;
- }
- }
-
- foreach(QtVCardGeneralField* field, items_to_remove) {
- fields.remove(field);
- }
+ std::vector<QtVCardGeneralField*> items_to_remove;
+ foreach (QtVCardGeneralField* field, fields) {
+ if (field->property("empty").isValid() && field->property("empty").toBool()) {
+ ui->cardFields->removeWidget(field);
+ items_to_remove.push_back(field);
+ delete field;
+ }
+ }
+
+ foreach(QtVCardGeneralField* field, items_to_remove) {
+ fields.remove(field);
+ }
}
void QtVCardWidget::appendField(QtVCardGeneralField *field) {
- connect(field, SIGNAL(deleteField(QtVCardGeneralField*)), SLOT(removeField(QtVCardGeneralField*)));
-
- QtVCardGeneralField* fieldToChange = NULL;
- foreach (QtVCardGeneralField* vcardField, fields) {
- if (typeid(*vcardField) == typeid(*field)) {
- fieldToChange = vcardField;
- break;
- }
- }
-
- if (fieldToChange) {
- fieldToChange->setStarVisible(true);
- field->setStarVisible(true);
- }
-
- fields.push_back(field);
+ connect(field, SIGNAL(deleteField(QtVCardGeneralField*)), SLOT(removeField(QtVCardGeneralField*)));
+
+ QtVCardGeneralField* fieldToChange = NULL;
+ foreach (QtVCardGeneralField* vcardField, fields) {
+ if (typeid(*vcardField) == typeid(*field)) {
+ fieldToChange = vcardField;
+ break;
+ }
+ }
+
+ if (fieldToChange) {
+ fieldToChange->setStarVisible(true);
+ field->setStarVisible(true);
+ }
+
+ fields.push_back(field);
}
void QtVCardWidget::relayoutToolButton() {
- ui->cardFields->addWidget(toolButton, ui->cardFields->rowCount(), ui->cardFields->columnCount()-2, 1, 1, Qt::AlignRight);
+ ui->cardFields->addWidget(toolButton, ui->cardFields->rowCount(), ui->cardFields->columnCount()-2, 1, 1, Qt::AlignRight);
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.h b/Swift/QtUI/QtVCardWidget/QtVCardWidget.h
index 8c0ff31..95283c5 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardWidget.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.h
@@ -24,50 +24,50 @@
#include <Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h>
namespace Ui {
- class QtVCardWidget;
+ class QtVCardWidget;
}
namespace Swift {
- class QtVCardWidget : public QWidget {
- Q_OBJECT
- Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
-
- public :
- explicit QtVCardWidget(QWidget* parent = 0);
- ~QtVCardWidget();
-
- bool isEditable() const;
- void setEditable(bool);
-
- void setVCard(VCard::ref vcard);
- VCard::ref getVCard();
-
- virtual QSize sizeHint() const;
-
- signals:
- void editableChanged(bool editable);
-
- private slots:
- void addField();
- void removeField(QtVCardGeneralField* field);
-
- private:
- void addFieldType(QMenu*, boost::shared_ptr<QtVCardFieldInfo>);
- int fieldTypeInstances(boost::shared_ptr<QtVCardFieldInfo>);
- void clearFields();
- void clearEmptyFields();
- void appendField(QtVCardGeneralField* field);
- void relayoutToolButton();
-
- private:
- VCard::ref vcard;
- Ui::QtVCardWidget* ui;
- QToolButton* toolButton;
- bool editable;
- QMenu* menu;
- std::list<QtVCardGeneralField*> fields;
- std::map<QAction*, boost::shared_ptr<QtVCardFieldInfo> > actionFieldInfo;
- };
+ class QtVCardWidget : public QWidget {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+
+ public :
+ explicit QtVCardWidget(QWidget* parent = 0);
+ ~QtVCardWidget();
+
+ bool isEditable() const;
+ void setEditable(bool);
+
+ void setVCard(VCard::ref vcard);
+ VCard::ref getVCard();
+
+ virtual QSize sizeHint() const;
+
+ signals:
+ void editableChanged(bool editable);
+
+ private slots:
+ void addField();
+ void removeField(QtVCardGeneralField* field);
+
+ private:
+ void addFieldType(QMenu*, boost::shared_ptr<QtVCardFieldInfo>);
+ int fieldTypeInstances(boost::shared_ptr<QtVCardFieldInfo>);
+ void clearFields();
+ void clearEmptyFields();
+ void appendField(QtVCardGeneralField* field);
+ void relayoutToolButton();
+
+ private:
+ VCard::ref vcard;
+ Ui::QtVCardWidget* ui;
+ QToolButton* toolButton;
+ bool editable;
+ QMenu* menu;
+ std::list<QtVCardGeneralField*> fields;
+ std::map<QAction*, boost::shared_ptr<QtVCardFieldInfo> > actionFieldInfo;
+ };
}
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index a0c65ef..4193921 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -50,926 +50,926 @@ const QString QtWebKitChatView::ButtonFileTransferOpenFile = QString("filetransf
const QString QtWebKitChatView::ButtonMUCInvite = QString("mucinvite");
QtWebKitChatView::QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStream, QtChatTheme* theme, QWidget* parent, bool disableAutoScroll) : QtChatView(parent), window_(window), eventStream_(eventStream), fontSizeSteps_(0), disableAutoScroll_(disableAutoScroll), previousMessageKind_(PreviosuMessageWasNone), previousMessageWasSelf_(false), showEmoticons_(false), insertingLastLine_(false), idCounter_(0) {
- theme_ = theme;
-
- QVBoxLayout* mainLayout = new QVBoxLayout(this);
- mainLayout->setSpacing(0);
- mainLayout->setContentsMargins(0,0,0,0);
- webView_ = new QtWebView(this);
- connect(webView_, SIGNAL(linkClicked(const QUrl&)), SLOT(handleLinkClicked(const QUrl&)));
- connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool)));
- connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus()));
- connect(webView_, SIGNAL(clearRequested()), SLOT(handleClearRequested()));
- connect(webView_, SIGNAL(fontGrowRequested()), SLOT(increaseFontSize()));
- connect(webView_, SIGNAL(fontShrinkRequested()), SLOT(decreaseFontSize()));
+ theme_ = theme;
+
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
+ mainLayout->setSpacing(0);
+ mainLayout->setContentsMargins(0,0,0,0);
+ webView_ = new QtWebView(this);
+ connect(webView_, SIGNAL(linkClicked(const QUrl&)), SLOT(handleLinkClicked(const QUrl&)));
+ connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool)));
+ connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus()));
+ connect(webView_, SIGNAL(clearRequested()), SLOT(handleClearRequested()));
+ connect(webView_, SIGNAL(fontGrowRequested()), SLOT(increaseFontSize()));
+ connect(webView_, SIGNAL(fontShrinkRequested()), SLOT(decreaseFontSize()));
#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
- /* To give a border on Linux, where it looks bad without */
- QStackedWidget* stack = new QStackedWidget(this);
- stack->addWidget(webView_);
- stack->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
- stack->setLineWidth(2);
- mainLayout->addWidget(stack);
+ /* To give a border on Linux, where it looks bad without */
+ QStackedWidget* stack = new QStackedWidget(this);
+ stack->addWidget(webView_);
+ stack->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+ stack->setLineWidth(2);
+ mainLayout->addWidget(stack);
#else
- mainLayout->addWidget(webView_);
+ mainLayout->addWidget(webView_);
#endif
#ifdef SWIFT_EXPERIMENTAL_FT
- setAcceptDrops(true);
+ setAcceptDrops(true);
#endif
- webPage_ = new QWebPage(this);
- webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
- if (Log::getLogLevel() == Log::debug) {
- webPage_->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
- }
- webView_->setPage(webPage_);
- connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
- connect(webPage_, SIGNAL(scrollRequested(int, int, const QRect&)), SLOT(handleScrollRequested(int, int, const QRect&)));
+ webPage_ = new QWebPage(this);
+ webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
+ if (Log::getLogLevel() == Log::debug) {
+ webPage_->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
+ }
+ webView_->setPage(webPage_);
+ connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
+ connect(webPage_, SIGNAL(scrollRequested(int, int, const QRect&)), SLOT(handleScrollRequested(int, int, const QRect&)));
- viewReady_ = false;
- isAtBottom_ = true;
- resetView();
+ viewReady_ = false;
+ isAtBottom_ = true;
+ resetView();
- jsBridge = new QtChatWindowJSBridge();
- addToJSEnvironment("chatwindow", jsBridge);
- connect(jsBridge, SIGNAL(buttonClicked(QString,QString,QString,QString,QString,QString)), this, SLOT(handleHTMLButtonClicked(QString,QString,QString,QString,QString,QString)));
+ jsBridge = new QtChatWindowJSBridge();
+ addToJSEnvironment("chatwindow", jsBridge);
+ connect(jsBridge, SIGNAL(buttonClicked(QString,QString,QString,QString,QString,QString)), this, SLOT(handleHTMLButtonClicked(QString,QString,QString,QString,QString,QString)));
}
QtWebKitChatView::~QtWebKitChatView() {
- delete jsBridge;
+ delete jsBridge;
}
void QtWebKitChatView::handleClearRequested() {
- QMessageBox messageBox(this);
- messageBox.setWindowTitle(tr("Clear log"));
- messageBox.setText(tr("You are about to clear the contents of your chat log."));
- messageBox.setInformativeText(tr("Are you sure?"));
- messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- messageBox.setDefaultButton(QMessageBox::Yes);
- int button = messageBox.exec();
- if (button == QMessageBox::Yes) {
- logCleared();
- resetView();
- }
+ QMessageBox messageBox(this);
+ messageBox.setWindowTitle(tr("Clear log"));
+ messageBox.setText(tr("You are about to clear the contents of your chat log."));
+ messageBox.setInformativeText(tr("Are you sure?"));
+ messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ messageBox.setDefaultButton(QMessageBox::Yes);
+ int button = messageBox.exec();
+ if (button == QMessageBox::Yes) {
+ logCleared();
+ resetView();
+ }
}
void QtWebKitChatView::handleKeyPressEvent(QKeyEvent* event) {
- webView_->keyPressEvent(event);
+ webView_->keyPressEvent(event);
}
void QtWebKitChatView::addMessageBottom(boost::shared_ptr<ChatSnippet> snippet) {
- if (viewReady_) {
- addToDOM(snippet);
- } else {
- /* If this asserts, the previous queuing code was necessary and should be reinstated */
- assert(false);
- }
+ if (viewReady_) {
+ addToDOM(snippet);
+ } else {
+ /* If this asserts, the previous queuing code was necessary and should be reinstated */
+ assert(false);
+ }
}
void QtWebKitChatView::addMessageTop(boost::shared_ptr<ChatSnippet> /* snippet */) {
- // TODO: Implement this in a sensible manner later.
- assert(false);
+ // TODO: Implement this in a sensible manner later.
+ assert(false);
}
void QtWebKitChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) {
- //qDebug() << snippet->getContent();
- rememberScrolledToBottom();
+ //qDebug() << snippet->getContent();
+ rememberScrolledToBottom();
- QWebElement insertElement = webPage_->mainFrame()->findFirstElement("#insert");
- assert(!insertElement.isNull());
- insertElement.prependOutside(snippet->getContent());
+ QWebElement insertElement = webPage_->mainFrame()->findFirstElement("#insert");
+ assert(!insertElement.isNull());
+ insertElement.prependOutside(snippet->getContent());
- //qDebug() << "-----------------";
- //qDebug() << webPage_->mainFrame()->toHtml();
+ //qDebug() << "-----------------";
+ //qDebug() << webPage_->mainFrame()->toHtml();
}
void QtWebKitChatView::addLastSeenLine() {
- // Remove a potentially existing unread bar.
- QWebElement existingUnreadBar = webPage_->mainFrame()->findFirstElement("div.unread");
- if (!existingUnreadBar.isNull()) {
- existingUnreadBar.removeFromDocument();
- }
+ // Remove a potentially existing unread bar.
+ QWebElement existingUnreadBar = webPage_->mainFrame()->findFirstElement("div.unread");
+ if (!existingUnreadBar.isNull()) {
+ existingUnreadBar.removeFromDocument();
+ }
- QWebElement insertElement = webPage_->mainFrame()->findFirstElement("#insert");
- insertElement.prependOutside(theme_->getUnread());
+ QWebElement insertElement = webPage_->mainFrame()->findFirstElement("#insert");
+ insertElement.prependOutside(theme_->getUnread());
}
void QtWebKitChatView::replaceLastMessage(const QString& newMessage, const ChatWindow::TimestampBehaviour timestampBehaviour) {
- rememberScrolledToBottom();
- QWebElement insertElement = webPage_->mainFrame()->findFirstElement("#insert");
- assert(!insertElement.isNull());
+ rememberScrolledToBottom();
+ QWebElement insertElement = webPage_->mainFrame()->findFirstElement("#insert");
+ assert(!insertElement.isNull());
- QWebElement lastMessageElement = insertElement.previousSibling();
- QWebElement messageChild = lastMessageElement.findFirst("span.swift_message");
- assert(!messageChild.isNull());
- messageChild.setInnerXml(ChatSnippet::escape(newMessage));
- if (timestampBehaviour == ChatWindow::UpdateTimestamp) {
- QWebElement timeChild = lastMessageElement.findFirst("span.swift_time");
- assert(!timeChild.isNull());
- timeChild.setInnerXml(ChatSnippet::timeToEscapedString(QDateTime::currentDateTime()));
- }
+ QWebElement lastMessageElement = insertElement.previousSibling();
+ QWebElement messageChild = lastMessageElement.findFirst("span.swift_message");
+ assert(!messageChild.isNull());
+ messageChild.setInnerXml(ChatSnippet::escape(newMessage));
+ if (timestampBehaviour == ChatWindow::UpdateTimestamp) {
+ QWebElement timeChild = lastMessageElement.findFirst("span.swift_time");
+ assert(!timeChild.isNull());
+ timeChild.setInnerXml(ChatSnippet::timeToEscapedString(QDateTime::currentDateTime()));
+ }
}
void QtWebKitChatView::replaceLastMessage(const QString& newMessage, const QString& note) {
- rememberScrolledToBottom();
- replaceLastMessage(newMessage, ChatWindow::KeepTimestamp);
- QWebElement replace = lastElement_.findFirst("span.swift_time");
- assert(!replace.isNull());
- replace.setInnerXml(ChatSnippet::escape(note));
+ rememberScrolledToBottom();
+ replaceLastMessage(newMessage, ChatWindow::KeepTimestamp);
+ QWebElement replace = lastElement_.findFirst("span.swift_time");
+ assert(!replace.isNull());
+ replace.setInnerXml(ChatSnippet::escape(note));
}
QString QtWebKitChatView::getLastSentMessage() {
- return lastElement_.toPlainText();
+ return lastElement_.toPlainText();
}
void QtWebKitChatView::addToJSEnvironment(const QString& name, QObject* obj) {
- webView_->page()->currentFrame()->addToJavaScriptWindowObject(name, obj);
+ webView_->page()->currentFrame()->addToJavaScriptWindowObject(name, obj);
}
void QtWebKitChatView::replaceMessage(const QString& newMessage, const QString& id, const QDateTime& editTime) {
- rememberScrolledToBottom();
- QWebElement message = document_.findFirst("#" + id);
- if (!message.isNull()) {
- QWebElement replaceContent = message.findFirst("span.swift_inner_message");
- assert(!replaceContent.isNull());
- QString old = replaceContent.toOuterXml();
- replaceContent.setInnerXml(ChatSnippet::escape(newMessage));
- QWebElement replaceTime = message.findFirst("span.swift_time");
- assert(!replaceTime.isNull());
- old = replaceTime.toOuterXml();
- replaceTime.setInnerXml(ChatSnippet::escape(tr("%1 edited").arg(ChatSnippet::timeToEscapedString(editTime))));
- }
- else {
- qWarning() << "Trying to replace element with id " << id << " but it's not there.";
- }
+ rememberScrolledToBottom();
+ QWebElement message = document_.findFirst("#" + id);
+ if (!message.isNull()) {
+ QWebElement replaceContent = message.findFirst("span.swift_inner_message");
+ assert(!replaceContent.isNull());
+ QString old = replaceContent.toOuterXml();
+ replaceContent.setInnerXml(ChatSnippet::escape(newMessage));
+ QWebElement replaceTime = message.findFirst("span.swift_time");
+ assert(!replaceTime.isNull());
+ old = replaceTime.toOuterXml();
+ replaceTime.setInnerXml(ChatSnippet::escape(tr("%1 edited").arg(ChatSnippet::timeToEscapedString(editTime))));
+ }
+ else {
+ qWarning() << "Trying to replace element with id " << id << " but it's not there.";
+ }
}
void QtWebKitChatView::showEmoticons(bool show) {
- showEmoticons_ = show;
- {
- const QWebElementCollection spans = document_.findAll("span.swift_emoticon_image");
- Q_FOREACH (QWebElement span, spans) {
- span.setStyleProperty("display", show ? "inline" : "none");
- }
- }
- {
- const QWebElementCollection spans = document_.findAll("span.swift_emoticon_text");
- Q_FOREACH (QWebElement span, spans) {
- span.setStyleProperty("display", show ? "none" : "inline");
- }
- }
+ showEmoticons_ = show;
+ {
+ const QWebElementCollection spans = document_.findAll("span.swift_emoticon_image");
+ Q_FOREACH (QWebElement span, spans) {
+ span.setStyleProperty("display", show ? "inline" : "none");
+ }
+ }
+ {
+ const QWebElementCollection spans = document_.findAll("span.swift_emoticon_text");
+ Q_FOREACH (QWebElement span, spans) {
+ span.setStyleProperty("display", show ? "none" : "inline");
+ }
+ }
}
void QtWebKitChatView::copySelectionToClipboard() {
- if (!webPage_->selectedText().isEmpty()) {
- webPage_->triggerAction(QWebPage::Copy);
- }
+ if (!webPage_->selectedText().isEmpty()) {
+ webPage_->triggerAction(QWebPage::Copy);
+ }
}
void QtWebKitChatView::setAckXML(const QString& id, const QString& xml) {
- QWebElement message = document_.findFirst("#" + id);
- /* Deliberately not asserting here, so that when we start expiring old messages it won't hit us */
- if (message.isNull()) return;
- QWebElement ackElement = message.findFirst("span.swift_ack");
- assert(!ackElement.isNull());
- ackElement.setInnerXml(xml);
+ QWebElement message = document_.findFirst("#" + id);
+ /* Deliberately not asserting here, so that when we start expiring old messages it won't hit us */
+ if (message.isNull()) return;
+ QWebElement ackElement = message.findFirst("span.swift_ack");
+ assert(!ackElement.isNull());
+ ackElement.setInnerXml(xml);
}
void QtWebKitChatView::setReceiptXML(const QString& id, const QString& xml) {
- QWebElement message = document_.findFirst("#" + id);
- if (message.isNull()) return;
- QWebElement receiptElement = message.findFirst("span.swift_receipt");
- assert(!receiptElement.isNull());
- receiptElement.setInnerXml(xml);
+ QWebElement message = document_.findFirst("#" + id);
+ if (message.isNull()) return;
+ QWebElement receiptElement = message.findFirst("span.swift_receipt");
+ assert(!receiptElement.isNull());
+ receiptElement.setInnerXml(xml);
}
void QtWebKitChatView::displayReceiptInfo(const QString& id, bool showIt) {
- QWebElement message = document_.findFirst("#" + id);
- if (message.isNull()) return;
- QWebElement receiptElement = message.findFirst("span.swift_receipt");
- assert(!receiptElement.isNull());
- receiptElement.setStyleProperty("display", showIt ? "inline" : "none");
+ QWebElement message = document_.findFirst("#" + id);
+ if (message.isNull()) return;
+ QWebElement receiptElement = message.findFirst("span.swift_receipt");
+ assert(!receiptElement.isNull());
+ receiptElement.setStyleProperty("display", showIt ? "inline" : "none");
}
void QtWebKitChatView::rememberScrolledToBottom() {
- isAtBottom_ = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) >= (webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical) - 1);
+ isAtBottom_ = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) >= (webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical) - 1);
}
void QtWebKitChatView::scrollToBottom() {
- isAtBottom_ = true;
- webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical));
- webView_->update(); /* Work around redraw bug in some versions of Qt. */
+ isAtBottom_ = true;
+ webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical));
+ webView_->update(); /* Work around redraw bug in some versions of Qt. */
}
void QtWebKitChatView::handleFrameSizeChanged() {
- if (topMessageAdded_) {
- // adjust new scrollbar position
- int newMaximum = webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical);
- webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, newMaximum - scrollBarMaximum_);
- topMessageAdded_ = false;
- }
+ if (topMessageAdded_) {
+ // adjust new scrollbar position
+ int newMaximum = webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical);
+ webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, newMaximum - scrollBarMaximum_);
+ topMessageAdded_ = false;
+ }
- if (isAtBottom_ && !disableAutoScroll_) {
- scrollToBottom();
- }
+ if (isAtBottom_ && !disableAutoScroll_) {
+ scrollToBottom();
+ }
}
void QtWebKitChatView::handleLinkClicked(const QUrl& url) {
- QDesktopServices::openUrl(url);
+ QDesktopServices::openUrl(url);
}
void QtWebKitChatView::handleViewLoadFinished(bool ok) {
- Q_ASSERT(ok);
- viewReady_ = true;
+ Q_ASSERT(ok);
+ viewReady_ = true;
}
void QtWebKitChatView::increaseFontSize(int numSteps) {
- //qDebug() << "Increasing";
- fontSizeSteps_ += numSteps;
- emit fontResized(fontSizeSteps_);
+ //qDebug() << "Increasing";
+ fontSizeSteps_ += numSteps;
+ emit fontResized(fontSizeSteps_);
}
void QtWebKitChatView::decreaseFontSize() {
- fontSizeSteps_--;
- if (fontSizeSteps_ < 0) {
- fontSizeSteps_ = 0;
- }
- emit fontResized(fontSizeSteps_);
+ fontSizeSteps_--;
+ if (fontSizeSteps_ < 0) {
+ fontSizeSteps_ = 0;
+ }
+ emit fontResized(fontSizeSteps_);
}
void QtWebKitChatView::resizeFont(int fontSizeSteps) {
- fontSizeSteps_ = fontSizeSteps;
- double size = 1.0 + 0.2 * fontSizeSteps_;
- QString sizeString(QString().setNum(size, 'g', 3) + "em");
+ fontSizeSteps_ = fontSizeSteps;
+ double size = 1.0 + 0.2 * fontSizeSteps_;
+ QString sizeString(QString().setNum(size, 'g', 3) + "em");
- // Set the font size in the <style id="text-resize-style"> element in the theme <head> element.
- QWebElement resizableTextStyle = document_.findFirst("style#text-resize-style");
- assert(!resizableTextStyle.isNull());
- resizableTextStyle.setInnerXml(QString("span.swift_resizable { font-size: %1;}").arg(sizeString));
- webView_->setFontSizeIsMinimal(size == 1.0);
+ // Set the font size in the <style id="text-resize-style"> element in the theme <head> element.
+ QWebElement resizableTextStyle = document_.findFirst("style#text-resize-style");
+ assert(!resizableTextStyle.isNull());
+ resizableTextStyle.setInnerXml(QString("span.swift_resizable { font-size: %1;}").arg(sizeString));
+ webView_->setFontSizeIsMinimal(size == 1.0);
}
void QtWebKitChatView::resetView() {
- lastElement_ = QWebElement();
- firstElement_ = lastElement_;
- topMessageAdded_ = false;
- scrollBarMaximum_ = 0;
- QString pageHTML = theme_->getTemplate();
- pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3");
- pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase());
- if (pageHTML.count("%@") > 3) {
- pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getMainCSS());
- }
- pageHTML.replace(pageHTML.indexOf("%@"), 2, "Variants/Blue on Green.css");
- pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*headerSnippet.getContent()*/);
- pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*footerSnippet.getContent()*/);
- QEventLoop syncLoop;
- connect(webView_, SIGNAL(loadFinished(bool)), &syncLoop, SLOT(quit()));
- webPage_->mainFrame()->setHtml(pageHTML);
- while (!viewReady_) {
- QTimer t;
- t.setSingleShot(true);
- connect(&t, SIGNAL(timeout()), &syncLoop, SLOT(quit()));
- t.start(50);
- syncLoop.exec();
- }
- document_ = webPage_->mainFrame()->documentElement();
-
- scrollToBottom();
-
- connect(webPage_->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), this, SLOT(handleFrameSizeChanged()), Qt::UniqueConnection);
+ lastElement_ = QWebElement();
+ firstElement_ = lastElement_;
+ topMessageAdded_ = false;
+ scrollBarMaximum_ = 0;
+ QString pageHTML = theme_->getTemplate();
+ pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3");
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase());
+ if (pageHTML.count("%@") > 3) {
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getMainCSS());
+ }
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, "Variants/Blue on Green.css");
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*headerSnippet.getContent()*/);
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*footerSnippet.getContent()*/);
+ QEventLoop syncLoop;
+ connect(webView_, SIGNAL(loadFinished(bool)), &syncLoop, SLOT(quit()));
+ webPage_->mainFrame()->setHtml(pageHTML);
+ while (!viewReady_) {
+ QTimer t;
+ t.setSingleShot(true);
+ connect(&t, SIGNAL(timeout()), &syncLoop, SLOT(quit()));
+ t.start(50);
+ syncLoop.exec();
+ }
+ document_ = webPage_->mainFrame()->documentElement();
+
+ scrollToBottom();
+
+ connect(webPage_->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), this, SLOT(handleFrameSizeChanged()), Qt::UniqueConnection);
}
static QWebElement findElementWithID(QWebElement document, QString elementName, QString id) {
- QWebElementCollection elements = document.findAll(elementName);
- Q_FOREACH(QWebElement element, elements) {
- if (element.attribute("id") == id) {
- return element;
- }
- }
- return QWebElement();
+ QWebElementCollection elements = document.findAll(elementName);
+ Q_FOREACH(QWebElement element, elements) {
+ if (element.attribute("id") == id) {
+ return element;
+ }
+ }
+ return QWebElement();
}
void QtWebKitChatView::setFileTransferProgress(QString id, const int percentageDone) {
- rememberScrolledToBottom();
- QWebElement ftElement = findElementWithID(document_, "div", id);
- if (ftElement.isNull()) {
- SWIFT_LOG(debug) << "Tried to access FT UI via invalid id!" << std::endl;
- return;
- }
- QWebElement progressBar = ftElement.findFirst("div.progressbar");
- progressBar.setStyleProperty("width", QString::number(percentageDone) + "%");
+ rememberScrolledToBottom();
+ QWebElement ftElement = findElementWithID(document_, "div", id);
+ if (ftElement.isNull()) {
+ SWIFT_LOG(debug) << "Tried to access FT UI via invalid id!" << std::endl;
+ return;
+ }
+ QWebElement progressBar = ftElement.findFirst("div.progressbar");
+ progressBar.setStyleProperty("width", QString::number(percentageDone) + "%");
- QWebElement progressBarValue = ftElement.findFirst("div.progressbar-value");
- progressBarValue.setInnerXml(QString::number(percentageDone) + " %");
+ QWebElement progressBarValue = ftElement.findFirst("div.progressbar-value");
+ progressBarValue.setInnerXml(QString::number(percentageDone) + " %");
}
void QtWebKitChatView::setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& /* msg */) {
- rememberScrolledToBottom();
- QWebElement ftElement = findElementWithID(document_, "div", id);
- if (ftElement.isNull()) {
- SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
- return;
- }
-
- QString newInnerHTML = "";
- if (state == ChatWindow::Initialisation) {
- QWebElement filenameSizeDescriptionElement = ftElement.parent().firstChild();
- QString description = QtUtilities::htmlEscape(descriptions_[id]);
- if (!description.isEmpty()) {
- filenameSizeDescriptionElement.prependOutside(QString(" \"%1\"").arg(description));
- }
- newInnerHTML = tr("Preparing to transfer.") + "<br/>" +
- buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
- }
- else if (state == ChatWindow::WaitingForAccept) {
- newInnerHTML = tr("Waiting for other side to accept the transfer.") + "<br/>" +
- buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
- }
- else if (state == ChatWindow::Negotiating) {
- // replace with text "Negotiaging" + Cancel button
- newInnerHTML = tr("Negotiating...") + "<br/>" +
- buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
- }
- else if (state == ChatWindow::Transferring) {
- // progress bar + Cancel Button
- newInnerHTML = "<div style=\"position: relative; width: 90%; height: 20px; border: 2px solid grey; -webkit-border-radius: 10px;\">"
- "<div class=\"progressbar\" style=\"width: 0%; height: 100%; background: #AAA; -webkit-border-radius: 6px;\">"
- "<div class=\"progressbar-value\" style=\"position: absolute; top: 0px; left: 0px; width: 100%; text-align: center; padding-top: 2px;\">"
- "0%"
- "</div>"
- "</div>"
- "</div>" +
- buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
- }
- else if (state == ChatWindow::Canceled) {
- newInnerHTML = tr("Transfer has been canceled!");
- }
- else if (state == ChatWindow::Finished) {
- // text "Successful transfer"
- newInnerHTML = tr("Transfer completed successfully." ) + " " + buildChatWindowButton(tr("Open file"), ButtonFileTransferOpenFile, id, filePaths_[id]);
- filePaths_.erase(id);
- }
- else if (state == ChatWindow::FTFailed) {
- newInnerHTML = tr("Transfer failed.");
- }
-
- ftElement.setInnerXml(newInnerHTML);
+ rememberScrolledToBottom();
+ QWebElement ftElement = findElementWithID(document_, "div", id);
+ if (ftElement.isNull()) {
+ SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
+ return;
+ }
+
+ QString newInnerHTML = "";
+ if (state == ChatWindow::Initialisation) {
+ QWebElement filenameSizeDescriptionElement = ftElement.parent().firstChild();
+ QString description = QtUtilities::htmlEscape(descriptions_[id]);
+ if (!description.isEmpty()) {
+ filenameSizeDescriptionElement.prependOutside(QString(" \"%1\"").arg(description));
+ }
+ newInnerHTML = tr("Preparing to transfer.") + "<br/>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
+ }
+ else if (state == ChatWindow::WaitingForAccept) {
+ newInnerHTML = tr("Waiting for other side to accept the transfer.") + "<br/>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
+ }
+ else if (state == ChatWindow::Negotiating) {
+ // replace with text "Negotiaging" + Cancel button
+ newInnerHTML = tr("Negotiating...") + "<br/>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
+ }
+ else if (state == ChatWindow::Transferring) {
+ // progress bar + Cancel Button
+ newInnerHTML = "<div style=\"position: relative; width: 90%; height: 20px; border: 2px solid grey; -webkit-border-radius: 10px;\">"
+ "<div class=\"progressbar\" style=\"width: 0%; height: 100%; background: #AAA; -webkit-border-radius: 6px;\">"
+ "<div class=\"progressbar-value\" style=\"position: absolute; top: 0px; left: 0px; width: 100%; text-align: center; padding-top: 2px;\">"
+ "0%"
+ "</div>"
+ "</div>"
+ "</div>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
+ }
+ else if (state == ChatWindow::Canceled) {
+ newInnerHTML = tr("Transfer has been canceled!");
+ }
+ else if (state == ChatWindow::Finished) {
+ // text "Successful transfer"
+ newInnerHTML = tr("Transfer completed successfully." ) + " " + buildChatWindowButton(tr("Open file"), ButtonFileTransferOpenFile, id, filePaths_[id]);
+ filePaths_.erase(id);
+ }
+ else if (state == ChatWindow::FTFailed) {
+ newInnerHTML = tr("Transfer failed.");
+ }
+
+ ftElement.setInnerXml(newInnerHTML);
}
void QtWebKitChatView::setWhiteboardSessionStatus(QString id, const ChatWindow::WhiteboardSessionState state) {
- QWebElement divElement = findElementWithID(document_, "div", id);
- QString newInnerHTML;
- if (state == ChatWindow::WhiteboardAccepted) {
- newInnerHTML = tr("Started whiteboard chat") + "<br/>" + buildChatWindowButton(tr("Show whiteboard"), ButtonWhiteboardShowWindow, id);
- } else if (state == ChatWindow::WhiteboardTerminated) {
- newInnerHTML = tr("Whiteboard chat has been canceled");
- } else if (state == ChatWindow::WhiteboardRejected) {
- newInnerHTML = tr("Whiteboard chat request has been rejected");
- }
- divElement.setInnerXml(newInnerHTML);
+ QWebElement divElement = findElementWithID(document_, "div", id);
+ QString newInnerHTML;
+ if (state == ChatWindow::WhiteboardAccepted) {
+ newInnerHTML = tr("Started whiteboard chat") + "<br/>" + buildChatWindowButton(tr("Show whiteboard"), ButtonWhiteboardShowWindow, id);
+ } else if (state == ChatWindow::WhiteboardTerminated) {
+ newInnerHTML = tr("Whiteboard chat has been canceled");
+ } else if (state == ChatWindow::WhiteboardRejected) {
+ newInnerHTML = tr("Whiteboard chat request has been rejected");
+ }
+ divElement.setInnerXml(newInnerHTML);
}
void QtWebKitChatView::setMUCInvitationJoined(QString id) {
- QWebElement divElement = findElementWithID(document_, "div", id);
- QWebElement buttonElement = findElementWithID(divElement, "input", "mucinvite");
- if (!buttonElement.isNull()) {
- buttonElement.setAttribute("value", tr("Return to room"));
- }
+ QWebElement divElement = findElementWithID(document_, "div", id);
+ QWebElement buttonElement = findElementWithID(divElement, "input", "mucinvite");
+ if (!buttonElement.isNull()) {
+ buttonElement.setAttribute("value", tr("Return to room"));
+ }
}
void QtWebKitChatView::askDesktopToOpenFile(const QString& filename) {
- QFileInfo fileInfo(filename);
- if (fileInfo.exists() && fileInfo.isFile()) {
- QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
- }
+ QFileInfo fileInfo(filename);
+ if (fileInfo.exists() && fileInfo.isFile()) {
+ QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
+ }
}
void QtWebKitChatView::handleScrollRequested(int, int dy, const QRect&) {
- rememberScrolledToBottom();
+ rememberScrolledToBottom();
- int pos = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) - dy;
- emit scrollRequested(pos);
+ int pos = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) - dy;
+ emit scrollRequested(pos);
- if (pos == 0) {
- emit scrollReachedTop();
- }
- else if (pos == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical)) {
- emit scrollReachedBottom();
- }
+ if (pos == 0) {
+ emit scrollReachedTop();
+ }
+ else if (pos == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical)) {
+ emit scrollReachedBottom();
+ }
}
int QtWebKitChatView::getSnippetPositionByDate(const QDate& date) {
- QWebElement message = webPage_->mainFrame()->documentElement().findFirst(".date" + date.toString(Qt::ISODate));
+ QWebElement message = webPage_->mainFrame()->documentElement().findFirst(".date" + date.toString(Qt::ISODate));
- return message.geometry().top();
+ return message.geometry().top();
}
void QtWebKitChatView::resetTopInsertPoint() {
- // TODO: Implement or refactor later.
- assert(false);
+ // TODO: Implement or refactor later.
+ assert(false);
}
std::string QtWebKitChatView::addMessage(
- const ChatWindow::ChatMessage& message,
- const std::string& senderName,
- bool senderIsSelf,
- boost::shared_ptr<SecurityLabel> label,
- const std::string& avatarPath,
- const boost::posix_time::ptime& time) {
- return addMessage(chatMessageToHTML(message), senderName, senderIsSelf, label, avatarPath, "", time, message.getFullMessageHighlightAction(), ChatSnippet::getDirection(message));
+ const ChatWindow::ChatMessage& message,
+ const std::string& senderName,
+ bool senderIsSelf,
+ boost::shared_ptr<SecurityLabel> label,
+ const std::string& avatarPath,
+ const boost::posix_time::ptime& time) {
+ return addMessage(chatMessageToHTML(message), senderName, senderIsSelf, label, avatarPath, "", time, message.getFullMessageHighlightAction(), ChatSnippet::getDirection(message));
}
QString QtWebKitChatView::getHighlightSpanStart(const std::string& text, const std::string& background) {
- QString ecsapeColor = QtUtilities::htmlEscape(P2QSTRING(text));
- QString escapeBackground = QtUtilities::htmlEscape(P2QSTRING(background));
- if (ecsapeColor.isEmpty()) {
- ecsapeColor = "black";
- }
- if (escapeBackground.isEmpty()) {
- escapeBackground = "yellow";
- }
- return QString("<span style=\"color: %1; background: %2\">").arg(ecsapeColor).arg(escapeBackground);
+ QString ecsapeColor = QtUtilities::htmlEscape(P2QSTRING(text));
+ QString escapeBackground = QtUtilities::htmlEscape(P2QSTRING(background));
+ if (ecsapeColor.isEmpty()) {
+ ecsapeColor = "black";
+ }
+ if (escapeBackground.isEmpty()) {
+ escapeBackground = "yellow";
+ }
+ return QString("<span style=\"color: %1; background: %2\">").arg(ecsapeColor).arg(escapeBackground);
}
QString QtWebKitChatView::getHighlightSpanStart(const HighlightAction& highlight) {
- return getHighlightSpanStart(highlight.getTextColor(), highlight.getTextBackground());
+ return getHighlightSpanStart(highlight.getTextColor(), highlight.getTextBackground());
}
QString QtWebKitChatView::chatMessageToHTML(const ChatWindow::ChatMessage& message) {
- QString result;
- foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
- boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
- boost::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart;
- boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart;
- boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart;
-
- if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
- QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text));
- text.replace("\n","<br/>");
- result += text;
- continue;
- }
- if ((uriPart = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) {
- QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target));
- result += "<a href='" + uri + "' >" + uri + "</a>";
- continue;
- }
- if ((emoticonPart = boost::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) {
- QString textStyle = showEmoticons_ ? "style='display:none'" : "";
- QString imageStyle = showEmoticons_ ? "" : "style='display:none'";
- result += "<span class='swift_emoticon_image' " + imageStyle + "><img src='" + P2QSTRING(emoticonPart->imagePath) + "'/></span><span class='swift_emoticon_text' " + textStyle + ">" + QtUtilities::htmlEscape(P2QSTRING(emoticonPart->alternativeText)) + "</span>";
- continue;
- }
- if ((highlightPart = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) {
- QString spanStart = getHighlightSpanStart(highlightPart->action.getTextColor(), highlightPart->action.getTextBackground());
- result += spanStart + QtUtilities::htmlEscape(P2QSTRING(highlightPart->text)) + "</span>";
- continue;
- }
-
- }
- return result;
+ QString result;
+ foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
+ boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
+ boost::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart;
+ boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart;
+ boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart;
+
+ if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
+ QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text));
+ text.replace("\n","<br/>");
+ result += text;
+ continue;
+ }
+ if ((uriPart = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) {
+ QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target));
+ result += "<a href='" + uri + "' >" + uri + "</a>";
+ continue;
+ }
+ if ((emoticonPart = boost::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) {
+ QString textStyle = showEmoticons_ ? "style='display:none'" : "";
+ QString imageStyle = showEmoticons_ ? "" : "style='display:none'";
+ result += "<span class='swift_emoticon_image' " + imageStyle + "><img src='" + P2QSTRING(emoticonPart->imagePath) + "'/></span><span class='swift_emoticon_text' " + textStyle + ">" + QtUtilities::htmlEscape(P2QSTRING(emoticonPart->alternativeText)) + "</span>";
+ continue;
+ }
+ if ((highlightPart = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) {
+ QString spanStart = getHighlightSpanStart(highlightPart->action.getTextColor(), highlightPart->action.getTextBackground());
+ result += spanStart + QtUtilities::htmlEscape(P2QSTRING(highlightPart->text)) + "</span>";
+ continue;
+ }
+
+ }
+ return result;
}
std::string QtWebKitChatView::addMessage(
- const QString& message,
- const std::string& senderName,
- bool senderIsSelf,
- boost::shared_ptr<SecurityLabel> label,
- const std::string& avatarPath,
- const QString& style,
- const boost::posix_time::ptime& time,
- const HighlightAction& highlight,
- ChatSnippet::Direction direction) {
+ const QString& message,
+ const std::string& senderName,
+ bool senderIsSelf,
+ boost::shared_ptr<SecurityLabel> label,
+ const std::string& avatarPath,
+ const QString& style,
+ const boost::posix_time::ptime& time,
+ const HighlightAction& highlight,
+ ChatSnippet::Direction direction) {
- QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str());
+ QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str());
- QString htmlString;
- if (label) {
- htmlString = QString("<span style=\"border: thin dashed grey; padding-left: .5em; padding-right: .5em; color: %1; background-color: %2; font-size: 90%; margin-right: .5em; \" class='swift_label'>").arg(QtUtilities::htmlEscape(P2QSTRING(label->getForegroundColor()))).arg(QtUtilities::htmlEscape(P2QSTRING(label->getBackgroundColor())));
- htmlString += QString("%1</span> ").arg(QtUtilities::htmlEscape(P2QSTRING(label->getDisplayMarking())));
- }
+ QString htmlString;
+ if (label) {
+ htmlString = QString("<span style=\"border: thin dashed grey; padding-left: .5em; padding-right: .5em; color: %1; background-color: %2; font-size: 90%; margin-right: .5em; \" class='swift_label'>").arg(QtUtilities::htmlEscape(P2QSTRING(label->getForegroundColor()))).arg(QtUtilities::htmlEscape(P2QSTRING(label->getBackgroundColor())));
+ htmlString += QString("%1</span> ").arg(QtUtilities::htmlEscape(P2QSTRING(label->getDisplayMarking())));
+ }
- QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
- QString styleSpanEnd = style == "" ? "" : "</span>";
+ QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
+ QString styleSpanEnd = style == "" ? "" : "</span>";
- bool highlightWholeMessage = highlight.highlightWholeMessage() && highlight.getTextBackground() != "" && highlight.getTextColor() != "";
- QString highlightSpanStart = highlightWholeMessage ? getHighlightSpanStart(highlight) : "";
- QString highlightSpanEnd = highlightWholeMessage ? "</span>" : "";
- htmlString += "<span class='swift_inner_message'>" + styleSpanStart + highlightSpanStart + message + highlightSpanEnd + styleSpanEnd + "</span>" ;
+ bool highlightWholeMessage = highlight.highlightWholeMessage() && highlight.getTextBackground() != "" && highlight.getTextColor() != "";
+ QString highlightSpanStart = highlightWholeMessage ? getHighlightSpanStart(highlight) : "";
+ QString highlightSpanEnd = highlightWholeMessage ? "</span>" : "";
+ htmlString += "<span class='swift_inner_message'>" + styleSpanStart + highlightSpanStart + message + highlightSpanEnd + styleSpanEnd + "</span>" ;
- bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMessage, senderName, senderIsSelf);
+ bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMessage, senderName, senderIsSelf);
- QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
- std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
- addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), direction));
+ QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
+ std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), direction));
- previousMessageWasSelf_ = senderIsSelf;
- previousSenderName_ = P2QSTRING(senderName);
- previousMessageKind_ = PreviousMessageWasMessage;
- return id;
+ previousMessageWasSelf_ = senderIsSelf;
+ previousSenderName_ = P2QSTRING(senderName);
+ previousMessageKind_ = PreviousMessageWasMessage;
+ return id;
}
std::string QtWebKitChatView::addAction(const ChatWindow::ChatMessage& message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) {
- return addMessage(" *" + chatMessageToHTML(message) + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ", time, message.getFullMessageHighlightAction(), ChatSnippet::getDirection(message));
+ return addMessage(" *" + chatMessageToHTML(message) + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ", time, message.getFullMessageHighlightAction(), ChatSnippet::getDirection(message));
}
static QString encodeButtonArgument(const QString& str) {
- return QtUtilities::htmlEscape(P2QSTRING(Base64::encode(createByteArray(Q2PSTRING(str)))));
+ return QtUtilities::htmlEscape(P2QSTRING(Base64::encode(createByteArray(Q2PSTRING(str)))));
}
static QString decodeButtonArgument(const QString& str) {
- return P2QSTRING(byteArrayToString(Base64::decode(Q2PSTRING(str))));
+ return P2QSTRING(byteArrayToString(Base64::decode(Q2PSTRING(str))));
}
QString QtWebKitChatView::buildChatWindowButton(const QString& name, const QString& id, const QString& arg1, const QString& arg2, const QString& arg3, const QString& arg4, const QString& arg5) {
- QRegExp regex("[A-Za-z][A-Za-z0-9\\-\\_]+");
- Q_ASSERT(regex.exactMatch(id));
- QString html = QString("<input id='%2' type='submit' value='%1' onclick='chatwindow.buttonClicked(\"%2\", \"%3\", \"%4\", \"%5\", \"%6\", \"%7\");' />").arg(name).arg(id).arg(encodeButtonArgument(arg1)).arg(encodeButtonArgument(arg2)).arg(encodeButtonArgument(arg3)).arg(encodeButtonArgument(arg4)).arg(encodeButtonArgument(arg5));
- return html;
+ QRegExp regex("[A-Za-z][A-Za-z0-9\\-\\_]+");
+ Q_ASSERT(regex.exactMatch(id));
+ QString html = QString("<input id='%2' type='submit' value='%1' onclick='chatwindow.buttonClicked(\"%2\", \"%3\", \"%4\", \"%5\", \"%6\", \"%7\");' />").arg(name).arg(id).arg(encodeButtonArgument(arg1)).arg(encodeButtonArgument(arg2)).arg(encodeButtonArgument(arg3)).arg(encodeButtonArgument(arg4)).arg(encodeButtonArgument(arg5));
+ return html;
}
std::string QtWebKitChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) {
- SWIFT_LOG(debug) << "addFileTransfer" << std::endl;
- QString ft_id = QString("ft%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
-
- QString actionText;
- QString htmlString;
- QString formattedFileSize = P2QSTRING(formatSize(sizeInBytes));
- QString sanitizedFileName = QtUtilities::htmlEscape(P2QSTRING(filename));
- QString sanitizedDescription = QtUtilities::htmlEscape(P2QSTRING(description));
- if (senderIsSelf) {
- // outgoing
- filePaths_[ft_id] = sanitizedFileName;
- actionText = tr("Send file: %1 (%2)").arg(sanitizedFileName).arg(formattedFileSize);
- htmlString = actionText + " <br/>" +
- "<div id='" + ft_id + "'>" +
- buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
- buildChatWindowButton(tr("Set Description"), ButtonFileTransferSetDescription, ft_id) +
- buildChatWindowButton(tr("Send"), ButtonFileTransferSendRequest, ft_id) +
- "</div>";
- } else {
- // incoming
- actionText = tr("Receiving file: %1 (%2)").arg(sanitizedFileName).arg(formattedFileSize);
- if (!sanitizedDescription.isEmpty()) {
- actionText += QString(" \"%1\"").arg(sanitizedDescription);
- }
- htmlString = actionText + " <br/>" +
- "<div id='" + ft_id + "'>" +
- buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
- buildChatWindowButton(tr("Accept"), ButtonFileTransferAcceptRequest, ft_id, P2QSTRING(filename)) +
- "</div>";
- }
-
- //addMessage(message, senderName, senderIsSelf, boost::shared_ptr<SecurityLabel>(), "", boost::posix_time::second_clock::local_time());
-
- bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasFileTransfer, senderName, senderIsSelf);
-
- QString qAvatarPath = "qrc:/icons/avatar.png";
- std::string id = "ftmessage" + boost::lexical_cast<std::string>(idCounter_++);
- addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::universal_time()), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(actionText)));
-
- previousMessageWasSelf_ = senderIsSelf;
- previousSenderName_ = P2QSTRING(senderName);
- previousMessageKind_ = PreviousMessageWasFileTransfer;
- return Q2PSTRING(ft_id);
+ SWIFT_LOG(debug) << "addFileTransfer" << std::endl;
+ QString ft_id = QString("ft%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
+
+ QString actionText;
+ QString htmlString;
+ QString formattedFileSize = P2QSTRING(formatSize(sizeInBytes));
+ QString sanitizedFileName = QtUtilities::htmlEscape(P2QSTRING(filename));
+ QString sanitizedDescription = QtUtilities::htmlEscape(P2QSTRING(description));
+ if (senderIsSelf) {
+ // outgoing
+ filePaths_[ft_id] = sanitizedFileName;
+ actionText = tr("Send file: %1 (%2)").arg(sanitizedFileName).arg(formattedFileSize);
+ htmlString = actionText + " <br/>" +
+ "<div id='" + ft_id + "'>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
+ buildChatWindowButton(tr("Set Description"), ButtonFileTransferSetDescription, ft_id) +
+ buildChatWindowButton(tr("Send"), ButtonFileTransferSendRequest, ft_id) +
+ "</div>";
+ } else {
+ // incoming
+ actionText = tr("Receiving file: %1 (%2)").arg(sanitizedFileName).arg(formattedFileSize);
+ if (!sanitizedDescription.isEmpty()) {
+ actionText += QString(" \"%1\"").arg(sanitizedDescription);
+ }
+ htmlString = actionText + " <br/>" +
+ "<div id='" + ft_id + "'>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
+ buildChatWindowButton(tr("Accept"), ButtonFileTransferAcceptRequest, ft_id, P2QSTRING(filename)) +
+ "</div>";
+ }
+
+ //addMessage(message, senderName, senderIsSelf, boost::shared_ptr<SecurityLabel>(), "", boost::posix_time::second_clock::local_time());
+
+ bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasFileTransfer, senderName, senderIsSelf);
+
+ QString qAvatarPath = "qrc:/icons/avatar.png";
+ std::string id = "ftmessage" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::universal_time()), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(actionText)));
+
+ previousMessageWasSelf_ = senderIsSelf;
+ previousSenderName_ = P2QSTRING(senderName);
+ previousMessageKind_ = PreviousMessageWasFileTransfer;
+ return Q2PSTRING(ft_id);
}
void QtWebKitChatView::setFileTransferProgress(std::string id, const int percentageDone) {
- setFileTransferProgress(P2QSTRING(id), percentageDone);
+ setFileTransferProgress(P2QSTRING(id), percentageDone);
}
void QtWebKitChatView::setFileTransferStatus(std::string id, const ChatWindow::FileTransferState state, const std::string& msg) {
- setFileTransferStatus(P2QSTRING(id), state, P2QSTRING(msg));
+ setFileTransferStatus(P2QSTRING(id), state, P2QSTRING(msg));
}
std::string QtWebKitChatView::addWhiteboardRequest(const QString& contact, bool senderIsSelf) {
- QString wb_id = QString("wb%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
- QString htmlString;
- QString actionText;
- if (senderIsSelf) {
- actionText = tr("Starting whiteboard chat");
- htmlString = "<div id='" + wb_id + "'>" + actionText + "<br />"+
- buildChatWindowButton(tr("Cancel"), ButtonWhiteboardSessionCancel, wb_id) +
- "</div>";
- } else {
- actionText = tr("%1 would like to start a whiteboard chat");
- htmlString = "<div id='" + wb_id + "'>" + actionText.arg(QtUtilities::htmlEscape(contact)) + ": <br/>" +
- buildChatWindowButton(tr("Cancel"), ButtonWhiteboardSessionCancel, wb_id) +
- buildChatWindowButton(tr("Accept"), ButtonWhiteboardSessionAcceptRequest, wb_id) +
- "</div>";
- }
- QString qAvatarPath = "qrc:/icons/avatar.png";
- std::string id = "wbmessage" + boost::lexical_cast<std::string>(idCounter_++);
- addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(contact), B2QDATE(boost::posix_time::second_clock::universal_time()), qAvatarPath, false, false, theme_, P2QSTRING(id), ChatSnippet::getDirection(actionText)));
- previousMessageWasSelf_ = false;
- previousSenderName_ = contact;
- return Q2PSTRING(wb_id);
+ QString wb_id = QString("wb%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
+ QString htmlString;
+ QString actionText;
+ if (senderIsSelf) {
+ actionText = tr("Starting whiteboard chat");
+ htmlString = "<div id='" + wb_id + "'>" + actionText + "<br />"+
+ buildChatWindowButton(tr("Cancel"), ButtonWhiteboardSessionCancel, wb_id) +
+ "</div>";
+ } else {
+ actionText = tr("%1 would like to start a whiteboard chat");
+ htmlString = "<div id='" + wb_id + "'>" + actionText.arg(QtUtilities::htmlEscape(contact)) + ": <br/>" +
+ buildChatWindowButton(tr("Cancel"), ButtonWhiteboardSessionCancel, wb_id) +
+ buildChatWindowButton(tr("Accept"), ButtonWhiteboardSessionAcceptRequest, wb_id) +
+ "</div>";
+ }
+ QString qAvatarPath = "qrc:/icons/avatar.png";
+ std::string id = "wbmessage" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(contact), B2QDATE(boost::posix_time::second_clock::universal_time()), qAvatarPath, false, false, theme_, P2QSTRING(id), ChatSnippet::getDirection(actionText)));
+ previousMessageWasSelf_ = false;
+ previousSenderName_ = contact;
+ return Q2PSTRING(wb_id);
}
void QtWebKitChatView::setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) {
- setWhiteboardSessionStatus(P2QSTRING(id), state);
+ setWhiteboardSessionStatus(P2QSTRING(id), state);
}
static bool isFilePathWritable(const QString& path) {
- QFileInfo fileInfo = QFileInfo(path);
- if (fileInfo.exists()) {
- return fileInfo.isWritable();
- }
- else {
- bool writable = false;
- QFile writeTestFile(path);
- if (writeTestFile.open(QIODevice::ReadWrite)) {
- writeTestFile.write("test");
- if (writeTestFile.error() == QFileDevice::NoError) {
- writable = true;
- }
- }
- writeTestFile.close();
- writeTestFile.remove();
- return writable;
- }
+ QFileInfo fileInfo = QFileInfo(path);
+ if (fileInfo.exists()) {
+ return fileInfo.isWritable();
+ }
+ else {
+ bool writable = false;
+ QFile writeTestFile(path);
+ if (writeTestFile.open(QIODevice::ReadWrite)) {
+ writeTestFile.write("test");
+ if (writeTestFile.error() == QFileDevice::NoError) {
+ writable = true;
+ }
+ }
+ writeTestFile.close();
+ writeTestFile.remove();
+ return writable;
+ }
}
void QtWebKitChatView::setFileTransferWarning(QString id, QString warningText) {
- QWebElement ftElement = findElementWithID(document_, "div", id);
- if (ftElement.isNull()) {
- SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
- return;
- }
+ QWebElement ftElement = findElementWithID(document_, "div", id);
+ if (ftElement.isNull()) {
+ SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
+ return;
+ }
- removeFileTransferWarning(id);
- ftElement.appendInside(QString("<div class='ft_warning' style='color: red;'><br/>%1</div>").arg(QtUtilities::htmlEscape(warningText)));
+ removeFileTransferWarning(id);
+ ftElement.appendInside(QString("<div class='ft_warning' style='color: red;'><br/>%1</div>").arg(QtUtilities::htmlEscape(warningText)));
}
void QtWebKitChatView::removeFileTransferWarning(QString id) {
- QWebElement ftElement = findElementWithID(document_, "div", id);
- if (ftElement.isNull()) {
- SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
- return;
- }
+ QWebElement ftElement = findElementWithID(document_, "div", id);
+ if (ftElement.isNull()) {
+ SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
+ return;
+ }
- QWebElement warningElement = ftElement.findFirst(".ft_warning");
- if (!warningElement.isNull()) {
- warningElement.removeFromDocument();
- }
+ QWebElement warningElement = ftElement.findFirst(".ft_warning");
+ if (!warningElement.isNull()) {
+ warningElement.removeFromDocument();
+ }
}
void QtWebKitChatView::handleHTMLButtonClicked(QString id, QString encodedArgument1, QString encodedArgument2, QString encodedArgument3, QString encodedArgument4, QString encodedArgument5) {
- QString arg1 = decodeButtonArgument(encodedArgument1);
- QString arg2 = decodeButtonArgument(encodedArgument2);
- QString arg3 = decodeButtonArgument(encodedArgument3);
- QString arg4 = decodeButtonArgument(encodedArgument4);
- QString arg5 = decodeButtonArgument(encodedArgument5);
-
- if (id.startsWith(ButtonFileTransferCancel)) {
- QString ft_id = arg1;
- window_->onFileTransferCancel(Q2PSTRING(ft_id));
- }
- else if (id.startsWith(ButtonFileTransferSetDescription)) {
- QString ft_id = arg1;
- bool ok = false;
- QString text = QInputDialog::getText(this, tr("File transfer description"),
- tr("Description:"), QLineEdit::Normal, "", &ok);
- if (ok) {
- descriptions_[ft_id] = text;
- }
- }
- else if (id.startsWith(ButtonFileTransferSendRequest)) {
- QString ft_id = arg1;
- QString text = descriptions_.find(ft_id) == descriptions_.end() ? QString() : descriptions_[ft_id];
- window_->onFileTransferStart(Q2PSTRING(ft_id), Q2PSTRING(text));
- }
- else if (id.startsWith(ButtonFileTransferAcceptRequest)) {
- QString ft_id = arg1;
- QString filename = arg2;
-
- QString path = QFileDialog::getSaveFileName(this, tr("Save File"), filename);
- if (!path.isEmpty() && isFilePathWritable(path)) {
- filePaths_[ft_id] = path;
- window_->onFileTransferAccept(Q2PSTRING(ft_id), Q2PSTRING(path));
- removeFileTransferWarning(ft_id);
- }
- else {
- setFileTransferWarning(ft_id, tr("The chosen save location is not writable! Click the 'Accept' button to select a different save location."));
- }
- }
- else if (id.startsWith(ButtonFileTransferOpenFile)) {
- QString ft_id = arg1;
- QString filename = arg2;
- askDesktopToOpenFile(filename);
- }
- else if (id.startsWith(ButtonWhiteboardSessionAcceptRequest)) {
- QString id = arg1;
- setWhiteboardSessionStatus(id, ChatWindow::WhiteboardAccepted);
- window_->onWhiteboardSessionAccept();
- }
- else if (id.startsWith(ButtonWhiteboardSessionCancel)) {
- QString id = arg1;
- setWhiteboardSessionStatus(id, ChatWindow::WhiteboardTerminated);
- window_->onWhiteboardSessionCancel();
- }
- else if (id.startsWith(ButtonWhiteboardShowWindow)) {
- QString id = arg1;
- window_->onWhiteboardWindowShow();
- }
- else if (id.startsWith(ButtonMUCInvite)) {
- QString roomJID = arg1;
- QString password = arg2;
- QString elementID = arg3;
- QString isImpromptu = arg4;
- QString isContinuation = arg5;
- eventStream_->send(boost::make_shared<JoinMUCUIEvent>(Q2PSTRING(roomJID), Q2PSTRING(password), boost::optional<std::string>(), false, false, isImpromptu.contains("true"), isContinuation.contains("true")));
- setMUCInvitationJoined(elementID);
- }
- else {
- SWIFT_LOG(debug) << "Unknown HTML button! ( " << Q2PSTRING(id) << " )" << std::endl;
- }
+ QString arg1 = decodeButtonArgument(encodedArgument1);
+ QString arg2 = decodeButtonArgument(encodedArgument2);
+ QString arg3 = decodeButtonArgument(encodedArgument3);
+ QString arg4 = decodeButtonArgument(encodedArgument4);
+ QString arg5 = decodeButtonArgument(encodedArgument5);
+
+ if (id.startsWith(ButtonFileTransferCancel)) {
+ QString ft_id = arg1;
+ window_->onFileTransferCancel(Q2PSTRING(ft_id));
+ }
+ else if (id.startsWith(ButtonFileTransferSetDescription)) {
+ QString ft_id = arg1;
+ bool ok = false;
+ QString text = QInputDialog::getText(this, tr("File transfer description"),
+ tr("Description:"), QLineEdit::Normal, "", &ok);
+ if (ok) {
+ descriptions_[ft_id] = text;
+ }
+ }
+ else if (id.startsWith(ButtonFileTransferSendRequest)) {
+ QString ft_id = arg1;
+ QString text = descriptions_.find(ft_id) == descriptions_.end() ? QString() : descriptions_[ft_id];
+ window_->onFileTransferStart(Q2PSTRING(ft_id), Q2PSTRING(text));
+ }
+ else if (id.startsWith(ButtonFileTransferAcceptRequest)) {
+ QString ft_id = arg1;
+ QString filename = arg2;
+
+ QString path = QFileDialog::getSaveFileName(this, tr("Save File"), filename);
+ if (!path.isEmpty() && isFilePathWritable(path)) {
+ filePaths_[ft_id] = path;
+ window_->onFileTransferAccept(Q2PSTRING(ft_id), Q2PSTRING(path));
+ removeFileTransferWarning(ft_id);
+ }
+ else {
+ setFileTransferWarning(ft_id, tr("The chosen save location is not writable! Click the 'Accept' button to select a different save location."));
+ }
+ }
+ else if (id.startsWith(ButtonFileTransferOpenFile)) {
+ QString ft_id = arg1;
+ QString filename = arg2;
+ askDesktopToOpenFile(filename);
+ }
+ else if (id.startsWith(ButtonWhiteboardSessionAcceptRequest)) {
+ QString id = arg1;
+ setWhiteboardSessionStatus(id, ChatWindow::WhiteboardAccepted);
+ window_->onWhiteboardSessionAccept();
+ }
+ else if (id.startsWith(ButtonWhiteboardSessionCancel)) {
+ QString id = arg1;
+ setWhiteboardSessionStatus(id, ChatWindow::WhiteboardTerminated);
+ window_->onWhiteboardSessionCancel();
+ }
+ else if (id.startsWith(ButtonWhiteboardShowWindow)) {
+ QString id = arg1;
+ window_->onWhiteboardWindowShow();
+ }
+ else if (id.startsWith(ButtonMUCInvite)) {
+ QString roomJID = arg1;
+ QString password = arg2;
+ QString elementID = arg3;
+ QString isImpromptu = arg4;
+ QString isContinuation = arg5;
+ eventStream_->send(boost::make_shared<JoinMUCUIEvent>(Q2PSTRING(roomJID), Q2PSTRING(password), boost::optional<std::string>(), false, false, isImpromptu.contains("true"), isContinuation.contains("true")));
+ setMUCInvitationJoined(elementID);
+ }
+ else {
+ SWIFT_LOG(debug) << "Unknown HTML button! ( " << Q2PSTRING(id) << " )" << std::endl;
+ }
}
void QtWebKitChatView::addErrorMessage(const ChatWindow::ChatMessage& errorMessage) {
- if (window_->isWidgetSelected()) {
- window_->onAllMessagesRead();
- }
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
- QString errorMessageHTML(chatMessageToHTML(errorMessage));
- std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
- addMessageBottom(boost::make_shared<SystemMessageSnippet>("<span class=\"error\">" + errorMessageHTML + "</span>", QDateTime::currentDateTime(), false, theme_, P2QSTRING(id), ChatSnippet::getDirection(errorMessage)));
+ QString errorMessageHTML(chatMessageToHTML(errorMessage));
+ std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<SystemMessageSnippet>("<span class=\"error\">" + errorMessageHTML + "</span>", QDateTime::currentDateTime(), false, theme_, P2QSTRING(id), ChatSnippet::getDirection(errorMessage)));
- previousMessageWasSelf_ = false;
- previousMessageKind_ = PreviousMessageWasSystem;
+ previousMessageWasSelf_ = false;
+ previousMessageKind_ = PreviousMessageWasSystem;
}
std::string QtWebKitChatView::addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) {
- if (window_->isWidgetSelected()) {
- window_->onAllMessagesRead();
- }
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
- QString messageHTML = chatMessageToHTML(message);
- std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
- addMessageBottom(boost::make_shared<SystemMessageSnippet>(messageHTML, QDateTime::currentDateTime(), false, theme_, P2QSTRING(id), getActualDirection(message, direction)));
+ QString messageHTML = chatMessageToHTML(message);
+ std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<SystemMessageSnippet>(messageHTML, QDateTime::currentDateTime(), false, theme_, P2QSTRING(id), getActualDirection(message, direction)));
- previousMessageKind_ = PreviousMessageWasSystem;
- return id;
+ previousMessageKind_ = PreviousMessageWasSystem;
+ return id;
}
void QtWebKitChatView::replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) {
- replaceMessage(" *" + chatMessageToHTML(message) + "*", id, time, "font-style:italic ", message.getFullMessageHighlightAction());
+ replaceMessage(" *" + chatMessageToHTML(message) + "*", id, time, "font-style:italic ", message.getFullMessageHighlightAction());
}
void QtWebKitChatView::replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) {
- replaceMessage(chatMessageToHTML(message), id, time, "", message.getFullMessageHighlightAction());
+ replaceMessage(chatMessageToHTML(message), id, time, "", message.getFullMessageHighlightAction());
}
void QtWebKitChatView::replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, ChatWindow::TimestampBehaviour timestampBehavior) {
- replaceSystemMessage(chatMessageToHTML(message), P2QSTRING(id), timestampBehavior);
+ replaceSystemMessage(chatMessageToHTML(message), P2QSTRING(id), timestampBehavior);
}
void QtWebKitChatView::replaceSystemMessage(const QString& newMessage, const QString& id, const ChatWindow::TimestampBehaviour timestampBehaviour) {
- rememberScrolledToBottom();
- QWebElement message = document_.findFirst("#" + id);
- if (!message.isNull()) {
- QWebElement replaceContent = message.findFirst("span.swift_message");
- assert(!replaceContent.isNull());
- QString old = replaceContent.toOuterXml();
- replaceContent.setInnerXml(ChatSnippet::escape(newMessage));
-
- if (timestampBehaviour == ChatWindow::UpdateTimestamp) {
- QWebElement replace = message.findFirst("span.swift_time");
- assert(!replace.isNull());
- replace.setInnerXml(ChatSnippet::timeToEscapedString(QDateTime::currentDateTime()));
- }
- }
- else {
- qWarning() << "Trying to replace element with id " << id << " but it's not there.";
- }
+ rememberScrolledToBottom();
+ QWebElement message = document_.findFirst("#" + id);
+ if (!message.isNull()) {
+ QWebElement replaceContent = message.findFirst("span.swift_message");
+ assert(!replaceContent.isNull());
+ QString old = replaceContent.toOuterXml();
+ replaceContent.setInnerXml(ChatSnippet::escape(newMessage));
+
+ if (timestampBehaviour == ChatWindow::UpdateTimestamp) {
+ QWebElement replace = message.findFirst("span.swift_time");
+ assert(!replace.isNull());
+ replace.setInnerXml(ChatSnippet::timeToEscapedString(QDateTime::currentDateTime()));
+ }
+ }
+ else {
+ qWarning() << "Trying to replace element with id " << id << " but it's not there.";
+ }
}
void QtWebKitChatView::replaceMessage(const QString& message, const std::string& id, const boost::posix_time::ptime& time, const QString& style, const HighlightAction& highlight) {
- if (!id.empty()) {
- if (window_->isWidgetSelected()) {
- window_->onAllMessagesRead();
- }
+ if (!id.empty()) {
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
- QString messageHTML(message);
+ QString messageHTML(message);
- QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
- QString styleSpanEnd = style == "" ? "" : "</span>";
- QString highlightSpanStart = highlight.highlightWholeMessage() ? getHighlightSpanStart(highlight) : "";
- QString highlightSpanEnd = highlight.highlightWholeMessage() ? "</span>" : "";
- messageHTML = styleSpanStart + highlightSpanStart + messageHTML + highlightSpanEnd + styleSpanEnd;
+ QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
+ QString styleSpanEnd = style == "" ? "" : "</span>";
+ QString highlightSpanStart = highlight.highlightWholeMessage() ? getHighlightSpanStart(highlight) : "";
+ QString highlightSpanEnd = highlight.highlightWholeMessage() ? "</span>" : "";
+ messageHTML = styleSpanStart + highlightSpanStart + messageHTML + highlightSpanEnd + styleSpanEnd;
- replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time));
- }
- else {
- std::cerr << "Trying to replace a message with no id";
- }
+ replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time));
+ }
+ else {
+ std::cerr << "Trying to replace a message with no id";
+ }
}
void QtWebKitChatView::addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) {
- if (window_->isWidgetSelected()) {
- window_->onAllMessagesRead();
- }
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
- QString messageHTML = chatMessageToHTML(message);
- std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
- addMessageBottom(boost::make_shared<SystemMessageSnippet>(messageHTML, QDateTime::currentDateTime(), false, theme_, P2QSTRING(id), getActualDirection(message, direction)));
+ QString messageHTML = chatMessageToHTML(message);
+ std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<SystemMessageSnippet>(messageHTML, QDateTime::currentDateTime(), false, theme_, P2QSTRING(id), getActualDirection(message, direction)));
- previousMessageKind_ = PreviousMessageWasPresence;
+ previousMessageKind_ = PreviousMessageWasPresence;
}
void QtWebKitChatView::replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour timestampBehaviour) {
- replaceLastMessage(chatMessageToHTML(message), timestampBehaviour);
+ replaceLastMessage(chatMessageToHTML(message), timestampBehaviour);
}
void QtWebKitChatView::addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) {
- if (window_->isWidgetSelected()) {
- window_->onAllMessagesRead();
- }
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
- QString message;
- if (isImpromptu) {
- message = QObject::tr("You've been invited to join a chat.") + "\n";
- } else {
- message = QObject::tr("You've been invited to enter the %1 room.").arg(P2QSTRING(jid.toString())) + "\n";
- }
- QString htmlString = message;
- if (!reason.empty()) {
- htmlString += QObject::tr("Reason: %1").arg(P2QSTRING(reason)) + "\n";
- }
- if (!direct) {
- htmlString += QObject::tr("This person may not have really sent this invitation!") + "\n";
- }
- htmlString = chatMessageToHTML(ChatWindow::ChatMessage(Q2PSTRING(htmlString)));
+ QString message;
+ if (isImpromptu) {
+ message = QObject::tr("You've been invited to join a chat.") + "\n";
+ } else {
+ message = QObject::tr("You've been invited to enter the %1 room.").arg(P2QSTRING(jid.toString())) + "\n";
+ }
+ QString htmlString = message;
+ if (!reason.empty()) {
+ htmlString += QObject::tr("Reason: %1").arg(P2QSTRING(reason)) + "\n";
+ }
+ if (!direct) {
+ htmlString += QObject::tr("This person may not have really sent this invitation!") + "\n";
+ }
+ htmlString = chatMessageToHTML(ChatWindow::ChatMessage(Q2PSTRING(htmlString)));
- QString id = QString(ButtonMUCInvite + "%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
- htmlString += "<div id='" + id + "'>" +
- buildChatWindowButton(chatMessageToHTML(ChatWindow::ChatMessage(Q2PSTRING((tr("Accept Invite"))))), ButtonMUCInvite, QtUtilities::htmlEscape(P2QSTRING(jid.toString())), QtUtilities::htmlEscape(P2QSTRING(password)), id, QtUtilities::htmlEscape(isImpromptu ? "true" : "false"), QtUtilities::htmlEscape(isContinuation ? "true" : "false")) +
- "</div>";
+ QString id = QString(ButtonMUCInvite + "%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
+ htmlString += "<div id='" + id + "'>" +
+ buildChatWindowButton(chatMessageToHTML(ChatWindow::ChatMessage(Q2PSTRING((tr("Accept Invite"))))), ButtonMUCInvite, QtUtilities::htmlEscape(P2QSTRING(jid.toString())), QtUtilities::htmlEscape(P2QSTRING(password)), id, QtUtilities::htmlEscape(isImpromptu ? "true" : "false"), QtUtilities::htmlEscape(isContinuation ? "true" : "false")) +
+ "</div>";
- bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMUCInvite, senderName, false);
+ bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMUCInvite, senderName, false);
- QString qAvatarPath = "qrc:/icons/avatar.png";
+ QString qAvatarPath = "qrc:/icons/avatar.png";
- addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::universal_time()), qAvatarPath, false, appendToPrevious, theme_, id, ChatSnippet::getDirection(message)));
- previousMessageWasSelf_ = false;
- previousSenderName_ = P2QSTRING(senderName);
- previousMessageKind_ = PreviousMessageWasMUCInvite;
+ addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::universal_time()), qAvatarPath, false, appendToPrevious, theme_, id, ChatSnippet::getDirection(message)));
+ previousMessageWasSelf_ = false;
+ previousSenderName_ = P2QSTRING(senderName);
+ previousMessageKind_ = PreviousMessageWasMUCInvite;
}
void QtWebKitChatView::setAckState(std::string const& id, ChatWindow::AckState state) {
- QString xml;
- switch (state) {
- case ChatWindow::Pending:
- xml = "<img src='qrc:/icons/throbber.gif' title='" + tr("This message has not been received by your server yet.") + "'/>";
- displayReceiptInfo(P2QSTRING(id), false);
- break;
- case ChatWindow::Received:
- xml = "";
- displayReceiptInfo(P2QSTRING(id), true);
- break;
- case ChatWindow::Failed: xml = "<img src='qrc:/icons/error.png' title='" + tr("This message may not have been transmitted.") + "'/>"; break;
- }
- setAckXML(P2QSTRING(id), xml);
+ QString xml;
+ switch (state) {
+ case ChatWindow::Pending:
+ xml = "<img src='qrc:/icons/throbber.gif' title='" + tr("This message has not been received by your server yet.") + "'/>";
+ displayReceiptInfo(P2QSTRING(id), false);
+ break;
+ case ChatWindow::Received:
+ xml = "";
+ displayReceiptInfo(P2QSTRING(id), true);
+ break;
+ case ChatWindow::Failed: xml = "<img src='qrc:/icons/error.png' title='" + tr("This message may not have been transmitted.") + "'/>"; break;
+ }
+ setAckXML(P2QSTRING(id), xml);
}
void QtWebKitChatView::setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) {
- QString xml;
- switch (state) {
- case ChatWindow::ReceiptReceived:
- xml = "<img src='qrc:/icons/delivery-successful.png' title='" + tr("The receipt for this message has been received.") + "'/>";
- break;
- case ChatWindow::ReceiptRequested:
- xml = "<img src='qrc:/icons/warn.png' title='" + tr("The receipt for this message has not yet been received. The recipient(s) might not have received this message.") + "'/>";
- break;
- case ChatWindow::ReceiptFailed:
- xml = "<img src='qrc:/icons/delivery-failure.png' title='" + tr("Failed to transmit message to the receipient(s).") + "'/>";
- }
- setReceiptXML(P2QSTRING(id), xml);
+ QString xml;
+ switch (state) {
+ case ChatWindow::ReceiptReceived:
+ xml = "<img src='qrc:/icons/delivery-successful.png' title='" + tr("The receipt for this message has been received.") + "'/>";
+ break;
+ case ChatWindow::ReceiptRequested:
+ xml = "<img src='qrc:/icons/warn.png' title='" + tr("The receipt for this message has not yet been received. The recipient(s) might not have received this message.") + "'/>";
+ break;
+ case ChatWindow::ReceiptFailed:
+ xml = "<img src='qrc:/icons/delivery-failure.png' title='" + tr("Failed to transmit message to the receipient(s).") + "'/>";
+ }
+ setReceiptXML(P2QSTRING(id), xml);
}
bool QtWebKitChatView::appendToPreviousCheck(PreviousMessageKind messageKind, const std::string& senderName, bool senderIsSelf) {
- bool result = previousMessageKind_ == messageKind && ((senderIsSelf && previousMessageWasSelf_) || (!senderIsSelf && !previousMessageWasSelf_&& previousSenderName_ == P2QSTRING(senderName)));
- if (insertingLastLine_) {
- insertingLastLine_ = false;
- return false;
- }
- return result;
+ bool result = previousMessageKind_ == messageKind && ((senderIsSelf && previousMessageWasSelf_) || (!senderIsSelf && !previousMessageWasSelf_&& previousSenderName_ == P2QSTRING(senderName)));
+ if (insertingLastLine_) {
+ insertingLastLine_ = false;
+ return false;
+ }
+ return result;
}
ChatSnippet::Direction QtWebKitChatView::getActualDirection(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) {
- if (direction == ChatWindow::DefaultDirection) {
- return QCoreApplication::translate("QApplication", "QT_LAYOUT_DIRECTION") == "RTL" ? ChatSnippet::RTL : ChatSnippet::LTR;
- }
- else {
- return ChatSnippet::getDirection(message);
- }
+ if (direction == ChatWindow::DefaultDirection) {
+ return QCoreApplication::translate("QApplication", "QT_LAYOUT_DIRECTION") == "RTL" ? ChatSnippet::RTL : ChatSnippet::LTR;
+ }
+ else {
+ return ChatSnippet::getDirection(message);
+ }
}
// void QtWebKitChatView::setShowEmoticons(bool value) {
-// showEmoticons_ = value;
+// showEmoticons_ = value;
// }
diff --git a/Swift/QtUI/QtWebKitChatView.h b/Swift/QtUI/QtWebKitChatView.h
index aeed53b..e3fb967 100644
--- a/Swift/QtUI/QtWebKitChatView.h
+++ b/Swift/QtUI/QtWebKitChatView.h
@@ -25,168 +25,168 @@ class QUrl;
class QDate;
namespace Swift {
- class QtWebView;
- class QtChatTheme;
- class QtChatWindowJSBridge;
- class UIEventStream;
- class QtChatWindow;
- class QtWebKitChatView : public QtChatView {
- Q_OBJECT
-
- public:
- static const QString ButtonWhiteboardSessionCancel;
- static const QString ButtonWhiteboardSessionAcceptRequest;
- static const QString ButtonWhiteboardShowWindow;
- static const QString ButtonFileTransferCancel;
- static const QString ButtonFileTransferSetDescription;
- static const QString ButtonFileTransferSendRequest;
- static const QString ButtonFileTransferAcceptRequest;
- static const QString ButtonFileTransferOpenFile;
- static const QString ButtonMUCInvite;
- public:
- QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStream, QtChatTheme* theme, QWidget* parent, bool disableAutoScroll = false);
- ~QtWebKitChatView();
-
- /** Add message to window.
- * @return id of added message (for acks).
- */
- virtual std::string addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
- /** Adds action to window.
- * @return id of added message (for acks);
- */
- virtual std::string addAction(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
-
- virtual std::string addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) SWIFTEN_OVERRIDE;
- virtual void addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) SWIFTEN_OVERRIDE;
-
- virtual void addErrorMessage(const ChatWindow::ChatMessage& message) SWIFTEN_OVERRIDE;
- virtual void replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
- virtual void replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, ChatWindow::TimestampBehaviour timestampBehaviour) SWIFTEN_OVERRIDE;
- virtual void replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
- virtual void replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour timestampBehaviour) SWIFTEN_OVERRIDE;
- virtual void setAckState(const std::string& id, ChatWindow::AckState state) SWIFTEN_OVERRIDE;
-
- virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) SWIFTEN_OVERRIDE;
- virtual void setFileTransferProgress(std::string, const int percentageDone) SWIFTEN_OVERRIDE;
- virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState state, const std::string& msg = "") SWIFTEN_OVERRIDE;
- virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) SWIFTEN_OVERRIDE;
- virtual std::string addWhiteboardRequest(const QString& contact, bool senderIsSelf) SWIFTEN_OVERRIDE;
- virtual void setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) SWIFTEN_OVERRIDE;
- virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) SWIFTEN_OVERRIDE;
-
- virtual void showEmoticons(bool show) SWIFTEN_OVERRIDE;
- void addMessageTop(boost::shared_ptr<ChatSnippet> snippet);
- void addMessageBottom(boost::shared_ptr<ChatSnippet> snippet);
-
- int getSnippetPositionByDate(const QDate& date); // FIXME : This probably shouldn't have been public
- virtual void addLastSeenLine() SWIFTEN_OVERRIDE;
-
- private: // previously public, now private
- void replaceLastMessage(const QString& newMessage, const ChatWindow::TimestampBehaviour timestampBehaviour);
- void replaceLastMessage(const QString& newMessage, const QString& note);
- void replaceMessage(const QString& newMessage, const QString& id, const QDateTime& time);
- void replaceSystemMessage(const QString& newMessage, const QString&id, const ChatWindow::TimestampBehaviour timestampBehaviour);
- void rememberScrolledToBottom();
- void setAckXML(const QString& id, const QString& xml);
- void setReceiptXML(const QString& id, const QString& xml);
- void displayReceiptInfo(const QString& id, bool showIt);
-
- QString getLastSentMessage();
- void addToJSEnvironment(const QString&, QObject*);
- void setFileTransferProgress(QString id, const int percentageDone);
- void setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& msg);
- void setFileTransferWarning(QString id, QString warningText);
- void removeFileTransferWarning(QString id);
- void setWhiteboardSessionStatus(QString id, const ChatWindow::WhiteboardSessionState state);
- void setMUCInvitationJoined(QString id);
- void askDesktopToOpenFile(const QString& filename);
-
- signals:
- void gotFocus();
- void fontResized(int);
- void logCleared();
- void scrollRequested(int pos);
- void scrollReachedTop();
- void scrollReachedBottom();
-
- public slots:
- void copySelectionToClipboard();
- void handleLinkClicked(const QUrl&);
- void resetView();
- void resetTopInsertPoint();
- void increaseFontSize(int numSteps = 1);
- void decreaseFontSize();
- virtual void resizeFont(int fontSizeSteps) SWIFTEN_OVERRIDE;
- virtual void scrollToBottom() SWIFTEN_OVERRIDE;
- virtual void handleKeyPressEvent(QKeyEvent* event) SWIFTEN_OVERRIDE;
-
- private slots:
- void handleViewLoadFinished(bool);
- void handleFrameSizeChanged();
- void handleClearRequested();
- void handleScrollRequested(int dx, int dy, const QRect& rectToScroll);
- void handleHTMLButtonClicked(QString id, QString arg1, QString arg2, QString arg3, QString arg4, QString arg5);
-
- private:
- enum PreviousMessageKind {
- PreviosuMessageWasNone,
- PreviousMessageWasMessage,
- PreviousMessageWasSystem,
- PreviousMessageWasPresence,
- PreviousMessageWasFileTransfer,
- PreviousMessageWasMUCInvite
- };
- std::string addMessage(
- const QString& message,
- const std::string& senderName,
- bool senderIsSelf,
- boost::shared_ptr<SecurityLabel> label,
- const std::string& avatarPath,
- const QString& style,
- const boost::posix_time::ptime& time,
- const HighlightAction& highlight,
- ChatSnippet::Direction direction);
- void replaceMessage(
- const QString& message,
- const std::string& id,
- const boost::posix_time::ptime& time,
- const QString& style,
- const HighlightAction& highlight);
- bool appendToPreviousCheck(PreviousMessageKind messageKind, const std::string& senderName, bool senderIsSelf);
- static ChatSnippet::Direction getActualDirection(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction);
- QString getHighlightSpanStart(const std::string& text, const std::string& background);
- QString getHighlightSpanStart(const HighlightAction& highlight);
- QString chatMessageToHTML(const ChatWindow::ChatMessage& message);
- static QString buildChatWindowButton(const QString& name, const QString& id, const QString& arg1 = QString(), const QString& arg2 = QString(), const QString& arg3 = QString(), const QString& arg4 = QString(), const QString& arg5 = QString());
-
- private:
- void headerEncode();
- void messageEncode();
- void addToDOM(boost::shared_ptr<ChatSnippet> snippet);
-
- QtChatWindow* window_;
- UIEventStream* eventStream_;
- bool viewReady_;
- bool isAtBottom_;
- bool topMessageAdded_;
- int scrollBarMaximum_;
- QtWebView* webView_;
- QWebPage* webPage_;
- int fontSizeSteps_;
- QtChatTheme* theme_;
- QWebElement lineSeparator_;
- QWebElement lastElement_;
- QWebElement firstElement_;
- QWebElement document_;
- bool disableAutoScroll_;
- QtChatWindowJSBridge* jsBridge;
- PreviousMessageKind previousMessageKind_;
- bool previousMessageWasSelf_;
- bool showEmoticons_;
- bool insertingLastLine_;
- int idCounter_;
- QString previousSenderName_;
- std::map<QString, QString> descriptions_;
- std::map<QString, QString> filePaths_;
- };
+ class QtWebView;
+ class QtChatTheme;
+ class QtChatWindowJSBridge;
+ class UIEventStream;
+ class QtChatWindow;
+ class QtWebKitChatView : public QtChatView {
+ Q_OBJECT
+
+ public:
+ static const QString ButtonWhiteboardSessionCancel;
+ static const QString ButtonWhiteboardSessionAcceptRequest;
+ static const QString ButtonWhiteboardShowWindow;
+ static const QString ButtonFileTransferCancel;
+ static const QString ButtonFileTransferSetDescription;
+ static const QString ButtonFileTransferSendRequest;
+ static const QString ButtonFileTransferAcceptRequest;
+ static const QString ButtonFileTransferOpenFile;
+ static const QString ButtonMUCInvite;
+ public:
+ QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStream, QtChatTheme* theme, QWidget* parent, bool disableAutoScroll = false);
+ ~QtWebKitChatView();
+
+ /** Add message to window.
+ * @return id of added message (for acks).
+ */
+ virtual std::string addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
+ /** Adds action to window.
+ * @return id of added message (for acks);
+ */
+ virtual std::string addAction(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
+
+ virtual std::string addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) SWIFTEN_OVERRIDE;
+ virtual void addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) SWIFTEN_OVERRIDE;
+
+ virtual void addErrorMessage(const ChatWindow::ChatMessage& message) SWIFTEN_OVERRIDE;
+ virtual void replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
+ virtual void replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, ChatWindow::TimestampBehaviour timestampBehaviour) SWIFTEN_OVERRIDE;
+ virtual void replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time) SWIFTEN_OVERRIDE;
+ virtual void replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour timestampBehaviour) SWIFTEN_OVERRIDE;
+ virtual void setAckState(const std::string& id, ChatWindow::AckState state) SWIFTEN_OVERRIDE;
+
+ virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) SWIFTEN_OVERRIDE;
+ virtual void setFileTransferProgress(std::string, const int percentageDone) SWIFTEN_OVERRIDE;
+ virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState state, const std::string& msg = "") SWIFTEN_OVERRIDE;
+ virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) SWIFTEN_OVERRIDE;
+ virtual std::string addWhiteboardRequest(const QString& contact, bool senderIsSelf) SWIFTEN_OVERRIDE;
+ virtual void setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) SWIFTEN_OVERRIDE;
+ virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) SWIFTEN_OVERRIDE;
+
+ virtual void showEmoticons(bool show) SWIFTEN_OVERRIDE;
+ void addMessageTop(boost::shared_ptr<ChatSnippet> snippet);
+ void addMessageBottom(boost::shared_ptr<ChatSnippet> snippet);
+
+ int getSnippetPositionByDate(const QDate& date); // FIXME : This probably shouldn't have been public
+ virtual void addLastSeenLine() SWIFTEN_OVERRIDE;
+
+ private: // previously public, now private
+ void replaceLastMessage(const QString& newMessage, const ChatWindow::TimestampBehaviour timestampBehaviour);
+ void replaceLastMessage(const QString& newMessage, const QString& note);
+ void replaceMessage(const QString& newMessage, const QString& id, const QDateTime& time);
+ void replaceSystemMessage(const QString& newMessage, const QString&id, const ChatWindow::TimestampBehaviour timestampBehaviour);
+ void rememberScrolledToBottom();
+ void setAckXML(const QString& id, const QString& xml);
+ void setReceiptXML(const QString& id, const QString& xml);
+ void displayReceiptInfo(const QString& id, bool showIt);
+
+ QString getLastSentMessage();
+ void addToJSEnvironment(const QString&, QObject*);
+ void setFileTransferProgress(QString id, const int percentageDone);
+ void setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& msg);
+ void setFileTransferWarning(QString id, QString warningText);
+ void removeFileTransferWarning(QString id);
+ void setWhiteboardSessionStatus(QString id, const ChatWindow::WhiteboardSessionState state);
+ void setMUCInvitationJoined(QString id);
+ void askDesktopToOpenFile(const QString& filename);
+
+ signals:
+ void gotFocus();
+ void fontResized(int);
+ void logCleared();
+ void scrollRequested(int pos);
+ void scrollReachedTop();
+ void scrollReachedBottom();
+
+ public slots:
+ void copySelectionToClipboard();
+ void handleLinkClicked(const QUrl&);
+ void resetView();
+ void resetTopInsertPoint();
+ void increaseFontSize(int numSteps = 1);
+ void decreaseFontSize();
+ virtual void resizeFont(int fontSizeSteps) SWIFTEN_OVERRIDE;
+ virtual void scrollToBottom() SWIFTEN_OVERRIDE;
+ virtual void handleKeyPressEvent(QKeyEvent* event) SWIFTEN_OVERRIDE;
+
+ private slots:
+ void handleViewLoadFinished(bool);
+ void handleFrameSizeChanged();
+ void handleClearRequested();
+ void handleScrollRequested(int dx, int dy, const QRect& rectToScroll);
+ void handleHTMLButtonClicked(QString id, QString arg1, QString arg2, QString arg3, QString arg4, QString arg5);
+
+ private:
+ enum PreviousMessageKind {
+ PreviosuMessageWasNone,
+ PreviousMessageWasMessage,
+ PreviousMessageWasSystem,
+ PreviousMessageWasPresence,
+ PreviousMessageWasFileTransfer,
+ PreviousMessageWasMUCInvite
+ };
+ std::string addMessage(
+ const QString& message,
+ const std::string& senderName,
+ bool senderIsSelf,
+ boost::shared_ptr<SecurityLabel> label,
+ const std::string& avatarPath,
+ const QString& style,
+ const boost::posix_time::ptime& time,
+ const HighlightAction& highlight,
+ ChatSnippet::Direction direction);
+ void replaceMessage(
+ const QString& message,
+ const std::string& id,
+ const boost::posix_time::ptime& time,
+ const QString& style,
+ const HighlightAction& highlight);
+ bool appendToPreviousCheck(PreviousMessageKind messageKind, const std::string& senderName, bool senderIsSelf);
+ static ChatSnippet::Direction getActualDirection(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction);
+ QString getHighlightSpanStart(const std::string& text, const std::string& background);
+ QString getHighlightSpanStart(const HighlightAction& highlight);
+ QString chatMessageToHTML(const ChatWindow::ChatMessage& message);
+ static QString buildChatWindowButton(const QString& name, const QString& id, const QString& arg1 = QString(), const QString& arg2 = QString(), const QString& arg3 = QString(), const QString& arg4 = QString(), const QString& arg5 = QString());
+
+ private:
+ void headerEncode();
+ void messageEncode();
+ void addToDOM(boost::shared_ptr<ChatSnippet> snippet);
+
+ QtChatWindow* window_;
+ UIEventStream* eventStream_;
+ bool viewReady_;
+ bool isAtBottom_;
+ bool topMessageAdded_;
+ int scrollBarMaximum_;
+ QtWebView* webView_;
+ QWebPage* webPage_;
+ int fontSizeSteps_;
+ QtChatTheme* theme_;
+ QWebElement lineSeparator_;
+ QWebElement lastElement_;
+ QWebElement firstElement_;
+ QWebElement document_;
+ bool disableAutoScroll_;
+ QtChatWindowJSBridge* jsBridge;
+ PreviousMessageKind previousMessageKind_;
+ bool previousMessageWasSelf_;
+ bool showEmoticons_;
+ bool insertingLastLine_;
+ int idCounter_;
+ QString previousSenderName_;
+ std::map<QString, QString> descriptions_;
+ std::map<QString, QString> filePaths_;
+ };
}
diff --git a/Swift/QtUI/QtWebView.cpp b/Swift/QtUI/QtWebView.cpp
index 4950d27..717310b 100644
--- a/Swift/QtUI/QtWebView.cpp
+++ b/Swift/QtUI/QtWebView.cpp
@@ -17,29 +17,29 @@
namespace Swift {
QtWebView::QtWebView(QWidget* parent) : QWebView(parent), fontSizeIsMinimal(false) {
- setRenderHint(QPainter::SmoothPixmapTransform);
- filteredActions.push_back(QWebPage::CopyLinkToClipboard);
- filteredActions.push_back(QWebPage::CopyImageToClipboard);
- filteredActions.push_back(QWebPage::Copy);
- if (Log::getLogLevel() == Log::debug) {
- filteredActions.push_back(QWebPage::InspectElement);
- }
+ setRenderHint(QPainter::SmoothPixmapTransform);
+ filteredActions.push_back(QWebPage::CopyLinkToClipboard);
+ filteredActions.push_back(QWebPage::CopyImageToClipboard);
+ filteredActions.push_back(QWebPage::Copy);
+ if (Log::getLogLevel() == Log::debug) {
+ filteredActions.push_back(QWebPage::InspectElement);
+ }
}
void QtWebView::keyPressEvent(QKeyEvent* event) {
- Qt::KeyboardModifiers modifiers = event->modifiers();
- int key = event->key();
- if (modifiers == Qt::ShiftModifier && (key == Qt::Key_PageUp || key == Qt::Key_PageDown)) {
- modifiers = Qt::NoModifier;
- }
- QKeyEvent* translatedEvent = new QKeyEvent(QEvent::KeyPress,
- key,
- modifiers,
- event->text(),
- event->isAutoRepeat(),
- boost::numeric_cast<unsigned short>(event->count()));
- QWebView::keyPressEvent(translatedEvent);
- delete translatedEvent;
+ Qt::KeyboardModifiers modifiers = event->modifiers();
+ int key = event->key();
+ if (modifiers == Qt::ShiftModifier && (key == Qt::Key_PageUp || key == Qt::Key_PageDown)) {
+ modifiers = Qt::NoModifier;
+ }
+ QKeyEvent* translatedEvent = new QKeyEvent(QEvent::KeyPress,
+ key,
+ modifiers,
+ event->text(),
+ event->isAutoRepeat(),
+ boost::numeric_cast<unsigned short>(event->count()));
+ QWebView::keyPressEvent(translatedEvent);
+ delete translatedEvent;
}
void QtWebView::dragEnterEvent(QDragEnterEvent*) {
@@ -47,43 +47,43 @@ void QtWebView::dragEnterEvent(QDragEnterEvent*) {
}
void QtWebView::setFontSizeIsMinimal(bool minimum) {
- fontSizeIsMinimal = minimum;
+ fontSizeIsMinimal = minimum;
}
void QtWebView::contextMenuEvent(QContextMenuEvent* ev) {
- // Filter out the relevant actions from the standard actions
-
- QMenu* menu = page()->createStandardContextMenu();
- QList<QAction*> actions(menu->actions());
- for (int i = 0; i < actions.size(); ++i) {
- QAction* action = actions.at(i);
- bool removeAction = true;
- for(size_t j = 0; j < filteredActions.size(); ++j) {
- if (action == pageAction(filteredActions[j])) {
- removeAction = false;
- break;
- }
- }
- if (removeAction) {
- menu->removeAction(action);
- }
- }
-
- // Add our own custom actions
- menu->addAction(tr("Clear"), this, SIGNAL(clearRequested()));
- menu->addAction(tr("Increase font size"), this, SIGNAL(fontGrowRequested()));
- QAction* shrink = new QAction(tr("Decrease font size"), this);
- shrink->setEnabled(!fontSizeIsMinimal);
- connect(shrink, SIGNAL(triggered()), this, SIGNAL(fontShrinkRequested()));
- menu->addAction(shrink);
-
- menu->exec(ev->globalPos());
- delete menu;
+ // Filter out the relevant actions from the standard actions
+
+ QMenu* menu = page()->createStandardContextMenu();
+ QList<QAction*> actions(menu->actions());
+ for (int i = 0; i < actions.size(); ++i) {
+ QAction* action = actions.at(i);
+ bool removeAction = true;
+ for(size_t j = 0; j < filteredActions.size(); ++j) {
+ if (action == pageAction(filteredActions[j])) {
+ removeAction = false;
+ break;
+ }
+ }
+ if (removeAction) {
+ menu->removeAction(action);
+ }
+ }
+
+ // Add our own custom actions
+ menu->addAction(tr("Clear"), this, SIGNAL(clearRequested()));
+ menu->addAction(tr("Increase font size"), this, SIGNAL(fontGrowRequested()));
+ QAction* shrink = new QAction(tr("Decrease font size"), this);
+ shrink->setEnabled(!fontSizeIsMinimal);
+ connect(shrink, SIGNAL(triggered()), this, SIGNAL(fontShrinkRequested()));
+ menu->addAction(shrink);
+
+ menu->exec(ev->globalPos());
+ delete menu;
}
void QtWebView::focusInEvent(QFocusEvent* event) {
- QWebView::focusInEvent(event);
- emit gotFocus();
+ QWebView::focusInEvent(event);
+ emit gotFocus();
}
}
diff --git a/Swift/QtUI/QtWebView.h b/Swift/QtUI/QtWebView.h
index 134f578..985a0db 100644
--- a/Swift/QtUI/QtWebView.h
+++ b/Swift/QtUI/QtWebView.h
@@ -12,26 +12,26 @@
#include <QWebView>
namespace Swift {
- class QtWebView : public QWebView {
- Q_OBJECT
- public:
- QtWebView(QWidget* parent);
- void keyPressEvent(QKeyEvent* event);
- void dragEnterEvent(QDragEnterEvent *event);
- void contextMenuEvent(QContextMenuEvent* ev);
- void setFontSizeIsMinimal(bool minimum);
-
- signals:
- void gotFocus();
- void clearRequested();
- void fontGrowRequested();
- void fontShrinkRequested();
-
- protected:
- void focusInEvent(QFocusEvent* event);
-
- private:
- std::vector<QWebPage::WebAction> filteredActions;
- bool fontSizeIsMinimal;
- };
+ class QtWebView : public QWebView {
+ Q_OBJECT
+ public:
+ QtWebView(QWidget* parent);
+ void keyPressEvent(QKeyEvent* event);
+ void dragEnterEvent(QDragEnterEvent *event);
+ void contextMenuEvent(QContextMenuEvent* ev);
+ void setFontSizeIsMinimal(bool minimum);
+
+ signals:
+ void gotFocus();
+ void clearRequested();
+ void fontGrowRequested();
+ void fontShrinkRequested();
+
+ protected:
+ void focusInEvent(QFocusEvent* event);
+
+ private:
+ std::vector<QWebPage::WebAction> filteredActions;
+ bool fontSizeIsMinimal;
+ };
}
diff --git a/Swift/QtUI/QtWin32NotifierWindow.h b/Swift/QtUI/QtWin32NotifierWindow.h
index 54369cf..bf55706 100644
--- a/Swift/QtUI/QtWin32NotifierWindow.h
+++ b/Swift/QtUI/QtWin32NotifierWindow.h
@@ -11,19 +11,19 @@
#include <SwifTools/Notifier/Win32NotifierWindow.h>
namespace Swift {
- class QtWin32NotifierWindow : public QWidget, public Win32NotifierWindow {
- public:
- QtWin32NotifierWindow(QWidget* parent = NULL) {
- setVisible(false);
- }
+ class QtWin32NotifierWindow : public QWidget, public Win32NotifierWindow {
+ public:
+ QtWin32NotifierWindow(QWidget* parent = NULL) {
+ setVisible(false);
+ }
- bool winEvent (MSG* message, long* result ) {
- onMessageReceived(message);
- return false;
- }
+ bool winEvent (MSG* message, long* result ) {
+ onMessageReceived(message);
+ return false;
+ }
- virtual HWND getID() const {
- return (HWND) winId();
- }
- };
+ virtual HWND getID() const {
+ return (HWND) winId();
+ }
+ };
}
diff --git a/Swift/QtUI/QtXMLConsoleWidget.cpp b/Swift/QtUI/QtXMLConsoleWidget.cpp
index 1fbad8f..a7f9702 100644
--- a/Swift/QtUI/QtXMLConsoleWidget.cpp
+++ b/Swift/QtUI/QtXMLConsoleWidget.cpp
@@ -22,99 +22,99 @@
namespace Swift {
QtXMLConsoleWidget::QtXMLConsoleWidget() {
- setWindowTitle(tr("Console"));
+ setWindowTitle(tr("Console"));
- QVBoxLayout* layout = new QVBoxLayout(this);
- layout->setSpacing(0);
- layout->setContentsMargins(0,0,0,0);
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->setSpacing(0);
+ layout->setContentsMargins(0,0,0,0);
- textEdit = new QTextEdit(this);
- textEdit->setReadOnly(true);
- layout->addWidget(textEdit);
+ textEdit = new QTextEdit(this);
+ textEdit->setReadOnly(true);
+ layout->addWidget(textEdit);
- QWidget* bottom = new QWidget(this);
- layout->addWidget(bottom);
- bottom->setAutoFillBackground(true);
+ QWidget* bottom = new QWidget(this);
+ layout->addWidget(bottom);
+ bottom->setAutoFillBackground(true);
- QHBoxLayout* buttonLayout = new QHBoxLayout(bottom);
- buttonLayout->setContentsMargins(10,0,20,0);
- buttonLayout->setSpacing(0);
+ QHBoxLayout* buttonLayout = new QHBoxLayout(bottom);
+ buttonLayout->setContentsMargins(10,0,20,0);
+ buttonLayout->setSpacing(0);
- enabled = new QCheckBox(tr("Trace input/output"), bottom);
- enabled->setChecked(true);
- buttonLayout->addWidget(enabled);
+ enabled = new QCheckBox(tr("Trace input/output"), bottom);
+ enabled->setChecked(true);
+ buttonLayout->addWidget(enabled);
- buttonLayout->addStretch();
+ buttonLayout->addStretch();
- QPushButton* clearButton = new QPushButton(tr("Clear"), bottom);
- connect(clearButton, SIGNAL(clicked()), textEdit, SLOT(clear()));
- buttonLayout->addWidget(clearButton);
+ QPushButton* clearButton = new QPushButton(tr("Clear"), bottom);
+ connect(clearButton, SIGNAL(clicked()), textEdit, SLOT(clear()));
+ buttonLayout->addWidget(clearButton);
- setWindowTitle(tr("Debug Console"));
- emit titleUpdated();
+ setWindowTitle(tr("Debug Console"));
+ emit titleUpdated();
}
QtXMLConsoleWidget::~QtXMLConsoleWidget() {
}
void QtXMLConsoleWidget::showEvent(QShowEvent* event) {
- emit windowOpening();
- emit titleUpdated(); /* This just needs to be somewhere after construction */
- QWidget::showEvent(event);
+ emit windowOpening();
+ emit titleUpdated(); /* This just needs to be somewhere after construction */
+ QWidget::showEvent(event);
}
void QtXMLConsoleWidget::show() {
- QWidget::show();
- emit windowOpening();
+ QWidget::show();
+ emit windowOpening();
}
void QtXMLConsoleWidget::activate() {
- emit wantsToActivate();
+ emit wantsToActivate();
}
void QtXMLConsoleWidget::closeEvent(QCloseEvent* event) {
- emit windowClosing();
- event->accept();
+ emit windowClosing();
+ event->accept();
}
void QtXMLConsoleWidget::handleDataRead(const SafeByteArray& data) {
- boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
- std::string tag = Q2PSTRING(tr("<!-- IN %1 -->").arg(P2QSTRING(boost::posix_time::to_iso_extended_string(now))));
- appendTextIfEnabled(tag + "\n" + safeByteArrayToString(data) + "\n", QColor(33,98,33));
+ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
+ std::string tag = Q2PSTRING(tr("<!-- IN %1 -->").arg(P2QSTRING(boost::posix_time::to_iso_extended_string(now))));
+ appendTextIfEnabled(tag + "\n" + safeByteArrayToString(data) + "\n", QColor(33,98,33));
}
void QtXMLConsoleWidget::handleDataWritten(const SafeByteArray& data) {
- boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
- std::string tag = Q2PSTRING(tr("<!-- OUT %1 -->").arg(P2QSTRING(boost::posix_time::to_iso_extended_string(now))));
- appendTextIfEnabled(tag + "\n" + safeByteArrayToString(data) + "\n", QColor(155,1,0));
+ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
+ std::string tag = Q2PSTRING(tr("<!-- OUT %1 -->").arg(P2QSTRING(boost::posix_time::to_iso_extended_string(now))));
+ appendTextIfEnabled(tag + "\n" + safeByteArrayToString(data) + "\n", QColor(155,1,0));
}
std::string QtXMLConsoleWidget::getID() const {
- return "QtXMLConsoleWidget";
+ return "QtXMLConsoleWidget";
}
void QtXMLConsoleWidget::appendTextIfEnabled(const std::string& data, const QColor& color) {
- if (enabled->isChecked()) {
- QScrollBar* scrollBar = textEdit->verticalScrollBar();
- bool scrollToBottom = (!scrollBar || scrollBar->value() == scrollBar->maximum());
-
- QTextCursor cursor(textEdit->document());
- cursor.beginEditBlock();
- cursor.movePosition(QTextCursor::End);
- QTextCharFormat format;
- format.setForeground(QBrush(color));
- cursor.mergeCharFormat(format);
- cursor.insertText(P2QSTRING(data));
- cursor.endEditBlock();
-
- // Checking for the scrollbar again, because it could have appeared after inserting text.
- // In practice, I suspect that the scrollbar is always there, but hidden, but since we were
- // explicitly testing for this already above, I'm leaving the code in.
- scrollBar = textEdit->verticalScrollBar();
- if (scrollToBottom && scrollBar) {
- scrollBar->setValue(scrollBar->maximum());
- }
- }
+ if (enabled->isChecked()) {
+ QScrollBar* scrollBar = textEdit->verticalScrollBar();
+ bool scrollToBottom = (!scrollBar || scrollBar->value() == scrollBar->maximum());
+
+ QTextCursor cursor(textEdit->document());
+ cursor.beginEditBlock();
+ cursor.movePosition(QTextCursor::End);
+ QTextCharFormat format;
+ format.setForeground(QBrush(color));
+ cursor.mergeCharFormat(format);
+ cursor.insertText(P2QSTRING(data));
+ cursor.endEditBlock();
+
+ // Checking for the scrollbar again, because it could have appeared after inserting text.
+ // In practice, I suspect that the scrollbar is always there, but hidden, but since we were
+ // explicitly testing for this already above, I'm leaving the code in.
+ scrollBar = textEdit->verticalScrollBar();
+ if (scrollToBottom && scrollBar) {
+ scrollBar->setValue(scrollBar->maximum());
+ }
+ }
}
}
diff --git a/Swift/QtUI/QtXMLConsoleWidget.h b/Swift/QtUI/QtXMLConsoleWidget.h
index ddcfe20..ef10e63 100644
--- a/Swift/QtUI/QtXMLConsoleWidget.h
+++ b/Swift/QtUI/QtXMLConsoleWidget.h
@@ -15,29 +15,29 @@ class QCheckBox;
class QColor;
namespace Swift {
- class QtXMLConsoleWidget : public QtTabbable, public XMLConsoleWidget {
- Q_OBJECT
+ class QtXMLConsoleWidget : public QtTabbable, public XMLConsoleWidget {
+ Q_OBJECT
- public:
- QtXMLConsoleWidget();
- ~QtXMLConsoleWidget();
+ public:
+ QtXMLConsoleWidget();
+ ~QtXMLConsoleWidget();
- void show();
- void activate();
+ void show();
+ void activate();
- virtual void handleDataRead(const SafeByteArray& data);
- virtual void handleDataWritten(const SafeByteArray& data);
+ virtual void handleDataRead(const SafeByteArray& data);
+ virtual void handleDataWritten(const SafeByteArray& data);
- virtual std::string getID() const;
+ virtual std::string getID() const;
- private:
- virtual void closeEvent(QCloseEvent* event);
- virtual void showEvent(QShowEvent* event);
+ private:
+ virtual void closeEvent(QCloseEvent* event);
+ virtual void showEvent(QShowEvent* event);
- void appendTextIfEnabled(const std::string& data, const QColor& color);
+ void appendTextIfEnabled(const std::string& data, const QColor& color);
- private:
- QTextEdit* textEdit;
- QCheckBox* enabled;
- };
+ private:
+ QTextEdit* textEdit;
+ QCheckBox* enabled;
+ };
}
diff --git a/Swift/QtUI/Roster/DelegateCommons.cpp b/Swift/QtUI/Roster/DelegateCommons.cpp
index f9d732c..517683b 100644
--- a/Swift/QtUI/Roster/DelegateCommons.cpp
+++ b/Swift/QtUI/Roster/DelegateCommons.cpp
@@ -14,96 +14,96 @@ namespace Swift {
void DelegateCommons::drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags) {
- QString adjustedText(painter->fontMetrics().elidedText(text, Qt::ElideRight, region.width(), Qt::TextShowMnemonic));
- painter->setClipRect(region);
- painter->drawText(region, flags, adjustedText.simplified());
- painter->setClipping(false);
+ QString adjustedText(painter->fontMetrics().elidedText(text, Qt::ElideRight, region.width(), Qt::TextShowMnemonic));
+ painter->setClipRect(region);
+ painter->drawText(region, flags, adjustedText.simplified());
+ painter->setClipping(false);
}
void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, bool isIdle, int unreadCount, bool compact) const {
- painter->save();
- QRect fullRegion(option.rect);
- if ( option.state & QStyle::State_Selected ) {
- painter->fillRect(fullRegion, option.palette.highlight());
- painter->setPen(option.palette.highlightedText().color());
- } else {
- painter->setPen(QPen(nameColor));
- }
-
- QRect presenceIconRegion(QPoint(farLeftMargin, fullRegion.top()), QSize(presenceIconWidth, fullRegion.height() - verticalMargin));
-
- QRect idleIconRegion(QPoint(farLeftMargin, fullRegion.top()), QSize(presenceIconWidth*2, fullRegion.height() - verticalMargin));
- int calculatedAvatarSize = presenceIconRegion.height();
- //This overlaps the presenceIcon, so must be painted first
- QRect avatarRegion(QPoint(presenceIconRegion.right() - presenceIconWidth / 2, presenceIconRegion.top()), QSize(calculatedAvatarSize, calculatedAvatarSize));
-
- QPixmap avatarPixmap;
- if (!compact && !avatarPath.isEmpty()) {
- QString scaledAvatarPath = QtScaledAvatarCache(avatarRegion.height()).getScaledAvatarPath(avatarPath);
- if (QFileInfo(scaledAvatarPath).exists()) {
- avatarPixmap.load(scaledAvatarPath);
- }
- }
- if (!compact && avatarPixmap.isNull()) {
- avatarPixmap = QPixmap(":/icons/avatar.png").scaled(avatarRegion.height(), avatarRegion.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
- }
-
- if (!compact) {
- painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap);
- }
-
- //Paint the presence icon over the top of the avatar
- presenceIcon.paint(painter, presenceIconRegion, Qt::AlignBottom | Qt::AlignHCenter);
-
- if (isIdle) {
- idleIcon.paint(painter, idleIconRegion, Qt::AlignBottom | Qt::AlignHCenter);
- }
-
- QFontMetrics nameMetrics(nameFont);
- painter->setFont(nameFont);
- int extraFontWidth = nameMetrics.width("H");
- int leftOffset = (compact ? presenceIconRegion : avatarRegion).right() + horizontalMargin * 2 + extraFontWidth / 2;
- QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0/*-leftOffset*/, 0));
-
- int nameHeight = nameMetrics.height() + verticalMargin;
- QRect nameRegion(textRegion.adjusted(0, verticalMargin, 0, 0));
-
- DelegateCommons::drawElidedText(painter, nameRegion, name);
-
- if (!compact) {
- painter->setFont(detailFont);
- painter->setPen(QPen(QColor(160,160,160)));
-
- QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0));
- DelegateCommons::drawElidedText(painter, statusTextRegion, statusText);
- }
-
- if (unreadCount > 0) {
- QRect unreadRect(fullRegion.right() - unreadCountSize - horizontalMargin, fullRegion.top() + (fullRegion.height() - unreadCountSize) / 2, unreadCountSize, unreadCountSize);
- QPen pen(QColor("black"));
- pen.setWidth(1);
- painter->setRenderHint(QPainter::Antialiasing, true);
- painter->setPen(pen);
- painter->setBrush(QBrush(QColor("red"), Qt::SolidPattern));
- //painter->setBackgroundMode(Qt::OpaqueMode);
- painter->drawEllipse(unreadRect);
- painter->setBackgroundMode(Qt::TransparentMode);
- painter->setPen(QColor("white"));
- drawElidedText(painter, unreadRect, QString("%1").arg(unreadCount), Qt::AlignCenter);
- }
-
- painter->restore();
+ painter->save();
+ QRect fullRegion(option.rect);
+ if ( option.state & QStyle::State_Selected ) {
+ painter->fillRect(fullRegion, option.palette.highlight());
+ painter->setPen(option.palette.highlightedText().color());
+ } else {
+ painter->setPen(QPen(nameColor));
+ }
+
+ QRect presenceIconRegion(QPoint(farLeftMargin, fullRegion.top()), QSize(presenceIconWidth, fullRegion.height() - verticalMargin));
+
+ QRect idleIconRegion(QPoint(farLeftMargin, fullRegion.top()), QSize(presenceIconWidth*2, fullRegion.height() - verticalMargin));
+ int calculatedAvatarSize = presenceIconRegion.height();
+ //This overlaps the presenceIcon, so must be painted first
+ QRect avatarRegion(QPoint(presenceIconRegion.right() - presenceIconWidth / 2, presenceIconRegion.top()), QSize(calculatedAvatarSize, calculatedAvatarSize));
+
+ QPixmap avatarPixmap;
+ if (!compact && !avatarPath.isEmpty()) {
+ QString scaledAvatarPath = QtScaledAvatarCache(avatarRegion.height()).getScaledAvatarPath(avatarPath);
+ if (QFileInfo(scaledAvatarPath).exists()) {
+ avatarPixmap.load(scaledAvatarPath);
+ }
+ }
+ if (!compact && avatarPixmap.isNull()) {
+ avatarPixmap = QPixmap(":/icons/avatar.png").scaled(avatarRegion.height(), avatarRegion.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ }
+
+ if (!compact) {
+ painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap);
+ }
+
+ //Paint the presence icon over the top of the avatar
+ presenceIcon.paint(painter, presenceIconRegion, Qt::AlignBottom | Qt::AlignHCenter);
+
+ if (isIdle) {
+ idleIcon.paint(painter, idleIconRegion, Qt::AlignBottom | Qt::AlignHCenter);
+ }
+
+ QFontMetrics nameMetrics(nameFont);
+ painter->setFont(nameFont);
+ int extraFontWidth = nameMetrics.width("H");
+ int leftOffset = (compact ? presenceIconRegion : avatarRegion).right() + horizontalMargin * 2 + extraFontWidth / 2;
+ QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0/*-leftOffset*/, 0));
+
+ int nameHeight = nameMetrics.height() + verticalMargin;
+ QRect nameRegion(textRegion.adjusted(0, verticalMargin, 0, 0));
+
+ DelegateCommons::drawElidedText(painter, nameRegion, name);
+
+ if (!compact) {
+ painter->setFont(detailFont);
+ painter->setPen(QPen(QColor(160,160,160)));
+
+ QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0));
+ DelegateCommons::drawElidedText(painter, statusTextRegion, statusText);
+ }
+
+ if (unreadCount > 0) {
+ QRect unreadRect(fullRegion.right() - unreadCountSize - horizontalMargin, fullRegion.top() + (fullRegion.height() - unreadCountSize) / 2, unreadCountSize, unreadCountSize);
+ QPen pen(QColor("black"));
+ pen.setWidth(1);
+ painter->setRenderHint(QPainter::Antialiasing, true);
+ painter->setPen(pen);
+ painter->setBrush(QBrush(QColor("red"), Qt::SolidPattern));
+ //painter->setBackgroundMode(Qt::OpaqueMode);
+ painter->drawEllipse(unreadRect);
+ painter->setBackgroundMode(Qt::TransparentMode);
+ painter->setPen(QColor("white"));
+ drawElidedText(painter, unreadRect, QString("%1").arg(unreadCount), Qt::AlignCenter);
+ }
+
+ painter->restore();
}
QSize DelegateCommons::contactSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/, bool compact ) const {
- int heightByAvatar = (compact ? presenceIconHeight : avatarSize) + verticalMargin * 2;
- QFontMetrics nameMetrics(nameFont);
- QFontMetrics statusMetrics(detailFont);
- int sizeByText = 2 * verticalMargin + nameMetrics.height() + (compact ? 0 : statusMetrics.height());
- //Doesn't work, yay! FIXME: why?
- //QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150, avatarSize_ + margin_ * 2);
- //qDebug() << "Returning size" << size;
- return QSize(150, sizeByText > heightByAvatar ? sizeByText : heightByAvatar);
+ int heightByAvatar = (compact ? presenceIconHeight : avatarSize) + verticalMargin * 2;
+ QFontMetrics nameMetrics(nameFont);
+ QFontMetrics statusMetrics(detailFont);
+ int sizeByText = 2 * verticalMargin + nameMetrics.height() + (compact ? 0 : statusMetrics.height());
+ //Doesn't work, yay! FIXME: why?
+ //QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150, avatarSize_ + margin_ * 2);
+ //qDebug() << "Returning size" << size;
+ return QSize(150, sizeByText > heightByAvatar ? sizeByText : heightByAvatar);
}
const int DelegateCommons::horizontalMargin = 2;
diff --git a/Swift/QtUI/Roster/DelegateCommons.h b/Swift/QtUI/Roster/DelegateCommons.h
index 5e28ac1..74b08f2 100644
--- a/Swift/QtUI/Roster/DelegateCommons.h
+++ b/Swift/QtUI/Roster/DelegateCommons.h
@@ -15,29 +15,29 @@
#include <QStyleOptionViewItem>
namespace Swift {
- class DelegateCommons {
- public:
- DelegateCommons() : nameFont(QApplication::font()), detailFont(QApplication::font()), idleIcon(QIcon(":/icons/zzz.png")) {
- detailFontSizeDrop = nameFont.pointSize() >= 10 ? 2 : 0;
- detailFont.setStyle(QFont::StyleItalic);
- detailFont.setPointSize(nameFont.pointSize() - detailFontSizeDrop);
- }
+ class DelegateCommons {
+ public:
+ DelegateCommons() : nameFont(QApplication::font()), detailFont(QApplication::font()), idleIcon(QIcon(":/icons/zzz.png")) {
+ detailFontSizeDrop = nameFont.pointSize() >= 10 ? 2 : 0;
+ detailFont.setStyle(QFont::StyleItalic);
+ detailFont.setPointSize(nameFont.pointSize() - detailFontSizeDrop);
+ }
- static void drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags = Qt::AlignTop);
+ static void drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags = Qt::AlignTop);
- QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index, bool compact) const;
- void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, bool isIdle, int unreadCount, bool compact) const;
+ QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index, bool compact) const;
+ void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, bool isIdle, int unreadCount, bool compact) const;
- int detailFontSizeDrop;
- QFont nameFont;
- QFont detailFont;
- static const int horizontalMargin;
- static const int verticalMargin;
- static const int farLeftMargin;
- static const int avatarSize;
- static const int presenceIconHeight;
- static const int presenceIconWidth;
- static const int unreadCountSize;
- QIcon idleIcon;
- };
+ int detailFontSizeDrop;
+ QFont nameFont;
+ QFont detailFont;
+ static const int horizontalMargin;
+ static const int verticalMargin;
+ static const int farLeftMargin;
+ static const int avatarSize;
+ static const int presenceIconHeight;
+ static const int presenceIconWidth;
+ static const int unreadCountSize;
+ QIcon idleIcon;
+ };
}
diff --git a/Swift/QtUI/Roster/GroupItemDelegate.cpp b/Swift/QtUI/Roster/GroupItemDelegate.cpp
index d91d4ba..0356aa0 100644
--- a/Swift/QtUI/Roster/GroupItemDelegate.cpp
+++ b/Swift/QtUI/Roster/GroupItemDelegate.cpp
@@ -13,100 +13,100 @@
namespace Swift {
GroupItemDelegate::GroupItemDelegate() : groupFont_(QApplication::font()) {
- groupFont_.setPointSize(common_.nameFont.pointSize() - common_.detailFontSizeDrop);
- groupFont_.setWeight(QFont::Bold);
+ groupFont_.setPointSize(common_.nameFont.pointSize() - common_.detailFontSizeDrop);
+ groupFont_.setWeight(QFont::Bold);
}
QSize GroupItemDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const {
- QFontMetrics groupMetrics(groupFont_);
- return QSize(150, groupMetrics.height() + common_.verticalMargin + 2);
+ QFontMetrics groupMetrics(groupFont_);
+ return QSize(150, groupMetrics.height() + common_.verticalMargin + 2);
}
void GroupItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QString& name, int rowCount, bool expanded) const {
- painter->save();
- painter->setPen(QPen(QColor(189, 189, 189)));
- //FIXME: It looks like Qt is passing us a rectangle that's too small
- //This deliberately draws outside the lines, and we need to find a better solution.
- int correctionAmount = groupCornerRadius_ > 0 ? 0 : 1;
- QRect region(QPoint(option.rect.left() - correctionAmount, option.rect.top()), QSize(option.rect.width() + correctionAmount, option.rect.height() - common_.verticalMargin));
- QLinearGradient fillGradient(region.topLeft(), region.bottomLeft());
- fillGradient.setColorAt(0, QColor(244, 244, 244));
- fillGradient.setColorAt(0.1, QColor(231, 231, 231));
- fillGradient.setColorAt(1, QColor(209, 209, 209));
-
- QBrush backgroundBrush = QBrush(fillGradient);
- QPainterPath fillPath;
- fillPath.addRoundedRect(region, groupCornerRadius_, groupCornerRadius_);
- QPainterPath linePath;
- linePath.addRoundedRect(region, groupCornerRadius_, groupCornerRadius_);
- painter->fillPath(fillPath, backgroundBrush);
- painter->drawPath(linePath);
-
- int triangleHorizontalOffset = 1;
- int triangleWidth = 9;
- int triangleHeight = 5;
- paintExpansionTriangle(painter, region.adjusted(common_.horizontalMargin + triangleHorizontalOffset + 1, 0, 0, 0), triangleWidth, triangleHeight, expanded);
-
- int textLeftOffset = 3 * common_.horizontalMargin + 1 + triangleWidth + triangleHorizontalOffset;
- QFontMetrics fontMetrics(groupFont_);
- int textTopOffset = (region.height() - fontMetrics.height()) / 2;
- painter->setFont(groupFont_);
- int contactCountWidth = 0;
- QRect textRect = region.adjusted(textLeftOffset, textTopOffset, -1 * textLeftOffset, -1 * textTopOffset);
-
- if (!expanded) {
- QFontMetrics groupMetrics(groupFont_);
- int contactCount = rowCount;
- QString countString = QString("%1").arg(contactCount);
- contactCountWidth = groupMetrics.width(countString) + 2 * common_.horizontalMargin;
- int offsetAmount = textRect.width() - contactCountWidth + common_.horizontalMargin;
- QRect countRect = textRect.adjusted(offsetAmount, 0, 0/*-1 * offsetAmount*/, 0);
- paintShadowText(painter, countRect, countString);
- }
- QRect nameTextRect = expanded ? textRect : textRect.adjusted(0, 0, -contactCountWidth, 0);
- QString elidedName = fontMetrics.elidedText(name, Qt::ElideRight, nameTextRect.width(), Qt::TextShowMnemonic);
- paintShadowText(painter, nameTextRect, elidedName);
- painter->restore();
+ painter->save();
+ painter->setPen(QPen(QColor(189, 189, 189)));
+ //FIXME: It looks like Qt is passing us a rectangle that's too small
+ //This deliberately draws outside the lines, and we need to find a better solution.
+ int correctionAmount = groupCornerRadius_ > 0 ? 0 : 1;
+ QRect region(QPoint(option.rect.left() - correctionAmount, option.rect.top()), QSize(option.rect.width() + correctionAmount, option.rect.height() - common_.verticalMargin));
+ QLinearGradient fillGradient(region.topLeft(), region.bottomLeft());
+ fillGradient.setColorAt(0, QColor(244, 244, 244));
+ fillGradient.setColorAt(0.1, QColor(231, 231, 231));
+ fillGradient.setColorAt(1, QColor(209, 209, 209));
+
+ QBrush backgroundBrush = QBrush(fillGradient);
+ QPainterPath fillPath;
+ fillPath.addRoundedRect(region, groupCornerRadius_, groupCornerRadius_);
+ QPainterPath linePath;
+ linePath.addRoundedRect(region, groupCornerRadius_, groupCornerRadius_);
+ painter->fillPath(fillPath, backgroundBrush);
+ painter->drawPath(linePath);
+
+ int triangleHorizontalOffset = 1;
+ int triangleWidth = 9;
+ int triangleHeight = 5;
+ paintExpansionTriangle(painter, region.adjusted(common_.horizontalMargin + triangleHorizontalOffset + 1, 0, 0, 0), triangleWidth, triangleHeight, expanded);
+
+ int textLeftOffset = 3 * common_.horizontalMargin + 1 + triangleWidth + triangleHorizontalOffset;
+ QFontMetrics fontMetrics(groupFont_);
+ int textTopOffset = (region.height() - fontMetrics.height()) / 2;
+ painter->setFont(groupFont_);
+ int contactCountWidth = 0;
+ QRect textRect = region.adjusted(textLeftOffset, textTopOffset, -1 * textLeftOffset, -1 * textTopOffset);
+
+ if (!expanded) {
+ QFontMetrics groupMetrics(groupFont_);
+ int contactCount = rowCount;
+ QString countString = QString("%1").arg(contactCount);
+ contactCountWidth = groupMetrics.width(countString) + 2 * common_.horizontalMargin;
+ int offsetAmount = textRect.width() - contactCountWidth + common_.horizontalMargin;
+ QRect countRect = textRect.adjusted(offsetAmount, 0, 0/*-1 * offsetAmount*/, 0);
+ paintShadowText(painter, countRect, countString);
+ }
+ QRect nameTextRect = expanded ? textRect : textRect.adjusted(0, 0, -contactCountWidth, 0);
+ QString elidedName = fontMetrics.elidedText(name, Qt::ElideRight, nameTextRect.width(), Qt::TextShowMnemonic);
+ paintShadowText(painter, nameTextRect, elidedName);
+ painter->restore();
}
void GroupItemDelegate::paintExpansionTriangle(QPainter* painter, const QRect& region, int width, int height, bool expanded) const {
- // height is the height of the downward pointing triangle
- QPolygonF triangle;
- if (expanded) {
- QPointF triangleTopLeft(region.left(), region.top() + region.height() / 2 - height / 2);
- triangle << triangleTopLeft;
- triangle << triangleTopLeft + QPointF(width, 0);
- triangle << triangleTopLeft + QPointF(width / 2, height);
- // The expanded triangle should be a little lower, because its pointy shape makes it feel
- // as if it's too high.
- triangle.translate(QPointF(0,1));
- }
- else {
- QPointF triangleTopLeft(region.left() + ((width - height) / 2), region.top() + region.height() / 2 - width / 2);
- triangle << triangleTopLeft;
- triangle << triangleTopLeft + QPointF(height, width / 2);
- triangle << triangleTopLeft + QPointF(0, width);
- }
- //qDebug() << "Painting triangle: " << triangle;
-
- QPolygonF triangleShadow(triangle);
- triangleShadow.translate(QPointF(0, -1));
-
- QPainterPath trianglePath;
- QPainterPath triangleShadowPath;
- QBrush triangleBrush(QColor(110, 110, 110));
- QBrush triangleShadowBrush(QColor(47, 47, 47));
- trianglePath.addPolygon(triangle);
- triangleShadowPath.addPolygon(triangleShadow);
- painter->fillPath(triangleShadowPath, triangleShadowBrush);
- painter->fillPath(trianglePath, triangleBrush);
+ // height is the height of the downward pointing triangle
+ QPolygonF triangle;
+ if (expanded) {
+ QPointF triangleTopLeft(region.left(), region.top() + region.height() / 2 - height / 2);
+ triangle << triangleTopLeft;
+ triangle << triangleTopLeft + QPointF(width, 0);
+ triangle << triangleTopLeft + QPointF(width / 2, height);
+ // The expanded triangle should be a little lower, because its pointy shape makes it feel
+ // as if it's too high.
+ triangle.translate(QPointF(0,1));
+ }
+ else {
+ QPointF triangleTopLeft(region.left() + ((width - height) / 2), region.top() + region.height() / 2 - width / 2);
+ triangle << triangleTopLeft;
+ triangle << triangleTopLeft + QPointF(height, width / 2);
+ triangle << triangleTopLeft + QPointF(0, width);
+ }
+ //qDebug() << "Painting triangle: " << triangle;
+
+ QPolygonF triangleShadow(triangle);
+ triangleShadow.translate(QPointF(0, -1));
+
+ QPainterPath trianglePath;
+ QPainterPath triangleShadowPath;
+ QBrush triangleBrush(QColor(110, 110, 110));
+ QBrush triangleShadowBrush(QColor(47, 47, 47));
+ trianglePath.addPolygon(triangle);
+ triangleShadowPath.addPolygon(triangleShadow);
+ painter->fillPath(triangleShadowPath, triangleShadowBrush);
+ painter->fillPath(trianglePath, triangleBrush);
}
void GroupItemDelegate::paintShadowText(QPainter* painter, const QRect& region, const QString& text) const {
- painter->setPen(QPen(QColor(254, 254, 254)));
- painter->drawText(region.adjusted(0, 1, 0, 0), Qt::AlignTop, text);
- painter->setPen(QPen(QColor(115, 115, 115)));
- painter->drawText(region, Qt::AlignTop, text);
+ painter->setPen(QPen(QColor(254, 254, 254)));
+ painter->drawText(region.adjusted(0, 1, 0, 0), Qt::AlignTop, text);
+ painter->setPen(QPen(QColor(115, 115, 115)));
+ painter->drawText(region, Qt::AlignTop, text);
}
const int GroupItemDelegate::groupCornerRadius_ = 0;
diff --git a/Swift/QtUI/Roster/GroupItemDelegate.h b/Swift/QtUI/Roster/GroupItemDelegate.h
index c279c79..f989ed0 100644
--- a/Swift/QtUI/Roster/GroupItemDelegate.h
+++ b/Swift/QtUI/Roster/GroupItemDelegate.h
@@ -13,17 +13,17 @@
#include <Swift/QtUI/Roster/DelegateCommons.h>
namespace Swift {
- class QtTreeWidgetItem;
- class GroupItemDelegate {
- public:
- GroupItemDelegate();
- QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
- void paint(QPainter* painter, const QStyleOptionViewItem& option, const QString& name, int rowCount, bool expanded) const;
- private:
- void paintShadowText(QPainter* painter, const QRect& region, const QString& text) const;
- void paintExpansionTriangle(QPainter* painter, const QRect& region, int width, int height, bool expanded) const;
- QFont groupFont_;
- static const int groupCornerRadius_;
- DelegateCommons common_;
- };
+ class QtTreeWidgetItem;
+ class GroupItemDelegate {
+ public:
+ GroupItemDelegate();
+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QString& name, int rowCount, bool expanded) const;
+ private:
+ void paintShadowText(QPainter* painter, const QRect& region, const QString& text) const;
+ void paintExpansionTriangle(QPainter* painter, const QRect& region, int width, int height, bool expanded) const;
+ QFont groupFont_;
+ static const int groupCornerRadius_;
+ DelegateCommons common_;
+ };
}
diff --git a/Swift/QtUI/Roster/QtFilterWidget.cpp b/Swift/QtUI/Roster/QtFilterWidget.cpp
index 24be214..60b87df 100644
--- a/Swift/QtUI/Roster/QtFilterWidget.cpp
+++ b/Swift/QtUI/Roster/QtFilterWidget.cpp
@@ -27,24 +27,24 @@
namespace Swift {
QtFilterWidget::QtFilterWidget(QWidget* parent, QtTreeWidget* treeView, UIEventStream* eventStream, QBoxLayout* layout) : QWidget(parent), treeView_(treeView), eventStream_(eventStream), fuzzyRosterFilter_(0), isModifierSinglePressed_(false) {
- int targetIndex = layout->indexOf(treeView);
+ int targetIndex = layout->indexOf(treeView);
- QVBoxLayout* vboxLayout = new QVBoxLayout(this);
- vboxLayout->setSpacing(0);
- vboxLayout->setContentsMargins(0,0,0,0);
+ QVBoxLayout* vboxLayout = new QVBoxLayout(this);
+ vboxLayout->setSpacing(0);
+ vboxLayout->setContentsMargins(0,0,0,0);
- filterLineEdit_ = new QtClosableLineEdit(this);
- filterLineEdit_->hide();
- vboxLayout->addWidget(filterLineEdit_);
+ filterLineEdit_ = new QtClosableLineEdit(this);
+ filterLineEdit_->hide();
+ vboxLayout->addWidget(filterLineEdit_);
- vboxLayout->addWidget(treeView);
- setLayout(vboxLayout);
- layout->insertWidget(targetIndex, this);
+ vboxLayout->addWidget(treeView);
+ setLayout(vboxLayout);
+ layout->insertWidget(targetIndex, this);
- filterLineEdit_->installEventFilter(this);
- treeView->installEventFilter(this);
+ filterLineEdit_->installEventFilter(this);
+ treeView->installEventFilter(this);
- sourceModel_ = treeView_->model();
+ sourceModel_ = treeView_->model();
}
QtFilterWidget::~QtFilterWidget() {
@@ -52,118 +52,118 @@ QtFilterWidget::~QtFilterWidget() {
}
bool QtFilterWidget::eventFilter(QObject*, QEvent* event) {
- if (event->type() == QEvent::KeyPress ||
- event->type() == QEvent::KeyRelease ||
- // InputMethodQuery got introduced in Qt 5.
+ if (event->type() == QEvent::KeyPress ||
+ event->type() == QEvent::KeyRelease ||
+ // InputMethodQuery got introduced in Qt 5.
#if QT_VERSION >= 0x050000
- event->type() == QEvent::InputMethodQuery ||
+ event->type() == QEvent::InputMethodQuery ||
#endif
- event->type() == QEvent::InputMethod) {
- event->ignore();
- QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
- if (keyEvent) {
- if (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down) {
- return false;
- } else if ((keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Right) && filterLineEdit_->text().isEmpty()) {
- return false;
- } else if (keyEvent->key() == Qt::Key_Alt && event->type() == QEvent::KeyPress) {
- isModifierSinglePressed_ = true;
- } else if ((keyEvent->key() == Qt::Key_Alt && event->type() == QEvent::KeyRelease && isModifierSinglePressed_)
- || (keyEvent->key() == Qt::Key_Menu)) {
- QPoint itemOffset(2,2);
- QPoint contextMenuPosition = treeView_->visualRect(treeView_->currentIndex()).topLeft() + itemOffset;;
- QApplication::postEvent(treeView_, new QContextMenuEvent(QContextMenuEvent::Keyboard, contextMenuPosition, treeView_->mapToGlobal(contextMenuPosition)));
- return true;
- } else if (keyEvent->key() == Qt::Key_Return) {
- JID target = treeView_->selectedJID();
- if (target.isValid()) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target)));
- }
- filterLineEdit_->setText("");
- updateRosterFilters();
- } else if (keyEvent->key() == Qt::Key_Escape) {
- filterLineEdit_->setText("");
- } else {
- isModifierSinglePressed_ = false;
- }
- }
-
- filterLineEdit_->event(event);
-
- if (event->type() == QEvent::KeyRelease) {
- updateRosterFilters();
- }
- return true;
- }
- return false;
+ event->type() == QEvent::InputMethod) {
+ event->ignore();
+ QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
+ if (keyEvent) {
+ if (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down) {
+ return false;
+ } else if ((keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Right) && filterLineEdit_->text().isEmpty()) {
+ return false;
+ } else if (keyEvent->key() == Qt::Key_Alt && event->type() == QEvent::KeyPress) {
+ isModifierSinglePressed_ = true;
+ } else if ((keyEvent->key() == Qt::Key_Alt && event->type() == QEvent::KeyRelease && isModifierSinglePressed_)
+ || (keyEvent->key() == Qt::Key_Menu)) {
+ QPoint itemOffset(2,2);
+ QPoint contextMenuPosition = treeView_->visualRect(treeView_->currentIndex()).topLeft() + itemOffset;;
+ QApplication::postEvent(treeView_, new QContextMenuEvent(QContextMenuEvent::Keyboard, contextMenuPosition, treeView_->mapToGlobal(contextMenuPosition)));
+ return true;
+ } else if (keyEvent->key() == Qt::Key_Return) {
+ JID target = treeView_->selectedJID();
+ if (target.isValid()) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target)));
+ }
+ filterLineEdit_->setText("");
+ updateRosterFilters();
+ } else if (keyEvent->key() == Qt::Key_Escape) {
+ filterLineEdit_->setText("");
+ } else {
+ isModifierSinglePressed_ = false;
+ }
+ }
+
+ filterLineEdit_->event(event);
+
+ if (event->type() == QEvent::KeyRelease) {
+ updateRosterFilters();
+ }
+ return true;
+ }
+ return false;
}
void QtFilterWidget::popAllFilters() {
- std::vector<RosterFilter*> filters = treeView_->getRoster()->getFilters();
- foreach(RosterFilter* filter, filters) {
- filters_.push_back(filter);
- treeView_->getRoster()->removeFilter(filter);
- }
- treeView_->getRoster()->onFilterAdded.connect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
- treeView_->getRoster()->onFilterRemoved.connect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
+ std::vector<RosterFilter*> filters = treeView_->getRoster()->getFilters();
+ foreach(RosterFilter* filter, filters) {
+ filters_.push_back(filter);
+ treeView_->getRoster()->removeFilter(filter);
+ }
+ treeView_->getRoster()->onFilterAdded.connect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
+ treeView_->getRoster()->onFilterRemoved.connect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
}
void QtFilterWidget::pushAllFilters() {
- treeView_->getRoster()->onFilterAdded.disconnect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
- treeView_->getRoster()->onFilterRemoved.disconnect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
- foreach(RosterFilter* filter, filters_) {
- treeView_->getRoster()->addFilter(filter);
- }
- filters_.clear();
+ treeView_->getRoster()->onFilterAdded.disconnect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
+ treeView_->getRoster()->onFilterRemoved.disconnect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
+ foreach(RosterFilter* filter, filters_) {
+ treeView_->getRoster()->addFilter(filter);
+ }
+ filters_.clear();
}
void QtFilterWidget::updateRosterFilters() {
- if (fuzzyRosterFilter_) {
- if (filterLineEdit_->text().isEmpty()) {
- // remove currently installed search filter and put old filters back
- treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
- delete fuzzyRosterFilter_;
- fuzzyRosterFilter_ = NULL;
- pushAllFilters();
- } else {
- // remove currently intsalled search filter and put new search filter in place
- updateSearchFilter();
- }
- } else {
- if (!filterLineEdit_->text().isEmpty()) {
- // remove currently installed filters and put a search filter in place
- popAllFilters();
- updateSearchFilter();
- }
- }
- filterLineEdit_->setVisible(!filterLineEdit_->text().isEmpty());
+ if (fuzzyRosterFilter_) {
+ if (filterLineEdit_->text().isEmpty()) {
+ // remove currently installed search filter and put old filters back
+ treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
+ delete fuzzyRosterFilter_;
+ fuzzyRosterFilter_ = NULL;
+ pushAllFilters();
+ } else {
+ // remove currently intsalled search filter and put new search filter in place
+ updateSearchFilter();
+ }
+ } else {
+ if (!filterLineEdit_->text().isEmpty()) {
+ // remove currently installed filters and put a search filter in place
+ popAllFilters();
+ updateSearchFilter();
+ }
+ }
+ filterLineEdit_->setVisible(!filterLineEdit_->text().isEmpty());
}
void QtFilterWidget::updateSearchFilter() {
- if (fuzzyRosterFilter_) {
- treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
- delete fuzzyRosterFilter_;
- fuzzyRosterFilter_ = NULL;
- }
- fuzzyRosterFilter_ = new FuzzyRosterFilter(Q2PSTRING(filterLineEdit_->text()));
- treeView_->getRoster()->addFilter(fuzzyRosterFilter_);
- treeView_->setCurrentIndex(sourceModel_->index(0, 0, sourceModel_->index(0,0)));
+ if (fuzzyRosterFilter_) {
+ treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
+ delete fuzzyRosterFilter_;
+ fuzzyRosterFilter_ = NULL;
+ }
+ fuzzyRosterFilter_ = new FuzzyRosterFilter(Q2PSTRING(filterLineEdit_->text()));
+ treeView_->getRoster()->addFilter(fuzzyRosterFilter_);
+ treeView_->setCurrentIndex(sourceModel_->index(0, 0, sourceModel_->index(0,0)));
}
void QtFilterWidget::handleFilterAdded(RosterFilter* filter) {
- if (filter != fuzzyRosterFilter_) {
- filterLineEdit_->setText("");
- updateRosterFilters();
- }
+ if (filter != fuzzyRosterFilter_) {
+ filterLineEdit_->setText("");
+ updateRosterFilters();
+ }
}
void QtFilterWidget::handleFilterRemoved(RosterFilter* filter) {
- /* make sure we don't end up adding this one back in later */
- filters_.erase(std::remove(filters_.begin(), filters_.end(), filter), filters_.end());
- if (filter != fuzzyRosterFilter_) {
- filterLineEdit_->setText("");
- updateRosterFilters();
- }
+ /* make sure we don't end up adding this one back in later */
+ filters_.erase(std::remove(filters_.begin(), filters_.end(), filter), filters_.end());
+ if (filter != fuzzyRosterFilter_) {
+ filterLineEdit_->setText("");
+ updateRosterFilters();
+ }
}
}
diff --git a/Swift/QtUI/Roster/QtFilterWidget.h b/Swift/QtUI/Roster/QtFilterWidget.h
index 314aec2..5edcc5b 100644
--- a/Swift/QtUI/Roster/QtFilterWidget.h
+++ b/Swift/QtUI/Roster/QtFilterWidget.h
@@ -26,32 +26,32 @@ namespace Swift {
class UIEventStream;
class QtClosableLineEdit;
class QtFilterWidget : public QWidget {
- Q_OBJECT
- public:
- QtFilterWidget(QWidget* parent, QtTreeWidget* treeView, UIEventStream* eventStream, QBoxLayout* layout = 0);
- virtual ~QtFilterWidget();
-
- protected:
- bool eventFilter(QObject*, QEvent* event);
-
- private:
- void popAllFilters();
- void pushAllFilters();
-
- void updateRosterFilters();
- void updateSearchFilter();
-
- void handleFilterAdded(RosterFilter* filter);
- void handleFilterRemoved(RosterFilter* filter);
-
- private:
- QtClosableLineEdit* filterLineEdit_;
- QtTreeWidget* treeView_;
- UIEventStream* eventStream_;
- std::vector<RosterFilter*> filters_;
- QAbstractItemModel* sourceModel_;
- FuzzyRosterFilter* fuzzyRosterFilter_;
- bool isModifierSinglePressed_;
+ Q_OBJECT
+ public:
+ QtFilterWidget(QWidget* parent, QtTreeWidget* treeView, UIEventStream* eventStream, QBoxLayout* layout = 0);
+ virtual ~QtFilterWidget();
+
+ protected:
+ bool eventFilter(QObject*, QEvent* event);
+
+ private:
+ void popAllFilters();
+ void pushAllFilters();
+
+ void updateRosterFilters();
+ void updateSearchFilter();
+
+ void handleFilterAdded(RosterFilter* filter);
+ void handleFilterRemoved(RosterFilter* filter);
+
+ private:
+ QtClosableLineEdit* filterLineEdit_;
+ QtTreeWidget* treeView_;
+ UIEventStream* eventStream_;
+ std::vector<RosterFilter*> filters_;
+ QAbstractItemModel* sourceModel_;
+ FuzzyRosterFilter* fuzzyRosterFilter_;
+ bool isModifierSinglePressed_;
};
}
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.cpp b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
index 1eefd56..03c14fd 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.cpp
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
@@ -29,47 +29,47 @@ QtOccupantListWidget::~QtOccupantListWidget() {
}
void QtOccupantListWidget::setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions) {
- availableOccupantActions_ = actions;
+ availableOccupantActions_ = actions;
}
void QtOccupantListWidget::contextMenuEvent(QContextMenuEvent* event) {
- QModelIndex index = indexAt(event->pos());
- if (!index.isValid()) {
- return;
- }
+ QModelIndex index = indexAt(event->pos());
+ if (!index.isValid()) {
+ return;
+ }
- RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact) {
- onSomethingSelectedChanged(contact);
- QMenu contextMenu;
- if (availableOccupantActions_.empty()) {
- QAction* noAction = contextMenu.addAction(tr("No actions for this user"));
- noAction->setEnabled(false);
- contextMenu.exec(event->globalPos());
- }
- else {
- std::map<QAction*, ChatWindow::OccupantAction> actions;
- foreach (ChatWindow::OccupantAction availableAction, availableOccupantActions_) {
- QString text = "Error: missing string";
- switch (availableAction) {
- case ChatWindow::Kick: text = tr("Kick user"); break;
- case ChatWindow::Ban: text = tr("Kick and ban user"); break;
- case ChatWindow::MakeModerator: text = tr("Make moderator"); break;
- case ChatWindow::MakeParticipant: text = tr("Make participant"); break;
- case ChatWindow::MakeVisitor: text = tr("Remove voice"); break;
- case ChatWindow::AddContact: text = tr("Add to contacts"); break;
- case ChatWindow::ShowProfile: text = tr("Show profile"); break;
- }
- QAction* action = contextMenu.addAction(text);
- actions[action] = availableAction;
- }
- QAction* result = contextMenu.exec(event->globalPos());
- if (result) {
- onOccupantActionSelected(actions[result], contact);
- }
- }
- }
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact) {
+ onSomethingSelectedChanged(contact);
+ QMenu contextMenu;
+ if (availableOccupantActions_.empty()) {
+ QAction* noAction = contextMenu.addAction(tr("No actions for this user"));
+ noAction->setEnabled(false);
+ contextMenu.exec(event->globalPos());
+ }
+ else {
+ std::map<QAction*, ChatWindow::OccupantAction> actions;
+ foreach (ChatWindow::OccupantAction availableAction, availableOccupantActions_) {
+ QString text = "Error: missing string";
+ switch (availableAction) {
+ case ChatWindow::Kick: text = tr("Kick user"); break;
+ case ChatWindow::Ban: text = tr("Kick and ban user"); break;
+ case ChatWindow::MakeModerator: text = tr("Make moderator"); break;
+ case ChatWindow::MakeParticipant: text = tr("Make participant"); break;
+ case ChatWindow::MakeVisitor: text = tr("Remove voice"); break;
+ case ChatWindow::AddContact: text = tr("Add to contacts"); break;
+ case ChatWindow::ShowProfile: text = tr("Show profile"); break;
+ }
+ QAction* action = contextMenu.addAction(text);
+ actions[action] = availableAction;
+ }
+ QAction* result = contextMenu.exec(event->globalPos());
+ if (result) {
+ onOccupantActionSelected(actions[result], contact);
+ }
+ }
+ }
}
}
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.h b/Swift/QtUI/Roster/QtOccupantListWidget.h
index d433d07..4cff50f 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.h
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.h
@@ -16,16 +16,16 @@ namespace Swift {
class SettingsProvider;
class QtOccupantListWidget : public QtTreeWidget {
- Q_OBJECT
- public:
- QtOccupantListWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget privateMessageTarget, QWidget* parent = NULL);
- virtual ~QtOccupantListWidget();
- void setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions);
- boost::signal<void (ChatWindow::OccupantAction, ContactRosterItem*)> onOccupantActionSelected;
- protected:
- void contextMenuEvent(QContextMenuEvent* event);
- private:
- std::vector<ChatWindow::OccupantAction> availableOccupantActions_;
+ Q_OBJECT
+ public:
+ QtOccupantListWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget privateMessageTarget, QWidget* parent = NULL);
+ virtual ~QtOccupantListWidget();
+ void setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions);
+ boost::signal<void (ChatWindow::OccupantAction, ContactRosterItem*)> onOccupantActionSelected;
+ protected:
+ void contextMenuEvent(QContextMenuEvent* event);
+ private:
+ std::vector<ChatWindow::OccupantAction> availableOccupantActions_;
};
}
diff --git a/Swift/QtUI/Roster/QtRosterWidget.cpp b/Swift/QtUI/Roster/QtRosterWidget.cpp
index 469fa83..027ff00 100644
--- a/Swift/QtUI/Roster/QtRosterWidget.cpp
+++ b/Swift/QtUI/Roster/QtRosterWidget.cpp
@@ -38,125 +38,125 @@ QtRosterWidget::~QtRosterWidget() {
}
void QtRosterWidget::handleEditUserActionTriggered(bool /*checked*/) {
- QModelIndexList selectedIndexList = getSelectedIndexes();
- if (selectedIndexList.empty()) {
- return;
- }
- QModelIndex index = selectedIndexList[0];
- if (!index.isValid()) {
- return;
- }
- RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
- if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
- eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID()));
- }
+ QModelIndexList selectedIndexList = getSelectedIndexes();
+ if (selectedIndexList.empty()) {
+ return;
+ }
+ QModelIndex index = selectedIndexList[0];
+ if (!index.isValid()) {
+ return;
+ }
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
+ eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID()));
+ }
}
void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) {
- QModelIndex index = indexAt(event->pos());
- if (!index.isValid()) {
- return;
- }
- RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
- QMenu contextMenu;
- if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
- QAction* editContact = contextMenu.addAction(tr("Edit…"));
- editContact->setEnabled(isOnline());
- QAction* removeContact = contextMenu.addAction(tr("Remove"));
- removeContact->setEnabled(isOnline());
- QAction* showProfileForContact = contextMenu.addAction(tr("Show Profile"));
-
- QAction* unblockContact = NULL;
- if (contact->blockState() == ContactRosterItem::IsBlocked ||
- contact->blockState() == ContactRosterItem::IsDomainBlocked) {
- unblockContact = contextMenu.addAction(tr("Unblock"));
- unblockContact->setEnabled(isOnline());
- }
-
- QAction* blockContact = NULL;
- if (contact->blockState() == ContactRosterItem::IsUnblocked) {
- blockContact = contextMenu.addAction(tr("Block"));
- blockContact->setEnabled(isOnline());
- }
+ QModelIndex index = indexAt(event->pos());
+ if (!index.isValid()) {
+ return;
+ }
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ QMenu contextMenu;
+ if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
+ QAction* editContact = contextMenu.addAction(tr("Edit…"));
+ editContact->setEnabled(isOnline());
+ QAction* removeContact = contextMenu.addAction(tr("Remove"));
+ removeContact->setEnabled(isOnline());
+ QAction* showProfileForContact = contextMenu.addAction(tr("Show Profile"));
+
+ QAction* unblockContact = NULL;
+ if (contact->blockState() == ContactRosterItem::IsBlocked ||
+ contact->blockState() == ContactRosterItem::IsDomainBlocked) {
+ unblockContact = contextMenu.addAction(tr("Unblock"));
+ unblockContact->setEnabled(isOnline());
+ }
+
+ QAction* blockContact = NULL;
+ if (contact->blockState() == ContactRosterItem::IsUnblocked) {
+ blockContact = contextMenu.addAction(tr("Block"));
+ blockContact->setEnabled(isOnline());
+ }
#ifdef SWIFT_EXPERIMENTAL_FT
- QAction* sendFile = NULL;
- if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
- sendFile = contextMenu.addAction(tr("Send File"));
- sendFile->setEnabled(isOnline());
- }
+ QAction* sendFile = NULL;
+ if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
+ sendFile = contextMenu.addAction(tr("Send File"));
+ sendFile->setEnabled(isOnline());
+ }
#endif
#ifdef SWIFT_EXPERIMENTAL_WB
- QAction* startWhiteboardChat = NULL;
- if (contact->supportsFeature(ContactRosterItem::WhiteboardFeature)) {
- startWhiteboardChat = contextMenu.addAction(tr("Start Whiteboard Chat"));
- startWhiteboardChat->setEnabled(isOnline());
- }
+ QAction* startWhiteboardChat = NULL;
+ if (contact->supportsFeature(ContactRosterItem::WhiteboardFeature)) {
+ startWhiteboardChat = contextMenu.addAction(tr("Start Whiteboard Chat"));
+ startWhiteboardChat->setEnabled(isOnline());
+ }
#endif
- QAction* result = contextMenu.exec(event->globalPos());
- if (result == editContact) {
- eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID()));
- }
- else if (result == removeContact) {
- if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) {
- eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID()));
- }
- }
- else if (result == showProfileForContact) {
- eventStream_->send(boost::make_shared<ShowProfileForRosterItemUIEvent>(contact->getJID()));
- }
- else if (unblockContact && result == unblockContact) {
- if (contact->blockState() == ContactRosterItem::IsDomainBlocked) {
- QMessageBox messageBox(QMessageBox::Question, tr("Swift"), tr("%2 is currently blocked because of a block on all users of the %1 service.\n %2 cannot be unblocked individually; do you want to unblock all %1 users?").arg(P2QSTRING(contact->getJID().getDomain()), P2QSTRING(contact->getJID().toString())), QMessageBox::NoButton, this);
- QPushButton* unblockDomainButton = messageBox.addButton(tr("Unblock %1 domain").arg(P2QSTRING(contact->getJID().getDomain())), QMessageBox::AcceptRole);
- messageBox.addButton(QMessageBox::Abort);
-
- messageBox.exec();
- if (messageBox.clickedButton() == unblockDomainButton) {
- eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, contact->getJID().getDomain()));
- }
- } else {
- eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, contact->getJID()));
- }
- }
- else if (blockContact && result == blockContact) {
- eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Blocked, contact->getJID()));
- }
+ QAction* result = contextMenu.exec(event->globalPos());
+ if (result == editContact) {
+ eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID()));
+ }
+ else if (result == removeContact) {
+ if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) {
+ eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID()));
+ }
+ }
+ else if (result == showProfileForContact) {
+ eventStream_->send(boost::make_shared<ShowProfileForRosterItemUIEvent>(contact->getJID()));
+ }
+ else if (unblockContact && result == unblockContact) {
+ if (contact->blockState() == ContactRosterItem::IsDomainBlocked) {
+ QMessageBox messageBox(QMessageBox::Question, tr("Swift"), tr("%2 is currently blocked because of a block on all users of the %1 service.\n %2 cannot be unblocked individually; do you want to unblock all %1 users?").arg(P2QSTRING(contact->getJID().getDomain()), P2QSTRING(contact->getJID().toString())), QMessageBox::NoButton, this);
+ QPushButton* unblockDomainButton = messageBox.addButton(tr("Unblock %1 domain").arg(P2QSTRING(contact->getJID().getDomain())), QMessageBox::AcceptRole);
+ messageBox.addButton(QMessageBox::Abort);
+
+ messageBox.exec();
+ if (messageBox.clickedButton() == unblockDomainButton) {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, contact->getJID().getDomain()));
+ }
+ } else {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, contact->getJID()));
+ }
+ }
+ else if (blockContact && result == blockContact) {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Blocked, contact->getJID()));
+ }
#ifdef SWIFT_EXPERIMENTAL_FT
- else if (sendFile && result == sendFile) {
- QString fileName = QFileDialog::getOpenFileName(this, tr("Send File"), "", tr("All Files (*);;"));
- if (!fileName.isEmpty()) {
- eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(fileName)));
- }
- }
+ else if (sendFile && result == sendFile) {
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Send File"), "", tr("All Files (*);;"));
+ if (!fileName.isEmpty()) {
+ eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(fileName)));
+ }
+ }
#endif
#ifdef SWIFT_EXPERIMENTAL_WB
- else if (startWhiteboardChat && result == startWhiteboardChat) {
- eventStream_->send(boost::make_shared<RequestWhiteboardUIEvent>(contact->getJID()));
- }
+ else if (startWhiteboardChat && result == startWhiteboardChat) {
+ eventStream_->send(boost::make_shared<RequestWhiteboardUIEvent>(contact->getJID()));
+ }
#endif
- }
- else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) {
- QAction* renameGroupAction = contextMenu.addAction(tr("Rename"));
- if (P2QSTRING(group->getDisplayName()) == tr("Contacts")) {
- renameGroupAction->setEnabled(false);
- }
- else {
- renameGroupAction->setEnabled(isOnline());
- }
- QAction* result = contextMenu.exec(event->globalPos());
- if (result == renameGroupAction) {
- renameGroup(group);
- }
- }
+ }
+ else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) {
+ QAction* renameGroupAction = contextMenu.addAction(tr("Rename"));
+ if (P2QSTRING(group->getDisplayName()) == tr("Contacts")) {
+ renameGroupAction->setEnabled(false);
+ }
+ else {
+ renameGroupAction->setEnabled(isOnline());
+ }
+ QAction* result = contextMenu.exec(event->globalPos());
+ if (result == renameGroupAction) {
+ renameGroup(group);
+ }
+ }
}
void QtRosterWidget::renameGroup(GroupRosterItem* group) {
- bool ok;
- QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("Enter a new name for group '%1':").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok);
- if (ok) {
- eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName)));
- }
+ bool ok;
+ QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("Enter a new name for group '%1':").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok);
+ if (ok) {
+ eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName)));
+ }
}
}
diff --git a/Swift/QtUI/Roster/QtRosterWidget.h b/Swift/QtUI/Roster/QtRosterWidget.h
index de5ee9b..25f7f9d 100644
--- a/Swift/QtUI/Roster/QtRosterWidget.h
+++ b/Swift/QtUI/Roster/QtRosterWidget.h
@@ -12,16 +12,16 @@ namespace Swift {
class QtUIPreferences;
class QtRosterWidget : public QtTreeWidget {
- Q_OBJECT
- public:
- QtRosterWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent = 0);
- virtual ~QtRosterWidget();
- public slots:
- void handleEditUserActionTriggered(bool checked);
- protected:
- void contextMenuEvent(QContextMenuEvent* event);
- private:
- void renameGroup(GroupRosterItem* group);
+ Q_OBJECT
+ public:
+ QtRosterWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent = 0);
+ virtual ~QtRosterWidget();
+ public slots:
+ void handleEditUserActionTriggered(bool checked);
+ protected:
+ void contextMenuEvent(QContextMenuEvent* event);
+ private:
+ void renameGroup(GroupRosterItem* group);
};
}
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index 277effb..a0b6e92 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -32,232 +32,232 @@
namespace Swift {
QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget messageTarget, QWidget* parent) : QTreeView(parent), tooltipShown_(false), messageTarget_(messageTarget) {
- eventStream_ = eventStream;
- settings_ = settings;
- model_ = new RosterModel(this, settings_->getSetting(QtUISettingConstants::USE_SCREENREADER));
- setModel(model_);
- delegate_ = new RosterDelegate(this, settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
- setItemDelegate(delegate_);
- setHeaderHidden(true);
+ eventStream_ = eventStream;
+ settings_ = settings;
+ model_ = new RosterModel(this, settings_->getSetting(QtUISettingConstants::USE_SCREENREADER));
+ setModel(model_);
+ delegate_ = new RosterDelegate(this, settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ setItemDelegate(delegate_);
+ setHeaderHidden(true);
#ifdef SWIFT_PLATFORM_MACOSX
- setAlternatingRowColors(true);
+ setAlternatingRowColors(true);
#endif
- setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
- expandAll();
- setAnimated(true);
- setIndentation(0);
+ setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
+ expandAll();
+ setAnimated(true);
+ setIndentation(0);
#ifdef SWIFT_EXPERIMENTAL_FT
- setAcceptDrops(true);
+ setAcceptDrops(true);
#endif
- setDragEnabled(true);
- setRootIsDecorated(true);
- connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
- connect(model_, SIGNAL(itemExpanded(const QModelIndex&, bool)), this, SLOT(handleModelItemExpanded(const QModelIndex&, bool)));
- connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(handleExpanded(const QModelIndex&)));
- connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(handleCollapsed(const QModelIndex&)));
- connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&)));
-
- settings_->onSettingChanged.connect(boost::bind(&QtTreeWidget::handleSettingChanged, this, _1));
+ setDragEnabled(true);
+ setRootIsDecorated(true);
+ connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
+ connect(model_, SIGNAL(itemExpanded(const QModelIndex&, bool)), this, SLOT(handleModelItemExpanded(const QModelIndex&, bool)));
+ connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(handleExpanded(const QModelIndex&)));
+ connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(handleCollapsed(const QModelIndex&)));
+ connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&)));
+
+ settings_->onSettingChanged.connect(boost::bind(&QtTreeWidget::handleSettingChanged, this, _1));
}
QtTreeWidget::~QtTreeWidget() {
- settings_->onSettingChanged.disconnect(boost::bind(&QtTreeWidget::handleSettingChanged, this, _1));
- delete model_;
- delete delegate_;
+ settings_->onSettingChanged.disconnect(boost::bind(&QtTreeWidget::handleSettingChanged, this, _1));
+ delete model_;
+ delete delegate_;
}
void QtTreeWidget::handleSettingChanged(const std::string& setting) {
- if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
- delegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
- repaint();
- }
+ if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
+ delegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ repaint();
+ }
}
void QtTreeWidget::handleRefreshTooltip() {
- if (tooltipShown_) {
- QPoint position = QCursor::pos();
- QModelIndex index = indexAt(mapFromGlobal(position));
- QToolTip::showText(position, model_->data(index, Qt::ToolTipRole).toString());
- }
+ if (tooltipShown_) {
+ QPoint position = QCursor::pos();
+ QModelIndex index = indexAt(mapFromGlobal(position));
+ QToolTip::showText(position, model_->data(index, Qt::ToolTipRole).toString());
+ }
}
void QtTreeWidget::setRosterModel(Roster* roster) {
- roster_ = roster;
- model_->setRoster(roster);
- expandAll();
+ roster_ = roster;
+ model_->setRoster(roster);
+ expandAll();
}
void QtTreeWidget::refreshTooltip() {
- // Qt needs some time to emit the events we need to detect tooltip's visibility correctly; 20 ms should be enough
- QTimer::singleShot(20, this, SLOT(handleRefreshTooltip()));
+ // Qt needs some time to emit the events we need to detect tooltip's visibility correctly; 20 ms should be enough
+ QTimer::singleShot(20, this, SLOT(handleRefreshTooltip()));
}
QtTreeWidgetItem* QtTreeWidget::getRoot() {
- return treeRoot_;
+ return treeRoot_;
}
void QtTreeWidget::handleClicked(const QModelIndex& index) {
- GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer()));
- if (item) {
- setExpanded(index, !isExpanded(index));
- }
- currentChanged(index, QModelIndex());
+ GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer()));
+ if (item) {
+ setExpanded(index, !isExpanded(index));
+ }
+ currentChanged(index, QModelIndex());
}
QModelIndexList QtTreeWidget::getSelectedIndexes() const {
- // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the
- // QModelIndexList destructor.
- // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case
- // was resolved by linking against the debug libs, ours isn't, and we're not alone)
- QItemSelection ranges = selectionModel()->selection();
- QModelIndexList selectedIndexList;
- for (int i = 0; i < ranges.count(); ++i) {
- QModelIndex parent = ranges.at(i).parent();
- int right = ranges.at(i).model()->columnCount(parent) - 1;
- if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) {
- for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) {
- selectedIndexList.append(ranges.at(i).model()->index(r, 0, parent));
- }
- }
- }
- return selectedIndexList;
+ // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the
+ // QModelIndexList destructor.
+ // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case
+ // was resolved by linking against the debug libs, ours isn't, and we're not alone)
+ QItemSelection ranges = selectionModel()->selection();
+ QModelIndexList selectedIndexList;
+ for (int i = 0; i < ranges.count(); ++i) {
+ QModelIndex parent = ranges.at(i).parent();
+ int right = ranges.at(i).model()->columnCount(parent) - 1;
+ if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) {
+ for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) {
+ selectedIndexList.append(ranges.at(i).model()->index(r, 0, parent));
+ }
+ }
+ }
+ return selectedIndexList;
}
void QtTreeWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) {
- RosterItem* item = NULL;
- QModelIndexList selectedIndexList = getSelectedIndexes();
- if (selectedIndexList.empty() || !selectedIndexList[0].isValid()) {
- /* I didn't quite understand why using current didn't seem to work here.*/
- }
- else if (current.isValid()) {
- item = static_cast<RosterItem*>(current.internalPointer());
- item = dynamic_cast<ContactRosterItem*>(item);
- }
- onSomethingSelectedChanged(item);
- QTreeView::currentChanged(current, previous);
+ RosterItem* item = NULL;
+ QModelIndexList selectedIndexList = getSelectedIndexes();
+ if (selectedIndexList.empty() || !selectedIndexList[0].isValid()) {
+ /* I didn't quite understand why using current didn't seem to work here.*/
+ }
+ else if (current.isValid()) {
+ item = static_cast<RosterItem*>(current.internalPointer());
+ item = dynamic_cast<ContactRosterItem*>(item);
+ }
+ onSomethingSelectedChanged(item);
+ QTreeView::currentChanged(current, previous);
}
void QtTreeWidget::handleItemActivated(const QModelIndex& index) {
- JID target = jidFromIndex(index);
- if (target.isValid()) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target)));
- }
+ JID target = jidFromIndex(index);
+ if (target.isValid()) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target)));
+ }
}
void QtTreeWidget::dragEnterEvent(QDragEnterEvent *event) {
- if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
- event->acceptProposedAction();
- }
+ if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
+ event->acceptProposedAction();
+ }
}
void QtTreeWidget::dropEvent(QDropEvent *event) {
- QModelIndex index = indexAt(event->pos());
- if (index.isValid()) {
- RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
- if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
- if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
- QString filename = event->mimeData()->urls().at(0).toLocalFile();
- if (!filename.isEmpty()) {
- eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(filename)));
- }
- }
- }
- }
+ QModelIndex index = indexAt(event->pos());
+ if (index.isValid()) {
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
+ if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
+ QString filename = event->mimeData()->urls().at(0).toLocalFile();
+ if (!filename.isEmpty()) {
+ eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(filename)));
+ }
+ }
+ }
+ }
}
void QtTreeWidget::dragMoveEvent(QDragMoveEvent* event) {
- QModelIndex index = indexAt(event->pos());
- if (index.isValid()) {
- RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
- if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
- if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
- event->accept();
- return;
- }
- }
- }
- QTreeView::dragMoveEvent(event);
+ QModelIndex index = indexAt(event->pos());
+ if (index.isValid()) {
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
+ if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
+ event->accept();
+ return;
+ }
+ }
+ }
+ QTreeView::dragMoveEvent(event);
}
bool QtTreeWidget::event(QEvent* event) {
- QChildEvent* childEvent = NULL;
- if ((childEvent = dynamic_cast<QChildEvent*>(event))) {
- if (childEvent->polished()) {
- if (dynamic_cast<QLabel*>(childEvent->child())) {
- tooltipShown_ = true;
- }
- }
- else if (childEvent->removed()) {
- if (childEvent->child()->objectName() == "qtooltip_label") {
- tooltipShown_ = false;
- }
- }
- }
- return QAbstractItemView::event(event);
+ QChildEvent* childEvent = NULL;
+ if ((childEvent = dynamic_cast<QChildEvent*>(event))) {
+ if (childEvent->polished()) {
+ if (dynamic_cast<QLabel*>(childEvent->child())) {
+ tooltipShown_ = true;
+ }
+ }
+ else if (childEvent->removed()) {
+ if (childEvent->child()->objectName() == "qtooltip_label") {
+ tooltipShown_ = false;
+ }
+ }
+ }
+ return QAbstractItemView::event(event);
}
void QtTreeWidget::handleExpanded(const QModelIndex& index) {
- GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer()));
- if (item) {
- item->setExpanded(true);
- }
+ GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer()));
+ if (item) {
+ item->setExpanded(true);
+ }
}
void QtTreeWidget::handleCollapsed(const QModelIndex& index) {
- GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer()));
- if (item) {
- item->setExpanded(false);
- }
+ GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer()));
+ if (item) {
+ item->setExpanded(false);
+ }
}
void QtTreeWidget::handleModelItemExpanded(const QModelIndex& index, bool shouldExpand) {
- if (!index.isValid()) {
- return;
- }
- bool alreadyRight = this->isExpanded(index) == shouldExpand;
- if (alreadyRight) {
- return;
- }
- setExpanded(index, shouldExpand);
+ if (!index.isValid()) {
+ return;
+ }
+ bool alreadyRight = this->isExpanded(index) == shouldExpand;
+ if (alreadyRight) {
+ return;
+ }
+ setExpanded(index, shouldExpand);
}
void QtTreeWidget::drawBranches(QPainter*, const QRect&, const QModelIndex&) const {
}
void QtTreeWidget::show() {
- QWidget::show();
+ QWidget::show();
}
void QtTreeWidget::setMessageTarget(MessageTarget messageTarget) {
- messageTarget_ = messageTarget;
+ messageTarget_ = messageTarget;
}
JID QtTreeWidget::jidFromIndex(const QModelIndex& index) const {
- JID target;
- if (messageTarget_ == MessageDisplayJID) {
- target = JID(Q2PSTRING(index.data(DisplayJIDRole).toString()));
- target = target.toBare();
- }
- if (!target.isValid()) {
- target = JID(Q2PSTRING(index.data(JIDRole).toString()));
- }
- return target;
+ JID target;
+ if (messageTarget_ == MessageDisplayJID) {
+ target = JID(Q2PSTRING(index.data(DisplayJIDRole).toString()));
+ target = target.toBare();
+ }
+ if (!target.isValid()) {
+ target = JID(Q2PSTRING(index.data(JIDRole).toString()));
+ }
+ return target;
}
JID QtTreeWidget::selectedJID() const {
- QModelIndexList list = selectedIndexes();
- if (list.size() != 1) {
- return JID();
- }
- return jidFromIndex(list[0]);
+ QModelIndexList list = selectedIndexes();
+ if (list.size() != 1) {
+ return JID();
+ }
+ return jidFromIndex(list[0]);
}
void QtTreeWidget::setOnline(bool isOnline) {
- isOnline_ = isOnline;
+ isOnline_ = isOnline;
}
bool QtTreeWidget::isOnline() const {
- return isOnline_;
+ return isOnline_;
}
}
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index 205bc70..9a94e8f 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -22,59 +22,59 @@ class UIEventStream;
class SettingsProvider;
class QtTreeWidget : public QTreeView {
- Q_OBJECT
- public:
- enum MessageTarget {MessageDefaultJID, MessageDisplayJID};
+ Q_OBJECT
+ public:
+ enum MessageTarget {MessageDefaultJID, MessageDisplayJID};
- QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget messageTarget, QWidget* parent = 0);
- ~QtTreeWidget();
- void show();
- QtTreeWidgetItem* getRoot();
- void setRosterModel(Roster* roster);
- Roster* getRoster() {return roster_;}
- void refreshTooltip();
- void setMessageTarget(MessageTarget messageTarget);
- JID jidFromIndex(const QModelIndex& index) const;
- JID selectedJID() const;
- void setOnline(bool isOnline);
+ QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget messageTarget, QWidget* parent = 0);
+ ~QtTreeWidget();
+ void show();
+ QtTreeWidgetItem* getRoot();
+ void setRosterModel(Roster* roster);
+ Roster* getRoster() {return roster_;}
+ void refreshTooltip();
+ void setMessageTarget(MessageTarget messageTarget);
+ JID jidFromIndex(const QModelIndex& index) const;
+ JID selectedJID() const;
+ void setOnline(bool isOnline);
- public:
- boost::signal<void (RosterItem*)> onSomethingSelectedChanged;
+ public:
+ boost::signal<void (RosterItem*)> onSomethingSelectedChanged;
- private slots:
- void handleItemActivated(const QModelIndex&);
- void handleModelItemExpanded(const QModelIndex&, bool expanded);
- void handleExpanded(const QModelIndex&);
- void handleCollapsed(const QModelIndex&);
- void handleClicked(const QModelIndex&);
- void handleSettingChanged(const std::string& setting);
- void handleRefreshTooltip();
+ private slots:
+ void handleItemActivated(const QModelIndex&);
+ void handleModelItemExpanded(const QModelIndex&, bool expanded);
+ void handleExpanded(const QModelIndex&);
+ void handleCollapsed(const QModelIndex&);
+ void handleClicked(const QModelIndex&);
+ void handleSettingChanged(const std::string& setting);
+ void handleRefreshTooltip();
- protected:
- void dragEnterEvent(QDragEnterEvent* event);
- void dropEvent(QDropEvent* event);
- void dragMoveEvent(QDragMoveEvent* event);
- bool event(QEvent* event);
- QModelIndexList getSelectedIndexes() const;
- bool isOnline() const;
+ protected:
+ void dragEnterEvent(QDragEnterEvent* event);
+ void dropEvent(QDropEvent* event);
+ void dragMoveEvent(QDragMoveEvent* event);
+ bool event(QEvent* event);
+ QModelIndexList getSelectedIndexes() const;
+ bool isOnline() const;
- private:
- void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;
+ private:
+ void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;
- protected slots:
- virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
- protected:
- UIEventStream* eventStream_;
+ protected slots:
+ virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
+ protected:
+ UIEventStream* eventStream_;
- private:
- RosterModel* model_;
- Roster* roster_;
- RosterDelegate* delegate_;
- QtTreeWidgetItem* treeRoot_;
- SettingsProvider* settings_;
- bool tooltipShown_;
- MessageTarget messageTarget_;
- bool isOnline_;
+ private:
+ RosterModel* model_;
+ Roster* roster_;
+ RosterDelegate* delegate_;
+ QtTreeWidgetItem* treeRoot_;
+ SettingsProvider* settings_;
+ bool tooltipShown_;
+ MessageTarget messageTarget_;
+ bool isOnline_;
};
}
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp
index ff950e5..061982e 100644
--- a/Swift/QtUI/Roster/RosterDelegate.cpp
+++ b/Swift/QtUI/Roster/RosterDelegate.cpp
@@ -25,59 +25,59 @@
namespace Swift {
RosterDelegate::RosterDelegate(QtTreeWidget* tree, bool compact) : compact_(compact) {
- tree_ = tree;
- groupDelegate_ = new GroupItemDelegate();
+ tree_ = tree;
+ groupDelegate_ = new GroupItemDelegate();
}
RosterDelegate::~RosterDelegate() {
- delete groupDelegate_;
+ delete groupDelegate_;
}
void RosterDelegate::setCompact(bool compact) {
- compact_ = compact;
- emit sizeHintChanged(QModelIndex());
+ compact_ = compact;
+ emit sizeHintChanged(QModelIndex());
}
-
+
QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
- RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
- if (dynamic_cast<GroupRosterItem*>(item)) {
- return groupDelegate_->sizeHint(option, index);
- }
- return contactSizeHint(option, index);
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ if (dynamic_cast<GroupRosterItem*>(item)) {
+ return groupDelegate_->sizeHint(option, index);
+ }
+ return contactSizeHint(option, index);
}
QSize RosterDelegate::contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
- return common_.contactSizeHint(option, index, compact_);
+ return common_.contactSizeHint(option, index, compact_);
}
void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
- if (dynamic_cast<GroupRosterItem*>(item)) {
- paintGroup(painter, option, index);
- } else {
- paintContact(painter, option, index);
- }
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ if (dynamic_cast<GroupRosterItem*>(item)) {
+ paintGroup(painter, option, index);
+ } else {
+ paintContact(painter, option, index);
+ }
}
void RosterDelegate::paintGroup(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- if (index.isValid()) {
- groupDelegate_->paint(painter, option, index.data(Qt::DisplayRole).toString(), index.data(ChildCountRole).toInt(), tree_->isExpanded(index));
- }
+ if (index.isValid()) {
+ groupDelegate_->paint(painter, option, index.data(Qt::DisplayRole).toString(), index.data(ChildCountRole).toInt(), tree_->isExpanded(index));
+ }
}
void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
- QString avatarPath;
- if (index.data(AvatarRole).isValid() && !index.data(AvatarRole).value<QString>().isNull()) {
- avatarPath = index.data(AvatarRole).value<QString>();
- }
- QIcon presenceIcon = index.data(PresenceIconRole).isValid() && !index.data(PresenceIconRole).value<QIcon>().isNull()
- ? index.data(PresenceIconRole).value<QIcon>()
- : QIcon(":/icons/offline.png");
- bool isIdle = index.data(IdleRole).isValid() ? index.data(IdleRole).toBool() : false;
- QString name = index.data(Qt::DisplayRole).toString();
- QString statusText = index.data(StatusTextRole).toString();
- common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, isIdle, 0, compact_);
+ QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
+ QString avatarPath;
+ if (index.data(AvatarRole).isValid() && !index.data(AvatarRole).value<QString>().isNull()) {
+ avatarPath = index.data(AvatarRole).value<QString>();
+ }
+ QIcon presenceIcon = index.data(PresenceIconRole).isValid() && !index.data(PresenceIconRole).value<QIcon>().isNull()
+ ? index.data(PresenceIconRole).value<QIcon>()
+ : QIcon(":/icons/offline.png");
+ bool isIdle = index.data(IdleRole).isValid() ? index.data(IdleRole).toBool() : false;
+ QString name = index.data(Qt::DisplayRole).toString();
+ QString statusText = index.data(StatusTextRole).toString();
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, isIdle, 0, compact_);
}
}
diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h
index f17f9b8..34c1569 100644
--- a/Swift/QtUI/Roster/RosterDelegate.h
+++ b/Swift/QtUI/Roster/RosterDelegate.h
@@ -14,22 +14,22 @@
#include <Swift/QtUI/Roster/GroupItemDelegate.h>
namespace Swift {
- class QtTreeWidget;
- class RosterDelegate : public QStyledItemDelegate {
- public:
- RosterDelegate(QtTreeWidget* tree, bool compact);
- ~RosterDelegate();
- QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
- void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
- public slots:
- void setCompact(bool compact);
- private:
- QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
- void paintGroup(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
- void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
- bool compact_;
- DelegateCommons common_;
- GroupItemDelegate* groupDelegate_;
- QtTreeWidget* tree_;
- };
+ class QtTreeWidget;
+ class RosterDelegate : public QStyledItemDelegate {
+ public:
+ RosterDelegate(QtTreeWidget* tree, bool compact);
+ ~RosterDelegate();
+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ public slots:
+ void setCompact(bool compact);
+ private:
+ QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void paintGroup(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ bool compact_;
+ DelegateCommons common_;
+ GroupItemDelegate* groupDelegate_;
+ QtTreeWidget* tree_;
+ };
}
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
index 60e4aca..2b3759d 100644
--- a/Swift/QtUI/Roster/RosterModel.cpp
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -29,251 +29,251 @@
namespace Swift {
RosterModel::RosterModel(QtTreeWidget* view, bool screenReaderMode) : roster_(NULL), view_(view), screenReader_(screenReaderMode) {
- const int tooltipAvatarSize = 96; // maximal suggested size according to XEP-0153
- cachedImageScaler_ = new QtScaledAvatarCache(tooltipAvatarSize);
+ const int tooltipAvatarSize = 96; // maximal suggested size according to XEP-0153
+ cachedImageScaler_ = new QtScaledAvatarCache(tooltipAvatarSize);
}
RosterModel::~RosterModel() {
- delete cachedImageScaler_;
+ delete cachedImageScaler_;
}
void RosterModel::setRoster(Roster* roster) {
- roster_ = roster;
- if (roster_) {
- roster->onChildrenChanged.connect(boost::bind(&RosterModel::handleChildrenChanged, this, _1));
- roster->onDataChanged.connect(boost::bind(&RosterModel::handleDataChanged, this, _1));
- }
- reLayout();
+ roster_ = roster;
+ if (roster_) {
+ roster->onChildrenChanged.connect(boost::bind(&RosterModel::handleChildrenChanged, this, _1));
+ roster->onDataChanged.connect(boost::bind(&RosterModel::handleDataChanged, this, _1));
+ }
+ reLayout();
}
void RosterModel::reLayout() {
- //emit layoutChanged();
- beginResetModel();
- endResetModel(); // TODO: Not sure if this isn't too early?
- if (!roster_) {
- return;
- }
- foreach (RosterItem* item, roster_->getRoot()->getDisplayedChildren()) {
- GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(item);
- if (!child) continue;
- emit itemExpanded(index(child), child->isExpanded());
- }
+ //emit layoutChanged();
+ beginResetModel();
+ endResetModel(); // TODO: Not sure if this isn't too early?
+ if (!roster_) {
+ return;
+ }
+ foreach (RosterItem* item, roster_->getRoot()->getDisplayedChildren()) {
+ GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(item);
+ if (!child) continue;
+ emit itemExpanded(index(child), child->isExpanded());
+ }
}
void RosterModel::handleChildrenChanged(GroupRosterItem* /*group*/) {
- reLayout();
+ reLayout();
}
void RosterModel::handleDataChanged(RosterItem* item) {
- Q_ASSERT(item);
- QModelIndex modelIndex = index(item);
- if (modelIndex.isValid()) {
- emit dataChanged(modelIndex, modelIndex);
- view_->refreshTooltip();
- }
+ Q_ASSERT(item);
+ QModelIndex modelIndex = index(item);
+ if (modelIndex.isValid()) {
+ emit dataChanged(modelIndex, modelIndex);
+ view_->refreshTooltip();
+ }
}
Qt::ItemFlags RosterModel::flags(const QModelIndex& index) const {
- Qt::ItemFlags flags = QAbstractItemModel::flags(index);
- if (dynamic_cast<GroupRosterItem*>(getItem(index)) == NULL) {
- flags |= Qt::ItemIsDragEnabled;
- }
- return flags;
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ if (dynamic_cast<GroupRosterItem*>(getItem(index)) == NULL) {
+ flags |= Qt::ItemIsDragEnabled;
+ }
+ return flags;
}
int RosterModel::columnCount(const QModelIndex& /*parent*/) const {
- return 1;
+ return 1;
}
RosterItem* RosterModel::getItem(const QModelIndex& index) const {
- return index.isValid() ? static_cast<RosterItem*>(index.internalPointer()) : NULL;
+ return index.isValid() ? static_cast<RosterItem*>(index.internalPointer()) : NULL;
}
QVariant RosterModel::data(const QModelIndex& index, int role) const {
- RosterItem* item = getItem(index);
- if (!item) return QVariant();
-
- switch (role) {
- case Qt::DisplayRole: return getScreenReaderTextOr(item, P2QSTRING(item->getDisplayName()));
- case Qt::TextColorRole: return getTextColor(item);
- case Qt::BackgroundColorRole: return getBackgroundColor(item);
- case Qt::ToolTipRole: return getToolTip(item);
- case StatusTextRole: return getStatusText(item);
- case AvatarRole: return getAvatar(item);
- case PresenceIconRole: return getPresenceIcon(item);
- case ChildCountRole: return getChildCount(item);
- case IdleRole: return getIsIdle(item);
- case JIDRole: return getJID(item);
- case DisplayJIDRole: return getDisplayJID(item);
- default: return QVariant();
- }
+ RosterItem* item = getItem(index);
+ if (!item) return QVariant();
+
+ switch (role) {
+ case Qt::DisplayRole: return getScreenReaderTextOr(item, P2QSTRING(item->getDisplayName()));
+ case Qt::TextColorRole: return getTextColor(item);
+ case Qt::BackgroundColorRole: return getBackgroundColor(item);
+ case Qt::ToolTipRole: return getToolTip(item);
+ case StatusTextRole: return getStatusText(item);
+ case AvatarRole: return getAvatar(item);
+ case PresenceIconRole: return getPresenceIcon(item);
+ case ChildCountRole: return getChildCount(item);
+ case IdleRole: return getIsIdle(item);
+ case JIDRole: return getJID(item);
+ case DisplayJIDRole: return getDisplayJID(item);
+ default: return QVariant();
+ }
}
QString RosterModel::getScreenReaderTextOr(RosterItem* item, const QString& alternative) const {
- QString name = P2QSTRING(item->getDisplayName());
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact && screenReader_) {
- name += ": " + P2QSTRING(statusShowTypeToFriendlyName(contact->getStatusShow()));
- if (!contact->getStatusText().empty()) {
- name += " (" + P2QSTRING(contact->getStatusText()) + ")";
- }
- return name;
- }
- else {
- return alternative;
- }
+ QString name = P2QSTRING(item->getDisplayName());
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact && screenReader_) {
+ name += ": " + P2QSTRING(statusShowTypeToFriendlyName(contact->getStatusShow()));
+ if (!contact->getStatusText().empty()) {
+ name += " (" + P2QSTRING(contact->getStatusText()) + ")";
+ }
+ return name;
+ }
+ else {
+ return alternative;
+ }
}
int RosterModel::getChildCount(RosterItem* item) const {
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- return group ? group->getDisplayedChildren().size() : 0;
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
+ return group ? group->getDisplayedChildren().size() : 0;
}
bool RosterModel::getIsIdle(RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- return contact ? !contact->getIdleText().empty() : false;
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ return contact ? !contact->getIdleText().empty() : false;
}
QColor RosterModel::intToColor(int color) const {
- return QColor(
- ((color & 0xFF0000)>>16),
- ((color & 0xFF00)>>8),
- (color & 0xFF));
+ return QColor(
+ ((color & 0xFF0000)>>16),
+ ((color & 0xFF00)>>8),
+ (color & 0xFF));
}
QColor RosterModel::getTextColor(RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- int color = 0;
- if (contact) {
- switch (contact->getStatusShow()) {
- case StatusShow::Online: color = 0x000000; break;
- case StatusShow::Away: color = 0x336699; break;
- case StatusShow::XA: color = 0x336699; break;
- case StatusShow::FFC: color = 0x000000; break;
- case StatusShow::DND: color = 0x990000; break;
- case StatusShow::None: color = 0x7F7F7F;break;
- }
- }
- return intToColor(color);
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ int color = 0;
+ if (contact) {
+ switch (contact->getStatusShow()) {
+ case StatusShow::Online: color = 0x000000; break;
+ case StatusShow::Away: color = 0x336699; break;
+ case StatusShow::XA: color = 0x336699; break;
+ case StatusShow::FFC: color = 0x000000; break;
+ case StatusShow::DND: color = 0x990000; break;
+ case StatusShow::None: color = 0x7F7F7F;break;
+ }
+ }
+ return intToColor(color);
}
QColor RosterModel::getBackgroundColor(RosterItem* item) const {
- return dynamic_cast<ContactRosterItem*>(item) ? intToColor(0xFFFFFF) : intToColor(0x969696);
+ return dynamic_cast<ContactRosterItem*>(item) ? intToColor(0xFFFFFF) : intToColor(0x969696);
}
QString RosterModel::getToolTip(RosterItem* item) const {
- QString tip(P2QSTRING(item->getDisplayName()));
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact) {
- return RosterTooltip::buildDetailedTooltip(contact, cachedImageScaler_);
- }
- return tip;
+ QString tip(P2QSTRING(item->getDisplayName()));
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact) {
+ return RosterTooltip::buildDetailedTooltip(contact, cachedImageScaler_);
+ }
+ return tip;
}
QString RosterModel::getAvatar(RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (!contact) {
- return "";
- }
- return P2QSTRING(pathToString(contact->getAvatarPath()));
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (!contact) {
+ return "";
+ }
+ return P2QSTRING(pathToString(contact->getAvatarPath()));
}
QString RosterModel::getStatusText(RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (!contact) return "";
- return P2QSTRING(contact->getStatusText());
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (!contact) return "";
+ return P2QSTRING(contact->getStatusText());
}
QString RosterModel::getJID(RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- return contact ? P2QSTRING(contact->getJID().toString()) : QString();
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ return contact ? P2QSTRING(contact->getJID().toString()) : QString();
}
QString RosterModel::getDisplayJID(RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- QString result = contact ? P2QSTRING(contact->getDisplayJID().toString()) : QString();
- if (result.isEmpty()) {
- result = getJID(item);
- }
- return result;
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ QString result = contact ? P2QSTRING(contact->getDisplayJID().toString()) : QString();
+ if (result.isEmpty()) {
+ result = getJID(item);
+ }
+ return result;
}
QIcon RosterModel::getPresenceIcon(RosterItem* item) const {
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (!contact) return QIcon();
- if (contact->blockState() == ContactRosterItem::IsBlocked ||
- contact->blockState() == ContactRosterItem::IsDomainBlocked) {
- return QIcon(":/icons/stop.png");
- }
-
- return QIcon(statusShowTypeToIconPath(contact->getStatusShow()));
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (!contact) return QIcon();
+ if (contact->blockState() == ContactRosterItem::IsBlocked ||
+ contact->blockState() == ContactRosterItem::IsDomainBlocked) {
+ return QIcon(":/icons/stop.png");
+ }
+
+ return QIcon(statusShowTypeToIconPath(contact->getStatusShow()));
}
QModelIndex RosterModel::index(int row, int column, const QModelIndex& parent) const {
- if (!roster_) {
- return QModelIndex();
- }
- GroupRosterItem* parentItem;
- if (!parent.isValid()) {
- //top level
- parentItem = roster_->getRoot();
- } else {
- parentItem = dynamic_cast<GroupRosterItem*>(getItem(parent));
- if (!parentItem) return QModelIndex();
- }
- return static_cast<size_t>(row) < parentItem->getDisplayedChildren().size() ? createIndex(row, column, parentItem->getDisplayedChildren()[row]) : QModelIndex();
+ if (!roster_) {
+ return QModelIndex();
+ }
+ GroupRosterItem* parentItem;
+ if (!parent.isValid()) {
+ //top level
+ parentItem = roster_->getRoot();
+ } else {
+ parentItem = dynamic_cast<GroupRosterItem*>(getItem(parent));
+ if (!parentItem) return QModelIndex();
+ }
+ return static_cast<size_t>(row) < parentItem->getDisplayedChildren().size() ? createIndex(row, column, parentItem->getDisplayedChildren()[row]) : QModelIndex();
}
QModelIndex RosterModel::index(RosterItem* item) const {
- GroupRosterItem* parent = item->getParent();
- /* Recursive check that it's ok to create such an item
- Assuming there are more contacts in a group than groups in a
- group, this could save a decent chunk of search time at startup.*/
- if (parent == NULL || roster_ == NULL || (parent != roster_->getRoot() && !index(parent).isValid())) {
- return QModelIndex();
- }
- for (size_t i = 0; i < parent->getDisplayedChildren().size(); i++) {
- if (parent->getDisplayedChildren()[i] == item) {
- return createIndex(i, 0, item);
- }
- }
- return QModelIndex();
+ GroupRosterItem* parent = item->getParent();
+ /* Recursive check that it's ok to create such an item
+ Assuming there are more contacts in a group than groups in a
+ group, this could save a decent chunk of search time at startup.*/
+ if (parent == NULL || roster_ == NULL || (parent != roster_->getRoot() && !index(parent).isValid())) {
+ return QModelIndex();
+ }
+ for (size_t i = 0; i < parent->getDisplayedChildren().size(); i++) {
+ if (parent->getDisplayedChildren()[i] == item) {
+ return createIndex(i, 0, item);
+ }
+ }
+ return QModelIndex();
}
QModelIndex RosterModel::parent(const QModelIndex& child) const {
- if (!roster_ || !child.isValid()) {
- return QModelIndex();
- }
-
- GroupRosterItem* parent = getItem(child)->getParent();
- return (parent != roster_->getRoot()) ? index(parent) : QModelIndex();
+ if (!roster_ || !child.isValid()) {
+ return QModelIndex();
+ }
+
+ GroupRosterItem* parent = getItem(child)->getParent();
+ return (parent != roster_->getRoot()) ? index(parent) : QModelIndex();
}
int RosterModel::rowCount(const QModelIndex& parent) const {
- if (!roster_) return 0;
- RosterItem* item = parent.isValid() ? static_cast<RosterItem*>(parent.internalPointer()) : roster_->getRoot();
- Q_ASSERT(item);
- GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
- int count = group ? group->getDisplayedChildren().size() : 0;
-// qDebug() << "rowCount = " << count << " where parent.isValid() == " << parent.isValid() << ", group == " << (group ? P2QSTRING(group->getDisplayName()) : "*contact*");
- return count;
+ if (!roster_) return 0;
+ RosterItem* item = parent.isValid() ? static_cast<RosterItem*>(parent.internalPointer()) : roster_->getRoot();
+ Q_ASSERT(item);
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
+ int count = group ? group->getDisplayedChildren().size() : 0;
+// qDebug() << "rowCount = " << count << " where parent.isValid() == " << parent.isValid() << ", group == " << (group ? P2QSTRING(group->getDisplayName()) : "*contact*");
+ return count;
}
QMimeData* RosterModel::mimeData(const QModelIndexList& indexes) const {
- QMimeData* data = QAbstractItemModel::mimeData(indexes);
-
- ContactRosterItem *item = dynamic_cast<ContactRosterItem*>(getItem(indexes.first()));
- if (item == NULL) {
- return data;
- }
-
- /* only a single JID in this list */
- QByteArray itemData;
- QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- dataStream << P2QSTRING(item->getJID().toString());
- data->setData("application/vnd.swift.contact-jid-list", itemData);
- return data;
+ QMimeData* data = QAbstractItemModel::mimeData(indexes);
+
+ ContactRosterItem *item = dynamic_cast<ContactRosterItem*>(getItem(indexes.first()));
+ if (item == NULL) {
+ return data;
+ }
+
+ /* only a single JID in this list */
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+ dataStream << P2QSTRING(item->getJID().toString());
+ data->setData("application/vnd.swift.contact-jid-list", itemData);
+ return data;
}
}
diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h
index 47ed614..af0d43a 100644
--- a/Swift/QtUI/Roster/RosterModel.h
+++ b/Swift/QtUI/Roster/RosterModel.h
@@ -14,58 +14,58 @@
#include <Swift/QtUI/QtScaledAvatarCache.h>
namespace Swift {
- enum RosterRoles {
- StatusTextRole = Qt::UserRole,
- AvatarRole = Qt::UserRole + 1,
- PresenceIconRole = Qt::UserRole + 2,
- StatusShowTypeRole = Qt::UserRole + 3,
- ChildCountRole = Qt::UserRole + 4,
- IdleRole = Qt::UserRole + 5,
- JIDRole = Qt::UserRole + 6,
- DisplayJIDRole = Qt::UserRole + 7
- };
+ enum RosterRoles {
+ StatusTextRole = Qt::UserRole,
+ AvatarRole = Qt::UserRole + 1,
+ PresenceIconRole = Qt::UserRole + 2,
+ StatusShowTypeRole = Qt::UserRole + 3,
+ ChildCountRole = Qt::UserRole + 4,
+ IdleRole = Qt::UserRole + 5,
+ JIDRole = Qt::UserRole + 6,
+ DisplayJIDRole = Qt::UserRole + 7
+ };
- class QtTreeWidget;
+ class QtTreeWidget;
- class RosterModel : public QAbstractItemModel {
- Q_OBJECT
- public:
- RosterModel(QtTreeWidget* view, bool screenReaderMode);
- ~RosterModel();
- void setRoster(Roster* swiftRoster);
- Qt::ItemFlags flags(const QModelIndex& index) const;
- int columnCount(const QModelIndex& parent = QModelIndex()) const;
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
- QModelIndex index(RosterItem* item) const;
- QModelIndex parent(const QModelIndex& index) const;
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
- QMimeData* mimeData(const QModelIndexList& indexes) const;
+ class RosterModel : public QAbstractItemModel {
+ Q_OBJECT
+ public:
+ RosterModel(QtTreeWidget* view, bool screenReaderMode);
+ ~RosterModel();
+ void setRoster(Roster* swiftRoster);
+ Qt::ItemFlags flags(const QModelIndex& index) const;
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
+ QModelIndex index(RosterItem* item) const;
+ QModelIndex parent(const QModelIndex& index) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ QMimeData* mimeData(const QModelIndexList& indexes) const;
- signals:
- void itemExpanded(const QModelIndex& item, bool expanded);
- private:
- void handleDataChanged(RosterItem* item);
- void handleChildrenChanged(GroupRosterItem* item);
- RosterItem* getItem(const QModelIndex& index) const;
- QColor intToColor(int color) const;
- QColor getTextColor(RosterItem* item) const;
- QColor getBackgroundColor(RosterItem* item) const;
- QString getToolTip(RosterItem* item) const;
- QString getAvatar(RosterItem* item) const;
- QString getStatusText(RosterItem* item) const;
- QString getJID(RosterItem* item) const;
- QString getDisplayJID(RosterItem* item) const;
- QIcon getPresenceIcon(RosterItem* item) const;
- int getChildCount(RosterItem* item) const;
- bool getIsIdle(RosterItem* item) const;
- void reLayout();
- /** calculates screenreader-friendly text if in screenreader mode, otherwise uses alternative text */
- QString getScreenReaderTextOr(RosterItem* item, const QString& alternative) const;
- private:
- Roster* roster_;
- QtTreeWidget* view_;
- QtScaledAvatarCache* cachedImageScaler_;
- bool screenReader_;
- };
+ signals:
+ void itemExpanded(const QModelIndex& item, bool expanded);
+ private:
+ void handleDataChanged(RosterItem* item);
+ void handleChildrenChanged(GroupRosterItem* item);
+ RosterItem* getItem(const QModelIndex& index) const;
+ QColor intToColor(int color) const;
+ QColor getTextColor(RosterItem* item) const;
+ QColor getBackgroundColor(RosterItem* item) const;
+ QString getToolTip(RosterItem* item) const;
+ QString getAvatar(RosterItem* item) const;
+ QString getStatusText(RosterItem* item) const;
+ QString getJID(RosterItem* item) const;
+ QString getDisplayJID(RosterItem* item) const;
+ QIcon getPresenceIcon(RosterItem* item) const;
+ int getChildCount(RosterItem* item) const;
+ bool getIsIdle(RosterItem* item) const;
+ void reLayout();
+ /** calculates screenreader-friendly text if in screenreader mode, otherwise uses alternative text */
+ QString getScreenReaderTextOr(RosterItem* item, const QString& alternative) const;
+ private:
+ Roster* roster_;
+ QtTreeWidget* view_;
+ QtScaledAvatarCache* cachedImageScaler_;
+ bool screenReader_;
+ };
}
diff --git a/Swift/QtUI/Roster/RosterTooltip.cpp b/Swift/QtUI/Roster/RosterTooltip.cpp
index e4a5626..d151628 100644
--- a/Swift/QtUI/Roster/RosterTooltip.cpp
+++ b/Swift/QtUI/Roster/RosterTooltip.cpp
@@ -31,142 +31,142 @@ using namespace QtUtilities;
namespace Swift {
QString RosterTooltip::buildDetailedTooltip(ContactRosterItem* contact, QtScaledAvatarCache* cachedImageScaler) {
- QString tooltipTemplate;
- if (QApplication::layoutDirection() == Qt::RightToLeft) {
- tooltipTemplate = QString(
- "<table style='white-space:pre'>"
- "<tr>"
- "<td>"
- "<img src=\"%1\" />"
- "</td>"
- "<td>"
- "<p style='font-size: 14px'>%3 %2</p>"
- "<table><tr><td valign='middle'>%5</td><td valign='middle'>%4</td></tr></table>"
- "%6"
- "%7"
- "%8"
- "%9"
- "</td>"
- "</tr>"
- "</table>");
- } else {
- tooltipTemplate = QString(
- "<table style='white-space:pre'>"
- "<tr>"
- "<td>"
- "<img src=\"%1\" />"
- "</td>"
- "<td>"
- "<p style='font-size: 14px'>%2 %3</p>"
- "<table><tr><td valign='middle'>%4</td><td valign='middle'>%5</td></tr></table>"
- "%6"
- "%7"
- "%8"
- "%9"
- "</td>"
- "</tr>"
- "</table>");
- }
- // prepare tooltip
- QString fullName = P2QSTRING(contact->getDisplayName());
-
- QString vCardSummary;
- VCard::ref vCard = contact->getVCard();
- if (vCard) {
- fullName = P2QSTRING(vCard->getFullName()).trimmed();
- if (fullName.isEmpty()) {
- fullName = (P2QSTRING(vCard->getGivenName()) + " " + P2QSTRING(vCard->getFamilyName())).trimmed();
- }
- if (fullName.isEmpty()) {
- fullName = P2QSTRING(contact->getDisplayName());
- }
- vCardSummary = buildVCardSummary(vCard);
- } else {
- contact->onVCardRequested();
- }
-
- QString scaledAvatarPath = cachedImageScaler->getScaledAvatarPath(P2QSTRING(contact->getAvatarPath().empty() ? ":/icons/avatar.png" : pathToString(contact->getAvatarPath())));
-
- QString bareJID = contact->getDisplayJID().toString().empty() ? "" : "( " + P2QSTRING(contact->getDisplayJID().toString()) + " )";
-
- QString presenceIconTag = QString("<img src='%1' />").arg(statusShowTypeToIconPath(contact->getStatusShow()));
-
- QString statusMessage = contact->getStatusText().empty() ? QObject::tr("(No message)") : P2QSTRING(contact->getStatusText());
-
- QString idleString = P2QSTRING(contact->getIdleText());
- if (!idleString.isEmpty()) {
- idleString = QObject::tr("Idle since %1").arg(idleString);
- idleString = htmlEscape(idleString) + "<br/>";
- }
-
- QString lastSeen = P2QSTRING(contact->getOfflineSinceText());
- if (!lastSeen.isEmpty()) {
- lastSeen = QObject::tr("Last seen %1").arg(lastSeen);
- lastSeen = htmlEscape(lastSeen) + "<br/>";
- }
-
- QString mucOccupant= P2QSTRING(contact->getMUCAffiliationText());
- if (!mucOccupant.isEmpty()) {
- mucOccupant = htmlEscape(mucOccupant) + "<br/>";
- }
-
- return tooltipTemplate.arg(scaledAvatarPath, htmlEscape(fullName), htmlEscape(bareJID), presenceIconTag, htmlEscape(statusMessage), mucOccupant, idleString, lastSeen, vCardSummary);
+ QString tooltipTemplate;
+ if (QApplication::layoutDirection() == Qt::RightToLeft) {
+ tooltipTemplate = QString(
+ "<table style='white-space:pre'>"
+ "<tr>"
+ "<td>"
+ "<img src=\"%1\" />"
+ "</td>"
+ "<td>"
+ "<p style='font-size: 14px'>%3 %2</p>"
+ "<table><tr><td valign='middle'>%5</td><td valign='middle'>%4</td></tr></table>"
+ "%6"
+ "%7"
+ "%8"
+ "%9"
+ "</td>"
+ "</tr>"
+ "</table>");
+ } else {
+ tooltipTemplate = QString(
+ "<table style='white-space:pre'>"
+ "<tr>"
+ "<td>"
+ "<img src=\"%1\" />"
+ "</td>"
+ "<td>"
+ "<p style='font-size: 14px'>%2 %3</p>"
+ "<table><tr><td valign='middle'>%4</td><td valign='middle'>%5</td></tr></table>"
+ "%6"
+ "%7"
+ "%8"
+ "%9"
+ "</td>"
+ "</tr>"
+ "</table>");
+ }
+ // prepare tooltip
+ QString fullName = P2QSTRING(contact->getDisplayName());
+
+ QString vCardSummary;
+ VCard::ref vCard = contact->getVCard();
+ if (vCard) {
+ fullName = P2QSTRING(vCard->getFullName()).trimmed();
+ if (fullName.isEmpty()) {
+ fullName = (P2QSTRING(vCard->getGivenName()) + " " + P2QSTRING(vCard->getFamilyName())).trimmed();
+ }
+ if (fullName.isEmpty()) {
+ fullName = P2QSTRING(contact->getDisplayName());
+ }
+ vCardSummary = buildVCardSummary(vCard);
+ } else {
+ contact->onVCardRequested();
+ }
+
+ QString scaledAvatarPath = cachedImageScaler->getScaledAvatarPath(P2QSTRING(contact->getAvatarPath().empty() ? ":/icons/avatar.png" : pathToString(contact->getAvatarPath())));
+
+ QString bareJID = contact->getDisplayJID().toString().empty() ? "" : "( " + P2QSTRING(contact->getDisplayJID().toString()) + " )";
+
+ QString presenceIconTag = QString("<img src='%1' />").arg(statusShowTypeToIconPath(contact->getStatusShow()));
+
+ QString statusMessage = contact->getStatusText().empty() ? QObject::tr("(No message)") : P2QSTRING(contact->getStatusText());
+
+ QString idleString = P2QSTRING(contact->getIdleText());
+ if (!idleString.isEmpty()) {
+ idleString = QObject::tr("Idle since %1").arg(idleString);
+ idleString = htmlEscape(idleString) + "<br/>";
+ }
+
+ QString lastSeen = P2QSTRING(contact->getOfflineSinceText());
+ if (!lastSeen.isEmpty()) {
+ lastSeen = QObject::tr("Last seen %1").arg(lastSeen);
+ lastSeen = htmlEscape(lastSeen) + "<br/>";
+ }
+
+ QString mucOccupant= P2QSTRING(contact->getMUCAffiliationText());
+ if (!mucOccupant.isEmpty()) {
+ mucOccupant = htmlEscape(mucOccupant) + "<br/>";
+ }
+
+ return tooltipTemplate.arg(scaledAvatarPath, htmlEscape(fullName), htmlEscape(bareJID), presenceIconTag, htmlEscape(statusMessage), mucOccupant, idleString, lastSeen, vCardSummary);
}
QString RosterTooltip::buildVCardSummary(VCard::ref vcard) {
- QString summary;
- summary = "<table>";
-
- // star | name | content
- QString currentBlock;
- foreach (const VCard::Telephone& tel, vcard->getTelephones()) {
- QString type = tel.isFax ? QObject::tr("Fax") : QObject::tr("Telephone");
- QString field = buildVCardField(tel.isPreferred, type, htmlEscape(P2QSTRING(tel.number)));
- if (tel.isPreferred) {
- currentBlock = field;
- break;
- }
- currentBlock += field;
- }
- summary += currentBlock;
-
- currentBlock = "";
- foreach (const VCard::EMailAddress& mail, vcard->getEMailAddresses()) {
- QString field = buildVCardField(mail.isPreferred, QObject::tr("E-Mail"), htmlEscape(P2QSTRING(mail.address)));
- if (mail.isPreferred) {
- currentBlock = field;
- break;
- }
- currentBlock += field;
- }
- summary += currentBlock;
-
- currentBlock = "";
- foreach (const VCard::Organization& org, vcard->getOrganizations()) {
- QString field = buildVCardField(false, QObject::tr("Organization"), htmlEscape(P2QSTRING(org.name)));
- currentBlock += field;
- }
- summary += currentBlock;
-
- currentBlock = "";
- foreach(const std::string& title, vcard->getTitles()) {
- QString field = buildVCardField(false, QObject::tr("Title"), htmlEscape(P2QSTRING(title)));
- currentBlock += field;
- }
- summary += currentBlock;
-
- summary += "</table>";
- return summary;
+ QString summary;
+ summary = "<table>";
+
+ // star | name | content
+ QString currentBlock;
+ foreach (const VCard::Telephone& tel, vcard->getTelephones()) {
+ QString type = tel.isFax ? QObject::tr("Fax") : QObject::tr("Telephone");
+ QString field = buildVCardField(tel.isPreferred, type, htmlEscape(P2QSTRING(tel.number)));
+ if (tel.isPreferred) {
+ currentBlock = field;
+ break;
+ }
+ currentBlock += field;
+ }
+ summary += currentBlock;
+
+ currentBlock = "";
+ foreach (const VCard::EMailAddress& mail, vcard->getEMailAddresses()) {
+ QString field = buildVCardField(mail.isPreferred, QObject::tr("E-Mail"), htmlEscape(P2QSTRING(mail.address)));
+ if (mail.isPreferred) {
+ currentBlock = field;
+ break;
+ }
+ currentBlock += field;
+ }
+ summary += currentBlock;
+
+ currentBlock = "";
+ foreach (const VCard::Organization& org, vcard->getOrganizations()) {
+ QString field = buildVCardField(false, QObject::tr("Organization"), htmlEscape(P2QSTRING(org.name)));
+ currentBlock += field;
+ }
+ summary += currentBlock;
+
+ currentBlock = "";
+ foreach(const std::string& title, vcard->getTitles()) {
+ QString field = buildVCardField(false, QObject::tr("Title"), htmlEscape(P2QSTRING(title)));
+ currentBlock += field;
+ }
+ summary += currentBlock;
+
+ summary += "</table>";
+ return summary;
}
QString RosterTooltip::buildVCardField(bool preferred, const QString& name, const QString& content) {
- QString rowTemplate;
- if (QApplication::layoutDirection() == Qt::RightToLeft) {
- rowTemplate = QString("<tr><td>%3</td><td valign='middle'><strong>%2</strong></td><td valign='middle'>%1</td></tr>");
- } else {
- rowTemplate = QString("<tr><td>%1</td><td valign='middle'><strong>%2</strong></td><td valign='middle'>%3</td></tr>");
- }
- return rowTemplate.arg(preferred ? "<img src=':/icons/star-checked.png' />" : "", name, content);
+ QString rowTemplate;
+ if (QApplication::layoutDirection() == Qt::RightToLeft) {
+ rowTemplate = QString("<tr><td>%3</td><td valign='middle'><strong>%2</strong></td><td valign='middle'>%1</td></tr>");
+ } else {
+ rowTemplate = QString("<tr><td>%1</td><td valign='middle'><strong>%2</strong></td><td valign='middle'>%3</td></tr>");
+ }
+ return rowTemplate.arg(preferred ? "<img src=':/icons/star-checked.png' />" : "", name, content);
}
}
diff --git a/Swift/QtUI/Roster/RosterTooltip.h b/Swift/QtUI/Roster/RosterTooltip.h
index 37f5da2..642809f 100644
--- a/Swift/QtUI/Roster/RosterTooltip.h
+++ b/Swift/QtUI/Roster/RosterTooltip.h
@@ -16,12 +16,12 @@ class ContactRosterItem;
class QtScaledAvatarCache;
class RosterTooltip {
- public:
- static QString buildDetailedTooltip(ContactRosterItem* contact, QtScaledAvatarCache* cachedImageScaler);
+ public:
+ static QString buildDetailedTooltip(ContactRosterItem* contact, QtScaledAvatarCache* cachedImageScaler);
- private:
- static QString buildVCardSummary(VCard::ref vcard);
- static QString buildVCardField(bool preferred, const QString& name, const QString& content);
+ private:
+ static QString buildVCardSummary(VCard::ref vcard);
+ static QString buildVCardField(bool preferred, const QString& name, const QString& content);
};
}
diff --git a/Swift/QtUI/Roster/main.cpp b/Swift/QtUI/Roster/main.cpp
index 078fcaf..c0402e8 100644
--- a/Swift/QtUI/Roster/main.cpp
+++ b/Swift/QtUI/Roster/main.cpp
@@ -13,55 +13,55 @@
int main(int argc, char *argv[])
{
- QApplication app(argc, argv);
+ QApplication app(argc, argv);
- //Swift::RosterModel model;
+ //Swift::RosterModel model;
- //QTreeView view;
- //view.setModel(&model);
- //view.setWindowTitle("A roster");
- //view.show();
+ //QTreeView view;
+ //view.setModel(&model);
+ //view.setWindowTitle("A roster");
+ //view.show();
- Swift::QtTreeWidgetFactory treeWidgetFactory;
- Swift::QtTreeWidget* tree = dynamic_cast<Swift::QtTreeWidget*>(treeWidgetFactory.createTreeWidget());
- tree->show();
- QList<Swift::QtTreeWidgetItem*> item3s;
- for (int i = 0; i < 500; i++) {
- Swift::QtTreeWidgetItem* group = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(tree));
- group->setText("People");
- group->setBackgroundColor(0xBBBBBB);
- Swift::QtTreeWidgetItem* item1 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
- Swift::QtTreeWidgetItem* item2 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
- Swift::QtTreeWidgetItem* item3 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
- Swift::QtTreeWidgetItem* item4 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
- item1->setText("Remko");
- item2->setText("Kevin");
- item3->setText("Cath");
- item4->setText("KimTypo");
- item4->setText("Kim");
- item3s.push_back(item3);
- }
-
- Swift::QtTreeWidgetItem* group = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(tree));
- group->setText("Many People");
-
- Swift::QtTreeWidgetItem* person350;
- Swift::QtTreeWidgetItem* person1200;
+ Swift::QtTreeWidgetFactory treeWidgetFactory;
+ Swift::QtTreeWidget* tree = dynamic_cast<Swift::QtTreeWidget*>(treeWidgetFactory.createTreeWidget());
+ tree->show();
+ QList<Swift::QtTreeWidgetItem*> item3s;
+ for (int i = 0; i < 500; i++) {
+ Swift::QtTreeWidgetItem* group = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(tree));
+ group->setText("People");
+ group->setBackgroundColor(0xBBBBBB);
+ Swift::QtTreeWidgetItem* item1 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ Swift::QtTreeWidgetItem* item2 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ Swift::QtTreeWidgetItem* item3 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ Swift::QtTreeWidgetItem* item4 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ item1->setText("Remko");
+ item2->setText("Kevin");
+ item3->setText("Cath");
+ item4->setText("KimTypo");
+ item4->setText("Kim");
+ item3s.push_back(item3);
+ }
- for (int i = 0; i < 1500; i++) {
- Swift::QtTreeWidgetItem* item = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
- item->setText(Q2PSTRING(QString("Some person %1").arg(i)));
- item->setStatusShow(Swift::StatusShow::Away);
- if (i == 350) person350 = item;
- if (i == 1200) person1200 = item;
- }
+ Swift::QtTreeWidgetItem* group = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(tree));
+ group->setText("Many People");
- for (int i = 0; i < item3s.size(); i++) {
- item3s[i]->setStatusShow(Swift::StatusShow::XA);
- }
+ Swift::QtTreeWidgetItem* person350;
+ Swift::QtTreeWidgetItem* person1200;
- person350->setStatusShow(Swift::StatusShow::DND);
- person1200->setStatusShow(Swift::StatusShow::Online);
+ for (int i = 0; i < 1500; i++) {
+ Swift::QtTreeWidgetItem* item = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ item->setText(Q2PSTRING(QString("Some person %1").arg(i)));
+ item->setStatusShow(Swift::StatusShow::Away);
+ if (i == 350) person350 = item;
+ if (i == 1200) person1200 = item;
+ }
- return app.exec();
+ for (int i = 0; i < item3s.size(); i++) {
+ item3s[i]->setStatusShow(Swift::StatusShow::XA);
+ }
+
+ person350->setStatusShow(Swift::StatusShow::DND);
+ person1200->setStatusShow(Swift::StatusShow::Online);
+
+ return app.exec();
}
diff --git a/Swift/QtUI/SystemMessageSnippet.cpp b/Swift/QtUI/SystemMessageSnippet.cpp
index 87c17b1..fbf8810 100644
--- a/Swift/QtUI/SystemMessageSnippet.cpp
+++ b/Swift/QtUI/SystemMessageSnippet.cpp
@@ -11,16 +11,16 @@
namespace Swift {
SystemMessageSnippet::SystemMessageSnippet(const QString& message, const QDateTime& time, bool appendToPrevious, QtChatTheme* theme, const QString& id, Direction direction) : ChatSnippet(appendToPrevious) {
- if (appendToPrevious) {
- setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(message, time, false, theme, id, direction)));
- }
- content_ = theme->getStatus();
-
- content_.replace("%direction%", directionToCSS(direction));
- content_.replace("%message%", wrapResizable("<span class='swift_message'>" + escape(message) + "</span>"));
- content_.replace("%shortTime%", wrapResizable(escape(time.toString("h:mm"))));
- content_.replace("%time%", wrapResizable("<span class='swift_time'>" + timeToEscapedString(time) + "</span>"));
- content_.replace("%id%", id);
+ if (appendToPrevious) {
+ setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(message, time, false, theme, id, direction)));
+ }
+ content_ = theme->getStatus();
+
+ content_.replace("%direction%", directionToCSS(direction));
+ content_.replace("%message%", wrapResizable("<span class='swift_message'>" + escape(message) + "</span>"));
+ content_.replace("%shortTime%", wrapResizable(escape(time.toString("h:mm"))));
+ content_.replace("%time%", wrapResizable("<span class='swift_time'>" + timeToEscapedString(time) + "</span>"));
+ content_.replace("%id%", id);
}
SystemMessageSnippet::~SystemMessageSnippet() {
diff --git a/Swift/QtUI/SystemMessageSnippet.h b/Swift/QtUI/SystemMessageSnippet.h
index a1f2682..c0d4d2f 100644
--- a/Swift/QtUI/SystemMessageSnippet.h
+++ b/Swift/QtUI/SystemMessageSnippet.h
@@ -13,18 +13,18 @@
class QDateTime;
namespace Swift {
- class SystemMessageSnippet : public ChatSnippet {
- public:
- SystemMessageSnippet(const QString& message, const QDateTime& time, bool appendToPrevious, QtChatTheme* theme, const QString& id, Direction direction);
- virtual ~SystemMessageSnippet();
+ class SystemMessageSnippet : public ChatSnippet {
+ public:
+ SystemMessageSnippet(const QString& message, const QDateTime& time, bool appendToPrevious, QtChatTheme* theme, const QString& id, Direction direction);
+ virtual ~SystemMessageSnippet();
- const QString& getContent() const {return content_;}
+ const QString& getContent() const {return content_;}
- /*QString getContinuationElementID() const {
- return "insert";
- };*/
+ /*QString getContinuationElementID() const {
+ return "insert";
+ };*/
- private:
- QString content_;
- };
+ private:
+ QString content_;
+ };
}
diff --git a/Swift/QtUI/Trellis/QtDNDTabBar.cpp b/Swift/QtUI/Trellis/QtDNDTabBar.cpp
index dbe397b..fac2233 100644
--- a/Swift/QtUI/Trellis/QtDNDTabBar.cpp
+++ b/Swift/QtUI/Trellis/QtDNDTabBar.cpp
@@ -18,12 +18,12 @@
namespace Swift {
QtDNDTabBar::QtDNDTabBar(QWidget* parent) : QTabBar(parent) {
- setAcceptDrops(true);
+ setAcceptDrops(true);
- // detect the default tab bar height;
- insertTab(0, "");
- defaultTabHeight = QTabBar::sizeHint().height();
- removeTab(0);
+ // detect the default tab bar height;
+ insertTab(0, "");
+ defaultTabHeight = QTabBar::sizeHint().height();
+ removeTab(0);
}
QtDNDTabBar::~QtDNDTabBar() {
@@ -31,136 +31,136 @@ QtDNDTabBar::~QtDNDTabBar() {
}
int QtDNDTabBar::getDragIndex() const {
- return dragIndex;
+ return dragIndex;
}
QString QtDNDTabBar::getDragText() const {
- return dragText;
+ return dragText;
}
QWidget* QtDNDTabBar::getDragWidget() const {
- return dragWidget;
+ return dragWidget;
}
QSize QtDNDTabBar::sizeHint() const {
- QSize hint = QTabBar::sizeHint();
- if (hint.isEmpty()) {
- hint = QSize(parentWidget()->width(), defaultTabHeight);
- }
- return hint;
+ QSize hint = QTabBar::sizeHint();
+ if (hint.isEmpty()) {
+ hint = QSize(parentWidget()->width(), defaultTabHeight);
+ }
+ return hint;
}
QSize QtDNDTabBar::tabSizeHint(int index) const {
- QSize tabSize = QTabBar::tabSizeHint(index);
+ QSize tabSize = QTabBar::tabSizeHint(index);
#if defined(Q_OS_MAC)
- // With multiple tabs having the same label in a QTabBar, the size hint computed by
- // Qt on OS X is too small and it is elided even though there is enough horizontal
- // space available. We work around this issue by adding the width of a letter to the
- // size hint.
- tabSize += QSize(QFontMetrics(font()).width("I"), 0);
+ // With multiple tabs having the same label in a QTabBar, the size hint computed by
+ // Qt on OS X is too small and it is elided even though there is enough horizontal
+ // space available. We work around this issue by adding the width of a letter to the
+ // size hint.
+ tabSize += QSize(QFontMetrics(font()).width("I"), 0);
#endif
- return tabSize;
+ return tabSize;
}
void QtDNDTabBar::dragEnterEvent(QDragEnterEvent* dragEnterEvent) {
- QtDNDTabBar* sourceTabBar = dynamic_cast<QtDNDTabBar*>(dragEnterEvent->source());
- if (sourceTabBar) {
- dragEnterEvent->acceptProposedAction();
- }
+ QtDNDTabBar* sourceTabBar = dynamic_cast<QtDNDTabBar*>(dragEnterEvent->source());
+ if (sourceTabBar) {
+ dragEnterEvent->acceptProposedAction();
+ }
}
void QtDNDTabBar::dropEvent(QDropEvent* dropEvent) {
- QtDNDTabBar* sourceTabBar = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
- if (sourceTabBar && dropEvent->mimeData() && dropEvent->mimeData()->data("action") == QByteArray("application/tab-detach")) {
- QtDNDTabBar* source = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
-
- int targetTabIndex = tabAt(dropEvent->pos());
- QRect rect = tabRect(targetTabIndex);
- if (targetTabIndex >= 0 && (dropEvent->pos().x() - rect.left() - rect.width()/2 > 0)) {
- targetTabIndex++;
- }
-
- QWidget* tab = source->getDragWidget();
- assert(tab);
- QTabWidget* targetTabWidget = dynamic_cast<QTabWidget*>(parentWidget());
-
- QString tabText = source->getDragText();
-
- /*
- * When you add a widget to an empty QTabWidget, it's automatically made the current widget.
- * Making the widget the current widget, widget->show() is called for the widget. Directly reacting
- * to that event, and adding the widget again to the QTabWidget results in undefined behavior. For
- * example the tab label is shown but the widget is neither has the old nor in the new QTabWidget as
- * parent. Blocking signals on the QWidget to be added to a QTabWidget prevents this behavior.
- */
- targetTabWidget->setUpdatesEnabled(false);
- tab->blockSignals(true);
- targetTabWidget->insertTab(targetTabIndex, tab, tabText);
- dropEvent->acceptProposedAction();
- tab->blockSignals(false);
- targetTabWidget->setUpdatesEnabled(true);
- onDropSucceeded();
- }
+ QtDNDTabBar* sourceTabBar = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
+ if (sourceTabBar && dropEvent->mimeData() && dropEvent->mimeData()->data("action") == QByteArray("application/tab-detach")) {
+ QtDNDTabBar* source = dynamic_cast<QtDNDTabBar*>(dropEvent->source());
+
+ int targetTabIndex = tabAt(dropEvent->pos());
+ QRect rect = tabRect(targetTabIndex);
+ if (targetTabIndex >= 0 && (dropEvent->pos().x() - rect.left() - rect.width()/2 > 0)) {
+ targetTabIndex++;
+ }
+
+ QWidget* tab = source->getDragWidget();
+ assert(tab);
+ QTabWidget* targetTabWidget = dynamic_cast<QTabWidget*>(parentWidget());
+
+ QString tabText = source->getDragText();
+
+ /*
+ * When you add a widget to an empty QTabWidget, it's automatically made the current widget.
+ * Making the widget the current widget, widget->show() is called for the widget. Directly reacting
+ * to that event, and adding the widget again to the QTabWidget results in undefined behavior. For
+ * example the tab label is shown but the widget is neither has the old nor in the new QTabWidget as
+ * parent. Blocking signals on the QWidget to be added to a QTabWidget prevents this behavior.
+ */
+ targetTabWidget->setUpdatesEnabled(false);
+ tab->blockSignals(true);
+ targetTabWidget->insertTab(targetTabIndex, tab, tabText);
+ dropEvent->acceptProposedAction();
+ tab->blockSignals(false);
+ targetTabWidget->setUpdatesEnabled(true);
+ onDropSucceeded();
+ }
}
bool QtDNDTabBar::event(QEvent* event) {
- QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
- if (mouseEvent) {
- QWidget* childAtPoint = window()->childAt(mapTo(window(), mouseEvent->pos()));
- QtDNDTabBar* underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint);
- if (!underMouse && childAtPoint) {
- underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint->parent());
- }
- if (!underMouse && currentIndex() >= 0) {
- // detach and drag
-
- // stop move event
- QMouseEvent* finishMoveEvent = new QMouseEvent (QEvent::MouseMove, mouseEvent->pos (), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
- QTabBar::event(finishMoveEvent);
- delete finishMoveEvent;
- finishMoveEvent = NULL;
-
- // start drag
- QDrag* drag = new QDrag(this);
- QMimeData* mimeData = new QMimeData;
-
- // distinguish tab-reordering drops from other ones
- mimeData->setData("action", "application/tab-detach") ;
- drag->setMimeData(mimeData);
-
- // set drag image
- QRect rect = tabRect( currentIndex() );
+ QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
+ if (mouseEvent) {
+ QWidget* childAtPoint = window()->childAt(mapTo(window(), mouseEvent->pos()));
+ QtDNDTabBar* underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint);
+ if (!underMouse && childAtPoint) {
+ underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint->parent());
+ }
+ if (!underMouse && currentIndex() >= 0) {
+ // detach and drag
+
+ // stop move event
+ QMouseEvent* finishMoveEvent = new QMouseEvent (QEvent::MouseMove, mouseEvent->pos (), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
+ QTabBar::event(finishMoveEvent);
+ delete finishMoveEvent;
+ finishMoveEvent = NULL;
+
+ // start drag
+ QDrag* drag = new QDrag(this);
+ QMimeData* mimeData = new QMimeData;
+
+ // distinguish tab-reordering drops from other ones
+ mimeData->setData("action", "application/tab-detach") ;
+ drag->setMimeData(mimeData);
+
+ // set drag image
+ QRect rect = tabRect( currentIndex() );
#if QT_VERSION >= 0x050000
- QPixmap pixmap = grab(rect);
+ QPixmap pixmap = grab(rect);
#else
- QPixmap pixmap = QPixmap::grabWidget(this, rect);
+ QPixmap pixmap = QPixmap::grabWidget(this, rect);
#endif
- QPixmap targetPixmap (pixmap.size ());
- QPainter painter (&targetPixmap);
- painter.setOpacity(0.9);
- painter.drawPixmap(0,0, pixmap);
- painter.end ();
- drag->setPixmap (targetPixmap);
-
- drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()));
-
- dragIndex = currentIndex();
- dragText = tabText(dragIndex);
- dragWidget = dynamic_cast<QTabWidget*>(parent())->widget(dragIndex);
- assert(dragWidget);
- dynamic_cast<QTabWidget*>(parent())->removeTab(currentIndex());
- Qt::DropAction dropAction = drag->exec();
- if (dropAction == Qt::IgnoreAction) {
- // aborted drag, put tab back in place
- // disable event handling during the insert for the tab to prevent infinite recursion (stack overflow)
- dragWidget->blockSignals(true);
- dynamic_cast<QTabWidget*>(parent())->insertTab(dragIndex, dragWidget, dragText);
- dragWidget->blockSignals(false);
- }
- return true;
- }
- }
- return QTabBar::event(event);
+ QPixmap targetPixmap (pixmap.size ());
+ QPainter painter (&targetPixmap);
+ painter.setOpacity(0.9);
+ painter.drawPixmap(0,0, pixmap);
+ painter.end ();
+ drag->setPixmap (targetPixmap);
+
+ drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()));
+
+ dragIndex = currentIndex();
+ dragText = tabText(dragIndex);
+ dragWidget = dynamic_cast<QTabWidget*>(parent())->widget(dragIndex);
+ assert(dragWidget);
+ dynamic_cast<QTabWidget*>(parent())->removeTab(currentIndex());
+ Qt::DropAction dropAction = drag->exec();
+ if (dropAction == Qt::IgnoreAction) {
+ // aborted drag, put tab back in place
+ // disable event handling during the insert for the tab to prevent infinite recursion (stack overflow)
+ dragWidget->blockSignals(true);
+ dynamic_cast<QTabWidget*>(parent())->insertTab(dragIndex, dragWidget, dragText);
+ dragWidget->blockSignals(false);
+ }
+ return true;
+ }
+ }
+ return QTabBar::event(event);
}
}
diff --git a/Swift/QtUI/Trellis/QtDNDTabBar.h b/Swift/QtUI/Trellis/QtDNDTabBar.h
index 71ca94b..3677b73 100644
--- a/Swift/QtUI/Trellis/QtDNDTabBar.h
+++ b/Swift/QtUI/Trellis/QtDNDTabBar.h
@@ -11,31 +11,31 @@
namespace Swift {
class QtDNDTabBar : public QTabBar {
- Q_OBJECT
- public:
- explicit QtDNDTabBar(QWidget* parent = 0);
- virtual ~QtDNDTabBar();
-
- int getDragIndex() const;
- QString getDragText() const;
- QWidget* getDragWidget() const;
-
- virtual QSize sizeHint() const;
-
- signals:
- void onDropSucceeded();
-
- protected:
- virtual void dragEnterEvent(QDragEnterEvent* dragEnterEvent);
- virtual void dropEvent(QDropEvent* dropEvent);
- virtual bool event(QEvent* event);
- virtual QSize tabSizeHint(int index) const;
-
- private:
- int defaultTabHeight;
- int dragIndex;
- QString dragText;
- QWidget* dragWidget;
+ Q_OBJECT
+ public:
+ explicit QtDNDTabBar(QWidget* parent = 0);
+ virtual ~QtDNDTabBar();
+
+ int getDragIndex() const;
+ QString getDragText() const;
+ QWidget* getDragWidget() const;
+
+ virtual QSize sizeHint() const;
+
+ signals:
+ void onDropSucceeded();
+
+ protected:
+ virtual void dragEnterEvent(QDragEnterEvent* dragEnterEvent);
+ virtual void dropEvent(QDropEvent* dropEvent);
+ virtual bool event(QEvent* event);
+ virtual QSize tabSizeHint(int index) const;
+
+ private:
+ int defaultTabHeight;
+ int dragIndex;
+ QString dragText;
+ QWidget* dragWidget;
};
}
diff --git a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp
index 3b8adf8..7de2791 100644
--- a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp
+++ b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp
@@ -24,127 +24,127 @@
namespace Swift {
QtDynamicGridLayout::QtDynamicGridLayout(QWidget* parent, bool enableDND) : QWidget(parent), dndEnabled_(enableDND), movingTab_(NULL) {
- gridLayout_ = new QGridLayout(this);
- setContentsMargins(0,0,0,0);
- setDimensions(QSize(1,1));
- connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*,QWidget*)));
+ gridLayout_ = new QGridLayout(this);
+ setContentsMargins(0,0,0,0);
+ setDimensions(QSize(1,1));
+ connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*,QWidget*)));
}
QtDynamicGridLayout::~QtDynamicGridLayout() {
}
int QtDynamicGridLayout::addTab(QtTabbable* tab, const QString& title) {
- assert(gridLayout_->rowCount() > 0 && gridLayout_->columnCount() > 0);
+ assert(gridLayout_->rowCount() > 0 && gridLayout_->columnCount() > 0);
- QPoint lastPos(0,0);
- if (tabPositions_.contains(P2QSTRING(tab->getID()))) {
- lastPos = tabPositions_[P2QSTRING(tab->getID())];
- }
+ QPoint lastPos(0,0);
+ if (tabPositions_.contains(P2QSTRING(tab->getID()))) {
+ lastPos = tabPositions_[P2QSTRING(tab->getID())];
+ }
- lastPos = QPoint(qMin(lastPos.x(), gridLayout_->columnCount() - 1), qMin(lastPos.y(), gridLayout_->rowCount() - 1));
+ lastPos = QPoint(qMin(lastPos.x(), gridLayout_->columnCount() - 1), qMin(lastPos.y(), gridLayout_->rowCount() - 1));
- QLayoutItem* item = gridLayout_->itemAtPosition(lastPos.y(), lastPos.x());
- QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(item ? item->widget() : 0);
- if (tabWidget) {
- tabWidget->addTab(tab, title);
- }
- return tabWidget ? indexOf(tab) : -1;
+ QLayoutItem* item = gridLayout_->itemAtPosition(lastPos.y(), lastPos.x());
+ QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(item ? item->widget() : 0);
+ if (tabWidget) {
+ tabWidget->addTab(tab, title);
+ }
+ return tabWidget ? indexOf(tab) : -1;
}
int QtDynamicGridLayout::count() const {
- int count = 0;
- for (int y = 0; y < gridLayout_->rowCount(); y++) {
- for (int x = 0; x < gridLayout_->columnCount(); x++) {
- QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
- QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
- if (tabWidget) {
- count += tabWidget->count();
- }
- }
- }
- return count;
+ int count = 0;
+ for (int y = 0; y < gridLayout_->rowCount(); y++) {
+ for (int x = 0; x < gridLayout_->columnCount(); x++) {
+ QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
+ QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
+ if (tabWidget) {
+ count += tabWidget->count();
+ }
+ }
+ }
+ return count;
}
QWidget* QtDynamicGridLayout::widget(int index) const {
- QWidget* widgetAtIndex = NULL;
- for (int y = 0; y < gridLayout_->rowCount(); y++) {
- for (int x = 0; x < gridLayout_->columnCount(); x++) {
- QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
- QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
- if (tabWidget) {
- if (index < tabWidget->count()) {
- widgetAtIndex = tabWidget->widget(index);
- return widgetAtIndex;
- }
- else {
- index -= tabWidget->count();
- }
- }
- }
- }
- return widgetAtIndex;
+ QWidget* widgetAtIndex = NULL;
+ for (int y = 0; y < gridLayout_->rowCount(); y++) {
+ for (int x = 0; x < gridLayout_->columnCount(); x++) {
+ QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
+ QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
+ if (tabWidget) {
+ if (index < tabWidget->count()) {
+ widgetAtIndex = tabWidget->widget(index);
+ return widgetAtIndex;
+ }
+ else {
+ index -= tabWidget->count();
+ }
+ }
+ }
+ }
+ return widgetAtIndex;
}
int QtDynamicGridLayout::indexOf(const QWidget* widget) const {
- int index = 0;
- if (widget) {
- for (int y = 0; y < gridLayout_->rowCount(); y++) {
- for (int x = 0; x < gridLayout_->columnCount(); x++) {
- QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
- QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
- if (tabWidget) {
- for (int n = 0; n < tabWidget->count(); n++) {
- QWidget* nthWidget = tabWidget->widget(n);
- if (nthWidget == widget) {
- return index;
- }
- index++;
- }
- }
- }
- }
- }
- return -1;
+ int index = 0;
+ if (widget) {
+ for (int y = 0; y < gridLayout_->rowCount(); y++) {
+ for (int x = 0; x < gridLayout_->columnCount(); x++) {
+ QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
+ QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
+ if (tabWidget) {
+ for (int n = 0; n < tabWidget->count(); n++) {
+ QWidget* nthWidget = tabWidget->widget(n);
+ if (nthWidget == widget) {
+ return index;
+ }
+ index++;
+ }
+ }
+ }
+ }
+ }
+ return -1;
}
void QtDynamicGridLayout::handleApplicationFocusChanged(QWidget*, QWidget* newFocus) {
- if (movingTab_) {
- return;
- }
-
- if (newFocus) {
- if (isAncestorOf(newFocus)) {
- QtTabbable *newTab = dynamic_cast<QtTabbable*>(newFocus->parentWidget());
- if (newTab) {
- onCurrentIndexChanged(currentIndex());
- }
- }
- }
+ if (movingTab_) {
+ return;
+ }
+
+ if (newFocus) {
+ if (isAncestorOf(newFocus)) {
+ QtTabbable *newTab = dynamic_cast<QtTabbable*>(newFocus->parentWidget());
+ if (newTab) {
+ onCurrentIndexChanged(currentIndex());
+ }
+ }
+ }
}
int QtDynamicGridLayout::currentIndex() const {
- return indexOf(currentWidget());
+ return indexOf(currentWidget());
}
void QtDynamicGridLayout::setCurrentIndex(int index) {
- int tabIndex = -1;
- QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
- if (tabIndex >= 0) {
- tabWidget->setCurrentIndex(tabIndex);
- if (!tabWidget->hasFocus()) {
- tabWidget->widget(tabIndex)->setFocus(Qt::TabFocusReason);
- }
- } else {
- assert(false);
- }
+ int tabIndex = -1;
+ QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
+ if (tabIndex >= 0) {
+ tabWidget->setCurrentIndex(tabIndex);
+ if (!tabWidget->hasFocus()) {
+ tabWidget->widget(tabIndex)->setFocus(Qt::TabFocusReason);
+ }
+ } else {
+ assert(false);
+ }
}
void QtDynamicGridLayout::removeTab(int index) {
- int tabIndex = -1;
- QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
- if (tabWidget) {
- tabWidget->removeTab(tabIndex);
- }
+ int tabIndex = -1;
+ QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
+ if (tabWidget) {
+ tabWidget->removeTab(tabIndex);
+ }
}
/**
@@ -158,348 +158,348 @@ void QtDynamicGridLayout::removeTab(int index) {
* being out of sync in an inconsistent state.
*/
bool QtDynamicGridLayout::eventFilter(QObject* object, QEvent* event) {
- QtTabbable* tab = qobject_cast<QtTabbable*>(object);
- if (!tab) {
- return false;
- }
- if (tab && (tab != movingTab_)) {
- if (event->type() == QEvent::Show) {
- return true;
- }
- }
- return false;
+ QtTabbable* tab = qobject_cast<QtTabbable*>(object);
+ if (!tab) {
+ return false;
+ }
+ if (tab && (tab != movingTab_)) {
+ if (event->type() == QEvent::Show) {
+ return true;
+ }
+ }
+ return false;
}
QWidget* QtDynamicGridLayout::currentWidget() const {
- QWidget* current = NULL;
- current = focusWidget();
- while (current && !dynamic_cast<QtTabbable*>(current)) {
- if (current->parentWidget()) {
- current = current->parentWidget();
- } else {
- current = NULL;
- break;
- }
- }
- if (!current) {
- current = widget(0);
- }
- return current;
+ QWidget* current = NULL;
+ current = focusWidget();
+ while (current && !dynamic_cast<QtTabbable*>(current)) {
+ if (current->parentWidget()) {
+ current = current->parentWidget();
+ } else {
+ current = NULL;
+ break;
+ }
+ }
+ if (!current) {
+ current = widget(0);
+ }
+ return current;
}
void QtDynamicGridLayout::setCurrentWidget(QWidget* widget) {
- for (int y = 0; y < gridLayout_->rowCount(); y++) {
- for (int x = 0; x < gridLayout_->columnCount(); x++) {
- QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
- QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
- if (tabWidget) {
- for (int n = 0; n < tabWidget->count(); n++) {
- if (tabWidget->widget(n) == widget) {
- tabWidget->setCurrentWidget(widget);
- }
- }
- }
- }
- }
+ for (int y = 0; y < gridLayout_->rowCount(); y++) {
+ for (int x = 0; x < gridLayout_->columnCount(); x++) {
+ QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
+ QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
+ if (tabWidget) {
+ for (int n = 0; n < tabWidget->count(); n++) {
+ if (tabWidget->widget(n) == widget) {
+ tabWidget->setCurrentWidget(widget);
+ }
+ }
+ }
+ }
+ }
}
QtTabWidget* QtDynamicGridLayout::indexToTabWidget(int index, int& tabIndex) {
- for (int y = 0; y < gridLayout_->rowCount(); y++) {
- for (int x = 0; x < gridLayout_->columnCount(); x++) {
- QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
- QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
- if (tabWidget) {
- if (index < tabWidget->count()) {
- tabIndex = index;
- return tabWidget;
- }
- else {
- index -= tabWidget->count();
- if (index < 0) {
- qWarning() << "Called QtDynamicGridLayout::setCurrentIndex with index out of bounds: index = " << index;
- tabIndex = -1;
- return NULL;
- }
- }
- }
- }
- }
- tabIndex = -1;
- return NULL;
+ for (int y = 0; y < gridLayout_->rowCount(); y++) {
+ for (int x = 0; x < gridLayout_->columnCount(); x++) {
+ QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
+ QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
+ if (tabWidget) {
+ if (index < tabWidget->count()) {
+ tabIndex = index;
+ return tabWidget;
+ }
+ else {
+ index -= tabWidget->count();
+ if (index < 0) {
+ qWarning() << "Called QtDynamicGridLayout::setCurrentIndex with index out of bounds: index = " << index;
+ tabIndex = -1;
+ return NULL;
+ }
+ }
+ }
+ }
+ }
+ tabIndex = -1;
+ return NULL;
}
bool QtDynamicGridLayout::isDNDEnabled() const {
- return dndEnabled_;
+ return dndEnabled_;
}
QHash<QString, QPoint> QtDynamicGridLayout::getTabPositions() const {
- return tabPositions_;
+ return tabPositions_;
}
void QtDynamicGridLayout::setTabPositions(const QHash<QString, QPoint> positions) {
- tabPositions_ = positions;
+ tabPositions_ = positions;
}
QSize QtDynamicGridLayout::getDimension() const {
- return QSize(gridLayout_->columnCount(), gridLayout_->rowCount());
+ return QSize(gridLayout_->columnCount(), gridLayout_->rowCount());
}
void QtDynamicGridLayout::setDimensions(const QSize& dim) {
- assert(dim.width() > 0 && dim.height() > 0);
- setUpdatesEnabled(false);
-
- QGridLayout* oldLayout = dynamic_cast<QGridLayout*>(layout());
- QGridLayout* newLayout = new QGridLayout;
- newLayout->setSpacing(4);
- newLayout->setContentsMargins(0,0,0,0);
-
- int oldWidth = oldLayout->columnCount();
- int oldHeight = oldLayout->rowCount();
- int maxCol = qMax(oldWidth, dim.width());
- int minCol = qMin(oldWidth, dim.width());
- int maxRow = qMax(oldHeight, dim.height());
- int minRow = qMin(oldHeight, dim.height());
-
- for (int row = 0; row < maxRow; row++) {
- for (int col = 0; col < maxCol; col++) {
- QLayoutItem* oldItem = oldLayout->itemAtPosition(row, col);
- QLayoutItem* newItem = newLayout->itemAtPosition(row, col);
- bool removeRow = !(row < dim.height());
- bool removeCol = !(col < dim.width());
-
- if (removeCol || removeRow) {
- if (oldItem) {
- int squeezeRow = removeRow ? (minRow - 1) : row;
- int squeezeCol = removeCol ? (minCol - 1) : col;
- newItem = newLayout->itemAtPosition(squeezeRow, squeezeCol);
- if (!newItem) {
- newLayout->addWidget(createDNDTabWidget(this), squeezeRow, squeezeCol);
- newItem = newLayout->itemAtPosition(squeezeRow, squeezeCol);
- }
- QtTabWidget* oldTabWidget = dynamic_cast<QtTabWidget*>(oldItem->widget());
- QtTabWidget* newTabWidget = dynamic_cast<QtTabWidget*>(newItem->widget());
- assert(oldTabWidget && newTabWidget);
-
- oldTabWidget->hide();
- while(oldTabWidget->count()) {
- QIcon icon = oldTabWidget->tabIcon(0);
- QString text = oldTabWidget->tabText(0);
- newTabWidget->addTab(oldTabWidget->widget(0), icon, text);
- }
- delete oldTabWidget;
- }
- } else {
- if (oldItem) {
- newLayout->addWidget(oldItem->widget(), row, col);
- newItem = newLayout->itemAtPosition(row, col);
- } else {
- newLayout->addWidget(createDNDTabWidget(this), row, col);
- }
- }
- }
- }
-
- for (int col = 0; col < dim.width(); col++) {
- newLayout->setColumnStretch(col, 1);
- }
- for (int row = 0; row < dim.height(); row++) {
- newLayout->setRowStretch(row, 1);
- }
-
- setUpdatesEnabled(true);
- delete layout();
- setLayout(newLayout);
- gridLayout_ = newLayout;
+ assert(dim.width() > 0 && dim.height() > 0);
+ setUpdatesEnabled(false);
+
+ QGridLayout* oldLayout = dynamic_cast<QGridLayout*>(layout());
+ QGridLayout* newLayout = new QGridLayout;
+ newLayout->setSpacing(4);
+ newLayout->setContentsMargins(0,0,0,0);
+
+ int oldWidth = oldLayout->columnCount();
+ int oldHeight = oldLayout->rowCount();
+ int maxCol = qMax(oldWidth, dim.width());
+ int minCol = qMin(oldWidth, dim.width());
+ int maxRow = qMax(oldHeight, dim.height());
+ int minRow = qMin(oldHeight, dim.height());
+
+ for (int row = 0; row < maxRow; row++) {
+ for (int col = 0; col < maxCol; col++) {
+ QLayoutItem* oldItem = oldLayout->itemAtPosition(row, col);
+ QLayoutItem* newItem = newLayout->itemAtPosition(row, col);
+ bool removeRow = !(row < dim.height());
+ bool removeCol = !(col < dim.width());
+
+ if (removeCol || removeRow) {
+ if (oldItem) {
+ int squeezeRow = removeRow ? (minRow - 1) : row;
+ int squeezeCol = removeCol ? (minCol - 1) : col;
+ newItem = newLayout->itemAtPosition(squeezeRow, squeezeCol);
+ if (!newItem) {
+ newLayout->addWidget(createDNDTabWidget(this), squeezeRow, squeezeCol);
+ newItem = newLayout->itemAtPosition(squeezeRow, squeezeCol);
+ }
+ QtTabWidget* oldTabWidget = dynamic_cast<QtTabWidget*>(oldItem->widget());
+ QtTabWidget* newTabWidget = dynamic_cast<QtTabWidget*>(newItem->widget());
+ assert(oldTabWidget && newTabWidget);
+
+ oldTabWidget->hide();
+ while(oldTabWidget->count()) {
+ QIcon icon = oldTabWidget->tabIcon(0);
+ QString text = oldTabWidget->tabText(0);
+ newTabWidget->addTab(oldTabWidget->widget(0), icon, text);
+ }
+ delete oldTabWidget;
+ }
+ } else {
+ if (oldItem) {
+ newLayout->addWidget(oldItem->widget(), row, col);
+ newItem = newLayout->itemAtPosition(row, col);
+ } else {
+ newLayout->addWidget(createDNDTabWidget(this), row, col);
+ }
+ }
+ }
+ }
+
+ for (int col = 0; col < dim.width(); col++) {
+ newLayout->setColumnStretch(col, 1);
+ }
+ for (int row = 0; row < dim.height(); row++) {
+ newLayout->setRowStretch(row, 1);
+ }
+
+ setUpdatesEnabled(true);
+ delete layout();
+ setLayout(newLayout);
+ gridLayout_ = newLayout;
}
void QtDynamicGridLayout::moveCurrentTabRight() {
- int index = currentIndex();
- if (index >= 0) {
- int tabIndex = -1;
- QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
- assert(tabWidget);
- int newTabIndex = (tabIndex + 1) % tabWidget->count();
- moveTab(tabWidget, tabIndex, newTabIndex);
- }
+ int index = currentIndex();
+ if (index >= 0) {
+ int tabIndex = -1;
+ QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
+ assert(tabWidget);
+ int newTabIndex = (tabIndex + 1) % tabWidget->count();
+ moveTab(tabWidget, tabIndex, newTabIndex);
+ }
}
void QtDynamicGridLayout::moveCurrentTabLeft() {
- int index = currentIndex();
- if (index >= 0) {
- int tabIndex = -1;
- QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
- assert(tabWidget);
- int newTabIndex = (tabWidget->count() + tabIndex - 1) % tabWidget->count();
- moveTab(tabWidget, tabIndex, newTabIndex);
- }
+ int index = currentIndex();
+ if (index >= 0) {
+ int tabIndex = -1;
+ QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
+ assert(tabWidget);
+ int newTabIndex = (tabWidget->count() + tabIndex - 1) % tabWidget->count();
+ moveTab(tabWidget, tabIndex, newTabIndex);
+ }
}
void QtDynamicGridLayout::moveCurrentTabToNextGroup() {
- int index = currentIndex();
- if (index >= 0) {
- int tabIndex = -1;
- QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
-
- int row = -1;
- int col = -1;
- int tmp;
- gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp);
-
- // calculate next cell
- col++;
- if (!(col < gridLayout_->columnCount())) {
- col = 0;
- row++;
- if (!(row < gridLayout_->rowCount())) {
- row = 0;
- }
- }
-
- QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget());
- assert(tabWidget);
- assert(targetTabWidget);
-
- // fetch tab information
- QWidget* tab = tabWidget->widget(tabIndex);
- QString tabText = tabWidget->tabText(tabIndex);
-
- // move tab
- tab->blockSignals(true);
- targetTabWidget->addTab(tab, tabText);
- tab->blockSignals(false);
- tab->setFocus(Qt::TabFocusReason);
-
- updateTabPositions();
- }
+ int index = currentIndex();
+ if (index >= 0) {
+ int tabIndex = -1;
+ QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
+
+ int row = -1;
+ int col = -1;
+ int tmp;
+ gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp);
+
+ // calculate next cell
+ col++;
+ if (!(col < gridLayout_->columnCount())) {
+ col = 0;
+ row++;
+ if (!(row < gridLayout_->rowCount())) {
+ row = 0;
+ }
+ }
+
+ QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget());
+ assert(tabWidget);
+ assert(targetTabWidget);
+
+ // fetch tab information
+ QWidget* tab = tabWidget->widget(tabIndex);
+ QString tabText = tabWidget->tabText(tabIndex);
+
+ // move tab
+ tab->blockSignals(true);
+ targetTabWidget->addTab(tab, tabText);
+ tab->blockSignals(false);
+ tab->setFocus(Qt::TabFocusReason);
+
+ updateTabPositions();
+ }
}
void QtDynamicGridLayout::moveCurrentTabToPreviousGroup() {
- int index = currentIndex();
- if (index >= 0) {
- int tabIndex = -1;
- QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
-
- int row = -1;
- int col = -1;
- int tmp;
- gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp);
-
- // calculate next cell
- col--;
- if (col < 0) {
- col = gridLayout_->columnCount() - 1;
- row--;
- if (row < 0) {
- row = gridLayout_->rowCount() - 1;
- }
- }
-
- QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget());
- assert(tabWidget);
- assert(targetTabWidget);
-
- // fetch tab information
- QWidget* tab = tabWidget->widget(tabIndex);
- QString tabText = tabWidget->tabText(tabIndex);
-
- // move tab
- tab->blockSignals(true);
- targetTabWidget->addTab(tab, tabText);
- tab->blockSignals(false);
- tab->setFocus(Qt::TabFocusReason);
-
- updateTabPositions();
- }
+ int index = currentIndex();
+ if (index >= 0) {
+ int tabIndex = -1;
+ QtTabWidget* tabWidget = indexToTabWidget(index, tabIndex);
+
+ int row = -1;
+ int col = -1;
+ int tmp;
+ gridLayout_->getItemPosition(gridLayout_->indexOf(tabWidget), &row, &col, &tmp, &tmp);
+
+ // calculate next cell
+ col--;
+ if (col < 0) {
+ col = gridLayout_->columnCount() - 1;
+ row--;
+ if (row < 0) {
+ row = gridLayout_->rowCount() - 1;
+ }
+ }
+
+ QtTabWidget* targetTabWidget = dynamic_cast<QtTabWidget*>(gridLayout_->itemAtPosition(row, col)->widget());
+ assert(tabWidget);
+ assert(targetTabWidget);
+
+ // fetch tab information
+ QWidget* tab = tabWidget->widget(tabIndex);
+ QString tabText = tabWidget->tabText(tabIndex);
+
+ // move tab
+ tab->blockSignals(true);
+ targetTabWidget->addTab(tab, tabText);
+ tab->blockSignals(false);
+ tab->setFocus(Qt::TabFocusReason);
+
+ updateTabPositions();
+ }
}
void QtDynamicGridLayout::handleTabCloseRequested(int index) {
- updateTabPositions();
- QtTabWidget* tabWidgetSender = dynamic_cast<QtTabWidget*>(sender());
- for (int y = 0; y < gridLayout_->rowCount(); y++) {
- for (int x = 0; x < gridLayout_->columnCount(); x++) {
- QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
- QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
- if (tabWidget == tabWidgetSender) {
- tabCloseRequested(index);
- }
- else {
- index += tabWidget->count();
- }
- }
- }
+ updateTabPositions();
+ QtTabWidget* tabWidgetSender = dynamic_cast<QtTabWidget*>(sender());
+ for (int y = 0; y < gridLayout_->rowCount(); y++) {
+ for (int x = 0; x < gridLayout_->columnCount(); x++) {
+ QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
+ QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
+ if (tabWidget == tabWidgetSender) {
+ tabCloseRequested(index);
+ }
+ else {
+ index += tabWidget->count();
+ }
+ }
+ }
}
void QtDynamicGridLayout::handleTabCurrentChanged(int index) {
- if (movingTab_) {
- return;
- }
-
- if (index >= 0) {
- QTabWidget* sendingTabWidget = dynamic_cast<QTabWidget*>(sender());
- assert(sendingTabWidget);
- sendingTabWidget->widget(index)->setFocus();
- }
+ if (movingTab_) {
+ return;
+ }
+
+ if (index >= 0) {
+ QTabWidget* sendingTabWidget = dynamic_cast<QTabWidget*>(sender());
+ assert(sendingTabWidget);
+ sendingTabWidget->widget(index)->setFocus();
+ }
}
void QtDynamicGridLayout::updateTabPositions() {
- for (int y = 0; y < gridLayout_->rowCount(); y++) {
- for (int x = 0; x < gridLayout_->columnCount(); x++) {
- QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
- QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
- assert(tabWidget);
- for (int index = 0; index < tabWidget->count(); index++) {
- QtTabbable* tab = dynamic_cast<QtTabbable*>(tabWidget->widget(index));
- assert(tab);
- tabPositions_.insert(P2QSTRING(tab->getID()), QPoint(x, y));
- }
- }
- }
+ for (int y = 0; y < gridLayout_->rowCount(); y++) {
+ for (int x = 0; x < gridLayout_->columnCount(); x++) {
+ QLayoutItem* layoutItem = gridLayout_->itemAtPosition(y, x);
+ QtTabWidget* tabWidget = dynamic_cast<QtTabWidget*>(layoutItem->widget());
+ assert(tabWidget);
+ for (int index = 0; index < tabWidget->count(); index++) {
+ QtTabbable* tab = dynamic_cast<QtTabbable*>(tabWidget->widget(index));
+ assert(tab);
+ tabPositions_.insert(P2QSTRING(tab->getID()), QPoint(x, y));
+ }
+ }
+ }
}
void QtDynamicGridLayout::moveTab(QtTabWidget* tabWidget, int oldIndex, int newIndex) {
#if QT_VERSION >= 0x040500
- SWIFT_LOG_ASSERT(movingTab_ == NULL, error) << std::endl;
- movingTab_ = qobject_cast<QtTabbable*>(tabWidget->widget(oldIndex));
- SWIFT_LOG_ASSERT(movingTab_ != NULL, error) << std::endl;
-
- if (movingTab_) {
- // Install event filter that filters out events issued during the internal movement of the
- // tab but not targeted at the moving tab.
- qApp->installEventFilter(this);
-
- tabWidget->tabBar()->moveTab(oldIndex, newIndex);
-
- qApp->removeEventFilter(this);
- SWIFT_LOG_ASSERT(movingTab_ == tabWidget->widget(newIndex), error) << std::endl;
- }
- movingTab_ = NULL;
- tabWidget->widget(newIndex)->setFocus();
+ SWIFT_LOG_ASSERT(movingTab_ == NULL, error) << std::endl;
+ movingTab_ = qobject_cast<QtTabbable*>(tabWidget->widget(oldIndex));
+ SWIFT_LOG_ASSERT(movingTab_ != NULL, error) << std::endl;
+
+ if (movingTab_) {
+ // Install event filter that filters out events issued during the internal movement of the
+ // tab but not targeted at the moving tab.
+ qApp->installEventFilter(this);
+
+ tabWidget->tabBar()->moveTab(oldIndex, newIndex);
+
+ qApp->removeEventFilter(this);
+ SWIFT_LOG_ASSERT(movingTab_ == tabWidget->widget(newIndex), error) << std::endl;
+ }
+ movingTab_ = NULL;
+ tabWidget->widget(newIndex)->setFocus();
#else
#warning Qt 4.5 or later is needed. Trying anyway, some things will be disabled.
#endif
}
QtTabWidget* QtDynamicGridLayout::createDNDTabWidget(QWidget* parent) {
- QtTabWidget* tab = new QtTabWidget(parent);
- if (dndEnabled_) {
- QtDNDTabBar* tabBar = new QtDNDTabBar(tab);
- connect(tabBar, SIGNAL(onDropSucceeded()), this, SLOT(updateTabPositions()));
- tab->setTabBar(tabBar);
- }
- tab->setUsesScrollButtons(true);
- tab->setElideMode(Qt::ElideRight);
+ QtTabWidget* tab = new QtTabWidget(parent);
+ if (dndEnabled_) {
+ QtDNDTabBar* tabBar = new QtDNDTabBar(tab);
+ connect(tabBar, SIGNAL(onDropSucceeded()), this, SLOT(updateTabPositions()));
+ tab->setTabBar(tabBar);
+ }
+ tab->setUsesScrollButtons(true);
+ tab->setElideMode(Qt::ElideRight);
#if QT_VERSION >= 0x040500
- /*For Macs, change the tab rendering.*/
- tab->setDocumentMode(true);
- /*Closable tabs are only in Qt4.5 and later*/
- tab->setTabsClosable(true);
- tab->setMovable(true);
- connect(tab, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabCloseRequested(int)));
- connect(tab, SIGNAL(currentChanged(int)), this, SLOT(handleTabCurrentChanged(int)));
+ /*For Macs, change the tab rendering.*/
+ tab->setDocumentMode(true);
+ /*Closable tabs are only in Qt4.5 and later*/
+ tab->setTabsClosable(true);
+ tab->setMovable(true);
+ connect(tab, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabCloseRequested(int)));
+ connect(tab, SIGNAL(currentChanged(int)), this, SLOT(handleTabCurrentChanged(int)));
#else
#warning Qt 4.5 or later is needed. Trying anyway, some things will be disabled.
#endif
- return tab;
+ return tab;
}
}
diff --git a/Swift/QtUI/Trellis/QtDynamicGridLayout.h b/Swift/QtUI/Trellis/QtDynamicGridLayout.h
index ed8a9fc..2a6029c 100644
--- a/Swift/QtUI/Trellis/QtDynamicGridLayout.h
+++ b/Swift/QtUI/Trellis/QtDynamicGridLayout.h
@@ -14,67 +14,67 @@
#include <QWidget>
namespace Swift {
- class QtTabbable;
- class QtTabWidget;
+ class QtTabbable;
+ class QtTabWidget;
- class QtDynamicGridLayout : public QWidget {
- Q_OBJECT
- public:
- explicit QtDynamicGridLayout(QWidget* parent = 0, bool enableDND = false);
- virtual ~QtDynamicGridLayout();
+ class QtDynamicGridLayout : public QWidget {
+ Q_OBJECT
+ public:
+ explicit QtDynamicGridLayout(QWidget* parent = 0, bool enableDND = false);
+ virtual ~QtDynamicGridLayout();
- QSize getDimension() const;
+ QSize getDimension() const;
- // emulate QtTabWidget API
- int addTab(QtTabbable* tab, const QString& title);
- void removeTab(int index);
- int count() const;
+ // emulate QtTabWidget API
+ int addTab(QtTabbable* tab, const QString& title);
+ void removeTab(int index);
+ int count() const;
- QWidget* widget(int index) const;
- QWidget* currentWidget() const;
- void setCurrentWidget(QWidget* widget);
+ QWidget* widget(int index) const;
+ QWidget* currentWidget() const;
+ void setCurrentWidget(QWidget* widget);
- QtTabWidget* indexToTabWidget(int index, int& tabIndex);
+ QtTabWidget* indexToTabWidget(int index, int& tabIndex);
- int indexOf(const QWidget* widget) const;
- int currentIndex() const;
- void setCurrentIndex(int index);
+ int indexOf(const QWidget* widget) const;
+ int currentIndex() const;
+ void setCurrentIndex(int index);
- bool isDNDEnabled() const;
+ bool isDNDEnabled() const;
- QHash<QString, QPoint> getTabPositions() const;
- void setTabPositions(const QHash<QString, QPoint> positions);
+ QHash<QString, QPoint> getTabPositions() const;
+ void setTabPositions(const QHash<QString, QPoint> positions);
- bool eventFilter(QObject* object, QEvent* event);
+ bool eventFilter(QObject* object, QEvent* event);
- signals:
- void tabCloseRequested(int index);
- void onCurrentIndexChanged(int newIndex);
+ signals:
+ void tabCloseRequested(int index);
+ void onCurrentIndexChanged(int newIndex);
- public slots:
- void setDimensions(const QSize& dim);
+ public slots:
+ void setDimensions(const QSize& dim);
- // Tab Management
- void moveCurrentTabRight();
- void moveCurrentTabLeft();
- void moveCurrentTabToNextGroup();
- void moveCurrentTabToPreviousGroup();
+ // Tab Management
+ void moveCurrentTabRight();
+ void moveCurrentTabLeft();
+ void moveCurrentTabToNextGroup();
+ void moveCurrentTabToPreviousGroup();
- void updateTabPositions();
+ void updateTabPositions();
- private slots:
- void handleTabCloseRequested(int index);
- void handleTabCurrentChanged(int index);
- void handleApplicationFocusChanged(QWidget* oldFocus, QWidget* newFocus);
+ private slots:
+ void handleTabCloseRequested(int index);
+ void handleTabCurrentChanged(int index);
+ void handleApplicationFocusChanged(QWidget* oldFocus, QWidget* newFocus);
- private:
- void moveTab(QtTabWidget* tabWidget, int oldIndex, int newIndex);
- QtTabWidget* createDNDTabWidget(QWidget* parent);
+ private:
+ void moveTab(QtTabWidget* tabWidget, int oldIndex, int newIndex);
+ QtTabWidget* createDNDTabWidget(QWidget* parent);
- private:
- QGridLayout *gridLayout_;
- bool dndEnabled_;
- QHash<QString, QPoint> tabPositions_;
- QtTabbable* movingTab_;
- };
+ private:
+ QGridLayout *gridLayout_;
+ bool dndEnabled_;
+ QHash<QString, QPoint> tabPositions_;
+ QtTabbable* movingTab_;
+ };
}
diff --git a/Swift/QtUI/Trellis/QtGridSelectionDialog.cpp b/Swift/QtUI/Trellis/QtGridSelectionDialog.cpp
index a3a1bf8..c7b7edb 100644
--- a/Swift/QtUI/Trellis/QtGridSelectionDialog.cpp
+++ b/Swift/QtUI/Trellis/QtGridSelectionDialog.cpp
@@ -16,142 +16,142 @@
namespace Swift {
QtGridSelectionDialog::QtGridSelectionDialog(QWidget* parent) : QWidget(parent) {
- frameSize = QSize(23,23) * 2;
- maxGridSize = QSize(7,7);
- minGridSize = QSize(1,1);
- currentGridSize = QSize(1,1);
- padding = 4;
- setWindowFlags(Qt::FramelessWindowHint);
- setCursor(Qt::SizeAllCursor);
- horizontalMargin = style()->pixelMetric(QStyle::PM_MenuVMargin) * 2;
- verticalMargin = style()->pixelMetric(QStyle::PM_MenuVMargin) * 2;
+ frameSize = QSize(23,23) * 2;
+ maxGridSize = QSize(7,7);
+ minGridSize = QSize(1,1);
+ currentGridSize = QSize(1,1);
+ padding = 4;
+ setWindowFlags(Qt::FramelessWindowHint);
+ setCursor(Qt::SizeAllCursor);
+ horizontalMargin = style()->pixelMetric(QStyle::PM_MenuVMargin) * 2;
+ verticalMargin = style()->pixelMetric(QStyle::PM_MenuVMargin) * 2;
}
QSize QtGridSelectionDialog::sizeHint() const {
- // PM_MenuVMargin | frameSize | ( padding | frameSize ) * | PM_MenuVMargin
- int width = horizontalMargin + frameSize.width() + (padding + frameSize.width()) * (currentGridSize.width() - 1) + horizontalMargin;
- int height = verticalMargin + frameSize.height() + (padding + frameSize.height()) * (currentGridSize.height() - 1) + verticalMargin;
- return QSize(width, height);
+ // PM_MenuVMargin | frameSize | ( padding | frameSize ) * | PM_MenuVMargin
+ int width = horizontalMargin + frameSize.width() + (padding + frameSize.width()) * (currentGridSize.width() - 1) + horizontalMargin;
+ int height = verticalMargin + frameSize.height() + (padding + frameSize.height()) * (currentGridSize.height() - 1) + verticalMargin;
+ return QSize(width, height);
}
void QtGridSelectionDialog::setCurrentGridSize(const QSize& size) {
- currentGridSize = size;
- emit currentGridSizeChanged(size);
+ currentGridSize = size;
+ emit currentGridSizeChanged(size);
}
QSize QtGridSelectionDialog::getCurrentGridSize() const {
- return currentGridSize;
+ return currentGridSize;
}
void QtGridSelectionDialog::setMinGridSize(const QSize& size) {
- minGridSize = size;
- emit minGridSizeChanged(size);
+ minGridSize = size;
+ emit minGridSizeChanged(size);
}
QSize QtGridSelectionDialog::getMinGridSize() const {
- return minGridSize;
+ return minGridSize;
}
void QtGridSelectionDialog::setMaxGridSize(const QSize& size) {
- maxGridSize = size;
- emit maxGridSizeChanged(size);
+ maxGridSize = size;
+ emit maxGridSizeChanged(size);
}
QSize QtGridSelectionDialog::getMaxGridSize() const {
- return maxGridSize;
+ return maxGridSize;
}
void QtGridSelectionDialog::keyReleaseEvent(QKeyEvent* event) {
- if (event) {
- QSize newGridSize = currentGridSize;
- if (event->key() == Qt::Key_Up) {
- newGridSize += QSize(0, -1);
- }
- else if (event->key() == Qt::Key_Down) {
- newGridSize += QSize(0, 1);
- }
- else if (event->key() == Qt::Key_Left) {
- newGridSize += QSize(-1, 0);
- }
- else if (event->key() == Qt::Key_Right) {
- newGridSize += QSize(1, 0);
- }
- else if (event->key() == Qt::Key_Return) {
- hide();
- setCurrentGridSize(currentGridSize);
- }
- if (minGridSize.expandedTo(newGridSize).boundedTo(maxGridSize) != currentGridSize) {
- currentGridSize = minGridSize.expandedTo(newGridSize).boundedTo(maxGridSize);
- resize(sizeHint());
- }
- }
+ if (event) {
+ QSize newGridSize = currentGridSize;
+ if (event->key() == Qt::Key_Up) {
+ newGridSize += QSize(0, -1);
+ }
+ else if (event->key() == Qt::Key_Down) {
+ newGridSize += QSize(0, 1);
+ }
+ else if (event->key() == Qt::Key_Left) {
+ newGridSize += QSize(-1, 0);
+ }
+ else if (event->key() == Qt::Key_Right) {
+ newGridSize += QSize(1, 0);
+ }
+ else if (event->key() == Qt::Key_Return) {
+ hide();
+ setCurrentGridSize(currentGridSize);
+ }
+ if (minGridSize.expandedTo(newGridSize).boundedTo(maxGridSize) != currentGridSize) {
+ currentGridSize = minGridSize.expandedTo(newGridSize).boundedTo(maxGridSize);
+ resize(sizeHint());
+ }
+ }
}
void QtGridSelectionDialog::mousePressEvent(QMouseEvent*) {
- hide();
- setCurrentGridSize(currentGridSize);
+ hide();
+ setCurrentGridSize(currentGridSize);
}
void QtGridSelectionDialog::paintEvent(QPaintEvent*) {
- QPainter painter(this);
- QStyleOptionMenuItem option;
- option.state = QStyle::State_Enabled | QStyle::State_Selected;
- option.menuRect = QRect(QPoint(0,0), frameSize);
- for (int x = 0; x < currentGridSize.width(); x++) {
- for (int y = 0; y < currentGridSize.height(); y++) {
- int xPos = horizontalMargin + (x * (frameSize.width() + padding));
- int yPos = verticalMargin + (y * (frameSize.height() + padding));
- option.menuRect.moveTo(QPoint(xPos, yPos));
- option.rect = option.menuRect;
- style()->drawControl(QStyle::CE_MenuItem, &option, &painter, 0);
- }
- }
-
- QStyleOptionSizeGrip sizeGripOption;
- sizeGripOption.init(this);
- sizeGripOption.corner = Qt::BottomRightCorner;
- style()->drawControl(QStyle::CE_SizeGrip, &sizeGripOption, &painter, this);
+ QPainter painter(this);
+ QStyleOptionMenuItem option;
+ option.state = QStyle::State_Enabled | QStyle::State_Selected;
+ option.menuRect = QRect(QPoint(0,0), frameSize);
+ for (int x = 0; x < currentGridSize.width(); x++) {
+ for (int y = 0; y < currentGridSize.height(); y++) {
+ int xPos = horizontalMargin + (x * (frameSize.width() + padding));
+ int yPos = verticalMargin + (y * (frameSize.height() + padding));
+ option.menuRect.moveTo(QPoint(xPos, yPos));
+ option.rect = option.menuRect;
+ style()->drawControl(QStyle::CE_MenuItem, &option, &painter, 0);
+ }
+ }
+
+ QStyleOptionSizeGrip sizeGripOption;
+ sizeGripOption.init(this);
+ sizeGripOption.corner = Qt::BottomRightCorner;
+ style()->drawControl(QStyle::CE_SizeGrip, &sizeGripOption, &painter, this);
}
void QtGridSelectionDialog::showEvent(QShowEvent*) {
- int xPos = horizontalMargin + frameSize.width() + (padding + frameSize.width()) * (currentGridSize.width() - 1) - frameSize.width()/2;
- int yPos = verticalMargin + frameSize.height() + (padding + frameSize.height()) * (currentGridSize.height() - 1) - frameSize.height()/2;
- QCursor::setPos(mapToGlobal(QPoint(xPos, yPos)));
- setMouseTracking(true);
+ int xPos = horizontalMargin + frameSize.width() + (padding + frameSize.width()) * (currentGridSize.width() - 1) - frameSize.width()/2;
+ int yPos = verticalMargin + frameSize.height() + (padding + frameSize.height()) * (currentGridSize.height() - 1) - frameSize.height()/2;
+ QCursor::setPos(mapToGlobal(QPoint(xPos, yPos)));
+ setMouseTracking(true);
}
void QtGridSelectionDialog::hideEvent(QHideEvent*) {
- setMouseTracking(false);
+ setMouseTracking(false);
}
void QtGridSelectionDialog::mouseMoveEvent(QMouseEvent*) {
- QPoint diff = (frameGeometry().bottomRight() - QCursor::pos());
- QSize newDimensions = currentGridSize;
- if (diff.x() > frameSize.width() * 1.5) {
- newDimensions -= QSize(diff.x() / (frameSize.width() * 1.5), 0);
- }
- if (diff.y() > frameSize.height() * 1.5) {
- newDimensions -= QSize(0, diff.y() / (frameSize.height() * 1.5));
- }
- if (minGridSize.expandedTo(newDimensions).boundedTo(maxGridSize) != currentGridSize) {
- currentGridSize = minGridSize.expandedTo(newDimensions).boundedTo(maxGridSize);
- resize(sizeHint());
- }
+ QPoint diff = (frameGeometry().bottomRight() - QCursor::pos());
+ QSize newDimensions = currentGridSize;
+ if (diff.x() > frameSize.width() * 1.5) {
+ newDimensions -= QSize(diff.x() / (frameSize.width() * 1.5), 0);
+ }
+ if (diff.y() > frameSize.height() * 1.5) {
+ newDimensions -= QSize(0, diff.y() / (frameSize.height() * 1.5));
+ }
+ if (minGridSize.expandedTo(newDimensions).boundedTo(maxGridSize) != currentGridSize) {
+ currentGridSize = minGridSize.expandedTo(newDimensions).boundedTo(maxGridSize);
+ resize(sizeHint());
+ }
}
void QtGridSelectionDialog::leaveEvent(QEvent *) {
- QPoint diff = (frameGeometry().bottomRight() - QCursor::pos());
- QSize newGridSize = currentGridSize;
- if (diff.x() < 0) {
- newGridSize += QSize(1,0);
- }
- if (diff.y() < 0) {
- newGridSize += QSize(0,1);
- }
- if (minGridSize.expandedTo(newGridSize).boundedTo(maxGridSize) != currentGridSize) {
- currentGridSize = minGridSize.expandedTo(newGridSize).boundedTo(maxGridSize);
- resize(sizeHint());
- }
+ QPoint diff = (frameGeometry().bottomRight() - QCursor::pos());
+ QSize newGridSize = currentGridSize;
+ if (diff.x() < 0) {
+ newGridSize += QSize(1,0);
+ }
+ if (diff.y() < 0) {
+ newGridSize += QSize(0,1);
+ }
+ if (minGridSize.expandedTo(newGridSize).boundedTo(maxGridSize) != currentGridSize) {
+ currentGridSize = minGridSize.expandedTo(newGridSize).boundedTo(maxGridSize);
+ resize(sizeHint());
+ }
}
}
diff --git a/Swift/QtUI/Trellis/QtGridSelectionDialog.h b/Swift/QtUI/Trellis/QtGridSelectionDialog.h
index abcc8b1..c763e68 100644
--- a/Swift/QtUI/Trellis/QtGridSelectionDialog.h
+++ b/Swift/QtUI/Trellis/QtGridSelectionDialog.h
@@ -11,47 +11,47 @@
namespace Swift {
- class QtGridSelectionDialog : public QWidget {
- Q_OBJECT
-
- Q_PROPERTY(QSize currentGridSize READ getCurrentGridSize WRITE setCurrentGridSize NOTIFY currentGridSizeChanged)
- Q_PROPERTY(QSize minGridSize READ getMinGridSize WRITE setMinGridSize NOTIFY minGridSizeChanged)
- Q_PROPERTY(QSize maxGridSize READ getMaxGridSize WRITE setMaxGridSize NOTIFY maxGridSizeChanged)
- public:
- explicit QtGridSelectionDialog(QWidget* parent = 0);
-
- virtual QSize sizeHint() const;
-
- void setCurrentGridSize(const QSize& size);
- QSize getCurrentGridSize() const;
- void setMinGridSize(const QSize& size);
- QSize getMinGridSize() const;
- void setMaxGridSize(const QSize& size);
- QSize getMaxGridSize() const;
-
- signals:
- void currentGridSizeChanged(QSize);
- void minGridSizeChanged(QSize);
- void maxGridSizeChanged(QSize);
-
- protected:
- void keyReleaseEvent(QKeyEvent* event);
- void mousePressEvent(QMouseEvent* event);
- void mouseMoveEvent(QMouseEvent* event);
- void paintEvent(QPaintEvent* event);
- void showEvent(QShowEvent* event);
- void hideEvent(QHideEvent* event);
- void leaveEvent(QEvent *event);
-
- private:
- int padding;
- int horizontalMargin;
- int verticalMargin;
-
- QSize frameSize;
-
- QSize currentGridSize;
- QSize minGridSize;
- QSize maxGridSize;
- };
+ class QtGridSelectionDialog : public QWidget {
+ Q_OBJECT
+
+ Q_PROPERTY(QSize currentGridSize READ getCurrentGridSize WRITE setCurrentGridSize NOTIFY currentGridSizeChanged)
+ Q_PROPERTY(QSize minGridSize READ getMinGridSize WRITE setMinGridSize NOTIFY minGridSizeChanged)
+ Q_PROPERTY(QSize maxGridSize READ getMaxGridSize WRITE setMaxGridSize NOTIFY maxGridSizeChanged)
+ public:
+ explicit QtGridSelectionDialog(QWidget* parent = 0);
+
+ virtual QSize sizeHint() const;
+
+ void setCurrentGridSize(const QSize& size);
+ QSize getCurrentGridSize() const;
+ void setMinGridSize(const QSize& size);
+ QSize getMinGridSize() const;
+ void setMaxGridSize(const QSize& size);
+ QSize getMaxGridSize() const;
+
+ signals:
+ void currentGridSizeChanged(QSize);
+ void minGridSizeChanged(QSize);
+ void maxGridSizeChanged(QSize);
+
+ protected:
+ void keyReleaseEvent(QKeyEvent* event);
+ void mousePressEvent(QMouseEvent* event);
+ void mouseMoveEvent(QMouseEvent* event);
+ void paintEvent(QPaintEvent* event);
+ void showEvent(QShowEvent* event);
+ void hideEvent(QHideEvent* event);
+ void leaveEvent(QEvent *event);
+
+ private:
+ int padding;
+ int horizontalMargin;
+ int verticalMargin;
+
+ QSize frameSize;
+
+ QSize currentGridSize;
+ QSize minGridSize;
+ QSize maxGridSize;
+ };
}
diff --git a/Swift/QtUI/UserSearch/ContactListDelegate.cpp b/Swift/QtUI/UserSearch/ContactListDelegate.cpp
index 989743e..75e25a1 100644
--- a/Swift/QtUI/UserSearch/ContactListDelegate.cpp
+++ b/Swift/QtUI/UserSearch/ContactListDelegate.cpp
@@ -26,29 +26,29 @@ ContactListDelegate::~ContactListDelegate() {
}
void ContactListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- if (!index.isValid()) {
- return;
- }
- const Contact::ref contact = static_cast<Contact*>(index.internalPointer())->shared_from_this();
- QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
- QString avatarPath = index.data(ContactListModel::AvatarRole).value<QString>();
- QIcon presenceIcon =index.data(ChatListRecentItem::PresenceIconRole).isValid() && !index.data(ChatListRecentItem::PresenceIconRole).value<QIcon>().isNull()
- ? index.data(ChatListRecentItem::PresenceIconRole).value<QIcon>()
- : QIcon(":/icons/offline.png");
- QString name = P2QSTRING(contact->name);
- QString statusText = P2QSTRING(contact->jid.toString());
- common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, 0, compact_);
+ if (!index.isValid()) {
+ return;
+ }
+ const Contact::ref contact = static_cast<Contact*>(index.internalPointer())->shared_from_this();
+ QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
+ QString avatarPath = index.data(ContactListModel::AvatarRole).value<QString>();
+ QIcon presenceIcon =index.data(ChatListRecentItem::PresenceIconRole).isValid() && !index.data(ChatListRecentItem::PresenceIconRole).value<QIcon>().isNull()
+ ? index.data(ChatListRecentItem::PresenceIconRole).value<QIcon>()
+ : QIcon(":/icons/offline.png");
+ QString name = P2QSTRING(contact->name);
+ QString statusText = P2QSTRING(contact->jid.toString());
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, 0, compact_);
}
QSize ContactListDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const {
- QFontMetrics nameMetrics(common_.nameFont);
- QFontMetrics statusMetrics(common_.detailFont);
- int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
- return QSize(150, sizeByText);
+ QFontMetrics nameMetrics(common_.nameFont);
+ QFontMetrics statusMetrics(common_.detailFont);
+ int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
+ return QSize(150, sizeByText);
}
void ContactListDelegate::setCompact(bool compact) {
- compact_ = compact;
+ compact_ = compact;
}
}
diff --git a/Swift/QtUI/UserSearch/ContactListDelegate.h b/Swift/QtUI/UserSearch/ContactListDelegate.h
index 7680aba..208246a 100644
--- a/Swift/QtUI/UserSearch/ContactListDelegate.h
+++ b/Swift/QtUI/UserSearch/ContactListDelegate.h
@@ -13,18 +13,18 @@
namespace Swift {
class ContactListDelegate : public QStyledItemDelegate {
- public:
- ContactListDelegate(bool compact);
- virtual ~ContactListDelegate();
+ public:
+ ContactListDelegate(bool compact);
+ virtual ~ContactListDelegate();
- QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
- void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
- public slots:
- void setCompact(bool compact);
+ public slots:
+ void setCompact(bool compact);
- private:
- bool compact_;
- DelegateCommons common_;
+ private:
+ bool compact_;
+ DelegateCommons common_;
};
}
diff --git a/Swift/QtUI/UserSearch/ContactListModel.cpp b/Swift/QtUI/UserSearch/ContactListModel.cpp
index 3400924..376d3b1 100644
--- a/Swift/QtUI/UserSearch/ContactListModel.cpp
+++ b/Swift/QtUI/UserSearch/ContactListModel.cpp
@@ -24,116 +24,116 @@
namespace Swift {
QDataStream& operator >>(QDataStream& in, StatusShow::Type& e){
- quint32 buffer;
- in >> buffer;
- switch(buffer) {
- case StatusShow::Online:
- e = StatusShow::Online;
- break;
- case StatusShow::Away:
- e = StatusShow::Away;
- break;
- case StatusShow::FFC:
- e = StatusShow::FFC;
- break;
- case StatusShow::XA:
- e = StatusShow::XA;
- break;
- case StatusShow::DND:
- e = StatusShow::DND;
- break;
- default:
- e = StatusShow::None;
- break;
- }
- return in;
+ quint32 buffer;
+ in >> buffer;
+ switch(buffer) {
+ case StatusShow::Online:
+ e = StatusShow::Online;
+ break;
+ case StatusShow::Away:
+ e = StatusShow::Away;
+ break;
+ case StatusShow::FFC:
+ e = StatusShow::FFC;
+ break;
+ case StatusShow::XA:
+ e = StatusShow::XA;
+ break;
+ case StatusShow::DND:
+ e = StatusShow::DND;
+ break;
+ default:
+ e = StatusShow::None;
+ break;
+ }
+ return in;
}
ContactListModel::ContactListModel(bool editable) : QAbstractItemModel(), editable_(editable) {
}
void ContactListModel::setList(const std::vector<Contact::ref>& list) {
- emit layoutAboutToBeChanged();
- contacts_ = list;
- emit layoutChanged();
+ emit layoutAboutToBeChanged();
+ contacts_ = list;
+ emit layoutChanged();
}
const std::vector<Contact::ref>& ContactListModel::getList() const {
- return contacts_;
+ return contacts_;
}
Contact::ref ContactListModel::getContact(const size_t i) const {
- return contacts_[i];
+ return contacts_[i];
}
Qt::ItemFlags ContactListModel::flags(const QModelIndex& index) const {
- Qt::ItemFlags flags = QAbstractItemModel::flags(index);
- if (index.isValid()) {
- flags = flags & ~Qt::ItemIsDropEnabled;
- } else {
- flags = Qt::ItemIsDropEnabled | flags;
- }
- return flags;
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ if (index.isValid()) {
+ flags = flags & ~Qt::ItemIsDropEnabled;
+ } else {
+ flags = Qt::ItemIsDropEnabled | flags;
+ }
+ return flags;
}
int ContactListModel::columnCount(const QModelIndex&) const {
- return editable_ ? 2 : 1;
+ return editable_ ? 2 : 1;
}
QVariant ContactListModel::data(const QModelIndex& index, int role) const {
- if ((boost::numeric_cast<size_t>(index.row()) < contacts_.size()) && (index.column() == 0)) {
- const Contact::ref& contact = contacts_[index.row()];
- if (role == Qt::EditRole) {
- return P2QSTRING(contact->jid.toString());
- }
- return dataForContact(contact, role);
- } else {
- return QVariant();
- }
+ if ((boost::numeric_cast<size_t>(index.row()) < contacts_.size()) && (index.column() == 0)) {
+ const Contact::ref& contact = contacts_[index.row()];
+ if (role == Qt::EditRole) {
+ return P2QSTRING(contact->jid.toString());
+ }
+ return dataForContact(contact, role);
+ } else {
+ return QVariant();
+ }
}
QModelIndex ContactListModel::index(int row, int column, const QModelIndex& parent) const {
- if (!hasIndex(row, column, parent)) {
- return QModelIndex();
- }
+ if (!hasIndex(row, column, parent)) {
+ return QModelIndex();
+ }
- return boost::numeric_cast<size_t>(row) < contacts_.size() ? createIndex(row, column, contacts_[row].get()) : QModelIndex();
+ return boost::numeric_cast<size_t>(row) < contacts_.size() ? createIndex(row, column, contacts_[row].get()) : QModelIndex();
}
QModelIndex ContactListModel::parent(const QModelIndex& index) const {
- if (!index.isValid()) {
- return QModelIndex();
- }
- return QModelIndex();
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+ return QModelIndex();
}
int ContactListModel::rowCount(const QModelIndex& /*parent*/) const {
- return contacts_.size();
+ return contacts_.size();
}
bool ContactListModel::removeRows(int row, int /*count*/, const QModelIndex& /*parent*/) {
- if (boost::numeric_cast<size_t>(row) < contacts_.size()) {
- emit layoutAboutToBeChanged();
- contacts_.erase(contacts_.begin() + row);
- emit layoutChanged();
- onListChanged(getList());
- return true;
- }
- return false;
+ if (boost::numeric_cast<size_t>(row) < contacts_.size()) {
+ emit layoutAboutToBeChanged();
+ contacts_.erase(contacts_.begin() + row);
+ emit layoutChanged();
+ onListChanged(getList());
+ return true;
+ }
+ return false;
}
QVariant ContactListModel::dataForContact(const Contact::ref& contact, int role) const {
- switch (role) {
- case Qt::DisplayRole: return P2QSTRING(contact->name);
- case DetailTextRole: return P2QSTRING(contact->jid.toString());
- case AvatarRole: return QVariant(P2QSTRING(pathToString(contact->avatarPath)));
- case PresenceIconRole: return getPresenceIconForContact(contact);
- default: return QVariant();
- }
+ switch (role) {
+ case Qt::DisplayRole: return P2QSTRING(contact->name);
+ case DetailTextRole: return P2QSTRING(contact->jid.toString());
+ case AvatarRole: return QVariant(P2QSTRING(pathToString(contact->avatarPath)));
+ case PresenceIconRole: return getPresenceIconForContact(contact);
+ default: return QVariant();
+ }
}
QIcon ContactListModel::getPresenceIconForContact(const Contact::ref& contact) const {
- return QIcon(statusShowTypeToIconPath(contact->statusType));
+ return QIcon(statusShowTypeToIconPath(contact->statusType));
}
}
diff --git a/Swift/QtUI/UserSearch/ContactListModel.h b/Swift/QtUI/UserSearch/ContactListModel.h
index e980120..9b61484 100644
--- a/Swift/QtUI/UserSearch/ContactListModel.h
+++ b/Swift/QtUI/UserSearch/ContactListModel.h
@@ -27,41 +27,41 @@
#include <Swift/QtUI/ChatList/ChatListRecentItem.h>
namespace Swift {
- class ContactListModel : public QAbstractItemModel {
- Q_OBJECT
- public:
- enum ContactRoles {
- DetailTextRole = Qt::UserRole,
- AvatarRole = Qt::UserRole + 1,
- PresenceIconRole = Qt::UserRole + 2
- };
-
- public:
- ContactListModel(bool editable);
-
- void setList(const std::vector<Contact::ref>& list);
- const std::vector<Contact::ref>& getList() const;
- Contact::ref getContact(const size_t i) const;
-
- Qt::ItemFlags flags(const QModelIndex& index) const;
- int columnCount(const QModelIndex& parent = QModelIndex()) const;
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex& index) const;
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
- bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
-
- private:
- QVariant dataForContact(const Contact::ref& contact, int role) const;
- QIcon getPresenceIconForContact(const Contact::ref& contact) const;
-
- signals:
- void onListChanged(std::vector<Contact::ref> list);
- void onJIDsDropped(const std::vector<JID>& contact);
-
- private:
- bool editable_;
- std::vector<Contact::ref> contacts_;
- };
+ class ContactListModel : public QAbstractItemModel {
+ Q_OBJECT
+ public:
+ enum ContactRoles {
+ DetailTextRole = Qt::UserRole,
+ AvatarRole = Qt::UserRole + 1,
+ PresenceIconRole = Qt::UserRole + 2
+ };
+
+ public:
+ ContactListModel(bool editable);
+
+ void setList(const std::vector<Contact::ref>& list);
+ const std::vector<Contact::ref>& getList() const;
+ Contact::ref getContact(const size_t i) const;
+
+ Qt::ItemFlags flags(const QModelIndex& index) const;
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex& index) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
+
+ private:
+ QVariant dataForContact(const Contact::ref& contact, int role) const;
+ QIcon getPresenceIconForContact(const Contact::ref& contact) const;
+
+ signals:
+ void onListChanged(std::vector<Contact::ref> list);
+ void onJIDsDropped(const std::vector<JID>& contact);
+
+ private:
+ bool editable_;
+ std::vector<Contact::ref> contacts_;
+ };
}
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.cpp b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
index 0d55880..99bd791 100644
--- a/Swift/QtUI/UserSearch/QtContactListWidget.cpp
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
@@ -24,80 +24,80 @@
namespace Swift {
QtContactListWidget::QtContactListWidget(QWidget* parent, SettingsProvider* settings) : QTreeView(parent), settings_(settings), limited_(false) {
- contactListModel_ = new ContactListModel(true);
- setModel(contactListModel_);
+ contactListModel_ = new ContactListModel(true);
+ setModel(contactListModel_);
- connect(contactListModel_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SIGNAL(onListChanged(std::vector<Contact::ref>)));
- connect(contactListModel_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SIGNAL(onJIDsAdded(std::vector<JID>)));
+ connect(contactListModel_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SIGNAL(onListChanged(std::vector<Contact::ref>)));
+ connect(contactListModel_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SIGNAL(onJIDsAdded(std::vector<JID>)));
- setSelectionMode(QAbstractItemView::SingleSelection);
- setSelectionBehavior(QAbstractItemView::SelectRows);
- setUniformRowHeights(true);
+ setSelectionMode(QAbstractItemView::SingleSelection);
+ setSelectionBehavior(QAbstractItemView::SelectRows);
+ setUniformRowHeights(true);
- setAlternatingRowColors(true);
- setIndentation(0);
- setHeaderHidden(true);
- setExpandsOnDoubleClick(false);
- setItemsExpandable(false);
- setEditTriggers(QAbstractItemView::DoubleClicked);
+ setAlternatingRowColors(true);
+ setIndentation(0);
+ setHeaderHidden(true);
+ setExpandsOnDoubleClick(false);
+ setItemsExpandable(false);
+ setEditTriggers(QAbstractItemView::DoubleClicked);
- contactListDelegate_ = new ContactListDelegate(settings->getSetting(QtUISettingConstants::COMPACT_ROSTER));
- removableItemDelegate_ = new QtRemovableItemDelegate(style());
+ contactListDelegate_ = new ContactListDelegate(settings->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ removableItemDelegate_ = new QtRemovableItemDelegate(style());
- setItemDelegateForColumn(0, contactListDelegate_);
- setItemDelegateForColumn(1, removableItemDelegate_);
+ setItemDelegateForColumn(0, contactListDelegate_);
+ setItemDelegateForColumn(1, removableItemDelegate_);
- header()->resizeSection(1, removableItemDelegate_->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
+ header()->resizeSection(1, removableItemDelegate_->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
- header()->setStretchLastSection(false);
+ header()->setStretchLastSection(false);
#if QT_VERSION >= 0x050000
- header()->setSectionResizeMode(0, QHeaderView::Stretch);
+ header()->setSectionResizeMode(0, QHeaderView::Stretch);
#else
- header()->setResizeMode(0, QHeaderView::Stretch);
+ header()->setResizeMode(0, QHeaderView::Stretch);
#endif
}
QtContactListWidget::~QtContactListWidget() {
- delete contactListDelegate_;
- delete removableItemDelegate_;
- delete contactListModel_;
+ delete contactListDelegate_;
+ delete removableItemDelegate_;
+ delete contactListModel_;
}
void QtContactListWidget::setList(const std::vector<Contact::ref>& list) {
- contactListModel_->setList(list);
+ contactListModel_->setList(list);
}
std::vector<Contact::ref> QtContactListWidget::getList() const {
- return contactListModel_->getList();
+ return contactListModel_->getList();
}
Contact::ref QtContactListWidget::getContact(const size_t i) {
- return contactListModel_->getContact(i);
+ return contactListModel_->getContact(i);
}
void QtContactListWidget::setMaximumNoOfContactsToOne(bool limited) {
- limited_ = limited;
+ limited_ = limited;
}
bool QtContactListWidget::isFull() const {
- return limited_ && (getList().size() == 1);
+ return limited_ && (getList().size() == 1);
}
void QtContactListWidget::updateContacts(const std::vector<Contact::ref>& contactUpdates) {
- std::vector<Contact::ref> contacts = contactListModel_->getList();
- foreach(const Contact::ref& contactUpdate, contactUpdates) {
- for(size_t n = 0; n < contacts.size(); n++) {
- if (contactUpdate->jid == contacts[n]->jid) {
- contacts[n] = contactUpdate;
- break;
- }
- }
- }
- contactListModel_->setList(contacts);
+ std::vector<Contact::ref> contacts = contactListModel_->getList();
+ foreach(const Contact::ref& contactUpdate, contactUpdates) {
+ for(size_t n = 0; n < contacts.size(); n++) {
+ if (contactUpdate->jid == contacts[n]->jid) {
+ contacts[n] = contactUpdate;
+ break;
+ }
+ }
+ }
+ contactListModel_->setList(contacts);
}
void QtContactListWidget::handleSettingsChanged(const std::string&) {
- contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
}
}
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.h b/Swift/QtUI/UserSearch/QtContactListWidget.h
index 59bd8f3..f2483c3 100644
--- a/Swift/QtUI/UserSearch/QtContactListWidget.h
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.h
@@ -31,33 +31,33 @@ class SettingsProvider;
class QtRemovableItemDelegate;
class QtContactListWidget : public QTreeView {
- Q_OBJECT
+ Q_OBJECT
public:
- QtContactListWidget(QWidget* parent, SettingsProvider* settings);
- virtual ~QtContactListWidget();
+ QtContactListWidget(QWidget* parent, SettingsProvider* settings);
+ virtual ~QtContactListWidget();
- void setList(const std::vector<Contact::ref>& list);
- std::vector<Contact::ref> getList() const;
- Contact::ref getContact(const size_t i);
- void setMaximumNoOfContactsToOne(bool limited);
- bool isFull() const;
+ void setList(const std::vector<Contact::ref>& list);
+ std::vector<Contact::ref> getList() const;
+ Contact::ref getContact(const size_t i);
+ void setMaximumNoOfContactsToOne(bool limited);
+ bool isFull() const;
public slots:
- void updateContacts(const std::vector<Contact::ref>& contactUpdates);
+ void updateContacts(const std::vector<Contact::ref>& contactUpdates);
signals:
- void onListChanged(std::vector<Contact::ref> list);
- void onJIDsAdded(const std::vector<JID>& jids);
+ void onListChanged(std::vector<Contact::ref> list);
+ void onJIDsAdded(const std::vector<JID>& jids);
private:
- void handleSettingsChanged(const std::string&);
+ void handleSettingsChanged(const std::string&);
private:
- SettingsProvider* settings_;
- ContactListModel* contactListModel_;
- ContactListDelegate* contactListDelegate_;
- QtRemovableItemDelegate* removableItemDelegate_;
- bool limited_;
+ SettingsProvider* settings_;
+ ContactListModel* contactListModel_;
+ ContactListDelegate* contactListDelegate_;
+ QtRemovableItemDelegate* removableItemDelegate_;
+ bool limited_;
};
}
diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp
index 26d0f05..4e8f4e1 100644
--- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp
+++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp
@@ -31,180 +31,180 @@
namespace Swift {
QtSuggestingJIDInput::QtSuggestingJIDInput(QWidget* parent, SettingsProvider* settings) : QLineEdit(parent), settings_(settings) {
- treeViewPopup_ = new QTreeView();
- treeViewPopup_->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
- //treeViewPopup_->setAttribute(Qt::WA_ShowWithoutActivating);
- treeViewPopup_->setAlternatingRowColors(true);
- treeViewPopup_->setIndentation(0);
- treeViewPopup_->setHeaderHidden(true);
- treeViewPopup_->setExpandsOnDoubleClick(false);
- treeViewPopup_->setItemsExpandable(false);
- treeViewPopup_->setSelectionMode(QAbstractItemView::SingleSelection);
- treeViewPopup_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
- treeViewPopup_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- QSizePolicy policy(treeViewPopup_->sizePolicy());
- policy.setVerticalPolicy(QSizePolicy::Expanding);
- treeViewPopup_->setSizePolicy(policy);
- treeViewPopup_->hide();
- treeViewPopup_->setFocusProxy(this);
- connect(treeViewPopup_, SIGNAL(clicked(QModelIndex)), this, SLOT(handleClicked(QModelIndex)));
- connect(treeViewPopup_, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(handleClicked(QModelIndex)));
-
- contactListModel_ = new ContactListModel(false);
- treeViewPopup_->setModel(contactListModel_);
-
- contactListDelegate_ = new ContactListDelegate(settings->getSetting(QtUISettingConstants::COMPACT_ROSTER));
- treeViewPopup_->setItemDelegate(contactListDelegate_);
-
- settings_->onSettingChanged.connect(boost::bind(&QtSuggestingJIDInput::handleSettingsChanged, this, _1));
+ treeViewPopup_ = new QTreeView();
+ treeViewPopup_->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
+ //treeViewPopup_->setAttribute(Qt::WA_ShowWithoutActivating);
+ treeViewPopup_->setAlternatingRowColors(true);
+ treeViewPopup_->setIndentation(0);
+ treeViewPopup_->setHeaderHidden(true);
+ treeViewPopup_->setExpandsOnDoubleClick(false);
+ treeViewPopup_->setItemsExpandable(false);
+ treeViewPopup_->setSelectionMode(QAbstractItemView::SingleSelection);
+ treeViewPopup_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+ treeViewPopup_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ QSizePolicy policy(treeViewPopup_->sizePolicy());
+ policy.setVerticalPolicy(QSizePolicy::Expanding);
+ treeViewPopup_->setSizePolicy(policy);
+ treeViewPopup_->hide();
+ treeViewPopup_->setFocusProxy(this);
+ connect(treeViewPopup_, SIGNAL(clicked(QModelIndex)), this, SLOT(handleClicked(QModelIndex)));
+ connect(treeViewPopup_, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(handleClicked(QModelIndex)));
+
+ contactListModel_ = new ContactListModel(false);
+ treeViewPopup_->setModel(contactListModel_);
+
+ contactListDelegate_ = new ContactListDelegate(settings->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ treeViewPopup_->setItemDelegate(contactListDelegate_);
+
+ settings_->onSettingChanged.connect(boost::bind(&QtSuggestingJIDInput::handleSettingsChanged, this, _1));
}
QtSuggestingJIDInput::~QtSuggestingJIDInput() {
- settings_->onSettingChanged.disconnect(boost::bind(&QtSuggestingJIDInput::handleSettingsChanged, this, _1));
- delete treeViewPopup_;
- delete contactListDelegate_;
- delete contactListModel_;
+ settings_->onSettingChanged.disconnect(boost::bind(&QtSuggestingJIDInput::handleSettingsChanged, this, _1));
+ delete treeViewPopup_;
+ delete contactListDelegate_;
+ delete contactListModel_;
}
Contact::ref QtSuggestingJIDInput::getContact() {
- if (!!currentContact_) {
- return currentContact_;
- }
-
- if (!text().isEmpty()) {
- JID jid(Q2PSTRING(text()));
- if (jid.isValid()) {
- Contact::ref manualContact = boost::make_shared<Contact>();
- manualContact->name = jid.toString();
- manualContact->jid = jid;
- return manualContact;
- }
- }
- return boost::shared_ptr<Contact>();
+ if (!!currentContact_) {
+ return currentContact_;
+ }
+
+ if (!text().isEmpty()) {
+ JID jid(Q2PSTRING(text()));
+ if (jid.isValid()) {
+ Contact::ref manualContact = boost::make_shared<Contact>();
+ manualContact->name = jid.toString();
+ manualContact->jid = jid;
+ return manualContact;
+ }
+ }
+ return boost::shared_ptr<Contact>();
}
void QtSuggestingJIDInput::setSuggestions(const std::vector<Contact::ref>& suggestions) {
- contactListModel_->setList(suggestions);
- positionPopup();
- if (!suggestions.empty()) {
- treeViewPopup_->setCurrentIndex(contactListModel_->index(0, 0));
- showPopup();
- } else {
- currentContact_.reset();
- hidePopup();
- }
+ contactListModel_->setList(suggestions);
+ positionPopup();
+ if (!suggestions.empty()) {
+ treeViewPopup_->setCurrentIndex(contactListModel_->index(0, 0));
+ showPopup();
+ } else {
+ currentContact_.reset();
+ hidePopup();
+ }
}
void QtSuggestingJIDInput::clear() {
- setText("");
- currentContact_.reset();
+ setText("");
+ currentContact_.reset();
}
void QtSuggestingJIDInput::keyPressEvent(QKeyEvent* event) {
- if (event->key() == Qt::Key_Up) {
- if (contactListModel_->rowCount() > 0) {
- int row = treeViewPopup_->currentIndex().row();
- row = (row + contactListModel_->rowCount() - 1) % contactListModel_->rowCount();
- treeViewPopup_->setCurrentIndex(contactListModel_->index(row, 0));
- }
- } else if (event->key() == Qt::Key_Down) {
- if (contactListModel_->rowCount() > 0) {
- int row = treeViewPopup_->currentIndex().row();
- row = (row + contactListModel_->rowCount() + 1) % contactListModel_->rowCount();
- treeViewPopup_->setCurrentIndex(contactListModel_->index(row, 0));
- }
- } else if (event->key() == Qt::Key_Return && treeViewPopup_->isVisible()) {
- QModelIndex index = treeViewPopup_->currentIndex();
- if (!contactListModel_->getList().empty() && index.isValid()) {
- currentContact_ = contactListModel_->getContact(index.row());
- if (currentContact_->jid.isValid()) {
- setText(P2QSTRING(currentContact_->jid.toString()));
- } else {
- setText(P2QSTRING(currentContact_->name));
- }
- hidePopup();
- clearFocus();
- } else {
- currentContact_.reset();
- }
- editingDone();
- } else {
- QLineEdit::keyPressEvent(event);
- }
+ if (event->key() == Qt::Key_Up) {
+ if (contactListModel_->rowCount() > 0) {
+ int row = treeViewPopup_->currentIndex().row();
+ row = (row + contactListModel_->rowCount() - 1) % contactListModel_->rowCount();
+ treeViewPopup_->setCurrentIndex(contactListModel_->index(row, 0));
+ }
+ } else if (event->key() == Qt::Key_Down) {
+ if (contactListModel_->rowCount() > 0) {
+ int row = treeViewPopup_->currentIndex().row();
+ row = (row + contactListModel_->rowCount() + 1) % contactListModel_->rowCount();
+ treeViewPopup_->setCurrentIndex(contactListModel_->index(row, 0));
+ }
+ } else if (event->key() == Qt::Key_Return && treeViewPopup_->isVisible()) {
+ QModelIndex index = treeViewPopup_->currentIndex();
+ if (!contactListModel_->getList().empty() && index.isValid()) {
+ currentContact_ = contactListModel_->getContact(index.row());
+ if (currentContact_->jid.isValid()) {
+ setText(P2QSTRING(currentContact_->jid.toString()));
+ } else {
+ setText(P2QSTRING(currentContact_->name));
+ }
+ hidePopup();
+ clearFocus();
+ } else {
+ currentContact_.reset();
+ }
+ editingDone();
+ } else {
+ QLineEdit::keyPressEvent(event);
+ }
}
void QtSuggestingJIDInput::hideEvent(QHideEvent* /* event */) {
- // Hide our popup when we are hidden (can happen when a dialog is closed by the user).
- treeViewPopup_->hide();
+ // Hide our popup when we are hidden (can happen when a dialog is closed by the user).
+ treeViewPopup_->hide();
}
void QtSuggestingJIDInput::handleApplicationFocusChanged(QWidget* /*old*/, QWidget* /*now*/) {
- /* Using the now argument gives use the wrong widget. This is part of the code needed
- to prevent stealing of focus when opening a the suggestion window. */
- QWidget* now = qApp->focusWidget();
- if (!now || (now != treeViewPopup_ && now != this && !now->isAncestorOf(this) && !now->isAncestorOf(treeViewPopup_) && !this->isAncestorOf(now) && !treeViewPopup_->isAncestorOf(now))) {
- hidePopup();
- }
+ /* Using the now argument gives use the wrong widget. This is part of the code needed
+ to prevent stealing of focus when opening a the suggestion window. */
+ QWidget* now = qApp->focusWidget();
+ if (!now || (now != treeViewPopup_ && now != this && !now->isAncestorOf(this) && !now->isAncestorOf(treeViewPopup_) && !this->isAncestorOf(now) && !treeViewPopup_->isAncestorOf(now))) {
+ hidePopup();
+ }
}
void QtSuggestingJIDInput::handleSettingsChanged(const std::string& setting) {
- if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
- contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
- }
+ if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
+ contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ }
}
void QtSuggestingJIDInput::handleClicked(const QModelIndex& index) {
- if (index.isValid()) {
- currentContact_ = contactListModel_->getContact(index.row());
- onUserSelected(currentContact_);
- hidePopup();
- }
+ if (index.isValid()) {
+ currentContact_ = contactListModel_->getContact(index.row());
+ onUserSelected(currentContact_);
+ hidePopup();
+ }
}
void QtSuggestingJIDInput::positionPopup() {
- QDesktopWidget* desktop = QApplication::desktop();
- int screen = desktop->screenNumber(this);
- QPoint point = mapToGlobal(QPoint(0, height()));
- QRect geometry = desktop->availableGeometry(screen);
- int x = point.x();
- int y = point.y();
- int width = this->width();
- int height = 80;
-
- int screenWidth = geometry.x() + geometry.width();
- if (x + width > screenWidth) {
- x = screenWidth - width;
- }
-
- height = treeViewPopup_->sizeHintForRow(0) * contactListModel_->rowCount();
- height = height > 200 ? 200 : height;
-
- int marginLeft;
- int marginTop;
- int marginRight;
- int marginBottom;
- treeViewPopup_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
- height += marginTop + marginBottom;
- width += marginLeft + marginRight;
-
- treeViewPopup_->setGeometry(x, y, width, height);
- treeViewPopup_->move(x, y);
- treeViewPopup_->setMaximumWidth(width);
+ QDesktopWidget* desktop = QApplication::desktop();
+ int screen = desktop->screenNumber(this);
+ QPoint point = mapToGlobal(QPoint(0, height()));
+ QRect geometry = desktop->availableGeometry(screen);
+ int x = point.x();
+ int y = point.y();
+ int width = this->width();
+ int height = 80;
+
+ int screenWidth = geometry.x() + geometry.width();
+ if (x + width > screenWidth) {
+ x = screenWidth - width;
+ }
+
+ height = treeViewPopup_->sizeHintForRow(0) * contactListModel_->rowCount();
+ height = height > 200 ? 200 : height;
+
+ int marginLeft;
+ int marginTop;
+ int marginRight;
+ int marginBottom;
+ treeViewPopup_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
+ height += marginTop + marginBottom;
+ width += marginLeft + marginRight;
+
+ treeViewPopup_->setGeometry(x, y, width, height);
+ treeViewPopup_->move(x, y);
+ treeViewPopup_->setMaximumWidth(width);
}
void QtSuggestingJIDInput::showPopup() {
- treeViewPopup_->show();
- activateWindow();
- connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)), Qt::QueuedConnection);
- setFocus();
+ treeViewPopup_->show();
+ activateWindow();
+ connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)), Qt::QueuedConnection);
+ setFocus();
}
void QtSuggestingJIDInput::hidePopup() {
- disconnect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)));
- treeViewPopup_->hide();
+ disconnect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)));
+ treeViewPopup_->hide();
- // Give focus back to input widget because the hide() call passes the focus to the wrong widget.
- setFocus();
+ // Give focus back to input widget because the hide() call passes the focus to the wrong widget.
+ setFocus();
}
}
diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h
index 73840b4..2077d55 100644
--- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h
+++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h
@@ -26,44 +26,44 @@ class SettingsProvider;
class ContactListModel;
class QtSuggestingJIDInput : public QLineEdit {
- Q_OBJECT
- public:
- QtSuggestingJIDInput(QWidget* parent, SettingsProvider* settings);
- virtual ~QtSuggestingJIDInput();
+ Q_OBJECT
+ public:
+ QtSuggestingJIDInput(QWidget* parent, SettingsProvider* settings);
+ virtual ~QtSuggestingJIDInput();
- Contact::ref getContact();
+ Contact::ref getContact();
- void setSuggestions(const std::vector<Contact::ref>& suggestions);
+ void setSuggestions(const std::vector<Contact::ref>& suggestions);
- void clear();
+ void clear();
- boost::signal<void (const Contact::ref&)> onUserSelected;
+ boost::signal<void (const Contact::ref&)> onUserSelected;
- signals:
- void editingDone();
+ signals:
+ void editingDone();
- protected:
- virtual void keyPressEvent(QKeyEvent* event);
- virtual void hideEvent(QHideEvent* event);
+ protected:
+ virtual void keyPressEvent(QKeyEvent* event);
+ virtual void hideEvent(QHideEvent* event);
- private:
- void handleSettingsChanged(const std::string& setting);
+ private:
+ void handleSettingsChanged(const std::string& setting);
- private slots:
- void handleClicked(const QModelIndex& index);
- void handleApplicationFocusChanged(QWidget* old, QWidget* now);
+ private slots:
+ void handleClicked(const QModelIndex& index);
+ void handleApplicationFocusChanged(QWidget* old, QWidget* now);
- private:
- void positionPopup();
- void showPopup();
- void hidePopup();
+ private:
+ void positionPopup();
+ void showPopup();
+ void hidePopup();
- private:
- SettingsProvider* settings_;
- ContactListModel* contactListModel_;
- QTreeView* treeViewPopup_;
- ContactListDelegate* contactListDelegate_;
- Contact::ref currentContact_;
+ private:
+ SettingsProvider* settings_;
+ ContactListModel* contactListModel_;
+ QTreeView* treeViewPopup_;
+ ContactListDelegate* contactListDelegate_;
+ Contact::ref currentContact_;
};
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
index 4e8354f..601d6ac 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
@@ -19,10 +19,10 @@
namespace Swift {
QtUserSearchDetailsPage::QtUserSearchDetailsPage(const std::set<std::string>& groups) {
- QVBoxLayout* layout = new QVBoxLayout(this);
- layout->addWidget(new QLabel(tr("Please choose a name for the contact, and select the groups you want to add the contact to.")));
- editWidget = new QtContactEditWidget(groups, this);
- layout->addWidget(editWidget);
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->addWidget(new QLabel(tr("Please choose a name for the contact, and select the groups you want to add the contact to.")));
+ editWidget = new QtContactEditWidget(groups, this);
+ layout->addWidget(editWidget);
}
QtUserSearchDetailsPage::~QtUserSearchDetailsPage() {
@@ -30,27 +30,27 @@ QtUserSearchDetailsPage::~QtUserSearchDetailsPage() {
}
void QtUserSearchDetailsPage::setJID(const JID& jid) {
- contactJID = jid;
+ contactJID = jid;
}
void QtUserSearchDetailsPage::setNameSuggestions(const std::vector<std::string>& nameSuggestions) {
- editWidget->setNameSuggestions(nameSuggestions);
+ editWidget->setNameSuggestions(nameSuggestions);
}
void QtUserSearchDetailsPage::setName(const std::string& name) {
- editWidget->setName(name);
+ editWidget->setName(name);
}
std::set<std::string> QtUserSearchDetailsPage::getSelectedGroups() {
- return editWidget->getSelectedGroups();
+ return editWidget->getSelectedGroups();
}
std::string QtUserSearchDetailsPage::getName() {
- return editWidget->getName();
+ return editWidget->getName();
}
void QtUserSearchDetailsPage::clear() {
- editWidget->clear();
+ editWidget->clear();
}
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h
index 568dfe3..7185bce 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h
@@ -18,28 +18,28 @@
#include <Swift/QtUI/UserSearch/ui_QtUserSearchFieldsPage.h>
namespace Swift {
- class QtContactEditWidget;
+ class QtContactEditWidget;
- class QtUserSearchDetailsPage : public QWizardPage {
- Q_OBJECT
- public:
- QtUserSearchDetailsPage(const std::set<std::string>& availableGroups);
- virtual ~QtUserSearchDetailsPage();
+ class QtUserSearchDetailsPage : public QWizardPage {
+ Q_OBJECT
+ public:
+ QtUserSearchDetailsPage(const std::set<std::string>& availableGroups);
+ virtual ~QtUserSearchDetailsPage();
- void setJID(const JID& jid);
- void setNameSuggestions(const std::vector<std::string>& nameSuggestions);
- void setName(const std::string& name);
+ void setJID(const JID& jid);
+ void setNameSuggestions(const std::vector<std::string>& nameSuggestions);
+ void setName(const std::string& name);
- std::set<std::string> getSelectedGroups();
- std::string getName();
+ std::set<std::string> getSelectedGroups();
+ std::string getName();
- void clear();
+ void clear();
- signals:
- void onUserTriggersFinish();
+ signals:
+ void onUserTriggersFinish();
- private:
- QtContactEditWidget* editWidget;
- JID contactJID;
- };
+ private:
+ QtContactEditWidget* editWidget;
+ JID contactJID;
+ };
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFieldsPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFieldsPage.cpp
index 9b02273..3a82a62 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFieldsPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchFieldsPage.cpp
@@ -9,34 +9,34 @@
namespace Swift {
QtUserSearchFieldsPage::QtUserSearchFieldsPage() : formWidget_(0) {
- setupUi(this);
+ setupUi(this);
}
bool QtUserSearchFieldsPage::isComplete() const {
- if (formWidget_) {
- return formWidget_->isEnabled();
- } else {
- return nickInput_->isEnabled() || firstInput_->isEnabled() || lastInput_->isEnabled() || emailInput_->isEnabled();
- }
+ if (formWidget_) {
+ return formWidget_->isEnabled();
+ } else {
+ return nickInput_->isEnabled() || firstInput_->isEnabled() || lastInput_->isEnabled() || emailInput_->isEnabled();
+ }
}
QtFormWidget* QtUserSearchFieldsPage::getFormWidget() {
- return formWidget_;
+ return formWidget_;
}
void QtUserSearchFieldsPage::setFormWidget(QtFormWidget *widget) {
- if (formWidget_) {
- delete formWidget_;
- formWidget_ = NULL;
- }
- if (widget) {
- formContainer_->layout()->addWidget(widget);
- }
- formWidget_ = widget;
+ if (formWidget_) {
+ delete formWidget_;
+ formWidget_ = NULL;
+ }
+ if (widget) {
+ formContainer_->layout()->addWidget(widget);
+ }
+ formWidget_ = widget;
}
void QtUserSearchFieldsPage::emitCompletenessCheck() {
- emit completeChanged();
+ emit completeChanged();
}
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFieldsPage.h b/Swift/QtUI/UserSearch/QtUserSearchFieldsPage.h
index 29ff675..4089d05 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFieldsPage.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchFieldsPage.h
@@ -12,19 +12,19 @@
#include <Swift/QtUI/UserSearch/ui_QtUserSearchFieldsPage.h>
namespace Swift {
- class QtUserSearchFieldsPage : public QWizardPage, public Ui::QtUserSearchFieldsPage {
- Q_OBJECT
- public:
- QtUserSearchFieldsPage();
- virtual bool isComplete() const;
+ class QtUserSearchFieldsPage : public QWizardPage, public Ui::QtUserSearchFieldsPage {
+ Q_OBJECT
+ public:
+ QtUserSearchFieldsPage();
+ virtual bool isComplete() const;
- QtFormWidget* getFormWidget();
- void setFormWidget(QtFormWidget *widget);
+ QtFormWidget* getFormWidget();
+ void setFormWidget(QtFormWidget *widget);
- public slots:
- void emitCompletenessCheck();
+ public slots:
+ void emitCompletenessCheck();
- private:
- QtFormWidget *formWidget_;
- };
+ private:
+ QtFormWidget *formWidget_;
+ };
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
index 40ea1c0..1327a8f 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
@@ -25,78 +25,78 @@
namespace Swift {
QtUserSearchFirstMultiJIDPage::QtUserSearchFirstMultiJIDPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings) {
- setupUi(this);
- setTitle(title);
- QString introText = "";
- switch (type) {
- case UserSearchWindow::AddContact:
- introText = tr("Add another user to your contact list");
- break;
- case UserSearchWindow::ChatToContact:
- introText = tr("Chat to another user");
- break;
- case UserSearchWindow::InviteToChat:
- introText = tr("Invite contact to chat");
- break;
- }
-
- setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(introText));
-
- contactList_ = new QtContactListWidget(this, settings);
- horizontalLayout_5->addWidget(contactList_);
-
- jid_ = new QtSuggestingJIDInput(this, settings);
- horizontalLayout_6->insertWidget(0, jid_);
-
- connect(contactList_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SLOT(emitCompletenessCheck()));
- connect(jid_, SIGNAL(editingDone()), this, SLOT(handleEditingDone()));
-
- setAcceptDrops(true);
+ setupUi(this);
+ setTitle(title);
+ QString introText = "";
+ switch (type) {
+ case UserSearchWindow::AddContact:
+ introText = tr("Add another user to your contact list");
+ break;
+ case UserSearchWindow::ChatToContact:
+ introText = tr("Chat to another user");
+ break;
+ case UserSearchWindow::InviteToChat:
+ introText = tr("Invite contact to chat");
+ break;
+ }
+
+ setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(introText));
+
+ contactList_ = new QtContactListWidget(this, settings);
+ horizontalLayout_5->addWidget(contactList_);
+
+ jid_ = new QtSuggestingJIDInput(this, settings);
+ horizontalLayout_6->insertWidget(0, jid_);
+
+ connect(contactList_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SLOT(emitCompletenessCheck()));
+ connect(jid_, SIGNAL(editingDone()), this, SLOT(handleEditingDone()));
+
+ setAcceptDrops(true);
}
bool QtUserSearchFirstMultiJIDPage::isComplete() const {
- return !contactList_->getList().empty();
+ return !contactList_->getList().empty();
}
void QtUserSearchFirstMultiJIDPage::reset() {
- jid_->clear();
- reason_->clear();
+ jid_->clear();
+ reason_->clear();
}
void QtUserSearchFirstMultiJIDPage::emitCompletenessCheck() {
- emit completeChanged();
+ emit completeChanged();
}
void QtUserSearchFirstMultiJIDPage::handleEditingDone() {
- addContactButton_->setFocus();
+ addContactButton_->setFocus();
}
void QtUserSearchFirstMultiJIDPage::dragEnterEvent(QDragEnterEvent *event) {
- if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")
- || event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
- if (!contactList_->isFull()) {
- event->acceptProposedAction();
- }
- }
+ if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")
+ || event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
+ if (!contactList_->isFull()) {
+ event->acceptProposedAction();
+ }
+ }
}
void QtUserSearchFirstMultiJIDPage::dropEvent(QDropEvent *event) {
- if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
- QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list");
- QDataStream dataStream(&dataBytes, QIODevice::ReadOnly);
- std::vector<JID> jids;
- while (!dataStream.atEnd()) {
- QString jidString;
- dataStream >> jidString;
- jids.push_back(Q2PSTRING(jidString));
- }
- onJIDsDropped(jids);
- } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
- QMessageBox* messageBox = new QMessageBox(this);
- messageBox->setText(tr("You can't invite a room to chat."));
- messageBox->setWindowTitle(tr("Error inviting room to chat"));
- messageBox->show();
- }
+ if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
+ QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list");
+ QDataStream dataStream(&dataBytes, QIODevice::ReadOnly);
+ std::vector<JID> jids;
+ while (!dataStream.atEnd()) {
+ QString jidString;
+ dataStream >> jidString;
+ jids.push_back(Q2PSTRING(jidString));
+ }
+ onJIDsDropped(jids);
+ } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
+ QMessageBox* messageBox = new QMessageBox(this);
+ messageBox->setText(tr("You can't invite a room to chat."));
+ messageBox->setWindowTitle(tr("Error inviting room to chat"));
+ messageBox->show();
+ }
}
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h
index 82b8f93..d9147db 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h
@@ -19,35 +19,35 @@
#include <Swift/QtUI/UserSearch/ui_QtUserSearchFirstMultiJIDPage.h>
namespace Swift {
- class UserSearchModel;
- class UserSearchDelegate;
- class UserSearchResult;
- class UIEventStream;
- class QtContactListWidget;
- class ContactSuggester;
- class AvatarManager;
- class VCardManager;
- class SettingsProvider;
- class QtSuggestingJIDInput;
-
- class QtUserSearchFirstMultiJIDPage : public QWizardPage, public Ui::QtUserSearchFirstMultiJIDPage {
- Q_OBJECT
- public:
- QtUserSearchFirstMultiJIDPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings);
- virtual bool isComplete() const;
- void reset();
-
- signals:
- void onJIDsDropped(std::vector<JID> jid);
-
- public slots:
- void emitCompletenessCheck();
- void handleEditingDone();
- virtual void dragEnterEvent(QDragEnterEvent *event);
- virtual void dropEvent(QDropEvent *event);
-
- public:
- QtContactListWidget* contactList_;
- QtSuggestingJIDInput* jid_;
- };
+ class UserSearchModel;
+ class UserSearchDelegate;
+ class UserSearchResult;
+ class UIEventStream;
+ class QtContactListWidget;
+ class ContactSuggester;
+ class AvatarManager;
+ class VCardManager;
+ class SettingsProvider;
+ class QtSuggestingJIDInput;
+
+ class QtUserSearchFirstMultiJIDPage : public QWizardPage, public Ui::QtUserSearchFirstMultiJIDPage {
+ Q_OBJECT
+ public:
+ QtUserSearchFirstMultiJIDPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings);
+ virtual bool isComplete() const;
+ void reset();
+
+ signals:
+ void onJIDsDropped(std::vector<JID> jid);
+
+ public slots:
+ void emitCompletenessCheck();
+ void handleEditingDone();
+ virtual void dragEnterEvent(QDragEnterEvent *event);
+ virtual void dropEvent(QDropEvent *event);
+
+ public:
+ QtContactListWidget* contactList_;
+ QtSuggestingJIDInput* jid_;
+ };
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
index 93157c7..5d0c9fa 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
@@ -13,37 +13,37 @@
namespace Swift {
QtUserSearchFirstPage::QtUserSearchFirstPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings) {
- setupUi(this);
- setTitle(title);
- setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(type == UserSearchWindow::AddContact ? tr("Add another user to your contact list") : tr("Chat to another user")));
- jid_ = new QtSuggestingJIDInput(this, settings);
- horizontalLayout_2->addWidget(jid_);
- jidWarning_ = new QLabel(this);
- jidWarning_->setPixmap(QPixmap(":icons/warn.png"));
- jidWarning_->hide();
- horizontalLayout_2->addWidget(jidWarning_);
- setTabOrder(byJID_, jid_);
- setTabOrder(jid_, byLocalSearch_);
- setTabOrder(byLocalSearch_, byRemoteSearch_);
- connect(jid_, SIGNAL(textChanged(const QString&)), this, SLOT(emitCompletenessCheck()));
- connect(jid_, SIGNAL(editingDone()), this, SLOT(emitCompletenessCheck()));
- connect(service_->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(emitCompletenessCheck()));
+ setupUi(this);
+ setTitle(title);
+ setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(type == UserSearchWindow::AddContact ? tr("Add another user to your contact list") : tr("Chat to another user")));
+ jid_ = new QtSuggestingJIDInput(this, settings);
+ horizontalLayout_2->addWidget(jid_);
+ jidWarning_ = new QLabel(this);
+ jidWarning_->setPixmap(QPixmap(":icons/warn.png"));
+ jidWarning_->hide();
+ horizontalLayout_2->addWidget(jidWarning_);
+ setTabOrder(byJID_, jid_);
+ setTabOrder(jid_, byLocalSearch_);
+ setTabOrder(byLocalSearch_, byRemoteSearch_);
+ connect(jid_, SIGNAL(textChanged(const QString&)), this, SLOT(emitCompletenessCheck()));
+ connect(jid_, SIGNAL(editingDone()), this, SLOT(emitCompletenessCheck()));
+ connect(service_->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(emitCompletenessCheck()));
}
bool QtUserSearchFirstPage::isComplete() const {
- bool complete = false;
- if (byJID_->isChecked()) {
- complete = JID(Q2PSTRING(jid_->text().trimmed())).isValid() && jidWarning_->toolTip().isEmpty();
- } else if (byLocalSearch_->isChecked()) {
- complete = true;
- } else if (byRemoteSearch_->isChecked()) {
- complete = JID(Q2PSTRING(service_->currentText().trimmed())).isValid();
- }
- return complete;
+ bool complete = false;
+ if (byJID_->isChecked()) {
+ complete = JID(Q2PSTRING(jid_->text().trimmed())).isValid() && jidWarning_->toolTip().isEmpty();
+ } else if (byLocalSearch_->isChecked()) {
+ complete = true;
+ } else if (byRemoteSearch_->isChecked()) {
+ complete = JID(Q2PSTRING(service_->currentText().trimmed())).isValid();
+ }
+ return complete;
}
void QtUserSearchFirstPage::emitCompletenessCheck() {
- emit completeChanged();
+ emit completeChanged();
}
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.h b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.h
index 9e765a0..2e73e9e 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.h
@@ -14,20 +14,20 @@
#include <Swift/QtUI/UserSearch/ui_QtUserSearchFirstPage.h>
namespace Swift {
- class UserSearchModel;
- class UserSearchDelegate;
- class UserSearchResult;
- class UIEventStream;
+ class UserSearchModel;
+ class UserSearchDelegate;
+ class UserSearchResult;
+ class UIEventStream;
- class QtUserSearchFirstPage : public QWizardPage, public Ui::QtUserSearchFirstPage {
- Q_OBJECT
- public:
- QtUserSearchFirstPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings);
- virtual bool isComplete() const;
- public slots:
- void emitCompletenessCheck();
- public:
- QtSuggestingJIDInput* jid_;
- QLabel* jidWarning_;
- };
+ class QtUserSearchFirstPage : public QWizardPage, public Ui::QtUserSearchFirstPage {
+ Q_OBJECT
+ public:
+ QtUserSearchFirstPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings);
+ virtual bool isComplete() const;
+ public slots:
+ void emitCompletenessCheck();
+ public:
+ QtSuggestingJIDInput* jid_;
+ QLabel* jidWarning_;
+ };
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchResultsPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchResultsPage.cpp
index 6ec4a34..c8a9ad8 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchResultsPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchResultsPage.cpp
@@ -9,31 +9,31 @@
namespace Swift {
QtUserSearchResultsPage::QtUserSearchResultsPage() {
- setupUi(this);
- connect(results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
- connect(results_, SIGNAL(activated(const QModelIndex&)), this, SIGNAL(onUserTriggersContinue()));
- connect(results_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
- connect(results_, SIGNAL(entered(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
- results_->setExpandsOnDoubleClick(false);
- setNoResults(false);
+ setupUi(this);
+ connect(results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
+ connect(results_, SIGNAL(activated(const QModelIndex&)), this, SIGNAL(onUserTriggersContinue()));
+ connect(results_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
+ connect(results_, SIGNAL(entered(const QModelIndex&)), this, SLOT(emitCompletenessCheck()));
+ results_->setExpandsOnDoubleClick(false);
+ setNoResults(false);
}
bool QtUserSearchResultsPage::isComplete() const {
- return results_->currentIndex().isValid();
+ return results_->currentIndex().isValid();
}
void QtUserSearchResultsPage::setNoResults(bool noResults) {
- if (noResults) {
- results_->setEnabled(false);
- noResults_->show();
- } else {
- results_->setEnabled(true);
- noResults_->hide();
- }
+ if (noResults) {
+ results_->setEnabled(false);
+ noResults_->show();
+ } else {
+ results_->setEnabled(true);
+ noResults_->hide();
+ }
}
void QtUserSearchResultsPage::emitCompletenessCheck() {
- emit completeChanged();
+ emit completeChanged();
}
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchResultsPage.h b/Swift/QtUI/UserSearch/QtUserSearchResultsPage.h
index d2ee566..33227e6 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchResultsPage.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchResultsPage.h
@@ -11,15 +11,15 @@
#include <Swift/QtUI/UserSearch/ui_QtUserSearchResultsPage.h>
namespace Swift {
- class QtUserSearchResultsPage : public QWizardPage, public Ui::QtUserSearchResultsPage {
- Q_OBJECT
- public:
- QtUserSearchResultsPage();
- virtual bool isComplete() const;
- void setNoResults(bool noResults);
- signals:
- void onUserTriggersContinue();
- public slots:
- void emitCompletenessCheck();
- };
+ class QtUserSearchResultsPage : public QWizardPage, public Ui::QtUserSearchResultsPage {
+ Q_OBJECT
+ public:
+ QtUserSearchResultsPage();
+ virtual bool isComplete() const;
+ void setNoResults(bool noResults);
+ signals:
+ void onUserTriggersContinue();
+ public slots:
+ void emitCompletenessCheck();
+ };
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
index 52b17b0..1140b6e 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
@@ -37,592 +37,592 @@
namespace Swift {
QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups, SettingsProvider* settingsProvider) : eventStream_(eventStream), type_(type), model_(NULL), firstMultiJIDPage_(NULL), settings_(settingsProvider), searchNext_(false), supportsImpromptu_(false) {
- setupUi(this);
+ setupUi(this);
#ifndef Q_OS_MAC
#ifdef Q_OS_WIN32
- setWindowIcon(QIcon(":/logo-icon-16-win.png"));
+ setWindowIcon(QIcon(":/logo-icon-16-win.png"));
#else
- setWindowIcon(QIcon(":/logo-icon-16.png"));
+ setWindowIcon(QIcon(":/logo-icon-16.png"));
#endif
#endif
- QString title;
- switch(type) {
- case AddContact:
- title = tr("Add Contact");
- break;
- case ChatToContact:
- title = tr("Chat to Users");
- break;
- case InviteToChat:
- title = tr("Add Users to Chat");
- break;
- }
- setWindowTitle(title);
-
- delegate_ = new UserSearchDelegate(this);
-
- setFirstPage(title);
- setSecondPage();
- setThirdPage();
-
- detailsPage_ = new QtUserSearchDetailsPage(groups);
- setPage(4, detailsPage_);
-
- connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(handleCurrentChanged(int)));
- connect(this, SIGNAL(accepted()), this, SLOT(handleAccepted()));
- clear();
+ QString title;
+ switch(type) {
+ case AddContact:
+ title = tr("Add Contact");
+ break;
+ case ChatToContact:
+ title = tr("Chat to Users");
+ break;
+ case InviteToChat:
+ title = tr("Add Users to Chat");
+ break;
+ }
+ setWindowTitle(title);
+
+ delegate_ = new UserSearchDelegate(this);
+
+ setFirstPage(title);
+ setSecondPage();
+ setThirdPage();
+
+ detailsPage_ = new QtUserSearchDetailsPage(groups);
+ setPage(4, detailsPage_);
+
+ connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(handleCurrentChanged(int)));
+ connect(this, SIGNAL(accepted()), this, SLOT(handleAccepted()));
+ clear();
}
QtUserSearchWindow::~QtUserSearchWindow() {
- delete model_;
+ delete model_;
}
void QtUserSearchWindow::handleCurrentChanged(int page) {
- searchNext_ = false;
- if (firstMultiJIDPage_) {
- firstMultiJIDPage_->reset();
- }
- resultsPage_->emitCompletenessCheck();
- if (page == 1 && lastPage_ == 3) {
- addSearchedJIDToList(getContact());
- setSecondPage();
- }
- else if (page == 2 && lastPage_ == 1) {
- setError("");
- /* next won't be called if JID is selected */
- JID server = getServerToSearch();
- clearForm();
- onFormRequested(server);
- setThirdPage();
- }
- else if (page == 3 && lastPage_ == 2) {
- JID server = getServerToSearch();
- handleSearch();
-
- if (type_ == AddContact) {
- bool remote = firstPage_->byRemoteSearch_->isChecked();
- firstPage_->byRemoteSearch_->setChecked(remote);
- firstPage_->service_->setEditText(P2QSTRING(server.toString()));
- } else {
- bool remote = firstMultiJIDPage_->byRemoteSearch_->isChecked();
- setFirstPage();
- firstMultiJIDPage_->byRemoteSearch_->setChecked(remote);
- firstMultiJIDPage_->service_->setEditText(P2QSTRING(server.toString()));
- }
- }
- else if (page == 4) {
- detailsPage_->clear();
- detailsPage_->setJID(getContactJID());
- onNameSuggestionRequested(getContactJID());
- }
- lastPage_ = page;
+ searchNext_ = false;
+ if (firstMultiJIDPage_) {
+ firstMultiJIDPage_->reset();
+ }
+ resultsPage_->emitCompletenessCheck();
+ if (page == 1 && lastPage_ == 3) {
+ addSearchedJIDToList(getContact());
+ setSecondPage();
+ }
+ else if (page == 2 && lastPage_ == 1) {
+ setError("");
+ /* next won't be called if JID is selected */
+ JID server = getServerToSearch();
+ clearForm();
+ onFormRequested(server);
+ setThirdPage();
+ }
+ else if (page == 3 && lastPage_ == 2) {
+ JID server = getServerToSearch();
+ handleSearch();
+
+ if (type_ == AddContact) {
+ bool remote = firstPage_->byRemoteSearch_->isChecked();
+ firstPage_->byRemoteSearch_->setChecked(remote);
+ firstPage_->service_->setEditText(P2QSTRING(server.toString()));
+ } else {
+ bool remote = firstMultiJIDPage_->byRemoteSearch_->isChecked();
+ setFirstPage();
+ firstMultiJIDPage_->byRemoteSearch_->setChecked(remote);
+ firstMultiJIDPage_->service_->setEditText(P2QSTRING(server.toString()));
+ }
+ }
+ else if (page == 4) {
+ detailsPage_->clear();
+ detailsPage_->setJID(getContactJID());
+ onNameSuggestionRequested(getContactJID());
+ }
+ lastPage_ = page;
}
JID QtUserSearchWindow::getServerToSearch() {
- if (type_ == AddContact) {
- return firstPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstPage_->service_->currentText().trimmed())) : myServer_;
- } else {
- return firstMultiJIDPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstMultiJIDPage_->service_->currentText().trimmed())) : myServer_;
- }
+ if (type_ == AddContact) {
+ return firstPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstPage_->service_->currentText().trimmed())) : myServer_;
+ } else {
+ return firstMultiJIDPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstMultiJIDPage_->service_->currentText().trimmed())) : myServer_;
+ }
}
void QtUserSearchWindow::handleAccepted() {
- JID jid;
- std::vector<JID> jids;
- switch(type_) {
- case AddContact:
- jid = getContactJID();
- eventStream_->send(boost::make_shared<AddContactUIEvent>(jid, detailsPage_->getName(), detailsPage_->getSelectedGroups()));
- break;
- case ChatToContact:
- if (contactVector_.size() == 1) {
- boost::shared_ptr<UIEvent> event(new RequestChatUIEvent(contactVector_[0]->jid));
- eventStream_->send(event);
- break;
- }
-
- foreach(Contact::ref contact, contactVector_) {
- jids.push_back(contact->jid);
- }
-
- eventStream_->send(boost::make_shared<CreateImpromptuMUCUIEvent>(jids, JID(), Q2PSTRING(firstMultiJIDPage_->reason_->text())));
- break;
- case InviteToChat:
- foreach(Contact::ref contact, contactVector_) {
- jids.push_back(contact->jid);
- }
- eventStream_->send(boost::make_shared<InviteToMUCUIEvent>(roomJID_, jids, Q2PSTRING(firstMultiJIDPage_->reason_->text())));
- break;
- }
+ JID jid;
+ std::vector<JID> jids;
+ switch(type_) {
+ case AddContact:
+ jid = getContactJID();
+ eventStream_->send(boost::make_shared<AddContactUIEvent>(jid, detailsPage_->getName(), detailsPage_->getSelectedGroups()));
+ break;
+ case ChatToContact:
+ if (contactVector_.size() == 1) {
+ boost::shared_ptr<UIEvent> event(new RequestChatUIEvent(contactVector_[0]->jid));
+ eventStream_->send(event);
+ break;
+ }
+
+ foreach(Contact::ref contact, contactVector_) {
+ jids.push_back(contact->jid);
+ }
+
+ eventStream_->send(boost::make_shared<CreateImpromptuMUCUIEvent>(jids, JID(), Q2PSTRING(firstMultiJIDPage_->reason_->text())));
+ break;
+ case InviteToChat:
+ foreach(Contact::ref contact, contactVector_) {
+ jids.push_back(contact->jid);
+ }
+ eventStream_->send(boost::make_shared<InviteToMUCUIEvent>(roomJID_, jids, Q2PSTRING(firstMultiJIDPage_->reason_->text())));
+ break;
+ }
}
void QtUserSearchWindow::handleContactSuggestionRequested(const QString& text) {
- std::string stdText = Q2PSTRING(text);
- onContactSuggestionsRequested(stdText);
+ std::string stdText = Q2PSTRING(text);
+ onContactSuggestionsRequested(stdText);
}
void QtUserSearchWindow::addContact() {
- if (!!firstMultiJIDPage_->jid_->getContact()) {
- contactVector_.push_back(firstMultiJIDPage_->jid_->getContact());
- firstMultiJIDPage_->jid_->clear();
- }
- firstMultiJIDPage_->contactList_->setList(contactVector_);
- firstMultiJIDPage_->emitCompletenessCheck();
- if (type_ == ChatToContact) {
- firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
- }
+ if (!!firstMultiJIDPage_->jid_->getContact()) {
+ contactVector_.push_back(firstMultiJIDPage_->jid_->getContact());
+ firstMultiJIDPage_->jid_->clear();
+ }
+ firstMultiJIDPage_->contactList_->setList(contactVector_);
+ firstMultiJIDPage_->emitCompletenessCheck();
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
+ }
}
void QtUserSearchWindow::setWarning(const boost::optional<std::string>& message) {
- if (message) {
- firstPage_->jidWarning_->setToolTip(P2QSTRING((*message)));
- firstPage_->jidWarning_->setAccessibleDescription(P2QSTRING((*message)));
- firstPage_->jidWarning_->show();
- }
- else {
- firstPage_->jidWarning_->setToolTip("");
- firstPage_->jidWarning_->setAccessibleDescription("");
- firstPage_->jidWarning_->hide();
- }
- firstPage_->emitCompletenessCheck();
+ if (message) {
+ firstPage_->jidWarning_->setToolTip(P2QSTRING((*message)));
+ firstPage_->jidWarning_->setAccessibleDescription(P2QSTRING((*message)));
+ firstPage_->jidWarning_->show();
+ }
+ else {
+ firstPage_->jidWarning_->setToolTip("");
+ firstPage_->jidWarning_->setAccessibleDescription("");
+ firstPage_->jidWarning_->hide();
+ }
+ firstPage_->emitCompletenessCheck();
}
int QtUserSearchWindow::nextId() const {
- if (type_ == AddContact) {
- switch (currentId()) {
- case 1: return firstPage_->byJID_->isChecked() ? (type_ == AddContact ? 4 : -1) : 2;
- case 2: return 3;
- case 3: return type_ == AddContact ? 4 : -1;
- case 4: return -1;
- default: return -1;
- }
- } else {
- switch (currentId()) {
- case 1: return searchNext_ ? 2 : -1;
- case 2: return 3;
- case 3: return 1;
- case 4: return -1;
- default: return -1;
- }
- }
+ if (type_ == AddContact) {
+ switch (currentId()) {
+ case 1: return firstPage_->byJID_->isChecked() ? (type_ == AddContact ? 4 : -1) : 2;
+ case 2: return 3;
+ case 3: return type_ == AddContact ? 4 : -1;
+ case 4: return -1;
+ default: return -1;
+ }
+ } else {
+ switch (currentId()) {
+ case 1: return searchNext_ ? 2 : -1;
+ case 2: return 3;
+ case 3: return 1;
+ case 4: return -1;
+ default: return -1;
+ }
+ }
}
void QtUserSearchWindow::handleFirstPageRadioChange() {
- if (firstPage_->byJID_->isChecked()) {
- firstPage_->jid_->setText("");
- firstPage_->jid_->setEnabled(true);
- firstPage_->service_->setEnabled(false);
- restart();
- }
- else if (firstPage_->byRemoteSearch_->isChecked()) {
- firstPage_->service_->setEditText("");
- firstPage_->jid_->setEnabled(false);
- firstPage_->service_->setEnabled(true);
- //firstPage_->jid_->setText("");
- restart();
- }
- else {
- firstPage_->jid_->setEnabled(false);
- firstPage_->service_->setEnabled(false);
- restart();
- }
+ if (firstPage_->byJID_->isChecked()) {
+ firstPage_->jid_->setText("");
+ firstPage_->jid_->setEnabled(true);
+ firstPage_->service_->setEnabled(false);
+ restart();
+ }
+ else if (firstPage_->byRemoteSearch_->isChecked()) {
+ firstPage_->service_->setEditText("");
+ firstPage_->jid_->setEnabled(false);
+ firstPage_->service_->setEnabled(true);
+ //firstPage_->jid_->setText("");
+ restart();
+ }
+ else {
+ firstPage_->jid_->setEnabled(false);
+ firstPage_->service_->setEnabled(false);
+ restart();
+ }
}
void QtUserSearchWindow::handleSearch() {
- boost::shared_ptr<SearchPayload> search(new SearchPayload());
- if (fieldsPage_->getFormWidget()) {
- search->setForm(fieldsPage_->getFormWidget()->getCompletedForm());
- search->getForm()->clearEmptyTextFields();
- } else {
- if (fieldsPage_->nickInput_->isEnabled() && !fieldsPage_->nickInput_->text().isEmpty()) {
- search->setNick(Q2PSTRING(fieldsPage_->nickInput_->text()));
- }
- if (fieldsPage_->firstInput_->isEnabled() && !fieldsPage_->firstInput_->text().isEmpty()) {
- search->setFirst(Q2PSTRING(fieldsPage_->firstInput_->text()));
- }
- if (fieldsPage_->lastInput_->isEnabled() && !fieldsPage_->lastInput_->text().isEmpty()) {
- search->setLast(Q2PSTRING(fieldsPage_->lastInput_->text()));
- }
- if (fieldsPage_->emailInput_->isEnabled() && !fieldsPage_->emailInput_->text().isEmpty()) {
- search->setEMail(Q2PSTRING(fieldsPage_->emailInput_->text()));
- }
- }
- onSearchRequested(search, getServerToSearch());
+ boost::shared_ptr<SearchPayload> search(new SearchPayload());
+ if (fieldsPage_->getFormWidget()) {
+ search->setForm(fieldsPage_->getFormWidget()->getCompletedForm());
+ search->getForm()->clearEmptyTextFields();
+ } else {
+ if (fieldsPage_->nickInput_->isEnabled() && !fieldsPage_->nickInput_->text().isEmpty()) {
+ search->setNick(Q2PSTRING(fieldsPage_->nickInput_->text()));
+ }
+ if (fieldsPage_->firstInput_->isEnabled() && !fieldsPage_->firstInput_->text().isEmpty()) {
+ search->setFirst(Q2PSTRING(fieldsPage_->firstInput_->text()));
+ }
+ if (fieldsPage_->lastInput_->isEnabled() && !fieldsPage_->lastInput_->text().isEmpty()) {
+ search->setLast(Q2PSTRING(fieldsPage_->lastInput_->text()));
+ }
+ if (fieldsPage_->emailInput_->isEnabled() && !fieldsPage_->emailInput_->text().isEmpty()) {
+ search->setEMail(Q2PSTRING(fieldsPage_->emailInput_->text()));
+ }
+ }
+ onSearchRequested(search, getServerToSearch());
}
JID QtUserSearchWindow::getContactJID() const {
- JID jid;
-
- bool useSearchResult;
- if (type_ == AddContact) {
- useSearchResult = !firstPage_->byJID_->isChecked();
- } else {
- useSearchResult = true;
- }
-
- if (useSearchResult) {
- if (dynamic_cast<UserSearchModel*>(model_)) {
- UserSearchResult* userItem = static_cast<UserSearchResult*>(resultsPage_->results_->currentIndex().internalPointer());
- if (userItem) { /* Remember to leave this if we change to dynamic cast */
- jid = userItem->getJID();
- }
- } else if (dynamic_cast<QtFormResultItemModel*>(model_)) {
- int row = resultsPage_->results_->currentIndex().row();
-
- Form::FormItem item = dynamic_cast<QtFormResultItemModel*>(model_)->getForm()->getItems().at(row);
- JID fallbackJid;
- foreach(FormField::ref field, item) {
- if (field->getType() == FormField::JIDSingleType) {
- jid = JID(field->getJIDSingleValue());
- break;
- }
- if (field->getName() == "jid") {
- fallbackJid = field->getValues()[0];
- }
- }
- if (!jid.isValid()) {
- jid = fallbackJid;
- }
- }
- }
- else {
- jid = JID(Q2PSTRING(firstPage_->jid_->text().trimmed()));
- }
- return jid;
+ JID jid;
+
+ bool useSearchResult;
+ if (type_ == AddContact) {
+ useSearchResult = !firstPage_->byJID_->isChecked();
+ } else {
+ useSearchResult = true;
+ }
+
+ if (useSearchResult) {
+ if (dynamic_cast<UserSearchModel*>(model_)) {
+ UserSearchResult* userItem = static_cast<UserSearchResult*>(resultsPage_->results_->currentIndex().internalPointer());
+ if (userItem) { /* Remember to leave this if we change to dynamic cast */
+ jid = userItem->getJID();
+ }
+ } else if (dynamic_cast<QtFormResultItemModel*>(model_)) {
+ int row = resultsPage_->results_->currentIndex().row();
+
+ Form::FormItem item = dynamic_cast<QtFormResultItemModel*>(model_)->getForm()->getItems().at(row);
+ JID fallbackJid;
+ foreach(FormField::ref field, item) {
+ if (field->getType() == FormField::JIDSingleType) {
+ jid = JID(field->getJIDSingleValue());
+ break;
+ }
+ if (field->getName() == "jid") {
+ fallbackJid = field->getValues()[0];
+ }
+ }
+ if (!jid.isValid()) {
+ jid = fallbackJid;
+ }
+ }
+ }
+ else {
+ jid = JID(Q2PSTRING(firstPage_->jid_->text().trimmed()));
+ }
+ return jid;
}
Contact::ref QtUserSearchWindow::getContact() const {
- return boost::make_shared<Contact>("", getContactJID(), StatusShow::None, "");
+ return boost::make_shared<Contact>("", getContactJID(), StatusShow::None, "");
}
void QtUserSearchWindow::addSearchedJIDToList(const Contact::ref& contact) {
- std::vector<JID> jids;
- jids.push_back(contact->jid);
- handleJIDsAdded(jids);
- firstMultiJIDPage_->jid_->clear();
+ std::vector<JID> jids;
+ jids.push_back(contact->jid);
+ handleJIDsAdded(jids);
+ firstMultiJIDPage_->jid_->clear();
}
void QtUserSearchWindow::handleOnSearchedJIDSelected(const Contact::ref& contact) {
- firstPage_->jid_->setText(P2QSTRING(contact->jid.toString()));
+ firstPage_->jid_->setText(P2QSTRING(contact->jid.toString()));
}
void QtUserSearchWindow::show() {
- clear();
- if (type_ == AddContact) {
- setWarning(boost::optional<std::string>());
- }
- QWidget::show();
+ clear();
+ if (type_ == AddContact) {
+ setWarning(boost::optional<std::string>());
+ }
+ QWidget::show();
}
void QtUserSearchWindow::addSavedServices(const std::vector<JID>& services) {
- if (type_ == AddContact) {
- firstPage_->service_->clear();
- foreach (JID jid, services) {
- firstPage_->service_->addItem(P2QSTRING(jid.toString()));
- }
- firstPage_->service_->clearEditText();
- } else {
- firstMultiJIDPage_->service_->clear();
- foreach (JID jid, services) {
- firstMultiJIDPage_->service_->addItem(P2QSTRING(jid.toString()));
- }
- firstMultiJIDPage_->service_->clearEditText();
- }
+ if (type_ == AddContact) {
+ firstPage_->service_->clear();
+ foreach (JID jid, services) {
+ firstPage_->service_->addItem(P2QSTRING(jid.toString()));
+ }
+ firstPage_->service_->clearEditText();
+ } else {
+ firstMultiJIDPage_->service_->clear();
+ foreach (JID jid, services) {
+ firstMultiJIDPage_->service_->addItem(P2QSTRING(jid.toString()));
+ }
+ firstMultiJIDPage_->service_->clearEditText();
+ }
}
void QtUserSearchWindow::setSearchFields(boost::shared_ptr<SearchPayload> fields) {
- fieldsPage_->fetchingThrobber_->hide();
- fieldsPage_->fetchingThrobber_->movie()->stop();
- fieldsPage_->fetchingLabel_->hide();
-
- fieldsPage_->instructionsLabel_->setText(fields->getInstructions() ? P2QSTRING(fields->getInstructions().get()) : "Enter search terms");
- if (fields->getForm()) {
- fieldsPage_->setFormWidget(new QtFormWidget(fields->getForm(), fieldsPage_));
- } else {
- fieldsPage_->setFormWidget(NULL);
- bool enabled[8] = {!!fields->getNick(), !!fields->getNick(), !!fields->getFirst(), !!fields->getFirst(), !!fields->getLast(), !!fields->getLast(), !!fields->getEMail(), !!fields->getEMail()};
- QWidget* legacySearchWidgets[8] = {fieldsPage_->nickInputLabel_, fieldsPage_->nickInput_, fieldsPage_->firstInputLabel_, fieldsPage_->firstInput_, fieldsPage_->lastInputLabel_, fieldsPage_->lastInput_, fieldsPage_->emailInputLabel_, fieldsPage_->emailInput_};
- for (int i = 0; i < 8; i++) {
- legacySearchWidgets[i]->setVisible(enabled[i]);
- legacySearchWidgets[i]->setEnabled(enabled[i]);
- }
- }
- fieldsPage_->emitCompletenessCheck();
+ fieldsPage_->fetchingThrobber_->hide();
+ fieldsPage_->fetchingThrobber_->movie()->stop();
+ fieldsPage_->fetchingLabel_->hide();
+
+ fieldsPage_->instructionsLabel_->setText(fields->getInstructions() ? P2QSTRING(fields->getInstructions().get()) : "Enter search terms");
+ if (fields->getForm()) {
+ fieldsPage_->setFormWidget(new QtFormWidget(fields->getForm(), fieldsPage_));
+ } else {
+ fieldsPage_->setFormWidget(NULL);
+ bool enabled[8] = {!!fields->getNick(), !!fields->getNick(), !!fields->getFirst(), !!fields->getFirst(), !!fields->getLast(), !!fields->getLast(), !!fields->getEMail(), !!fields->getEMail()};
+ QWidget* legacySearchWidgets[8] = {fieldsPage_->nickInputLabel_, fieldsPage_->nickInput_, fieldsPage_->firstInputLabel_, fieldsPage_->firstInput_, fieldsPage_->lastInputLabel_, fieldsPage_->lastInput_, fieldsPage_->emailInputLabel_, fieldsPage_->emailInput_};
+ for (int i = 0; i < 8; i++) {
+ legacySearchWidgets[i]->setVisible(enabled[i]);
+ legacySearchWidgets[i]->setEnabled(enabled[i]);
+ }
+ }
+ fieldsPage_->emitCompletenessCheck();
}
void QtUserSearchWindow::setNameSuggestions(const std::vector<std::string>& suggestions) {
- if (detailsPage_) {
- detailsPage_->setNameSuggestions(suggestions);
- }
+ if (detailsPage_) {
+ detailsPage_->setNameSuggestions(suggestions);
+ }
}
void QtUserSearchWindow::prepopulateJIDAndName(const JID& jid, const std::string& name) {
- firstPage_->jid_->setText(P2QSTRING(jid.toBare().toString()));
- detailsPage_->setJID(jid);
- lastPage_ = 1;
- restart();
- next();
- detailsPage_->setName(name);
+ firstPage_->jid_->setText(P2QSTRING(jid.toBare().toString()));
+ detailsPage_->setJID(jid);
+ lastPage_ = 1;
+ restart();
+ next();
+ detailsPage_->setName(name);
}
void QtUserSearchWindow::setContactSuggestions(const std::vector<Contact::ref>& suggestions) {
- if (type_ == AddContact) {
- firstPage_->jid_->setSuggestions(suggestions);
- } else {
- firstMultiJIDPage_->jid_->setSuggestions(suggestions);
- }
+ if (type_ == AddContact) {
+ firstPage_->jid_->setSuggestions(suggestions);
+ } else {
+ firstMultiJIDPage_->jid_->setSuggestions(suggestions);
+ }
}
void QtUserSearchWindow::setJIDs(const std::vector<JID> &jids) {
- foreach(JID jid, jids) {
- addSearchedJIDToList(boost::make_shared<Contact>("", jid, StatusShow::None, ""));
- }
- onJIDUpdateRequested(jids);
+ foreach(JID jid, jids) {
+ addSearchedJIDToList(boost::make_shared<Contact>("", jid, StatusShow::None, ""));
+ }
+ onJIDUpdateRequested(jids);
}
void QtUserSearchWindow::setRoomJID(const JID& roomJID) {
- roomJID_ = roomJID;
+ roomJID_ = roomJID;
}
std::string QtUserSearchWindow::getReason() const {
- return Q2PSTRING(firstMultiJIDPage_->reason_->text());
+ return Q2PSTRING(firstMultiJIDPage_->reason_->text());
}
std::vector<JID> QtUserSearchWindow::getJIDs() const {
- std::vector<JID> jids;
- foreach (Contact::ref contact, contactVector_) {
- jids.push_back(contact->jid);
- }
- return jids;
+ std::vector<JID> jids;
+ foreach (Contact::ref contact, contactVector_) {
+ jids.push_back(contact->jid);
+ }
+ return jids;
}
void QtUserSearchWindow::setCanStartImpromptuChats(bool supportsImpromptu) {
- supportsImpromptu_ = supportsImpromptu;
- if (type_ == ChatToContact) {
- firstMultiJIDPage_->contactList_->setMaximumNoOfContactsToOne(!supportsImpromptu_);
- }
+ supportsImpromptu_ = supportsImpromptu;
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->contactList_->setMaximumNoOfContactsToOne(!supportsImpromptu_);
+ }
}
void QtUserSearchWindow::updateContacts(const std::vector<Contact::ref>& contacts) {
- if (type_ != AddContact) {
- firstMultiJIDPage_->contactList_->updateContacts(contacts);
- }
+ if (type_ != AddContact) {
+ firstMultiJIDPage_->contactList_->updateContacts(contacts);
+ }
}
void QtUserSearchWindow::addContacts(const std::vector<Contact::ref>& contacts) {
- if (type_ != AddContact) {
- /* prevent duplicate JIDs from appearing in the contact list */
- foreach (Contact::ref newContact, contacts) {
- bool found = false;
- foreach (Contact::ref oldContact, contactVector_) {
- if (newContact->jid == oldContact->jid) {
- found = true;
- break;
- }
- }
- if (!found) {
- contactVector_.push_back(newContact);
- }
- }
- if (!supportsImpromptu_ && contactVector_.size() > 1) {
- contactVector_.resize(1); /* can't chat with more than one user */
- }
- firstMultiJIDPage_->contactList_->setList(contactVector_);
- firstMultiJIDPage_->emitCompletenessCheck();
- if (type_ == ChatToContact) {
- firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? true : (contactVector_.size() < 1));
- }
- }
+ if (type_ != AddContact) {
+ /* prevent duplicate JIDs from appearing in the contact list */
+ foreach (Contact::ref newContact, contacts) {
+ bool found = false;
+ foreach (Contact::ref oldContact, contactVector_) {
+ if (newContact->jid == oldContact->jid) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ contactVector_.push_back(newContact);
+ }
+ }
+ if (!supportsImpromptu_ && contactVector_.size() > 1) {
+ contactVector_.resize(1); /* can't chat with more than one user */
+ }
+ firstMultiJIDPage_->contactList_->setList(contactVector_);
+ firstMultiJIDPage_->emitCompletenessCheck();
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? true : (contactVector_.size() < 1));
+ }
+ }
}
void QtUserSearchWindow::setCanSupplyDescription(bool allowed) {
- firstMultiJIDPage_->label->setVisible(allowed);
- firstMultiJIDPage_->reason_->setVisible(allowed);
+ firstMultiJIDPage_->label->setVisible(allowed);
+ firstMultiJIDPage_->reason_->setVisible(allowed);
}
void QtUserSearchWindow::handleAddViaSearch() {
- searchNext_ = true;
- next();
+ searchNext_ = true;
+ next();
}
void QtUserSearchWindow::handleListChanged(std::vector<Contact::ref> list) {
- contactVector_ = list;
- if (type_ == ChatToContact) {
- firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
- }
+ contactVector_ = list;
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
+ }
}
void QtUserSearchWindow::handleJIDsAdded(std::vector<JID> jids) {
- onJIDAddRequested(jids);
+ onJIDAddRequested(jids);
}
void QtUserSearchWindow::setResults(const std::vector<UserSearchResult>& results) {
- UserSearchModel *newModel = new UserSearchModel();
- newModel->setResults(results);
- resultsPage_->results_->setModel(newModel);
- resultsPage_->results_->setItemDelegate(delegate_);
- resultsPage_->results_->setHeaderHidden(true);
- delete model_;
- model_ = newModel;
- resultsPage_->setNoResults(model_->rowCount() == 0);
- resultsPage_->emitCompletenessCheck();
+ UserSearchModel *newModel = new UserSearchModel();
+ newModel->setResults(results);
+ resultsPage_->results_->setModel(newModel);
+ resultsPage_->results_->setItemDelegate(delegate_);
+ resultsPage_->results_->setHeaderHidden(true);
+ delete model_;
+ model_ = newModel;
+ resultsPage_->setNoResults(model_->rowCount() == 0);
+ resultsPage_->emitCompletenessCheck();
}
void QtUserSearchWindow::setResultsForm(Form::ref results) {
- QtFormResultItemModel *newModel = new QtFormResultItemModel(this);
- newModel->setForm(results);
- resultsPage_->results_->setModel(newModel);
- resultsPage_->results_->setItemDelegate(new QItemDelegate());
- resultsPage_->results_->setHeaderHidden(false);
+ QtFormResultItemModel *newModel = new QtFormResultItemModel(this);
+ newModel->setForm(results);
+ resultsPage_->results_->setModel(newModel);
+ resultsPage_->results_->setItemDelegate(new QItemDelegate());
+ resultsPage_->results_->setHeaderHidden(false);
#if QT_VERSION >= 0x050000
- resultsPage_->results_->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+ resultsPage_->results_->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
- resultsPage_->results_->header()->setResizeMode(QHeaderView::ResizeToContents);
+ resultsPage_->results_->header()->setResizeMode(QHeaderView::ResizeToContents);
#endif
- delete model_;
- model_ = newModel;
- resultsPage_->setNoResults(model_->rowCount() == 0);
- resultsPage_->emitCompletenessCheck();
+ delete model_;
+ model_ = newModel;
+ resultsPage_->setNoResults(model_->rowCount() == 0);
+ resultsPage_->emitCompletenessCheck();
}
void QtUserSearchWindow::setSelectedService(const JID& jid) {
- myServer_ = jid;
+ myServer_ = jid;
}
void QtUserSearchWindow::handleJIDEditingDone() {
- onJIDEditFieldChanged(JID(Q2PSTRING(firstPage_->jid_->text())));
+ onJIDEditFieldChanged(JID(Q2PSTRING(firstPage_->jid_->text())));
}
void QtUserSearchWindow::setFirstPage(QString title) {
- if (page(1) != 0) {
- removePage(1);
- }
- if (type_ == AddContact) {
- firstPage_ = new QtUserSearchFirstPage(type_, title.isEmpty() ? firstPage_->title() : title, settings_);
- connect(firstPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleContactSuggestionRequested(QString)));
- connect(firstPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleJIDEditingDone()), Qt::UniqueConnection);
- firstPage_->jid_->onUserSelected.connect(boost::bind(&QtUserSearchWindow::handleOnSearchedJIDSelected, this, _1));
- connect(firstPage_->byJID_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
- connect(firstPage_->byLocalSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
- connect(firstPage_->byRemoteSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
+ if (page(1) != 0) {
+ removePage(1);
+ }
+ if (type_ == AddContact) {
+ firstPage_ = new QtUserSearchFirstPage(type_, title.isEmpty() ? firstPage_->title() : title, settings_);
+ connect(firstPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleContactSuggestionRequested(QString)));
+ connect(firstPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleJIDEditingDone()), Qt::UniqueConnection);
+ firstPage_->jid_->onUserSelected.connect(boost::bind(&QtUserSearchWindow::handleOnSearchedJIDSelected, this, _1));
+ connect(firstPage_->byJID_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
+ connect(firstPage_->byLocalSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
+ connect(firstPage_->byRemoteSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
#if QT_VERSION >= 0x040700
- firstPage_->jid_->setPlaceholderText(tr("alice@wonderland.lit"));
+ firstPage_->jid_->setPlaceholderText(tr("alice@wonderland.lit"));
#endif
- firstPage_->service_->setEnabled(false);
- setPage(1, firstPage_);
- } else {
- firstMultiJIDPage_ = new QtUserSearchFirstMultiJIDPage(type_, title.isEmpty() ? firstMultiJIDPage_->title() : title, settings_);
- connect(firstMultiJIDPage_->addContactButton_, SIGNAL(clicked()), this, SLOT(addContact()));
- connect(firstMultiJIDPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleContactSuggestionRequested(QString)));
- firstMultiJIDPage_->jid_->onUserSelected.connect(boost::bind(&QtUserSearchWindow::addSearchedJIDToList, this, _1));
- connect(firstMultiJIDPage_->addViaSearchButton_, SIGNAL(clicked()), this, SLOT(handleAddViaSearch()));
- connect(firstMultiJIDPage_->contactList_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SLOT(handleListChanged(std::vector<Contact::ref>)));
- connect(firstMultiJIDPage_->contactList_, SIGNAL(onJIDsAdded(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>)));
- connect(firstMultiJIDPage_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>)));
- setPage(1, firstMultiJIDPage_);
- }
+ firstPage_->service_->setEnabled(false);
+ setPage(1, firstPage_);
+ } else {
+ firstMultiJIDPage_ = new QtUserSearchFirstMultiJIDPage(type_, title.isEmpty() ? firstMultiJIDPage_->title() : title, settings_);
+ connect(firstMultiJIDPage_->addContactButton_, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(firstMultiJIDPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleContactSuggestionRequested(QString)));
+ firstMultiJIDPage_->jid_->onUserSelected.connect(boost::bind(&QtUserSearchWindow::addSearchedJIDToList, this, _1));
+ connect(firstMultiJIDPage_->addViaSearchButton_, SIGNAL(clicked()), this, SLOT(handleAddViaSearch()));
+ connect(firstMultiJIDPage_->contactList_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SLOT(handleListChanged(std::vector<Contact::ref>)));
+ connect(firstMultiJIDPage_->contactList_, SIGNAL(onJIDsAdded(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>)));
+ connect(firstMultiJIDPage_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>)));
+ setPage(1, firstMultiJIDPage_);
+ }
}
void QtUserSearchWindow::setSecondPage() {
- if (page(2) != 0) {
- removePage(2);
- }
- fieldsPage_ = new QtUserSearchFieldsPage();
- fieldsPage_->fetchingThrobber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
- fieldsPage_->fetchingThrobber_->movie()->stop();
- setPage(2, fieldsPage_);
+ if (page(2) != 0) {
+ removePage(2);
+ }
+ fieldsPage_ = new QtUserSearchFieldsPage();
+ fieldsPage_->fetchingThrobber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
+ fieldsPage_->fetchingThrobber_->movie()->stop();
+ setPage(2, fieldsPage_);
}
void QtUserSearchWindow::setThirdPage() {
- if (page(3) != 0) {
- removePage(3);
- }
- resultsPage_ = new QtUserSearchResultsPage();
+ if (page(3) != 0) {
+ removePage(3);
+ }
+ resultsPage_ = new QtUserSearchResultsPage();
#ifdef SWIFT_PLATFORM_MACOSX
- resultsPage_->results_->setAlternatingRowColors(true);
+ resultsPage_->results_->setAlternatingRowColors(true);
#endif
- if (type_ == AddContact) {
- connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next()));
- }
- else {
- connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next()));
- }
- setPage(3, resultsPage_);
+ if (type_ == AddContact) {
+ connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next()));
+ }
+ else {
+ connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next()));
+ }
+ setPage(3, resultsPage_);
}
void QtUserSearchWindow::clearForm() {
- fieldsPage_->fetchingThrobber_->show();
- fieldsPage_->fetchingThrobber_->movie()->start();
- fieldsPage_->fetchingLabel_->show();
- QWidget* legacySearchWidgets[8] = {fieldsPage_->nickInputLabel_, fieldsPage_->nickInput_, fieldsPage_->firstInputLabel_, fieldsPage_->firstInput_, fieldsPage_->lastInputLabel_, fieldsPage_->lastInput_, fieldsPage_->emailInputLabel_, fieldsPage_->emailInput_};
- for (int i = 0; i < 8; i++) {
- legacySearchWidgets[i]->hide();
- if (QLineEdit* edit = qobject_cast<QLineEdit*>(legacySearchWidgets[i])) {
- edit->clear();
- }
- }
- fieldsPage_->emitCompletenessCheck();
+ fieldsPage_->fetchingThrobber_->show();
+ fieldsPage_->fetchingThrobber_->movie()->start();
+ fieldsPage_->fetchingLabel_->show();
+ QWidget* legacySearchWidgets[8] = {fieldsPage_->nickInputLabel_, fieldsPage_->nickInput_, fieldsPage_->firstInputLabel_, fieldsPage_->firstInput_, fieldsPage_->lastInputLabel_, fieldsPage_->lastInput_, fieldsPage_->emailInputLabel_, fieldsPage_->emailInput_};
+ for (int i = 0; i < 8; i++) {
+ legacySearchWidgets[i]->hide();
+ if (QLineEdit* edit = qobject_cast<QLineEdit*>(legacySearchWidgets[i])) {
+ edit->clear();
+ }
+ }
+ fieldsPage_->emitCompletenessCheck();
}
void QtUserSearchWindow::clear() {
- QString howText;
- if (type_ == AddContact) {
- firstPage_->errorLabel_->setVisible(false);
- howText = QString(tr("How would you like to find the user to add?"));
- firstPage_->howLabel_->setText(howText);
- firstPage_->byJID_->setChecked(true);
- handleFirstPageRadioChange();
- } else {
- contactVector_.clear();
- firstMultiJIDPage_->contactList_->setList(contactVector_);
- firstMultiJIDPage_->errorLabel_->setVisible(false);
- if (type_ == ChatToContact) {
- howText = QString(tr("List of participants:"));
- } else if (type_ == InviteToChat) {
- howText = QString(tr("Who do you want to invite to the chat?"));
- }
- firstMultiJIDPage_->howLabel_->setText(howText);
- }
- clearForm();
- resultsPage_->results_->setModel(NULL);
- delete model_;
- model_ = NULL;
- restart();
- lastPage_ = 1;
+ QString howText;
+ if (type_ == AddContact) {
+ firstPage_->errorLabel_->setVisible(false);
+ howText = QString(tr("How would you like to find the user to add?"));
+ firstPage_->howLabel_->setText(howText);
+ firstPage_->byJID_->setChecked(true);
+ handleFirstPageRadioChange();
+ } else {
+ contactVector_.clear();
+ firstMultiJIDPage_->contactList_->setList(contactVector_);
+ firstMultiJIDPage_->errorLabel_->setVisible(false);
+ if (type_ == ChatToContact) {
+ howText = QString(tr("List of participants:"));
+ } else if (type_ == InviteToChat) {
+ howText = QString(tr("Who do you want to invite to the chat?"));
+ }
+ firstMultiJIDPage_->howLabel_->setText(howText);
+ }
+ clearForm();
+ resultsPage_->results_->setModel(NULL);
+ delete model_;
+ model_ = NULL;
+ restart();
+ lastPage_ = 1;
}
void QtUserSearchWindow::setError(const QString& error) {
- if (error.isEmpty()) {
- if (type_ == AddContact) {
- firstPage_->errorLabel_->hide();
- } else {
- firstMultiJIDPage_->errorLabel_->hide();
- }
- }
- else {
- if (type_ == AddContact) {
- firstPage_->errorLabel_->setText(QString("<font color='red'>%1</font>").arg(error));
- firstPage_->errorLabel_->show();
- } else {
- firstMultiJIDPage_->errorLabel_->setText(QString("<font color='red'>%1</font>").arg(error));
- firstMultiJIDPage_->errorLabel_->show();
- }
- restart();
- lastPage_ = 1;
- }
+ if (error.isEmpty()) {
+ if (type_ == AddContact) {
+ firstPage_->errorLabel_->hide();
+ } else {
+ firstMultiJIDPage_->errorLabel_->hide();
+ }
+ }
+ else {
+ if (type_ == AddContact) {
+ firstPage_->errorLabel_->setText(QString("<font color='red'>%1</font>").arg(error));
+ firstPage_->errorLabel_->show();
+ } else {
+ firstMultiJIDPage_->errorLabel_->setText(QString("<font color='red'>%1</font>").arg(error));
+ firstMultiJIDPage_->errorLabel_->show();
+ }
+ restart();
+ lastPage_ = 1;
+ }
}
void QtUserSearchWindow::setSearchError(bool error) {
- if (error) {
- setError(tr("Error while searching"));
- }
+ if (error) {
+ setError(tr("Error while searching"));
+ }
}
void QtUserSearchWindow::setServerSupportsSearch(bool support) {
- if (!support) {
- setError(tr("This server doesn't support searching for users."));
- }
+ if (!support) {
+ setError(tr("This server doesn't support searching for users."));
+ }
}
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.h b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
index 81d6e85..bcef0b9 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
@@ -15,92 +15,92 @@
#include <Swift/QtUI/UserSearch/ui_QtUserSearchWizard.h>
namespace Swift {
- class UserSearchModel;
- class UserSearchDelegate;
- class UserSearchResult;
- class UIEventStream;
- class QtUserSearchFirstPage;
- class QtUserSearchFirstMultiJIDPage;
- class QtUserSearchFieldsPage;
- class QtUserSearchResultsPage;
- class QtUserSearchDetailsPage;
- class QtFormResultItemModel;
- class SettingsProvider;
+ class UserSearchModel;
+ class UserSearchDelegate;
+ class UserSearchResult;
+ class UIEventStream;
+ class QtUserSearchFirstPage;
+ class QtUserSearchFirstMultiJIDPage;
+ class QtUserSearchFieldsPage;
+ class QtUserSearchResultsPage;
+ class QtUserSearchDetailsPage;
+ class QtFormResultItemModel;
+ class SettingsProvider;
- class QtUserSearchWindow : public QWizard, public UserSearchWindow, private Ui::QtUserSearchWizard {
- Q_OBJECT
- public:
- QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups, SettingsProvider* settingsProvider);
- virtual ~QtUserSearchWindow();
+ class QtUserSearchWindow : public QWizard, public UserSearchWindow, private Ui::QtUserSearchWizard {
+ Q_OBJECT
+ public:
+ QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups, SettingsProvider* settingsProvider);
+ virtual ~QtUserSearchWindow();
- virtual void addSavedServices(const std::vector<JID>& services);
+ virtual void addSavedServices(const std::vector<JID>& services);
- virtual void clear();
- virtual void show();
- virtual void setResults(const std::vector<UserSearchResult>& results);
- virtual void setResultsForm(Form::ref results);
- virtual void setSelectedService(const JID& jid);
- virtual void setServerSupportsSearch(bool error);
- virtual void setSearchError(bool error);
- virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields);
- virtual void setNameSuggestions(const std::vector<std::string>& suggestions);
- virtual void prepopulateJIDAndName(const JID& jid, const std::string& name);
- virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions);
- virtual void setJIDs(const std::vector<JID> &jids);
- virtual void setRoomJID(const JID &roomJID);
- virtual std::string getReason() const;
- virtual std::vector<JID> getJIDs() const;
- virtual void setCanStartImpromptuChats(bool supportsImpromptu);
- virtual void updateContacts(const std::vector<Contact::ref> &contacts);
- virtual void addContacts(const std::vector<Contact::ref>& contacts);
- virtual void setCanSupplyDescription(bool allowed);
- virtual void setWarning(const boost::optional<std::string>& message);
+ virtual void clear();
+ virtual void show();
+ virtual void setResults(const std::vector<UserSearchResult>& results);
+ virtual void setResultsForm(Form::ref results);
+ virtual void setSelectedService(const JID& jid);
+ virtual void setServerSupportsSearch(bool error);
+ virtual void setSearchError(bool error);
+ virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields);
+ virtual void setNameSuggestions(const std::vector<std::string>& suggestions);
+ virtual void prepopulateJIDAndName(const JID& jid, const std::string& name);
+ virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions);
+ virtual void setJIDs(const std::vector<JID> &jids);
+ virtual void setRoomJID(const JID &roomJID);
+ virtual std::string getReason() const;
+ virtual std::vector<JID> getJIDs() const;
+ virtual void setCanStartImpromptuChats(bool supportsImpromptu);
+ virtual void updateContacts(const std::vector<Contact::ref> &contacts);
+ virtual void addContacts(const std::vector<Contact::ref>& contacts);
+ virtual void setCanSupplyDescription(bool allowed);
+ virtual void setWarning(const boost::optional<std::string>& message);
- protected:
- virtual int nextId() const;
+ protected:
+ virtual int nextId() const;
- private slots:
- void handleFirstPageRadioChange();
- virtual void handleCurrentChanged(int);
- virtual void handleAccepted();
- void handleContactSuggestionRequested(const QString& text);
- void addContact();
- void handleAddViaSearch();
- void handleListChanged(std::vector<Contact::ref> list);
- void handleJIDsAdded(std::vector<JID> jids);
- void handleJIDEditingDone();
+ private slots:
+ void handleFirstPageRadioChange();
+ virtual void handleCurrentChanged(int);
+ virtual void handleAccepted();
+ void handleContactSuggestionRequested(const QString& text);
+ void addContact();
+ void handleAddViaSearch();
+ void handleListChanged(std::vector<Contact::ref> list);
+ void handleJIDsAdded(std::vector<JID> jids);
+ void handleJIDEditingDone();
- private:
- void setFirstPage(QString title = "");
- void setSecondPage();
- void setThirdPage();
+ private:
+ void setFirstPage(QString title = "");
+ void setSecondPage();
+ void setThirdPage();
- private:
- void clearForm();
- void setError(const QString& error);
- JID getServerToSearch();
- void handleSearch();
- JID getContactJID() const;
- Contact::ref getContact() const;
- void addSearchedJIDToList(const Contact::ref& contact);
- void handleOnSearchedJIDSelected(const Contact::ref& contact);
+ private:
+ void clearForm();
+ void setError(const QString& error);
+ JID getServerToSearch();
+ void handleSearch();
+ JID getContactJID() const;
+ Contact::ref getContact() const;
+ void addSearchedJIDToList(const Contact::ref& contact);
+ void handleOnSearchedJIDSelected(const Contact::ref& contact);
- private:
- UIEventStream* eventStream_;
- UserSearchWindow::Type type_;
- QAbstractItemModel* model_;
- UserSearchDelegate* delegate_;
- QtUserSearchFirstPage* firstPage_;
- QtUserSearchFirstMultiJIDPage* firstMultiJIDPage_;
- QtUserSearchFieldsPage* fieldsPage_;
- QtUserSearchResultsPage* resultsPage_;
- QtUserSearchDetailsPage* detailsPage_;
- JID myServer_;
- JID roomJID_;
- int lastPage_;
- std::vector<Contact::ref> contactVector_;
- SettingsProvider* settings_;
- bool searchNext_;
- bool supportsImpromptu_;
- };
+ private:
+ UIEventStream* eventStream_;
+ UserSearchWindow::Type type_;
+ QAbstractItemModel* model_;
+ UserSearchDelegate* delegate_;
+ QtUserSearchFirstPage* firstPage_;
+ QtUserSearchFirstMultiJIDPage* firstMultiJIDPage_;
+ QtUserSearchFieldsPage* fieldsPage_;
+ QtUserSearchResultsPage* resultsPage_;
+ QtUserSearchDetailsPage* detailsPage_;
+ JID myServer_;
+ JID roomJID_;
+ int lastPage_;
+ std::vector<Contact::ref> contactVector_;
+ SettingsProvider* settings_;
+ bool searchNext_;
+ bool supportsImpromptu_;
+ };
}
diff --git a/Swift/QtUI/UserSearch/UserSearchDelegate.cpp b/Swift/QtUI/UserSearch/UserSearchDelegate.cpp
index 1ac9eb3..8c7ca9a 100644
--- a/Swift/QtUI/UserSearch/UserSearchDelegate.cpp
+++ b/Swift/QtUI/UserSearch/UserSearchDelegate.cpp
@@ -27,44 +27,44 @@ UserSearchDelegate::~UserSearchDelegate() {
}
QSize UserSearchDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const {
- //UserSearchItem* item = static_cast<UserSearchItem*>(index.internalPointer());
- QFontMetrics nameMetrics(common_.nameFont);
- QFontMetrics statusMetrics(common_.detailFont);
- int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
- return QSize(150, sizeByText);
+ //UserSearchItem* item = static_cast<UserSearchItem*>(index.internalPointer());
+ QFontMetrics nameMetrics(common_.nameFont);
+ QFontMetrics statusMetrics(common_.detailFont);
+ int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
+ return QSize(150, sizeByText);
}
-void UserSearchDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- UserSearchResult* item = static_cast<UserSearchResult*>(index.internalPointer());
- painter->save();
- QRect fullRegion(option.rect);
- if (option.state & QStyle::State_Selected) {
- painter->fillRect(fullRegion, option.palette.highlight());
- painter->setPen(option.palette.highlightedText().color());
- }
- else {
- QColor nameColor = UserSearchModel::data(item, Qt::TextColorRole).value<QColor> ();
- painter->setPen(QPen(nameColor));
- }
-
- QFontMetrics nameMetrics(common_.nameFont);
- painter->setFont(common_.nameFont);
- int extraFontWidth = nameMetrics.width("H");
- int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
- QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
-
- int nameHeight = nameMetrics.height() + common_.verticalMargin;
- QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
-
- painter->drawText(nameRegion, Qt::AlignTop, UserSearchModel::data(item, Qt::DisplayRole).toString());
-
- painter->setFont(common_.detailFont);
- painter->setPen(QPen(QColor(160, 160, 160)));
-
- QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
- painter->drawText(detailRegion, Qt::AlignTop, UserSearchModel::data(item, UserSearchModel::DetailTextRole).toString());
-
- painter->restore();
+void UserSearchDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
+ UserSearchResult* item = static_cast<UserSearchResult*>(index.internalPointer());
+ painter->save();
+ QRect fullRegion(option.rect);
+ if (option.state & QStyle::State_Selected) {
+ painter->fillRect(fullRegion, option.palette.highlight());
+ painter->setPen(option.palette.highlightedText().color());
+ }
+ else {
+ QColor nameColor = UserSearchModel::data(item, Qt::TextColorRole).value<QColor> ();
+ painter->setPen(QPen(nameColor));
+ }
+
+ QFontMetrics nameMetrics(common_.nameFont);
+ painter->setFont(common_.nameFont);
+ int extraFontWidth = nameMetrics.width("H");
+ int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
+ QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
+
+ int nameHeight = nameMetrics.height() + common_.verticalMargin;
+ QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
+
+ painter->drawText(nameRegion, Qt::AlignTop, UserSearchModel::data(item, Qt::DisplayRole).toString());
+
+ painter->setFont(common_.detailFont);
+ painter->setPen(QPen(QColor(160, 160, 160)));
+
+ QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
+ painter->drawText(detailRegion, Qt::AlignTop, UserSearchModel::data(item, UserSearchModel::DetailTextRole).toString());
+
+ painter->restore();
}
}
diff --git a/Swift/QtUI/UserSearch/UserSearchDelegate.h b/Swift/QtUI/UserSearch/UserSearchDelegate.h
index 92fa0e8..8234689 100644
--- a/Swift/QtUI/UserSearch/UserSearchDelegate.h
+++ b/Swift/QtUI/UserSearch/UserSearchDelegate.h
@@ -13,18 +13,18 @@
#include <Swift/QtUI/Roster/DelegateCommons.h>
namespace Swift {
- class UserSearchDelegate : public QStyledItemDelegate {
- Q_OBJECT
-
- public:
- UserSearchDelegate(QObject* parent = 0);
- virtual ~UserSearchDelegate();
-
- void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
- QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const;
- private:
- DelegateCommons common_;
- };
+ class UserSearchDelegate : public QStyledItemDelegate {
+ Q_OBJECT
+
+ public:
+ UserSearchDelegate(QObject* parent = 0);
+ virtual ~UserSearchDelegate();
+
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const;
+ private:
+ DelegateCommons common_;
+ };
}
diff --git a/Swift/QtUI/UserSearch/UserSearchModel.cpp b/Swift/QtUI/UserSearch/UserSearchModel.cpp
index ba6ede3..b6ac3cf 100644
--- a/Swift/QtUI/UserSearch/UserSearchModel.cpp
+++ b/Swift/QtUI/UserSearch/UserSearchModel.cpp
@@ -14,76 +14,76 @@ UserSearchModel::UserSearchModel() {
}
void UserSearchModel::clear() {
- emit layoutAboutToBeChanged();
- results_.clear();
- emit layoutChanged();
+ emit layoutAboutToBeChanged();
+ results_.clear();
+ emit layoutChanged();
}
void UserSearchModel::setResults(const std::vector<UserSearchResult>& results) {
- clear();
- emit layoutAboutToBeChanged();
- results_ = results;
- emit layoutChanged();
+ clear();
+ emit layoutAboutToBeChanged();
+ results_ = results;
+ emit layoutChanged();
}
int UserSearchModel::columnCount(const QModelIndex& /*parent*/) const {
- return 1;
+ return 1;
}
QVariant UserSearchModel::data(const QModelIndex& index, int role) const {
- if (!index.isValid()) return QVariant();
- UserSearchResult* result = static_cast<UserSearchResult*>(index.internalPointer());
- return data(result, role);
+ if (!index.isValid()) return QVariant();
+ UserSearchResult* result = static_cast<UserSearchResult*>(index.internalPointer());
+ return data(result, role);
}
QVariant UserSearchModel::data(UserSearchResult* item, int role) {
- switch (role) {
- case Qt::DisplayRole: return QVariant(nameLine(item));
- case DetailTextRole: return QVariant(detailLine(item));
- default: return QVariant();
- }
+ switch (role) {
+ case Qt::DisplayRole: return QVariant(nameLine(item));
+ case DetailTextRole: return QVariant(detailLine(item));
+ default: return QVariant();
+ }
}
QString UserSearchModel::nameLine(UserSearchResult* item) {
- QString result;
- const std::map<std::string, std::string> fields = item->getFields();
- std::map<std::string, std::string>::const_iterator first = fields.find("first");
- if (first != fields.end()) {
- result += P2QSTRING((*first).second);
- }
- std::map<std::string, std::string>::const_iterator last = fields.find("last");
- if (last != fields.end()) {
- if (!result.isEmpty()) {
- result += " ";
- }
- result += P2QSTRING((*last).second);
- }
- if (result.isEmpty()) {
- result = P2QSTRING(item->getJID().toString());
- }
- return result;
+ QString result;
+ const std::map<std::string, std::string> fields = item->getFields();
+ std::map<std::string, std::string>::const_iterator first = fields.find("first");
+ if (first != fields.end()) {
+ result += P2QSTRING((*first).second);
+ }
+ std::map<std::string, std::string>::const_iterator last = fields.find("last");
+ if (last != fields.end()) {
+ if (!result.isEmpty()) {
+ result += " ";
+ }
+ result += P2QSTRING((*last).second);
+ }
+ if (result.isEmpty()) {
+ result = P2QSTRING(item->getJID().toString());
+ }
+ return result;
}
QString UserSearchModel::detailLine(UserSearchResult* item) {
- return P2QSTRING(item->getJID().toString());
+ return P2QSTRING(item->getJID().toString());
}
QModelIndex UserSearchModel::index(int row, int column, const QModelIndex & parent) const {
- if (!hasIndex(row, column, parent)) {
- return QModelIndex();
- }
- return row < static_cast<int>(results_.size()) ? createIndex(row, column, reinterpret_cast<void*>(const_cast<UserSearchResult*>(&(results_[row])))) : QModelIndex();
+ if (!hasIndex(row, column, parent)) {
+ return QModelIndex();
+ }
+ return row < static_cast<int>(results_.size()) ? createIndex(row, column, reinterpret_cast<void*>(const_cast<UserSearchResult*>(&(results_[row])))) : QModelIndex();
}
QModelIndex UserSearchModel::parent(const QModelIndex& /*index*/) const {
- return QModelIndex();
+ return QModelIndex();
}
int UserSearchModel::rowCount(const QModelIndex& parentIndex) const {
- if (!parentIndex.isValid()) {
- return results_.size();
- }
- return 0;
+ if (!parentIndex.isValid()) {
+ return results_.size();
+ }
+ return 0;
}
}
diff --git a/Swift/QtUI/UserSearch/UserSearchModel.h b/Swift/QtUI/UserSearch/UserSearchModel.h
index db3ef3a..0a57b28 100644
--- a/Swift/QtUI/UserSearch/UserSearchModel.h
+++ b/Swift/QtUI/UserSearch/UserSearchModel.h
@@ -14,28 +14,28 @@
#include <Swift/Controllers/Chat/UserSearchController.h>
namespace Swift {
- class UserSearchModel : public QAbstractItemModel {
- Q_OBJECT
- public:
- enum UserItemRoles {
- DetailTextRole = Qt::UserRole/*,
- AvatarRole = Qt::UserRole + 1,
- PresenceIconRole = Qt::UserRole + 2,
- StatusShowTypeRole = Qt::UserRole + 3*/
- };
- UserSearchModel();
- void clear();
- void setResults(const std::vector<UserSearchResult>& results);
- int columnCount(const QModelIndex& parent = QModelIndex()) const;
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- static QVariant data(UserSearchResult* item, int role);
- QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex& index) const;
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
- private:
- static QString nameLine(UserSearchResult* item);
- static QString detailLine(UserSearchResult* item);
- std::vector<UserSearchResult> results_;
- };
+ class UserSearchModel : public QAbstractItemModel {
+ Q_OBJECT
+ public:
+ enum UserItemRoles {
+ DetailTextRole = Qt::UserRole/*,
+ AvatarRole = Qt::UserRole + 1,
+ PresenceIconRole = Qt::UserRole + 2,
+ StatusShowTypeRole = Qt::UserRole + 3*/
+ };
+ UserSearchModel();
+ void clear();
+ void setResults(const std::vector<UserSearchResult>& results);
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ static QVariant data(UserSearchResult* item, int role);
+ QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex& index) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ private:
+ static QString nameLine(UserSearchResult* item);
+ static QString detailLine(UserSearchResult* item);
+ std::vector<UserSearchResult> results_;
+ };
}
diff --git a/Swift/QtUI/Whiteboard/ColorWidget.cpp b/Swift/QtUI/Whiteboard/ColorWidget.cpp
index e12ade1..7669ecc 100644
--- a/Swift/QtUI/Whiteboard/ColorWidget.cpp
+++ b/Swift/QtUI/Whiteboard/ColorWidget.cpp
@@ -17,28 +17,28 @@
#include <QPainter>
namespace Swift {
- ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent) {
- setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
- }
-
- QSize ColorWidget::sizeHint() const {
- return QSize(20, 20);
- }
-
- void ColorWidget::setColor(QColor color) {
- this->color = color;
- update();
- }
-
- void ColorWidget::paintEvent(QPaintEvent* /*event*/) {
- QPainter painter(this);
- painter.fillRect(0, 0, 20, 20, color);
- }
-
- void ColorWidget::mouseReleaseEvent(QMouseEvent* event) {
- if (event->button() == Qt::LeftButton) {
- emit clicked();
- }
- }
+ ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent) {
+ setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
+ }
+
+ QSize ColorWidget::sizeHint() const {
+ return QSize(20, 20);
+ }
+
+ void ColorWidget::setColor(QColor color) {
+ this->color = color;
+ update();
+ }
+
+ void ColorWidget::paintEvent(QPaintEvent* /*event*/) {
+ QPainter painter(this);
+ painter.fillRect(0, 0, 20, 20, color);
+ }
+
+ void ColorWidget::mouseReleaseEvent(QMouseEvent* event) {
+ if (event->button() == Qt::LeftButton) {
+ emit clicked();
+ }
+ }
}
diff --git a/Swift/QtUI/Whiteboard/ColorWidget.h b/Swift/QtUI/Whiteboard/ColorWidget.h
index ae1af0f..18dc73f 100644
--- a/Swift/QtUI/Whiteboard/ColorWidget.h
+++ b/Swift/QtUI/Whiteboard/ColorWidget.h
@@ -9,25 +9,25 @@
#include <QWidget>
namespace Swift {
- class ColorWidget : public QWidget {
- Q_OBJECT
- public:
- ColorWidget(QWidget* parent = 0);
- QSize sizeHint() const;
+ class ColorWidget : public QWidget {
+ Q_OBJECT
+ public:
+ ColorWidget(QWidget* parent = 0);
+ QSize sizeHint() const;
- public slots:
- void setColor(QColor color);
+ public slots:
+ void setColor(QColor color);
- private:
- QColor color;
+ private:
+ QColor color;
- protected:
- void paintEvent(QPaintEvent* /*event*/);
- void mouseReleaseEvent(QMouseEvent* event);
+ protected:
+ void paintEvent(QPaintEvent* /*event*/);
+ void mouseReleaseEvent(QMouseEvent* event);
- signals:
- void clicked();
+ signals:
+ void clicked();
- };
+ };
}
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
index f4808d6..4ac93b8 100644
--- a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
+++ b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
@@ -13,90 +13,90 @@
#include <Swift/QtUI/Whiteboard/FreehandLineItem.h>
namespace Swift {
- FreehandLineItem::FreehandLineItem(QGraphicsItem* parent) : QGraphicsItem(parent) {
- }
+ FreehandLineItem::FreehandLineItem(QGraphicsItem* parent) : QGraphicsItem(parent) {
+ }
- QRectF FreehandLineItem::boundingRect() const
- {
- return boundRect;
- }
+ QRectF FreehandLineItem::boundingRect() const
+ {
+ return boundRect;
+ }
- void FreehandLineItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
- {
- painter->setPen(pen_);
- if (points_.size() > 0) {
- QVector<QPointF>::const_iterator it = points_.begin();
- QPointF previous = *it;
- ++it;
- for (; it != points_.end(); ++it) {
- painter->drawLine(previous, *it);
- previous = *it;
- }
- }
- }
+ void FreehandLineItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
+ {
+ painter->setPen(pen_);
+ if (points_.size() > 0) {
+ QVector<QPointF>::const_iterator it = points_.begin();
+ QPointF previous = *it;
+ ++it;
+ for (; it != points_.end(); ++it) {
+ painter->drawLine(previous, *it);
+ previous = *it;
+ }
+ }
+ }
- void FreehandLineItem::setStartPoint(QPointF point)
- {
- points_.clear();
- points_.append(point);
- QRectF rect(point, point);
- prepareGeometryChange();
- boundRect = rect;
- }
+ void FreehandLineItem::setStartPoint(QPointF point)
+ {
+ points_.clear();
+ points_.append(point);
+ QRectF rect(point, point);
+ prepareGeometryChange();
+ boundRect = rect;
+ }
- void FreehandLineItem::lineTo(QPointF point)
- {
- qreal x1, x2, y1, y2;
- x1 = points_.last().x();
- x2 = point.x();
- y1 = points_.last().y();
- y2 = point.y();
- if (x1 > x2) {
- qreal temp = x1;
- x1 = x2;
- x2 = temp;
- }
- if (y1 > y2) {
- qreal temp = y1;
- y1 = y2;
- y2 = temp;
- }
- QRectF rect(x1-1, y1-1, x2+1-x1, y2+1-y1);
+ void FreehandLineItem::lineTo(QPointF point)
+ {
+ qreal x1, x2, y1, y2;
+ x1 = points_.last().x();
+ x2 = point.x();
+ y1 = points_.last().y();
+ y2 = point.y();
+ if (x1 > x2) {
+ qreal temp = x1;
+ x1 = x2;
+ x2 = temp;
+ }
+ if (y1 > y2) {
+ qreal temp = y1;
+ y1 = y2;
+ y2 = temp;
+ }
+ QRectF rect(x1-1, y1-1, x2+1-x1, y2+1-y1);
- points_.append(point);
+ points_.append(point);
- prepareGeometryChange();
- boundRect |= rect;
- }
+ prepareGeometryChange();
+ boundRect |= rect;
+ }
- bool FreehandLineItem::collidesWithPath(const QPainterPath& path, Qt::ItemSelectionMode /*mode*/) const
- {
- QVector<QPointF>::const_iterator it;
- QSizeF size(1,1);
- for (it = points_.begin(); it != points_.end(); ++it) {
- if (path.intersects(QRectF(*it, size))) {
- return true;
- }
- }
- return false;
- }
+ bool FreehandLineItem::collidesWithPath(const QPainterPath& path, Qt::ItemSelectionMode /*mode*/) const
+ {
+ QVector<QPointF>::const_iterator it;
+ QSizeF size(1,1);
+ for (it = points_.begin(); it != points_.end(); ++it) {
+ if (path.intersects(QRectF(*it, size))) {
+ return true;
+ }
+ }
+ return false;
+ }
- void FreehandLineItem::setPen(const QPen& pen)
- {
- pen_ = pen;
- update(boundRect);
- }
+ void FreehandLineItem::setPen(const QPen& pen)
+ {
+ pen_ = pen;
+ update(boundRect);
+ }
- QPen FreehandLineItem::pen() const
- {
- return pen_;
- }
+ QPen FreehandLineItem::pen() const
+ {
+ return pen_;
+ }
- const QVector<QPointF>& FreehandLineItem::points() const {
- return points_;
- }
+ const QVector<QPointF>& FreehandLineItem::points() const {
+ return points_;
+ }
- int FreehandLineItem::type() const {
- return Type;
- }
+ int FreehandLineItem::type() const {
+ return Type;
+ }
}
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.h b/Swift/QtUI/Whiteboard/FreehandLineItem.h
index db37460..a2dab34 100644
--- a/Swift/QtUI/Whiteboard/FreehandLineItem.h
+++ b/Swift/QtUI/Whiteboard/FreehandLineItem.h
@@ -18,23 +18,23 @@
#include <QPainter>
namespace Swift {
- class FreehandLineItem : public QGraphicsItem {
- public:
- enum {Type = UserType + 1};
- FreehandLineItem(QGraphicsItem* parent = 0);
- QRectF boundingRect() const;
- void paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/ = 0);
- void setStartPoint(QPointF point);
- void lineTo(QPointF point);
- bool collidesWithPath(const QPainterPath& path, Qt::ItemSelectionMode /*mode*/ = Qt::IntersectsItemShape) const;
- void setPen(const QPen& pen);
- QPen pen() const;
- const QVector<QPointF>& points() const;
- int type() const;
+ class FreehandLineItem : public QGraphicsItem {
+ public:
+ enum {Type = UserType + 1};
+ FreehandLineItem(QGraphicsItem* parent = 0);
+ QRectF boundingRect() const;
+ void paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/ = 0);
+ void setStartPoint(QPointF point);
+ void lineTo(QPointF point);
+ bool collidesWithPath(const QPainterPath& path, Qt::ItemSelectionMode /*mode*/ = Qt::IntersectsItemShape) const;
+ void setPen(const QPen& pen);
+ QPen pen() const;
+ const QVector<QPointF>& points() const;
+ int type() const;
- private:
- QPen pen_;
- QVector<QPointF> points_;
- QRectF boundRect;
- };
+ private:
+ QPen pen_;
+ QVector<QPointF> points_;
+ QRectF boundRect;
+ };
}
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp
index 9134d58..4deaaf6 100644
--- a/Swift/QtUI/Whiteboard/GView.cpp
+++ b/Swift/QtUI/Whiteboard/GView.cpp
@@ -15,489 +15,489 @@
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
- GView::GView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent), zValue(0), mousePressed(false), brush(QColor(Qt::white)), defaultBrush(QColor(Qt::white)), mode(GView::Select), lastItem(NULL), selectionRect(NULL), textDialog(NULL) {
- }
-
- void GView::setLineWidth(int i) {
- pen.setWidth(i);
- if (selectionRect) {
- QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
- changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
- lastItemChanged(item, items_.indexOf(item)+1, Update);
- } else {
- defaultPen.setWidth(i);
- }
- }
-
- void GView::setLineColor(QColor color) {
- pen.setColor(color);
- if (selectionRect) {
- QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
- changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
- lastItemChanged(item, items_.indexOf(item)+1, Update);
- } else {
- defaultPen.setColor(color);
- }
- lineColorChanged(color);
- }
-
- QColor GView::getLineColor() {
- return pen.color();
- }
-
- void GView::setBrushColor(QColor color) {
- brush.setColor(color);
- if (selectionRect) {
- QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
- changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
- lastItemChanged(item, items_.indexOf(item)+1, Update);
- } else {
- defaultBrush.setColor(color);
- }
- brushColorChanged(color);
- }
-
- QColor GView::getBrushColor() {
- return brush.color();
- }
-
- void GView::setMode(Mode mode) {
- this->mode = mode;
- lastItem = 0;
- deselect();
- }
-
- void GView::addItem(QGraphicsItem* item, QString id, int pos) {
- itemsMap_.insert(id, item);
- if (pos > items_.size()) {
- item->setZValue(zValue++);
- scene()->addItem(item);
- items_.append(item);
- } else {
- QGraphicsItem* temp = items_.at(pos-1);
- item->setZValue(temp->zValue());
- scene()->addItem(item);
- item->stackBefore(temp);
- items_.insert(pos-1, item);
- }
- }
-
- void GView::clear() {
- scene()->clear();
- items_.clear();
- itemsMap_.clear();
- lastItem = 0;
- selectionRect = 0;
- brush = QBrush(QColor(Qt::white));
- defaultBrush = QBrush(QColor(Qt::white));
- pen = QPen();
- pen.setWidth(1);
- defaultPen = pen;
- lineWidthChanged(1);
- lineColorChanged(pen.color());
- brushColorChanged(brush.color());
- }
-
- QGraphicsItem* GView::getItem(QString id) {
- return itemsMap_.value(id);
- }
-
- void GView::deleteItem(QString id) {
- deselect(id);
- QGraphicsItem* item = itemsMap_.value(id);
- items_.removeOne(item);
- itemsMap_.remove(id);
- scene()->removeItem(item);
- delete item;
- }
-
- QString GView::getNewID() {
- return P2QSTRING(idGenerator.generateID());
- }
-
- void GView::mouseMoveEvent(QMouseEvent* event)
- {
- if (!mousePressed) {
- return;
- }
-
- if (mode == Line) {
- QGraphicsLineItem* item = qgraphicsitem_cast<QGraphicsLineItem*>(lastItem);
- if(item != 0) {
- QLineF line = item->line();
- line.setP1(this->mapToScene(event->pos()));
- item->setLine(line);
-
- }
- }
- else if (mode == Rect) {
- QGraphicsRectItem* item = qgraphicsitem_cast<QGraphicsRectItem*>(lastItem);
- if (item != 0) {
- QPointF beginPoint = item->data(0).toPointF();
- QPointF newPoint = this->mapToScene(event->pos());
- QRectF rect = item->rect();
- if (beginPoint.x() <= newPoint.x() && beginPoint.y() <= newPoint.y()) {
- rect.setTopLeft(beginPoint);
- rect.setBottomRight(newPoint);
- }
- else if (beginPoint.x() > newPoint.x() && beginPoint.y() <= newPoint.y()) {
- rect.setTopRight(beginPoint);
- rect.setBottomLeft(newPoint);
- }
- else if (beginPoint.x() <= newPoint.x() && beginPoint.y() > newPoint.y()) {
- rect.setBottomLeft(beginPoint);
- rect.setTopRight(newPoint);
- }
- else if (beginPoint.x() > newPoint.x() && beginPoint.y() > newPoint.y()) {
- rect.setBottomRight(beginPoint);
- rect.setTopLeft(newPoint);
- }
- item->setRect(rect);
- }
- }
- else if (mode == Circle) {
- QGraphicsEllipseItem* item = qgraphicsitem_cast<QGraphicsEllipseItem*>(lastItem);
- QPainterPath path;
- QPointF beginPoint = item->data(0).toPointF();
- QPointF newPoint = this->mapToScene(event->pos());
- QRectF rect = item->rect();
- if (beginPoint.x() <= newPoint.x() && beginPoint.y() <= newPoint.y()) {
- rect.setTopLeft(beginPoint);
- rect.setBottomRight(newPoint);
- }
- else if (beginPoint.x() > newPoint.x() && beginPoint.y() <= newPoint.y()) {
- rect.setTopRight(beginPoint);
- rect.setBottomLeft(newPoint);
- }
- else if (beginPoint.x() <= newPoint.x() && beginPoint.y() > newPoint.y()) {
- rect.setBottomLeft(beginPoint);
- rect.setTopRight(newPoint);
- }
- else if (beginPoint.x() > newPoint.x() && beginPoint.y() > newPoint.y()) {
- rect.setBottomRight(beginPoint);
- rect.setTopLeft(newPoint);
- }
-
- item->setRect(rect);
- }
- else if (mode == HandLine) {
- FreehandLineItem* item = qgraphicsitem_cast<FreehandLineItem*>(lastItem);
- if (item != 0) {
- QPointF newPoint = this->mapToScene(event->pos());
- item->lineTo(newPoint);
- }
- }
- else if (mode == Polygon) {
- QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(lastItem);
- QPointF newPoint = this->mapToScene(event->pos());
- QPolygonF polygon = item->polygon();
- polygon.erase(polygon.end()-1);
- polygon.append(newPoint);
- item->setPolygon(polygon);
- }
- else if (mode == Select) {
- QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
- if (item != 0) {
- QPainterPath path;
- QPointF beginPoint = selectionRect->data(0).toPointF();
- QPointF newPoint = this->mapToScene(event->pos());
- item->setPos(beginPoint + newPoint);
- selectionRect->setPos(beginPoint + newPoint);
- }
- }
- }
-
- void GView::mousePressEvent(QMouseEvent *event)
- {
- mousePressed = true;
- deselect();
- if (mode == Line) {
- QPointF point = this->mapToScene(event->pos());
- QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen);
- QString id = getNewID();
- item->setZValue(10000000);
- item->setData(100, id);
- item->setData(101, items_.size());
- lastItem = item;
- }
- else if (mode == Rect) {
- QPointF point = this->mapToScene(event->pos());
- QGraphicsRectItem* item = scene()->addRect(point.x(), point.y(), 0, 0, pen, brush);
- QString id = getNewID();
- item->setZValue(10000000);
- item->setData(0, point);
- item->setData(100, id);
- item->setData(101, items_.size());
- lastItem = item;
- }
- else if (mode == Rubber) {
- QPointF point = this->mapToScene(event->pos());
- int w = pen.width();
- QRectF rect(point.x()-w, point.y()-w, w*2, w*2);
- QList<QGraphicsItem*> list = scene()->items(rect);
- if (!list.isEmpty())
- {
- QGraphicsItem* item = scene()->items(rect).first();
- QString id = item->data(100).toString();
- int pos = items_.indexOf(item)+1;
- itemDeleted(id, pos);
- deleteItem(id);
- }
- }
- else if (mode == Circle) {
- QPointF point = this->mapToScene(event->pos());
- QGraphicsEllipseItem* item = scene()->addEllipse(point.x(), point.y(), 0, 0, pen, brush);
- QString id = getNewID();
- item->setZValue(10000000);
- item->setData(0, point);
- item->setData(100, id);
- item->setData(101, items_.size());
- lastItem = item;
- }
- else if (mode == HandLine) {
- QPointF point = this->mapToScene(event->pos());
- FreehandLineItem* item = new FreehandLineItem;
- QString id = getNewID();
- item->setPen(pen);
- item->setStartPoint(point);
- item->setZValue(10000000);
- item->setData(100, id);
- item->setData(101, items_.size());
- scene()->addItem(item);
- lastItem = item;
- }
- else if (mode == Text) {
- QPointF point = this->mapToScene(event->pos());
- QGraphicsTextItem* item = scene()->addText("");
- QString id = getNewID();
- item->setData(100, id);
- item->setData(101, items_.size());
- item->setDefaultTextColor(pen.color());
- textDialog = new TextDialog(item, this);
- connect(textDialog, SIGNAL(accepted(QGraphicsTextItem*)), this, SLOT(handleTextItemModified(QGraphicsTextItem*)));
- textDialog->setAttribute(Qt::WA_DeleteOnClose);
- textDialog->show();
- item->setPos(point);
- lastItem = item;
- }
- else if (mode == Polygon) {
- QPointF point = this->mapToScene(event->pos());
- QGraphicsPolygonItem* item = dynamic_cast<QGraphicsPolygonItem*>(lastItem);
- if (item == 0) {
- QPolygonF polygon;
- polygon.append(point);
- polygon.append(point);
- item = scene()->addPolygon(polygon, pen, brush);
- QString id = getNewID();
- item->setZValue(10000000);
- item->setData(100, id);
- item->setData(101, items_.size());
- lastItem = item;
- }
- else {
- QPolygonF polygon;
- polygon = item->polygon();
- polygon.append(point);
- item->setPolygon(polygon);
- }
- }
- else if (mode == Select) {
- QPointF point = this->mapToScene(event->pos());
- int w = pen.width();
- if (w == 0) {
- w = 1;
- }
- QRectF rect(point.x()-w, point.y()-w, w*2, w*2);
- QList<QGraphicsItem*> list = scene()->items(rect);
- if (!list.isEmpty()) {
- QPen pen;
- pen.setColor(QColor(Qt::gray));
- pen.setStyle(Qt::DashLine);
- QGraphicsItem *item = scene()->items(rect).first();
- selectionRect = scene()->addRect(item->boundingRect(), pen);
- selectionRect->setZValue(1000000);
- selectionRect->setData(0, item->pos()-point);
- selectionRect->setPos(item->pos());
- QVariant var(QVariant::UserType);
- var.setValue(item);
- selectionRect->setData(1, var);
- setActualPenAndBrushFromItem(item);
- }
- }
- }
-
- void GView::mouseReleaseEvent(QMouseEvent* /*event*/)
- {
- mousePressed = false;
- QGraphicsPolygonItem* polygon = dynamic_cast<QGraphicsPolygonItem*>(lastItem);
- if (polygon && polygon->polygon().size() >= 3) {
- lastItemChanged(polygon, items_.indexOf(polygon)+1, Update);
- } else if (lastItem) {
- zValue++;
- lastItem->setZValue(zValue++);
- items_.append(lastItem);
- itemsMap_.insert(lastItem->data(100).toString(), lastItem);
-
- lastItemChanged(lastItem, items_.size(), New);
- } else if (selectionRect){
- QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
- lastItemChanged(item, items_.indexOf(item)+1, Update);
- }
- }
-
-
- void GView::handleTextItemModified(QGraphicsTextItem* item) {
- lastItemChanged(item, item->data(101).toInt(), Update);
- }
-
- void GView::moveUpSelectedItem()
- {
- if (selectionRect) {
- QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
- int pos = items_.indexOf(item);
- if (pos < items_.size()-1) {
- lastItemChanged(item, pos+1, MoveUp);
- move(item, pos+2);
- }
- }
- }
-
- void GView::moveDownSelectedItem()
- {
- if (selectionRect) {
- QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
- int pos = items_.indexOf(item);
- if (pos > 0) {
- lastItemChanged(item, pos+1, MoveDown);
- move(item, pos);
- }
- }
- }
-
- void GView::move(QGraphicsItem* item, int npos) {
- int pos = items_.indexOf(item);
- QGraphicsItem* itemAfter = NULL;
- if (npos-1 > pos) {
- if (npos == items_.size()) {
- item->setZValue(zValue++);
- } else {
- itemAfter = items_.at(npos);
- }
-
- items_.insert(npos, item);
- items_.removeAt(pos);
- } else if (npos-1 < pos) {
- itemAfter = items_.at(npos-1);
- items_.insert(npos-1, item);
- items_.removeAt(pos+1);
- }
- if (itemAfter) {
- item->setZValue(itemAfter->zValue());
- item->stackBefore(itemAfter);
- }
- }
-
- void GView::changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush) {
- QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
- if (lineItem) {
- lineItem->setPen(pen);
- }
-
- FreehandLineItem* handLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
- if (handLineItem) {
- handLineItem->setPen(pen);
- }
-
- QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
- if (rectItem) {
- rectItem->setPen(pen);
- rectItem->setBrush(brush);
- }
-
- QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
- if (textItem) {
- textItem->setDefaultTextColor(pen.color());
- }
-
- QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
- if (polygonItem) {
- polygonItem->setPen(pen);
- polygonItem->setBrush(brush);
- }
-
- QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
- if (ellipseItem) {
- ellipseItem->setPen(pen);
- ellipseItem->setBrush(brush);
- }
- lineColorChanged(pen.color());
- brushColorChanged(brush.color());
- }
-
- void GView::setActualPenAndBrushFromItem(QGraphicsItem* item) {
- QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
- if (lineItem) {
- pen = lineItem->pen();
- }
-
- FreehandLineItem* handLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
- if (handLineItem) {
- pen = handLineItem->pen();
- }
-
- QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
- if (rectItem) {
- pen = rectItem->pen();
- brush = rectItem->brush();
- }
-
- QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
- if (textItem) {
- pen.setColor(textItem->defaultTextColor());
- }
-
- QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
- if (polygonItem) {
- pen = polygonItem->pen();
- brush = polygonItem->brush();
- }
-
- QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
- if (ellipseItem) {
- pen = ellipseItem->pen();
- brush = ellipseItem->brush();
- }
- lineWidthChanged(pen.width());
- lineColorChanged(pen.color());
- brushColorChanged(brush.color());
- }
-
- void GView::deselect() {
- if (selectionRect != 0) {
- pen = defaultPen;
- brush = defaultBrush;
- scene()->removeItem(selectionRect);
- delete selectionRect;
- selectionRect = 0;
- lineWidthChanged(pen.width());
- lineColorChanged(pen.color());
- brushColorChanged(brush.color());
- }
- }
-
- void GView::deselect(QString id) {
- if (selectionRect != 0) {
- QGraphicsItem* item = getItem(id);
- if (item && selectionRect->data(1).value<QGraphicsItem*>() == item) {
- pen = defaultPen;
- brush = defaultBrush;
- scene()->removeItem(selectionRect);
- delete selectionRect;
- selectionRect = 0;
- lineWidthChanged(pen.width());
- lineColorChanged(pen.color());
- brushColorChanged(brush.color());
- }
- }
- }
+ GView::GView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent), zValue(0), mousePressed(false), brush(QColor(Qt::white)), defaultBrush(QColor(Qt::white)), mode(GView::Select), lastItem(NULL), selectionRect(NULL), textDialog(NULL) {
+ }
+
+ void GView::setLineWidth(int i) {
+ pen.setWidth(i);
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
+ lastItemChanged(item, items_.indexOf(item)+1, Update);
+ } else {
+ defaultPen.setWidth(i);
+ }
+ }
+
+ void GView::setLineColor(QColor color) {
+ pen.setColor(color);
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
+ lastItemChanged(item, items_.indexOf(item)+1, Update);
+ } else {
+ defaultPen.setColor(color);
+ }
+ lineColorChanged(color);
+ }
+
+ QColor GView::getLineColor() {
+ return pen.color();
+ }
+
+ void GView::setBrushColor(QColor color) {
+ brush.setColor(color);
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
+ lastItemChanged(item, items_.indexOf(item)+1, Update);
+ } else {
+ defaultBrush.setColor(color);
+ }
+ brushColorChanged(color);
+ }
+
+ QColor GView::getBrushColor() {
+ return brush.color();
+ }
+
+ void GView::setMode(Mode mode) {
+ this->mode = mode;
+ lastItem = 0;
+ deselect();
+ }
+
+ void GView::addItem(QGraphicsItem* item, QString id, int pos) {
+ itemsMap_.insert(id, item);
+ if (pos > items_.size()) {
+ item->setZValue(zValue++);
+ scene()->addItem(item);
+ items_.append(item);
+ } else {
+ QGraphicsItem* temp = items_.at(pos-1);
+ item->setZValue(temp->zValue());
+ scene()->addItem(item);
+ item->stackBefore(temp);
+ items_.insert(pos-1, item);
+ }
+ }
+
+ void GView::clear() {
+ scene()->clear();
+ items_.clear();
+ itemsMap_.clear();
+ lastItem = 0;
+ selectionRect = 0;
+ brush = QBrush(QColor(Qt::white));
+ defaultBrush = QBrush(QColor(Qt::white));
+ pen = QPen();
+ pen.setWidth(1);
+ defaultPen = pen;
+ lineWidthChanged(1);
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+
+ QGraphicsItem* GView::getItem(QString id) {
+ return itemsMap_.value(id);
+ }
+
+ void GView::deleteItem(QString id) {
+ deselect(id);
+ QGraphicsItem* item = itemsMap_.value(id);
+ items_.removeOne(item);
+ itemsMap_.remove(id);
+ scene()->removeItem(item);
+ delete item;
+ }
+
+ QString GView::getNewID() {
+ return P2QSTRING(idGenerator.generateID());
+ }
+
+ void GView::mouseMoveEvent(QMouseEvent* event)
+ {
+ if (!mousePressed) {
+ return;
+ }
+
+ if (mode == Line) {
+ QGraphicsLineItem* item = qgraphicsitem_cast<QGraphicsLineItem*>(lastItem);
+ if(item != 0) {
+ QLineF line = item->line();
+ line.setP1(this->mapToScene(event->pos()));
+ item->setLine(line);
+
+ }
+ }
+ else if (mode == Rect) {
+ QGraphicsRectItem* item = qgraphicsitem_cast<QGraphicsRectItem*>(lastItem);
+ if (item != 0) {
+ QPointF beginPoint = item->data(0).toPointF();
+ QPointF newPoint = this->mapToScene(event->pos());
+ QRectF rect = item->rect();
+ if (beginPoint.x() <= newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopLeft(beginPoint);
+ rect.setBottomRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopRight(beginPoint);
+ rect.setBottomLeft(newPoint);
+ }
+ else if (beginPoint.x() <= newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomLeft(beginPoint);
+ rect.setTopRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomRight(beginPoint);
+ rect.setTopLeft(newPoint);
+ }
+ item->setRect(rect);
+ }
+ }
+ else if (mode == Circle) {
+ QGraphicsEllipseItem* item = qgraphicsitem_cast<QGraphicsEllipseItem*>(lastItem);
+ QPainterPath path;
+ QPointF beginPoint = item->data(0).toPointF();
+ QPointF newPoint = this->mapToScene(event->pos());
+ QRectF rect = item->rect();
+ if (beginPoint.x() <= newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopLeft(beginPoint);
+ rect.setBottomRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopRight(beginPoint);
+ rect.setBottomLeft(newPoint);
+ }
+ else if (beginPoint.x() <= newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomLeft(beginPoint);
+ rect.setTopRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomRight(beginPoint);
+ rect.setTopLeft(newPoint);
+ }
+
+ item->setRect(rect);
+ }
+ else if (mode == HandLine) {
+ FreehandLineItem* item = qgraphicsitem_cast<FreehandLineItem*>(lastItem);
+ if (item != 0) {
+ QPointF newPoint = this->mapToScene(event->pos());
+ item->lineTo(newPoint);
+ }
+ }
+ else if (mode == Polygon) {
+ QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(lastItem);
+ QPointF newPoint = this->mapToScene(event->pos());
+ QPolygonF polygon = item->polygon();
+ polygon.erase(polygon.end()-1);
+ polygon.append(newPoint);
+ item->setPolygon(polygon);
+ }
+ else if (mode == Select) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ if (item != 0) {
+ QPainterPath path;
+ QPointF beginPoint = selectionRect->data(0).toPointF();
+ QPointF newPoint = this->mapToScene(event->pos());
+ item->setPos(beginPoint + newPoint);
+ selectionRect->setPos(beginPoint + newPoint);
+ }
+ }
+ }
+
+ void GView::mousePressEvent(QMouseEvent *event)
+ {
+ mousePressed = true;
+ deselect();
+ if (mode == Line) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen);
+ QString id = getNewID();
+ item->setZValue(10000000);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ lastItem = item;
+ }
+ else if (mode == Rect) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsRectItem* item = scene()->addRect(point.x(), point.y(), 0, 0, pen, brush);
+ QString id = getNewID();
+ item->setZValue(10000000);
+ item->setData(0, point);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ lastItem = item;
+ }
+ else if (mode == Rubber) {
+ QPointF point = this->mapToScene(event->pos());
+ int w = pen.width();
+ QRectF rect(point.x()-w, point.y()-w, w*2, w*2);
+ QList<QGraphicsItem*> list = scene()->items(rect);
+ if (!list.isEmpty())
+ {
+ QGraphicsItem* item = scene()->items(rect).first();
+ QString id = item->data(100).toString();
+ int pos = items_.indexOf(item)+1;
+ itemDeleted(id, pos);
+ deleteItem(id);
+ }
+ }
+ else if (mode == Circle) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsEllipseItem* item = scene()->addEllipse(point.x(), point.y(), 0, 0, pen, brush);
+ QString id = getNewID();
+ item->setZValue(10000000);
+ item->setData(0, point);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ lastItem = item;
+ }
+ else if (mode == HandLine) {
+ QPointF point = this->mapToScene(event->pos());
+ FreehandLineItem* item = new FreehandLineItem;
+ QString id = getNewID();
+ item->setPen(pen);
+ item->setStartPoint(point);
+ item->setZValue(10000000);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ scene()->addItem(item);
+ lastItem = item;
+ }
+ else if (mode == Text) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsTextItem* item = scene()->addText("");
+ QString id = getNewID();
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ item->setDefaultTextColor(pen.color());
+ textDialog = new TextDialog(item, this);
+ connect(textDialog, SIGNAL(accepted(QGraphicsTextItem*)), this, SLOT(handleTextItemModified(QGraphicsTextItem*)));
+ textDialog->setAttribute(Qt::WA_DeleteOnClose);
+ textDialog->show();
+ item->setPos(point);
+ lastItem = item;
+ }
+ else if (mode == Polygon) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsPolygonItem* item = dynamic_cast<QGraphicsPolygonItem*>(lastItem);
+ if (item == 0) {
+ QPolygonF polygon;
+ polygon.append(point);
+ polygon.append(point);
+ item = scene()->addPolygon(polygon, pen, brush);
+ QString id = getNewID();
+ item->setZValue(10000000);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ lastItem = item;
+ }
+ else {
+ QPolygonF polygon;
+ polygon = item->polygon();
+ polygon.append(point);
+ item->setPolygon(polygon);
+ }
+ }
+ else if (mode == Select) {
+ QPointF point = this->mapToScene(event->pos());
+ int w = pen.width();
+ if (w == 0) {
+ w = 1;
+ }
+ QRectF rect(point.x()-w, point.y()-w, w*2, w*2);
+ QList<QGraphicsItem*> list = scene()->items(rect);
+ if (!list.isEmpty()) {
+ QPen pen;
+ pen.setColor(QColor(Qt::gray));
+ pen.setStyle(Qt::DashLine);
+ QGraphicsItem *item = scene()->items(rect).first();
+ selectionRect = scene()->addRect(item->boundingRect(), pen);
+ selectionRect->setZValue(1000000);
+ selectionRect->setData(0, item->pos()-point);
+ selectionRect->setPos(item->pos());
+ QVariant var(QVariant::UserType);
+ var.setValue(item);
+ selectionRect->setData(1, var);
+ setActualPenAndBrushFromItem(item);
+ }
+ }
+ }
+
+ void GView::mouseReleaseEvent(QMouseEvent* /*event*/)
+ {
+ mousePressed = false;
+ QGraphicsPolygonItem* polygon = dynamic_cast<QGraphicsPolygonItem*>(lastItem);
+ if (polygon && polygon->polygon().size() >= 3) {
+ lastItemChanged(polygon, items_.indexOf(polygon)+1, Update);
+ } else if (lastItem) {
+ zValue++;
+ lastItem->setZValue(zValue++);
+ items_.append(lastItem);
+ itemsMap_.insert(lastItem->data(100).toString(), lastItem);
+
+ lastItemChanged(lastItem, items_.size(), New);
+ } else if (selectionRect){
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ lastItemChanged(item, items_.indexOf(item)+1, Update);
+ }
+ }
+
+
+ void GView::handleTextItemModified(QGraphicsTextItem* item) {
+ lastItemChanged(item, item->data(101).toInt(), Update);
+ }
+
+ void GView::moveUpSelectedItem()
+ {
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ int pos = items_.indexOf(item);
+ if (pos < items_.size()-1) {
+ lastItemChanged(item, pos+1, MoveUp);
+ move(item, pos+2);
+ }
+ }
+ }
+
+ void GView::moveDownSelectedItem()
+ {
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ int pos = items_.indexOf(item);
+ if (pos > 0) {
+ lastItemChanged(item, pos+1, MoveDown);
+ move(item, pos);
+ }
+ }
+ }
+
+ void GView::move(QGraphicsItem* item, int npos) {
+ int pos = items_.indexOf(item);
+ QGraphicsItem* itemAfter = NULL;
+ if (npos-1 > pos) {
+ if (npos == items_.size()) {
+ item->setZValue(zValue++);
+ } else {
+ itemAfter = items_.at(npos);
+ }
+
+ items_.insert(npos, item);
+ items_.removeAt(pos);
+ } else if (npos-1 < pos) {
+ itemAfter = items_.at(npos-1);
+ items_.insert(npos-1, item);
+ items_.removeAt(pos+1);
+ }
+ if (itemAfter) {
+ item->setZValue(itemAfter->zValue());
+ item->stackBefore(itemAfter);
+ }
+ }
+
+ void GView::changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush) {
+ QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
+ if (lineItem) {
+ lineItem->setPen(pen);
+ }
+
+ FreehandLineItem* handLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
+ if (handLineItem) {
+ handLineItem->setPen(pen);
+ }
+
+ QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
+ if (rectItem) {
+ rectItem->setPen(pen);
+ rectItem->setBrush(brush);
+ }
+
+ QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
+ if (textItem) {
+ textItem->setDefaultTextColor(pen.color());
+ }
+
+ QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
+ if (polygonItem) {
+ polygonItem->setPen(pen);
+ polygonItem->setBrush(brush);
+ }
+
+ QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
+ if (ellipseItem) {
+ ellipseItem->setPen(pen);
+ ellipseItem->setBrush(brush);
+ }
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+
+ void GView::setActualPenAndBrushFromItem(QGraphicsItem* item) {
+ QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
+ if (lineItem) {
+ pen = lineItem->pen();
+ }
+
+ FreehandLineItem* handLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
+ if (handLineItem) {
+ pen = handLineItem->pen();
+ }
+
+ QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
+ if (rectItem) {
+ pen = rectItem->pen();
+ brush = rectItem->brush();
+ }
+
+ QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
+ if (textItem) {
+ pen.setColor(textItem->defaultTextColor());
+ }
+
+ QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
+ if (polygonItem) {
+ pen = polygonItem->pen();
+ brush = polygonItem->brush();
+ }
+
+ QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
+ if (ellipseItem) {
+ pen = ellipseItem->pen();
+ brush = ellipseItem->brush();
+ }
+ lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+
+ void GView::deselect() {
+ if (selectionRect != 0) {
+ pen = defaultPen;
+ brush = defaultBrush;
+ scene()->removeItem(selectionRect);
+ delete selectionRect;
+ selectionRect = 0;
+ lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+ }
+
+ void GView::deselect(QString id) {
+ if (selectionRect != 0) {
+ QGraphicsItem* item = getItem(id);
+ if (item && selectionRect->data(1).value<QGraphicsItem*>() == item) {
+ pen = defaultPen;
+ brush = defaultBrush;
+ scene()->removeItem(selectionRect);
+ delete selectionRect;
+ selectionRect = 0;
+ lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+ }
+ }
}
diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h
index 1cf5275..396e381 100644
--- a/Swift/QtUI/Whiteboard/GView.h
+++ b/Swift/QtUI/Whiteboard/GView.h
@@ -25,60 +25,60 @@
#include <Swift/QtUI/Whiteboard/TextDialog.h>
namespace Swift {
- class GView : public QGraphicsView {
- Q_OBJECT
- public:
- enum Mode { Rubber, Line, Rect, Circle, HandLine, Text, Polygon, Select };
- enum Type { New, Update, MoveUp, MoveDown };
- GView(QGraphicsScene* scene, QWidget* parent = 0);
- void setLineWidth(int i);
- void setLineColor(QColor color);
- QColor getLineColor();
- void setBrushColor(QColor color);
- QColor getBrushColor();
- void setMode(Mode mode);
- void mouseMoveEvent(QMouseEvent* event);
- void mousePressEvent(QMouseEvent* event);
- void mouseReleaseEvent(QMouseEvent* /*event*/);
- void addItem(QGraphicsItem* item, QString id, int pos);
- void clear();
- QGraphicsItem* getItem(QString id);
- void deleteItem(QString id);
- QString getNewID();
- void move(QGraphicsItem* item, int npos);
- void deselect(QString id);
+ class GView : public QGraphicsView {
+ Q_OBJECT
+ public:
+ enum Mode { Rubber, Line, Rect, Circle, HandLine, Text, Polygon, Select };
+ enum Type { New, Update, MoveUp, MoveDown };
+ GView(QGraphicsScene* scene, QWidget* parent = 0);
+ void setLineWidth(int i);
+ void setLineColor(QColor color);
+ QColor getLineColor();
+ void setBrushColor(QColor color);
+ QColor getBrushColor();
+ void setMode(Mode mode);
+ void mouseMoveEvent(QMouseEvent* event);
+ void mousePressEvent(QMouseEvent* event);
+ void mouseReleaseEvent(QMouseEvent* /*event*/);
+ void addItem(QGraphicsItem* item, QString id, int pos);
+ void clear();
+ QGraphicsItem* getItem(QString id);
+ void deleteItem(QString id);
+ QString getNewID();
+ void move(QGraphicsItem* item, int npos);
+ void deselect(QString id);
- signals:
- void lastItemChanged(QGraphicsItem* item, int pos, GView::Type type);
- void itemDeleted(QString id, int pos);
- void lineWidthChanged(int i);
- void lineColorChanged(QColor color);
- void brushColorChanged(QColor color);
+ signals:
+ void lastItemChanged(QGraphicsItem* item, int pos, GView::Type type);
+ void itemDeleted(QString id, int pos);
+ void lineWidthChanged(int i);
+ void lineColorChanged(QColor color);
+ void brushColorChanged(QColor color);
- public slots:
- void moveUpSelectedItem();
- void moveDownSelectedItem();
+ public slots:
+ void moveUpSelectedItem();
+ void moveDownSelectedItem();
- private slots:
- void handleTextItemModified(QGraphicsTextItem*);
+ private slots:
+ void handleTextItemModified(QGraphicsTextItem*);
- private:
- void changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush);
- void setActualPenAndBrushFromItem(QGraphicsItem* item);
- void deselect();
+ private:
+ void changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush);
+ void setActualPenAndBrushFromItem(QGraphicsItem* item);
+ void deselect();
- int zValue;
- bool mousePressed;
- QPen pen;
- QBrush brush;
- QPen defaultPen;
- QBrush defaultBrush;
- Mode mode;
- QGraphicsItem* lastItem;
- QGraphicsRectItem* selectionRect;
- TextDialog* textDialog;
- QMap<QString, QGraphicsItem*> itemsMap_;
- QList<QGraphicsItem*> items_;
- IDGenerator idGenerator;
- };
+ int zValue;
+ bool mousePressed;
+ QPen pen;
+ QBrush brush;
+ QPen defaultPen;
+ QBrush defaultBrush;
+ Mode mode;
+ QGraphicsItem* lastItem;
+ QGraphicsRectItem* selectionRect;
+ TextDialog* textDialog;
+ QMap<QString, QGraphicsItem*> itemsMap_;
+ QList<QGraphicsItem*> items_;
+ IDGenerator idGenerator;
+ };
}
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
index ca887d1..26887e0 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -32,374 +32,374 @@
#include <Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h>
namespace Swift {
- QtWhiteboardWindow::QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession) : QWidget() {
+ QtWhiteboardWindow::QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession) : QWidget() {
#ifndef Q_OS_MAC
#ifdef Q_OS_WIN32
- setWindowIcon(QIcon(":/logo-icon-16-win.png"));
+ setWindowIcon(QIcon(":/logo-icon-16-win.png"));
#else
- setWindowIcon(QIcon(":/logo-icon-16.png"));
+ setWindowIcon(QIcon(":/logo-icon-16.png"));
#endif
#endif
- layout = new QVBoxLayout(this);
- hLayout = new QHBoxLayout;
- sidebarLayout = new QVBoxLayout;
- toolboxLayout = new QGridLayout;
-
- scene = new QGraphicsScene(this);
- scene->setSceneRect(0, 0, 400, 400);
-
- graphicsView = new GView(scene, this);
- graphicsView->setMode(GView::Line);
- connect(graphicsView, SIGNAL(lastItemChanged(QGraphicsItem*, int, GView::Type)), this, SLOT(handleLastItemChanged(QGraphicsItem*, int, GView::Type)));
- connect(graphicsView, SIGNAL(itemDeleted(QString, int)), this, SLOT(handleItemDeleted(QString, int)));
-
- widthBox = new QSpinBox(this);
- connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int)));
- connect(graphicsView, SIGNAL(lineWidthChanged(int)), widthBox, SLOT(setValue(int)));
- widthBox->setValue(1);
-
- moveUpButton = new QPushButton("Move Up", this);
- connect(moveUpButton, SIGNAL(clicked()), graphicsView, SLOT(moveUpSelectedItem()));
-
- moveDownButton = new QPushButton("Move Down", this);
- connect(moveDownButton, SIGNAL(clicked()), graphicsView, SLOT(moveDownSelectedItem()));
-
- strokeLayout = new QHBoxLayout;
- strokeColor = new ColorWidget;
- strokeLayout->addWidget(new QLabel("Stroke:"));
- strokeLayout->addWidget(strokeColor);
- connect(strokeColor, SIGNAL(clicked()), this, SLOT(showColorDialog()));
- connect(graphicsView, SIGNAL(lineColorChanged(QColor)), strokeColor, SLOT(setColor(QColor)));
-
- fillLayout = new QHBoxLayout;
- fillColor = new ColorWidget;
- fillLayout->addWidget(new QLabel("Fill:"));
- fillLayout->addWidget(fillColor);
- connect(fillColor, SIGNAL(clicked()), this, SLOT(showBrushColorDialog()));
- connect(graphicsView, SIGNAL(brushColorChanged(QColor)), fillColor, SLOT(setColor(QColor)));
-
- rubberButton = new QToolButton(this);
- rubberButton->setIcon(QIcon(":/icons/eraser.png"));
- rubberButton->setCheckable(true);
- rubberButton->setAutoExclusive(true);
- connect(rubberButton, SIGNAL(clicked()), this, SLOT(setRubberMode()));
-
- lineButton = new QToolButton(this);
- lineButton->setIcon(QIcon(":/icons/line.png"));
- lineButton->setCheckable(true);
- lineButton->setAutoExclusive(true);
- lineButton->setChecked(true);
- connect(lineButton, SIGNAL(clicked()), this, SLOT(setLineMode()));
-
- rectButton = new QToolButton(this);
- rectButton->setIcon(QIcon(":/icons/rect.png"));
- rectButton->setCheckable(true);
- rectButton->setAutoExclusive(true);
- connect(rectButton, SIGNAL(clicked()), this, SLOT(setRectMode()));
-
- circleButton = new QToolButton(this);
- circleButton->setIcon(QIcon(":/icons/circle.png"));
- circleButton->setCheckable(true);
- circleButton->setAutoExclusive(true);
- connect(circleButton, SIGNAL(clicked()), this, SLOT(setCircleMode()));
-
- handLineButton = new QToolButton(this);
- handLineButton->setIcon(QIcon(":/icons/handline.png"));
- handLineButton->setCheckable(true);
- handLineButton->setAutoExclusive(true);
- connect(handLineButton, SIGNAL(clicked()), this, SLOT(setHandLineMode()));
-
- textButton = new QToolButton(this);
- textButton->setIcon(QIcon(":/icons/text.png"));
- textButton->setCheckable(true);
- textButton->setAutoExclusive(true);
- connect(textButton, SIGNAL(clicked()), this, SLOT(setTextMode()));
-
- polygonButton = new QToolButton(this);
- polygonButton->setIcon(QIcon(":/icons/polygon.png"));
- polygonButton->setCheckable(true);
- polygonButton->setAutoExclusive(true);
- connect(polygonButton, SIGNAL(clicked()), this, SLOT(setPolygonMode()));
-
- selectButton = new QToolButton(this);
- selectButton->setIcon(QIcon(":/icons/cursor.png"));
- selectButton->setCheckable(true);
- selectButton->setAutoExclusive(true);
- connect(selectButton, SIGNAL(clicked()), this, SLOT(setSelectMode()));
-
- toolboxLayout->addWidget(rubberButton, 0, 0);
- toolboxLayout->addWidget(selectButton, 0, 1);
- toolboxLayout->addWidget(lineButton, 0, 2);
- toolboxLayout->addWidget(circleButton, 1, 0);
- toolboxLayout->addWidget(handLineButton, 1, 1);
- toolboxLayout->addWidget(rectButton, 1, 2);
- toolboxLayout->addWidget(textButton, 2, 0);
- toolboxLayout->addWidget(polygonButton, 2, 1);
-
- sidebarLayout->addLayout(toolboxLayout);
- sidebarLayout->addSpacing(30);
- sidebarLayout->addWidget(moveUpButton);
- sidebarLayout->addWidget(moveDownButton);
- sidebarLayout->addSpacing(40);
- sidebarLayout->addWidget(widthBox);
- sidebarLayout->addLayout(strokeLayout);
- sidebarLayout->addLayout(fillLayout);
- sidebarLayout->addStretch();
- hLayout->addWidget(graphicsView);
- hLayout->addLayout(sidebarLayout);
- layout->addLayout(hLayout);
- this->setLayout(layout);
-
- setSession(whiteboardSession);
- }
-
- void QtWhiteboardWindow::handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation) {
- WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation);
- if (insertOp) {
- WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::New);
- insertOp->getElement()->accept(visitor);
- }
-
- WhiteboardUpdateOperation::ref updateOp = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(operation);
- if (updateOp) {
- WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::Update);
- updateOp->getElement()->accept(visitor);
- if (updateOp->getPos() != updateOp->getNewPos()) {
- graphicsView->move(graphicsView->getItem(P2QSTRING(updateOp->getElement()->getID())), updateOp->getNewPos());
- }
- }
-
- WhiteboardDeleteOperation::ref deleteOp = boost::dynamic_pointer_cast<WhiteboardDeleteOperation>(operation);
- if (deleteOp) {
- graphicsView->deleteItem(P2QSTRING(deleteOp->getElementID()));
- }
- }
-
- void QtWhiteboardWindow::changeLineWidth(int i)
- {
- graphicsView->setLineWidth(i);
- }
-
- void QtWhiteboardWindow::showColorDialog()
- {
- QColor color = QColorDialog::getColor(graphicsView->getLineColor(), 0, "Select pen color", QColorDialog::ShowAlphaChannel);
- if(color.isValid())
- graphicsView->setLineColor(color);
- }
-
- void QtWhiteboardWindow::showBrushColorDialog()
- {
- QColor color = QColorDialog::getColor(graphicsView->getBrushColor(), 0, "Select brush color", QColorDialog::ShowAlphaChannel);
- if(color.isValid())
- graphicsView->setBrushColor(color);
- }
-
- void QtWhiteboardWindow::setRubberMode()
- {
- graphicsView->setMode(GView::Rubber);
- }
-
- void QtWhiteboardWindow::setLineMode()
- {
- graphicsView->setMode(GView::Line);
- }
-
- void QtWhiteboardWindow::setRectMode()
- {
- graphicsView->setMode(GView::Rect);
- }
-
- void QtWhiteboardWindow::setCircleMode()
- {
- graphicsView->setMode(GView::Circle);
- }
-
- void QtWhiteboardWindow::setHandLineMode()
- {
- graphicsView->setMode(GView::HandLine);
- }
-
- void QtWhiteboardWindow::setTextMode()
- {
- graphicsView->setMode(GView::Text);
- }
-
- void QtWhiteboardWindow::setPolygonMode()
- {
- graphicsView->setMode(GView::Polygon);
- }
-
- void QtWhiteboardWindow::setSelectMode()
- {
- graphicsView->setMode(GView::Select);
- }
-
- void QtWhiteboardWindow::show()
- {
- QWidget::show();
- }
-
- void QtWhiteboardWindow::setSession(WhiteboardSession::ref session) {
- graphicsView->clear();
- whiteboardSession_ = session;
- whiteboardSession_->onOperationReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardOperationReceive, this, _1));
- whiteboardSession_->onRequestAccepted.connect(boost::bind(&QWidget::show, this));
- whiteboardSession_->onSessionTerminated.connect(boost::bind(&QtWhiteboardWindow::handleSessionTerminate, this));
- }
-
- void QtWhiteboardWindow::activateWindow() {
- QWidget::activateWindow();
- }
-
- void QtWhiteboardWindow::setName(const std::string& name) {
- setWindowTitle(P2QSTRING(name));
- }
-
- void QtWhiteboardWindow::handleLastItemChanged(QGraphicsItem* item, int pos, GView::Type type) {
- WhiteboardElement::ref el;
- QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
- if (lineItem != 0) {
- QLine line = lineItem->line().toLine();
- QColor color = lineItem->pen().color();
- WhiteboardLineElement::ref element = boost::make_shared<WhiteboardLineElement>(line.x1()+lineItem->pos().x(), line.y1()+lineItem->pos().y(), line.x2()+lineItem->pos().x(), line.y2()+lineItem->pos().y());
- element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
- element->setPenWidth(lineItem->pen().width());
-
- element->setID(lineItem->data(100).toString().toStdString());
- el = element;
- }
-
- FreehandLineItem* freehandLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
- if (freehandLineItem != 0) {
- WhiteboardFreehandPathElement::ref element = boost::make_shared<WhiteboardFreehandPathElement>();
- QColor color = freehandLineItem->pen().color();
- std::vector<std::pair<int, int> > points;
- QVector<QPointF>::const_iterator it = freehandLineItem->points().constBegin();
- for ( ; it != freehandLineItem->points().constEnd(); ++it) {
- points.push_back(std::pair<int, int>(
- boost::numeric_cast<int>(it->x()+item->pos().x()),
- boost::numeric_cast<int>(it->y()+item->pos().y())));
- }
-
- element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
- element->setPenWidth(freehandLineItem->pen().width());
- element->setPoints(points);
-
- element->setID(freehandLineItem->data(100).toString().toStdString());
- el = element;
- }
-
- QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
- if (rectItem != 0) {
- QRectF rect = rectItem->rect();
- WhiteboardRectElement::ref element = boost::make_shared<WhiteboardRectElement>(rect.x()+item->pos().x(), rect.y()+item->pos().y(), rect.width(), rect.height());
- QColor penColor = rectItem->pen().color();
- QColor brushColor = rectItem->brush().color();
-
- element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
- element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
- element->setPenWidth(rectItem->pen().width());
-
- element->setID(rectItem->data(100).toString().toStdString());
- el = element;
- }
-
- QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
- if (textItem != 0) {
- QPointF point = textItem->pos();
- WhiteboardTextElement::ref element = boost::make_shared<WhiteboardTextElement>(point.x(), point.y());
- element->setText(textItem->toPlainText().toStdString());
- element->setSize(textItem->font().pointSize());
- QColor color = textItem->defaultTextColor();
- element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
-
- element->setID(textItem->data(100).toString().toStdString());
- el = element;
- }
-
- QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
- if (polygonItem) {
- WhiteboardPolygonElement::ref element = boost::make_shared<WhiteboardPolygonElement>();
- QPolygonF polygon = polygonItem->polygon();
- std::vector<std::pair<int, int> > points;
- QVector<QPointF>::const_iterator it = polygon.begin();
- for (; it != polygon.end(); ++it) {
- points.push_back(std::pair<int, int>(
- boost::numeric_cast<int>(it->x()+item->pos().x()),
- boost::numeric_cast<int>(it->y()+item->pos().y())));
- }
-
- element->setPoints(points);
-
- QColor penColor = polygonItem->pen().color();
- QColor brushColor = polygonItem->brush().color();
- element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
- element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
- element->setPenWidth(polygonItem->pen().width());
-
- element->setID(polygonItem->data(100).toString().toStdString());
- el = element;
- }
-
- QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
- if (ellipseItem) {
- QRectF rect = ellipseItem->rect();
- int cx = boost::numeric_cast<int>(rect.x()+rect.width()/2 + item->pos().x());
- int cy = boost::numeric_cast<int>(rect.y()+rect.height()/2 + item->pos().y());
- int rx = boost::numeric_cast<int>(rect.width()/2);
- int ry = boost::numeric_cast<int>(rect.height()/2);
- WhiteboardEllipseElement::ref element = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry);
-
- QColor penColor = ellipseItem->pen().color();
- QColor brushColor = ellipseItem->brush().color();
- element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
- element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
- element->setPenWidth(ellipseItem->pen().width());
-
- element->setID(ellipseItem->data(100).toString().toStdString());
- el = element;
- }
-
- if (type == GView::New) {
- WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>();
- insertOp->setPos(pos);
- insertOp->setElement(el);
- whiteboardSession_->sendOperation(insertOp);
- } else {
- WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>();
- updateOp->setPos(pos);
- if (type == GView::Update) {
- updateOp->setNewPos(pos);
- } else if (type == GView::MoveUp) {
- updateOp->setNewPos(pos+1);
- } else if (type == GView::MoveDown) {
- updateOp->setNewPos(pos-1);
- }
- updateOp->setElement(el);
- whiteboardSession_->sendOperation(updateOp);
- }
- }
-
- void QtWhiteboardWindow::handleItemDeleted(QString id, int pos) {
- WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>();
- deleteOp->setElementID(Q2PSTRING(id));
- deleteOp->setPos(pos);
- whiteboardSession_->sendOperation(deleteOp);
- }
-
- void QtWhiteboardWindow::handleSessionTerminate() {
- hide();
- }
-
- void QtWhiteboardWindow::closeEvent(QCloseEvent* event) {
- QMessageBox box(this);
- box.setText(tr("Closing window is equivalent closing the session. Are you sure you want to do this?"));
- box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- box.setIcon(QMessageBox::Question);
- if (box.exec() == QMessageBox::Yes) {
- whiteboardSession_->cancel();
- } else {
- event->ignore();
- }
- }
+ layout = new QVBoxLayout(this);
+ hLayout = new QHBoxLayout;
+ sidebarLayout = new QVBoxLayout;
+ toolboxLayout = new QGridLayout;
+
+ scene = new QGraphicsScene(this);
+ scene->setSceneRect(0, 0, 400, 400);
+
+ graphicsView = new GView(scene, this);
+ graphicsView->setMode(GView::Line);
+ connect(graphicsView, SIGNAL(lastItemChanged(QGraphicsItem*, int, GView::Type)), this, SLOT(handleLastItemChanged(QGraphicsItem*, int, GView::Type)));
+ connect(graphicsView, SIGNAL(itemDeleted(QString, int)), this, SLOT(handleItemDeleted(QString, int)));
+
+ widthBox = new QSpinBox(this);
+ connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int)));
+ connect(graphicsView, SIGNAL(lineWidthChanged(int)), widthBox, SLOT(setValue(int)));
+ widthBox->setValue(1);
+
+ moveUpButton = new QPushButton("Move Up", this);
+ connect(moveUpButton, SIGNAL(clicked()), graphicsView, SLOT(moveUpSelectedItem()));
+
+ moveDownButton = new QPushButton("Move Down", this);
+ connect(moveDownButton, SIGNAL(clicked()), graphicsView, SLOT(moveDownSelectedItem()));
+
+ strokeLayout = new QHBoxLayout;
+ strokeColor = new ColorWidget;
+ strokeLayout->addWidget(new QLabel("Stroke:"));
+ strokeLayout->addWidget(strokeColor);
+ connect(strokeColor, SIGNAL(clicked()), this, SLOT(showColorDialog()));
+ connect(graphicsView, SIGNAL(lineColorChanged(QColor)), strokeColor, SLOT(setColor(QColor)));
+
+ fillLayout = new QHBoxLayout;
+ fillColor = new ColorWidget;
+ fillLayout->addWidget(new QLabel("Fill:"));
+ fillLayout->addWidget(fillColor);
+ connect(fillColor, SIGNAL(clicked()), this, SLOT(showBrushColorDialog()));
+ connect(graphicsView, SIGNAL(brushColorChanged(QColor)), fillColor, SLOT(setColor(QColor)));
+
+ rubberButton = new QToolButton(this);
+ rubberButton->setIcon(QIcon(":/icons/eraser.png"));
+ rubberButton->setCheckable(true);
+ rubberButton->setAutoExclusive(true);
+ connect(rubberButton, SIGNAL(clicked()), this, SLOT(setRubberMode()));
+
+ lineButton = new QToolButton(this);
+ lineButton->setIcon(QIcon(":/icons/line.png"));
+ lineButton->setCheckable(true);
+ lineButton->setAutoExclusive(true);
+ lineButton->setChecked(true);
+ connect(lineButton, SIGNAL(clicked()), this, SLOT(setLineMode()));
+
+ rectButton = new QToolButton(this);
+ rectButton->setIcon(QIcon(":/icons/rect.png"));
+ rectButton->setCheckable(true);
+ rectButton->setAutoExclusive(true);
+ connect(rectButton, SIGNAL(clicked()), this, SLOT(setRectMode()));
+
+ circleButton = new QToolButton(this);
+ circleButton->setIcon(QIcon(":/icons/circle.png"));
+ circleButton->setCheckable(true);
+ circleButton->setAutoExclusive(true);
+ connect(circleButton, SIGNAL(clicked()), this, SLOT(setCircleMode()));
+
+ handLineButton = new QToolButton(this);
+ handLineButton->setIcon(QIcon(":/icons/handline.png"));
+ handLineButton->setCheckable(true);
+ handLineButton->setAutoExclusive(true);
+ connect(handLineButton, SIGNAL(clicked()), this, SLOT(setHandLineMode()));
+
+ textButton = new QToolButton(this);
+ textButton->setIcon(QIcon(":/icons/text.png"));
+ textButton->setCheckable(true);
+ textButton->setAutoExclusive(true);
+ connect(textButton, SIGNAL(clicked()), this, SLOT(setTextMode()));
+
+ polygonButton = new QToolButton(this);
+ polygonButton->setIcon(QIcon(":/icons/polygon.png"));
+ polygonButton->setCheckable(true);
+ polygonButton->setAutoExclusive(true);
+ connect(polygonButton, SIGNAL(clicked()), this, SLOT(setPolygonMode()));
+
+ selectButton = new QToolButton(this);
+ selectButton->setIcon(QIcon(":/icons/cursor.png"));
+ selectButton->setCheckable(true);
+ selectButton->setAutoExclusive(true);
+ connect(selectButton, SIGNAL(clicked()), this, SLOT(setSelectMode()));
+
+ toolboxLayout->addWidget(rubberButton, 0, 0);
+ toolboxLayout->addWidget(selectButton, 0, 1);
+ toolboxLayout->addWidget(lineButton, 0, 2);
+ toolboxLayout->addWidget(circleButton, 1, 0);
+ toolboxLayout->addWidget(handLineButton, 1, 1);
+ toolboxLayout->addWidget(rectButton, 1, 2);
+ toolboxLayout->addWidget(textButton, 2, 0);
+ toolboxLayout->addWidget(polygonButton, 2, 1);
+
+ sidebarLayout->addLayout(toolboxLayout);
+ sidebarLayout->addSpacing(30);
+ sidebarLayout->addWidget(moveUpButton);
+ sidebarLayout->addWidget(moveDownButton);
+ sidebarLayout->addSpacing(40);
+ sidebarLayout->addWidget(widthBox);
+ sidebarLayout->addLayout(strokeLayout);
+ sidebarLayout->addLayout(fillLayout);
+ sidebarLayout->addStretch();
+ hLayout->addWidget(graphicsView);
+ hLayout->addLayout(sidebarLayout);
+ layout->addLayout(hLayout);
+ this->setLayout(layout);
+
+ setSession(whiteboardSession);
+ }
+
+ void QtWhiteboardWindow::handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation) {
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation);
+ if (insertOp) {
+ WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::New);
+ insertOp->getElement()->accept(visitor);
+ }
+
+ WhiteboardUpdateOperation::ref updateOp = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(operation);
+ if (updateOp) {
+ WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::Update);
+ updateOp->getElement()->accept(visitor);
+ if (updateOp->getPos() != updateOp->getNewPos()) {
+ graphicsView->move(graphicsView->getItem(P2QSTRING(updateOp->getElement()->getID())), updateOp->getNewPos());
+ }
+ }
+
+ WhiteboardDeleteOperation::ref deleteOp = boost::dynamic_pointer_cast<WhiteboardDeleteOperation>(operation);
+ if (deleteOp) {
+ graphicsView->deleteItem(P2QSTRING(deleteOp->getElementID()));
+ }
+ }
+
+ void QtWhiteboardWindow::changeLineWidth(int i)
+ {
+ graphicsView->setLineWidth(i);
+ }
+
+ void QtWhiteboardWindow::showColorDialog()
+ {
+ QColor color = QColorDialog::getColor(graphicsView->getLineColor(), 0, "Select pen color", QColorDialog::ShowAlphaChannel);
+ if(color.isValid())
+ graphicsView->setLineColor(color);
+ }
+
+ void QtWhiteboardWindow::showBrushColorDialog()
+ {
+ QColor color = QColorDialog::getColor(graphicsView->getBrushColor(), 0, "Select brush color", QColorDialog::ShowAlphaChannel);
+ if(color.isValid())
+ graphicsView->setBrushColor(color);
+ }
+
+ void QtWhiteboardWindow::setRubberMode()
+ {
+ graphicsView->setMode(GView::Rubber);
+ }
+
+ void QtWhiteboardWindow::setLineMode()
+ {
+ graphicsView->setMode(GView::Line);
+ }
+
+ void QtWhiteboardWindow::setRectMode()
+ {
+ graphicsView->setMode(GView::Rect);
+ }
+
+ void QtWhiteboardWindow::setCircleMode()
+ {
+ graphicsView->setMode(GView::Circle);
+ }
+
+ void QtWhiteboardWindow::setHandLineMode()
+ {
+ graphicsView->setMode(GView::HandLine);
+ }
+
+ void QtWhiteboardWindow::setTextMode()
+ {
+ graphicsView->setMode(GView::Text);
+ }
+
+ void QtWhiteboardWindow::setPolygonMode()
+ {
+ graphicsView->setMode(GView::Polygon);
+ }
+
+ void QtWhiteboardWindow::setSelectMode()
+ {
+ graphicsView->setMode(GView::Select);
+ }
+
+ void QtWhiteboardWindow::show()
+ {
+ QWidget::show();
+ }
+
+ void QtWhiteboardWindow::setSession(WhiteboardSession::ref session) {
+ graphicsView->clear();
+ whiteboardSession_ = session;
+ whiteboardSession_->onOperationReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardOperationReceive, this, _1));
+ whiteboardSession_->onRequestAccepted.connect(boost::bind(&QWidget::show, this));
+ whiteboardSession_->onSessionTerminated.connect(boost::bind(&QtWhiteboardWindow::handleSessionTerminate, this));
+ }
+
+ void QtWhiteboardWindow::activateWindow() {
+ QWidget::activateWindow();
+ }
+
+ void QtWhiteboardWindow::setName(const std::string& name) {
+ setWindowTitle(P2QSTRING(name));
+ }
+
+ void QtWhiteboardWindow::handleLastItemChanged(QGraphicsItem* item, int pos, GView::Type type) {
+ WhiteboardElement::ref el;
+ QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
+ if (lineItem != 0) {
+ QLine line = lineItem->line().toLine();
+ QColor color = lineItem->pen().color();
+ WhiteboardLineElement::ref element = boost::make_shared<WhiteboardLineElement>(line.x1()+lineItem->pos().x(), line.y1()+lineItem->pos().y(), line.x2()+lineItem->pos().x(), line.y2()+lineItem->pos().y());
+ element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
+ element->setPenWidth(lineItem->pen().width());
+
+ element->setID(lineItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ FreehandLineItem* freehandLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
+ if (freehandLineItem != 0) {
+ WhiteboardFreehandPathElement::ref element = boost::make_shared<WhiteboardFreehandPathElement>();
+ QColor color = freehandLineItem->pen().color();
+ std::vector<std::pair<int, int> > points;
+ QVector<QPointF>::const_iterator it = freehandLineItem->points().constBegin();
+ for ( ; it != freehandLineItem->points().constEnd(); ++it) {
+ points.push_back(std::pair<int, int>(
+ boost::numeric_cast<int>(it->x()+item->pos().x()),
+ boost::numeric_cast<int>(it->y()+item->pos().y())));
+ }
+
+ element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
+ element->setPenWidth(freehandLineItem->pen().width());
+ element->setPoints(points);
+
+ element->setID(freehandLineItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
+ if (rectItem != 0) {
+ QRectF rect = rectItem->rect();
+ WhiteboardRectElement::ref element = boost::make_shared<WhiteboardRectElement>(rect.x()+item->pos().x(), rect.y()+item->pos().y(), rect.width(), rect.height());
+ QColor penColor = rectItem->pen().color();
+ QColor brushColor = rectItem->brush().color();
+
+ element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
+ element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
+ element->setPenWidth(rectItem->pen().width());
+
+ element->setID(rectItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
+ if (textItem != 0) {
+ QPointF point = textItem->pos();
+ WhiteboardTextElement::ref element = boost::make_shared<WhiteboardTextElement>(point.x(), point.y());
+ element->setText(textItem->toPlainText().toStdString());
+ element->setSize(textItem->font().pointSize());
+ QColor color = textItem->defaultTextColor();
+ element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
+
+ element->setID(textItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
+ if (polygonItem) {
+ WhiteboardPolygonElement::ref element = boost::make_shared<WhiteboardPolygonElement>();
+ QPolygonF polygon = polygonItem->polygon();
+ std::vector<std::pair<int, int> > points;
+ QVector<QPointF>::const_iterator it = polygon.begin();
+ for (; it != polygon.end(); ++it) {
+ points.push_back(std::pair<int, int>(
+ boost::numeric_cast<int>(it->x()+item->pos().x()),
+ boost::numeric_cast<int>(it->y()+item->pos().y())));
+ }
+
+ element->setPoints(points);
+
+ QColor penColor = polygonItem->pen().color();
+ QColor brushColor = polygonItem->brush().color();
+ element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
+ element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
+ element->setPenWidth(polygonItem->pen().width());
+
+ element->setID(polygonItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
+ if (ellipseItem) {
+ QRectF rect = ellipseItem->rect();
+ int cx = boost::numeric_cast<int>(rect.x()+rect.width()/2 + item->pos().x());
+ int cy = boost::numeric_cast<int>(rect.y()+rect.height()/2 + item->pos().y());
+ int rx = boost::numeric_cast<int>(rect.width()/2);
+ int ry = boost::numeric_cast<int>(rect.height()/2);
+ WhiteboardEllipseElement::ref element = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry);
+
+ QColor penColor = ellipseItem->pen().color();
+ QColor brushColor = ellipseItem->brush().color();
+ element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
+ element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
+ element->setPenWidth(ellipseItem->pen().width());
+
+ element->setID(ellipseItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ if (type == GView::New) {
+ WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>();
+ insertOp->setPos(pos);
+ insertOp->setElement(el);
+ whiteboardSession_->sendOperation(insertOp);
+ } else {
+ WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>();
+ updateOp->setPos(pos);
+ if (type == GView::Update) {
+ updateOp->setNewPos(pos);
+ } else if (type == GView::MoveUp) {
+ updateOp->setNewPos(pos+1);
+ } else if (type == GView::MoveDown) {
+ updateOp->setNewPos(pos-1);
+ }
+ updateOp->setElement(el);
+ whiteboardSession_->sendOperation(updateOp);
+ }
+ }
+
+ void QtWhiteboardWindow::handleItemDeleted(QString id, int pos) {
+ WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>();
+ deleteOp->setElementID(Q2PSTRING(id));
+ deleteOp->setPos(pos);
+ whiteboardSession_->sendOperation(deleteOp);
+ }
+
+ void QtWhiteboardWindow::handleSessionTerminate() {
+ hide();
+ }
+
+ void QtWhiteboardWindow::closeEvent(QCloseEvent* event) {
+ QMessageBox box(this);
+ box.setText(tr("Closing window is equivalent closing the session. Are you sure you want to do this?"));
+ box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ box.setIcon(QMessageBox::Question);
+ if (box.exec() == QMessageBox::Yes) {
+ whiteboardSession_->cancel();
+ } else {
+ event->ignore();
+ }
+ }
}
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
index 862ae66..3b3f74e 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
@@ -35,61 +35,61 @@
#include <Swift/QtUI/Whiteboard/GView.h>
namespace Swift {
- class QtWhiteboardWindow : public QWidget, public WhiteboardWindow
- {
- Q_OBJECT
- public:
- QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession);
- void show();
- void setSession(WhiteboardSession::ref session);
- void activateWindow();
- void setName(const std::string& name);
+ class QtWhiteboardWindow : public QWidget, public WhiteboardWindow
+ {
+ Q_OBJECT
+ public:
+ QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession);
+ void show();
+ void setSession(WhiteboardSession::ref session);
+ void activateWindow();
+ void setName(const std::string& name);
- private slots:
- void changeLineWidth(int i);
- void showColorDialog();
- void showBrushColorDialog();
- void setRubberMode();
- void setLineMode();
- void setRectMode();
- void setCircleMode();
- void setHandLineMode();
- void setTextMode();
- void setPolygonMode();
- void setSelectMode();
- void handleLastItemChanged(QGraphicsItem* item, int pos, GView::Type type);
- void handleItemDeleted(QString id, int pos);
+ private slots:
+ void changeLineWidth(int i);
+ void showColorDialog();
+ void showBrushColorDialog();
+ void setRubberMode();
+ void setLineMode();
+ void setRectMode();
+ void setCircleMode();
+ void setHandLineMode();
+ void setTextMode();
+ void setPolygonMode();
+ void setSelectMode();
+ void handleLastItemChanged(QGraphicsItem* item, int pos, GView::Type type);
+ void handleItemDeleted(QString id, int pos);
- private:
- void handleSessionTerminate();
- void handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation);
- void closeEvent(QCloseEvent* event);
+ private:
+ void handleSessionTerminate();
+ void handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation);
+ void closeEvent(QCloseEvent* event);
- private:
- QGraphicsScene* scene;
- GView* graphicsView;
- QVBoxLayout* layout;
- QVBoxLayout* sidebarLayout;
- QHBoxLayout* hLayout;
- QGridLayout* toolboxLayout;
- QHBoxLayout* strokeLayout;
- QHBoxLayout* fillLayout;
- ColorWidget* strokeColor;
- ColorWidget* fillColor;
- QWidget* widget;
- QPushButton* moveUpButton;
- QPushButton* moveDownButton;
- QSpinBox* widthBox;
- QToolButton* rubberButton;
- QToolButton* lineButton;
- QToolButton* rectButton;
- QToolButton* circleButton;
- QToolButton* handLineButton;
- QToolButton* textButton;
- QToolButton* polygonButton;
- QToolButton* selectButton;
+ private:
+ QGraphicsScene* scene;
+ GView* graphicsView;
+ QVBoxLayout* layout;
+ QVBoxLayout* sidebarLayout;
+ QHBoxLayout* hLayout;
+ QGridLayout* toolboxLayout;
+ QHBoxLayout* strokeLayout;
+ QHBoxLayout* fillLayout;
+ ColorWidget* strokeColor;
+ ColorWidget* fillColor;
+ QWidget* widget;
+ QPushButton* moveUpButton;
+ QPushButton* moveDownButton;
+ QSpinBox* widthBox;
+ QToolButton* rubberButton;
+ QToolButton* lineButton;
+ QToolButton* rectButton;
+ QToolButton* circleButton;
+ QToolButton* handLineButton;
+ QToolButton* textButton;
+ QToolButton* polygonButton;
+ QToolButton* selectButton;
- std::string lastOpID;
- WhiteboardSession::ref whiteboardSession_;
- };
+ std::string lastOpID;
+ WhiteboardSession::ref whiteboardSession_;
+ };
}
diff --git a/Swift/QtUI/Whiteboard/TextDialog.cpp b/Swift/QtUI/Whiteboard/TextDialog.cpp
index 13d83d5..c15e7b4 100644
--- a/Swift/QtUI/Whiteboard/TextDialog.cpp
+++ b/Swift/QtUI/Whiteboard/TextDialog.cpp
@@ -13,46 +13,46 @@
#include <Swift/QtUI/Whiteboard/TextDialog.h>
namespace Swift {
- TextDialog::TextDialog(QGraphicsTextItem* item, QWidget* parent) : QDialog(parent)
- {
- this->item = item;
-
- layout = new QVBoxLayout(this);
- hLayout = new QHBoxLayout;
-
- editor = new QLineEdit(this);
- connect(editor, SIGNAL(textChanged(const QString&)), this, SLOT(changeItemText(const QString&)));
-
- fontSizeBox = new QSpinBox(this);
- fontSizeBox->setMinimum(1);
- connect(fontSizeBox, SIGNAL(valueChanged(int)), this, SLOT(changeItemFontSize(int)));
- fontSizeBox->setValue(13);
-
-
- buttonBox = new QDialogButtonBox(this);
- buttonBox->setStandardButtons(QDialogButtonBox::Ok);
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
-
- hLayout->addWidget(editor);
- hLayout->addWidget(fontSizeBox);
- layout->addLayout(hLayout);
- layout->addWidget(buttonBox);
- }
-
- void TextDialog::changeItemText(const QString &text)
- {
- item->setPlainText(text);
- }
-
- void TextDialog::changeItemFontSize(int i)
- {
- QFont font = item->font();
- font.setPointSize(i);
- item->setFont(font);
- }
-
- void TextDialog::accept() {
- emit accepted(item);
- done(QDialog::Accepted);
- }
+ TextDialog::TextDialog(QGraphicsTextItem* item, QWidget* parent) : QDialog(parent)
+ {
+ this->item = item;
+
+ layout = new QVBoxLayout(this);
+ hLayout = new QHBoxLayout;
+
+ editor = new QLineEdit(this);
+ connect(editor, SIGNAL(textChanged(const QString&)), this, SLOT(changeItemText(const QString&)));
+
+ fontSizeBox = new QSpinBox(this);
+ fontSizeBox->setMinimum(1);
+ connect(fontSizeBox, SIGNAL(valueChanged(int)), this, SLOT(changeItemFontSize(int)));
+ fontSizeBox->setValue(13);
+
+
+ buttonBox = new QDialogButtonBox(this);
+ buttonBox->setStandardButtons(QDialogButtonBox::Ok);
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+
+ hLayout->addWidget(editor);
+ hLayout->addWidget(fontSizeBox);
+ layout->addLayout(hLayout);
+ layout->addWidget(buttonBox);
+ }
+
+ void TextDialog::changeItemText(const QString &text)
+ {
+ item->setPlainText(text);
+ }
+
+ void TextDialog::changeItemFontSize(int i)
+ {
+ QFont font = item->font();
+ font.setPointSize(i);
+ item->setFont(font);
+ }
+
+ void TextDialog::accept() {
+ emit accepted(item);
+ done(QDialog::Accepted);
+ }
}
diff --git a/Swift/QtUI/Whiteboard/TextDialog.h b/Swift/QtUI/Whiteboard/TextDialog.h
index 911bd37..31bd096 100644
--- a/Swift/QtUI/Whiteboard/TextDialog.h
+++ b/Swift/QtUI/Whiteboard/TextDialog.h
@@ -23,27 +23,27 @@
#include <QVBoxLayout>
namespace Swift {
- class TextDialog : public QDialog
- {
- Q_OBJECT
- public:
- TextDialog(QGraphicsTextItem* item, QWidget* parent = 0);
-
- private:
- QGraphicsTextItem* item;
- QLineEdit* editor;
- QDialogButtonBox* buttonBox;
- QVBoxLayout* layout;
- QHBoxLayout* hLayout;
- QSpinBox* fontSizeBox;
-
- signals:
- void accepted(QGraphicsTextItem* item);
-
- private slots:
- void accept();
- void changeItemText(const QString &text);
- void changeItemFontSize(int i);
- };
+ class TextDialog : public QDialog
+ {
+ Q_OBJECT
+ public:
+ TextDialog(QGraphicsTextItem* item, QWidget* parent = 0);
+
+ private:
+ QGraphicsTextItem* item;
+ QLineEdit* editor;
+ QDialogButtonBox* buttonBox;
+ QVBoxLayout* layout;
+ QHBoxLayout* hLayout;
+ QSpinBox* fontSizeBox;
+
+ signals:
+ void accepted(QGraphicsTextItem* item);
+
+ private slots:
+ void accept();
+ void changeItemText(const QString &text);
+ void changeItemFontSize(int i);
+ };
}
diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
index 4d37704..719725c 100644
--- a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
+++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
@@ -23,172 +23,172 @@
#include <Swift/QtUI/Whiteboard/GView.h>
namespace Swift {
- class WhiteboardElementDrawingVisitor : public WhiteboardElementVisitor {
- public:
- WhiteboardElementDrawingVisitor(GView* graphicsView, int pos, GView::Type type) : graphicsView_(graphicsView), pos_(pos), type_(type) {}
-
- void visit(WhiteboardLineElement& element) {
- QGraphicsLineItem *item;
- if (type_ == GView::New) {
- item = new QGraphicsLineItem(element.x1(), element.y1(), element.x2(), element.y2());
- graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
- } else {
- item = qgraphicsitem_cast<QGraphicsLineItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
- QLineF line(element.x1(), element.y1(), element.x2(), element.y2());
- item->setLine(line);
- item->setPos(0,0);
- graphicsView_->deselect(P2QSTRING(element.getID()));
- }
- if (item) {
- QPen pen;
- WhiteboardColor color = element.getColor();
- pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
- pen.setWidth(element.getPenWidth());
- item->setPen(pen);
- QString id = P2QSTRING(element.getID());
- item->setData(100, id);
- }
- }
-
- void visit(WhiteboardFreehandPathElement& element) {
- FreehandLineItem *item;
- if (type_ == GView::New) {
- item = new FreehandLineItem;
- } else {
- item = qgraphicsitem_cast<FreehandLineItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
- item->setPos(0,0);
- graphicsView_->deselect(P2QSTRING(element.getID()));
- }
-
- if (item) {
- QPen pen;
- WhiteboardColor color = element.getColor();
- pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
- pen.setWidth(element.getPenWidth());
- item->setPen(pen);
-
- std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin();
- item->setStartPoint(QPointF(it->first, it->second));
- for (++it; it != element.getPoints().end(); ++it) {
- item->lineTo(QPointF(it->first, it->second));
- }
-
- QString id = P2QSTRING(element.getID());
- item->setData(100, id);
- }
- if (type_ == GView::New) {
- graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
- }
- }
-
- void visit(WhiteboardRectElement& element) {
- QGraphicsRectItem* item;
- if (type_ == GView::New) {
- item = new QGraphicsRectItem(element.getX(), element.getY(), element.getWidth(), element.getHeight());
- graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
- } else {
- item = qgraphicsitem_cast<QGraphicsRectItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
- QRectF rect(element.getX(), element.getY(), element.getWidth(), element.getHeight());
- item->setRect(rect);
- item->setPos(0,0);
- graphicsView_->deselect(P2QSTRING(element.getID()));
- }
-
- if (item) {
- QPen pen;
- QBrush brush(Qt::SolidPattern);
- WhiteboardColor penColor = element.getPenColor();
- WhiteboardColor brushColor = element.getBrushColor();
- pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
- pen.setWidth(element.getPenWidth());
- brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
- item->setPen(pen);
- item->setBrush(brush);
- QString id = P2QSTRING(element.getID());
- item->setData(100, id);
- }
- }
-
- void visit(WhiteboardPolygonElement& element) {
- QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
- if (item == 0 && type_ == GView::New) {
- item = new QGraphicsPolygonItem();
- QString id = P2QSTRING(element.getID());
- item->setData(100, id);
- graphicsView_->addItem(item, id, pos_);
- }
- graphicsView_->deselect(P2QSTRING(element.getID()));
- QPen pen;
- QBrush brush(Qt::SolidPattern);
- WhiteboardColor penColor = element.getPenColor();
- WhiteboardColor brushColor = element.getBrushColor();
- pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
- pen.setWidth(element.getPenWidth());
- brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
- item->setPen(pen);
- item->setBrush(brush);
-
- item->setPos(0,0);
- QPolygonF polygon;
- std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin();
- for (; it != element.getPoints().end(); ++it) {
- polygon.append(QPointF(it->first, it->second));
- }
- item->setPolygon(polygon);
- }
-
- void visit(WhiteboardTextElement& element) {
- QGraphicsTextItem* item;
- QString id = P2QSTRING(element.getID());
- if (type_ == GView::New) {
- item = new QGraphicsTextItem;
- graphicsView_->addItem(item, id, pos_);
- } else {
- item = qgraphicsitem_cast<QGraphicsTextItem*>(graphicsView_->getItem(id));
- graphicsView_->deselect(P2QSTRING(element.getID()));
- }
- if (item) {
- item->setPlainText(P2QSTRING(element.getText()));
- item->setPos(QPointF(element.getX(), element.getY()));
- QFont font = item->font();
- font.setPointSize(element.getSize());
- item->setFont(font);
- WhiteboardColor color = element.getColor();
- item->setDefaultTextColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
- item->setData(100, id);
- }
- }
-
- void visit(WhiteboardEllipseElement& element) {
- QRectF rect;
- QGraphicsEllipseItem* item;
- QString id = P2QSTRING(element.getID());
- rect.setTopLeft(QPointF(element.getCX()-element.getRX(), element.getCY()-element.getRY()));
- rect.setBottomRight(QPointF(element.getCX()+element.getRX(), element.getCY()+element.getRY()));
- if (type_ == GView::New) {
- item = new QGraphicsEllipseItem(rect);
- graphicsView_->addItem(item, id, pos_);
- } else {
- item = qgraphicsitem_cast<QGraphicsEllipseItem*>(graphicsView_->getItem(id));
- item->setRect(rect);
- item->setPos(0,0);
- graphicsView_->deselect(P2QSTRING(element.getID()));
- }
- QPen pen;
- QBrush brush(Qt::SolidPattern);
- WhiteboardColor penColor = element.getPenColor();
- WhiteboardColor brushColor = element.getBrushColor();
- pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
- pen.setWidth(element.getPenWidth());
- brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
- item->setPen(pen);
- item->setBrush(brush);
- item->setData(100, id);
- }
-
- private:
- GView* graphicsView_;
- int pos_;
- GView::Type type_;
- };
+ class WhiteboardElementDrawingVisitor : public WhiteboardElementVisitor {
+ public:
+ WhiteboardElementDrawingVisitor(GView* graphicsView, int pos, GView::Type type) : graphicsView_(graphicsView), pos_(pos), type_(type) {}
+
+ void visit(WhiteboardLineElement& element) {
+ QGraphicsLineItem *item;
+ if (type_ == GView::New) {
+ item = new QGraphicsLineItem(element.x1(), element.y1(), element.x2(), element.y2());
+ graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
+ } else {
+ item = qgraphicsitem_cast<QGraphicsLineItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ QLineF line(element.x1(), element.y1(), element.x2(), element.y2());
+ item->setLine(line);
+ item->setPos(0,0);
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+ if (item) {
+ QPen pen;
+ WhiteboardColor color = element.getColor();
+ pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ item->setPen(pen);
+ QString id = P2QSTRING(element.getID());
+ item->setData(100, id);
+ }
+ }
+
+ void visit(WhiteboardFreehandPathElement& element) {
+ FreehandLineItem *item;
+ if (type_ == GView::New) {
+ item = new FreehandLineItem;
+ } else {
+ item = qgraphicsitem_cast<FreehandLineItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ item->setPos(0,0);
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+
+ if (item) {
+ QPen pen;
+ WhiteboardColor color = element.getColor();
+ pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ item->setPen(pen);
+
+ std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin();
+ item->setStartPoint(QPointF(it->first, it->second));
+ for (++it; it != element.getPoints().end(); ++it) {
+ item->lineTo(QPointF(it->first, it->second));
+ }
+
+ QString id = P2QSTRING(element.getID());
+ item->setData(100, id);
+ }
+ if (type_ == GView::New) {
+ graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
+ }
+ }
+
+ void visit(WhiteboardRectElement& element) {
+ QGraphicsRectItem* item;
+ if (type_ == GView::New) {
+ item = new QGraphicsRectItem(element.getX(), element.getY(), element.getWidth(), element.getHeight());
+ graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
+ } else {
+ item = qgraphicsitem_cast<QGraphicsRectItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ QRectF rect(element.getX(), element.getY(), element.getWidth(), element.getHeight());
+ item->setRect(rect);
+ item->setPos(0,0);
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+
+ if (item) {
+ QPen pen;
+ QBrush brush(Qt::SolidPattern);
+ WhiteboardColor penColor = element.getPenColor();
+ WhiteboardColor brushColor = element.getBrushColor();
+ pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
+ item->setPen(pen);
+ item->setBrush(brush);
+ QString id = P2QSTRING(element.getID());
+ item->setData(100, id);
+ }
+ }
+
+ void visit(WhiteboardPolygonElement& element) {
+ QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ if (item == 0 && type_ == GView::New) {
+ item = new QGraphicsPolygonItem();
+ QString id = P2QSTRING(element.getID());
+ item->setData(100, id);
+ graphicsView_->addItem(item, id, pos_);
+ }
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ QPen pen;
+ QBrush brush(Qt::SolidPattern);
+ WhiteboardColor penColor = element.getPenColor();
+ WhiteboardColor brushColor = element.getBrushColor();
+ pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
+ item->setPen(pen);
+ item->setBrush(brush);
+
+ item->setPos(0,0);
+ QPolygonF polygon;
+ std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin();
+ for (; it != element.getPoints().end(); ++it) {
+ polygon.append(QPointF(it->first, it->second));
+ }
+ item->setPolygon(polygon);
+ }
+
+ void visit(WhiteboardTextElement& element) {
+ QGraphicsTextItem* item;
+ QString id = P2QSTRING(element.getID());
+ if (type_ == GView::New) {
+ item = new QGraphicsTextItem;
+ graphicsView_->addItem(item, id, pos_);
+ } else {
+ item = qgraphicsitem_cast<QGraphicsTextItem*>(graphicsView_->getItem(id));
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+ if (item) {
+ item->setPlainText(P2QSTRING(element.getText()));
+ item->setPos(QPointF(element.getX(), element.getY()));
+ QFont font = item->font();
+ font.setPointSize(element.getSize());
+ item->setFont(font);
+ WhiteboardColor color = element.getColor();
+ item->setDefaultTextColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
+ item->setData(100, id);
+ }
+ }
+
+ void visit(WhiteboardEllipseElement& element) {
+ QRectF rect;
+ QGraphicsEllipseItem* item;
+ QString id = P2QSTRING(element.getID());
+ rect.setTopLeft(QPointF(element.getCX()-element.getRX(), element.getCY()-element.getRY()));
+ rect.setBottomRight(QPointF(element.getCX()+element.getRX(), element.getCY()+element.getRY()));
+ if (type_ == GView::New) {
+ item = new QGraphicsEllipseItem(rect);
+ graphicsView_->addItem(item, id, pos_);
+ } else {
+ item = qgraphicsitem_cast<QGraphicsEllipseItem*>(graphicsView_->getItem(id));
+ item->setRect(rect);
+ item->setPos(0,0);
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+ QPen pen;
+ QBrush brush(Qt::SolidPattern);
+ WhiteboardColor penColor = element.getPenColor();
+ WhiteboardColor brushColor = element.getBrushColor();
+ pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
+ item->setPen(pen);
+ item->setBrush(brush);
+ item->setData(100, id);
+ }
+
+ private:
+ GView* graphicsView_;
+ int pos_;
+ GView::Type type_;
+ };
}
diff --git a/Swift/QtUI/WinUIHelpers.cpp b/Swift/QtUI/WinUIHelpers.cpp
index c307937..30f18a6 100644
--- a/Swift/QtUI/WinUIHelpers.cpp
+++ b/Swift/QtUI/WinUIHelpers.cpp
@@ -24,44 +24,44 @@
namespace Swift {
void WinUIHelpers::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
- if (chain.empty()) {
- return;
- }
+ if (chain.empty()) {
+ return;
+ }
- // create certificate store to store the certificate chain in
- HCERTSTORE chainStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL);
- if (!chainStore) {
- return;
- }
+ // create certificate store to store the certificate chain in
+ HCERTSTORE chainStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL);
+ if (!chainStore) {
+ return;
+ }
- ByteArray certAsDER = chain[0]->toDER();
- boost::shared_ptr<const CERT_CONTEXT> certificate_chain;
- {
- PCCERT_CONTEXT certChain;
- BOOL ok = CertAddCertificateContextToStore(chainStore, CertCreateCertificateContext(X509_ASN_ENCODING, vecptr(certAsDER), certAsDER.size()), CERT_STORE_ADD_ALWAYS, &certChain);
- // maybe free the cert contex we created
- if (!ok || !certChain) {
- return;
- }
- certificate_chain.reset(certChain, CertFreeCertificateContext);
- }
+ ByteArray certAsDER = chain[0]->toDER();
+ boost::shared_ptr<const CERT_CONTEXT> certificate_chain;
+ {
+ PCCERT_CONTEXT certChain;
+ BOOL ok = CertAddCertificateContextToStore(chainStore, CertCreateCertificateContext(X509_ASN_ENCODING, vecptr(certAsDER), certAsDER.size()), CERT_STORE_ADD_ALWAYS, &certChain);
+ // maybe free the cert contex we created
+ if (!ok || !certChain) {
+ return;
+ }
+ certificate_chain.reset(certChain, CertFreeCertificateContext);
+ }
- for (size_t i = 1; i < chain.size(); ++i) {
- ByteArray certAsDER = chain[i]->toDER();
- CertAddCertificateContextToStore(chainStore, CertCreateCertificateContext(X509_ASN_ENCODING, vecptr(certAsDER), certAsDER.size()), CERT_STORE_ADD_ALWAYS, NULL);
- }
+ for (size_t i = 1; i < chain.size(); ++i) {
+ ByteArray certAsDER = chain[i]->toDER();
+ CertAddCertificateContextToStore(chainStore, CertCreateCertificateContext(X509_ASN_ENCODING, vecptr(certAsDER), certAsDER.size()), CERT_STORE_ADD_ALWAYS, NULL);
+ }
- CRYPTUI_VIEWCERTIFICATE_STRUCT viewDialogProperties = { 0 };
- viewDialogProperties.dwSize = sizeof(viewDialogProperties);
- viewDialogProperties.hwndParent = (HWND) parent->winId();
- viewDialogProperties.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | CRYPTUI_DISABLE_ADDTOSTORE | CRYPTUI_ENABLE_REVOCATION_CHECKING;
- viewDialogProperties.pCertContext = certificate_chain.get();
- viewDialogProperties.cStores = 1;
- viewDialogProperties.rghStores = &chainStore;
- BOOL properties_changed;
+ CRYPTUI_VIEWCERTIFICATE_STRUCT viewDialogProperties = { 0 };
+ viewDialogProperties.dwSize = sizeof(viewDialogProperties);
+ viewDialogProperties.hwndParent = (HWND) parent->winId();
+ viewDialogProperties.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | CRYPTUI_DISABLE_ADDTOSTORE | CRYPTUI_ENABLE_REVOCATION_CHECKING;
+ viewDialogProperties.pCertContext = certificate_chain.get();
+ viewDialogProperties.cStores = 1;
+ viewDialogProperties.rghStores = &chainStore;
+ BOOL properties_changed;
- // blocking call that shows modal certificate dialog
- BOOL rv = ::CryptUIDlgViewCertificate(&viewDialogProperties, &properties_changed);
+ // blocking call that shows modal certificate dialog
+ BOOL rv = ::CryptUIDlgViewCertificate(&viewDialogProperties, &properties_changed);
}
}
diff --git a/Swift/QtUI/WinUIHelpers.h b/Swift/QtUI/WinUIHelpers.h
index 2146cfd..36f5c9e 100644
--- a/Swift/QtUI/WinUIHelpers.h
+++ b/Swift/QtUI/WinUIHelpers.h
@@ -20,7 +20,7 @@ namespace Swift {
class WinUIHelpers {
public:
- static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
+ static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
};
}
diff --git a/Swift/QtUI/WindowsNotifier.cpp b/Swift/QtUI/WindowsNotifier.cpp
index 1241d8f..c954fab 100644
--- a/Swift/QtUI/WindowsNotifier.cpp
+++ b/Swift/QtUI/WindowsNotifier.cpp
@@ -19,38 +19,38 @@
namespace Swift {
WindowsNotifier::WindowsNotifier(const std::string& name, const boost::filesystem::path& icon, QSystemTrayIcon* tray) : tray(tray) {
- notifierWindow = new QtWin32NotifierWindow();
- snarlNotifier = new SnarlNotifier(name, notifierWindow, icon);
- connect(tray, SIGNAL(messageClicked()), SLOT(handleMessageClicked()));
+ notifierWindow = new QtWin32NotifierWindow();
+ snarlNotifier = new SnarlNotifier(name, notifierWindow, icon);
+ connect(tray, SIGNAL(messageClicked()), SLOT(handleMessageClicked()));
}
WindowsNotifier::~WindowsNotifier() {
- delete snarlNotifier;
- delete notifierWindow;
+ delete snarlNotifier;
+ delete notifierWindow;
}
void WindowsNotifier::showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback) {
- if (snarlNotifier->isAvailable()) {
- snarlNotifier->showMessage(type, subject, description, picture, callback);
- return;
- }
- std::vector<Notifier::Type> defaultTypes = getDefaultTypes();
- if (std::find(defaultTypes.begin(), defaultTypes.end(), type) == defaultTypes.end()) {
- return;
- }
- lastCallback = callback;
- int timeout = (type == IncomingMessage || type == SystemMessage) ? DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS : DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS;
- tray->showMessage(P2QSTRING(subject), P2QSTRING(description), type == SystemMessage ? QSystemTrayIcon::Information : QSystemTrayIcon::NoIcon, timeout * 1000);
+ if (snarlNotifier->isAvailable()) {
+ snarlNotifier->showMessage(type, subject, description, picture, callback);
+ return;
+ }
+ std::vector<Notifier::Type> defaultTypes = getDefaultTypes();
+ if (std::find(defaultTypes.begin(), defaultTypes.end(), type) == defaultTypes.end()) {
+ return;
+ }
+ lastCallback = callback;
+ int timeout = (type == IncomingMessage || type == SystemMessage) ? DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS : DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS;
+ tray->showMessage(P2QSTRING(subject), P2QSTRING(description), type == SystemMessage ? QSystemTrayIcon::Information : QSystemTrayIcon::NoIcon, timeout * 1000);
}
void WindowsNotifier::handleMessageClicked() {
- if (lastCallback) {
- lastCallback();
- }
+ if (lastCallback) {
+ lastCallback();
+ }
}
void WindowsNotifier::purgeCallbacks() {
- lastCallback = boost::function<void()>();
+ lastCallback = boost::function<void()>();
}
}
diff --git a/Swift/QtUI/WindowsNotifier.h b/Swift/QtUI/WindowsNotifier.h
index 8412b6e..fae0795 100644
--- a/Swift/QtUI/WindowsNotifier.h
+++ b/Swift/QtUI/WindowsNotifier.h
@@ -16,23 +16,23 @@
class QSystemTrayIcon;
namespace Swift {
- class WindowsNotifier : public QObject, public Notifier {
- Q_OBJECT
+ class WindowsNotifier : public QObject, public Notifier {
+ Q_OBJECT
- public:
- WindowsNotifier(const std::string& name, const boost::filesystem::path& icon, QSystemTrayIcon* tray);
- ~WindowsNotifier();
+ public:
+ WindowsNotifier(const std::string& name, const boost::filesystem::path& icon, QSystemTrayIcon* tray);
+ ~WindowsNotifier();
- virtual void showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback);
- virtual void purgeCallbacks();
+ virtual void showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback);
+ virtual void purgeCallbacks();
- private slots:
- void handleMessageClicked();
+ private slots:
+ void handleMessageClicked();
- private:
- QSystemTrayIcon* tray;
- Win32NotifierWindow* notifierWindow;
- SnarlNotifier* snarlNotifier;
- boost::function<void()> lastCallback;
- };
+ private:
+ QSystemTrayIcon* tray;
+ Win32NotifierWindow* notifierWindow;
+ SnarlNotifier* snarlNotifier;
+ boost::function<void()> lastCallback;
+ };
}
diff --git a/Swift/QtUI/main.cpp b/Swift/QtUI/main.cpp
index 46b3853..86ba931 100644
--- a/Swift/QtUI/main.cpp
+++ b/Swift/QtUI/main.cpp
@@ -33,72 +33,72 @@
#include <Swift/QtUI/QtTranslator.h>
int main(int argc, char* argv[]) {
- Swift::PlatformApplicationPathProvider applicationPathProvider(SWIFT_APPLICATION_NAME);
+ Swift::PlatformApplicationPathProvider applicationPathProvider(SWIFT_APPLICATION_NAME);
- Swift::CrashReporter crashReporter(applicationPathProvider.getDataDir() / "crashes");
+ Swift::CrashReporter crashReporter(applicationPathProvider.getDataDir() / "crashes");
#if QT_VERSION < 0x050000
- QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
+ QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
- // Parse program options
- boost::program_options::options_description desc = Swift::QtSwift::getOptionsDescription();
- boost::program_options::variables_map vm;
- try {
- boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
- } catch (const boost::program_options::unknown_option& option) {
+ // Parse program options
+ boost::program_options::options_description desc = Swift::QtSwift::getOptionsDescription();
+ boost::program_options::variables_map vm;
+ try {
+ boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
+ } catch (const boost::program_options::unknown_option& option) {
#if BOOST_VERSION >= 104200
- std::cout << "Ignoring unknown option " << option.get_option_name() << " but continuing." << std::endl;
+ std::cout << "Ignoring unknown option " << option.get_option_name() << " but continuing." << std::endl;
#else
- std::cout << "Error: " << option.what() << " (continuing)" << std::endl;
+ std::cout << "Error: " << option.what() << " (continuing)" << std::endl;
#endif
- }
- boost::program_options::notify(vm);
- if (vm.count("help") > 0) {
- std::cout << SWIFT_APPLICATION_NAME << " is an instant messaging client for the XMPP network." << std::endl;
- std::cout << std::endl;
- std::cout << "Usage: " << argv[0] << " [OPTIONS]..." << std::endl;
- std::cout << std::endl;
- std::cout << desc << std::endl;
- return 1;
- }
- if (vm.count("version") > 0) {
- std::cout << SWIFT_APPLICATION_NAME << " " << buildVersion << std::endl;
- return 0;
- }
-
- // Translation
+ }
+ boost::program_options::notify(vm);
+ if (vm.count("help") > 0) {
+ std::cout << SWIFT_APPLICATION_NAME << " is an instant messaging client for the XMPP network." << std::endl;
+ std::cout << std::endl;
+ std::cout << "Usage: " << argv[0] << " [OPTIONS]..." << std::endl;
+ std::cout << std::endl;
+ std::cout << desc << std::endl;
+ return 1;
+ }
+ if (vm.count("version") > 0) {
+ std::cout << SWIFT_APPLICATION_NAME << " " << buildVersion << std::endl;
+ return 0;
+ }
+
+ // Translation
#if QT_VERSION < 0x050000
- QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
+ QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
#endif
- boost::filesystem::path someTranslationPath = applicationPathProvider.getResourcePath("/translations/swift_en.qm");
+ boost::filesystem::path someTranslationPath = applicationPathProvider.getResourcePath("/translations/swift_en.qm");
- QTranslator qtTranslator;
- if (!someTranslationPath.empty()) {
+ QTranslator qtTranslator;
+ if (!someTranslationPath.empty()) {
#if QT_VERSION >= 0x040800
- if (vm.count("language") > 0) {
- qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(vm["language"].as<std::string>()), P2QSTRING(Swift::pathToString(someTranslationPath.parent_path())));
- }
- else {
- qtTranslator.load(QLocale::system(), QString(SWIFT_APPLICATION_NAME).toLower(), "_", P2QSTRING(Swift::pathToString(someTranslationPath)));
- }
+ if (vm.count("language") > 0) {
+ qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(vm["language"].as<std::string>()), P2QSTRING(Swift::pathToString(someTranslationPath.parent_path())));
+ }
+ else {
+ qtTranslator.load(QLocale::system(), QString(SWIFT_APPLICATION_NAME).toLower(), "_", P2QSTRING(Swift::pathToString(someTranslationPath)));
+ }
#else
- //std::cout << "Loading " << std::string(QLocale::system().name().toUtf8()) << std::endl;
- qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + QLocale::system().name(), P2QSTRING(Swift::pathToString(someTranslationPath)));
+ //std::cout << "Loading " << std::string(QLocale::system().name().toUtf8()) << std::endl;
+ qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + QLocale::system().name(), P2QSTRING(Swift::pathToString(someTranslationPath)));
#endif
- }
+ }
- QApplication app(argc, argv);
+ QApplication app(argc, argv);
- app.installTranslator(&qtTranslator);
- QtTranslator swiftTranslator;
- Swift::Translator::setInstance(&swiftTranslator);
+ app.installTranslator(&qtTranslator);
+ QtTranslator swiftTranslator;
+ Swift::Translator::setInstance(&swiftTranslator);
- Swift::QtSwift swift(vm);
- int result = app.exec();
+ Swift::QtSwift swift(vm);
+ int result = app.exec();
- Swift::Translator::setInstance(NULL);
+ Swift::Translator::setInstance(NULL);
- return result;
+ return result;
}
diff --git a/Swift/QtUI/swift-open-uri.cpp b/Swift/QtUI/swift-open-uri.cpp
index 735cf5e..23a8851 100644
--- a/Swift/QtUI/swift-open-uri.cpp
+++ b/Swift/QtUI/swift-open-uri.cpp
@@ -11,21 +11,21 @@
#include <QDBusMessage>
int main(int argc, char* argv[]) {
- QCoreApplication app(argc, argv);
+ QCoreApplication app(argc, argv);
- QDBusConnection bus = QDBusConnection::sessionBus();
- if (!bus.isConnected()) {
- return -1;
- }
- if (argc != 2) {
- std::cerr << "Usage: " << argv[0] << " uri" << std::endl;
- return -1;
- }
+ QDBusConnection bus = QDBusConnection::sessionBus();
+ if (!bus.isConnected()) {
+ return -1;
+ }
+ if (argc != 2) {
+ std::cerr << "Usage: " << argv[0] << " uri" << std::endl;
+ return -1;
+ }
- QDBusMessage msg = QDBusMessage::createMethodCall("im.swift.Swift.URIHandler", "/", "im.swift.Swift.URIHandler", "openURI");
- msg << argv[1];
+ QDBusMessage msg = QDBusMessage::createMethodCall("im.swift.Swift.URIHandler", "/", "im.swift.Swift.URIHandler", "openURI");
+ msg << argv[1];
- bus.call(msg);
+ bus.call(msg);
- return 0;
+ return 0;
}