From 4150dafb7d38c9932a36f37c63101d863b022002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E7=82=9C?= Date: Thu, 2 Jun 2022 16:29:41 +0800 Subject: [PATCH] Import Upstream version 3.1.4+2022.0531 --- README.md | 69 + data/com.bluetooth.systemdbus.conf | 22 + data/com.bluetooth.systemdbus.policy | 18 + data/com.bluetooth.systemdbus.service | 4 + data/connection-failed.svg | 13 + data/file-transfer-failed.svg | 8 + data/file-transfer-success.svg | 7 + data/no-bluetooth.svg | 3 + data/org.bluez.Agent1.conf | 24 + data/org.ukui.bluetooth.gschema.xml | 54 + ...rg.ukui.log4qt.bluetoothserver.gschema.xml | 39 + data/ukui-bluetooth-service.desktop | 9 + data/ukui-bluetooth.desktop | 14 + environment.pri | 8 + ...-fixed-bug-97200-bug-97056-bug-91207.patch | 102 + patches/0001-fixed-bug-97561.patch | 119 + patches/Icon_Transfer_to_White.patch | 135 + ...e_anomalies_and_compatibility_issues.patch | 149 + .../Re-fix_Modify_back_link_and_layout.patch | 101 + patches/add_bo_zh_translations.patch | 78 + .../add_intel_tray_UI_open_interface.patch | 82 + .../add_intel_window_manager_protocol.patch | 124 + patches/add_log4qt_log.patch | 98 + ...mouse_right_click_menu_for_tray_icon.patch | 281 ++ patches/avoid_Intel_QT_MessageBox_Error.patch | 0 ...thService_before_pair_stop_discovery.patch | 71 + patches/bluetoothService_fix_102535.patch | 83 + patches/bluetoothService_fix_bug105897.patch | 147 + ...y_phone_only_connection_audio_source.patch | 82 + .../bluetoothService_segmentation_fault.patch | 14 + patches/bluetooth_pangguw_ukcc_cut.patch | 127 + ...cloes_bt_by_trayWidget_segment_fault.patch | 12 + patches/delete_battery_shown_in_HUAWEI.patch | 67 + ...lete_install_depend_conflict_blueman.patch | 11 + ...leSend_and_fileReceive_filetype_show.patch | 386 +++ patches/fix_102683.patch | 123 + patches/fix_2th_send_file_failed.patch | 42 + ..._to_tail_of_query_when_sending_files.patch | 105 + patches/fix_audiovideo_icon_wrong.patch | 178 ++ .../fix_background_transparency_calc.patch | 111 + patches/fix_bluetoothService_crash.patch | 105 + patches/fix_bluetooth_show_bug.patch | 110 + patches/fix_bluetooth_style.patch | 22 + patches/fix_bluetooth_ukcc_crash.patch | 584 ++++ patches/fix_bug101672and102290.patch | 87 + patches/fix_bug103413.patch | 26 + .../fix_cannot_send_symbol_named_files.patch | 35 + ...t_adapter_traywidget_changed_nothing.patch | 33 + ...system_font_size_label_doesnt_change.patch | 60 + .../fix_chzn_show_and_tooltip_problem.patch | 88 + patches/fix_dev_name_label_size.patch | 211 ++ patches/fix_different_gsetting_key.patch | 13 + ...rnal_screen_traywidget_show_geometry.patch | 29 + patches/fix_file_send_widget_file_num.patch | 31 + ...fix_file_send_widget_may_not_pop_out.patch | 12 + ...lesend_widget_file_name_label_height.patch | 59 + ...rst_connect_wont_pop_out_hint_window.patch | 472 ++++ ...nge_remote_device_name_segment_fault.patch | 15 + ...roblem_and_remove_dev_without_notify.patch | 218 ++ patches/fix_icon_changed.patch | 76 + patches/fix_incorrect_modify.patch | 13 + patches/fix_init_font_size.patch | 233 ++ ...label_show_on_file_send_progress_bar.patch | 17 + patches/fix_lasted_mistake.patch | 70 + patches/fix_layout_after_update.patch | 63 + ...out_when_transfer_more_than_10_files.patch | 22 + ...ns_when_remote_device_cancel_sending.patch | 63 + ...x_no_branch_detective_caused_problem.patch | 26 + ...ment_fualt_and_tray_menu_action_icon.patch | 142 + ...fix_pin_code_layout_and_translations.patch | 307 +++ ...idget_title_and_intel_tray_icon_hide.patch | 39 + ...from_WINDOWS_icon_after_click_accept.patch | 52 + ..._segment_fault_in_send_non_type_file.patch | 56 + ...segmentfault_and_clicked_active_icon.patch | 52 + patches/fix_send_file_no_type_icon.patch | 105 + patches/fix_send_file_when_delete_file.patch | 18 + .../fix_send_file_widget_label_width.patch | 22 + ...send_file_widget_wrong_long_of_label.patch | 113 + ...e_panel_and_no_adapter_hide_trayicon.patch | 141 + patches/fix_signal_canceled_bind.patch | 92 + patches/fix_the_window_type_in_intel.patch | 885 ++++++ .../fix_three_status_in_settings_label.patch | 71 + ...sferwidget_has_wrong_show_on_details.patch | 102 + patches/fix_traywidget_window_frameless.patch | 12 + patches/fix_ukbt_layout_when_scale_150%.patch | 104 + ...ck_menu_cannot_open_bluetoothsetting.patch | 86 + ...get_and_upgrade_the_speed_of_open_up.patch | 238 ++ ...transfer_fail_window_doesnt_activate.patch | 32 + patches/fix_widget_font_size_change.patch | 436 +++ ...fix_wrong_click_color_in_circle_icon.patch | 81 + ...fix_wrong_icon_in_classic_icon_theme.patch | 19 + patches/fixed_bug_101081.patch | 57 + patches/fixed_bug_89263.patch | 438 +++ patches/fixed_bug_93037.patch | 125 + patches/fixed_bug_94862_66894.patch | 116 + patches/fixed_bug_97056.patch | 26 + patches/font_size_shown_in_traywidget.patch | 30 + patches/huawei_connect_back_strategy.patch | 97 + patches/modify_intel_UI.patch | 607 +++++ ...anged_error_and_fileReceive_wrong_UI.patch | 309 +++ patches/optimum_101650.patch | 34 + patches/resolev_fix98561.patch | 28 + patches/resolve_100352and100295.patch | 25 + patches/resolve_bluedevstatus.patch | 407 +++ patches/resolve_bluesvr_crash.patch | 62 + patches/resolve_bluez_reboot.patch | 64 + patches/resolve_bluez_reboot1.patch | 89 + patches/resolve_delaybluestatus.patch | 228 ++ patches/resolve_fix97544.patch | 21 + patches/resolve_keyboard_display.patch | 390 +++ patches/resolve_keyboard_display1.patch | 31 + patches/resolve_nopair_status.patch | 69 + patches/resolve_pinshow.patch | 130 + patches/resolve_pinwiget_status.patch | 217 ++ .../resolve_task_removeHuaeiSendfile.patch | 273 ++ patches/restart_bluez_traywidget_error.patch | 96 + patches/restart_state_synchronization.patch | 111 + .../send_file_widget_dark_theme_fixed.patch | 120 + patches/send_multiple_files.patch | 19 + .../sendfile_again_widget_doesnt_change.patch | 46 + patches/series | 135 + patches/sleep_state_problem.patch | 61 + .../the_interface_shows_a_line_problem.patch | 49 + patches/traywidget_label_size.patch | 22 + .../ukcc_bleutooth_add_disconnect_btn.patch | 33 + patches/ukcc_bluetooth_93217and94720.patch | 146 + ...h_and_bluetoothService_scan_optimise.patch | 135 + patches/ukcc_bluetooth_clear_core.patch | 521 ++++ .../ukcc_bluetooth_conn_fail_show_error.patch | 62 + patches/ukcc_bluetooth_delete_scan.patch | 38 + .../ukcc_bluetooth_errorUi_abnormality.patch | 91 + ...cc_bluetooth_fix_big_font_show_error.patch | 285 ++ patches/ukcc_bluetooth_fix_bug101654.patch | 85 + patches/ukcc_bluetooth_fix_bug103561.patch | 42 + patches/ukcc_bluetooth_fix_bug104249.patch | 33 + patches/ukcc_bluetooth_fix_bug98646.patch | 30 + patches/ukcc_bluetooth_fix_cmpbug103927.patch | 24 + ...ukcc_bluetooth_fix_devConnect_signal.patch | 20 + ...ukcc_bluetooth_fix_device_random_mac.patch | 72 + patches/ukcc_bluetooth_fix_more_adapter.patch | 99 + ...cc_bluetooth_fix_optimize_error_info.patch | 227 ++ ...oth_fix_probability_show_connectfail.patch | 19 + ...kcc_bluetooth_fix_remove_show_window.patch | 120 + patches/ukcc_bluetooth_fix_show_error.patch | 965 +++++++ ...ukcc_bluetooth_fix_widget_show_error.patch | 59 + .../ukcc_bluetooth_fix_zh_show_error.patch | 180 ++ ...ooth_fix_zoom_device_name_show_error.patch | 262 ++ patches/ukcc_bluetooth_fixbug105541.patch | 28 + patches/ukcc_bluetooth_fixbug105687.patch | 142 + .../ukcc_bluetooth_huawei_disconnect.patch | 140 + patches/ukcc_bluetooth_more_adapter.patch | 621 +++++ .../ukcc_bluetooth_name_change_error.patch | 13 + ...h_optimize_device_connection_display.patch | 592 ++++ patches/ukcc_bluetooth_ota_upgrade.patch | 95 + ...ukcc_bluetooth_pin_time_connect_fail.patch | 194 ++ .../ukcc_bluetooth_power_refresh_error.patch | 278 ++ patches/ukcc_bluetooth_s4_core.patch | 32 + patches/ukcc_bluetooth_show_state_error.patch | 63 + patches/ukcc_bluetooth_ui_error.patch | 139 + patches/ukcc_pullup_bluetoothService.patch | 341 +++ profileDaemon/main.cpp | 32 + profileDaemon/profileDaemon.pro | 53 + profileDaemon/sysdbusregister.cpp | 124 + profileDaemon/sysdbusregister.h | 33 + qtsingleapplication/QtLockedFile | 1 + qtsingleapplication/QtSingleApplication | 1 + qtsingleapplication/QtSingleCoreApplication | 1 + qtsingleapplication/qtlocalpeer.cpp | 213 ++ qtsingleapplication/qtlocalpeer.h | 77 + qtsingleapplication/qtlockedfile.cpp | 193 ++ qtsingleapplication/qtlockedfile.h | 97 + qtsingleapplication/qtlockedfile_unix.cpp | 115 + qtsingleapplication/qtlockedfile_win.cpp | 211 ++ qtsingleapplication/qtsingleapplication.cpp | 347 +++ qtsingleapplication/qtsingleapplication.h | 105 + qtsingleapplication/qtsingleapplication.pri | 16 + .../qtsinglecoreapplication.cpp | 149 + qtsingleapplication/qtsinglecoreapplication.h | 71 + .../qtsinglecoreapplication.pri | 10 + service/bluetoothagent.cpp | 189 ++ service/bluetoothagent.h | 85 + service/bluetoothobexagent.cpp | 175 ++ service/bluetoothobexagent.h | 52 + service/config.cpp | 129 + service/config.h | 60 + service/daemon.cpp | 805 ++++++ service/daemon.h | 127 + service/globalsize.cpp | 42 + service/globalsize.h | 26 + service/main.cpp | 109 + service/rfkill.cpp | 212 ++ service/rfkill.h | 49 + service/service.pro | 87 + service/sessiondbusregister.cpp | 1671 ++++++++++++ service/sessiondbusregister.h | 254 ++ service/tmpdevclear.cpp | 104 + service/tmpdevclear.h | 38 + ukcc-bluetooth/bluetooth.cpp | 166 ++ ukcc-bluetooth/bluetooth.h | 47 + ukcc-bluetooth/bluetoothdbusservice.cpp | 139 + ukcc-bluetooth/bluetoothdbusservice.h | 43 + ukcc-bluetooth/bluetoothmain.cpp | 2396 +++++++++++++++++ ukcc-bluetooth/bluetoothmain.h | 283 ++ ukcc-bluetooth/bluetoothmainwindow.cpp | 317 +++ ukcc-bluetooth/bluetoothmainwindow.h | 77 + ukcc-bluetooth/bluetoothnamelabel.cpp | 251 ++ ukcc-bluetooth/bluetoothnamelabel.h | 58 + ukcc-bluetooth/config.h | 27 + ukcc-bluetooth/devicebase.cpp | 240 ++ ukcc-bluetooth/devicebase.h | 243 ++ ukcc-bluetooth/deviceinfoitem.cpp | 1033 +++++++ ukcc-bluetooth/deviceinfoitem.h | 158 ++ ukcc-bluetooth/devremovedialog.cpp | 152 ++ ukcc-bluetooth/devremovedialog.h | 62 + ukcc-bluetooth/devrenamedialog.cpp | 182 ++ ukcc-bluetooth/devrenamedialog.h | 67 + ukcc-bluetooth/loadinglabel.cpp | 46 + ukcc-bluetooth/loadinglabel.h | 32 + .../translations/ukcc-bluetooth_bo_CN.qm | Bin 0 -> 1903 bytes .../translations/ukcc-bluetooth_bo_CN.ts | 234 ++ .../translations/ukcc-bluetooth_zh_CN.qm | Bin 0 -> 2797 bytes .../translations/ukcc-bluetooth_zh_CN.ts | 331 +++ ukcc-bluetooth/ukcc-bluetooth.json | 3 + ukcc-bluetooth/ukcc-bluetooth.pro | 85 + ukcc-bluetooth/ukcc-bluetooth.qrc | 3 + ukcc-bluetooth/ukccbluetoothconfig.cpp | 70 + ukcc-bluetooth/ukccbluetoothconfig.h | 21 + ukui-bluetooth.pro | 24 + .../activeConn/activeconnectionwidget.cpp | 126 + .../activeConn/activeconnectionwidget.h | 53 + .../component/bluetoothsettinglabel.cpp | 102 + .../component/bluetoothsettinglabel.h | 49 + ukui-bluetooth/component/kyfiledialog.cpp | 75 + ukui-bluetooth/component/kyfiledialog.h | 38 + ukui-bluetooth/component/qdevitem.cpp | 422 +++ ukui-bluetooth/component/qdevitem.h | 92 + ukui-bluetooth/component/switchaction.cpp | 30 + ukui-bluetooth/component/switchaction.h | 27 + ukui-bluetooth/component/switchbutton.cpp | 306 +++ ukui-bluetooth/component/switchbutton.h | 111 + ukui-bluetooth/config/config.cpp | 59 + ukui-bluetooth/config/config.h | 30 + ukui-bluetooth/config/xatom-helper.cpp | 216 ++ ukui-bluetooth/config/xatom-helper.h | 111 + ukui-bluetooth/daemon/bluetoothdbus.cpp | 486 ++++ ukui-bluetooth/daemon/bluetoothdbus.h | 132 + .../fileReceive/filereceivingpopupwidget.cpp | 568 ++++ .../fileReceive/filereceivingpopupwidget.h | 108 + .../fileSend/bluetoothfiletransferwidget.cpp | 633 +++++ .../fileSend/bluetoothfiletransferwidget.h | 148 + ukui-bluetooth/fileSend/deviceselectitem.cpp | 222 ++ ukui-bluetooth/fileSend/deviceselectitem.h | 68 + .../fileSend/deviceseleterwidget.cpp | 175 ++ ukui-bluetooth/fileSend/deviceseleterwidget.h | 63 + ukui-bluetooth/main/main.cpp | 89 + ukui-bluetooth/main/mainprogram.cpp | 377 +++ ukui-bluetooth/main/mainprogram.h | 81 + ukui-bluetooth/mainwidget/trayicon.cpp | 94 + ukui-bluetooth/mainwidget/trayicon.h | 49 + ukui-bluetooth/mainwidget/traywidget.cpp | 572 ++++ ukui-bluetooth/mainwidget/traywidget.h | 104 + ukui-bluetooth/pin/pincodewidget.cpp | 256 ++ ukui-bluetooth/pin/pincodewidget.h | 72 + .../translations/ukui-bluetooth_bo_CN.qm | Bin 0 -> 2356 bytes .../translations/ukui-bluetooth_bo_CN.ts | 344 +++ .../translations/ukui-bluetooth_zh_CN.qm | Bin 0 -> 5146 bytes .../translations/ukui-bluetooth_zh_CN.ts | 401 +++ ukui-bluetooth/ukui-bluetooth.pro | 115 + ukui-bluetooth/ukui-bluetooth.qrc | 6 + 269 files changed, 39739 insertions(+) create mode 100644 README.md create mode 100644 data/com.bluetooth.systemdbus.conf create mode 100644 data/com.bluetooth.systemdbus.policy create mode 100644 data/com.bluetooth.systemdbus.service create mode 100644 data/connection-failed.svg create mode 100644 data/file-transfer-failed.svg create mode 100644 data/file-transfer-success.svg create mode 100644 data/no-bluetooth.svg create mode 100644 data/org.bluez.Agent1.conf create mode 100644 data/org.ukui.bluetooth.gschema.xml create mode 100644 data/org.ukui.log4qt.bluetoothserver.gschema.xml create mode 100644 data/ukui-bluetooth-service.desktop create mode 100644 data/ukui-bluetooth.desktop create mode 100644 environment.pri create mode 100644 patches/0001-fixed-bug-97200-bug-97056-bug-91207.patch create mode 100644 patches/0001-fixed-bug-97561.patch create mode 100644 patches/Icon_Transfer_to_White.patch create mode 100644 patches/Modify_interface_anomalies_and_compatibility_issues.patch create mode 100644 patches/Re-fix_Modify_back_link_and_layout.patch create mode 100644 patches/add_bo_zh_translations.patch create mode 100644 patches/add_intel_tray_UI_open_interface.patch create mode 100644 patches/add_intel_window_manager_protocol.patch create mode 100644 patches/add_log4qt_log.patch create mode 100644 patches/add_mouse_right_click_menu_for_tray_icon.patch create mode 100644 patches/avoid_Intel_QT_MessageBox_Error.patch create mode 100644 patches/bluetoothService_before_pair_stop_discovery.patch create mode 100644 patches/bluetoothService_fix_102535.patch create mode 100644 patches/bluetoothService_fix_bug105897.patch create mode 100644 patches/bluetoothService_modify_phone_only_connection_audio_source.patch create mode 100644 patches/bluetoothService_segmentation_fault.patch create mode 100644 patches/bluetooth_pangguw_ukcc_cut.patch create mode 100644 patches/cloes_bt_by_trayWidget_segment_fault.patch create mode 100644 patches/delete_battery_shown_in_HUAWEI.patch create mode 100644 patches/delete_install_depend_conflict_blueman.patch create mode 100644 patches/fileSend_and_fileReceive_filetype_show.patch create mode 100644 patches/fix_102683.patch create mode 100644 patches/fix_2th_send_file_failed.patch create mode 100644 patches/fix_append_files_to_tail_of_query_when_sending_files.patch create mode 100644 patches/fix_audiovideo_icon_wrong.patch create mode 100644 patches/fix_background_transparency_calc.patch create mode 100644 patches/fix_bluetoothService_crash.patch create mode 100644 patches/fix_bluetooth_show_bug.patch create mode 100644 patches/fix_bluetooth_style.patch create mode 100644 patches/fix_bluetooth_ukcc_crash.patch create mode 100644 patches/fix_bug101672and102290.patch create mode 100644 patches/fix_bug103413.patch create mode 100644 patches/fix_cannot_send_symbol_named_files.patch create mode 100644 patches/fix_change_default_adapter_traywidget_changed_nothing.patch create mode 100644 patches/fix_change_system_font_size_label_doesnt_change.patch create mode 100644 patches/fix_chzn_show_and_tooltip_problem.patch create mode 100644 patches/fix_dev_name_label_size.patch create mode 100644 patches/fix_different_gsetting_key.patch create mode 100644 patches/fix_external_screen_traywidget_show_geometry.patch create mode 100644 patches/fix_file_send_widget_file_num.patch create mode 100644 patches/fix_file_send_widget_may_not_pop_out.patch create mode 100644 patches/fix_filesend_widget_file_name_label_height.patch create mode 100644 patches/fix_first_connect_wont_pop_out_hint_window.patch create mode 100644 patches/fix_first_time_connect_change_remote_device_name_segment_fault.patch create mode 100644 patches/fix_huawei_scale_problem_and_remove_dev_without_notify.patch create mode 100644 patches/fix_icon_changed.patch create mode 100644 patches/fix_incorrect_modify.patch create mode 100644 patches/fix_init_font_size.patch create mode 100644 patches/fix_label_show_on_file_send_progress_bar.patch create mode 100644 patches/fix_lasted_mistake.patch create mode 100644 patches/fix_layout_after_update.patch create mode 100644 patches/fix_layout_when_transfer_more_than_10_files.patch create mode 100644 patches/fix_no_actions_when_remote_device_cancel_sending.patch create mode 100644 patches/fix_no_branch_detective_caused_problem.patch create mode 100644 patches/fix_pair_timeout_twice_segement_fualt_and_tray_menu_action_icon.patch create mode 100644 patches/fix_pin_code_layout_and_translations.patch create mode 100644 patches/fix_pin_code_widget_title_and_intel_tray_icon_hide.patch create mode 100644 patches/fix_receive_file_from_WINDOWS_icon_after_click_accept.patch create mode 100644 patches/fix_segment_fault_in_send_non_type_file.patch create mode 100644 patches/fix_segmentfault_and_clicked_active_icon.patch create mode 100644 patches/fix_send_file_no_type_icon.patch create mode 100644 patches/fix_send_file_when_delete_file.patch create mode 100644 patches/fix_send_file_widget_label_width.patch create mode 100644 patches/fix_send_file_widget_wrong_long_of_label.patch create mode 100644 patches/fix_sigmentfault_start_before_panel_and_no_adapter_hide_trayicon.patch create mode 100644 patches/fix_signal_canceled_bind.patch create mode 100644 patches/fix_the_window_type_in_intel.patch create mode 100644 patches/fix_three_status_in_settings_label.patch create mode 100644 patches/fix_transferwidget_has_wrong_show_on_details.patch create mode 100644 patches/fix_traywidget_window_frameless.patch create mode 100644 patches/fix_ukbt_layout_when_scale_150%.patch create mode 100644 patches/fix_ukbt_segment_faulse_and_right_click_menu_cannot_open_bluetoothsetting.patch create mode 100644 patches/fix_unsorted_table_in_traywidget_and_upgrade_the_speed_of_open_up.patch create mode 100644 patches/fix_when_transfer_fail_window_doesnt_activate.patch create mode 100644 patches/fix_widget_font_size_change.patch create mode 100644 patches/fix_wrong_click_color_in_circle_icon.patch create mode 100644 patches/fix_wrong_icon_in_classic_icon_theme.patch create mode 100644 patches/fixed_bug_101081.patch create mode 100644 patches/fixed_bug_89263.patch create mode 100644 patches/fixed_bug_93037.patch create mode 100644 patches/fixed_bug_94862_66894.patch create mode 100644 patches/fixed_bug_97056.patch create mode 100644 patches/font_size_shown_in_traywidget.patch create mode 100644 patches/huawei_connect_back_strategy.patch create mode 100644 patches/modify_intel_UI.patch create mode 100644 patches/namechanged_error_and_fileReceive_wrong_UI.patch create mode 100644 patches/optimum_101650.patch create mode 100644 patches/resolev_fix98561.patch create mode 100644 patches/resolve_100352and100295.patch create mode 100644 patches/resolve_bluedevstatus.patch create mode 100644 patches/resolve_bluesvr_crash.patch create mode 100644 patches/resolve_bluez_reboot.patch create mode 100644 patches/resolve_bluez_reboot1.patch create mode 100644 patches/resolve_delaybluestatus.patch create mode 100644 patches/resolve_fix97544.patch create mode 100644 patches/resolve_keyboard_display.patch create mode 100644 patches/resolve_keyboard_display1.patch create mode 100644 patches/resolve_nopair_status.patch create mode 100644 patches/resolve_pinshow.patch create mode 100644 patches/resolve_pinwiget_status.patch create mode 100644 patches/resolve_task_removeHuaeiSendfile.patch create mode 100644 patches/restart_bluez_traywidget_error.patch create mode 100644 patches/restart_state_synchronization.patch create mode 100644 patches/send_file_widget_dark_theme_fixed.patch create mode 100644 patches/send_multiple_files.patch create mode 100644 patches/sendfile_again_widget_doesnt_change.patch create mode 100644 patches/series create mode 100644 patches/sleep_state_problem.patch create mode 100644 patches/the_interface_shows_a_line_problem.patch create mode 100644 patches/traywidget_label_size.patch create mode 100644 patches/ukcc_bleutooth_add_disconnect_btn.patch create mode 100644 patches/ukcc_bluetooth_93217and94720.patch create mode 100644 patches/ukcc_bluetooth_and_bluetoothService_scan_optimise.patch create mode 100644 patches/ukcc_bluetooth_clear_core.patch create mode 100644 patches/ukcc_bluetooth_conn_fail_show_error.patch create mode 100644 patches/ukcc_bluetooth_delete_scan.patch create mode 100644 patches/ukcc_bluetooth_errorUi_abnormality.patch create mode 100644 patches/ukcc_bluetooth_fix_big_font_show_error.patch create mode 100644 patches/ukcc_bluetooth_fix_bug101654.patch create mode 100644 patches/ukcc_bluetooth_fix_bug103561.patch create mode 100644 patches/ukcc_bluetooth_fix_bug104249.patch create mode 100644 patches/ukcc_bluetooth_fix_bug98646.patch create mode 100644 patches/ukcc_bluetooth_fix_cmpbug103927.patch create mode 100644 patches/ukcc_bluetooth_fix_devConnect_signal.patch create mode 100644 patches/ukcc_bluetooth_fix_device_random_mac.patch create mode 100644 patches/ukcc_bluetooth_fix_more_adapter.patch create mode 100644 patches/ukcc_bluetooth_fix_optimize_error_info.patch create mode 100644 patches/ukcc_bluetooth_fix_probability_show_connectfail.patch create mode 100644 patches/ukcc_bluetooth_fix_remove_show_window.patch create mode 100644 patches/ukcc_bluetooth_fix_show_error.patch create mode 100644 patches/ukcc_bluetooth_fix_widget_show_error.patch create mode 100644 patches/ukcc_bluetooth_fix_zh_show_error.patch create mode 100644 patches/ukcc_bluetooth_fix_zoom_device_name_show_error.patch create mode 100644 patches/ukcc_bluetooth_fixbug105541.patch create mode 100644 patches/ukcc_bluetooth_fixbug105687.patch create mode 100644 patches/ukcc_bluetooth_huawei_disconnect.patch create mode 100644 patches/ukcc_bluetooth_more_adapter.patch create mode 100644 patches/ukcc_bluetooth_name_change_error.patch create mode 100644 patches/ukcc_bluetooth_optimize_device_connection_display.patch create mode 100644 patches/ukcc_bluetooth_ota_upgrade.patch create mode 100644 patches/ukcc_bluetooth_pin_time_connect_fail.patch create mode 100644 patches/ukcc_bluetooth_power_refresh_error.patch create mode 100644 patches/ukcc_bluetooth_s4_core.patch create mode 100644 patches/ukcc_bluetooth_show_state_error.patch create mode 100644 patches/ukcc_bluetooth_ui_error.patch create mode 100644 patches/ukcc_pullup_bluetoothService.patch create mode 100644 profileDaemon/main.cpp create mode 100644 profileDaemon/profileDaemon.pro create mode 100644 profileDaemon/sysdbusregister.cpp create mode 100644 profileDaemon/sysdbusregister.h create mode 100644 qtsingleapplication/QtLockedFile create mode 100644 qtsingleapplication/QtSingleApplication create mode 100644 qtsingleapplication/QtSingleCoreApplication create mode 100644 qtsingleapplication/qtlocalpeer.cpp create mode 100644 qtsingleapplication/qtlocalpeer.h create mode 100644 qtsingleapplication/qtlockedfile.cpp create mode 100644 qtsingleapplication/qtlockedfile.h create mode 100644 qtsingleapplication/qtlockedfile_unix.cpp create mode 100644 qtsingleapplication/qtlockedfile_win.cpp create mode 100644 qtsingleapplication/qtsingleapplication.cpp create mode 100644 qtsingleapplication/qtsingleapplication.h create mode 100644 qtsingleapplication/qtsingleapplication.pri create mode 100644 qtsingleapplication/qtsinglecoreapplication.cpp create mode 100644 qtsingleapplication/qtsinglecoreapplication.h create mode 100644 qtsingleapplication/qtsinglecoreapplication.pri create mode 100644 service/bluetoothagent.cpp create mode 100644 service/bluetoothagent.h create mode 100644 service/bluetoothobexagent.cpp create mode 100644 service/bluetoothobexagent.h create mode 100644 service/config.cpp create mode 100644 service/config.h create mode 100644 service/daemon.cpp create mode 100644 service/daemon.h create mode 100644 service/globalsize.cpp create mode 100644 service/globalsize.h create mode 100644 service/main.cpp create mode 100644 service/rfkill.cpp create mode 100644 service/rfkill.h create mode 100644 service/service.pro create mode 100644 service/sessiondbusregister.cpp create mode 100644 service/sessiondbusregister.h create mode 100644 service/tmpdevclear.cpp create mode 100644 service/tmpdevclear.h create mode 100644 ukcc-bluetooth/bluetooth.cpp create mode 100644 ukcc-bluetooth/bluetooth.h create mode 100644 ukcc-bluetooth/bluetoothdbusservice.cpp create mode 100644 ukcc-bluetooth/bluetoothdbusservice.h create mode 100644 ukcc-bluetooth/bluetoothmain.cpp create mode 100644 ukcc-bluetooth/bluetoothmain.h create mode 100644 ukcc-bluetooth/bluetoothmainwindow.cpp create mode 100644 ukcc-bluetooth/bluetoothmainwindow.h create mode 100644 ukcc-bluetooth/bluetoothnamelabel.cpp create mode 100644 ukcc-bluetooth/bluetoothnamelabel.h create mode 100644 ukcc-bluetooth/config.h create mode 100644 ukcc-bluetooth/devicebase.cpp create mode 100644 ukcc-bluetooth/devicebase.h create mode 100644 ukcc-bluetooth/deviceinfoitem.cpp create mode 100644 ukcc-bluetooth/deviceinfoitem.h create mode 100644 ukcc-bluetooth/devremovedialog.cpp create mode 100644 ukcc-bluetooth/devremovedialog.h create mode 100644 ukcc-bluetooth/devrenamedialog.cpp create mode 100644 ukcc-bluetooth/devrenamedialog.h create mode 100644 ukcc-bluetooth/loadinglabel.cpp create mode 100644 ukcc-bluetooth/loadinglabel.h create mode 100644 ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm create mode 100644 ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.ts create mode 100644 ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.qm create mode 100644 ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.ts create mode 100644 ukcc-bluetooth/ukcc-bluetooth.json create mode 100644 ukcc-bluetooth/ukcc-bluetooth.pro create mode 100644 ukcc-bluetooth/ukcc-bluetooth.qrc create mode 100644 ukcc-bluetooth/ukccbluetoothconfig.cpp create mode 100644 ukcc-bluetooth/ukccbluetoothconfig.h create mode 100644 ukui-bluetooth.pro create mode 100644 ukui-bluetooth/activeConn/activeconnectionwidget.cpp create mode 100644 ukui-bluetooth/activeConn/activeconnectionwidget.h create mode 100644 ukui-bluetooth/component/bluetoothsettinglabel.cpp create mode 100644 ukui-bluetooth/component/bluetoothsettinglabel.h create mode 100644 ukui-bluetooth/component/kyfiledialog.cpp create mode 100644 ukui-bluetooth/component/kyfiledialog.h create mode 100644 ukui-bluetooth/component/qdevitem.cpp create mode 100644 ukui-bluetooth/component/qdevitem.h create mode 100644 ukui-bluetooth/component/switchaction.cpp create mode 100644 ukui-bluetooth/component/switchaction.h create mode 100644 ukui-bluetooth/component/switchbutton.cpp create mode 100644 ukui-bluetooth/component/switchbutton.h create mode 100644 ukui-bluetooth/config/config.cpp create mode 100644 ukui-bluetooth/config/config.h create mode 100644 ukui-bluetooth/config/xatom-helper.cpp create mode 100644 ukui-bluetooth/config/xatom-helper.h create mode 100644 ukui-bluetooth/daemon/bluetoothdbus.cpp create mode 100644 ukui-bluetooth/daemon/bluetoothdbus.h create mode 100644 ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp create mode 100644 ukui-bluetooth/fileReceive/filereceivingpopupwidget.h create mode 100644 ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp create mode 100644 ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h create mode 100644 ukui-bluetooth/fileSend/deviceselectitem.cpp create mode 100644 ukui-bluetooth/fileSend/deviceselectitem.h create mode 100644 ukui-bluetooth/fileSend/deviceseleterwidget.cpp create mode 100644 ukui-bluetooth/fileSend/deviceseleterwidget.h create mode 100644 ukui-bluetooth/main/main.cpp create mode 100644 ukui-bluetooth/main/mainprogram.cpp create mode 100644 ukui-bluetooth/main/mainprogram.h create mode 100644 ukui-bluetooth/mainwidget/trayicon.cpp create mode 100644 ukui-bluetooth/mainwidget/trayicon.h create mode 100644 ukui-bluetooth/mainwidget/traywidget.cpp create mode 100644 ukui-bluetooth/mainwidget/traywidget.h create mode 100644 ukui-bluetooth/pin/pincodewidget.cpp create mode 100644 ukui-bluetooth/pin/pincodewidget.h create mode 100644 ukui-bluetooth/translations/ukui-bluetooth_bo_CN.qm create mode 100644 ukui-bluetooth/translations/ukui-bluetooth_bo_CN.ts create mode 100644 ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm create mode 100644 ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts create mode 100644 ukui-bluetooth/ukui-bluetooth.pro create mode 100644 ukui-bluetooth/ukui-bluetooth.qrc diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b3535a --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# UKUI-Bluetooth +## Simple bluetooth tool for ukui desktop environment + +### 依赖 +- KF5 + - libkf5bluezqt6 + - libkf5bluezqt-dev + - libkf5windowsystem-dev + - libqt5x11extras5-dev + - libgsettings-qt-dev + - libkf5bluezqt-data + +- libglib2.0-dev, +- libxrandr-dev, +- libxinerama-dev, +- libxi-dev, +- libxcursor-dev, +- libukui-log4qt-dev +- bluez +- bluez-obexd + +### 编译 + +------ + +```shell +$ cd ukui-bluetooth +$ mkdir build +$ cd build +$ qmake .. +$ make +``` + +### 安装 + +------ + +```shell +$ sudo make install +``` +### 主体框架 + - **InProgress** + - [x] 界面绘制 + - [x] 功能实现 + - [x] 基础DBus接口提供 + - **TROUBLE** + - 无 + - **TODO** + - 无 + +### 功能插件 +##### 蓝牙服务bluetoothService + - **InProgress** + - [x] 功能实现 + - [x] 基础DBus接口提供 + - **TODO** + - 无 +##### 任务栏蓝牙ukui-bluetooth + - **InProgress** + - [x] 界面绘制 + - [x] 功能实现 + - **TODO** + - 无 +##### 控制面板蓝牙ukcc-bluetooth + - **InProgress** + - [x] 界面绘制 + - [x] 功能实现 + - **TODO** + - 无 diff --git a/data/com.bluetooth.systemdbus.conf b/data/com.bluetooth.systemdbus.conf new file mode 100644 index 0000000..5efeca2 --- /dev/null +++ b/data/com.bluetooth.systemdbus.conf @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + diff --git a/data/com.bluetooth.systemdbus.policy b/data/com.bluetooth.systemdbus.policy new file mode 100644 index 0000000..8c0fbde --- /dev/null +++ b/data/com.bluetooth.systemdbus.policy @@ -0,0 +1,18 @@ + + + + kylin os + http://github.com/ukui/ + + ukui bluetooth + system policy bluetooth + + auth_admin + auth_admin + auth_admin_keep + + + + diff --git a/data/com.bluetooth.systemdbus.service b/data/com.bluetooth.systemdbus.service new file mode 100644 index 0000000..cfa606e --- /dev/null +++ b/data/com.bluetooth.systemdbus.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=com.bluetooth.systemdbus +Exec=/usr/bin/profileDaemon +User=root diff --git a/data/connection-failed.svg b/data/connection-failed.svg new file mode 100644 index 0000000..3efddbd --- /dev/null +++ b/data/connection-failed.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/data/file-transfer-failed.svg b/data/file-transfer-failed.svg new file mode 100644 index 0000000..3c35cdc --- /dev/null +++ b/data/file-transfer-failed.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/data/file-transfer-success.svg b/data/file-transfer-success.svg new file mode 100644 index 0000000..1667eaf --- /dev/null +++ b/data/file-transfer-success.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/data/no-bluetooth.svg b/data/no-bluetooth.svg new file mode 100644 index 0000000..5aa6b61 --- /dev/null +++ b/data/no-bluetooth.svg @@ -0,0 +1,3 @@ + + + diff --git a/data/org.bluez.Agent1.conf b/data/org.bluez.Agent1.conf new file mode 100644 index 0000000..7348e15 --- /dev/null +++ b/data/org.bluez.Agent1.conf @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/data/org.ukui.bluetooth.gschema.xml b/data/org.ukui.bluetooth.gschema.xml new file mode 100644 index 0000000..3b12e56 --- /dev/null +++ b/data/org.ukui.bluetooth.gschema.xml @@ -0,0 +1,54 @@ + + + + true + bluetooth power switch + bluetooth power switch + + + true + bluetooth discoverable switch + bluetooth discoverable switch + + + "" + File save path + File save path + + + "" + Finally connect the device + Last connected device saved + + + [] + List of paired devices + Save a list of paired devices + + + [] + List of paired device address + Save a list of paired device address + + + [] + List of adapter address + Save a list of adapter address + + + "" + Save the Adapter used by default + Save the Adapter used by default + + + true + Whether to display the icon in the tray + Whether to display the icon in the tray + + + true + Whether to active connection + Whether to active connection + + + diff --git a/data/org.ukui.log4qt.bluetoothserver.gschema.xml b/data/org.ukui.log4qt.bluetoothserver.gschema.xml new file mode 100644 index 0000000..c101bf3 --- /dev/null +++ b/data/org.ukui.log4qt.bluetoothserver.gschema.xml @@ -0,0 +1,39 @@ + + + + "true" + hook qt messages + Control if hook qt messages + + + "DEBUG,console,daily" + config rootLogger's level and appenders + config rootLogger's level and appenders:"level,appender" + + + ".yyyy-MM-dd" + daily log file pattern + set daily log file pattern format:one day + + + "%d{yyyy-MM-dd HH:mm:ss,zzz}(%-4r)[%t]|%-5p| - %m%n" + set log message's format + set log message's format + + + 3600 + set check log files delay time + set check log files delay time + + + 7 + set log files count + set log files count,unit s + + + 512 + set log files total size + set log files total size, unit M + + + diff --git a/data/ukui-bluetooth-service.desktop b/data/ukui-bluetooth-service.desktop new file mode 100644 index 0000000..1066148 --- /dev/null +++ b/data/ukui-bluetooth-service.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Encoding=UTF-8 +Name=ukui-bluetooth-daemon +Name[zh_CN]=蓝牙服务 +Comment=Simple bluetooth server for ukui desktop environment +Comment[zh_CN]=UKUI桌面环境蓝牙系统级配置文件修改进程 +Exec=/usr/bin/profileDaemon +NoDisplay=true diff --git a/data/ukui-bluetooth.desktop b/data/ukui-bluetooth.desktop new file mode 100644 index 0000000..36f74d1 --- /dev/null +++ b/data/ukui-bluetooth.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Type=Application +Encoding=UTF-8 +Name=ukui-bluetooth +Name[zh_CN]=蓝牙 +Comment=Simple bluetooth tool for ukui desktop environment +Comment[zh_CN]=UKUI桌面环境简单的蓝牙工具 +Exec=/usr/bin/bluetoothService -o +Icon=bluetooth +StartupNotify=false +OnlyShowIn=UKUI; +X-UKUI-AutoRestart=true +NoDisplay=true +Terminal=false diff --git a/environment.pri b/environment.pri new file mode 100644 index 0000000..713b2fd --- /dev/null +++ b/environment.pri @@ -0,0 +1,8 @@ +FILES_INSTALL_DIR = $$[QT_INSTALL_LIBS]/ukui-control-center +SCHEMAS_INSTALL_DIR = /usr/share/glib-2.0/schemas/ +SHARE_INSTALL_DIR = /usr/share/ukui-bluetooth/ +BIN_INSTALL_DIR = /usr/bin/ +ACTIONS_INSTALL_DIR = /usr/share/polkit-1/actions/ +SERVICE_INSTALL_DIR = /usr/share/dbus-1/system-services/ +CONF_INSTALL_DIR = /etc/dbus-1/system.d/ +SHARE_TRANSLATIONS_INSTALL_DIR = /usr/share/ukui-bluetooth/translations diff --git a/patches/0001-fixed-bug-97200-bug-97056-bug-91207.patch b/patches/0001-fixed-bug-97200-bug-97056-bug-91207.patch new file mode 100644 index 0000000..89e9634 --- /dev/null +++ b/patches/0001-fixed-bug-97200-bug-97056-bug-91207.patch @@ -0,0 +1,102 @@ +From ff10669daffb0b6f5e31f6f60e52ba583824ad8a Mon Sep 17 00:00:00 2001 +From: supreme886 <985636263@qq.com> +Date: Wed, 15 Dec 2021 11:04:57 +0800 +Subject: [PATCH] fixed bug#97200/bug#97056/bug#91207 + +--- + ukcc-bluetooth/bluetoothmain.cpp | 7 ++++--- + ukcc-bluetooth/deviceinfoitem.cpp | 27 ++++++++++++++------------- + 2 files changed, 18 insertions(+), 16 deletions(-) + +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index d46b0e2..581a261 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -2136,11 +2136,11 @@ void BlueToothMain::adapterComboxChanged(int i) + + void BlueToothMain::mDevFrameAddLineFrame(QString str,QString addr) + { +- qDebug() << Q_FUNC_INFO << "#########################" << addr; ++ qDebug() << Q_FUNC_INFO << "#########################" << str << addr; + + if ("paired" == str) { + +- if (!frame_middle->findChildren().size()) { ++ if (frame_middle->findChildren().size() <= 1) { + return; + } + +@@ -2153,7 +2153,7 @@ void BlueToothMain::mDevFrameAddLineFrame(QString str,QString addr) + + } else if ("other" == str) { + +- if (!frame_bottom->findChildren().size()) { ++ if (frame_bottom->findChildren().size() <= 1) { + return; + } + +@@ -2223,6 +2223,7 @@ void BlueToothMain::cleanPairDevices() + delete child; + child = nullptr; + } ++ device_list->setVisible(false); + } + + void BlueToothMain::gSettingsChanged(const QString &key) +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 57d890b..0bb9431 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -478,9 +478,9 @@ QColor DeviceInfoItem::getPainterBrushColor() + break; + case Status::Hover: + if(_themeIsBlack) +- color = QColor("#37373B"); ++ color = _inBtn?QColor(Qt::black):QColor("#37373B"); + else +- color = QColor("#D1D1D1"); ++ color = _inBtn?QColor(Qt::white):QColor("#D1D1D1"); + break; + case Status::Check: + if(_themeIsBlack) +@@ -764,14 +764,9 @@ void DeviceInfoItem::DrawFuncBtn(QPainter &painter) + { + painter.save(); + +- QPixmap pixmap; +- + if (_inBtn) { +- painter.setPen(QColor("#2FB3E8")); +- pixmap = ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"blue"); +- } else { +- painter.setBrush(getPainterBrushColor()); +- pixmap = ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"default"); ++ painter.setPen(QColor("#D1CFCF")); ++ painter.setBrush(QColor("#D1CFCF")); + } + + painter.drawRoundRect(this->width()-55,10,36,36,30,30); +@@ -779,10 +774,16 @@ void DeviceInfoItem::DrawFuncBtn(QPainter &painter) + painter.setRenderHint(QPainter::SmoothPixmapTransform); + + +- if (_themeIsBlack && (Status::Hover != _MStatus)) +- style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"blue")); +- else +- style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, pixmap); ++ if (_themeIsBlack) { ++ if (_inBtn) ++ style()->drawItemPixmap(&painter,QRect(this->width()-48,19,20,20), Qt::AlignCenter, ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"black")); ++ else ++ style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"white")); ++ } else ++ style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"black")); + + painter.restore(); + } +-- +2.25.1 + diff --git a/patches/0001-fixed-bug-97561.patch b/patches/0001-fixed-bug-97561.patch new file mode 100644 index 0000000..934d08d --- /dev/null +++ b/patches/0001-fixed-bug-97561.patch @@ -0,0 +1,119 @@ +From 52235f325aa20fd700144749c0d9b79700e32730 Mon Sep 17 00:00:00 2001 +From: supreme886 <985636263@qq.com> +Date: Fri, 24 Dec 2021 10:38:53 +0800 +Subject: [PATCH] =?UTF-8?q?fixed=20bug#97561;=E8=A7=A3=E5=86=B3=E5=9B=A0?= + =?UTF-8?q?=E4=B8=BA=E5=85=BC=E5=AE=B9=E9=A3=9E=E8=A1=8C=E6=A8=A1=E5=BC=8F?= + =?UTF-8?q?,=E5=BC=95=E5=85=A5=E7=9A=84=E5=BC=80=E5=85=B3=E8=93=9D?= + =?UTF-8?q?=E7=89=99=E4=B8=8D=E5=9B=9E=E8=BF=9E=E9=97=AE=E9=A2=98?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + service/daemon.cpp | 13 ++----------- + service/daemon.h | 3 ++- + service/sessiondbusregister.cpp | 10 +++++++--- + 3 files changed, 11 insertions(+), 15 deletions(-) + +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 26d5ebf..3d39132 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -292,10 +292,6 @@ void Daemon::initBluezManager() + connect(_BluezManager,&BluezQt::Manager::bluetoothOperationalChanged,this,[=](bool operational){ + qInfo() << Q_FUNC_INFO << "bluetoothOperationalChanged" << operational << resetFlag << QDateTime::currentMSecsSinceEpoch(); + +- ::powerChangeTime = QDateTime::currentMSecsSinceEpoch(); +- +- if (operational) +- reconnectFunc(); + }); + + connect(_BluezManager,&BluezQt::Manager::bluetoothBlockedChanged,this,[=](bool operational){ +@@ -633,7 +629,7 @@ void Daemon::launchDbusSignal() + void Daemon::reconnectFunc() + { + qInfo() << Q_FUNC_INFO << "START"; +- QTimer::singleShot(1000,this,[=]{ ++ QTimer::singleShot(1000,[=]{ + + if (nullptr == _DefualtAdapter) + { +@@ -664,12 +660,7 @@ void Daemon::reconnectFunc() + if (dev.data()->type() == BluezQt::Device::Headset || + dev.data()->type() == BluezQt::Device::AudioVideo) { + +- BluezQt::PendingCall *pp = dev->connectToDevice(); +- connect(pp,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ +- if(call->error() == 0){ +- return; +- } +- }); ++ dev->connectToDevice(); + } + } + } +diff --git a/service/daemon.h b/service/daemon.h +index 67d3012..8a34d31 100644 +--- a/service/daemon.h ++++ b/service/daemon.h +@@ -66,6 +66,7 @@ public: + // static void devOperateFunc(const QString,const DevOperate,const bool value = false); + // static void sendDevSignal(DevOperate,QString); + static QDBusMessage createCustomSignalMsg(QString); ++ static void reconnectFunc(); + Q_SIGNALS: + void startThread(); + +@@ -91,7 +92,7 @@ private: + // void connectDefualtSignal(); + void monitorDbusSignal(); + void launchDbusSignal(); +- void reconnectFunc(); ++ + QString getFileName(); + + Rfkill *_rfkill = nullptr; +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 7f08669..b814928 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -176,10 +176,10 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + + if (!call->error()) { + BluezQt::PendingCall *call = dev.data()->connectToDevice(); +- GlobalSize::refBlueDevActive(tmpdev->address()); ++ GlobalSize::refBlueDevActive(dev->address()); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; +- GlobalSize::unrefBlueDevActive(tmpdev->address()); ++ GlobalSize::unrefBlueDevActive(dev->address()); + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address(), + callReturn->error(), +@@ -358,6 +358,7 @@ void SessionDbusRegister::setDefaultAdapter(QString addr) + BluezQt::AdapterPtr adapter = Daemon::_BluezManager->adapterForAddress(addr); + if (!adapter.isNull()) { + Daemon::_DefualtAdapter = adapter; ++ emit this->defaultAdapterChanged(addr); + } + } + +@@ -740,10 +741,13 @@ void SessionDbusRegister::connectSignal() + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::poweredChanged,this,[=](bool powered){ +- qInfo() << Q_FUNC_INFO << "poweredChanged" << powered <<__LINE__; ++ qDebug() << Q_FUNC_INFO << "poweredChanged" << powered <<__LINE__; + + ::powerChangeTime = QDateTime::currentMSecsSinceEpoch(); + ++// if (powered) ++ Daemon::reconnectFunc(); ++ + if (::resetFlag) { + QTimer::singleShot(100,this,[=]{ + Daemon::_DefualtAdapter.data()->setPowered(false); +-- +2.25.1 + diff --git a/patches/Icon_Transfer_to_White.patch b/patches/Icon_Transfer_to_White.patch new file mode 100644 index 0000000..65abebf --- /dev/null +++ b/patches/Icon_Transfer_to_White.patch @@ -0,0 +1,135 @@ +Index: ukui-bluetooth/ukui-bluetooth/component/qdevitem.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/component/qdevitem.cpp ++++ ukui-bluetooth/ukui-bluetooth/component/qdevitem.cpp +@@ -241,11 +241,22 @@ void QDevItem::DrawBackground(QPainter & + *************************************************/ + void QDevItem::DrawStatusIcon(QPainter &painter) + { ++ QPixmap batteryPixmap; ++ + painter.save(); + painter.setBrush(getDevStatusColor()); + painter.drawEllipse(16,7,36,36); + painter.setRenderHint(QPainter::SmoothPixmapTransform); +- style()->drawItemPixmap(&painter, QRect(25, 16, 18, 18), Qt::AlignCenter, getDevTypeIcon()); ++ ++ if(StyleSettings->get("style-name").toString() == "ukui-light") { ++ painter.setPen(QColor(Qt::black)); ++ batteryPixmap = getDevTypeIcon(); ++ } else { ++ painter.setPen(QColor(Qt::white)); ++ batteryPixmap = loadSvg(getDevTypeIcon(), PixmapColor::WHITE); ++ } ++ ++ style()->drawItemPixmap(&painter, QRect(25, 16, 18, 18), Qt::AlignCenter, batteryPixmap); + painter.restore(); + } + +@@ -281,14 +292,18 @@ void QDevItem::DrawBattery(QPainter &pai + + QString batteryIcon = QString("battery-level-") + QString::number(battery / 10 * 10) + QString("-symbolic"); + QString batteryString = _Battery + QString("%"); ++ QPixmap batteryPixmap; + +- if(StyleSettings->get("style-name").toString() == "ukui-light") ++ if(StyleSettings->get("style-name").toString() == "ukui-light") { + painter.setPen(QColor(Qt::black)); +- else ++ batteryPixmap = QIcon::fromTheme(batteryIcon).pixmap(20,20); ++ } else { + painter.setPen(QColor(Qt::white)); ++ batteryPixmap = loadSvg(QIcon::fromTheme(batteryIcon).pixmap(20,20), PixmapColor::WHITE); ++ } + +- painter.drawText(358,12,24,20,Qt::AlignLeft, batteryString); +- style()->drawItemPixmap(&painter, QRect(334, 14, 20, 20), Qt::AlignCenter, QIcon::fromTheme(batteryIcon).pixmap(20,20)); ++ painter.drawText(348,12,38,20,Qt::AlignLeft, batteryString); ++ style()->drawItemPixmap(&painter, QRect(324, 14, 20, 20), Qt::AlignCenter, batteryPixmap); + painter.restore(); + } + +@@ -316,3 +331,47 @@ void QDevItem::MouseClickedFunc() + }); + } + } ++ ++ ++ ++const QPixmap QDevItem::loadSvg(const QPixmap &source, const PixmapColor &cgColor) ++{ ++ QImage img = source.toImage(); ++ for (int x = 0; x < img.width(); x++) { ++ for (int y = 0; y < img.height(); y++) { ++ auto color = img.pixelColor(x, y); ++ if (color.alpha() > 0) { ++ switch (cgColor) { ++ case PixmapColor::WHITE: ++ color.setRed(255); ++ color.setGreen(255); ++ color.setBlue(255); ++ img.setPixelColor(x, y, color); ++ break; ++ case PixmapColor::BLACK: ++ color.setRed(0); ++ color.setGreen(0); ++ color.setBlue(0); ++ img.setPixelColor(x, y, color); ++ break; ++ case PixmapColor::GRAY: ++ color.setRed(152); ++ color.setGreen(163); ++ color.setBlue(164); ++ img.setPixelColor(x, y, color); ++ break; ++ case PixmapColor::BLUE: ++ color.setRed(61); ++ color.setGreen(107); ++ color.setBlue(229); ++ img.setPixelColor(x, y, color); ++ break; ++ default: ++ return source; ++ break; ++ } ++ } ++ } ++ } ++ return QPixmap::fromImage(img); ++} +Index: ukui-bluetooth/ukui-bluetooth/component/qdevitem.h +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/component/qdevitem.h ++++ ukui-bluetooth/ukui-bluetooth/component/qdevitem.h +@@ -19,10 +19,7 @@ + class QDevItem : public QFrame + { + Q_OBJECT +-public: +- QDevItem(QString address, QStringList deviceinfo, bool connected, QWidget *parent = nullptr); +- QDevItem(QWidget *parent); +- ~QDevItem(); ++public: + enum Status{ + Hover = 0, + Nomal, +@@ -30,6 +27,19 @@ public: + }; + Q_ENUM(Status) + ++ enum PixmapColor { ++ WHITE = 0, ++ BLACK, ++ GRAY, ++ BLUE, ++ }; ++ Q_ENUM(PixmapColor) ++ ++ QDevItem(QString address, QStringList deviceinfo, bool connected, QWidget *parent = nullptr); ++ QDevItem(QWidget *parent); ++ ~QDevItem(); ++ const QPixmap loadSvg(const QPixmap &source, const PixmapColor &color); ++ + void InitMemberVariables(); + + signals: diff --git a/patches/Modify_interface_anomalies_and_compatibility_issues.patch b/patches/Modify_interface_anomalies_and_compatibility_issues.patch new file mode 100644 index 0000000..bc4faeb --- /dev/null +++ b/patches/Modify_interface_anomalies_and_compatibility_issues.patch @@ -0,0 +1,149 @@ +diff --git a/service/config.cpp b/service/config.cpp +index d96ac66..2e817b2 100644 +--- a/service/config.cpp ++++ b/service/config.cpp +@@ -6,6 +6,8 @@ extern "C" { + #include + } + ++Environment envPC = Environment::NOMAL; ++ + const QString UIExe = "/usr/bin/ukui-bluetooth"; + + QGSettings* Config::gsetting = new QGSettings("org.ukui.bluetooth"); +@@ -48,9 +50,14 @@ void Config::OpenBluetoothSettings() + QProcess *process = new QProcess(); + QString cmd = "ukui-control-center"; + QStringList arg; +- qDebug() << Q_FUNC_INFO; +- arg << "-m"; +- arg << "Bluetooth"; ++ arg.clear(); ++ if (Environment::INTER == envPC) { ++ arg << "--bluetooth"; ++ } else { ++ arg << "-m"; ++ arg << "Bluetooth"; ++ } ++ qDebug() << Q_FUNC_INFO << arg; + process->startDetached(cmd,arg); + } + +@@ -122,5 +129,3 @@ void Config::removeKey(QString addr) + qDebug() << Q_FUNC_INFO << addr << response.errorMessage(); + + } +- +-bool global_ishuawei = false; +diff --git a/service/config.h b/service/config.h +index 195e486..1bdcdb6 100644 +--- a/service/config.h ++++ b/service/config.h +@@ -13,7 +13,14 @@ + #include + + //全局变量,是否是华为机器, 默认false, 在config.cpp文件定义 +-extern bool global_ishuawei; ++enum Environment ++{ ++ NOMAL = 0, ++ HUAWEI, ++ INTER, ++}; ++ ++extern Environment envPC; + + class Config : public QObject + { +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 34a3a54..d02f9e2 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -194,7 +194,7 @@ void Daemon::rfkillStatusChange(int status) + if (findStartupOptions("-o") || findStartupOptions("--obex")) + { + //非华为机器才存在文件传输功能 +- if(!global_ishuawei) ++ if(Environment::HUAWEI == envPC) + { + initObexManager(); + } +@@ -664,6 +664,7 @@ void Daemon::reconnectFunc() + break; + + if (dev.data()->type() == BluezQt::Device::Headset || ++ dev.data()->type() == BluezQt::Device::Headphones || + dev.data()->type() == BluezQt::Device::AudioVideo) { + + dev->connectToDevice(); +diff --git a/service/main.cpp b/service/main.cpp +index 0903a3f..4808e0b 100644 +--- a/service/main.cpp ++++ b/service/main.cpp +@@ -3,6 +3,7 @@ + #include + #include + #include ++#include + + #include + +@@ -29,24 +30,26 @@ static QString executeLinuxCmd(QString strCmd) + return strResult.toLower(); + } + +-static bool IsHuawei() ++static void setEnvPCValue() + { ++ envPC = Environment::NOMAL; ++ + QString str = executeLinuxCmd("cat /proc/cpuinfo | grep Hardware"); + if(str.length() == 0) + { +- return false; ++ goto FuncEnd; + } + + if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || + str.indexOf("kirin") != -1) + { +- return true; +- } +- else +- { +- return false; ++ envPC = Environment::HUAWEI; + } +- return false; ++ ++FuncEnd: ++ if (QFile::exists("/etc/apt/ota_version")) ++ envPC = Environment::INTER; ++ + } + + int main(int argc, char *argv[]) +@@ -54,8 +57,8 @@ int main(int argc, char *argv[]) + fprintf(stdout,"Program running.....\n"); + initUkuiLog4qt(QString("bluetoothserver")); + +- global_ishuawei = IsHuawei(); +- qDebug() << "Ishuawei: "<< global_ishuawei; ++ setEnvPCValue(); ++ qDebug() << "envPC: "<< envPC; + + QtSingleCoreApplication a(argc, argv); + a.setOrganizationName("Kylin Team"); +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index fa7422c..d85d5ec 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -1736,7 +1736,7 @@ void BlueToothMain::refreshUIWhenAdapterChanged() + m_open_bluetooth_btn->setChecked(true); + // bluetooth_name->setVisible(true); + frame_middle->setVisible(m_myDev_show_flag); +- if (!frame_bottom->isVisible()) ++ if (!frame_bottom->isVisible() && frame_bottom->children().size()) + frame_bottom->setVisible(true); + } + else diff --git a/patches/Re-fix_Modify_back_link_and_layout.patch b/patches/Re-fix_Modify_back_link_and_layout.patch new file mode 100644 index 0000000..4edad69 --- /dev/null +++ b/patches/Re-fix_Modify_back_link_and_layout.patch @@ -0,0 +1,101 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 8e7f13d..1d8fb26 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -162,48 +162,6 @@ void Daemon::setBluetoothBlock(bool) + + } + +-/*void Daemon::devOperateFunc(const QString addr, const DevOperate operate, const bool value) +-{ +- qDebug() << Q_FUNC_INFO << addr << operate; +- if (addr.isEmpty() || addr.isNull()) +- return; +- +- BluezQt::DevicePtr targetDev = _DefualtAdapter.data()->deviceForAddress(addr); +- if(nullptr == targetDev) +- { +- qDebug() << Q_FUNC_INFO << "null targetDev: "<< addr; +- return; +- } +- +- BluezQt::PendingCall *targetCall; +- +- switch (operate) { +- case DevOperate::CONNECT: +- devConnectFunc(targetDev); +- break; +- case DevOperate::DISCONNECT: +- qDebug() << Q_FUNC_INFO << "DISCONNECT"; +- targetCall = targetDev.data()->disconnectFromDevice(); +- break; +- case DevOperate::REMOVE: +- qDebug() << Q_FUNC_INFO << "REMOVE"; +- targetCall = targetDev.data()->disconnectFromDevice(); +- break; +- case DevOperate::TRUST: +- qDebug() << Q_FUNC_INFO << "TRUST"; +- targetCall = targetDev.data()->setTrusted(value); +- default: +- break; +- } +- connect(targetCall,&BluezQt::PendingCall::finished,[=](BluezQt::PendingCall *newCall){ +- qDebug() << Q_FUNC_INFO << newCall->error() <<__LINE__; +- if (newCall->error() == 0) +- sendDevSignal(operate,addr); +- else +- sendDevSignal(DevOperate::ERROR,addr); +- }); +-}*/ +- + /************************************************ + * @brief 监听gsetting key的改变,并同步更新对应的value + * @param key value改变的键名 +@@ -306,20 +264,29 @@ void Daemon::initBluezManager() + }); + + connect(_BluezManager,&BluezQt::Manager::adapterAdded,this,[=](BluezQt::AdapterPtr ptr){ ++ Q_UNUSED(ptr) + qInfo() << Q_FUNC_INFO << "adapterAdded"; + }); + + connect(_BluezManager,&BluezQt::Manager::usableAdapterChanged,this,[=](BluezQt::AdapterPtr ptr){ ++ Q_UNUSED(ptr) + qInfo() << Q_FUNC_INFO << "usableAdapterChanged" ; ++ _DefualtAdapter = getDefualtAdapter(); ++ qDebug() << Q_FUNC_INFO << _DefualtAdapter.data()->name(); ++ launchDbusSignal(); ++ ++ connect(_DefualtAdapter.data(),&BluezQt::Adapter::poweredChanged,this,[=](bool v){ ++ ++ _mConfig->gsetting->set("switch",QVariant(v)); ++ ++ if (v) ++ reconnectFunc(); ++ }); + }); + + connect(_BluezManager,&BluezQt::Manager::adapterChanged,this,[=](BluezQt::AdapterPtr ptr){ +- ++ Q_UNUSED(ptr) + qInfo() << Q_FUNC_INFO << "adapterChanged"; +- +- _DefualtAdapter = getDefualtAdapter(); +- qDebug() << Q_FUNC_INFO << _DefualtAdapter.data()->name(); +- launchDbusSignal(); + }); + + connect(_BluezManager,&BluezQt::Manager::bluetoothOperationalChanged,this,[=](bool operational){ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index e026131..046c3e5 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -1342,7 +1342,7 @@ void BlueToothMain::showBluetoothNormalMainWindow() + + main_layout = new QVBoxLayout(m_normal_main_widget); + main_layout->setSpacing(40); +- main_layout->setContentsMargins(0,0,30,10); ++ main_layout->setContentsMargins(0,0,0,10); + frame_top = new QWidget(m_normal_main_widget); + frame_top->setObjectName("frame_top"); + if ((m_adapter_address_list.size() > 1) && diff --git a/patches/add_bo_zh_translations.patch b/patches/add_bo_zh_translations.patch new file mode 100644 index 0000000..aea6fc9 --- /dev/null +++ b/patches/add_bo_zh_translations.patch @@ -0,0 +1,78 @@ +Index: ukui-bluetooth/service/daemon.cpp +=================================================================== +--- ukui-bluetooth.orig/service/daemon.cpp ++++ ukui-bluetooth/service/daemon.cpp +@@ -478,7 +478,6 @@ BluezQt::AdapterPtr Daemon::getDefualtAd + return nullptr; + + }else if(_BluezManager->adapters().size() == 1){ +- + return _BluezManager->adapters().at(0); + _mConfig->gsetting->set("adapter-address",QVariant::fromValue(_DefualtAdapter->address())); + +@@ -487,10 +486,18 @@ BluezQt::AdapterPtr Daemon::getDefualtAd + if(_mGsetting["adapter-address-list"].toStringList().indexOf(_mGsetting["adapter-address"].toString()) != -1){ + return _BluezManager->adapterForAddress(_mGsetting["adapter-address"].toString()); + }else{ +- return _BluezManager->adapterForAddress(_mGsetting["adapter-address-list"].toStringList().at(0)); ++ //这里adapter-address-list的数据不一定存在 ++ if (_mGsetting["adapter-address-list"].toStringList().size() > 0) ++ { ++ return _BluezManager->adapterForAddress(_mGsetting["adapter-address-list"].toStringList().at(0)); ++ } ++ else ++ { ++ return _BluezManager->adapterForAddress(_mGsetting["adapter-address"].toString()); ++ } + } + } +- qWarning("No bluetooth adapter end!!!"); ++ qWarning("get bluetooth adapter end!!!"); + return nullptr; + + } +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -496,6 +496,11 @@ void BlueToothMain::removeAdapterDataLis + { + qDebug () << Q_FUNC_INFO << adapterAddress << __LINE__; + int i = m_adapter_address_list.indexOf(adapterAddress); ++ if (-1 == i) ++ { ++ qDebug () << Q_FUNC_INFO << "Not device :" << adapterAddress << __LINE__; ++ return; ++ } + qDebug() << Q_FUNC_INFO << __LINE__ << m_adapter_address_list << m_adapter_name_list << i; + m_adapter_name_list.removeAt(i); + m_adapter_address_list.removeAll(adapterAddress); +Index: ukui-bluetooth/ukcc-bluetooth/ukcc-bluetooth.pro +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/ukcc-bluetooth.pro ++++ ukui-bluetooth/ukcc-bluetooth/ukcc-bluetooth.pro +@@ -49,7 +49,8 @@ HEADERS += \ + loadinglabel.h + + TRANSLATIONS += \ +- ukcc-bluetooth_zh_CN.ts ++ ukcc-bluetooth_zh_CN.ts \ ++ ukcc-bluetooth_bo_CN.ts + + DISTFILES += ukcc-bluetooth.json + +Index: ukui-bluetooth/ukui-bluetooth/ukui-bluetooth.pro +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/ukui-bluetooth.pro ++++ ukui-bluetooth/ukui-bluetooth/ukui-bluetooth.pro +@@ -96,8 +96,8 @@ HEADERS += \ + + + TRANSLATIONS += \ +- translations/ukui-bluetooth_zh_CN.ts +- ++ translations/ukui-bluetooth_zh_CN.ts \ ++ translations/ukui-bluetooth_bo_CN.ts + # Default rules for deployment. + #qnx: target.path = /tmp/$${TARGET}/bin + #else: unix:!android: target.path = /opt/$${TARGET}/bin diff --git a/patches/add_intel_tray_UI_open_interface.patch b/patches/add_intel_tray_UI_open_interface.patch new file mode 100644 index 0000000..636147d --- /dev/null +++ b/patches/add_intel_tray_UI_open_interface.patch @@ -0,0 +1,82 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index b89cd61..f0c69a0 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -977,3 +977,8 @@ void SessionDbusRegister::cancelFileReceiving() { + qDebug() << "SessionDbusRegister::cancelFileReceiving"; + emit cancelFileReceivingSignal(); + } ++ ++void SessionDbusRegister::showTrayWidgetUI() { ++ qDebug() << "SessionDbusRegister::showTrayWidgetUI"; ++ emit showTrayWidgetUISignal(); ++} +diff --git a/service/sessiondbusregister.h b/service/sessiondbusregister.h +index 3ac2518..a5225ef 100644 +--- a/service/sessiondbusregister.h ++++ b/service/sessiondbusregister.h +@@ -137,6 +137,8 @@ public slots: + + void connectSignal(); + ++ void showTrayWidgetUI(); ++ + //test + void sendReplyRequestConfirmation(bool); + void sendReplyFileReceivingSignal(bool v); +@@ -211,6 +213,8 @@ signals: + void clearOldSession(); + + void cancelFileReceivingSignal(); ++ ++ void showTrayWidgetUISignal(); + }; + + #endif // SESSIONDBUSREGISTER_H +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 1bda657..149ea45 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -17,6 +17,8 @@ BluetoothDbus::~BluetoothDbus() + + void BluetoothDbus::connectDBusSignals() { + qDebug() << Q_FUNC_INFO << __LINE__; ++ TRANSFER_DBUS_SIGNAL("showTrayWidgetUISignal", showTrayWidgetUISignal()); ++ + //适配器相关dbus + CONNECT_DBUS_SIGNAL("defaultAdapterPowerChanged", defaultAdapterPowerChangedSLot(bool)); + CONNECT_DBUS_SIGNAL("defaultAdapterChanged", defaultAdapterChangedSLot(QString)); +@@ -34,7 +36,6 @@ void BluetoothDbus::connectDBusSignals() { + TRANSFER_DBUS_SIGNAL("requestConfirmation", requestConfirmationSignal(QString,QString)); + TRANSFER_DBUS_SIGNAL("pairAgentCanceled", pairAgentCanceledSignal()); + +- + //文件传输相关dbus + CONNECT_DBUS_SIGNAL("fileReceivingSignal", receiveFilesSlot(QString,QString,QString,QString,quint64)); + TRANSFER_DBUS_SIGNAL("obexAgentCanceled", obexAgentCanceledSignal()); +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.h b/ukui-bluetooth/daemon/bluetoothdbus.h +index 556b62a..3cb9422 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.h ++++ b/ukui-bluetooth/daemon/bluetoothdbus.h +@@ -92,6 +92,7 @@ signals: + void AdapterChangedSignal(QString); + void devConnectStatusSignal(QString, bool); + void fileReceiveMore(QString, quint64, QString); ++ void showTrayWidgetUISignal(); + + private: + void connectDBusSignals(); +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index 82b8340..352b199 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -19,6 +19,9 @@ MainProgram::MainProgram(bool intel, QObject *parent) : + connect(_sessionDbus, &BluetoothDbus::sendTransferFilesMesgSignal, this, &MainProgram::sendTransferFilesMesgSlot); + } + ++ connect(_sessionDbus, &BluetoothDbus::showTrayWidgetUISignal, this, [=]() { ++ UI->showUI(); ++ }); + connect(_sessionDbus, &BluetoothDbus::displayPasskeySignal, this, &MainProgram::displayPasskeySlot); + connect(_sessionDbus, &BluetoothDbus::requestConfirmationSignal, this, &MainProgram::requestConfirmationSlot); + connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired) { diff --git a/patches/add_intel_window_manager_protocol.patch b/patches/add_intel_window_manager_protocol.patch new file mode 100644 index 0000000..a052046 --- /dev/null +++ b/patches/add_intel_window_manager_protocol.patch @@ -0,0 +1,124 @@ +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index cf56849..1c23ae2 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -10,10 +10,14 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + qDebug() << Q_FUNC_INFO; + + // 窗管适配 +-// MotifWmHints hints; +-// hints.flags = MWM_HINTS_DECORATIONS; +-// hints.decorations = MWM_DECOR_ALL; +-// XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); ++ if (_Intel) { ++ MotifWmHints hints; ++ hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; ++ hints.functions = MWM_FUNC_ALL; ++ hints.decorations = MWM_DECOR_BORDER; ++ XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); ++ installEventFilter(this); ++ } + if (!_Intel) { + trayicon = new TrayIcon(); + connect(this, &TrayWidget::trayIconStatusChanged, trayicon, &TrayIcon::SetTrayIcon); +@@ -24,6 +28,9 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + connect(_SessionDBus, &BluetoothDbus::showTrayIcon, this, [=](bool show) { + trayicon->SetAdapterFlag(show); + }); ++ setProperty("useSystemStyleBlur", true); ++ this->setAttribute(Qt::WA_TranslucentBackground); ++ this->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint); + } + connect(QApplication::desktop(), &QDesktopWidget::resized, this, [=] { + setWidgetPosition(); +@@ -39,9 +46,6 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + } + }); + +- setProperty("useSystemStyleBlur", true); +- this->setAttribute(Qt::WA_TranslucentBackground); +- this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); + + if(QGSettings::isSchemaInstalled("org.ukui.style")) { + StyleSettings = new QGSettings("org.ukui.style"); +@@ -76,7 +80,6 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + this->setAutoFillBackground(true); + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("bluetooth")); +- + pairedDevices = _SessionDBus->getPairedDevices(); + + InitMemberVariables(); +@@ -387,6 +390,16 @@ void TrayWidget::layoutAddPairedDev() + int count = 0; + qDebug() << Q_FUNC_INFO << pairedDevices.size() << __LINE__; + if (!_PairedWidget->findChildren().size()) { ++ for (int i = 0; i < 5; i++) { ++ QStringList list; ++ list.append(QString("name")); ++ list.append(QString("phone")); ++ list.append(QString("-1")); ++ QDevItem *dev = new QDevItem(QString("ppp"), list, false, _PairedWidget); ++ _PairedLayout->addWidget(dev); ++ isNull = false; ++ count++; ++ } + for (auto item : pairedDevices.keys()) { + QString name = pairedDevices.value(item).at(0); + _SessionDBus->getDevConnectStatus(item); +@@ -492,6 +505,18 @@ void TrayWidget::showUI() + showNormal(); + } + ++bool TrayWidget::eventFilter(QObject *o, QEvent *e) ++{ ++ if (e->type() == QEvent::ActivationChange) ++ { ++ if(QApplication::activeWindow() != this) ++ { ++ this->hide(); ++ } ++ } ++ return QWidget::eventFilter(o,e); ++} ++ + void TrayWidget::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QPainter painter(this); +@@ -499,13 +524,19 @@ void TrayWidget::paintEvent(QPaintEvent *event) { + painter.setPen(Qt::transparent); + QColor col; + if(StyleSettings->get("style-name").toString() == "ukui-light"){ +- col = QColor(255,255,255,tran); ++ col = QColor(255,255,255); + } else{ +- col = QColor(35,36,38,tran); ++ col = QColor(35,36,38); + } +- painter.setBrush(col); +- + QPainterPath rectPath; +- rectPath.addRoundedRect(this->rect(),12,12); ++ ++ if (_Intel) ++ rectPath.addRect(this->rect()); ++ else { ++ col.setAlpha(tran); ++ rectPath.addRoundedRect(this->rect(),12,12); ++ } ++ ++ painter.setBrush(col); + painter.drawPath(rectPath); + } +diff --git a/ukui-bluetooth/mainwidget/traywidget.h b/ukui-bluetooth/mainwidget/traywidget.h +index 0a00d1b..233910f 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.h ++++ b/ukui-bluetooth/mainwidget/traywidget.h +@@ -92,6 +92,7 @@ signals: + + protected: + void paintEvent(QPaintEvent *event); ++ bool eventFilter(QObject *o, QEvent *e); + }; + + #endif // TRAYWIDGET_H diff --git a/patches/add_log4qt_log.patch b/patches/add_log4qt_log.patch new file mode 100644 index 0000000..fe0c8cc --- /dev/null +++ b/patches/add_log4qt_log.patch @@ -0,0 +1,98 @@ +diff --git a/service/main.cpp b/service/main.cpp +index 1bd0611..799718b 100644 +--- a/service/main.cpp ++++ b/service/main.cpp +@@ -4,54 +4,17 @@ + #include + #include + ++#include ++ + #include "daemon.h" + #include "sessiondbusregister.h" + ++ + extern "C" { + #include + #include + } + +-static bool debugFlag = false; +-static bool infoFlag = false; +- +-static void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +-{ +- if (infoFlag) { +- QByteArray localMsg = msg.toLocal8Bit(); +- switch (type) { +- case QtDebugMsg: +- if (debugFlag) +- fprintf(stdout, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); +- break; +- case QtInfoMsg: +- fprintf(stdout, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); +- break; +- case QtWarningMsg: +- fprintf(stdout, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); +- break; +- case QtCriticalMsg: +- fprintf(stdout, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); +- break; +- case QtFatalMsg: +- fprintf(stdout, "\033[41;37;1m Fatal:\033[41;37;4m %s (%s:%u, %s)\033[0m\n", localMsg.constData(), context.file, context.line, context.function); +- abort(); +- } +- } +-} +- +-static void getDebugFlag(int argc, char *argv[]) +-{ +-// fprintf(stderr,"\033[41;37;1m hello world\033[0m\n"); +- for (int i = 0; i < argc; i++) { +- if (strcmp(argv[i],"-d") == 0 || strcmp(argv[i],"--debug") == 0) +- debugFlag = true; +- if (strcmp(argv[i],"-i") == 0 || strcmp(argv[i],"--info") == 0) +- infoFlag = true; +- } +-// fprintf(stderr,"%d %d\n",debugFlag,infoFlag); +-} +- + void signalHandlerFunc(int signal) { + fprintf(stderr,"---------------------- %d",signal); + } +@@ -59,11 +22,10 @@ void signalHandlerFunc(int signal) { + int main(int argc, char *argv[]) + { + fprintf(stdout,"Program running.....\n"); +- getDebugFlag(argc,argv); +-// qInstallMessageHandler(myMessageOutput); ++ initUkuiLog4qt(QString("bluetoothserver")); + QtSingleCoreApplication a(argc, argv); + a.setOrganizationName("Kylin Team"); +- a.setApplicationName("bus-bluetooth-service"); ++ a.setApplicationName("dbus-bluetooth-service"); + a.setApplicationVersion("1.0.0"); + + if (a.isRunning()) { +@@ -77,8 +39,6 @@ int main(int argc, char *argv[]) + parser.addHelpOption(); + parser.addVersionOption(); + parser.addOptions({{{"o","obex"},QCoreApplication::translate("main","Load the Bluetooth file transfer agent")}}); +- parser.addOptions({{{"d","debug"},QCoreApplication::translate("main","Debug options to enable")}}); +- parser.addOptions({{{"i","info"},QCoreApplication::translate("main","Info options to enable")}}); + + parser.setApplicationDescription(QCoreApplication::translate("main","UKUI bluetooth daemon")); + parser.process(a); +diff --git a/service/service.pro b/service/service.pro +index 355ae38..d70ced2 100644 +--- a/service/service.pro ++++ b/service/service.pro +@@ -31,6 +31,8 @@ QMAKE_LFLAGS += -D_FORTIFY_SOURCE=2 -O2 + #ins3.path = /usr/share/polkit-1/actions/ + target.source += $$TARGET + target.path = $$BIN_INSTALL_DIR ++inst1.files += ../data/org.ukui.log4qt.bluetoothserver.gschema.xml ++inst1.path = $$SCHEMAS_INSTALL_DIR + INSTALLS += target + + # The following define makes your compiler warn you if you use any diff --git a/patches/add_mouse_right_click_menu_for_tray_icon.patch b/patches/add_mouse_right_click_menu_for_tray_icon.patch new file mode 100644 index 0000000..3ea7c17 --- /dev/null +++ b/patches/add_mouse_right_click_menu_for_tray_icon.patch @@ -0,0 +1,281 @@ +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index 0472ca2..b87e4e5 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -2,10 +2,10 @@ + + MainProgram::MainProgram(bool intel, QObject *parent) : + QObject(parent), +- _sessionDbus(new BluetoothDbus(this)), +- _mConfig(new Config(this)), + _mIntel(intel) + { ++ _sessionDbus = new BluetoothDbus(this); ++ _mConfig = new Config(this); + initGSettingInfo(); + UI = TrayWidget::self(_sessionDbus, _mIntel); + if (!_mIntel) +diff --git a/ukui-bluetooth/main/mainprogram.h b/ukui-bluetooth/main/mainprogram.h +index 4debc4c..cb4b6ca 100644 +--- a/ukui-bluetooth/main/mainprogram.h ++++ b/ukui-bluetooth/main/mainprogram.h +@@ -60,10 +60,10 @@ private: + + bool _mIntel; + QStringList selectedFiles; +- Config *_mConfig; + QMap _mGsetting; +- FileReceivingPopupWidget *receiving_widget ; + ++ FileReceivingPopupWidget *receiving_widget = nullptr; ++ Config *_mConfig = nullptr; + BluetoothDbus *_sessionDbus = nullptr; + BluetoothFileTransferWidget *fileSendWidget = nullptr; + QList *deviceAddressList = nullptr; +diff --git a/ukui-bluetooth/mainwidget/trayicon.cpp b/ukui-bluetooth/mainwidget/trayicon.cpp +index 046dfb7..dc8f111 100644 +--- a/ukui-bluetooth/mainwidget/trayicon.cpp ++++ b/ukui-bluetooth/mainwidget/trayicon.cpp +@@ -3,30 +3,20 @@ + TrayIcon::TrayIcon(QWidget *parent) + : QWidget(parent) + { +- +- // MainProgram *w = new MainProgram(); +- +- //==============获取gsettings的配置信息========================== + if(QGSettings::isSchemaInstalled("org.ukui.bluetooth")){ + settings = new QGSettings("org.ukui.bluetooth"); +- +- paired_device_address = settings->get("paired-device-address").toStringList(); +- finally_connect_the_device = settings->get("finally-connect-the-device").toString(); +- paired_device = settings->get("paired-device").toStringList(); +- Default_Adapter = settings->get("adapter-address").toString(); +- File_save_path = settings->get("file-save-path").toString(); +- +- qDebug() << "GSetting Value: " << Default_Adapter << finally_connect_the_device << paired_device; + connect(settings, &QGSettings::changed,this,&TrayIcon::GSettings_value_chanage); + } +- //========================END=================================== + + bluetooth_tray_icon = new QSystemTrayIcon(this); ++ tray_Menu = new QMenu(this); ++ QAction *settins_action = new QAction(QIcon::fromTheme("ukui-settings-symbolic"),tr("Set Bluetooth Item"),tray_Menu); ++ tray_Menu->addAction(settins_action); + + //Create taskbar tray icon and connect to signal slot + //创建任务栏托盘图标,并连接信号槽 + bluetooth_tray_icon = new QSystemTrayIcon(this); +- //bluetooth_tray_icon->setContextMenu(tray_Menu); ++ bluetooth_tray_icon->setContextMenu(tray_Menu); + bluetooth_tray_icon->setToolTip(tr("Bluetooth")); + bluetooth_tray_icon->setVisible(settings->get("tray-show").toBool()); + +@@ -43,27 +33,24 @@ TrayIcon::TrayIcon(QWidget *parent) + [=](QSystemTrayIcon::ActivationReason reason){ + switch (reason) + { ++ case QSystemTrayIcon::MiddleClick: + case QSystemTrayIcon::DoubleClick: /* 来自于双击激活。 */ + case QSystemTrayIcon::Trigger: /* 来自于单击激活。 */ +- InitTrayMenu(); +- break; +- case QSystemTrayIcon::Context: +- //InitTrayMenu(); ++ InitTrayWidget(); + break; ++ case QSystemTrayIcon::Unknown: ++ case QSystemTrayIcon::Context: ++ break; + } + }); + } + +-void TrayIcon::replyRequestConfirmationFunc(bool a) { +- qDebug() << Q_FUNC_INFO << a; +-} +- + TrayIcon::~TrayIcon() + { + delete settings; + } + +-void TrayIcon::InitTrayMenu() ++void TrayIcon::InitTrayWidget() + { + emit showTayWidget(); + } +diff --git a/ukui-bluetooth/mainwidget/trayicon.h b/ukui-bluetooth/mainwidget/trayicon.h +index e5b9a78..313f3bd 100644 +--- a/ukui-bluetooth/mainwidget/trayicon.h ++++ b/ukui-bluetooth/mainwidget/trayicon.h +@@ -5,15 +5,11 @@ + #include "daemon/bluetoothdbus.h" + #include "component/switchaction.h" + +-#include + #include + #include + +-#include +- + #include + #include +-#include + #include + #include + #include +@@ -21,28 +17,9 @@ + #include + #include + #include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include + #include +-#include +-#include +- +-#define LIST_PATH "/etc/pairDevice.list" +-#define RFKILL_DEV "/dev/rfkill" + + using namespace std; +-class BluetoothDbus; + + class TrayIcon : public QWidget + { +@@ -51,53 +28,18 @@ class TrayIcon : public QWidget + public: + TrayIcon(QWidget *parent = nullptr); + ~TrayIcon(); +- bool exit_flag = false; +- void InitTrayMenu(); ++ void InitTrayWidget(); + + signals: +- void ProgramExit(); + void showTayWidget(); + + public slots: + void GSettings_value_chanage(const QString &key); + void SetTrayIcon(bool open); + +- +- +- void replyRequestConfirmationFunc(bool a); +- + private: +- bool isPowered = false; +- void InitGSettings(); +- +- +- QList is_connected; + QSystemTrayIcon *bluetooth_tray_icon = nullptr; + QMenu *tray_Menu = nullptr; +- SwitchAction *m_action = nullptr; + QGSettings *settings = nullptr; +- +- QStringList paired_device_address; +- QStringList paired_device; +- QString finally_connect_the_device; +- QString Default_Adapter; +- QString File_save_path; +- QString cur_adapter_address; +- QStringList adapter_list; +- QString selected_file; +- quint64 transfer_file_size = 0; +- bool flag = true; +- +- BluetoothDbus *session_dbus = nullptr; +- BluetoothFileTransferWidget *transfer_widget = nullptr; +- +- QTimer *notify_timer; +- QDBusObjectPath pre_session; +- bool dev_remove_flag = false; +- bool sleep_flag = false; +- bool dev_connected_when_sleep = false; +- QString pair_device_file; +- int dev_callbak_flag = 0; +- bool pair_flag = true; + } ; + #endif // TRAYICON_H +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm +index 63e204c..a22748f 100644 +Binary files a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm and b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm differ +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +index 9188a0c..962d0ec 100644 +--- a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts ++++ b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +@@ -11,7 +11,7 @@ + + + +- ++ + Transferring to " + 发送文件至 " + +@@ -217,13 +217,13 @@ + + + +- ++ + Please enter the following PIN code on the bluetooth device '%1' and press enter to pair ! + 请在蓝牙设备 "%1" 上输入下列PIN码,并按连接进行匹配! + + + +- ++ + If ' + 如果 " + +@@ -234,7 +234,7 @@ + + + +- ++ + ' the PIN on is the same as this PIN. Please press 'Connect'. + " 上的PIN码与此PIN码相同,请按 "连接"。 + +@@ -264,12 +264,12 @@ + + QDevItem + +- ++ + The connection with the Bluetooth device “%1” is successful! + 与蓝牙设备“%1”连接成功! + + +- ++ + Bluetooth device “%1” disconnected! + 蓝牙设备“%1”失去连接! + +@@ -285,7 +285,12 @@ + + TrayIcon + +- ++ ++ Set Bluetooth Item ++ 设置蓝牙项 ++ ++ ++ + Bluetooth + 蓝牙 + diff --git a/patches/avoid_Intel_QT_MessageBox_Error.patch b/patches/avoid_Intel_QT_MessageBox_Error.patch new file mode 100644 index 0000000..e69de29 diff --git a/patches/bluetoothService_before_pair_stop_discovery.patch b/patches/bluetoothService_before_pair_stop_discovery.patch new file mode 100644 index 0000000..b37558a --- /dev/null +++ b/patches/bluetoothService_before_pair_stop_discovery.patch @@ -0,0 +1,71 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 7a519b2..e8832d6 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -142,18 +142,18 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + + if (dev) + { +- if (Daemon::_DefualtAdapter.data()->isDiscovering()) { +- ::isScan = true; +- BluezQt::PendingCall * stop_call = Daemon::_DefualtAdapter.data()->stopDiscovery(); +- connect(stop_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn) +- { +- qDebug() << Q_FUNC_INFO << "stopDiscovery:" << callReturn->error() << callReturn->errorText() << __LINE__; +- }); +- //qDebug() << Q_FUNC_INFO << "stopDiscovery:111111111111111111" << __LINE__; +- stop_call->waitForFinished(); +- //qDebug() << Q_FUNC_INFO << "stopDiscovery:222222222222222222" << __LINE__; +- +- } ++// if (Daemon::_DefualtAdapter.data()->isDiscovering()) { ++// ::isScan = true; ++// BluezQt::PendingCall * stop_call = Daemon::_DefualtAdapter.data()->stopDiscovery(); ++// connect(stop_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn) ++// { ++// qDebug() << Q_FUNC_INFO << "stopDiscovery:" << callReturn->error() << callReturn->errorText() << __LINE__; ++// }); ++// //qDebug() << Q_FUNC_INFO << "stopDiscovery:111111111111111111" << __LINE__; ++// stop_call->waitForFinished(); ++// //qDebug() << Q_FUNC_INFO << "stopDiscovery:222222222222222222" << __LINE__; ++ ++// } + + if (dev.data()->type() == BluezQt::Device::AudioVideo || + dev.data()->type() == BluezQt::Device::Headphones || +@@ -420,6 +420,17 @@ void SessionDbusRegister::devConnect(const QString addr) + if (!devPtr) + return; + ++ ++ if (Daemon::_DefualtAdapter.data()->isDiscovering()) { ++ ::isScan = true; ++ BluezQt::PendingCall * stop_call = Daemon::_DefualtAdapter.data()->stopDiscovery(); ++ connect(stop_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn) ++ { ++ qDebug() << Q_FUNC_INFO << "stopDiscovery:" << callReturn->error() << callReturn->errorText() << __LINE__; ++ }); ++ stop_call->waitForFinished(); ++ } ++ + if (devPtr.data()->isPaired()) { + AudioDevConnectFunc(devPtr); + } else { +@@ -429,6 +440,17 @@ void SessionDbusRegister::devConnect(const QString addr) + emit devOperateErrorSignal(devPtr.data()->address(), + callReturn->error(), + callReturn->errorText()); ++ //主动连接全部完成后,启动扫描 ++ if(GlobalSize::BlueDevActiveSize() == 0) ++ { ++ qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; ++ if (::isScan) { ++ BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); ++ connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ }); ++ } ++ } + } else + AudioDevConnectFunc(devPtr); + }); diff --git a/patches/bluetoothService_fix_102535.patch b/patches/bluetoothService_fix_102535.patch new file mode 100644 index 0000000..e54ed1f --- /dev/null +++ b/patches/bluetoothService_fix_102535.patch @@ -0,0 +1,83 @@ +diff --git a/service/bluetoothagent.cpp b/service/bluetoothagent.cpp +index bb80f6d..c6de8a5 100644 +--- a/service/bluetoothagent.cpp ++++ b/service/bluetoothagent.cpp +@@ -107,11 +107,10 @@ void BluetoothAgent::displayPasskey(BluezQt::DevicePtr device, const QString &pa + cancelEmitDevStatus(device->address()); + if(m_displayedPasskey == passkey) + return; +- + QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "displayPasskey"); +- displayPasskeySignal << device.data()->name() << passkey; ++ displayPasskeySignal << device.data()->name() << passkey << device.data()->address();; + QDBusConnection::sessionBus().send(displayPasskeySignal); + } + +@@ -121,16 +120,25 @@ void BluetoothAgent::requestConfirmation(BluezQt::DevicePtr device, const QStrin + + cancelEmitDevStatus(device->address()); + +- QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", +- "com.ukui.bluetooth", +- "requestConfirmation"); +- displayPasskeySignal << device.data()->name() << passkey; +- QDBusConnection::sessionBus().send(displayPasskeySignal); +- + m_device = device; +- tmpRequestConfirmation = request; +- ++ //规避设备类型为耳机、音响设备时还会弹出pin窗口的问题 ++ if ((nullptr != m_device) && ++ (m_device.data()->type() == BluezQt::Device::AudioVideo || ++ m_device.data()->type() == BluezQt::Device::Headphones || ++ m_device.data()->type() == BluezQt::Device::Headset )) ++ { ++ request.accept(); ++ } ++ else ++ { ++ QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", ++ "com.ukui.bluetooth", ++ "requestConfirmation"); ++ displayPasskeySignal << device.data()->name() << passkey << device.data()->address(); ++ QDBusConnection::sessionBus().send(displayPasskeySignal); + ++ tmpRequestConfirmation = request; ++ } + } + + void BluetoothAgent::requestAuthorization(BluezQt::DevicePtr device, const BluezQt::Request<> &request) +diff --git a/ukcc-bluetooth/devicebase.cpp b/ukcc-bluetooth/devicebase.cpp +index 05a3a66..fdb6ec8 100644 +--- a/ukcc-bluetooth/devicebase.cpp ++++ b/ukcc-bluetooth/devicebase.cpp +@@ -183,8 +183,11 @@ bool bluetoothdevice::isPaired() + void bluetoothdevice::devPairedChanged(bool value) + { + qDebug() << Q_FUNC_INFO << value << __LINE__; +- this->m_dev_isPaired = value; +- emit pairedChanged(value); ++ if(this->m_dev_isPaired != value) ++ { ++ this->m_dev_isPaired = value; ++ emit pairedChanged(value); ++ } + } + + bool bluetoothdevice::isConnected() +@@ -195,8 +198,11 @@ bool bluetoothdevice::isConnected() + + void bluetoothdevice::devConnectedChanged(bool value) + { +- this->m_dev_isConnected = value; +- emit connectedChanged(value); ++ if(this->m_dev_isConnected != value) ++ { ++ this->m_dev_isConnected = value; ++ emit connectedChanged(value); ++ } + } + + void bluetoothdevice::setErrorInfo(int errorId,QString errorText) diff --git a/patches/bluetoothService_fix_bug105897.patch b/patches/bluetoothService_fix_bug105897.patch new file mode 100644 index 0000000..a1eb41b --- /dev/null +++ b/patches/bluetoothService_fix_bug105897.patch @@ -0,0 +1,147 @@ +diff --git a/data/org.ukui.bluetooth.gschema.xml b/data/org.ukui.bluetooth.gschema.xml +index 20da8c3..e4d8372 100644 +--- a/data/org.ukui.bluetooth.gschema.xml ++++ b/data/org.ukui.bluetooth.gschema.xml +@@ -2,8 +2,13 @@ + + + true +- bluetooth switch +- bluetooth switch ++ bluetooth power switch ++ bluetooth power switch ++ ++ ++ true ++ bluetooth discoverable switch ++ bluetooth discoverable switch + + + "" +diff --git a/service/config.h b/service/config.h +index 1e4ba0e..7fa5818 100644 +--- a/service/config.h ++++ b/service/config.h +@@ -20,6 +20,16 @@ enum Environment + INTER, + }; + ++//gsetting name define ++ ++//名称请勿随意改动,会导致升级时获取的gsetting值不一致, ++#define GSETTING_STR_BLUETOOTH_POWER_SWTICH "switch" ++#define GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH "bluetooth-discoverable-switch" ++#define GSETTING_STR_FINALLY_CONNECT_THE_DEVICE "finally-connect-the-device" ++#define GSETTING_STR_ADAPTER_ADDRESS "adapter-address" ++#define GSETTING_STR_FILE_SAVE_PATH "file-save-path" ++#define GSETTING_STR_ADAPTER_ADDRESS_LIST "adapter-address-list" ++ + extern Environment envPC; + + class Config : public QObject +diff --git a/service/daemon.cpp b/service/daemon.cpp +index dc24407..d2eba67 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -219,11 +219,12 @@ void Daemon::rfkillStatusChange(int status) + void Daemon::initGSettingInfo() + { + _mGsetting.clear(); +- _mGsetting["switch"] = Config::gsetting->get("switch"); +- _mGsetting["finally-connect-the-device"] = Config::gsetting->get("finally-connect-the-device"); +- _mGsetting["adapter-address"] = Config::gsetting->get("adapter-address"); +- _mGsetting["file-save-path"] = Config::gsetting->get("file-save-path"); +- _mGsetting["adapter-address-list"] = Config::gsetting->get("adapter-address-list"); ++ _mGsetting[GSETTING_STR_BLUETOOTH_POWER_SWTICH] = Config::gsetting->get(GSETTING_STR_BLUETOOTH_POWER_SWTICH); ++ _mGsetting[GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH] = Config::gsetting->get(GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH); ++ _mGsetting[GSETTING_STR_FINALLY_CONNECT_THE_DEVICE] = Config::gsetting->get(GSETTING_STR_FINALLY_CONNECT_THE_DEVICE); ++ _mGsetting[GSETTING_STR_ADAPTER_ADDRESS] = Config::gsetting->get(GSETTING_STR_ADAPTER_ADDRESS); ++ _mGsetting[GSETTING_STR_FILE_SAVE_PATH] = Config::gsetting->get(GSETTING_STR_FILE_SAVE_PATH); ++ _mGsetting[GSETTING_STR_ADAPTER_ADDRESS_LIST] = Config::gsetting->get(GSETTING_STR_ADAPTER_ADDRESS_LIST); + + connect(Config::gsetting,SIGNAL(changed(QString)),this,SLOT(gsettingsChangedSlot(QString))); + } +@@ -334,8 +335,15 @@ void Daemon::initBluezManager() + launchTrayUI(); + + if (!_DefualtAdapter.isNull()) +- _DefualtAdapter.data()->setPowered(_mGsetting["switch"].toBool()); ++ { ++ _DefualtAdapter.data()->setPowered(_mGsetting[GSETTING_STR_BLUETOOTH_POWER_SWTICH].toBool()); + ++ //intel机型需要安装启动时为开启 ++ if ((Environment::INTER == envPC)) ++ { ++ _DefualtAdapter.data()->setDiscoverable(_mGsetting[GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH].toBool()); ++ } ++ } + reconnectFunc(); + qInfo() << Q_FUNC_INFO << __LINE__; + } +@@ -492,21 +500,21 @@ BluezQt::AdapterPtr Daemon::getDefualtAdapter() + + }else if(_BluezManager->adapters().size() == 1){ + return _BluezManager->adapters().at(0); +- Config::gsetting->set("adapter-address",QVariant::fromValue(_DefualtAdapter->address())); ++ Config::gsetting->set(GSETTING_STR_ADAPTER_ADDRESS,QVariant::fromValue(_DefualtAdapter->address())); + + }else{ + +- if(_mGsetting["adapter-address-list"].toStringList().indexOf(_mGsetting["adapter-address"].toString()) != -1){ +- return _BluezManager->adapterForAddress(_mGsetting["adapter-address"].toString()); ++ if(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS_LIST].toStringList().indexOf(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS].toString()) != -1){ ++ return _BluezManager->adapterForAddress(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS].toString()); + }else{ + //这里adapter-address-list的数据不一定存在 +- if (_mGsetting["adapter-address-list"].toStringList().size() > 0) ++ if (_mGsetting[GSETTING_STR_ADAPTER_ADDRESS_LIST].toStringList().size() > 0) + { +- return _BluezManager->adapterForAddress(_mGsetting["adapter-address-list"].toStringList().at(0)); ++ return _BluezManager->adapterForAddress(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS_LIST].toStringList().at(0)); + } + else + { +- return _BluezManager->adapterForAddress(_mGsetting["adapter-address"].toString()); ++ return _BluezManager->adapterForAddress(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS].toString()); + } + } + } +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 82a2863..4172b44 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -804,7 +804,7 @@ void SessionDbusRegister::connectSignal() + ::sleepFlag = false; + } + +- Config::gsetting->set("switch",QVariant(powered)); ++ Config::gsetting->set(GSETTING_STR_BLUETOOTH_POWER_SWTICH,QVariant(powered)); + + emit defaultAdapterPowerChanged(powered); + }); +@@ -816,6 +816,10 @@ void SessionDbusRegister::connectSignal() + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoverableChanged,this,[=](bool discoverable){ + qDebug() << Q_FUNC_INFO << "discoverableChanged" << discoverable << __LINE__; ++ ++ //这里是否需要增加intel机型判断,intel默认可被发状态为开启 ++ Config::gsetting->set(GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH,QVariant(discoverable)); ++ + emit defaultDiscoverableChanged(discoverable); + }); + +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 912053d..da09619 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -2165,7 +2165,9 @@ void BlueToothMain::adapterComboxChanged(int i) + setDefaultAdapterScanOn(false); + clearAllUnPairedDevicelist(); + +- setDefaultAdapter(m_bluetooth_adapter_list.at(i)->getDevAddress()); ++ if (i < m_bluetooth_adapter_list.size()) ++ setDefaultAdapter(m_bluetooth_adapter_list.at(i)->getDevAddress()); ++ + refreshUIWhenAdapterChanged(); + }else{ + if(m_open_bluetooth_btn->isChecked()){ diff --git a/patches/bluetoothService_modify_phone_only_connection_audio_source.patch b/patches/bluetoothService_modify_phone_only_connection_audio_source.patch new file mode 100644 index 0000000..983ec78 --- /dev/null +++ b/patches/bluetoothService_modify_phone_only_connection_audio_source.patch @@ -0,0 +1,82 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 4172b44..6f950ad 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -241,7 +241,52 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + } + + }); +- } else { ++ } ++ //Dt-test phone只连接媒体音频 ++ else if(dev.data()->type() == BluezQt::Device::Phone) ++ { ++ qDebug () << Q_FUNC_INFO << ++ dev.data()->name() << ++ dev.data()->address() << ++ dev.data()->type() << __LINE__; ++ ++ if (Environment::HUAWEI == envPC) ++ { ++ //华为 ++ qDebug () << Q_FUNC_INFO << "Environment::HUAWEI??"<< envPC; ++ return; ++ } ++ //背景:PC连接手机后,PC端播放音频无法从手机端输出 ++ //手机移动设备只连接媒体音频,可通过手机端发送音频至PC播放.将PC设备作为一个输出设备。 ++ //UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb) ++ BluezQt::PendingCall *call = dev.data()->connectProfile("0000110a-0000-1000-8000-00805f9b34fb"); ++ GlobalSize::refBlueDevActive(dev->address()); ++ connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ GlobalSize::unrefBlueDevActive(dev->address()); ++ if (callReturn->error()) { ++ emit devOperateErrorSignal(dev.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); ++ } ++ else ++ { ++ //主动连接成功后,发送连接成功信号 ++ addDelay(dev); ++ } ++ ++ //不存在主动连接 ++ if(GlobalSize::BlueDevActiveSize() == 0) ++ { ++ qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; ++ if (::isScan) { ++ if(!Daemon::_DefualtAdapter.data()->isDiscovering()) ++ Daemon::_DefualtAdapter.data()->startDiscovery(); ++ } ++ } ++ }); ++ } ++ else { + + qDebug () << Q_FUNC_INFO << dev.data()->type() << __LINE__; + +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index da09619..7370c3f 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -2297,7 +2297,6 @@ void BlueToothMain::cleanPairDevices() + delete child; + child = nullptr; + +- + } + device_list->setVisible(false); + qDebug() << Q_FUNC_INFO << "=============33333333" ; +diff --git a/ukcc-bluetooth/ukccbluetoothconfig.cpp b/ukcc-bluetooth/ukccbluetoothconfig.cpp +index b687b17..12258d4 100644 +--- a/ukcc-bluetooth/ukccbluetoothconfig.cpp ++++ b/ukcc-bluetooth/ukccbluetoothconfig.cpp +@@ -41,6 +41,7 @@ bool ukccbluetoothconfig::checkProcessRunning(const QString &processName, QList< + // strCommand = "ps -ef|grep '" + processName + " -o' |grep -v grep |awk '{print $2}'"; + //else + strCommand = "ps -ef|grep '" + processName + "' |grep -v grep |awk '{print $2}'"; ++ qDebug() << Q_FUNC_INFO << strCommand << __LINE__; + + QByteArray ba = strCommand.toLatin1(); + const char* strFind_ComName = ba.data(); diff --git a/patches/bluetoothService_segmentation_fault.patch b/patches/bluetoothService_segmentation_fault.patch new file mode 100644 index 0000000..8b2f655 --- /dev/null +++ b/patches/bluetoothService_segmentation_fault.patch @@ -0,0 +1,14 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 32b55bf..6dc15a3 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -333,7 +333,8 @@ void Daemon::initBluezManager() + launchDbusSignal(); + launchTrayUI(); + +- _DefualtAdapter.data()->setPowered(_mGsetting["switch"].toBool()); ++ if (nullptr != _DefualtAdapter) ++ _DefualtAdapter.data()->setPowered(_mGsetting["switch"].toBool()); + + reconnectFunc(); + qInfo() << Q_FUNC_INFO << __LINE__; diff --git a/patches/bluetooth_pangguw_ukcc_cut.patch b/patches/bluetooth_pangguw_ukcc_cut.patch new file mode 100644 index 0000000..c9dfb68 --- /dev/null +++ b/patches/bluetooth_pangguw_ukcc_cut.patch @@ -0,0 +1,127 @@ +Index: ukui-bluetooth/ukcc-bluetooth/bluetooth.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetooth.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetooth.cpp +@@ -39,6 +39,8 @@ QWidget *Bluetooth::pluginUi() { + pluginWidget = new BlueToothMain; + // pluginWidget = new BlueToothMainWindow; + } ++ if (!mFirstLoad && (nullptr != pluginWidget)) ++ pluginWidget->setbluetoothAdapterDiscoveringStatus(true); + return pluginWidget; + } + +@@ -61,6 +63,10 @@ bool Bluetooth::isEnable() const + return true; + } + +- ++void Bluetooth::plugin_leave() ++{ ++ if (nullptr != pluginWidget) ++ pluginWidget->setbluetoothAdapterDiscoveringStatus(false); ++} + + +Index: ukui-bluetooth/ukcc-bluetooth/bluetooth.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetooth.h ++++ ukui-bluetooth/ukcc-bluetooth/bluetooth.h +@@ -27,6 +27,8 @@ public: + QIcon icon() const Q_DECL_OVERRIDE; + bool isEnable() const Q_DECL_OVERRIDE; + ++ void plugin_leave() Q_DECL_OVERRIDE; ++ + private: + QString pluginName; + int pluginType; +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -1193,6 +1193,11 @@ void BlueToothMain::setDefaultAdapterDis + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + } ++void BlueToothMain::setbluetoothAdapterDiscoveringStatus(bool isScan) ++{ ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ setDefaultAdapterScanOn(isScan); ++} + + void BlueToothMain::setDefaultAdapterScanOn(bool value) + { +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.h ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.h +@@ -60,7 +60,7 @@ protected: + //dev-3.1 界面服务分离 + + public: +- ++ void setbluetoothAdapterDiscoveringStatus(bool); + signals: + void sendAdapterNameChangeSignal(const QString &value); + void defaultAdapterNameChanged(const QString &name); +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothnamelabel.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothnamelabel.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothnamelabel.cpp +@@ -100,6 +100,28 @@ void BluetoothNameLabel::dev_name_limit_ + } + } + } ++void BluetoothNameLabel::mousePressEvent(QMouseEvent *event) ++{ ++ Q_UNUSED(event); ++ ++// m_label->setVisible(false); ++// icon_pencil->setVisible(false); ++ ++// m_lineedit->setText(device_name); ++// m_lineedit->setVisible(true); ++// m_lineedit->setFocus(); ++ ++ DevRenameDialog *renameDialog = new DevRenameDialog(); ++ renameDialog->setDevName(device_name); ++ ++ connect(renameDialog,&DevRenameDialog::nameChanged,this,[=](QString name){ ++ m_label->setText(name); ++ device_name = name; ++ emit sendAdapterName(name); ++ }); ++ ++ renameDialog->exec(); ++} + + void BluetoothNameLabel::mouseDoubleClickEvent(QMouseEvent *event) + { +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothnamelabel.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothnamelabel.h ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothnamelabel.h +@@ -27,6 +27,7 @@ public: + void set_dev_name(const QString &dev_name); + void dev_name_limit_fun(); + protected: ++ void mousePressEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void leaveEvent(QEvent *event); + void enterEvent(QEvent *event); +Index: ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/deviceinfoitem.cpp ++++ ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +@@ -250,8 +250,8 @@ void DeviceInfoItem::setDeviceConnectSig + _DevStatus = DEVSTATUS::ConnectFailed; + } + +- if (_MDev->isPaired()) +- emit devConnectionComplete(); ++ //if (_MDev->isPaired()) ++ emit devConnectionComplete(); + + update(); + }); diff --git a/patches/cloes_bt_by_trayWidget_segment_fault.patch b/patches/cloes_bt_by_trayWidget_segment_fault.patch new file mode 100644 index 0000000..26c66a8 --- /dev/null +++ b/patches/cloes_bt_by_trayWidget_segment_fault.patch @@ -0,0 +1,12 @@ +Index: ukui-bluetooth/ukui-bluetooth/mainwidget/traywidget.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/mainwidget/traywidget.cpp ++++ ukui-bluetooth/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -79,7 +79,6 @@ TrayWidget::~TrayWidget() + + void TrayWidget::openBluetoothSlot(bool v) + { +- qDebug() <getPairedDevices().size(); + emit trayIconStatusChanged(v); + if (v != _SessionDBus->isPowered()) + _SessionDBus->setDefaultAdapterPower(v); diff --git a/patches/delete_battery_shown_in_HUAWEI.patch b/patches/delete_battery_shown_in_HUAWEI.patch new file mode 100644 index 0000000..fef5c83 --- /dev/null +++ b/patches/delete_battery_shown_in_HUAWEI.patch @@ -0,0 +1,67 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 30b6705..051c296 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -10,7 +10,13 @@ QDevItem::QDevItem(QString address, QStringList deviceinfo, bool connected, QWid + _MType(deviceinfo.at(1)) + { + initMap(); ++ ++ if (isHuaWei()) ++ _Battery = QString("-1"); ++ else ++ qDebug() << "This is Normal Machine in Normal Progress."; + qDebug() << " get dev Battery : " << deviceinfo.at(0) << _Battery; ++ + if(QGSettings::isSchemaInstalled("org.ukui.style")) { + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,[=]{ +@@ -39,6 +45,21 @@ QDevItem::~QDevItem() + + } + ++bool QDevItem::isHuaWei() { ++ QProcess p; ++ p.start("bash", QStringList() <<"-c" << "cat /proc/cpuinfo | grep Hardware"); ++ p.waitForFinished(); ++ QString strResult = p.readAllStandardOutput(); ++ ++ QString str = strResult.toLower(); ++ if(str.length() == 0) ++ return false; ++ if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || ++ str.indexOf("kirin") != -1) ++ return true; ++ return false; ++} ++ + void QDevItem::initMap() { + typeMap = new QMap(); + typeMap->insert(QString("phone"), QIcon::fromTheme("phone-symbolic")); +diff --git a/ukui-bluetooth/component/qdevitem.h b/ukui-bluetooth/component/qdevitem.h +index a7156d8..642efde 100644 +--- a/ukui-bluetooth/component/qdevitem.h ++++ b/ukui-bluetooth/component/qdevitem.h +@@ -58,6 +58,7 @@ private: + QColor getPainterBrushColor(); + QColor getDevStatusColor(); + QPixmap getDevTypeIcon(); ++ bool isHuaWei(); + void initMap(); + void DrawBackground(QPainter &); + void DrawStatusIcon(QPainter &); +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index b1e0951..7e6795e 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -137,8 +137,8 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + title_text->setGeometry(38, 9, 160, 20); + PIN_label->setGeometry(25,90,207,36); + tip_label->setGeometry(25,56,437,40); +- accept_btn->setGeometry(400,152,116,36); +- refuse_btn->setGeometry(288,152,116,36); ++ accept_btn->setGeometry(400,152,96,36); ++ refuse_btn->setGeometry(288,152,96,36); + } + QList list = QGuiApplication::screens(); + this->move(list.at(0)->size().width()/2-this->width()/2,list.at(0)->size().height()/2-this->height()/2); diff --git a/patches/delete_install_depend_conflict_blueman.patch b/patches/delete_install_depend_conflict_blueman.patch new file mode 100644 index 0000000..524171a --- /dev/null +++ b/patches/delete_install_depend_conflict_blueman.patch @@ -0,0 +1,11 @@ +diff --git a/debian/control b/debian/control +index 5047fc4..2935656 100644 +--- a/debian/control ++++ b/debian/control +@@ -30,6 +30,5 @@ Depends: libkf5bluezqt6, + peony-bluetooth (>= 3.2.2+0611), + ${shlibs:Depends}, ${misc:Depends} + Recommends: pulseaudio-module-bluetooth +-Conflicts: blueman + Description: Manual for UKUI desktop environment (common files) + A lightweight Bluetooth tool based on libkf5bluezqt6 on the UKUI desktop environment diff --git a/patches/fileSend_and_fileReceive_filetype_show.patch b/patches/fileSend_and_fileReceive_filetype_show.patch new file mode 100644 index 0000000..f557267 --- /dev/null +++ b/patches/fileSend_and_fileReceive_filetype_show.patch @@ -0,0 +1,386 @@ +diff --git a/service/bluetoothobexagent.cpp b/service/bluetoothobexagent.cpp +index 7ee5348..b9f05c8 100644 +--- a/service/bluetoothobexagent.cpp ++++ b/service/bluetoothobexagent.cpp +@@ -54,7 +54,7 @@ void BluetoothObexAgent::authorizePush(BluezQt::ObexTransferPtr transfer, BluezQ + QDBusMessage fileReceivingSignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "fileReceivingSignal"); +- fileReceivingSignal << session->destination() << transfer->name() << session->source() << transfer.data()->size(); ++ fileReceivingSignal << session->destination() << transfer->name() << transfer->type() << session->source() << transfer.data()->size(); + QDBusConnection::sessionBus().send(fileReceivingSignal); + qDebug() << Q_FUNC_INFO << __LINE__; + +diff --git a/service/daemon.cpp b/service/daemon.cpp +index f7de0d9..ef7c80f 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -335,7 +335,7 @@ void Daemon::continueSendFiles(QString filename) { + filePtr = v.value(); + if(!filePtr.isNull()){ + transfer_file_size = filePtr->size(); +- qDebug() << Q_FUNC_INFO << "Sending file size:" << transfer_file_size << __LINE__; ++ qDebug() << Q_FUNC_INFO << "Sending file size:" << transfer_file_size << filePtr->type() << filePtr->name() <<__LINE__; + + connect(filePtr.data(),&BluezQt::ObexTransfer::transferredChanged,this,[=](quint64 vl){ + qDebug() << Q_FUNC_INFO << "Sending file size:" << vl << __LINE__; +diff --git a/service/sessiondbusregister.h b/service/sessiondbusregister.h +index 92a2e41..3ac2518 100644 +--- a/service/sessiondbusregister.h ++++ b/service/sessiondbusregister.h +@@ -192,7 +192,7 @@ signals: + + void statusChanged(QString); + +- void fileReceivingSignal(QString,QString,QString,quint64); ++ void fileReceivingSignal(QString,QString,QString,QString,quint64); + + void replyFileReceivingSignal(bool); + +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 0a61b51..43aaefa 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -36,7 +36,7 @@ void BluetoothDbus::connectDBusSignals() { + + + //文件传输相关dbus +- CONNECT_DBUS_SIGNAL("fileReceivingSignal", receiveFilesSlot(QString,QString,QString,quint64)); ++ CONNECT_DBUS_SIGNAL("fileReceivingSignal", receiveFilesSlot(QString,QString,QString,QString,quint64)); + TRANSFER_DBUS_SIGNAL("obexAgentCanceled", obexAgentCanceledSignal()); + TRANSFER_DBUS_SIGNAL("fileReceiveMore", fileReceiveMore(QString, quint64, QString)); + TRANSFER_DBUS_SIGNAL("sendTransferFilesMesg", sendTransferFilesMesgSignal(QStringList)); +@@ -127,9 +127,10 @@ void BluetoothDbus::devErrorSignalSLot(QString a) { + qDebug() << "-----------------------" << a; + } + +-void BluetoothDbus::receiveFilesSlot(QString destination, QString filename, QString source, quint64 size) { ++void BluetoothDbus::receiveFilesSlot(QString destination, QString filename, QString type, QString source, quint64 size) { + emit receiveFilesSignal(pairedDevice.value(destination).at(0), + filename, ++ type, + source, + size); + } +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.h b/ukui-bluetooth/daemon/bluetoothdbus.h +index 3ca8036..556b62a 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.h ++++ b/ukui-bluetooth/daemon/bluetoothdbus.h +@@ -77,7 +77,7 @@ public: + signals: + void powerChangedSignal(bool); + void displayPasskeySignal(QString,QString); +- void receiveFilesSignal(QString,QString,QString,quint64); ++ void receiveFilesSignal(QString,QString,QString,QString,quint64); + void requestConfirmationSignal(QString,QString); + void transferredChangedSignal(quint64); + void statusChangedSignal(QString); +@@ -109,7 +109,7 @@ private slots: + void devErrorSignalSLot(QString); + void devNameChangedSignalSLot(QString address, QString name); + void devBatteryChangedSignalSLot(QString address, QString battery); +- void receiveFilesSlot(QString destination, QString filename, QString source, quint64 size); ++ void receiveFilesSlot(QString destination, QString filename, QString type, QString source, quint64 size); + }; + + #endif // BLUETOOTHDBUS_H +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index b83fa7d..760c671 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -1,9 +1,10 @@ + #include "filereceivingpopupwidget.h" + #include "config/xatom-helper.h" + +-FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString filename, QString root, quint64 size): ++FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString filename, QString type, QString root, quint64 size): + target_name(devname), + target_source(filename), ++ target_type(type), + root_address(root), + target_size(size) + { +@@ -72,26 +73,32 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + this->close(); + }); + QIcon fileicon; +- if (target_source.contains(".")) +- { +- if (target_source.contains(".jpg", Qt::CaseInsensitive) +- || target_source.contains(".png", Qt::CaseInsensitive) +- || target_source.contains(".svg", Qt::CaseInsensitive)){ +- fileicon = QIcon::fromTheme("image"); +- }else if (target_source.contains(".mp4", Qt::CaseInsensitive) +- || target_source.contains(".mkv", Qt::CaseInsensitive)) +- fileicon = QIcon::fromTheme("video-x-generic"); +- if (target_source.contains(".txt", Qt::CaseInsensitive)) +- fileicon = QIcon::fromTheme("text-plain"); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(target_source.split(".").at(1)); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); +- } +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme("text-plain"); ++ if (target_type.split("/").at(0) == "image"){ ++ fileicon = QIcon::fromTheme("image"); ++ if (fileicon.isNull()) { ++ fileicon = QIcon::fromTheme("text"); ++ } ++ }else if (target_type.split("/").at(0) == "video") ++ fileicon = QIcon::fromTheme("video-x-generic"); ++ else if (target_type.split("/").at(0) == "audio" || ++ target_type.split("/").at(0) == "application" || ++ target_type.split("/").at(0) == "text" || ++ target_type.split("/").at(0) == "inode"){ ++ if (QIcon::hasThemeIcon(target_type.split("/").join("-"))) { ++ fileicon = QIcon::fromTheme(target_type.split("/").join("-")); ++ qDebug() << target_type.split("/").join("-"); ++ } else { ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme("text-plain"); ++ } ++ }else ++ fileicon = QIcon::fromTheme("text"); + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); + file_source->setGeometry(32,52,460,54); + file_source->setAlignment(Qt::AlignTop); +@@ -198,10 +205,41 @@ void FileReceivingPopupWidget::updateUI(QString name, quint64 size, QString type + unitcount++; + } + qDebug() << type; ++ target_type = type; + target_source = name; ++ QIcon fileicon; ++ if (target_type.split("/").at(0) == "image"){ ++ fileicon = QIcon::fromTheme("image"); ++ if (fileicon.isNull()) { ++ fileicon = QIcon::fromTheme("text"); ++ } ++ }else if (target_type.split("/").at(0) == "video") ++ fileicon = QIcon::fromTheme("video-x-generic"); ++ else if (target_type.split("/").at(0) == "audio" || ++ target_type.split("/").at(0) == "application" || ++ target_type.split("/").at(0) == "text" || ++ target_type.split("/").at(0) == "inode"){ ++ if (QIcon::hasThemeIcon(target_type.split("/").join("-"))) { ++ fileicon = QIcon::fromTheme(target_type.split("/").join("-")); ++ qDebug() << target_type.split("/").join("-"); ++ } else { ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme("text-plain"); ++ } ++ }else ++ fileicon = QIcon::fromTheme("text"); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ file_icon->setPixmap(fileicon.pixmap(64,64)); + file_name->setText(fileName); + file_size->setText(QString::asprintf("%.2f", calc_size) + unitString[unitcount]); + file_source->setText(tr("File from \"")+target_name+tr("\", is receiving... \(has recieved ")+QString::number(fileNums)+tr(" files\)")); ++ this->update(); + } + + void FileReceivingPopupWidget::configuration_transfer_progress_bar(quint64 value) +@@ -323,46 +361,6 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + receiveTimer->stop(); + } else + file_source->setText(tr("File from \"")+target_name+tr("\", is receiving...")); +- QString filePathName = QDir::homePath()+"/.cache/obexd/"+target_source; +- GError *error; +- qDebug() << Q_FUNC_INFO << filePathName; +- GFile *file = g_file_new_for_path(filePathName.toStdString().c_str()); +- GFileInfo *file_info = g_file_query_info(file,"*",G_FILE_QUERY_INFO_NONE,NULL,&error); +- qDebug() << Q_FUNC_INFO << g_file_info_get_size(file_info) << g_file_info_get_content_type(file_info); +- qDebug() << Q_FUNC_INFO << __LINE__; +- +- QString str = g_file_info_get_content_type(file_info); +- qDebug() << Q_FUNC_INFO << __LINE__; +- QIcon fileicon; +- if (str.split("/").at(0) == "image"){ +- fileicon = QIcon::fromTheme("image"); +- if (fileicon.isNull()) { +- fileicon = QIcon::fromTheme("text"); +- } +- }else if (str.split("/").at(0) == "video") +- fileicon = QIcon::fromTheme("video-x-generic"); +- else if (str.split("/").at(0) == "audio" || +- str.split("/").at(0) == "application" || +- str.split("/").at(0) == "text" || +- str.split("/").at(0) == "inode"){ +- if (QIcon::hasThemeIcon(str.split("/").join("-"))) { +- fileicon = QIcon::fromTheme(str.split("/").join("-")); +- qDebug() << str.split("/").join("-"); +- } else { +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(target_source.split(".").at(1)); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme("text-plain"); +- } +- }else +- fileicon = QIcon::fromTheme("text"); +- qDebug() << Q_FUNC_INFO << __LINE__; +- file_icon->setPixmap(fileicon.pixmap(64,64)); +- this->update(); + cancel_btn->disconnect(); + cancel_btn->connect(cancel_btn,&QPushButton::clicked,this,[=]{ + emit this->cancel(); +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +index f2dfe43..c2d8626 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +@@ -45,7 +45,7 @@ class FileReceivingPopupWidget : public QWidget + { + Q_OBJECT + public: +- explicit FileReceivingPopupWidget(QString devname = "", QString filename = "", QString root = "", quint64 size = 0); ++ explicit FileReceivingPopupWidget(QString devname = "", QString filename = "", QString type = "", QString root = "", quint64 size = 0); + ~FileReceivingPopupWidget(); + void configuration_transfer_progress_bar(quint64); + void window_pop_up_animation(); +@@ -89,6 +89,7 @@ private: + QString target_address; + QString target_name; + QString target_source; ++ QString target_type; + QString root_address; + QString file_path; + quint64 target_size; +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 1db6210..c36eb55 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -257,6 +257,7 @@ void BluetoothFileTransferWidget::Get_fie_type(int i) + file_size.push_back(g_format_size_full(g_file_info_get_size(file_info),G_FORMAT_SIZE_IEC_UNITS)); + _filesize.push_back(g_file_info_get_size(file_info)); + QString str = g_file_info_get_content_type(file_info); ++ filetype.push_back(str); + qDebug() << Q_FUNC_INFO << __LINE__; + QIcon fileicon; + if (str.split("/").at(0) == "image"){ +@@ -335,6 +336,7 @@ void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { + QList fileIconList; + QList _fileSizeList; + QList fileSizeList; ++ QList filetypeList; + for (int i = 0; i < fileList.size(); i++) { + GError *error; + qDebug() << Q_FUNC_INFO << fileList.at(i); +@@ -346,6 +348,7 @@ void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { + fileSizeList.push_back(g_format_size_full(g_file_info_get_size(file_info),G_FORMAT_SIZE_IEC_UNITS)); + _fileSizeList.push_back(g_file_info_get_size(file_info)); + QString str = g_file_info_get_content_type(file_info); ++ filetypeList.push_back(str); + qDebug() << Q_FUNC_INFO << __LINE__; + QIcon fileicon; + if (str.split("/").at(0) == "image"){ +@@ -369,6 +372,7 @@ void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { + qDebug() << Q_FUNC_INFO << __LINE__; + fileIconList.push_back(fileicon); + } ++ filetype.append(filetypeList); + file_icon.append(fileIconList); + file_size.append(fileSizeList); + _filesize.append(_fileSizeList); +@@ -396,7 +400,7 @@ void BluetoothFileTransferWidget::get_transfer_status(QString status) + qDebug() << Q_FUNC_INFO << status; + if(status == QString("Complete")){ + if (selectedFiles.size() > 1) { +- emit continueSendFiles(selectedFiles.at(1)); ++ emit continueSendFiles(selectedFiles.at(1) + QString(" ") + filetype.at(1)); + selectedFiles.pop_front(); + file_size.pop_front(); + file_icon.pop_front(); +@@ -544,6 +548,6 @@ void BluetoothFileTransferWidget::onClicked_OK_Btn() + + }else{ + Initialize_and_start_animation(); +- emit this->sender_dev_name(dev_widget->get_seleter_device()); ++ emit this->sender_dev_name(dev_widget->get_seleter_device(), filetype.at(0)); + } + } +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h +index de34eea..725be3b 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h +@@ -97,7 +97,7 @@ public: + int get_send_data_state(); + + signals: +- void sender_dev_name(QString); ++ void sender_dev_name(QString, QString); + void close_the_pre_session(); + void continueSendFiles(QString); + public slots: +@@ -132,6 +132,7 @@ private: + QStringList selectedFiles; + QList file_size; + QList _filesize; ++ QList filetype; + QString dev_name; + SEND_DATA_STATE send_state = _SEND_NONE; + bool is_Intel; +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index 79e8727..493f1e4 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -65,18 +65,18 @@ void MainProgram::gsettingsChangedSlot(const QString &key) + } + } + +-void MainProgram::sendFiles(QString address) { +- _sessionDbus->sendFiles(address, selectedFiles.at(0)); ++void MainProgram::sendFiles(QString address, QString type) { ++ _sessionDbus->sendFiles(address, selectedFiles.at(0) + QString(" ") + type); + } + + void MainProgram::closeSession() { + _sessionDbus->closeSession(); + } + +-void MainProgram::receiveFileSlot(QString devname, QString filename, QString source, quint64 size) ++void MainProgram::receiveFileSlot(QString devname, QString filename, QString type, QString source, quint64 size) + { + qDebug() << Q_FUNC_INFO << __LINE__; +- receiving_widget = new FileReceivingPopupWidget(devname,filename,source, size); ++ receiving_widget = new FileReceivingPopupWidget(devname, filename, type, source, size); + qDebug() << Q_FUNC_INFO << __LINE__; + connect(receiving_widget, &FileReceivingPopupWidget::clearOldSession, _sessionDbus, &BluetoothDbus::clearOldSession); + connect(_sessionDbus, &BluetoothDbus::fileReceiveMore, receiving_widget, &FileReceivingPopupWidget::updateUI); +diff --git a/ukui-bluetooth/main/mainprogram.h b/ukui-bluetooth/main/mainprogram.h +index cb4b6ca..3b993e7 100644 +--- a/ukui-bluetooth/main/mainprogram.h ++++ b/ukui-bluetooth/main/mainprogram.h +@@ -45,13 +45,13 @@ public: + + private slots: + void closeSession(); +- void sendFiles(QString address); ++ void sendFiles(QString address, QString type); + + private slots: + void gsettingsChangedSlot(const QString &); + void sendTransferFilesMesgSlot(QStringList); + void sendTransferDeviceMesgSlot(QString address); +- void receiveFileSlot(QString name, QString filename, QString source, quint64 size); ++ void receiveFileSlot(QString name, QString filename, QString type, QString source, quint64 size); + void displayPasskeySlot(QString name, QString passkey); + void requestConfirmationSlot(QString name, QString passkey); + diff --git a/patches/fix_102683.patch b/patches/fix_102683.patch new file mode 100644 index 0000000..6881ad8 --- /dev/null +++ b/patches/fix_102683.patch @@ -0,0 +1,123 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 84a63a9..2736f5f 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -281,6 +281,7 @@ void Daemon::initBluezManager() + ::rebootFlag = false; + } + } ++ qDebug() << Q_FUNC_INFO << __LINE__ << " ::rebootFlag " << ::rebootFlag; + } + }); + +@@ -322,7 +323,7 @@ void Daemon::initBluezManager() + else + ::resetFlag = false; + } +- ++ qDebug() << Q_FUNC_INFO << __LINE__ << " ::resetFlag " << ::resetFlag; + }); + + registerBluezAgent(); +@@ -506,7 +507,7 @@ BluezQt::AdapterPtr Daemon::getDefualtAdapter() + } + } + } +- qWarning("get bluetooth adapter end!!!"); ++ qWarning("get bluetooth adapter nullptr!!! adaptersize<%d>", _BluezManager->adapters().size()); + return nullptr; + + } +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 5fe86bd..2b38703 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -304,6 +304,8 @@ void SessionDbusRegister::setDefaultAdapterPower(bool v) + if (!Daemon::_DefualtAdapter.isNull()) { + if (Daemon::_BluezManager && Daemon::_BluezManager->isBluetoothBlocked()) + Daemon::_BluezManager->setBluetoothBlocked(false); ++ ++ qDebug() << Q_FUNC_INFO << "setDefaultAdapterPower" << v << __LINE__; + Daemon::_DefualtAdapter.data()->setPowered(v)->errorText(); + } + } +@@ -611,7 +613,7 @@ QStringList SessionDbusRegister::getDefaultAdapterCacheDevAddress() + { + QStringList CacheDevList; + CacheDevList.clear(); +- if (Daemon::_BluezManager) { ++ if (!Daemon::_DefualtAdapter.isNull()) { + for (auto item : Daemon::_DefualtAdapter.data()->devices()) { + CacheDevList.append(item.data()->address()); + } +@@ -722,7 +724,7 @@ void SessionDbusRegister::connectSignal() + } + else{ + if(adapter->isPowered()){ +- qDebug() << Q_FUNC_INFO << "adapter->isPowered() true, emit false" << __LINE__; ++ qDebug() << Q_FUNC_INFO << "adapter->isPowered() true" << __LINE__; + static_bluezreboot_power = 1; + } + else{ +@@ -759,7 +761,9 @@ void SessionDbusRegister::connectSignal() + if (::resetFlag || ::rebootFlag) { + QTimer::singleShot(100,this,[=]{ + Daemon::_DefualtAdapter.data()->setPowered(false); ++ qDebug() << Q_FUNC_INFO << __LINE__; + }); ++ qDebug() << Q_FUNC_INFO << __LINE__<< ::resetFlag << ::rebootFlag; + ::resetFlag = false; + ::rebootFlag = false; + } +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 7c97374..f212edf 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -1,4 +1,4 @@ +-#include "bluetoothmain.h" ++#include "bluetoothmain.h" + + #include "bluetoothdbusservice.h" + #include "devicebase.h" +@@ -1742,11 +1742,17 @@ void BlueToothMain::refreshUIWhenAdapterChanged() + //==============初始化蓝牙信息和基础信息==================================== + bluetooth_name->set_dev_name(m_default_adapter_name); + ++ ++ + qDebug() << Q_FUNC_INFO << "m_current_adapter_power_swtich:" << m_current_adapter_power_swtich ; + if(m_current_adapter_power_swtich) + { + if (!m_open_bluetooth_btn->isChecked()) ++ { ++ //添加标识,从蓝牙服务获取的数据 ++ m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(true); ++ } + // bluetooth_name->setVisible(true); + frame_middle->setVisible(m_myDev_show_flag); + if (!frame_bottom->isVisible() && frame_bottom->children().size()) +@@ -1755,7 +1761,11 @@ void BlueToothMain::refreshUIWhenAdapterChanged() + else + { + if (m_open_bluetooth_btn->isChecked()) ++ { ++ //添加标识,从蓝牙服务获取的数据 ++ m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(false); ++ } + // bluetooth_name->setVisible(false); + frame_bottom->setVisible(false); + frame_middle->setVisible(false); +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 808e5d8..9c8f208 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -267,6 +267,7 @@ void BluetoothDbus::setDefaultAdapterPower(bool power) { + SYSTEMD_INTERFACE, + "setDefaultAdapterPower"); + m << power; ++ qDebug() << " setDefaultAdapterPower " << power << __LINE__; + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + } + diff --git a/patches/fix_2th_send_file_failed.patch b/patches/fix_2th_send_file_failed.patch new file mode 100644 index 0000000..66b53d2 --- /dev/null +++ b/patches/fix_2th_send_file_failed.patch @@ -0,0 +1,42 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 9342c48..9dcb9ea 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -407,6 +407,16 @@ void Daemon::fileTransferSessionCreator(QString address,QString filename) + map["Source"] = _DefualtAdapter->address(); + map["Target"] = "OPP"; + ++ if (!_ObexManager->isOperational()) { ++ connect(_ObexManager, &BluezQt::ObexManager::operationalChanged, this, [=](bool operational) { ++ Q_UNUSED(operational) ++ fileTransferSessionCreator(address, filename); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ disconnect(_ObexManager, &BluezQt::ObexManager::operationalChanged, nullptr, nullptr); ++ }); ++ return; ++ } ++ + BluezQt::PendingCall *target = _ObexManager->createSession(address,map); + qDebug() << Q_FUNC_INFO << target->error() << target->errorText(); + connect(target,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 9388d01..6e6c1a9 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -64,7 +64,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + close_btn->setFixedSize(30,30); + close_btn->setGeometry(484,4,30,30); + connect(close_btn,&QPushButton::clicked,this,[=]{ +- emit this->close_the_pre_session(); ++ emit close_the_pre_session(); + this->close(); + }); + +@@ -495,7 +495,6 @@ void BluetoothFileTransferWidget::tranfer_error() + tranfer_status_text->setVisible(true); + + cancel_btn->setText(tr("OK")); +- emit this->close_the_pre_session(); + } + + int BluetoothFileTransferWidget::get_send_data_state() diff --git a/patches/fix_append_files_to_tail_of_query_when_sending_files.patch b/patches/fix_append_files_to_tail_of_query_when_sending_files.patch new file mode 100644 index 0000000..608452e --- /dev/null +++ b/patches/fix_append_files_to_tail_of_query_when_sending_files.patch @@ -0,0 +1,105 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 0afc86c..1a225cb 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -323,6 +323,66 @@ void BluetoothFileTransferWidget::init_m_progressbar_value(quint64 value) + m_progressbar->setValue(0); + } + ++void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { ++ QList fileIconList; ++ QList _fileSizeList; ++ QList fileSizeList; ++ for (int i = 0; i < fileList.size(); i++) { ++ GError *error; ++ qDebug() << Q_FUNC_INFO << fileList.at(i); ++ GFile *file = g_file_new_for_path(fileList.at(i).toStdString().c_str()); ++ GFileInfo *file_info = g_file_query_info(file,"*",G_FILE_QUERY_INFO_NONE,NULL,&error); ++ qDebug() << Q_FUNC_INFO << g_file_info_get_size(file_info) << g_file_info_get_content_type(file_info); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ ++ fileSizeList.push_back(g_format_size_full(g_file_info_get_size(file_info),G_FORMAT_SIZE_IEC_UNITS)); ++ _fileSizeList.push_back(g_file_info_get_size(file_info)); ++ QString str = g_file_info_get_content_type(file_info); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ QIcon fileicon; ++ if (str.split("/").at(0) == "image"){ ++ fileicon = QIcon(fileList.at(i)); ++ if (fileicon.isNull()) { ++ fileicon = QIcon::fromTheme("text"); ++ } ++ }else if (str.split("/").at(0) == "video") ++ fileicon = QIcon::fromTheme("video-x-generic"); ++ else if (str.split("/").at(0) == "audio" || ++ str.split("/").at(0) == "application" || ++ str.split("/").at(0) == "text" || ++ str.split("/").at(0) == "inode"){ ++ if (QIcon::hasThemeIcon(str.split("/").join("-"))) { ++ fileicon = QIcon::fromTheme(str.split("/").join("-")); ++ } else { ++ fileicon = QIcon::fromTheme("text"); ++ } ++ }else ++ fileicon = QIcon::fromTheme("text"); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ fileIconList.push_back(fileicon); ++ } ++ file_icon.append(fileIconList); ++ file_size.append(fileSizeList); ++ _filesize.append(_fileSizeList); ++ selectedFiles.append(fileList); ++ fileNums += fileList.size(); ++ if (selectedFiles.size() == 1) ++ target_name->setText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1)); ++ else if(selectedFiles.size() > 1) ++ { ++ target_name->setText("\"" ++ +selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1) ++ +"\"" ++ +tr(" and ") ++ +QString::number(selectedFiles.size()) ++ +tr(" files more")); ++ } ++ int transfing = fileNums - selectedFiles.size() + 1; ++ transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); ++ this->update(); ++} ++ ++ + void BluetoothFileTransferWidget::get_transfer_status(QString status) + { + qDebug() << Q_FUNC_INFO << status; +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h +index ca2be60..de34eea 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h +@@ -92,6 +92,7 @@ public: + void Initialize_and_start_animation(); + void init_m_progressbar_value(quint64); + void tranfer_error(); ++ void insertNewFileList(QStringList fileList); + + int get_send_data_state(); + +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index acffbc4..0472ca2 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -196,6 +196,8 @@ void MainProgram::sendTransferDeviceMesgSlot(QString address) + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::get_transfer_status); + connect(fileSendWidget,&BluetoothFileTransferWidget::continueSendFiles,_sessionDbus,&BluetoothDbus::continueSendFiles); + fileSendWidget->show(); ++ } else { ++ fileSendWidget->insertNewFileList(selectedFiles); + } + } + } +@@ -238,6 +240,8 @@ void MainProgram::sendTransferFilesMesgSlot(QStringList targetList) + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::get_transfer_status); + connect(fileSendWidget,&BluetoothFileTransferWidget::continueSendFiles,_sessionDbus,&BluetoothDbus::continueSendFiles); + fileSendWidget->show(); ++ } else { ++ fileSendWidget->insertNewFileList(selectedFiles); + } + } + } diff --git a/patches/fix_audiovideo_icon_wrong.patch b/patches/fix_audiovideo_icon_wrong.patch new file mode 100644 index 0000000..226ebb6 --- /dev/null +++ b/patches/fix_audiovideo_icon_wrong.patch @@ -0,0 +1,178 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index d3b22f2..c3ad860 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -785,7 +785,7 @@ bool BlueToothMain::whetherToAddCurrentInterface(bluetoothdevice * device) + case DevTypeShow::Audio: + if (device->getDevType() == bluetoothdevice::DEVICE_TYPE::headset || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::headphones || +- device->getDevType() == bluetoothdevice::DEVICE_TYPE::audioVideo) { ++ device->getDevType() == bluetoothdevice::DEVICE_TYPE::audiovideo) { + return true; + } else { + return false; +@@ -816,7 +816,7 @@ bool BlueToothMain::whetherToAddCurrentInterface(bluetoothdevice * device) + default: + if (device->getDevType() == bluetoothdevice::DEVICE_TYPE::headset || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::headphones || +- device->getDevType() == bluetoothdevice::DEVICE_TYPE::audioVideo || ++ device->getDevType() == bluetoothdevice::DEVICE_TYPE::audiovideo || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::phone || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::mouse || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::keyboard || +@@ -1985,7 +1985,7 @@ void BlueToothMain::addDiscoverDevListByFlag(BlueToothMain::DevTypeShow flag) + case DevTypeShow::Audio: + if (dev->getDevType() == bluetoothdevice::DEVICE_TYPE::headset || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::headphones || +- dev->getDevType() == bluetoothdevice::DEVICE_TYPE::audioVideo) { ++ dev->getDevType() == bluetoothdevice::DEVICE_TYPE::audiovideo) { + addOneBluetoothDeviceItemUi(dev); + } + break; +@@ -2008,7 +2008,7 @@ void BlueToothMain::addDiscoverDevListByFlag(BlueToothMain::DevTypeShow flag) + case DevTypeShow::Other: + if (dev->getDevType() == bluetoothdevice::DEVICE_TYPE::headset || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::headphones || +- dev->getDevType() == bluetoothdevice::DEVICE_TYPE::audioVideo || ++ dev->getDevType() == bluetoothdevice::DEVICE_TYPE::audiovideo || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::phone || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::mouse || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::keyboard || +diff --git a/ukcc-bluetooth/devicebase.h b/ukcc-bluetooth/devicebase.h +index 543281f..1f38ca0 100644 +--- a/ukcc-bluetooth/devicebase.h ++++ b/ukcc-bluetooth/devicebase.h +@@ -90,7 +90,7 @@ public: + /** The device is a headphones. */ + headphones, + /** The device is an uncategorized audio video device. */ +- audioVideo, ++ audiovideo, + /** The device is a keyboard. */ + keyboard, + /** The device is a mouse. */ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index efd52a7..bf40f45 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -598,7 +598,7 @@ QPixmap DeviceInfoItem::getDevTypeIcon() + case bluetoothdevice::DEVICE_TYPE::headphones: + iconName = "audio-headphones-symbolic"; + break; +- case bluetoothdevice::DEVICE_TYPE::audioVideo: ++ case bluetoothdevice::DEVICE_TYPE::audiovideo: + iconName = "audio-speakers-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::keyboard: +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 87985ba..7e7f69c 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -7,8 +7,9 @@ QDevItem::QDevItem(QString address, QStringList deviceinfo, bool connected, QWid + _Connected(connected), + _Name(deviceinfo.at(0)), + _Battery(deviceinfo.at(2)), +- _Type(BluezQt::Device::stringToType(deviceinfo.at(1))) ++ _MType(deviceinfo.at(1)) + { ++ initMap(); + qDebug() << " get dev Battery : " << deviceinfo.at(0) << _Battery; + if(QGSettings::isSchemaInstalled("org.ukui.style")) { + StyleSettings = new QGSettings("org.ukui.style"); +@@ -38,6 +39,17 @@ QDevItem::~QDevItem() + + } + ++void QDevItem::initMap() { ++ typeMap = new QMap(); ++ typeMap->insert(QString("phone"), QIcon::fromTheme("phone-symbolic")); ++ typeMap->insert(QString("computer"), QIcon::fromTheme("computer-symbolic")); ++ typeMap->insert(QString("headset"), QIcon::fromTheme("audio-headset-symbolic")); ++ typeMap->insert(QString("headphones"), QIcon::fromTheme("audio-headphones-symbolic")); ++ typeMap->insert(QString("audiovideo"), QIcon::fromTheme("audio-speakers-symbolic")); ++ typeMap->insert(QString("keyboard"), QIcon::fromTheme("input-keyboard-symbolic")); ++ typeMap->insert(QString("mouse"), QIcon::fromTheme("input-mouse-symbolic")); ++} ++ + void QDevItem::SendMessage(bool connected) + { + QString text; +@@ -207,32 +219,9 @@ QPixmap QDevItem::getDevTypeIcon() + if (_clicked) { + icon = QIcon::fromTheme("ukui-loading-" + QString::number(iconFlag)); + } else { +- switch (_Type) { +- case BluezQt::Device::Phone: +- icon = QIcon::fromTheme("phone-symbolic"); +- break; +- case BluezQt::Device::Computer: +- icon = QIcon::fromTheme("computer-symbolic"); +- break; +- case BluezQt::Device::Headset: +- icon = QIcon::fromTheme("audio-headset-symbolic"); +- break; +- case BluezQt::Device::Headphones: +- icon = QIcon::fromTheme("audio-headphones-symbolic"); +- break; +- case BluezQt::Device::AudioVideo: +- icon = QIcon::fromTheme("audio-speakers-symbolic"); +- break; +- case BluezQt::Device::Keyboard: +- icon = QIcon::fromTheme("input-keyboard-symbolic"); +- break; +- case BluezQt::Device::Mouse: +- icon = QIcon::fromTheme("input-mouse-symbolic"); +- break; +- default: +- icon = QIcon::fromTheme("bluetooth-symbolic"); +- break; +- } ++ icon = typeMap->value(_MType); ++ if (icon.isNull()) ++ icon = QIcon::fromTheme("bluetooth-symbolic"); + } + return icon.pixmap(18,18); + } +diff --git a/ukui-bluetooth/component/qdevitem.h b/ukui-bluetooth/component/qdevitem.h +index 837f992..a7156d8 100644 +--- a/ukui-bluetooth/component/qdevitem.h ++++ b/ukui-bluetooth/component/qdevitem.h +@@ -54,9 +54,11 @@ protected: + void paintEvent(QPaintEvent *); + + private: ++ QMap *typeMap = nullptr; + QColor getPainterBrushColor(); + QColor getDevStatusColor(); + QPixmap getDevTypeIcon(); ++ void initMap(); + void DrawBackground(QPainter &); + void DrawStatusIcon(QPainter &); + void DrawBattery(QPainter &painter); +@@ -78,9 +80,9 @@ private: + QString _Address; + QString _Name; + QString _Battery; +- BluezQt::Device::Type _Type; + QGSettings *StyleSettings = nullptr; + QGSettings *transparency_gsettings = nullptr; ++ QString _MType; + + public slots: + void connectedChangedSlot(bool connected); +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 7e7f69c..30b6705 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -219,8 +219,9 @@ QPixmap QDevItem::getDevTypeIcon() + if (_clicked) { + icon = QIcon::fromTheme("ukui-loading-" + QString::number(iconFlag)); + } else { +- icon = typeMap->value(_MType); +- if (icon.isNull()) ++ if (typeMap->keys().contains(_MType)) ++ icon = typeMap->value(_MType); ++ else + icon = QIcon::fromTheme("bluetooth-symbolic"); + } + return icon.pixmap(18,18); diff --git a/patches/fix_background_transparency_calc.patch b/patches/fix_background_transparency_calc.patch new file mode 100644 index 0000000..7a294df --- /dev/null +++ b/patches/fix_background_transparency_calc.patch @@ -0,0 +1,111 @@ +Index: upstream/ukui-bluetooth/mainwidget/traywidget.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/mainwidget/traywidget.cpp ++++ upstream/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -22,17 +22,24 @@ TrayWidget::TrayWidget(bool intel, Bluet + this->setAttribute(Qt::WA_TranslucentBackground); + this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); + +- if(QGSettings::isSchemaInstalled("org.ukui.style")){ ++ if(QGSettings::isSchemaInstalled("org.ukui.style")) { + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,&TrayWidget::GSettingsChanges); + } + + const QByteArray transparency_id(TRANSPARENCY_SETTINGS); +- if(QGSettings::isSchemaInstalled(transparency_id)){ ++ if(QGSettings::isSchemaInstalled(transparency_id)) { + transparency_gsettings = new QGSettings(transparency_id); + } +- if(QGSettings::isSchemaInstalled(transparency_id)){ +- tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; ++ if(QGSettings::isSchemaInstalled(transparency_id)) { ++ getTransparency(); ++ connect(transparency_gsettings,&QGSettings::changed,this,[=](QString key) { ++ qDebug() << Q_FUNC_INFO << key; ++ if (key == QString(TRANSPARENCY_KEY)) { ++ getTransparency(); ++ this->update(); ++ } ++ }); + } + QPalette palette; + if(StyleSettings->get("style-name").toString() == "ukui-light"){ +@@ -49,7 +56,6 @@ TrayWidget::TrayWidget(bool intel, Bluet + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("bluetooth")); + +- + pairedDevices = _SessionDBus->getPairedDevices(); + + InitMemberVariables(); +@@ -77,6 +83,13 @@ TrayWidget::~TrayWidget() + + } + ++void TrayWidget::getTransparency() { ++ double proportion = transparency_gsettings->get(TRANSPARENCY_KEY).toDouble(); ++ proportion = ((proportion > 0.85) ? 1 : (proportion + 0.15)); ++ qDebug() << Q_FUNC_INFO << proportion; ++ tran = proportion * 255; ++} ++ + void TrayWidget::openBluetoothSlot(bool v) + { + emit trayIconStatusChanged(v); +@@ -157,10 +170,10 @@ void TrayWidget::setWidgetPosition() + void TrayWidget::GSettingsChanges(const QString &key) + { + qDebug() << Q_FUNC_INFO << key; +- tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + if(key == "styleName"){ + QPalette palette; + QPalette pl; ++ getTransparency(); + if(StyleSettings->get("style-name").toString() == "ukui-light"){ + _MLabel->setStyleSheet("color:black;"); + palette.setColor(QPalette::Background,QColor(255,255,255,0)); +@@ -453,22 +466,19 @@ void TrayWidget::showUI() + } + + void TrayWidget::paintEvent(QPaintEvent *event) { +- QPainter p(this); +- p.setRenderHint(QPainter::Antialiasing); +- p.setPen(Qt::transparent); +- const QByteArray transparency_id(TRANSPARENCY_SETTINGS); +- if(QGSettings::isSchemaInstalled(transparency_id)){ +- tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; +- } ++ Q_UNUSED(event); ++ QPainter painter(this); ++ painter.setRenderHint(QPainter::Antialiasing); ++ painter.setPen(Qt::transparent); ++ QColor col; + if(StyleSettings->get("style-name").toString() == "ukui-light"){ +- QColor col(255,255,255,tran); +- p.setBrush(col); ++ col = QColor(255,255,255,tran); + } else{ +- QColor col(35,36,38,tran); +- p.setBrush(col); ++ col = QColor(35,36,38,tran); + } ++ painter.setBrush(col); + + QPainterPath rectPath; + rectPath.addRoundedRect(this->rect(),12,12); +- p.drawPath(rectPath); ++ painter.drawPath(rectPath); + } +Index: upstream/ukui-bluetooth/mainwidget/traywidget.h +=================================================================== +--- upstream.orig/ukui-bluetooth/mainwidget/traywidget.h ++++ upstream/ukui-bluetooth/mainwidget/traywidget.h +@@ -56,6 +56,7 @@ private: + void InitNomalWidget(); + void InitErrorWidget(); + void clearPairedWidget(); ++ void getTransparency(); + + TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent = nullptr); + static TrayWidget* _MSelf; diff --git a/patches/fix_bluetoothService_crash.patch b/patches/fix_bluetoothService_crash.patch new file mode 100644 index 0000000..d628e21 --- /dev/null +++ b/patches/fix_bluetoothService_crash.patch @@ -0,0 +1,105 @@ +Index: ukui-bluetooth/service/daemon.cpp +=================================================================== +--- ukui-bluetooth.orig/service/daemon.cpp ++++ ukui-bluetooth/service/daemon.cpp +@@ -464,6 +464,7 @@ BluezQt::AdapterPtr Daemon::getDefualtAd + if(_BluezManager->adapters().size() == 0){ + + qWarning("No bluetooth adapter !!!"); ++ return nullptr; + + }else if(_BluezManager->adapters().size() == 1){ + +@@ -478,6 +479,9 @@ BluezQt::AdapterPtr Daemon::getDefualtAd + return _BluezManager->adapterForAddress(_mGsetting["adapter-address-list"].toStringList().at(0)); + } + } ++ qWarning("No bluetooth adapter end!!!"); ++ return nullptr; ++ + } + + /************************************************ +@@ -545,7 +549,10 @@ void Daemon::monitorSleepSlot(bool sleep + + QTimer::singleShot(200,this,[=]{ + _DefualtAdapter = getDefualtAdapter(); ++ qDebug() <<__FUNCTION__<< "======================================1"; + launchDbusSignal(); ++ qDebug() <<__FUNCTION__<< "======================================2"; ++ + }); + + reconnectFunc(); +@@ -604,8 +611,11 @@ void Daemon::monitorDbusSignal() + + void Daemon::launchDbusSignal() + { ++ qDebug() << Q_FUNC_INFO << __LINE__; + QDBusInterface interface(SERVICE,PATH,INTERFACE,QDBusConnection::sessionBus()); + interface.call("connectSignal"); ++ qDebug() << Q_FUNC_INFO << "end"; ++ + } + + void Daemon::reconnectFunc() +@@ -616,6 +626,11 @@ void Daemon::reconnectFunc() + qInfo() << "reconnect dev list" << target_list; + qDebug() << Q_FUNC_INFO << target_list; + foreach (QString dev_address, target_list) { ++ if (nullptr == _DefualtAdapter) ++ { ++ qInfo() << Q_FUNC_INFO << "_DefualtAdapter is null!!"; ++ return ; ++ } + BluezQt::DevicePtr dev = _DefualtAdapter->deviceForAddress(dev_address); + + if (dev != nullptr) { +Index: ukui-bluetooth/service/sessiondbusregister.cpp +=================================================================== +--- ukui-bluetooth.orig/service/sessiondbusregister.cpp ++++ ukui-bluetooth/service/sessiondbusregister.cpp +@@ -479,7 +479,17 @@ void SessionDbusRegister::openBluetoothS + void SessionDbusRegister::connectSignal() + { + qDebug() << Q_FUNC_INFO ; ++ if (nullptr == Daemon::_BluezManager) ++ { ++ qDebug() << Q_FUNC_INFO << "btManaher is null!" ; ++ return; ++ } + ++ if (nullptr == Daemon::_DefualtAdapter) ++ { ++ qDebug() << Q_FUNC_INFO << "_DefualtAdapter is null!" ; ++ return; ++ } + connect(Daemon::_BluezManager,&BluezQt::Manager::adapterAdded,this,[=](BluezQt::AdapterPtr adapter){ + qDebug() << Q_FUNC_INFO << "adapterAdded" << __LINE__; + emit adapterAddSignal(adapter.data()->address()); +Index: ukui-bluetooth/ukui-bluetooth/daemon/bluetoothdbus.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ ukui-bluetooth/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -297,7 +297,7 @@ void BluetoothDbus::getDefaultAdapterPow + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "getDefaultAdapterPower"); +- QDBusMessage response = QDBusConnection::sessionBus().call(m, QDBus::NoBlock); ++ QDBusMessage response = QDBusConnection::sessionBus().call(m); + if (response.type() == QDBusMessage::ReplyMessage) + { + powered = response.arguments().takeFirst().toBool(); +Index: ukui-bluetooth/ukui-bluetooth/daemon/bluetoothdbus.h +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/daemon/bluetoothdbus.h ++++ ukui-bluetooth/ukui-bluetooth/daemon/bluetoothdbus.h +@@ -90,7 +90,7 @@ signals: + private: + void connectDBusSignals(); + void addNewPairedDevice(QString address); +- bool powered; ++ bool powered = false; + QMap pairedDevice; + QMap connectedDevice; + diff --git a/patches/fix_bluetooth_show_bug.patch b/patches/fix_bluetooth_show_bug.patch new file mode 100644 index 0000000..382e1bd --- /dev/null +++ b/patches/fix_bluetooth_show_bug.patch @@ -0,0 +1,110 @@ +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -316,17 +316,17 @@ void BlueToothMain::monitorBluetoothDbus + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, +- "devNameChangedSignal",this, SLOT(reportDevNameChangedSignal(QString,QString)));//设备mac地址+设备名称 ++ "devNameChangedSignal",this, SLOT(reportDevNameChangedSignal(QString,QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, +- "devTypeChangedSignal",this, SLOT(reportDevTypeChangedSignal(QString,QString)));//设备mac地址+设备类型 ++ "devTypeChangedSignal",this, SLOT(reportDevTypeChangedSignal(QString,QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, +- "devStatusChange",this, SLOT(reportDevStatusChange(QString)));//设备mac地址+设备状态 ++ "devStatusChange",this, SLOT(reportDevStatusChange(QString))); + + } + +@@ -1581,7 +1581,11 @@ void BlueToothMain::showBluetoothErrorMa + errorWidgetTip0->setFont(QFont("Noto Sans CJK SC",18,QFont::Bold)); + + if (QIcon::hasThemeIcon("dialog-warning")) { +- errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56)); ++ ++ if (isblack) ++ errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56),"white")); ++ else ++ errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56)); + } + + errorWidgetTip0->setText(tr("No Bluetooth adapter detected!")); +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothnamelabel.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothnamelabel.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothnamelabel.cpp +@@ -5,8 +5,6 @@ + BluetoothNameLabel::BluetoothNameLabel(QWidget *parent, int x, int y): + QWidget(parent) + { +-// qDebug() << Q_FUNC_INFO << x << y; +- + this->setAutoFillBackground(true); + this->setObjectName("BluetoothNameLabel"); + this->setStyleSheet("QWidget{border: none;border-radius:2px;}"); +@@ -38,10 +36,15 @@ BluetoothNameLabel::BluetoothNameLabel(Q + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + settings = new QGSettings("org.ukui.style"); + if(settings->get("style-name").toString() == "ukui-black" || settings->get("style-name").toString() == "ukui-dark") ++ { + style_flag = true; ++ icon_pencil->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20),"white")); ++ } + else ++ { + style_flag = false; +- ++ icon_pencil->setPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20)); ++ } + switch (settings->get("systemFontSize").toInt()) { + case 11: + case 12: +@@ -187,9 +190,15 @@ void BluetoothNameLabel::settings_change + qDebug() << Q_FUNC_INFO <get("style-name").toString() == "ukui-black" || settings->get("style-name").toString() == "ukui-dark") ++ { + style_flag = true; ++ icon_pencil->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20),"white")); ++ } + else ++ { + style_flag = false; ++ icon_pencil->setPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20)); ++ } + }else if(key == "systemFontSize"){ + QFont ft; + ft.setPixelSize(settings->get("systemFontSize").toInt()); +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothnamelabel.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothnamelabel.h ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothnamelabel.h +@@ -14,6 +14,7 @@ + #include + #include + #include ++#include + + #define DEVNAMELENGTH 30 + +Index: ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/deviceinfoitem.cpp ++++ ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +@@ -453,7 +453,8 @@ QColor DeviceInfoItem::getPainterBrushCo + case Status::Nomal: + + if(_themeIsBlack) +- color = QColor("#1F2022");//("#EBEBEB"); ++ //color = QColor("#1F2022");//("#EBEBEB"); ++ color = QColor(Qt::black);//("#EBEBEB"); + else + color = QColor(Qt::white);//("#EBEBEB"); + diff --git a/patches/fix_bluetooth_style.patch b/patches/fix_bluetooth_style.patch new file mode 100644 index 0000000..9665f5f --- /dev/null +++ b/patches/fix_bluetooth_style.patch @@ -0,0 +1,22 @@ +Index: ukui-bluetooth/ukui-bluetooth/component/bluetoothsettinglabel.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/component/bluetoothsettinglabel.cpp ++++ ukui-bluetooth/ukui-bluetooth/component/bluetoothsettinglabel.cpp +@@ -64,7 +64,8 @@ QColor BluetoothSettingLabel::getPainter + + void BluetoothSettingLabel::enterEvent(QEvent *event) { + Q_UNUSED(event); +- _MStatus = Hover; ++ //_MStatus = Hover; ++ _MStatus = Normal; + this->update(); + } + +@@ -101,6 +102,7 @@ void BluetoothSettingLabel::paintEvent(Q + painter.setPen(QColor(Qt::transparent)); + painter.setBrush(getPainterBrushColor()); + painter.drawRoundedRect(this->rect(),12,12,Qt::AbsoluteSize); ++ //painter.drawRect(this->rect()); + painter.restore(); + if(StyleSettings->get("style-name").toString() == "ukui-light") + painter.setPen(QColor(Qt::black)); diff --git a/patches/fix_bluetooth_ukcc_crash.patch b/patches/fix_bluetooth_ukcc_crash.patch new file mode 100644 index 0000000..859a548 --- /dev/null +++ b/patches/fix_bluetooth_ukcc_crash.patch @@ -0,0 +1,584 @@ +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -174,6 +174,10 @@ void rfkill_exit(void) + watch = 0; + } + ++const QString SERVICE = "com.ukui.bluetooth"; ++const QString PATH = "/com/ukui/bluetooth"; ++const QString INTERFACE = "com.ukui.bluetooth"; ++ + //dev-3.1 界面服务-分离 + BlueToothMain::BlueToothMain(QWidget *parent) + : QMainWindow(parent) +@@ -204,7 +208,7 @@ BlueToothMain::BlueToothMain(QWidget *pa + } + + //手动发起蓝牙服务连接 +- connectBluetoothServiceSignal(); ++ //connectBluetoothServiceSignal(); + + getAllAdapterData(); + +@@ -227,6 +231,7 @@ BlueToothMain::BlueToothMain(QWidget *pa + // } + + monitorBluetoothDbusConnection(); ++ monitorSleepSignal(); + return ; + } + +@@ -254,73 +259,73 @@ void BlueToothMain::monitorBluetoothDbus + // const QString &name, QObject *receiver, const char *slot); + //1.适配器数据上报 + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "defaultAdapterChanged",this, SLOT(reportDefaultAdapterChanged(QString))); + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "defaultAdapterNameChanged",this, SLOT(reportDefaultAdapterNameChanged(QString))); + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "adapterAddSignal",this, SLOT(reportAdapterAddSignal(QString))); +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "adapterRemoveSignal",this, SLOT(reportAdapterRemoveSignal(QString))); + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "defaultAdapterPowerChanged",this, SLOT(reportDefaultAdapterPowerChanged(bool))); +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "defaultDiscoverableChanged",this, SLOT(reportDefaultDiscoverableChanged(bool))); + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "defaultScanStatusChanged",this, SLOT(reportDefaultScanStatusChanged(bool))); + + //2.蓝牙设备数据上报 +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "deviceScanResult",this, SLOT(reportDeviceScanResult(QString,QString))); + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "devPairSignal",this, SLOT(reportDevPairSignal(QString,bool))); + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "devConnectStatusSignal",this, SLOT(reportDevConnectStatusSignal(QString,bool))); + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "devRemoveSignal",this, SLOT(reportDevRemoveSignal(QString))); + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "devNameChangedSignal",this, SLOT(reportDevNameChangedSignal(QString,QString)));//设备mac地址+设备名称 + +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", +- "devTypeChangedSignal",this, SLOT(reportDevTypeChange(QString,QString)));//设备mac地址+设备类型 +- +- QDBusConnection::sessionBus().connect("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, ++ "devTypeChangedSignal",this, SLOT(reportDevTypeChangedSignal(QString,QString)));//设备mac地址+设备类型 ++ ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, + "devStatusChange",this, SLOT(reportDevStatusChange(QString)));//设备mac地址+设备状态 + + } +@@ -429,6 +434,7 @@ void BlueToothMain::refreshBluetoothAdap + if(1 == m_adapter_address_list.size())// || + //(m_adapter_address_list.size() > 0 && m_adapter_address_list.size() != m_adapter_name_list.size())) + { ++ m_default_bluetooth_adapter = m_bluetooth_adapter_list.at(0); + if("normalWidget" != this->centralWidget()->objectName()) + { + showBluetoothNormalMainWindow(); +@@ -436,7 +442,7 @@ void BlueToothMain::refreshBluetoothAdap + if(frame_2->isVisible()) + frame_2->setVisible(false); + frame_top->setMinimumSize(582,187); +- frame_top->setMaximumSize(1000,187); ++ frame_top->setMaximumSize(1800,187); + } + else if (m_adapter_address_list.size() > 1) + { +@@ -447,7 +453,7 @@ void BlueToothMain::refreshBluetoothAdap + if(!frame_2->isVisible()) + frame_2->setVisible(true); + frame_top->setMinimumSize(582,239); +- frame_top->setMaximumSize(1000,239); ++ frame_top->setMaximumSize(1800,239); + } + else + { +@@ -457,6 +463,7 @@ void BlueToothMain::refreshBluetoothAdap + } + } + ++ refreshUIWhenAdapterChanged(); + } + + void BlueToothMain::addAdapterDataList(QString adapterAddress) +@@ -856,9 +863,9 @@ void BlueToothMain::getDefaultAdapterDat + void BlueToothMain::connectBluetoothServiceSignal() + { + qDebug () << Q_FUNC_INFO << __LINE__; +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + iface.setTimeout(20); + iface.call("connectSignal"); +@@ -914,9 +921,9 @@ void BlueToothMain::getAllAdapterData() + bool BlueToothMain::getBluetoothBlock() + { + qDebug () << Q_FUNC_INFO << __LINE__; +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -929,9 +936,9 @@ QString BlueToothMain::getDefaultAdapter + { + qDebug () << Q_FUNC_INFO << __LINE__; + +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -944,9 +951,9 @@ QStringList BlueToothMain::getAdapterDev + { + qDebug () << Q_FUNC_INFO << __LINE__; + +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -973,9 +980,9 @@ QString BlueToothMain::getAdapterName(QS + { + qDebug () << Q_FUNC_INFO << __LINE__; + +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -988,9 +995,9 @@ bool BlueToothMain::getDefaultAdapterPow + { + qDebug () << Q_FUNC_INFO << __LINE__; + +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 ms + iface.setTimeout(20); +@@ -1003,12 +1010,12 @@ QStringList BlueToothMain::getDefaultAda + { + qDebug () << Q_FUNC_INFO << __LINE__; + +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间, ms +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getDefaultAdapterCacheDevAddress"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -1018,9 +1025,9 @@ bool BlueToothMain::getDefaultAdapterDis + { + qDebug () << Q_FUNC_INFO << __LINE__; + +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -1032,9 +1039,9 @@ bool BlueToothMain::getDefaultAdapterDis + bool BlueToothMain::getDefaultAdapterScanStatus() + { + qDebug () << Q_FUNC_INFO << __LINE__; +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -1047,9 +1054,9 @@ bool BlueToothMain::getDefaultAdapterSca + QString BlueToothMain::getDevName(QString deviceAddress) + { + qDebug () << Q_FUNC_INFO << __LINE__; +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -1061,9 +1068,9 @@ QString BlueToothMain::getDevName(QStrin + bool BlueToothMain::getDevPairStatus(QString deviceAddress) + { + qDebug () << Q_FUNC_INFO << __LINE__; +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -1074,9 +1081,9 @@ bool BlueToothMain::getDevPairStatus(QSt + bool BlueToothMain::getDevConnectStatus(QString deviceAddress) + { + qDebug () << Q_FUNC_INFO << __LINE__; +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -1087,25 +1094,25 @@ bool BlueToothMain::getDevConnectStatus( + + bluetoothdevice::DEVICE_TYPE BlueToothMain::getDeviceType(QString deviceAddress , QString devType) + { +- //qDebug () << Q_FUNC_INFO << __LINE__; ++ qDebug () << Q_FUNC_INFO << __LINE__; + QString dev_type_str = devType ; + if (dev_type_str.isEmpty()) + dev_type_str = getDevType(deviceAddress); + +- //qDebug() << Q_FUNC_INFO << "Type:" << dev_type_str << __LINE__; ++ qDebug() << Q_FUNC_INFO << "Type:" << dev_type_str << __LINE__; + QByteArray enum_str_to_char = dev_type_str.toLatin1(); + const char * enum_char = enum_str_to_char.data(); + QMetaEnum metaEnum = QMetaEnum::fromType(); +- //qDebug() << Q_FUNC_INFO << "enum index:" << metaEnum.keysToValue(enum_char); ++ qDebug() << Q_FUNC_INFO << "enum index:" << metaEnum.keysToValue(enum_char); + + return (metaEnum.keysToValue(enum_char) == -1 ? bluetoothdevice::DEVICE_TYPE::uncategorized : bluetoothdevice::DEVICE_TYPE(metaEnum.keysToValue(enum_char))); + } + QString BlueToothMain::getDevType(QString deviceAddress) + { + qDebug () << Q_FUNC_INFO << __LINE__; +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(20); +@@ -1119,9 +1126,9 @@ void BlueToothMain::clearAllUnPairedDevi + { + qDebug () << Q_FUNC_INFO << __LINE__; + +- QDBusInterface iface("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusInterface iface(SERVICE, ++ PATH, ++ INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.call(QDBus::NoBlock, "clearAllUnPairedDevicelist"); +@@ -1138,9 +1145,9 @@ void BlueToothMain::setTrayVisible(bool + void BlueToothMain::setBluetoothBlock(bool value) + { + qDebug() << Q_FUNC_INFO << __LINE__; +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "setBluetoothBlock"); + m << value; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +@@ -1150,9 +1157,9 @@ void BlueToothMain::setBluetoothBlock(bo + void BlueToothMain::setDefaultAdapterName(QString adapterName) + { + qDebug() << Q_FUNC_INFO << __LINE__; +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "setDefaultAdapterName");//setBluetoothName + m << adapterName; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +@@ -1164,9 +1171,9 @@ void BlueToothMain::setDefaultAdapterNam + void BlueToothMain::setDefaultAdapterPower(bool value) + { + qDebug() << Q_FUNC_INFO << __LINE__; +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "setDefaultAdapterPower"); + m << value; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +@@ -1177,9 +1184,9 @@ void BlueToothMain::setDefaultAdapterPow + void BlueToothMain::setDefaultAdapterDiscoverable(bool value) + { + qDebug() << Q_FUNC_INFO << __LINE__; +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "setDefaultAdapterDiscoverable"); + m << value; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +@@ -1190,9 +1197,9 @@ void BlueToothMain::setDefaultAdapterDis + void BlueToothMain::setDefaultAdapterScanOn(bool value) + { + qDebug() << Q_FUNC_INFO << __LINE__; +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "setDefaultAdapterScanOn"); + m << value; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +@@ -1205,9 +1212,9 @@ void BlueToothMain::receiveConnectsignal + //停止扫描,连接完成或连接超时后继续开启扫描 + setDefaultAdapterScanOn(false); + qDebug() << Q_FUNC_INFO << __LINE__; +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "devConnect"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +@@ -1218,9 +1225,9 @@ void BlueToothMain::receiveConnectsignal + void BlueToothMain::receiveDisConnectSignal(QString address) + { + qDebug() << Q_FUNC_INFO << __LINE__; +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "devDisconnect"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +@@ -1231,9 +1238,9 @@ void BlueToothMain::receiveDisConnectSig + void BlueToothMain::receiveRemoveSignal(QString address) + { + qDebug() << Q_FUNC_INFO << __LINE__; +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "devRemove"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +@@ -1246,34 +1253,15 @@ void BlueToothMain::receiveRemoveSignal( + void BlueToothMain::receiveSendFileSignal(QString address) + { + qDebug() << Q_FUNC_INFO << address; +-/* +- QDBusMessage m = QDBusMessage::createSignal("/com/ukui/bluetooth", +- "com.ukui.bluetooth", +- "setSendTransferDeviceMesg"); +-// QList arg; +-// arg.append(address); +- // m.setArguments(arg); +-// qDebug() << QDBusConnection::sessionBus().send(m); +- qDebug() << Q_FUNC_INFO << __LINE__; +-*/ +- QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +- "/com/ukui/bluetooth", +- "com.ukui.bluetooth", ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, + "setSendTransferDeviceMesg"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + +- +-// QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", +-// "/com/ukui/bluetooth", +-// "com.ukui.bluetooth", +-// "sendTransferDeviceMesg"); +-// m << address; +-// qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; +-// // 发送Message +-// QDBusMessage response = QDBusConnection::sessionBus().call(m); + } + + void BlueToothMain::showBluetoothNormalMainWindow() +@@ -1517,10 +1505,15 @@ void BlueToothMain::initMainWindowbottom + { + delayStartDiscover_timer->stop(); + setDefaultAdapterScanOn(true); +- if (!m_current_adapter_power_swtich) ++ ++ QTimer::singleShot(500,this,[=] + { +- delayStartDiscover_timer->start(); +- } ++ if (!m_current_adapter_scan_status) ++ { ++ delayStartDiscover_timer->start(); ++ } ++ }); ++ + }); + + title_layout->addWidget(label_1); +@@ -1560,12 +1553,14 @@ void BlueToothMain::initMainWindowbottom + + frame_bottom->setLayout(bottom_layout); + } ++ + void BlueToothMain::stopAllTimer() + { + qDebug() << Q_FUNC_INFO << __LINE__; + if (delayStartDiscover_timer && delayStartDiscover_timer->isActive()) + delayStartDiscover_timer->stop(); + } ++ + void BlueToothMain::showBluetoothErrorMainWindow() + { + qDebug() << Q_FUNC_INFO << __LINE__; +@@ -1605,6 +1600,10 @@ void BlueToothMain::showBluetoothErrorMa + void BlueToothMain::refreshUIWhenAdapterChanged() + { + qDebug() << Q_FUNC_INFO << __LINE__; ++ if("normalWidget" != this->centralWidget()->objectName()) ++ { ++ return; ++ } + + // =============清空我的设备和蓝牙发现设备栏布局下的所有设备item================= + cleanPairDevices(); +@@ -1874,6 +1873,7 @@ void BlueToothMain::monitorSleepSignal() + + void BlueToothMain::monitorSleepSlot(bool value) + { ++ //connectBluetoothServiceSignal(); + if (!value) { + if (sleep_status) + { diff --git a/patches/fix_bug101672and102290.patch b/patches/fix_bug101672and102290.patch new file mode 100644 index 0000000..b93bf8b --- /dev/null +++ b/patches/fix_bug101672and102290.patch @@ -0,0 +1,87 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 9cafd28..94b8bb9 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -773,7 +773,14 @@ void SessionDbusRegister::connectSignal() + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::deviceAdded,this,[=](BluezQt::DevicePtr devPtr){ + // qInfo() << Q_FUNC_INFO << "deviceAdded:" << devPtr->address() << ";line = "<< __LINE__ ; +- emit deviceScanResult(devPtr.data()->address(),devPtr.data()->name(),BluezQt::Device::typeToString(devPtr.data()->type())); ++ ++ //设备类型正常,才发送信号 ++ if(devPtr->type() != BluezQt::Device::Type::Uncategorized) ++ { ++ emit deviceScanResult(devPtr.data()->address(),devPtr.data()->name(), ++ BluezQt::Device::typeToString(devPtr.data()->type())); ++ } ++ + + //清空信号,防止重复连接 + devPtr->disconnect(); +@@ -835,7 +842,24 @@ void SessionDbusRegister::connectSignal() + + connect(devPtr.data(),&BluezQt::Device::typeChanged,this,[=](BluezQt::Device::Type type){ + qDebug() << Q_FUNC_INFO << "typeChanged" << devPtr.data()->address(); +- emit devTypeChangedSignal(devPtr.data()->address(),BluezQt::Device::typeToString(devPtr.data()->type())); ++ ++ //设备类型正常,才发送信号 ++ if(devPtr->type() != BluezQt::Device::Type::Uncategorized) ++ { ++ emit deviceScanResult(devPtr->address(),devPtr->name(), ++ BluezQt::Device::typeToString(devPtr->type())); ++ ++ QTimer::singleShot(500, this, [=] ++ { ++ emit devTypeChangedSignal(devPtr->address(),BluezQt::Device::typeToString(devPtr->type())); ++ }); ++ } ++ //无蓝牙设备类型,删除设备 ++ else ++ { ++ emit devRemoveSignal(devPtr->address()); ++ } ++ + }); + + connect(devPtr.data(),&BluezQt::Device::nameChanged,this,[=](const QString &name){ +@@ -916,7 +940,23 @@ void SessionDbusRegister::connectSignal() + + connect(dev.data(),&BluezQt::Device::typeChanged,this,[=](BluezQt::Device::Type type){ + qDebug() << Q_FUNC_INFO << "typeChanged" << dev.data()->address(); +- emit devTypeChangedSignal(dev.data()->address(),BluezQt::Device::typeToString(dev.data()->type())); ++ //设备类型正常,才发送信号 ++ if(dev->type() != BluezQt::Device::Type::Uncategorized) ++ { ++ emit deviceScanResult(dev->address(),dev->name(), ++ BluezQt::Device::typeToString(dev->type())); ++ ++ QTimer::singleShot(500, this, [=] ++ { ++ emit devTypeChangedSignal(dev->address(),BluezQt::Device::typeToString(dev->type())); ++ }); ++ ++ } ++ //无蓝牙设备类型,删除设备 ++ else ++ { ++ emit devRemoveSignal(dev->address()); ++ } + }); + + connect(dev.data(),&BluezQt::Device::nameChanged,this,[=](const QString &name){ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index d85d5ec..d3b22f2 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -2240,9 +2240,9 @@ void BlueToothMain::gSettingsChanged(const QString &key) + isblack = false; + + if (isblack) +- errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56),"white")); ++ errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-disabled-symbolic").pixmap(54,88),"white")); + else +- errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56)); ++ errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-disabled-symbolic").pixmap(54,88)); + } + } + diff --git a/patches/fix_bug103413.patch b/patches/fix_bug103413.patch new file mode 100644 index 0000000..39d4b6f --- /dev/null +++ b/patches/fix_bug103413.patch @@ -0,0 +1,26 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 29eb44d..46df2f9 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -609,7 +609,7 @@ QPixmap DeviceInfoItem::getDevTypeIcon() + iconName = "phone-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::computer: +- iconName = "computer-symbolic"; ++ iconName = "video-display-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::headset: + iconName = "audio-headset-symbolic"; +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 051c296..7cb92e5 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -63,7 +63,7 @@ bool QDevItem::isHuaWei() { + void QDevItem::initMap() { + typeMap = new QMap(); + typeMap->insert(QString("phone"), QIcon::fromTheme("phone-symbolic")); +- typeMap->insert(QString("computer"), QIcon::fromTheme("computer-symbolic")); ++ typeMap->insert(QString("computer"), QIcon::fromTheme("video-display-symbolic")); + typeMap->insert(QString("headset"), QIcon::fromTheme("audio-headset-symbolic")); + typeMap->insert(QString("headphones"), QIcon::fromTheme("audio-headphones-symbolic")); + typeMap->insert(QString("audiovideo"), QIcon::fromTheme("audio-speakers-symbolic")); diff --git a/patches/fix_cannot_send_symbol_named_files.patch b/patches/fix_cannot_send_symbol_named_files.patch new file mode 100644 index 0000000..000fdba --- /dev/null +++ b/patches/fix_cannot_send_symbol_named_files.patch @@ -0,0 +1,35 @@ +diff --git a/debian/ukui-bluetooth.install b/debian/ukui-bluetooth.install +index ffb99d1..b1731a2 100644 +--- a/debian/ukui-bluetooth.install ++++ b/debian/ukui-bluetooth.install +@@ -1,4 +1,5 @@ + ukui-bluetooth/translations/*.qm /usr/share/ukui-bluetooth/translations/ ++data/ukui-bluetooth-tray.desktop /etc/xdg/autostart/ + data/ukui-bluetooth.desktop /etc/xdg/autostart/ + ukcc-bluetooth/translations/*.qm /usr/share/ukui-bluetooth/translations/ + ukcc-bluetooth/translations/*.ts /usr/share/ukui-bluetooth/translations/ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 6dc15a3..afcf30a 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -107,10 +107,10 @@ void Daemon::sendFile(QString addr,QString filename) + registerObexAgent(); + + if (isAddress(addr)) { +- selected_file = QUrl(filename).path(); ++ selected_file = filename; + qInfo() << Q_FUNC_INFO << QString("Send file : %1").arg(selected_file); + if(!selected_file.isNull()){ +- fileTransferSessionCreator(addr,selected_file); ++ fileTransferSessionCreator(addr, selected_file); + } + } else { + +@@ -341,6 +341,7 @@ void Daemon::initBluezManager() + } + + void Daemon::continueSendFiles(QString filename) { ++ qDebug() << Q_FUNC_INFO << filename << __LINE__; + BluezQt::PendingCall *transfer = opp->sendFile(filename); + qDebug() << Q_FUNC_INFO << transfer->error() << transfer->errorText(); + connect(transfer,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ diff --git a/patches/fix_change_default_adapter_traywidget_changed_nothing.patch b/patches/fix_change_default_adapter_traywidget_changed_nothing.patch new file mode 100644 index 0000000..6939f52 --- /dev/null +++ b/patches/fix_change_default_adapter_traywidget_changed_nothing.patch @@ -0,0 +1,33 @@ +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 1a3b161..1993eb3 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -79,6 +79,7 @@ void BluetoothDbus::adapterAddSignalSLot(QString address) { + + void BluetoothDbus::defaultAdapterChangedSLot(QString value) { + qDebug() << Q_FUNC_INFO << __LINE__ << value; ++ getDefaultAdapterPower(); + getDefaultAdapterPairedDevices(); + emit AdapterChangedSignal(value); + } +@@ -391,6 +392,8 @@ void BluetoothDbus::replyFileReceiving(bool v) { + + void BluetoothDbus::getDefaultAdapterPairedDevices() { + qDebug() << "get Default Adapter Paired Devices"; ++ pairedList.clear(); ++ pairedDevice.clear(); + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 6d0768d..01811fa 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -382,6 +382,7 @@ void TrayWidget::connectUISignalAndSlot() + }); + connect(_SessionDBus,&BluetoothDbus::AdapterChangedSignal,this,[=](QString address){ + Q_UNUSED(address) ++ _MBtn->setChecked(_SessionDBus->isPowered()); + updatePairedDev(); + }); + } diff --git a/patches/fix_change_system_font_size_label_doesnt_change.patch b/patches/fix_change_system_font_size_label_doesnt_change.patch new file mode 100644 index 0000000..f8df7cc --- /dev/null +++ b/patches/fix_change_system_font_size_label_doesnt_change.patch @@ -0,0 +1,60 @@ +diff --git a/ukui-bluetooth/component/bluetoothsettinglabel.cpp b/ukui-bluetooth/component/bluetoothsettinglabel.cpp +index 33ac0a3..d5387c9 100644 +--- a/ukui-bluetooth/component/bluetoothsettinglabel.cpp ++++ b/ukui-bluetooth/component/bluetoothsettinglabel.cpp +@@ -3,9 +3,7 @@ + BluetoothSettingLabel::BluetoothSettingLabel(QWidget *parent) : QLabel(parent) + { + _MStatus = Normal; +- this->setText(tr("Bluetooth Settings")); + this->setFixedSize(420,50); +- this->setStyleSheet("text-align:left"); + this->setAutoFillBackground(true); + this->setAttribute(Qt::WA_TranslucentBackground); + if(QGSettings::isSchemaInstalled("org.ukui.style")){ +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 27f069f..117379a 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -190,19 +190,21 @@ void TrayWidget::GSettingsChanges(const QString &key) + if(key == "styleName"){ + QPalette palette; + QPalette pl; ++ QPalette _pl; + getTransparency(); + if(StyleSettings->get("style-name").toString() == "ukui-light"){ +- _MLabel->setStyleSheet("color:black;"); ++ _pl.setColor(QPalette::WindowText,Qt::black); + palette.setColor(QPalette::Background,QColor(255,255,255,0)); + pl.setColor(QPalette::WindowText, QColor(0,0,0,20)); + }else{ +- _MLabel->setStyleSheet("color:white;"); + QColor col(QPalette::Base); + col.setAlpha(tran); ++ _pl.setColor(QPalette::WindowText,Qt::white); + palette.setColor(QPalette::Background, col); + pl.setColor(QPalette::WindowText, QColor(255,255,255,50)); + } + this->setPalette(palette); ++ _MLabel->setPalette(_pl); + lineFrame->setPalette(pl); + lineFrame2->setPalette(pl); + this->update(); +@@ -240,12 +242,14 @@ void TrayWidget::InitMemberVariables() + _MStackedWidget->setCurrentIndex(0); + + _MLabel->resize(60,32); +- _MLabel->setText(tr("Bluetooth")); ++ QPalette _pl; + if(StyleSettings->get("style-name").toString() == "ukui-light"){ +- _MLabel->setStyleSheet("color:black;"); ++ _pl.setColor(QPalette::WindowText, Qt::black); + }else{ +- _MLabel->setStyleSheet("color:white;"); ++ _pl.setColor(QPalette::WindowText, Qt::white); + } ++ _MLabel->setPalette(_pl); ++ _MLabel->setText(tr("Bluetooth")); + + _MMainLayout->setMargin(0); + _MMainLayout->setContentsMargins(0,0,0,0); diff --git a/patches/fix_chzn_show_and_tooltip_problem.patch b/patches/fix_chzn_show_and_tooltip_problem.patch new file mode 100644 index 0000000..4b2c962 --- /dev/null +++ b/patches/fix_chzn_show_and_tooltip_problem.patch @@ -0,0 +1,88 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 92b02e3..eb99fb2 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -24,7 +24,6 @@ QDevItem::QDevItem(QString address, QStringList deviceinfo, bool connected, QWid + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + } + +- this->setToolTip(_Name); + this->setFixedSize(404,50); + this->setObjectName(address); + _MStatus = Status::Nomal; +@@ -280,10 +279,25 @@ void QDevItem::DrawText(QPainter &painter) + fontSize = 15; + if (fontSize < 10) + fontSize = 10; +- if (_Name.size() > FontTable[fontSize - 10]) { +- nName.remove(FontTable[fontSize - 10], _Name.size() - FontTable[fontSize - 10]); +- nName.append("..."); ++ float shownum = 0; ++ for (int i = 0; i < _Name.size(); i++) { ++ QChar ch = _Name.at(i); ++ ushort uNum = ch.unicode(); ++ if ((uNum >= 0x4E00 && uNum <= 0x9FA5)) ++ shownum += 1.7; ++ else if (ch == 'm' || ch == 'M') ++ shownum += 1.5; ++ else ++ shownum += 1; ++ if (shownum + 1.5 >= FontTable[fontSize - 10]) { ++ nName.remove(i, _Name.size() - i); ++ nName.append("..."); ++ this->setToolTip(_Name); ++ break; ++ } ++ qDebug() << "======================" << shownum << i; + } ++ + painter.drawText(62,12,260,28,Qt::AlignLeft, nName); + painter.restore(); + } +diff --git a/ukui-bluetooth/component/qdevitem.h b/ukui-bluetooth/component/qdevitem.h +index c26d063..c5d3b4d 100644 +--- a/ukui-bluetooth/component/qdevitem.h ++++ b/ukui-bluetooth/component/qdevitem.h +@@ -38,7 +38,6 @@ public: + int FontTable[6] = {32, 30, 26, 24, 23, 22}; + + QDevItem(QString address, QStringList deviceinfo, bool connected, QWidget *parent = nullptr); +- QDevItem(QWidget *parent); + ~QDevItem(); + const QPixmap loadSvg(const QPixmap &source, const PixmapColor &color); + +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 6fce211..8126abb 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -290,9 +290,9 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + if (dev_widget->get_seleter_dev_name().size() > 30) { + Name.remove(30, dev_widget->get_seleter_dev_name().size() - 30); + Name.append("..."); ++ tip_text->setToolTip(dev_widget->get_seleter_dev_name()); + } + tip_text->setText(tr("Transferring to \"")+Name+"\""); +- tip_text->setToolTip(dev_widget->get_seleter_dev_name()); + tip_text->update(); + + ok_btn->setVisible(false); +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index c02e4b4..c240edf 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -188,6 +188,7 @@ void PinCodeWidget::updateUIInfo(const QString &name, const QString &pin) + if (name.size() > 30) { + Name.remove(30, name.size() - 30); + Name.append("..."); ++ tip_label->setToolTip(name); + } + if(show_flag) + tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); +@@ -195,7 +196,6 @@ void PinCodeWidget::updateUIInfo(const QString &name, const QString &pin) + tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(Name); + tip_label->setText(tip_text); + tip_label->update(); +- tip_label->setToolTip(name); + + if (!this->isActiveWindow()) + this->setHidden(false); diff --git a/patches/fix_dev_name_label_size.patch b/patches/fix_dev_name_label_size.patch new file mode 100644 index 0000000..b5ce50b --- /dev/null +++ b/patches/fix_dev_name_label_size.patch @@ -0,0 +1,211 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 1f2666d..ad1ce02 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -24,6 +24,7 @@ QDevItem::QDevItem(QString address, QStringList deviceinfo, bool connected, QWid + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + } + ++ this->setToolTip(_Name); + this->setFixedSize(404,50); + this->setObjectName(address); + _MStatus = Status::Nomal; +@@ -267,12 +268,19 @@ void QDevItem::DrawStatusIcon(QPainter &painter) + *************************************************/ + void QDevItem::DrawText(QPainter &painter) + { ++ QString nName; ++ nName = _Name; + painter.save(); + if(StyleSettings->get("style-name").toString() == "ukui-light") + painter.setPen(QColor(Qt::black)); + else + painter.setPen(QColor(Qt::white)); +- painter.drawText(62,12,260,28,Qt::AlignLeft, _Name); ++ int fontSize = StyleSettings->get("system-font-size").toInt(); ++ if (_Name.size() > FontTable[fontSize - 10]) { ++ nName.remove(FontTable[fontSize - 10], _Name.size() - FontTable[fontSize - 10]); ++ nName.append("..."); ++ } ++ painter.drawText(62,12,260,28,Qt::AlignLeft, nName); + painter.restore(); + } + +diff --git a/ukui-bluetooth/component/qdevitem.h b/ukui-bluetooth/component/qdevitem.h +index 9b16211..c26d063 100644 +--- a/ukui-bluetooth/component/qdevitem.h ++++ b/ukui-bluetooth/component/qdevitem.h +@@ -35,6 +35,8 @@ public: + }; + Q_ENUM(PixmapColor) + ++ int FontTable[6] = {32, 30, 26, 24, 23, 22}; ++ + QDevItem(QString address, QStringList deviceinfo, bool connected, QWidget *parent = nullptr); + QDevItem(QWidget *parent); + ~QDevItem(); +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 6e6c1a9..6fce211 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -77,7 +77,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + font-weight: 500;\ + line-height: 24px;\ + opacity: 1;}"); +- tip_text->setGeometry(32,52,400,28); ++ tip_text->setGeometry(32,52,440,28); + tip_text->setVisible(false); + + initFileInfo(); +@@ -121,7 +121,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + + + transNum = new QLabel("1/"+QString::number(fileNums), this); +- transNum->setGeometry(459,177,22,20); ++ transNum->setGeometry(459,168,22,20); + transNum->setVisible(false); + transNum->setStyleSheet("QLabel{\ + width: 22px;\ +@@ -136,9 +136,9 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + m_progressbar = new QProgressBar(this); + m_progressbar->setOrientation(Qt::Horizontal); + if (fileNums > 1) +- m_progressbar->setGeometry(32,184,406,8); ++ m_progressbar->setGeometry(32,175,406,8); + else +- m_progressbar->setGeometry(32,184,454,8); ++ m_progressbar->setGeometry(32,175,454,8); + m_progressbar->setTextVisible(false); + m_progressbar->setVisible(false); + +@@ -284,7 +284,15 @@ void BluetoothFileTransferWidget::Get_fie_type(int i) + void BluetoothFileTransferWidget::Initialize_and_start_animation() + { + this->setFixedSize(520,276); +- tip_text->setText(tr("Transferring to \"")+dev_widget->get_seleter_dev_name()+"\""); ++ ++ ++ QString Name = dev_widget->get_seleter_dev_name(); ++ if (dev_widget->get_seleter_dev_name().size() > 30) { ++ Name.remove(30, dev_widget->get_seleter_dev_name().size() - 30); ++ Name.append("..."); ++ } ++ tip_text->setText(tr("Transferring to \"")+Name+"\""); ++ tip_text->setToolTip(dev_widget->get_seleter_dev_name()); + tip_text->update(); + + ok_btn->setVisible(false); +@@ -295,9 +303,9 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + Tiptop->setVisible(false); + dev_widget->setVisible(false); + tip_text->setVisible(true); +- target_icon->setGeometry(32,108,64,64); +- target_name->setGeometry(112,115,300,20); +- target_size->setGeometry(112,140,60,30); ++ target_icon->setGeometry(32,95,64,64); ++ target_name->setGeometry(112,102,300,20); ++ target_size->setGeometry(112,127,68,30); + + main_animation_group = new QParallelAnimationGroup(this); + +diff --git a/ukui-bluetooth/fileSend/deviceselectitem.cpp b/ukui-bluetooth/fileSend/deviceselectitem.cpp +index 925e620..8562a8a 100644 +--- a/ukui-bluetooth/fileSend/deviceselectitem.cpp ++++ b/ukui-bluetooth/fileSend/deviceselectitem.cpp +@@ -28,6 +28,7 @@ DeviceSelectItem::DeviceSelectItem(QString name, QString address, QIcon icon, QW + this->update(); + }); + } ++ this->setToolTip(MName); + } + + DeviceSelectItem::~DeviceSelectItem(){ +@@ -189,5 +190,12 @@ void DeviceSelectItem::paintEvent(QPaintEvent *) { + painter.setPen(QColor(Qt::white)); + style()->drawItemPixmap(&painter, QRect(8, 13, 24, 24), Qt::AlignCenter, loadSvg(MIcon.pixmap(24,24), PixmapColor::WHITE)); + } +- painter.drawText(40,13,280,28,Qt::AlignLeft, MName); ++ QString nName; ++ nName = MName; ++ int fontSize = StyleSettings->get("system-font-size").toInt(); ++ if (MName.size() > FontTable[fontSize - 10]) { ++ nName.remove(FontTable[fontSize - 10], MName.size() - FontTable[fontSize - 10]); ++ nName.append("..."); ++ } ++ painter.drawText(40,13,380,28,Qt::AlignLeft, nName); + } +diff --git a/ukui-bluetooth/fileSend/deviceselectitem.h b/ukui-bluetooth/fileSend/deviceselectitem.h +index 548784a..cc396be 100644 +--- a/ukui-bluetooth/fileSend/deviceselectitem.h ++++ b/ukui-bluetooth/fileSend/deviceselectitem.h +@@ -37,6 +37,7 @@ public: + BLUE, + }; + Q_ENUM(PixmapColor) ++ int FontTable[6] = {48, 44, 42, 40, 34, 32}; + private: + QIcon MIcon; + QString MName; +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index e2ae452..54a1303 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -51,13 +51,18 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + + //QString top_text = tr("Bluetooth Connect Request From \'")+dev_name+tr("\'."); + QString tip_text; ++ QString Name = dev_name; ++ if (dev_name.size() > 30) { ++ Name.remove(30, dev_name.size() - 30); ++ Name.append("..."); ++ } + if(show_flag) { + if (is_Intel) + tip_text = tr("If you want to pair with this device, please make sure the numbers below are the same with the devices."); + else +- tip_text = tr("If \'")+dev_name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); ++ tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + } else +- tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(dev_name); ++ tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(Name); + //top_label = new QLabel(top_text,this); + //top_label->setStyleSheet("QLabel{\ + // font-size: 18px;\ +@@ -73,6 +78,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + font-weight: 400;\ + line-height: 24px;}"); + tip_label->setWordWrap(true); ++ tip_label->setToolTip(dev_name); + + PIN_label = new QLabel(PINCode,this); + PIN_label->setStyleSheet("QLabel{\ +@@ -121,7 +127,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + } else { + this->setFixedSize(520,202); + PIN_label->setGeometry(32,75,207,36); +- tip_label->setGeometry(32,40,430,20); ++ tip_label->setGeometry(32,40,430,40); + //top_label->setGeometry(32,56,456,50); + accept_btn->setGeometry(392,143,96,36); + refuse_btn->setGeometry(280,143,96,36); +@@ -175,12 +181,18 @@ void PinCodeWidget::updateUIInfo(const QString &name, const QString &pin) + PIN_label->update(); + + QString tip_text; ++ QString Name = name; ++ if (name.size() > 30) { ++ Name.remove(30, name.size() - 30); ++ Name.append("..."); ++ } + if(show_flag) +- tip_text = tr("Please make sure the PIN code displayed on \'")+dev_name+tr("\' matches the number below. Please press \'Connect\'."); ++ tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + else +- tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(dev_name); ++ tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(Name); + tip_label->setText(tip_text); + tip_label->update(); ++ tip_label->setToolTip(name); + + if (!this->isActiveWindow()) + this->setHidden(false); diff --git a/patches/fix_different_gsetting_key.patch b/patches/fix_different_gsetting_key.patch new file mode 100644 index 0000000..d2197f7 --- /dev/null +++ b/patches/fix_different_gsetting_key.patch @@ -0,0 +1,13 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index adc2c9c..89d9655 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -268,7 +268,7 @@ void QDevItem::DrawStatusIcon(QPainter &painter) + painter.setPen(QColor(Qt::black)); + batteryPixmap = getDevTypeIcon(); + } else { +- if (StyleSettings->get("icon-theme-name").toString() == "ukui-classical") ++ if (StyleSettings->get("icon-theme-name").toString() == "ukui-icon-theme-classical") + batteryPixmap = getDevTypeIcon(); + else { + painter.setPen(QColor(Qt::white)); diff --git a/patches/fix_external_screen_traywidget_show_geometry.patch b/patches/fix_external_screen_traywidget_show_geometry.patch new file mode 100644 index 0000000..bbd714a --- /dev/null +++ b/patches/fix_external_screen_traywidget_show_geometry.patch @@ -0,0 +1,29 @@ +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 3b280fe..6d0768d 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -89,8 +89,9 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + connectUISignalAndSlot(); + layoutAddAllPairedDev(); + if (_Intel) { +- QDesktopWidget *deskdop = QApplication::desktop(); +- move((deskdop->width()-this->width())/2, (deskdop->height()-this->height())/2); ++ QRect availableGeometry = QApplication::screens().at(0)->geometry(); ++ qDebug() << availableGeometry.x() << availableGeometry.y(); ++ move((availableGeometry.x() + (availableGeometry.width() - width())/2), (availableGeometry.y() + (availableGeometry.height() - height())/2)); + } + emit trayIconStatusChanged(_SessionDBus->isPowered()); + _MBtn->setChecked(_SessionDBus->isPowered()); +@@ -522,8 +523,10 @@ void TrayWidget::showUI() + this->setFixedHeight(((_MBtn->isChecked()) && (count != 0) ? selfHeight : 102)); + setWidgetPosition(); + } else { +- QDesktopWidget *deskdop = QApplication::desktop(); +- move((deskdop->width() - width())/2, (deskdop->height() - height())/2); ++ QApplication::desktop()->update(); ++ QRect availableGeometry = QApplication::screens().at(0)->geometry(); ++ qDebug() << availableGeometry.x() << availableGeometry.y(); ++ move((availableGeometry.x() + (availableGeometry.width() - width())/2), (availableGeometry.y() + (availableGeometry.height() - height())/2)); + } + showNormal(); + } diff --git a/patches/fix_file_send_widget_file_num.patch b/patches/fix_file_send_widget_file_num.patch new file mode 100644 index 0000000..2e8080a --- /dev/null +++ b/patches/fix_file_send_widget_file_num.patch @@ -0,0 +1,31 @@ +Index: upstream/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ upstream/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -104,7 +104,7 @@ BluetoothFileTransferWidget::BluetoothFi + fileName = fontMetrics.elidedText("\"" + +selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1) + +"\"", Qt::ElideMiddle, 280); +- fileName.append(tr(" and ")+QString::number(fileNums - 1)+tr(" files more")); ++ fileName.append(tr(" and ")+QString::number(fileNums)+tr(" files more")); + }else + fileName = fontMetrics.elidedText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1), Qt::ElideMiddle, 280); + target_name = new QLabel(fileName,this); +@@ -291,7 +291,7 @@ void BluetoothFileTransferWidget::Initia + cancel_btn->setVisible(true); + cancel_btn->setGeometry(376, 205, 112, 56); + m_progressbar->setVisible(true); +- transNum->setVisible(fileNums - 1); ++ transNum->setVisible(fileNums); + Tiptop->setVisible(false); + dev_widget->setVisible(false); + tip_text->setVisible(true); +@@ -341,7 +341,7 @@ void BluetoothFileTransferWidget::get_tr + +selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1) + +"\"" + +tr(" and ") +- +QString::number(selectedFiles.size() - 1) ++ +QString::number(selectedFiles.size()) + +tr(" files more")); + } + else diff --git a/patches/fix_file_send_widget_may_not_pop_out.patch b/patches/fix_file_send_widget_may_not_pop_out.patch new file mode 100644 index 0000000..b58aebb --- /dev/null +++ b/patches/fix_file_send_widget_may_not_pop_out.patch @@ -0,0 +1,12 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 4cbde9f..9e78915 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -205,6 +205,7 @@ void BluetoothFileTransferWidget::initIntelLayout() { + m_progressbar->setGeometry(24,155,372,8); + else + m_progressbar->setGeometry(24,155,420,8); ++ this->activateWindow(); + } + + void BluetoothFileTransferWidget::initFileInfo() { diff --git a/patches/fix_filesend_widget_file_name_label_height.patch b/patches/fix_filesend_widget_file_name_label_height.patch new file mode 100644 index 0000000..d33ed7c --- /dev/null +++ b/patches/fix_filesend_widget_file_name_label_height.patch @@ -0,0 +1,59 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 84ac4c6..5d94f9b 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -156,10 +156,10 @@ void BluetoothFileTransferWidget::initLayout() { + ok_btn->setGeometry(392,560,100,36); + dev_widget->setGeometry(32,175,456,356); + Tiptop->setGeometry(32,144,100,20); +- target_size->setGeometry(112,88,70,30); ++ target_size->setGeometry(112,88,88,30); + tip_text->setGeometry(32,52,452,56); + target_icon->setGeometry(32,56,64,64); +- target_name->setGeometry(112,63,400,24); ++ target_name->setGeometry(112,63,400,30); + transNum->setGeometry(459,168,52,20); + if (fileNums > 1) + m_progressbar->setGeometry(32,185,406,8); +@@ -185,8 +185,8 @@ void BluetoothFileTransferWidget::initIntelLayout() { + this->setFixedSize(478,530); + cancel_btn->setFixedSize(112,56); + ok_btn->setFixedSize(112,56); +- target_name->setFixedHeight(23); +- target_size->setFixedWidth(68); ++ target_name->setFixedHeight(30); ++ target_size->setFixedWidth(88); + dev_widget->resize(430,296); + + ok_btn->setGeometry(342,450,112,56); +@@ -195,10 +195,10 @@ void BluetoothFileTransferWidget::initIntelLayout() { + tranfer_status_icon->setGeometry(32,35,22,22); + dev_widget->setGeometry(24,139,430,296); + Tiptop->setGeometry(32,111,100,20); +- target_size->setGeometry(104,60,70,30); ++ target_size->setGeometry(104,60,88,30); + tip_text->setGeometry(24,24,430,56); + target_icon->setGeometry(24,24,64,64); +- target_name->setGeometry(104,28,400,24); ++ target_name->setGeometry(104,28,400,30); + transNum->setGeometry(410,148,52,20); + if (fileNums > 1) + m_progressbar->setGeometry(24,155,372,8); +@@ -302,13 +302,13 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + if (is_Intel) { + cancel_btn->setGeometry(342, 200, 112, 56); + target_icon->setGeometry(24,67,64,64); +- target_name->setGeometry(104,71,400,20); +- target_size->setGeometry(104,103,68,30); ++ target_name->setGeometry(104,71,400,30); ++ target_size->setGeometry(104,103,88,30); + } else { + cancel_btn->setGeometry(376, 213, 100, 36); + target_icon->setGeometry(32,105,64,64); +- target_name->setGeometry(112,112,400,20); +- target_size->setGeometry(112,137,68,30); ++ target_name->setGeometry(112,112,400,30); ++ target_size->setGeometry(112,137,88,30); + } + + main_animation_group = new QParallelAnimationGroup(this); diff --git a/patches/fix_first_connect_wont_pop_out_hint_window.patch b/patches/fix_first_connect_wont_pop_out_hint_window.patch new file mode 100644 index 0000000..56b0a23 --- /dev/null +++ b/patches/fix_first_connect_wont_pop_out_hint_window.patch @@ -0,0 +1,472 @@ +diff --git a/debian/ukui-bluetooth.install b/debian/ukui-bluetooth.install +index ffb99d1..b1731a2 100644 +--- a/debian/ukui-bluetooth.install ++++ b/debian/ukui-bluetooth.install +@@ -1,4 +1,5 @@ + ukui-bluetooth/translations/*.qm /usr/share/ukui-bluetooth/translations/ ++data/ukui-bluetooth-tray.desktop /etc/xdg/autostart/ + data/ukui-bluetooth.desktop /etc/xdg/autostart/ + ukcc-bluetooth/translations/*.qm /usr/share/ukui-bluetooth/translations/ + ukcc-bluetooth/translations/*.ts /usr/share/ukui-bluetooth/translations/ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 22fdc0e..e4d0c0a 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -64,10 +64,12 @@ void QDevItem::SendMessage(bool connected) + } + + void QDevItem::connectedChangedSlot(bool connected) { ++ qDebug() << Q_FUNC_INFO << connected; + if (_iconTimer->isActive()) + _iconTimer->stop(); + if (_Connected == connected) + return; ++ qDebug() << Q_FUNC_INFO << __LINE__; + _Connected = connected; + _clicked = false; + update(); +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 13c0afb..da0aafc 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -68,11 +68,11 @@ void BluetoothDbus::adapterRemoveSignalSLot(QString address) { + } + qDebug() << Q_FUNC_INFO << __LINE__ << _response1.arguments().takeFirst().toStringList(); + } +- emit adapterRemoveSignal(address); + } + + void BluetoothDbus::adapterAddSignalSLot(QString address) { + qDebug() << Q_FUNC_INFO << __LINE__ << address; ++ getDefaultAdapterPairedDevices(); + emit showTrayIcon(true); + emit adapterAddSignal(address); + } +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index a207d61..dfd12ca 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -27,7 +27,7 @@ MainProgram::MainProgram(bool intel, QObject *parent) : + connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired) { + Q_UNUSED(_name); + Q_UNUSED(paired); +- UI->updatePairedDev(); ++ UI->layoutAddOnePairedDev(_name, paired); + }); + connect(_sessionDbus, &BluetoothDbus::devNameChangedSignal, this, [=]() { + UI->updatePairedDev(); +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 3bfe09d..55e1b04 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -28,6 +28,8 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + }); + connect(_SessionDBus, &BluetoothDbus::showTrayIcon, this, [=](bool show) { + trayicon->SetAdapterFlag(show); ++ if (!show) ++ this->setVisible(show); + }); + setProperty("useSystemStyleBlur", true); + this->setAttribute(Qt::WA_TranslucentBackground); +@@ -85,7 +87,7 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + pairedList = _SessionDBus->getPairedDevicesList(); + InitMemberVariables(); + connectUISignalAndSlot(); +- layoutAddPairedDev(); ++ layoutAddAllPairedDev(); + if (_Intel) { + QDesktopWidget *deskdop = QApplication::desktop(); + move((deskdop->width()-this->width())/2, (deskdop->height()-this->height())/2); +@@ -365,6 +367,7 @@ void TrayWidget::InitErrorWidget() + void TrayWidget::connectUISignalAndSlot() + { + connect(_SessionDBus,&BluetoothDbus::devRemoveSignal,this,&TrayWidget::removePairedDevUIByAddress); ++ connect(_SessionDBus,&BluetoothDbus::adapterAddSignal,this,&TrayWidget::updatePairedDev); + connect(_SessionDBus,&BluetoothDbus::powerChangedSignal,this,[=](bool value){ + qDebug() << Q_FUNC_INFO << value <<__LINE__; + if (!_Intel) +@@ -373,6 +376,8 @@ void TrayWidget::connectUISignalAndSlot() + _MBtn->setChecked(value); + _config.gsetting->set("switch",QVariant::fromValue(value)); + emit trayIconStatusChanged(value); ++ _SessionDBus->getDefaultAdapterPairedDevices(); ++ updatePairedDev(); + }); + connect(_SessionDBus,&BluetoothDbus::AdapterChangedSignal,this,[=](QString address){ + Q_UNUSED(address) +@@ -380,16 +385,28 @@ void TrayWidget::connectUISignalAndSlot() + }); + } + ++void TrayWidget::SendMessage(QString name, bool connected) ++{ ++ QString text; ++ if (connected) { ++ text = QString(tr("The connection with the Bluetooth device “%1” is successful!").arg(name)); ++ ++ } else { ++ text = QString(tr("Bluetooth device “%1” disconnected!").arg(name)); ++ } ++ Config::SendNotifyMessage(text); ++} ++ + /************************************************ + * @brief 已配对的设备添加到布局中显示 + * @param null + * @return null + *************************************************/ +-void TrayWidget::layoutAddPairedDev() ++void TrayWidget::layoutAddAllPairedDev() + { + bool isNull = true; + int count = 0; +- qDebug() << Q_FUNC_INFO << pairedDevices.size() << __LINE__; ++ qDebug() << Q_FUNC_INFO << pairedDevices.size() << __LINE__ << pairedDevices; + if (!_PairedWidget->findChildren().size()) { + for (auto item : pairedList) { + QString name = pairedDevices.value(item).at(0); +@@ -428,11 +445,18 @@ void TrayWidget::layoutAddPairedDev() + } + } + ++void TrayWidget::layoutAddOnePairedDev(QString name, bool paired) ++{ ++ updatePairedDev(); ++ if (paired) ++ SendMessage(name, paired); ++} ++ + void TrayWidget::updatePairedDev() { + pairedDevices = _SessionDBus->getPairedDevices(); + pairedList = _SessionDBus->getPairedDevicesList(); + clearPairedWidget(); +- layoutAddPairedDev(); ++ layoutAddAllPairedDev(); + } + + /************************************************ +diff --git a/ukui-bluetooth/mainwidget/traywidget.h b/ukui-bluetooth/mainwidget/traywidget.h +index 3de9ae7..6a0da66 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.h ++++ b/ukui-bluetooth/mainwidget/traywidget.h +@@ -41,6 +41,7 @@ public: + void connectUISignalAndSlot(); + void setBluetoothOpen(bool v); + void updatePairedDev(); ++ void layoutAddOnePairedDev(QString name, bool paired); + void setWidgetPosition(); + + public slots: +@@ -50,13 +51,14 @@ public slots: + private slots: + void openBluetoothSlot(bool); + void removePairedDevUIByAddress(QString address); +- void layoutAddPairedDev(); ++ void layoutAddAllPairedDev(); + + private: + void InitNomalWidget(); + void InitErrorWidget(); + void clearPairedWidget(); + void getTransparency(); ++ void SendMessage(QString name, bool connected); + + TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent = nullptr); + static TrayWidget* _MSelf; +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm +index 5c2dd0a..6987182 100644 +Binary files a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm and b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm differ +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +index 482ff61..3269ed2 100644 +--- a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts ++++ b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +@@ -5,60 +5,60 @@ + BluetoothFileTransferWidget + + +- ++ + Bluetooth file transfer + 蓝牙文件 + + + +- ++ + Transferring to " + 发送文件至 " + + +- +- +- ++ ++ ++ + and + + + +- +- +- ++ ++ ++ + files more + 个文件 + + +- ++ + Select Device + 选择设备 + + +- +- +- ++ ++ ++ + OK + 确定 + + +- ++ + Cancel + 取消 + + +- ++ + File Transmission Failed ! + 文件发送失败! + + +- +- ++ ++ + File Transmition Succeed! + 文件发送成功! + + +- ++ + Close + 关闭 + +@@ -102,71 +102,71 @@ + 蓝牙文件传输 + + +- ++ + Bluetooth File + 蓝牙文件 + + +- +- +- +- +- ++ ++ ++ ++ ++ + File from " + 文件来自 " + + +- ++ + ", waiting for receive... + ",等待接收... + + +- ++ + ", waiting for receive. + ",等待接收。 + + +- ++ + Cancel + 取消 + + +- ++ + Accept + 接收 + + +- ++ + View + 查看 + + +- ++ + ", is receiving... (has recieved + ",正在接收… (已接收 + + +- ++ + files) + 个文件) + + +- ++ + ", is receiving... + ",正在接收… + + +- ++ + OK + 确定 + + +- ++ + ", received failed ! + ",接收失败! + + +- ++ + File Transmission Failed ! + 文件传输失败! + +@@ -201,61 +201,63 @@ + + + ++ + ' is the same as this PIN. Please press 'Connect' + ”上的数字与下面相同,请点击“连接” + + + +- ++ + If ' + 如果 " + + +- ++ + Refuse + 取消 + + +- ++ + Bluetooth Connections + 蓝牙连接 + + +- +- ++ ++ + Connect Failed! + 连接失败! + + + +- ++ + ' the PIN on is the same as this PIN. Please press 'Connect'. + " 上的PIN码与此PIN码相同,请按 "连接"。 + + + ++ + If the PIN on ' + 如“ + + + +- ++ + Please enter the following PIN code on the bluetooth device '%1' and press enter to pair: + 请在蓝牙设备 "%1" 上输入相同PIN,并按"Enter"确认: + + +- ++ + Confirm + 确定 + + +- ++ + Connect + 连接 + + +- +- ++ ++ + Pair + 配对 + +@@ -263,12 +265,12 @@ + + QDevItem + +- ++ + The connection with the Bluetooth device “%1” is successful! + 与蓝牙设备“%1”连接成功! + + +- ++ + Bluetooth device “%1” disconnected! + 蓝牙设备“%1”失去连接! + +@@ -297,19 +299,29 @@ + + TrayWidget + +- ++ + bluetooth + 蓝牙 + + +- ++ + Bluetooth + 蓝牙 + + +- ++ + My Device + 我的设备 + ++ ++ ++ The connection with the Bluetooth device “%1” is successful! ++ 与蓝牙设备“%1”连接成功! ++ ++ ++ ++ Bluetooth device “%1” disconnected! ++ 蓝牙设备“%1”失去连接! ++ + + diff --git a/patches/fix_first_time_connect_change_remote_device_name_segment_fault.patch b/patches/fix_first_time_connect_change_remote_device_name_segment_fault.patch new file mode 100644 index 0000000..544bd5e --- /dev/null +++ b/patches/fix_first_time_connect_change_remote_device_name_segment_fault.patch @@ -0,0 +1,15 @@ +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 43aaefa..1bda657 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -98,9 +98,8 @@ void BluetoothDbus::devNameChangedSignalSLot(QString address, QString name) { + updateList.append(name); + updateList.append(pairedDevice.value(address).at(1)); + updateList.append(pairedDevice.value(address).at(2)); +- QMap::iterator pos = pairedDevice.find(address); + pairedDevice.remove(address); +- pairedDevice.insert(pos, address, updateList); ++ pairedDevice.insert(address, updateList); + emit devNameChangedSignal(); + } + diff --git a/patches/fix_huawei_scale_problem_and_remove_dev_without_notify.patch b/patches/fix_huawei_scale_problem_and_remove_dev_without_notify.patch new file mode 100644 index 0000000..8fb1534 --- /dev/null +++ b/patches/fix_huawei_scale_problem_and_remove_dev_without_notify.patch @@ -0,0 +1,218 @@ +diff --git a/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm b/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm +index feff98a..6bcd41f 100644 +Binary files a/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm and b/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm differ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index af9532e..2f6138f 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -416,3 +416,7 @@ const QPixmap QDevItem::loadSvg(const QPixmap &source, const PixmapColor &cgColo + } + return QPixmap::fromImage(img); + } ++ ++bool QDevItem::isConnected() { ++ return _Connected; ++} +diff --git a/ukui-bluetooth/component/qdevitem.h b/ukui-bluetooth/component/qdevitem.h +index a7156d8..74d29a5 100644 +--- a/ukui-bluetooth/component/qdevitem.h ++++ b/ukui-bluetooth/component/qdevitem.h +@@ -42,6 +42,7 @@ public: + const QPixmap loadSvg(const QPixmap &source, const PixmapColor &color); + + void InitMemberVariables(); ++ bool isConnected(); + + signals: + void devConnect(bool); +diff --git a/ukui-bluetooth/config/config.cpp b/ukui-bluetooth/config/config.cpp +index 6630a99..43f8945 100644 +--- a/ukui-bluetooth/config/config.cpp ++++ b/ukui-bluetooth/config/config.cpp +@@ -33,6 +33,19 @@ void Config::SendNotifyMessage(QString message) + qDebug() << Q_FUNC_INFO << msg.errorMessage(); + } + ++bool Config::isHUAWEI() { ++ QProcess p; ++ p.start("bash", QStringList() <<"-c" << "cat /proc/cpuinfo | grep Hardware"); ++ p.waitForFinished(); ++ QString strResult = p.readAllStandardOutput().toLower(); ++ if(strResult.length() == 0) ++ return false; ++ if(strResult.indexOf("huawei") != -1 || strResult.indexOf("pangu") != -1 || ++ strResult.indexOf("kirin") != -1) ++ return true; ++ return false; ++} ++ + void Config::OpenBluetoothSettings() + { + QProcess *process = new QProcess(); +diff --git a/ukui-bluetooth/config/config.h b/ukui-bluetooth/config/config.h +index 3e495f9..43cfbc9 100644 +--- a/ukui-bluetooth/config/config.h ++++ b/ukui-bluetooth/config/config.h +@@ -20,10 +20,12 @@ public: + + static void SendNotifyMessage(QString); + static void OpenBluetoothSettings(); ++ static bool isHUAWEI(); + private: + QString setting_name; + QGSettings *gsetting = nullptr; + friend class MainProgram; + friend class TrayWidget; ++ bool is_Huawei = false; + }; + #endif // CONFIG_H +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 01811fa..7030107 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -505,6 +505,8 @@ void TrayWidget::removePairedDevUIByAddress(QString address) + qDebug() << Q_FUNC_INFO << address << __LINE__; + QDevItem *item = _PairedWidget->findChild(address); + if (item) { ++ if(item->isConnected()) ++ SendMessage(pairedDevices.value(address).at(0), false); + _PairedLayout->removeWidget(item); + item->setParent(NULL); + delete item; +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index fbc79ef..23f3af3 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -1,5 +1,6 @@ + #include "pincodewidget.h" + #include "config/xatom-helper.h" ++#include "config/config.h" + + PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + : dev_name(name), +@@ -7,6 +8,10 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + show_flag(flag) + { + is_Intel = QFile::exists("/etc/apt/ota_version"); ++ ++ if (Config::isHUAWEI()) ++ scale = QGSettings("org.ukui.SettingsDaemon.plugins.xsettings").get("scaling-factor").toDouble(); ++ + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + settings = new QGSettings("org.ukui.style"); + connect(settings,&QGSettings::changed,this,&PinCodeWidget::GSettingsChanges); +@@ -62,11 +67,11 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + + QFont ft_14, ft_16, ft_20, ft_24, ft_40; + int ft_size = settings->get("system-font-size").toInt() - 11; +- ft_14.setPixelSize(14 + ft_size); +- ft_16.setPixelSize(16 + ft_size); +- ft_20.setPixelSize(20 + ft_size); +- ft_24.setPixelSize(24 + ft_size); +- ft_40.setPixelSize(40 + ft_size); ++ ft_14.setPixelSize((14 + ft_size) * scale); ++ ft_16.setPixelSize((16 + ft_size) * scale); ++ ft_20.setPixelSize((20 + ft_size) * scale); ++ ft_24.setPixelSize((24 + ft_size) * scale); ++ ft_40.setPixelSize((40 + ft_size) * scale); + tip_label = new QLabel(tip_text,this); + tip_label->setFont(ft_14); + tip_label->setWordWrap(true); +@@ -100,10 +105,10 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + accept_btn->setGeometry(374,159,112,56); + refuse_btn->setGeometry(246,159,112,56); + } else { +- this->setFixedSize(520,212); ++ this->setFixedSize(520 * scale ,212 * scale); + title_icon = new QLabel(this); +- title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); +- title_icon->resize(22,22); ++ title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22 * scale,22 * scale)); ++ title_icon->resize(22 * scale,22 * scale); + + title_text = new QLabel(tr("Bluetooth Connections"),this); + title_text->setFont(ft_14); +@@ -117,14 +122,14 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + // close_btn->setProperty("setIconHighlightEffectDefaultColor", QColor(Qt::white)); + close_btn->setFlat(true); + connect(close_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_close_btn); +- close_btn->setGeometry(480,8,30,30); +- +- title_icon->setGeometry(8, 8, 22, 22); +- title_text->setGeometry(38, 9, 160, 20); +- PIN_label->setGeometry(25,98,207,36); +- tip_label->setGeometry(25,56,437,44); +- accept_btn->setGeometry(388,152,108,36); +- refuse_btn->setGeometry(264,152,108,36); ++ ++ close_btn->setGeometry(480 * scale,8 * scale,30 * scale,30 * scale); ++ title_icon->setGeometry(8 * scale, 8 * scale, 22 * scale, 22 * scale); ++ title_text->setGeometry(38 * scale, 9 * scale, 160 * scale, 20 * scale); ++ PIN_label->setGeometry(25 * scale,98 * scale,207 * scale,36 * scale); ++ tip_label->setGeometry(25 * scale,56 * scale,437 * scale,44 * scale); ++ accept_btn->setGeometry(388 * scale,152 * scale,108 * scale,36 * scale); ++ refuse_btn->setGeometry(264 * scale,152 * scale,108 * scale,36 * scale); + } + QList list = QGuiApplication::screens(); + this->move(list.at(0)->size().width()/2-this->width()/2,list.at(0)->size().height()/2-this->height()/2); +@@ -140,13 +145,13 @@ void PinCodeWidget::pairFailureShow() + qDebug() << Q_FUNC_INFO << __LINE__; + if (is_Intel) { + warn_icon = new QLabel(this); +- warn_icon->setFixedSize(64,64); ++ warn_icon->setFixedSize(64 * scale,64 * scale); + qDebug() << Q_FUNC_INFO << __LINE__; + warn_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/connection-failed.svg")); +- warn_icon->setGeometry(223,42,64,64); ++ warn_icon->setGeometry(223 * scale,42 * scale,64 * scale,64 * scale); + warn_icon->setVisible(true); + tip_label->setText(QString(tr("Bluetooth Connect Failed"))); +- tip_label->setGeometry(210,108,190,28); ++ tip_label->setGeometry(210 * scale,108 * scale,190 * scale,28 * scale); + tip_label->setStyleSheet("QLabel{\ + font-family: NotoSansCJKsc;\ + font-size: 16px;\ +@@ -156,7 +161,7 @@ void PinCodeWidget::pairFailureShow() + PIN_label->setVisible(false); + accept_btn->setVisible(false); + refuse_btn->setText(tr("Close")); +- refuse_btn->setGeometry(374,159,112,56); ++ refuse_btn->setGeometry(374 * scale,159 * scale,112 * scale,56 * scale); + return; + } + QMessageBox msgBox; +@@ -239,10 +244,10 @@ void PinCodeWidget::GSettingsChanges(const QString &key) + int size = settings->get("system-font-size").toInt() - 11; + qDebug() << Q_FUNC_INFO << size; + QFont ft, ft1; +- ft.setPixelSize(14 + size); ++ ft.setPixelSize((14 + size) * scale); + tip_label->setFont(ft); + title_text->setFont(ft); +- ft1.setPixelSize(24 + size); ++ ft1.setPixelSize((24 + size) * scale); + PIN_label->setFont(ft1); + } + this->setPalette(palette); +diff --git a/ukui-bluetooth/pin/pincodewidget.h b/ukui-bluetooth/pin/pincodewidget.h +index 2524df0..5587f24 100644 +--- a/ukui-bluetooth/pin/pincodewidget.h ++++ b/ukui-bluetooth/pin/pincodewidget.h +@@ -19,6 +19,7 @@ + #include + #include + #include ++#include + + #define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" + #define TRANSPARENCY_KEY "transparency" +@@ -64,7 +65,8 @@ private: + QString dev_name; + QString PINCode; + bool show_flag; +- bool is_Intel; ++ bool is_Intel = false; ++ double scale = 1.0; + }; + + #endif // PINCODEWIDGET_H diff --git a/patches/fix_icon_changed.patch b/patches/fix_icon_changed.patch new file mode 100644 index 0000000..00ed790 --- /dev/null +++ b/patches/fix_icon_changed.patch @@ -0,0 +1,76 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index ad1ce02..92b02e3 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -276,6 +276,10 @@ void QDevItem::DrawText(QPainter &painter) + else + painter.setPen(QColor(Qt::white)); + int fontSize = StyleSettings->get("system-font-size").toInt(); ++ if (fontSize > 15) ++ fontSize = 15; ++ if (fontSize < 10) ++ fontSize = 10; + if (_Name.size() > FontTable[fontSize - 10]) { + nName.remove(FontTable[fontSize - 10], _Name.size() - FontTable[fontSize - 10]); + nName.append("..."); +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index a6fb8a2..b83fa7d 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -5,8 +5,7 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + target_name(devname), + target_source(filename), + root_address(root), +- target_size(size), +- target_type(filename.split(".").length()-1) ++ target_size(size) + { + // 添加窗管协议 + MotifWmHints hints; +@@ -82,6 +81,8 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + }else if (target_source.contains(".mp4", Qt::CaseInsensitive) + || target_source.contains(".mkv", Qt::CaseInsensitive)) + fileicon = QIcon::fromTheme("video-x-generic"); ++ if (target_source.contains(".txt", Qt::CaseInsensitive)) ++ fileicon = QIcon::fromTheme("text-plain"); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(target_source.split(".").at(1)); + if (fileicon.isNull()) +@@ -90,7 +91,7 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); + } + if (fileicon.isNull()) +- fileicon = QIcon::fromTheme("text"); ++ fileicon = QIcon::fromTheme("text-plain"); + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); + file_source->setGeometry(32,52,460,54); + file_source->setAlignment(Qt::AlignTop); +@@ -346,6 +347,7 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + str.split("/").at(0) == "inode"){ + if (QIcon::hasThemeIcon(str.split("/").join("-"))) { + fileicon = QIcon::fromTheme(str.split("/").join("-")); ++ qDebug() << str.split("/").join("-"); + } else { + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(target_source.split(".").at(1)); +@@ -354,7 +356,7 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); + if (fileicon.isNull()) +- fileicon = QIcon::fromTheme("text"); ++ fileicon = QIcon::fromTheme("text-plain"); + } + }else + fileicon = QIcon::fromTheme("text"); +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +index cf066d3..f2dfe43 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +@@ -91,7 +91,6 @@ private: + QString target_source; + QString root_address; + QString file_path; +- QString target_type; + quint64 target_size; + QTimer *receiveTimer; + int fileNums = 0; diff --git a/patches/fix_incorrect_modify.patch b/patches/fix_incorrect_modify.patch new file mode 100644 index 0000000..2fcc585 --- /dev/null +++ b/patches/fix_incorrect_modify.patch @@ -0,0 +1,13 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 1a225cb..9388d01 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -291,7 +291,7 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + cancel_btn->setVisible(true); + cancel_btn->setGeometry(376, 205, 112, 56); + m_progressbar->setVisible(true); +- transNum->setVisible(fileNums); ++ transNum->setVisible(fileNums - 1); + Tiptop->setVisible(false); + dev_widget->setVisible(false); + tip_text->setVisible(true); diff --git a/patches/fix_init_font_size.patch b/patches/fix_init_font_size.patch new file mode 100644 index 0000000..90fff98 --- /dev/null +++ b/patches/fix_init_font_size.patch @@ -0,0 +1,233 @@ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index 62235fc..f64edf0 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -84,7 +84,6 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + ft1.setPixelSize(18); + file_source->setFont(ft1); + file_source->setWordWrap(true); +- file_source->setWordWrap(true); + + file_icon = new QLabel(this); + file_icon->setPixmap(fileicon.pixmap(64,64)); +@@ -96,7 +95,6 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + file_name->setToolTip(target_source); + file_name->setFont(ft); + file_name->setAlignment(Qt::AlignVCenter|Qt::AlignLeft); +- file_name->setWordWrap(true); + + int unitcount = 0; //将单位B转化为对应的KB、MB等单位 + double calc_size = target_size; +@@ -172,9 +170,6 @@ void FileReceivingPopupWidget::initLayout() { + + window_Title = new QLabel(tr("Bluetooth File"),this); + window_Title->setFixedSize(100,20); +- QFont ft; +- ft.setPixelSize(14); +- window_Title->setFont(ft); + connect(close_btn,&QPushButton::clicked,this,[=]{ + emit this->rejected(); + this->close(); +@@ -186,12 +181,27 @@ void FileReceivingPopupWidget::initLayout() { + view_btn->setGeometry(390,215,120,36); + file_source->setGeometry(32,52,460,54); + file_icon->setGeometry(32,104,64,64); +- file_name->setGeometry(112,111,293,20); ++ file_name->setGeometry(112,111,293,28); + file_size->setGeometry(112,136,293,20); + transfer_progress->setGeometry(32,184,454,8); + cancel_btn->setGeometry(278,215,96,36); + accept_btn->setGeometry(390,215,96,36); + warn_icon->setGeometry(32,54,22,22); ++ ++ int size = StyleSettings->get("system-font-size").toInt() - 11; ++ QFont ft; ++ ft.setPixelSize(18 + size); ++ file_source->setFont(ft); ++ QFontMetrics fontMetrics(file_source->font()); ++ QString fileName = fontMetrics.elidedText(target_source, Qt::ElideMiddle, 280); ++ QString fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", waiting for receive...")), Qt::ElideMiddle, file_source->width()); ++ file_source->setText(fileSource); ++ file_source->setToolTip(target_name); ++ file_name->setText(fileName); ++ ft.setPixelSize(14 + size); ++ file_name->setFont(ft); ++ file_size->setFont(ft); ++ window_Title->setFont(ft); + } + + void FileReceivingPopupWidget::initIntelLayout() { +@@ -459,9 +469,11 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + file_name->setVisible(false); + file_size->setVisible(false); + +- file_source->setText(tr("File from \"")+target_name+tr("\", received failed !")); ++ QFontMetrics fontMetrics(file_source->font()); ++ QString fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", received failed !")), Qt::ElideMiddle, file_source->width()); ++ file_source->setText(fileSource); + file_source->setAlignment(Qt::AlignTop); +- file_source->setGeometry(62,52,430,54); ++ file_source->setGeometry(62,52,430,60); + warn_icon->setVisible(true); + if (isIntel) { + warn_icon->setFixedSize(64,64); +@@ -509,6 +521,18 @@ void FileReceivingPopupWidget::GSettingsChanges(const QString &key) + QFont ft; + ft.setPixelSize(18 + size); + file_source->setFont(ft); ++ QFontMetrics fontMetrics(file_source->font()); ++ QString fileName = fontMetrics.elidedText(target_source, Qt::ElideMiddle, 280); ++ QString fileSource; ++ if (!cancel_btn->isVisible()) { ++ fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", received failed !")), Qt::ElideMiddle, file_source->width()); ++ file_source->setAlignment(Qt::AlignTop); ++ file_source->setGeometry(62,52,430,60); ++ } else ++ fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", waiting for receive...")), Qt::ElideMiddle, file_source->width()); ++ file_source->setText(fileSource); ++ file_source->setToolTip(target_name); ++ file_name->setText(fileName); + ft.setPixelSize(14 + size); + file_name->setFont(ft); + file_size->setFont(ft); +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 9e78915..fa09930 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -45,11 +45,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + move((deskdop->width()-this->width())/2, (deskdop->height()-this->height())/2); + + tip_text = new QLabel(tr("Transferring to \"")+dev_name+"\"",this); +- QFont ft_18, ft_14; +- ft_14.setPixelSize(14); +- ft_18.setPixelSize(18); + +- tip_text->setFont(ft_18); + tip_text->setWordWrap(true); + tip_text->setVisible(false); + +@@ -59,7 +55,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + target_icon->setPixmap(file_icon.at(0).pixmap(64,64)); + + target_size = new QLabel(file_size.at(0),this); +- target_size->setFont(ft_14); + + QFontMetrics fontMetrics(target_size->font()); + QString fileName; +@@ -71,13 +66,11 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + }else + fileName = fontMetrics.elidedText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1), Qt::ElideMiddle, 280); + target_name = new QLabel(fileName,this); +- target_name->setFont(ft_14); + target_name->setWordWrap(true); + + + transNum = new QLabel("1/"+QString::number(fileNums), this); + transNum->setVisible(false); +- transNum->setFont(ft_14); + + m_progressbar = new QProgressBar(this); + m_progressbar->setOrientation(Qt::Horizontal); +@@ -86,7 +79,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + + Tiptop = new QLabel(tr("Select Device"),this); + Tiptop->setFixedSize(100,20); +- Tiptop->setFont(ft_14); + + dev_widget = new DeviceSeleterWidget(devicelist, this,dev_address); + +@@ -120,7 +112,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + tranfer_status_text = new QLabel(this); + tranfer_status_text->setText(tr("File Transmission Failed !")); + tranfer_status_text->setVisible(false); +- tranfer_status_text->setFont(ft_18); + + if (is_Intel) + initIntelLayout(); +@@ -136,16 +127,12 @@ BluetoothFileTransferWidget::~BluetoothFileTransferWidget() + } + + void BluetoothFileTransferWidget::initLayout() { +- QFont ft_14; +- ft_14.setPixelSize(14); +- + this->setFixedSize(520,620); + title_icon = new QLabel(this); + title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); + title_icon->resize(22,22); + + title_text = new QLabel(tr("Bluetooth file transfer"),this); +- title_text->setFont(ft_14); + + close_btn = new QPushButton(this); + close_btn->setIcon(QIcon::fromTheme("window-close-symbolic")); +@@ -157,6 +144,8 @@ void BluetoothFileTransferWidget::initLayout() { + emit close_the_pre_session(); + this->close(); + }); ++ ++ //布局 + dev_widget->resize(456,356); + title_icon->setGeometry(8,8,22,22); + title_text->setGeometry(36,8,200,20); +@@ -176,6 +165,19 @@ void BluetoothFileTransferWidget::initLayout() { + m_progressbar->setGeometry(32,185,406,8); + else + m_progressbar->setGeometry(32,185,454,8); ++ ++ //字体 ++ int size = GSettings->get("system-font-size").toInt() - 11; ++ QFont ft; ++ ft.setPixelSize(14+size); ++ title_text->setFont(ft); ++ target_size->setFont(ft); ++ target_name->setFont(ft); ++ transNum->setFont(ft); ++ Tiptop->setFont(ft); ++ ft.setPixelSize(18+size); ++ tip_text->setFont(ft); ++ tranfer_status_text->setFont(ft); + } + + void BluetoothFileTransferWidget::initIntelLayout() { +@@ -190,6 +192,7 @@ void BluetoothFileTransferWidget::initIntelLayout() { + target_size->setFixedWidth(68); + target_size->setFont(ft_14); + dev_widget->resize(430,296); ++ + ok_btn->setGeometry(342,450,112,56); + cancel_btn->setGeometry(214,450,112,56); + tranfer_status_text->setGeometry(62,33,376,27); +@@ -205,6 +208,19 @@ void BluetoothFileTransferWidget::initIntelLayout() { + m_progressbar->setGeometry(24,155,372,8); + else + m_progressbar->setGeometry(24,155,420,8); ++ ++ int size = GSettings->get("system-font-size").toInt() - 11; ++ QFont ft; ++ ft.setPixelSize(14+size); ++ title_text->setFont(ft); ++ target_size->setFont(ft); ++ target_name->setFont(ft); ++ transNum->setFont(ft); ++ Tiptop->setFont(ft); ++ ft.setPixelSize(18+size); ++ tip_text->setFont(ft); ++ tranfer_status_text->setFont(ft); ++ + this->activateWindow(); + } + +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index 6fa5890..4c6c2f1 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -117,7 +117,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + close_btn->setGeometry(480,8,30,30); + title_icon->setGeometry(8, 8, 22, 22); + title_text->setGeometry(38, 9, 160, 20); +- PIN_label->setGeometry(25,90,207,36); ++ PIN_label->setGeometry(25,98,207,36); + tip_label->setGeometry(25,56,437,44); + accept_btn->setGeometry(388,152,108,36); + refuse_btn->setGeometry(264,152,108,36); diff --git a/patches/fix_label_show_on_file_send_progress_bar.patch b/patches/fix_label_show_on_file_send_progress_bar.patch new file mode 100644 index 0000000..69730bb --- /dev/null +++ b/patches/fix_label_show_on_file_send_progress_bar.patch @@ -0,0 +1,17 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index c36eb55..f17ad13 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -118,10 +118,11 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + line-height: 24px;\ + opacity: 1;\ + }"); ++ target_name->setWordWrap(true); + + + transNum = new QLabel("1/"+QString::number(fileNums), this); +- transNum->setGeometry(459,168,30,20); ++ transNum->setGeometry(459,168,52,20); + transNum->setVisible(false); + transNum->setStyleSheet("QLabel{\ + width: 22px;\ diff --git a/patches/fix_lasted_mistake.patch b/patches/fix_lasted_mistake.patch new file mode 100644 index 0000000..aadd056 --- /dev/null +++ b/patches/fix_lasted_mistake.patch @@ -0,0 +1,70 @@ +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 09f7277..aea8198 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -85,13 +85,15 @@ void BluetoothDbus::defaultAdapterChangedSLot(QString value) { + void BluetoothDbus::devPairSignalSLot(QString address, bool paired) { + qDebug() << "devPairSignalSLot" << address << paired; + if (paired && !pairedDevice.contains(address)) { +- pairedList.append(address); ++ if (!pairedList.contains(address)) ++ pairedList.append(address); + addNewPairedDevice(address); + emit devPairSignal(pairedDevice.value(address).at(0),paired); + } + if (!paired && pairedDevice.contains(address)) { + QString name = pairedDevice.value(address).at(0); +- pairedList.removeAll(address); ++ if (!pairedList.contains(address)) ++ pairedList.removeAll(address); + pairedDevice.remove(address); + emit devPairSignal(name, paired); + } +@@ -146,6 +148,8 @@ void BluetoothDbus::devBatteryChangedSignalSLot(QString address, QString battery + + void BluetoothDbus::devRemoveSignalSLot(QString address) { + qDebug() << "devRemoveSignalSLot" << address; ++ if (pairedList.contains(address)) ++ pairedList.removeAll(address); + if (pairedDevice.keys().contains(address)) + pairedDevice.remove(address); + emit devRemoveSignal(address); +@@ -396,7 +400,8 @@ void BluetoothDbus::getDefaultAdapterPairedDevices() { + QStringList ret = response.arguments().takeFirst().toStringList(); + qDebug() << ret; + for (int i = 0; i < ret.size(); i++) { +- pairedList.append(ret.at(i)); ++ if (!pairedList.contains(ret.at(i))) ++ pairedList.append(ret.at(i)); + addNewPairedDevice(ret.at(i)); + } + qDebug() << "init paired devices over : " << pairedDevice; +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index bc5ae12..3333629 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -423,6 +423,7 @@ void TrayWidget::layoutAddPairedDev() + _MSelf->setFixedHeight((isNull ? 102 : selfHeight)); + } + update(); ++ setWidgetPosition(); + } + } + +@@ -483,10 +484,16 @@ void TrayWidget::removePairedDevUIByAddress(QString address) + item = nullptr; + } + pairedDevices.remove(address); ++ updatePairedDev(); + } + + void TrayWidget::showUI() + { ++ int count = pairedList.size(); ++ selfHeight =160 + count * 54; ++ if (count >= 7) ++ selfHeight = 515; ++ this->setFixedHeight((_MBtn->isChecked() && count != 0 ? selfHeight : 102)); + if (!_Intel) + setWidgetPosition(); + else { diff --git a/patches/fix_layout_after_update.patch b/patches/fix_layout_after_update.patch new file mode 100644 index 0000000..e811255 --- /dev/null +++ b/patches/fix_layout_after_update.patch @@ -0,0 +1,63 @@ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index 1ec5122..62235fc 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -72,6 +72,7 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + } + }else + fileicon = QIcon::fromTheme("text"); ++ + if (isIntel) + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive..."),this); + else +@@ -203,12 +204,12 @@ void FileReceivingPopupWidget::initIntelLayout() { + + accept_btn->setGeometry(342,200,112,56); + cancel_btn->setGeometry(214,200,112,56); +- file_name->setGeometry(104,71,293,23); +- file_size->setGeometry(104,103,293,23); ++ file_name->setGeometry(104,75,293,23); ++ file_size->setGeometry(104,107,293,23); + view_btn->setGeometry(342,200,120,36); +- file_source->setGeometry(24,24,460,54); +- file_icon->setGeometry(24,67,64,64); +- transfer_progress->setGeometry(24,155,430,8); ++ file_source->setGeometry(24,24,430,54); ++ file_icon->setGeometry(24,71,64,64); ++ transfer_progress->setGeometry(24,159,430,8); + warn_icon->setGeometry(32,34,22,22); + } + +@@ -458,7 +459,6 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + file_name->setVisible(false); + file_size->setVisible(false); + +- + file_source->setText(tr("File from \"")+target_name+tr("\", received failed !")); + file_source->setAlignment(Qt::AlignTop); + file_source->setGeometry(62,52,430,54); +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 9b155c6..4cbde9f 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -170,7 +170,7 @@ void BluetoothFileTransferWidget::initLayout() { + target_size->setGeometry(112,88,70,30); + tip_text->setGeometry(32,52,452,56); + target_icon->setGeometry(32,56,64,64); +- target_name->setGeometry(112,63,400,20); ++ target_name->setGeometry(112,63,400,24); + transNum->setGeometry(459,168,52,20); + if (fileNums > 1) + m_progressbar->setGeometry(32,185,406,8); +@@ -197,9 +197,9 @@ void BluetoothFileTransferWidget::initIntelLayout() { + dev_widget->setGeometry(24,139,430,296); + Tiptop->setGeometry(32,111,100,20); + target_size->setGeometry(104,60,70,30); +- tip_text->setGeometry(32,32,452,56); ++ tip_text->setGeometry(24,24,430,56); + target_icon->setGeometry(24,24,64,64); +- target_name->setGeometry(104,28,400,20); ++ target_name->setGeometry(104,28,400,24); + transNum->setGeometry(410,148,52,20); + if (fileNums > 1) + m_progressbar->setGeometry(24,155,372,8); diff --git a/patches/fix_layout_when_transfer_more_than_10_files.patch b/patches/fix_layout_when_transfer_more_than_10_files.patch new file mode 100644 index 0000000..9f22cf5 --- /dev/null +++ b/patches/fix_layout_when_transfer_more_than_10_files.patch @@ -0,0 +1,22 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 8126abb..1db6210 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -77,7 +77,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + font-weight: 500;\ + line-height: 24px;\ + opacity: 1;}"); +- tip_text->setGeometry(32,52,440,28); ++ tip_text->setGeometry(32,52,452,28); + tip_text->setVisible(false); + + initFileInfo(); +@@ -121,7 +121,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + + + transNum = new QLabel("1/"+QString::number(fileNums), this); +- transNum->setGeometry(459,168,22,20); ++ transNum->setGeometry(459,168,30,20); + transNum->setVisible(false); + transNum->setStyleSheet("QLabel{\ + width: 22px;\ diff --git a/patches/fix_no_actions_when_remote_device_cancel_sending.patch b/patches/fix_no_actions_when_remote_device_cancel_sending.patch new file mode 100644 index 0000000..19e52ed --- /dev/null +++ b/patches/fix_no_actions_when_remote_device_cancel_sending.patch @@ -0,0 +1,63 @@ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index 760c671..79a27b2 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -394,7 +394,7 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + + + file_source->setText(tr("File from \"")+target_name+tr("\", received failed !")); +- file_source->setGeometry(62,52,500,54); ++ file_source->setGeometry(62,52,430,54); + file_source->setAlignment(Qt::AlignTop); + warn_icon->setVisible(true); + if (isIntel) { +@@ -402,19 +402,23 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + warn_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-failed.svg")); + warn_icon->setGeometry(220,86,64,64); + file_source->setText(tr("File Transmission Failed !")); +- file_source->setFixedWidth(500); ++ file_source->setFixedWidth(505); + file_source->setStyleSheet("QLabel{\ + font-family: NotoSansCJKsc;\ + font-size: 16px;\ + line-height: 19px;\ + text-align: center;\ + color: #FB5050;}"); +- file_source->setGeometry(12,150,500,24); ++ file_source->setGeometry(12,150,505,24); + file_source->setAlignment(Qt::AlignCenter); + } + } + } + ++void FileReceivingPopupWidget::cancelReceivingFiles() { ++ file_transfer_completed(QString("Error")); ++} ++ + void FileReceivingPopupWidget::GSettings_value_chanage(const QString &key) + { + if(key == "file-save-path"){ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +index c2d8626..4153af1 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +@@ -55,6 +55,7 @@ public slots: + void OnClickedAcceptBtn(); + void update_transfer_progress_bar(quint64); + void file_transfer_completed(QString status); ++ void cancelReceivingFiles(); + void GSettings_value_chanage(const QString &key); + void GSettingsChanges(const QString &key); + void transferCompelete(); +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index 493f1e4..7849c17 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -80,6 +80,7 @@ void MainProgram::receiveFileSlot(QString devname, QString filename, QString typ + qDebug() << Q_FUNC_INFO << __LINE__; + connect(receiving_widget, &FileReceivingPopupWidget::clearOldSession, _sessionDbus, &BluetoothDbus::clearOldSession); + connect(_sessionDbus, &BluetoothDbus::fileReceiveMore, receiving_widget, &FileReceivingPopupWidget::updateUI); ++ connect(_sessionDbus, &BluetoothDbus::obexAgentCanceledSignal, receiving_widget, &FileReceivingPopupWidget::cancelReceivingFiles); + + connect(receiving_widget,&FileReceivingPopupWidget::accepted,this,[=]{ + qDebug() << Q_FUNC_INFO << __LINE__; diff --git a/patches/fix_no_branch_detective_caused_problem.patch b/patches/fix_no_branch_detective_caused_problem.patch new file mode 100644 index 0000000..d88c2eb --- /dev/null +++ b/patches/fix_no_branch_detective_caused_problem.patch @@ -0,0 +1,26 @@ +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 55e1b04..f1e5af9 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -514,14 +514,14 @@ void TrayWidget::removePairedDevUIByAddress(QString address) + + void TrayWidget::showUI() + { +- int count = pairedList.size(); +- selfHeight =160 + count * 54; +- if (count >= 7) +- selfHeight = 515; +- this->setFixedHeight((_MBtn->isChecked() && count != 0 ? selfHeight : 102)); +- if (!_Intel) ++ if (!_Intel) { ++ int count = pairedList.size(); ++ selfHeight =160 + count * 54; ++ if (count >= 7) ++ selfHeight = 515; ++ this->setFixedHeight(((_MBtn->isChecked()) && (count != 0) ? selfHeight : 102)); + setWidgetPosition(); +- else { ++ } else { + QDesktopWidget *deskdop = QApplication::desktop(); + move((deskdop->width() - width())/2, (deskdop->height() - height())/2); + } diff --git a/patches/fix_pair_timeout_twice_segement_fualt_and_tray_menu_action_icon.patch b/patches/fix_pair_timeout_twice_segement_fualt_and_tray_menu_action_icon.patch new file mode 100644 index 0000000..f5fdfaf --- /dev/null +++ b/patches/fix_pair_timeout_twice_segement_fualt_and_tray_menu_action_icon.patch @@ -0,0 +1,142 @@ +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index b87e4e5..79e8727 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -261,10 +261,13 @@ void MainProgram::displayPasskeySlot(QString name, QString passkey) + } + + Keypincodewidget = new PinCodeWidget(name,passkey,false); ++ connect(Keypincodewidget, &PinCodeWidget::msgShowedOver, this, [=] { ++ Keypincodewidget->deleteLater(); ++ Keypincodewidget = nullptr; ++ }); + + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { + Keypincodewidget->pairFailureShow(); +- Keypincodewidget = nullptr; + disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); + }); + connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired){ +@@ -276,7 +279,6 @@ void MainProgram::displayPasskeySlot(QString name, QString passkey) + QTimer::singleShot(1000,this,[=]{ + if (!_sessionDbus->isConnected(name)) { + Keypincodewidget->pairFailureShow(); +- Keypincodewidget = nullptr; + } + }); + disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); +@@ -291,38 +293,34 @@ void MainProgram::requestConfirmationSlot(QString name, QString passkey) + qDebug() << Q_FUNC_INFO << name << passkey; + + if(pincodewidget != nullptr){ ++ qDebug() << Q_FUNC_INFO << __LINE__; + return; + } + m_Passkey = passkey; + pincodewidget = new PinCodeWidget(name,passkey); ++ connect(pincodewidget, &PinCodeWidget::msgShowedOver, this, [=] { ++ if (pincodewidget != nullptr) { ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ pincodewidget->deleteLater(); ++ pincodewidget = nullptr; ++ } ++ }); + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { + if (pincodewidget != nullptr) { ++ if (pincodewidget->canceled) ++ return; ++ pincodewidget->canceled = true; + pincodewidget->pairFailureShow(); + pincodewidget = nullptr; + } +- disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); + }); ++ + connect(pincodewidget,&PinCodeWidget::accepted,this,[=]{ + _sessionDbus->replyRequestConfirmation(true); +- disconnect(pincodewidget,&PinCodeWidget::accepted, nullptr, nullptr); + }); + + connect(pincodewidget,&PinCodeWidget::rejected,this,[=]{ + _sessionDbus->replyRequestConfirmation(false); +- disconnect(pincodewidget,&PinCodeWidget::rejected, nullptr, nullptr); +- }); +- +- connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired){ +- if (name != _name) +- return; +- if (!paired) { +- _sessionDbus->replyRequestConfirmation(false); +- if (pincodewidget != nullptr) { +- pincodewidget->close(); +- pincodewidget = nullptr; +- } +- } +- disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); + }); + connect(pincodewidget, &PinCodeWidget::destroyed, this, [=] { + pincodewidget = nullptr; +diff --git a/ukui-bluetooth/mainwidget/trayicon.cpp b/ukui-bluetooth/mainwidget/trayicon.cpp +index 197e6cb..903b8c4 100644 +--- a/ukui-bluetooth/mainwidget/trayicon.cpp ++++ b/ukui-bluetooth/mainwidget/trayicon.cpp +@@ -10,7 +10,8 @@ TrayIcon::TrayIcon(QWidget *parent) + + bluetooth_tray_icon = new QSystemTrayIcon(this); + tray_Menu = new QMenu(this); +- QAction *settins_action = new QAction(QIcon::fromTheme("ukui-settings-symbolic"),tr("Set Bluetooth Item"),tray_Menu); ++ QAction *settins_action = new QAction(tr("Set Bluetooth Item"),tray_Menu); ++ settins_action->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) ); + tray_Menu->addAction(settins_action); + connect(tray_Menu, &QMenu::triggered, this, [=]{ + emit openBluetoothSettings(); +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index c240edf..b7d7a85 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -151,10 +151,8 @@ void PinCodeWidget::Connection_timed_out() + msgBox.setText(tr("Connection error !!!")); + int ret = msgBox.exec(); + if(ret){ +- if (show_flag) +- this->close(); +- else +- this->setHidden(true); ++ this->setHidden(true); ++ emit msgShowedOver(); + } + } + +@@ -169,10 +167,8 @@ void PinCodeWidget::pairFailureShow() + int ret = msgBox.exec(); + if(ret){ + qDebug() << Q_FUNC_INFO << this << __LINE__; +- if (show_flag) +- this->close(); +- else +- this->setHidden(true); ++ this->setHidden(true); ++ emit msgShowedOver(); + } + } + +diff --git a/ukui-bluetooth/pin/pincodewidget.h b/ukui-bluetooth/pin/pincodewidget.h +index ce49ec9..4efd8e4 100644 +--- a/ukui-bluetooth/pin/pincodewidget.h ++++ b/ukui-bluetooth/pin/pincodewidget.h +@@ -32,6 +32,7 @@ public: + void Connection_timed_out(); + void pairFailureShow(); + void updateUIInfo(const QString &name,const QString &pin); ++ bool canceled = false; + public slots: + + private slots: +@@ -42,6 +43,7 @@ private slots: + signals: + void accepted(); + void rejected(); ++ void msgShowedOver(); + private: + QGSettings *settings = nullptr; + QGSettings *transparency_gsettings = nullptr; diff --git a/patches/fix_pin_code_layout_and_translations.patch b/patches/fix_pin_code_layout_and_translations.patch new file mode 100644 index 0000000..a951815 --- /dev/null +++ b/patches/fix_pin_code_layout_and_translations.patch @@ -0,0 +1,307 @@ +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index 67fc32b..c02e4b4 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -127,10 +127,10 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + line-height: 24px;}"); + } else { + this->setFixedSize(520,212); +- title_icon->setGeometry(8, 8, 20, 22); +- title_text->setGeometry(36, 9, 56, 20); +- PIN_label->setGeometry(25,84,207,36); +- tip_label->setGeometry(25,56,437,20); ++ title_icon->setGeometry(8, 8, 22, 22); ++ title_text->setGeometry(38, 9, 160, 20); ++ PIN_label->setGeometry(25,90,207,36); ++ tip_label->setGeometry(25,56,437,40); + //top_label->setGeometry(32,56,456,50); + accept_btn->setGeometry(392,152,96,36); + refuse_btn->setGeometry(288,152,96,36); +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm +index 321e1d3..63e204c 100644 +Binary files a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm and b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm differ +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +index 5d5556c..9188a0c 100644 +--- a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts ++++ b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +@@ -5,58 +5,60 @@ + BluetoothFileTransferWidget + + +- ++ + Bluetooth file transfer + 蓝牙文件 + + +- +- ++ ++ + Transferring to " + 发送文件至 " + + +- +- ++ ++ ++ + and + + + +- +- ++ ++ ++ + files more + 个文件 + + +- ++ + Select Device + 选择设备 + + +- +- +- ++ ++ ++ + OK + 确定 + + +- ++ + Cancel + 取消 + + +- ++ + File Transmission Failed ! + 文件发送失败! + + +- +- ++ ++ + File Transmition Succeed! + 文件发送成功! + + +- ++ + Close + 关闭 + +@@ -101,65 +103,65 @@ + 蓝牙文件传输 + + +- ++ + Bluetooth File + 蓝牙文件 + + +- +- +- +- ++ ++ ++ ++ + File from " + 文件来自 " + + +- ++ + ", waiting for receive. + ",等待接收。 + + +- ++ + Cancel + 取消 + + +- ++ + Accept + 接收 + + +- ++ + View + 查看 + + +- ++ + ", is receiving... (has recieved + ",正在接收… (已接收 + + +- ++ + files) + 个文件) + + +- ++ + ", is receiving... + ",正在接收… + + +- ++ + OK + 确定 + + +- ++ + ", received failed ! + ",接收失败! + + +- ++ + File Transmission Failed ! + 文件发送失败! + +@@ -192,10 +194,6 @@ + Bluetooth pairing + 蓝牙设备配对 + +- +- Bluetooth Connections +- 蓝牙连接 +- + + Bluetooth Connect Request From ' + 蓝牙连接请求来自 " +@@ -205,55 +203,60 @@ + "。 + + +- ++ + If you want to pair with this device, please make sure the numbers below are the same with the devices. + 若要连接此设备,请确认下面的数字与该设备上的一致。 + + +- + Please make sure the PIN code displayed on ' +- 如果 " ++ 如果 " + + +- + ' matches the number below. Please press 'Connect'. +- " 上的PIN码与此PIN码相同,请按 "连接"。 ++ " 上的PIN码与此PIN码相同,请按 "连接"。 + + +- +- ++ ++ + Please enter the following PIN code on the bluetooth device '%1' and press enter to pair ! + 请在蓝牙设备 "%1" 上输入下列PIN码,并按连接进行匹配! + + +- ++ ++ + If ' + 如果 " + + +- ++ ++ Bluetooth Connections ++ 蓝牙连接 ++ ++ ++ ++ + ' the PIN on is the same as this PIN. Please press 'Connect'. + " 上的PIN码与此PIN码相同,请按 "连接"。 + + +- ++ + Connect + 连接 + + +- ++ + Refush + 取消 + + +- +- ++ ++ + Pair + 配对 + + +- +- ++ ++ + Connection error !!! + 连接失败 !!! + +@@ -261,12 +264,12 @@ + + QDevItem + +- ++ + The connection with the Bluetooth device “%1” is successful! + 与蓝牙设备“%1”连接成功! + + +- ++ + Bluetooth device “%1” disconnected! + 蓝牙设备“%1”失去连接! + +@@ -290,17 +293,17 @@ + + TrayWidget + +- ++ + bluetooth + 蓝牙 + + +- ++ + Bluetooth + 蓝牙 + + +- ++ + My Device + 我的设备 + diff --git a/patches/fix_pin_code_widget_title_and_intel_tray_icon_hide.patch b/patches/fix_pin_code_widget_title_and_intel_tray_icon_hide.patch new file mode 100644 index 0000000..648cbe8 --- /dev/null +++ b/patches/fix_pin_code_widget_title_and_intel_tray_icon_hide.patch @@ -0,0 +1,39 @@ +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 117379a..25d72c8 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -14,13 +14,14 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + // hints.flags = MWM_HINTS_DECORATIONS; + // hints.decorations = MWM_DECOR_ALL; + // XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); +- +- trayicon = new TrayIcon(); +- connect(this, &TrayWidget::trayIconStatusChanged, trayicon, &TrayIcon::SetTrayIcon); +- connect(trayicon, &TrayIcon::showTayWidget, this, &TrayWidget::showUI); +- connect(trayicon, &TrayIcon::openBluetoothSettings, this, [=]{ +- _SessionDBus->openBluetoothSettings(); +- }); ++ if (!_Intel) { ++ trayicon = new TrayIcon(); ++ connect(this, &TrayWidget::trayIconStatusChanged, trayicon, &TrayIcon::SetTrayIcon); ++ connect(trayicon, &TrayIcon::showTayWidget, this, &TrayWidget::showUI); ++ connect(trayicon, &TrayIcon::openBluetoothSettings, this, [=]{ ++ _SessionDBus->openBluetoothSettings(); ++ }); ++ } + connect(QApplication::desktop(), &QDesktopWidget::resized, this, [=] { + setWidgetPosition(); + }); +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index c7a1605..7945bba 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -115,6 +115,8 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + + if (is_Intel) { + this->setFixedSize(510, 287); ++ title_icon->setGeometry(16,12,24,24); ++ title_text->setGeometry(48,12,100,24); + //top_label->setGeometry(24,60,456,50); + tip_label->setGeometry(24,72,450,40); + tip_label->setStyleSheet("QLabel{\ diff --git a/patches/fix_receive_file_from_WINDOWS_icon_after_click_accept.patch b/patches/fix_receive_file_from_WINDOWS_icon_after_click_accept.patch new file mode 100644 index 0000000..b214ec5 --- /dev/null +++ b/patches/fix_receive_file_from_WINDOWS_icon_after_click_accept.patch @@ -0,0 +1,52 @@ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index 998611e..8dd0a27 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -388,7 +388,46 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + if (receiveTimer->isActive()) { + receiveTimer->stop(); + } else +- file_source->setText(tr("File from \"")+target_name+tr("\", is receiving...")); ++ file_source->setText(tr("File from \"")+target_name+tr("\", is receiving..."));QString filePathName = QDir::homePath()+"/.cache/obexd/"+target_source; ++ GError *error; ++ qDebug() << Q_FUNC_INFO << filePathName; ++ GFile *file = g_file_new_for_path(filePathName.toStdString().c_str()); ++ GFileInfo *file_info = g_file_query_info(file,"*",G_FILE_QUERY_INFO_NONE,NULL,&error); ++ qDebug() << Q_FUNC_INFO << g_file_info_get_size(file_info) << g_file_info_get_content_type(file_info); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ ++ QString str = g_file_info_get_content_type(file_info); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ QIcon fileicon; ++ if (str.split("/").at(0) == "image"){ ++ fileicon = QIcon::fromTheme("image"); ++ if (fileicon.isNull()) { ++ fileicon = QIcon::fromTheme("text"); ++ } ++ }else if (str.split("/").at(0) == "video") ++ fileicon = QIcon::fromTheme("video-x-generic"); ++ else if (str.split("/").at(0) == "audio" || ++ str.split("/").at(0) == "application" || ++ str.split("/").at(0) == "text" || ++ str.split("/").at(0) == "inode"){ ++ if (QIcon::hasThemeIcon(str.split("/").join("-"))) { ++ fileicon = QIcon::fromTheme(str.split("/").join("-")); ++ } else { ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme("text"); ++ } ++ }else ++ fileicon = QIcon::fromTheme("text"); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ file_icon->setPixmap(fileicon.pixmap(64,64)); ++ this->update(); ++ + cancel_btn->disconnect(); + cancel_btn->connect(cancel_btn,&QPushButton::clicked,this,[=]{ + emit this->cancel(); diff --git a/patches/fix_segment_fault_in_send_non_type_file.patch b/patches/fix_segment_fault_in_send_non_type_file.patch new file mode 100644 index 0000000..6d4be44 --- /dev/null +++ b/patches/fix_segment_fault_in_send_non_type_file.patch @@ -0,0 +1,56 @@ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index a6dbc56..a6fb8a2 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -73,19 +73,22 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + this->close(); + }); + QIcon fileicon; +- if (target_source.contains(".jpg", Qt::CaseInsensitive) +- || target_source.contains(".png", Qt::CaseInsensitive) +- || target_source.contains(".svg", Qt::CaseInsensitive)){ +- fileicon = QIcon::fromTheme("image"); +- }else if (target_source.contains(".mp4", Qt::CaseInsensitive) +- || target_source.contains(".mkv", Qt::CaseInsensitive)) +- fileicon = QIcon::fromTheme("video-x-generic"); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(target_source.split(".").at(1)); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); +- if (fileicon.isNull()) +- fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); ++ if (target_source.contains(".")) ++ { ++ if (target_source.contains(".jpg", Qt::CaseInsensitive) ++ || target_source.contains(".png", Qt::CaseInsensitive) ++ || target_source.contains(".svg", Qt::CaseInsensitive)){ ++ fileicon = QIcon::fromTheme("image"); ++ }else if (target_source.contains(".mp4", Qt::CaseInsensitive) ++ || target_source.contains(".mkv", Qt::CaseInsensitive)) ++ fileicon = QIcon::fromTheme("video-x-generic"); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); ++ } + if (fileicon.isNull()) + fileicon = QIcon::fromTheme("text"); + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); +@@ -181,6 +184,7 @@ FileReceivingPopupWidget::~FileReceivingPopupWidget() + } + + void FileReceivingPopupWidget::updateUI(QString name, quint64 size, QString type) { ++ fileNums += 1; + qDebug() << Q_FUNC_INFO << name << size << type; + move_file(); + QFontMetrics fontMetrics(file_source->font()); +@@ -314,7 +318,6 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + } + qDebug() << Q_FUNC_INFO <isActive()) { + receiveTimer->stop(); + } else diff --git a/patches/fix_segmentfault_and_clicked_active_icon.patch b/patches/fix_segmentfault_and_clicked_active_icon.patch new file mode 100644 index 0000000..e839425 --- /dev/null +++ b/patches/fix_segmentfault_and_clicked_active_icon.patch @@ -0,0 +1,52 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index e4d0c0a..af9532e 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -65,13 +65,14 @@ void QDevItem::SendMessage(bool connected) + + void QDevItem::connectedChangedSlot(bool connected) { + qDebug() << Q_FUNC_INFO << connected; +- if (_iconTimer->isActive()) ++ if (_clicked) { + _iconTimer->stop(); ++ _clicked = false; ++ } + if (_Connected == connected) + return; +- qDebug() << Q_FUNC_INFO << __LINE__; + _Connected = connected; +- _clicked = false; ++ qDebug() << Q_FUNC_INFO << __LINE__; + update(); + SendMessage(connected); + } +@@ -362,10 +363,12 @@ void QDevItem::MouseClickedFunc() + _iconTimer->start(110); + + //以下这个只执行一次的定时器,用来设置点击后加载动画的持续时间 +- QTimer::singleShot(3000,this,[=]{ +- _iconTimer->stop(); +- _clicked = false; +- update(); ++ QTimer::singleShot(7000,this,[=]{ ++ if (_clicked) { ++ _iconTimer->stop(); ++ _clicked = false; ++ update(); ++ } + }); + } + } +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index f1e5af9..3b280fe 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -412,7 +412,7 @@ void TrayWidget::layoutAddAllPairedDev() + QString name = pairedDevices.value(item).at(0); + _SessionDBus->getDevConnectStatus(item); + QDevItem *dev = new QDevItem(item, pairedDevices.value(item), _SessionDBus->isConnected(name), _PairedWidget); +- connect(_SessionDBus, &BluetoothDbus::devConnectStatusSignal, this, [=](QString address, bool connected) { ++ connect(_SessionDBus, &BluetoothDbus::devConnectStatusSignal, dev, [=](QString address, bool connected) { + qDebug() << " +++ compare " << address << item; + if (address != item) + return; diff --git a/patches/fix_send_file_no_type_icon.patch b/patches/fix_send_file_no_type_icon.patch new file mode 100644 index 0000000..7ac66e6 --- /dev/null +++ b/patches/fix_send_file_no_type_icon.patch @@ -0,0 +1,105 @@ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index fe5767d..a6dbc56 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -5,7 +5,8 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + target_name(devname), + target_source(filename), + root_address(root), +- target_size(size) ++ target_size(size), ++ target_type(filename.split(".").length()-1) + { + // 添加窗管协议 + MotifWmHints hints; +@@ -71,7 +72,22 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + emit this->rejected(); + this->close(); + }); +- ++ QIcon fileicon; ++ if (target_source.contains(".jpg", Qt::CaseInsensitive) ++ || target_source.contains(".png", Qt::CaseInsensitive) ++ || target_source.contains(".svg", Qt::CaseInsensitive)){ ++ fileicon = QIcon::fromTheme("image"); ++ }else if (target_source.contains(".mp4", Qt::CaseInsensitive) ++ || target_source.contains(".mkv", Qt::CaseInsensitive)) ++ fileicon = QIcon::fromTheme("video-x-generic"); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme("text"); + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); + file_source->setGeometry(32,52,460,54); + file_source->setAlignment(Qt::AlignTop); +@@ -87,7 +103,7 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + file_source->setWordWrap(true); + + file_icon = new QLabel(this); +- file_icon->setPixmap(QIcon::fromTheme("ukui-folder-documents-symbolic").pixmap(64,64)); ++ file_icon->setPixmap(fileicon.pixmap(64,64)); + file_icon->setAlignment(Qt::AlignCenter); + file_icon->setGeometry(32,104,64,64); + +@@ -303,6 +319,45 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + receiveTimer->stop(); + } else + file_source->setText(tr("File from \"")+target_name+tr("\", is receiving...")); ++ QString filePathName = QDir::homePath()+"/.cache/obexd/"+target_source; ++ GError *error; ++ qDebug() << Q_FUNC_INFO << filePathName; ++ GFile *file = g_file_new_for_path(filePathName.toStdString().c_str()); ++ GFileInfo *file_info = g_file_query_info(file,"*",G_FILE_QUERY_INFO_NONE,NULL,&error); ++ qDebug() << Q_FUNC_INFO << g_file_info_get_size(file_info) << g_file_info_get_content_type(file_info); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ ++ QString str = g_file_info_get_content_type(file_info); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ QIcon fileicon; ++ if (str.split("/").at(0) == "image"){ ++ fileicon = QIcon::fromTheme("image"); ++ if (fileicon.isNull()) { ++ fileicon = QIcon::fromTheme("text"); ++ } ++ }else if (str.split("/").at(0) == "video") ++ fileicon = QIcon::fromTheme("video-x-generic"); ++ else if (str.split("/").at(0) == "audio" || ++ str.split("/").at(0) == "application" || ++ str.split("/").at(0) == "text" || ++ str.split("/").at(0) == "inode"){ ++ if (QIcon::hasThemeIcon(str.split("/").join("-"))) { ++ fileicon = QIcon::fromTheme(str.split("/").join("-")); ++ } else { ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); ++ if (fileicon.isNull()) ++ fileicon = QIcon::fromTheme("text"); ++ } ++ }else ++ fileicon = QIcon::fromTheme("text"); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ file_icon->setPixmap(fileicon.pixmap(64,64)); ++ this->update(); + cancel_btn->disconnect(); + cancel_btn->connect(cancel_btn,&QPushButton::clicked,this,[=]{ + emit this->cancel(); +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +index f2dfe43..cf066d3 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +@@ -91,6 +91,7 @@ private: + QString target_source; + QString root_address; + QString file_path; ++ QString target_type; + quint64 target_size; + QTimer *receiveTimer; + int fileNums = 0; diff --git a/patches/fix_send_file_when_delete_file.patch b/patches/fix_send_file_when_delete_file.patch new file mode 100644 index 0000000..9eb9536 --- /dev/null +++ b/patches/fix_send_file_when_delete_file.patch @@ -0,0 +1,18 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 9dcb9ea..16b52fe 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -380,7 +380,12 @@ void Daemon::continueSendFiles(QString filename) { + QDBusConnection::sessionBus().send(statusChanged); + }); + }else{ +-// transfer_widget->tranfer_error(); ++ QDBusMessage statusChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", ++ "com.ukui.bluetooth", ++ "statusChanged"); ++ statusChanged << QString("Error"); ++ ++ QDBusConnection::sessionBus().send(statusChanged); + } + }); + } diff --git a/patches/fix_send_file_widget_label_width.patch b/patches/fix_send_file_widget_label_width.patch new file mode 100644 index 0000000..a976fbb --- /dev/null +++ b/patches/fix_send_file_widget_label_width.patch @@ -0,0 +1,22 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index dcb1262..a71d2e3 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -108,7 +108,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + }else + fileName = fontMetrics.elidedText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1), Qt::ElideMiddle, 280); + target_name = new QLabel(fileName,this); +- target_name->setGeometry(112,63,300,20); ++ target_name->setGeometry(112,63,400,20); + target_name->setStyleSheet("QLabel{\ + width: 300px;\ + height: 20px;\ +@@ -321,7 +321,7 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + dev_widget->setVisible(false); + tip_text->setVisible(true); + target_icon->setGeometry(32,95,64,64); +- target_name->setGeometry(112,102,300,20); ++ target_name->setGeometry(112,102,400,20); + target_size->setGeometry(112,127,68,30); + + main_animation_group = new QParallelAnimationGroup(this); diff --git a/patches/fix_send_file_widget_wrong_long_of_label.patch b/patches/fix_send_file_widget_wrong_long_of_label.patch new file mode 100644 index 0000000..4111999 --- /dev/null +++ b/patches/fix_send_file_widget_wrong_long_of_label.patch @@ -0,0 +1,113 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index f17ad13..abf51e9 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -288,13 +288,28 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + this->setFixedSize(520,276); + + +- QString Name = dev_widget->get_seleter_dev_name(); +- if (dev_widget->get_seleter_dev_name().size() > 30) { +- Name.remove(30, dev_widget->get_seleter_dev_name().size() - 30); +- Name.append("..."); +- tip_text->setToolTip(dev_widget->get_seleter_dev_name()); ++ ++ QString nName; ++ nName = dev_widget->get_seleter_dev_name(); ++ float shownum = 0; ++ for (int i = 0; i < dev_widget->get_seleter_dev_name().size(); i++) { ++ QChar ch = dev_widget->get_seleter_dev_name().at(i); ++ ushort uNum = ch.unicode(); ++ if ((uNum >= 0x4E00 && uNum <= 0x9FA5)) ++ shownum += 1.7; ++ else if (ch == 'm' || ch == 'M') ++ shownum += 1.5; ++ else ++ shownum += 1; ++ if (shownum + 1.5 >= 30) { ++ nName.remove(i, dev_widget->get_seleter_dev_name().size() - i); ++ nName.append("..."); ++ tip_text->setToolTip(dev_widget->get_seleter_dev_name()); ++ break; ++ } + } +- tip_text->setText(tr("Transferring to \"")+Name+"\""); ++ ++ tip_text->setText(tr("Transferring to \"")+nName+"\""); + tip_text->update(); + + ok_btn->setVisible(false); +diff --git a/ukui-bluetooth/fileSend/deviceselectitem.cpp b/ukui-bluetooth/fileSend/deviceselectitem.cpp +index 8562a8a..90323a8 100644 +--- a/ukui-bluetooth/fileSend/deviceselectitem.cpp ++++ b/ukui-bluetooth/fileSend/deviceselectitem.cpp +@@ -193,9 +193,26 @@ void DeviceSelectItem::paintEvent(QPaintEvent *) { + QString nName; + nName = MName; + int fontSize = StyleSettings->get("system-font-size").toInt(); +- if (MName.size() > FontTable[fontSize - 10]) { +- nName.remove(FontTable[fontSize - 10], MName.size() - FontTable[fontSize - 10]); +- nName.append("..."); ++ if (fontSize > 15) ++ fontSize = 15; ++ if (fontSize < 10) ++ fontSize = 10; ++ float shownum = 0; ++ for (int i = 0; i < MName.size(); i++) { ++ QChar ch = MName.at(i); ++ ushort uNum = ch.unicode(); ++ if ((uNum >= 0x4E00 && uNum <= 0x9FA5)) ++ shownum += 1.7; ++ else if (ch == 'm' || ch == 'M') ++ shownum += 1.5; ++ else ++ shownum += 1; ++ if (shownum + 1.5 >= FontTable[fontSize - 10]) { ++ nName.remove(i, MName.size() - i); ++ nName.append("..."); ++ this->setToolTip(MName); ++ break; ++ } + } + painter.drawText(40,13,380,28,Qt::AlignLeft, nName); + } +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index b7d7a85..7045ff9 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -58,10 +58,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + Name.append("..."); + } + if(show_flag) { +- if (is_Intel) +- tip_text = tr("If you want to pair with this device, please make sure the numbers below are the same with the devices."); +- else +- tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); ++ tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + } else + tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(Name); + //top_label = new QLabel(top_text,this); +@@ -114,12 +111,18 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + close_btn->setGeometry(480,8,30,30); + + if (is_Intel) { +- this->setFixedSize(520, 328); ++ this->setFixedSize(510, 287); + //top_label->setGeometry(24,60,456,50); +- tip_label->setGeometry(24,118,450,40); +- PIN_label->setGeometry(24,163,462,47); +- accept_btn->setGeometry(373,248,112,56); +- refuse_btn->setGeometry(246,248,112,56); ++ tip_label->setGeometry(24,72,450,40); ++ tip_label->setStyleSheet("QLabel{\ ++ font-size: 16px;\ ++ font-family: Noto Sans CJK SC;\ ++ font-weight: 400;\ ++ line-height: 24px;}"); ++ PIN_label->setGeometry(24,136,462,47); ++ accept_btn->setGeometry(373,207,112,56); ++ refuse_btn->setGeometry(246,207,112,56); ++ close_btn->setGeometry(470, 8, 30, 30); + PIN_label->setStyleSheet("QLabel{\ + font-size: 40px;\ + font-family: Noto Sans CJK SC;\ diff --git a/patches/fix_sigmentfault_start_before_panel_and_no_adapter_hide_trayicon.patch b/patches/fix_sigmentfault_start_before_panel_and_no_adapter_hide_trayicon.patch new file mode 100644 index 0000000..741fcb4 --- /dev/null +++ b/patches/fix_sigmentfault_start_before_panel_and_no_adapter_hide_trayicon.patch @@ -0,0 +1,141 @@ +diff --git a/ukui-bluetooth/component/bluetoothsettinglabel.cpp b/ukui-bluetooth/component/bluetoothsettinglabel.cpp +index a46fafb..cb27087 100644 +--- a/ukui-bluetooth/component/bluetoothsettinglabel.cpp ++++ b/ukui-bluetooth/component/bluetoothsettinglabel.cpp +@@ -4,8 +4,6 @@ BluetoothSettingLabel::BluetoothSettingLabel(QWidget *parent) : QLabel(parent) + { + _MStatus = Normal; + this->setFixedSize(420,50); +- this->setAutoFillBackground(true); +- this->setAttribute(Qt::WA_TranslucentBackground); + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,[=]{ +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 149ea45..808e5d8 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -22,6 +22,8 @@ void BluetoothDbus::connectDBusSignals() { + //适配器相关dbus + CONNECT_DBUS_SIGNAL("defaultAdapterPowerChanged", defaultAdapterPowerChangedSLot(bool)); + CONNECT_DBUS_SIGNAL("defaultAdapterChanged", defaultAdapterChangedSLot(QString)); ++ CONNECT_DBUS_SIGNAL("adapterRemoveSignal", adapterRemoveSignalSLot(QString)); ++ CONNECT_DBUS_SIGNAL("adapterAddSignal", adapterAddSignalSLot(QString)); + + //连接移除相关dbus + CONNECT_DBUS_SIGNAL("devConnectStatusSignal", devConnectStatusSignalSLot(QString, bool)); +@@ -53,7 +55,28 @@ void BluetoothDbus::defaultAdapterPowerChangedSLot(bool value) { + emit powerChangedSignal(powered); + } + ++void BluetoothDbus::adapterRemoveSignalSLot(QString address) { ++ qDebug() << Q_FUNC_INFO << __LINE__ << address; ++ QDBusMessage _m = CREATE_METHOD_CALL("getAdapterDevAddressList"); ++ QDBusMessage _response1 = CALL_METHOD(_m); ++ if (_response1.type() == QDBusMessage::ReplyMessage) ++ { ++ if (_response1.arguments().takeFirst().toStringList().size() == 0) { ++ emit showTrayIcon(false); ++ } ++ qDebug() << Q_FUNC_INFO << __LINE__ << _response1.arguments().takeFirst().toStringList(); ++ } ++ emit adapterRemoveSignal(address); ++} ++ ++void BluetoothDbus::adapterAddSignalSLot(QString address) { ++ qDebug() << Q_FUNC_INFO << __LINE__ << address; ++ emit showTrayIcon(true); ++ emit adapterAddSignal(address); ++} ++ + void BluetoothDbus::defaultAdapterChangedSLot(QString value) { ++ qDebug() << Q_FUNC_INFO << __LINE__ << value; + getDefaultAdapterPairedDevices(); + emit AdapterChangedSignal(value); + } +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.h b/ukui-bluetooth/daemon/bluetoothdbus.h +index 3cb9422..365052f 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.h ++++ b/ukui-bluetooth/daemon/bluetoothdbus.h +@@ -75,6 +75,9 @@ public: + QMap getPairedDevices(); + + signals: ++ void showTrayIcon(bool); ++ void adapterAddSignal(QString); ++ void adapterRemoveSignal(QString); + void powerChangedSignal(bool); + void displayPasskeySignal(QString,QString); + void receiveFilesSignal(QString,QString,QString,QString,quint64); +@@ -102,6 +105,8 @@ private: + QMap connectedDevice; + + private slots: ++ void adapterAddSignalSLot(QString address); ++ void adapterRemoveSignalSLot(QString address); + void defaultAdapterPowerChangedSLot(bool value); + void defaultAdapterChangedSLot(QString value); + void devPairSignalSLot(QString address, bool paired); +diff --git a/ukui-bluetooth/mainwidget/trayicon.cpp b/ukui-bluetooth/mainwidget/trayicon.cpp +index 903b8c4..413b6b2 100644 +--- a/ukui-bluetooth/mainwidget/trayicon.cpp ++++ b/ukui-bluetooth/mainwidget/trayicon.cpp +@@ -77,8 +77,16 @@ void TrayIcon::GSettings_value_chanage(const QString &key) + qDebug() << Q_FUNC_INFO << key; + if(key != "trayShow") + return; ++ if (!hasAdapter) ++ return; + if(bluetooth_tray_icon->isVisible() != settings->get(key).toBool()){ + bluetooth_tray_icon->setVisible(settings->get(key).toBool()); + } + } + ++void TrayIcon::SetAdapterFlag(bool set) { ++ hasAdapter = set; ++ if (!settings->get("trayShow").toBool() && set) ++ return; ++ bluetooth_tray_icon->setVisible(set); ++} +diff --git a/ukui-bluetooth/mainwidget/trayicon.h b/ukui-bluetooth/mainwidget/trayicon.h +index 5f14729..9a64da5 100644 +--- a/ukui-bluetooth/mainwidget/trayicon.h ++++ b/ukui-bluetooth/mainwidget/trayicon.h +@@ -29,6 +29,7 @@ public: + TrayIcon(QWidget *parent = nullptr); + ~TrayIcon(); + void InitTrayWidget(); ++ void SetAdapterFlag(bool set); + + signals: + void showTayWidget(); +@@ -43,5 +44,6 @@ private: + QMenu *tray_Menu = nullptr; + QGSettings *StyleSettings = nullptr; + QGSettings *settings = nullptr; ++ bool hasAdapter = true; + } ; + #endif // TRAYICON_H +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 25d72c8..cf56849 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -21,6 +21,9 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + connect(trayicon, &TrayIcon::openBluetoothSettings, this, [=]{ + _SessionDBus->openBluetoothSettings(); + }); ++ connect(_SessionDBus, &BluetoothDbus::showTrayIcon, this, [=](bool show) { ++ trayicon->SetAdapterFlag(show); ++ }); + } + connect(QApplication::desktop(), &QDesktopWidget::resized, this, [=] { + setWidgetPosition(); +@@ -146,6 +149,8 @@ void TrayWidget::setWidgetPosition() + "/panel/position", + "org.ukui.panel", + QDBusConnection::sessionBus()); ++ if (!iface.isValid()) ++ return; + QDBusReply reply=iface.call("GetPrimaryScreenGeometry"); + //reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置 + diff --git a/patches/fix_signal_canceled_bind.patch b/patches/fix_signal_canceled_bind.patch new file mode 100644 index 0000000..0c5be88 --- /dev/null +++ b/patches/fix_signal_canceled_bind.patch @@ -0,0 +1,92 @@ +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index da0aafc..1a3b161 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -89,14 +89,14 @@ void BluetoothDbus::devPairSignalSLot(QString address, bool paired) { + if (!pairedList.contains(address)) + pairedList.append(address); + addNewPairedDevice(address); +- emit devPairSignal(pairedDevice.value(address).at(0),paired); ++ emit sessionDevPairSignal(pairedDevice.value(address).at(0),paired); + } + if (!paired && pairedDevice.contains(address)) { + QString name = pairedDevice.value(address).at(0); + if (pairedList.contains(address)) + pairedList.removeAll(address); + pairedDevice.remove(address); +- emit devPairSignal(name, paired); ++ emit sessionDevPairSignal(name, paired); + } + } + +@@ -336,7 +336,7 @@ void BluetoothDbus::getDevConnectStatus(QString address) { + && connectedDevice.values().contains(address) + && pairedDevice.keys().contains(address)) + connectedDevice.remove(pairedDevice.value(address).at(0)); +- qDebug() << "init connect status : " << connected << address; ++ qDebug() << "init connect status : " << connected << address << pairedDevice; + } else { + qDebug() << " init connect status method called failed!"; + } +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.h b/ukui-bluetooth/daemon/bluetoothdbus.h +index ba93476..0e40b1b 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.h ++++ b/ukui-bluetooth/daemon/bluetoothdbus.h +@@ -91,7 +91,7 @@ signals: + void devRemoveSignal(QString); + void devNameChangedSignal(); + void devBatteryChangedSignal(); +- void devPairSignal(QString, bool); ++ void sessionDevPairSignal(QString, bool); + void sendTransferFilesMesgSignal(QStringList); + void sendTransferDeviceMesgSignal(QString); + void AdapterChangedSignal(QString); +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index f64edf0..245ab47 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -150,6 +150,7 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + this->move(QPoint(desktop.right()-this->width(),desktop.bottom()-this->height())); + + window_pop_up_animation(); ++ this->activateWindow(); + } + + FileReceivingPopupWidget::~FileReceivingPopupWidget() +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index dfd12ca..1fa303e 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -24,7 +24,7 @@ MainProgram::MainProgram(bool intel, QObject *parent) : + }); + connect(_sessionDbus, &BluetoothDbus::displayPasskeySignal, this, &MainProgram::displayPasskeySlot); + connect(_sessionDbus, &BluetoothDbus::requestConfirmationSignal, this, &MainProgram::requestConfirmationSlot); +- connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired) { ++ connect(_sessionDbus, &BluetoothDbus::sessionDevPairSignal, this, [=](QString _name, bool paired) { + Q_UNUSED(_name); + Q_UNUSED(paired); + UI->layoutAddOnePairedDev(_name, paired); +@@ -278,14 +278,13 @@ void MainProgram::displayPasskeySlot(QString name, QString passkey) + }); + + disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); +- disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); + + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { + if(nullptr != Keypincodewidget) + Keypincodewidget->pairFailureShow(); + disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); + }); +- connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired){ ++ connect(_sessionDbus, &BluetoothDbus::sessionDevPairSignal, this, [=](QString _name, bool paired){ + qDebug() << Q_FUNC_INFO << __LINE__; + if (name != _name || nullptr == Keypincodewidget) + return; +@@ -294,7 +293,6 @@ void MainProgram::displayPasskeySlot(QString name, QString passkey) + Keypincodewidget->setHidden(true); + emit Keypincodewidget->msgShowedOver(); + } +- disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); + }); + //保持在最前 + Keypincodewidget->show(); diff --git a/patches/fix_the_window_type_in_intel.patch b/patches/fix_the_window_type_in_intel.patch new file mode 100644 index 0000000..1f4ff14 --- /dev/null +++ b/patches/fix_the_window_type_in_intel.patch @@ -0,0 +1,885 @@ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index b0a50d1..d229165 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -8,10 +8,14 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + root_address(root), + target_size(size) + { ++ isIntel = QFile::exists("/etc/apt/ota_version"); + // 添加窗管协议 + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; +- hints.functions = MWM_FUNC_ALL; ++ if (isIntel) ++ hints.functions = MWM_FUNC_CLOSE; ++ else ++ hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); + +@@ -19,7 +23,6 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,&FileReceivingPopupWidget::GSettingsChanges); + } +- this->setFixedSize(520,276); + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("Bluetooth file transfer")); + this->setAttribute(Qt::WA_DeleteOnClose); +@@ -42,35 +45,6 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + file_path = QDir::homePath(); + } + +- QDesktopWidget *desktop_widget = QApplication::desktop(); +- desktop = desktop_widget->availableGeometry(); +- qDebug() << Q_FUNC_INFO << this->width() << this->height(); +- qDebug() << Q_FUNC_INFO <width() << desktop.bottom()-this->height(); +- this->move(QPoint(desktop.right()-this->width(),desktop.bottom()-this->height())); +- +- window_pop_up_animation(); +- +- close_btn = new QPushButton(this); +- close_btn->setIcon(QIcon::fromTheme("window-close-symbolic")); +- close_btn->setGeometry(480,4,30,30); +- close_btn->setProperty("isWindowButton", 0x2); +- close_btn->setProperty("useIconHighlightEffect", 0x8); +- close_btn->setFlat(true); +- +- icon_label = new QLabel(this); +- icon_label->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); +- icon_label->setGeometry(8,8,22,22); +- +- window_Title = new QLabel(tr("Bluetooth File"),this); +- window_Title->setFixedSize(100,20); +- QFont ft; +- ft.setPixelSize(14); +- window_Title->setFont(ft); +- window_Title->setGeometry(36, 9, 100, 20); +- connect(close_btn,&QPushButton::clicked,this,[=]{ +- emit this->rejected(); +- this->close(); +- }); + QIcon fileicon; + if (target_type.split("/").at(0) == "image"){ + fileicon = QIcon::fromTheme("image"); +@@ -99,8 +73,9 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + }else + fileicon = QIcon::fromTheme("text"); + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); +- file_source->setGeometry(32,52,460,54); + file_source->setAlignment(Qt::AlignTop); ++ QFont ft; ++ ft.setPixelSize(14); + QFont ft1; + ft1.setPixelSize(18); + file_source->setFont(ft1); +@@ -115,13 +90,11 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + file_icon = new QLabel(this); + file_icon->setPixmap(fileicon.pixmap(64,64)); + file_icon->setAlignment(Qt::AlignCenter); +- file_icon->setGeometry(32,104,64,64); + + QFontMetrics fontMetrics(file_source->font()); + QString fileName = fontMetrics.elidedText(target_source, Qt::ElideMiddle, 280); + file_name = new QLabel(fileName,this); + file_name->setToolTip(target_source); +- file_name->setGeometry(112,111,293,20); + file_name->setFont(ft); + file_name->setAlignment(Qt::AlignVCenter|Qt::AlignLeft); + file_name->setWordWrap(true); +@@ -134,26 +107,23 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + } + + file_size = new QLabel(QString::asprintf("%.2f", calc_size) + unitString[unitcount],this); +- file_size->setGeometry(112,136,293,20); ++ + file_size->setFont(ft); + file_size->setAlignment(Qt::AlignVCenter|Qt::AlignLeft); + file_size->setWordWrap(true); + + transfer_progress = new QProgressBar(this); +- transfer_progress->setGeometry(32,184,454,8); + transfer_progress->setFixedHeight(8); + transfer_progress->setTextVisible(false); + transfer_progress->setVisible(false); + + cancel_btn = new QPushButton(tr("Cancel"),this); +- cancel_btn->setGeometry(278,215,96,36); + connect(cancel_btn,&QPushButton::clicked,this,[=]{ + emit this->rejected(); + this->close(); + }); + + accept_btn = new QPushButton(tr("Accept"),this); +- accept_btn->setGeometry(390,215,96,36); + connect(accept_btn,&QPushButton::clicked,this,[=]{ + OnClickedAcceptBtn(); + }); +@@ -162,27 +132,27 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + warn_icon->setPixmap(QIcon::fromTheme("kylin-dialog-warning").pixmap(22,22)); + if (warn_icon->pixmap()->isNull()) + warn_icon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(22,22)); +- warn_icon->setGeometry(32,54,22,22); + warn_icon->setVisible(false); + + view_btn = new QPushButton(tr("View"),this); +- view_btn->setGeometry(390,215,120,36); + view_btn->setVisible(false); + + receivedFiles.clear(); + receiveTimer = new QTimer(this); + connect(receiveTimer,SIGNAL(timeout()), this, SLOT(transferCompelete())); + +- isIntel = QFile::exists("/etc/apt/ota_version"); +- if (isIntel) { +- accept_btn->setGeometry(390,205,112,56); +- cancel_btn->setGeometry(262,205,112,56); +- file_name->setGeometry(112,111,293,23); +- file_size->setGeometry(112,136,293,23); +- ft.setPixelSize(16); +- file_size->setFont(ft); +- file_name->setFont(ft); +- } ++ if (isIntel) ++ initIntelLayout(); ++ else ++ initLayout(); ++ ++ QDesktopWidget *desktop_widget = QApplication::desktop(); ++ desktop = desktop_widget->availableGeometry(); ++ qDebug() << Q_FUNC_INFO << this->width() << this->height(); ++ qDebug() << Q_FUNC_INFO <width() << desktop.bottom()-this->height(); ++ this->move(QPoint(desktop.right()-this->width(),desktop.bottom()-this->height())); ++ ++ window_pop_up_animation(); + } + + FileReceivingPopupWidget::~FileReceivingPopupWidget() +@@ -190,6 +160,60 @@ FileReceivingPopupWidget::~FileReceivingPopupWidget() + delete settings; + } + ++void FileReceivingPopupWidget::initLayout() { ++ this->setFixedSize(520,276); ++ close_btn = new QPushButton(this); ++ close_btn->setIcon(QIcon::fromTheme("window-close-symbolic")); ++ close_btn->setProperty("isWindowButton", 0x2); ++ close_btn->setProperty("useIconHighlightEffect", 0x8); ++ close_btn->setFlat(true); ++ ++ icon_label = new QLabel(this); ++ icon_label->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); ++ ++ window_Title = new QLabel(tr("Bluetooth File"),this); ++ window_Title->setFixedSize(100,20); ++ QFont ft; ++ ft.setPixelSize(14); ++ window_Title->setFont(ft); ++ connect(close_btn,&QPushButton::clicked,this,[=]{ ++ emit this->rejected(); ++ this->close(); ++ }); ++ ++ close_btn->setGeometry(480,4,30,30); ++ icon_label->setGeometry(8,8,22,22); ++ window_Title->setGeometry(36, 9, 100, 20); ++ view_btn->setGeometry(390,215,120,36); ++ file_source->setGeometry(32,52,460,54); ++ file_icon->setGeometry(32,104,64,64); ++ file_name->setGeometry(112,111,293,20); ++ file_size->setGeometry(112,136,293,20); ++ transfer_progress->setGeometry(32,184,454,8); ++ cancel_btn->setGeometry(278,215,96,36); ++ accept_btn->setGeometry(390,215,96,36); ++ warn_icon->setGeometry(32,54,22,22); ++} ++ ++void FileReceivingPopupWidget::initIntelLayout() { ++ this->setWindowFlags(Qt::Dialog); ++ this->setFixedSize(520,256); ++ QFont ft; ++ ft.setPixelSize(16); ++ file_size->setFont(ft); ++ file_name->setFont(ft); ++ ++ accept_btn->setGeometry(390,185,112,56); ++ cancel_btn->setGeometry(262,185,112,56); ++ file_name->setGeometry(112,91,293,23); ++ file_size->setGeometry(112,116,293,23); ++ view_btn->setGeometry(390,195,120,36); ++ file_source->setGeometry(32,32,460,54); ++ file_icon->setGeometry(32,84,64,64); ++ transfer_progress->setGeometry(32,164,454,8); ++ warn_icon->setGeometry(32,34,22,22); ++} ++ + void FileReceivingPopupWidget::updateUI(QString name, quint64 size, QString type) { + fileNums += 1; + qDebug() << Q_FUNC_INFO << name << size << type; +@@ -325,10 +349,12 @@ void FileReceivingPopupWidget::update_transfer_progress_bar(quint64 value) + } + + void FileReceivingPopupWidget::transferCompelete() { +- close_btn->disconnect(); +- close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ +- this->close(); +- }); ++ if (!isIntel) { ++ close_btn->disconnect(); ++ close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ ++ this->close(); ++ }); ++ } + cancel_btn->setVisible(false); + + bool x = move_file(); +@@ -365,11 +391,13 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + emit this->cancel(); + isCanceled = true; + }); +- close_btn->disconnect(); +- close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ +- emit this->cancel(); +- isCanceled = true; +- }); ++ if (!isIntel) { ++ close_btn->disconnect(); ++ close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ ++ emit this->cancel(); ++ isCanceled = true; ++ }); ++ } + }else if(status == QString("Complete")){ + receiveTimer->start(2000); + qDebug() << Q_FUNC_INFO << __LINE__ ; +@@ -380,10 +408,12 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + accept_btn->connect(accept_btn,&QPushButton::clicked,this,[=]{ + this->close(); + }); +- close_btn->disconnect(); +- close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ +- this->close(); +- }); ++ if (!isIntel) { ++ close_btn->disconnect(); ++ close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ ++ this->close(); ++ }); ++ } + cancel_btn->setVisible(false); + view_btn->setVisible(false); + transfer_progress->setVisible(false); +@@ -393,13 +423,13 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + + + file_source->setText(tr("File from \"")+target_name+tr("\", received failed !")); +- file_source->setGeometry(62,52,430,54); + file_source->setAlignment(Qt::AlignTop); ++ file_source->setGeometry(62,52,430,54); + warn_icon->setVisible(true); + if (isIntel) { + warn_icon->setFixedSize(64,64); + warn_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-failed.svg")); +- warn_icon->setGeometry(220,86,64,64); ++ warn_icon->setGeometry(220,66,64,64); + file_source->setText(tr("File Transmission Failed !")); + file_source->setFixedWidth(505); + file_source->setStyleSheet("QLabel{\ +@@ -408,7 +438,7 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + line-height: 19px;\ + text-align: center;\ + color: #FB5050;}"); +- file_source->setGeometry(12,150,505,24); ++ file_source->setGeometry(12,130,505,24); + file_source->setAlignment(Qt::AlignCenter); + } + this->activateWindow(); +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +index 4153af1..b1fe108 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h +@@ -66,7 +66,7 @@ signals: + void clearOldSession(); + private: + bool isCanceled = false; +- bool isIntel; ++ bool isIntel = false; + QGSettings *StyleSettings = nullptr; + QGSettings *settings = nullptr; + QGSettings *transparency_gsettings = nullptr; +@@ -98,6 +98,9 @@ private: + int fileNums = 0; + QList receivedFiles; + ++ void initLayout(); ++ void initIntelLayout(); ++ + }; + + #endif // FILERECEIVINGPOPUPWIDGET_H +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 282c544..68ccfc0 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -10,6 +10,8 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + isShow = true; + send_state = _SEND_NONE; + ++ is_Intel = QFile::exists("/etc/apt/ota_version"); ++ + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + GSettings = new QGSettings("org.ukui.style"); + connect(GSettings,&QGSettings::changed,this,&BluetoothFileTransferWidget::GSettingsChanges); +@@ -18,12 +20,14 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + //窗管协议 + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; +- hints.functions = MWM_FUNC_ALL; ++ if (is_Intel) ++ hints.functions = MWM_FUNC_CLOSE; ++ else ++ hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); + + qDebug() << Q_FUNC_INFO << __LINE__; +- this->setFixedSize(520,620); + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("Bluetooth file transfer")); + this->setAttribute(Qt::WA_DeleteOnClose); +@@ -40,34 +44,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + QDesktopWidget *deskdop = QApplication::desktop(); + move((deskdop->width()-this->width())/2, (deskdop->height()-this->height())/2); + +- title_icon = new QLabel(this); +- title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); +- title_icon->resize(22,22); +- title_icon->setGeometry(8,8,22,22); +- +- title_text = new QLabel(tr("Bluetooth file transfer"),this); +- title_text->setGeometry(36,8,200,20); +- title_text->setStyleSheet("QLabel{\ +- width: 200px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;}"); +- +- close_btn = new QPushButton(this); +- close_btn->setIcon(QIcon::fromTheme("window-close-symbolic")); +- close_btn->setProperty("isWindowButton", 0x2); +- close_btn->setProperty("useIconHighlightEffect", 0x8); +- close_btn->setFlat(true); +- close_btn->setFixedSize(30,30); +- close_btn->setGeometry(484,4,30,30); +- connect(close_btn,&QPushButton::clicked,this,[=]{ +- emit close_the_pre_session(); +- this->close(); +- }); +- + tip_text = new QLabel(tr("Transferring to \"")+dev_name+"\"",this); + tip_text->setStyleSheet("QLabel{\ + width: 214px;\ +@@ -77,14 +53,12 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + font-weight: 500;\ + line-height: 24px;\ + opacity: 1;}"); +- tip_text->setGeometry(32,52,452,28); + tip_text->setVisible(false); + + initFileInfo(); + + target_icon = new QLabel(this); + target_icon->setPixmap(file_icon.at(0).pixmap(64,64)); +- target_icon->setGeometry(32,56,64,64); + + target_size = new QLabel(file_size.at(0),this); + target_size->setStyleSheet("QLabel{\ +@@ -96,7 +70,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + color: #818181;\ + opacity: 1;\ + }"); +- target_size->setGeometry(112,88,70,30); + + QFontMetrics fontMetrics(target_size->font()); + QString fileName; +@@ -108,7 +81,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + }else + fileName = fontMetrics.elidedText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1), Qt::ElideMiddle, 280); + target_name = new QLabel(fileName,this); +- target_name->setGeometry(112,63,400,20); + target_name->setStyleSheet("QLabel{\ + width: 300px;\ + height: 20px;\ +@@ -122,7 +94,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + + + transNum = new QLabel("1/"+QString::number(fileNums), this); +- transNum->setGeometry(459,168,52,20); + transNum->setVisible(false); + transNum->setStyleSheet("QLabel{\ + width: 22px;\ +@@ -136,10 +107,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + + m_progressbar = new QProgressBar(this); + m_progressbar->setOrientation(Qt::Horizontal); +- if (fileNums > 1) +- m_progressbar->setGeometry(32,175,406,8); +- else +- m_progressbar->setGeometry(32,175,454,8); + m_progressbar->setTextVisible(false); + m_progressbar->setVisible(false); + +@@ -153,15 +120,12 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + font-weight: 400;\ + line-height: 24px;\ + opacity: 1;}"); +- Tiptop->setGeometry(32,144,100,20); + + dev_widget = new DeviceSeleterWidget(devicelist, this,dev_address); + dev_widget->resize(456,356); +- dev_widget->setGeometry(32,175,456,356); + + ok_btn = new QPushButton(tr("OK"),this); + ok_btn->setFixedSize(100,36); +- ok_btn->setGeometry(392,560,100,36); + if(dev_widget->get_seleter_device().isNull()){ + ok_btn->setEnabled(false); + } +@@ -175,7 +139,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + + cancel_btn = new QPushButton(tr("Cancel"),this); + cancel_btn->setFixedSize(100,36); +- cancel_btn->setGeometry(280,560,100,36); + connect(cancel_btn,&QPushButton::clicked,this,[=]{ + emit this->close_the_pre_session(); + this->close(); +@@ -186,11 +149,9 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + if (tranfer_status_icon->pixmap()->isNull()) + tranfer_status_icon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(22,22)); + tranfer_status_icon->setFixedSize(22,22); +- tranfer_status_icon->setGeometry(32,55,22,22); + tranfer_status_icon->setVisible(false); + + tranfer_status_text = new QLabel(this); +- tranfer_status_text->setGeometry(62,53,376,27); + tranfer_status_text->setText(tr("File Transmission Failed !")); + tranfer_status_text->setVisible(false); + tranfer_status_text->setStyleSheet("QLabel{\ +@@ -200,37 +161,13 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + font-family: Noto Sans CJK SC;\ + font-weight: 500;\ + line-height: 24px;\ +- opacity: 1;}\ +- "); ++ opacity: 1;}"); + ++ if (is_Intel) ++ initIntelLayout(); ++ else ++ initLayout(); + +- is_Intel = QFile::exists("/etc/apt/ota_version"); +- if (is_Intel) { +- cancel_btn->setFixedSize(112,56); +- cancel_btn->setGeometry(240,545,112,56); +- ok_btn->setFixedSize(112,56); +- ok_btn->setGeometry(376,545,112,56); +- target_name->setFixedHeight(23); +- target_name->setStyleSheet("QLabel{\ +- width: 300px;\ +- height: 20px;\ +- font-size: 16px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;\ +- }"); +- target_size->setFixedWidth(68); +- target_size->setStyleSheet("QLabel{\ +- width: 100px;\ +- height: 20px;\ +- font-size: 16px;\ +- font-family: NotoSansCJKsc-Regular;\ +- line-height: 24px;\ +- color: #818181;\ +- opacity: 1;\ +- }"); +- } + init_m_progressbar_value(_filesize.at(0)); + } + +@@ -239,6 +176,92 @@ BluetoothFileTransferWidget::~BluetoothFileTransferWidget() + isShow = false; + } + ++void BluetoothFileTransferWidget::initLayout() { ++ this->setFixedSize(520,620); ++ title_icon = new QLabel(this); ++ title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); ++ title_icon->resize(22,22); ++ ++ title_text = new QLabel(tr("Bluetooth file transfer"),this); ++ title_text->setStyleSheet("QLabel{\ ++ width: 200px;\ ++ height: 20px;\ ++ font-size: 14px;\ ++ font-family: Noto Sans CJK SC;\ ++ font-weight: 400;\ ++ line-height: 24px;\ ++ opacity: 1;}"); ++ ++ close_btn = new QPushButton(this); ++ close_btn->setIcon(QIcon::fromTheme("window-close-symbolic")); ++ close_btn->setProperty("isWindowButton", 0x2); ++ close_btn->setProperty("useIconHighlightEffect", 0x8); ++ close_btn->setFlat(true); ++ close_btn->setFixedSize(30,30); ++ connect(close_btn,&QPushButton::clicked,this,[=]{ ++ emit close_the_pre_session(); ++ this->close(); ++ }); ++ title_icon->setGeometry(8,8,22,22); ++ title_text->setGeometry(36,8,200,20); ++ close_btn->setGeometry(484,4,30,30); ++ tranfer_status_text->setGeometry(62,53,376,27); ++ tranfer_status_icon->setGeometry(32,55,22,22); ++ cancel_btn->setGeometry(280,560,100,36); ++ ok_btn->setGeometry(392,560,100,36); ++ dev_widget->setGeometry(32,175,456,356); ++ Tiptop->setGeometry(32,144,100,20); ++ target_size->setGeometry(112,88,70,30); ++ tip_text->setGeometry(32,52,452,28); ++ target_icon->setGeometry(32,56,64,64); ++ target_name->setGeometry(112,63,400,20); ++ transNum->setGeometry(459,168,52,20); ++ if (fileNums > 1) ++ m_progressbar->setGeometry(32,175,406,8); ++ else ++ m_progressbar->setGeometry(32,175,454,8); ++} ++ ++void BluetoothFileTransferWidget::initIntelLayout() { ++ this->setWindowFlags(Qt::Dialog); ++ this->setFixedSize(520,600); ++ cancel_btn->setFixedSize(112,56); ++ ok_btn->setFixedSize(112,56); ++ target_name->setFixedHeight(23); ++ target_name->setStyleSheet("QLabel{\ ++ width: 300px;\ ++ height: 20px;\ ++ font-size: 16px;\ ++ font-family: Noto Sans CJK SC;\ ++ font-weight: 400;\ ++ line-height: 24px;\ ++ opacity: 1;}"); ++ target_size->setFixedWidth(68); ++ target_size->setStyleSheet("QLabel{\ ++ width: 100px;\ ++ height: 20px;\ ++ font-size: 16px;\ ++ font-family: NotoSansCJKsc-Regular;\ ++ line-height: 24px;\ ++ color: #818181;\ ++ opacity: 1;}"); ++ ok_btn->setGeometry(376,525,112,56); ++ cancel_btn->setGeometry(240,525,112,56); ++ tranfer_status_text->setGeometry(62,33,376,27); ++ tranfer_status_icon->setGeometry(32,35,22,22); ++ dev_widget->setGeometry(32,155,456,356); ++ Tiptop->setGeometry(32,124,100,20); ++ target_size->setGeometry(112,68,70,30); ++ tip_text->setGeometry(32,32,452,28); ++ target_icon->setGeometry(32,36,64,64); ++ target_name->setGeometry(112,43,400,20); ++ transNum->setGeometry(459,148,52,20); ++ if (fileNums > 1) ++ m_progressbar->setGeometry(32,155,406,8); ++ else ++ m_progressbar->setGeometry(32,155,454,8); ++} ++ + void BluetoothFileTransferWidget::initFileInfo() { + for (int i = 0; i < fileNums; i++) { + Get_fie_type(i); +@@ -314,15 +337,22 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + + ok_btn->setVisible(false); + cancel_btn->setVisible(true); +- cancel_btn->setGeometry(376, 205, 112, 56); + m_progressbar->setVisible(true); + transNum->setVisible(fileNums - 1); + Tiptop->setVisible(false); + dev_widget->setVisible(false); + tip_text->setVisible(true); +- target_icon->setGeometry(32,95,64,64); +- target_name->setGeometry(112,102,400,20); +- target_size->setGeometry(112,127,68,30); ++ if (is_Intel) { ++ cancel_btn->setGeometry(376, 185, 112, 56); ++ target_icon->setGeometry(32,75,64,64); ++ target_name->setGeometry(112,62,400,20); ++ target_size->setGeometry(112,107,68,30); ++ } else { ++ cancel_btn->setGeometry(376, 213, 100, 36); ++ target_icon->setGeometry(32,95,64,64); ++ target_name->setGeometry(112,102,400,20); ++ target_size->setGeometry(112,127,68,30); ++ } + + main_animation_group = new QParallelAnimationGroup(this); + +@@ -407,10 +437,16 @@ void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { + } + int transfing = fileNums - selectedFiles.size() + 1; + transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); +- if (fileNums > 1) +- m_progressbar->setGeometry(32,175,406,8); ++ if (is_Intel) ++ if (fileNums > 1) ++ m_progressbar->setGeometry(32,155,406,8); ++ else ++ m_progressbar->setGeometry(32,155,454,8); + else +- m_progressbar->setGeometry(32,175,454,8); ++ if (fileNums > 1) ++ m_progressbar->setGeometry(32,175,406,8); ++ else ++ m_progressbar->setGeometry(32,175,454,8); + transNum->setVisible(fileNums - 1); + this->update(); + this->activateWindow(); +@@ -469,7 +505,6 @@ void BluetoothFileTransferWidget::get_transfer_status(QString status) + cancel_btn->setText(tr("OK")); + tranfer_status_icon->setFixedSize(64,64); + tranfer_status_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-success.svg")); +- tranfer_status_icon->setGeometry(220,86,64,64); + tranfer_status_text->setText(tr("File Transmition Succeed!")); + tranfer_status_text->setFixedWidth(500); + tranfer_status_text->setStyleSheet("QLabel{\ +@@ -478,8 +513,14 @@ void BluetoothFileTransferWidget::get_transfer_status(QString status) + line-height: 19px;\ + text-align: center;\ + color: #0FCE75;}"); +- tranfer_status_text->setGeometry(12,150,500,24); + tranfer_status_text->setAlignment(Qt::AlignCenter); ++ if (is_Intel) { ++ tranfer_status_icon->setGeometry(220,66,64,64); ++ tranfer_status_text->setGeometry(12,130,500,24); ++ } else { ++ tranfer_status_icon->setGeometry(220,86,64,64); ++ tranfer_status_text->setGeometry(12,150,500,24); ++ } + } else { + tranfer_status_icon->setPixmap(QIcon::fromTheme("ukui-dialog-success").pixmap(22,22)); + tranfer_status_text->setText(tr("File Transmition Succeed!")); +@@ -516,7 +557,7 @@ void BluetoothFileTransferWidget::tranfer_error() + if (is_Intel){ + tranfer_status_icon->setFixedSize(64,64); + tranfer_status_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-failed.svg")); +- tranfer_status_icon->setGeometry(220,86,64,64); ++ tranfer_status_icon->setGeometry(220,66,64,64); + tranfer_status_text->setFixedWidth(500); + tranfer_status_text->setStyleSheet("QLabel{\ + font-family: NotoSansCJKsc;\ +@@ -524,7 +565,7 @@ void BluetoothFileTransferWidget::tranfer_error() + line-height: 19px;\ + text-align: center;\ + color: #FB5050;}"); +- tranfer_status_text->setGeometry(12,150,500,24); ++ tranfer_status_text->setGeometry(12,130,500,24); + tranfer_status_text->setAlignment(Qt::AlignCenter); + } + +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h +index 725be3b..846139e 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h +@@ -135,7 +135,10 @@ private: + QList filetype; + QString dev_name; + SEND_DATA_STATE send_state = _SEND_NONE; +- bool is_Intel; ++ bool is_Intel = false; ++ ++ void initLayout(); ++ void initIntelLayout(); + }; + + #endif // BLUETOOTHFILETRANSFERWIDGET_H +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index a241484..a207d61 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -35,6 +35,8 @@ MainProgram::MainProgram(bool intel, QObject *parent) : + connect(_sessionDbus, &BluetoothDbus::devBatteryChangedSignal, this, [=]() { + UI->updatePairedDev(); + }); ++ QStringList file; ++ file.append(QString("file")); + } + + MainProgram::~MainProgram() +@@ -181,8 +183,8 @@ void MainProgram::sendTransferDeviceMesgSlot(QString address) + + if (BluetoothFileTransferWidget::isShow == false) { + fileSendWidget = new BluetoothFileTransferWidget(selectedFiles,_sessionDbus->getPairedDevices(),address); ++ connect(fileSendWidget,&BluetoothFileTransferWidget::destroyed, this,&MainProgram::closeSession); + connect(fileSendWidget,&BluetoothFileTransferWidget::sender_dev_name,this,&MainProgram::sendFiles); +- connect(fileSendWidget,&BluetoothFileTransferWidget::close_the_pre_session,this,&MainProgram::closeSession); + connect(_sessionDbus,&BluetoothDbus::transferredChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::set_m_progressbar_value); + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::get_transfer_status); + connect(fileSendWidget,&BluetoothFileTransferWidget::continueSendFiles,_sessionDbus,&BluetoothDbus::continueSendFiles); +@@ -200,7 +202,7 @@ void MainProgram::sendTransferDeviceMesgSlot(QString address) + delete fileSendWidget; + fileSendWidget = new BluetoothFileTransferWidget(selectedFiles,_sessionDbus->getPairedDevices(),address); + connect(fileSendWidget,&BluetoothFileTransferWidget::sender_dev_name,this,&MainProgram::sendFiles); +- connect(fileSendWidget,&BluetoothFileTransferWidget::close_the_pre_session,this,&MainProgram::closeSession); ++ connect(fileSendWidget,&BluetoothFileTransferWidget::destroyed, this,&MainProgram::closeSession); + connect(_sessionDbus,&BluetoothDbus::transferredChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::set_m_progressbar_value); + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::get_transfer_status); + connect(fileSendWidget,&BluetoothFileTransferWidget::continueSendFiles,_sessionDbus,&BluetoothDbus::continueSendFiles); +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index 53d36ae..2b2b899 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -6,6 +6,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + PINCode(pin), + show_flag(flag) + { ++ is_Intel = QFile::exists("/etc/apt/ota_version"); + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + settings = new QGSettings("org.ukui.style"); + connect(settings,&QGSettings::changed,this,&PinCodeWidget::GSettingsChanges); +@@ -14,41 +15,25 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + //窗管协议 + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; +- hints.functions = MWM_FUNC_ALL; ++ if (is_Intel) ++ hints.functions = MWM_FUNC_CLOSE; ++ else ++ hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); + +- is_Intel = QFile::exists("/etc/apt/ota_version"); + QPalette palette; + if(settings->get("style-name").toString() == "ukui-default" || settings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(255,255,255)); + }else{ + palette.setColor(QPalette::Background,QColor(0,0,0)); + } +-// this->setWindowFlags(Qt::Dialog/*|Qt::FramelessWindowHint*/); + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("Bluetooth pairing")); + this->setAttribute(Qt::WA_DeleteOnClose); + +- QList list = QGuiApplication::screens(); +- this->move(list.at(0)->size().width()/2-this->width()/2,list.at(0)->size().height()/2-this->height()/2); +- + this->setPalette(palette); + this->setAutoFillBackground(true); +- title_icon = new QLabel(this); +- title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); +- title_icon->resize(22,22); +- +- title_text = new QLabel(tr("Bluetooth Connections"),this); +- title_text->setStyleSheet("QLabel{\ +- width: 200px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;}"); +- title_text->adjustSize(); + + //QString top_text = tr("Bluetooth Connect Request From \'")+dev_name+tr("\'."); + QString tip_text; +@@ -100,49 +85,60 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + refuse_btn->setVisible(false); + } + +- close_btn = new QPushButton(this); +- QIcon icon = QIcon::fromTheme("window-close-symbolic"); +- close_btn->setIcon(icon); +- close_btn->setProperty("isWindowButton", 0x2); +- close_btn->setProperty("useIconHighlightEffect", 0x8); +-// close_btn->setProperty("setIconHighlightEffectDefaultColor", QColor(Qt::white)); +- close_btn->setFlat(true); +- connect(close_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_close_btn); +- +- //title_text->setGeometry(36,12,200,20); +- //title_icon->setGeometry(8,12,22,22); +- close_btn->setGeometry(480,8,30,30); +- + if (is_Intel) { +- this->setFixedSize(510, 287); +- title_icon->setGeometry(16,12,24,24); +- title_text->setGeometry(48,12,100,24); +- //top_label->setGeometry(24,60,456,50); +- tip_label->setGeometry(24,72,450,40); ++ this->setWindowFlags(Qt::Dialog); ++ this->setFixedSize(510, 267); + tip_label->setStyleSheet("QLabel{\ + font-size: 16px;\ + font-family: Noto Sans CJK SC;\ + font-weight: 400;\ + line-height: 24px;}"); +- PIN_label->setGeometry(24,136,462,47); +- accept_btn->setGeometry(373,207,112,56); +- refuse_btn->setGeometry(246,207,112,56); +- close_btn->setGeometry(470, 8, 30, 30); ++ + PIN_label->setStyleSheet("QLabel{\ + font-size: 40px;\ + font-family: Noto Sans CJK SC;\ + font-weight: 400;\ + line-height: 24px;}"); ++ ++ tip_label->setGeometry(24,52,450,40); ++ PIN_label->setGeometry(24,116,462,47); ++ accept_btn->setGeometry(373,187,112,56); ++ refuse_btn->setGeometry(246,187,112,56); + } else { + this->setFixedSize(520,212); ++ title_icon = new QLabel(this); ++ title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); ++ title_icon->resize(22,22); ++ ++ title_text = new QLabel(tr("Bluetooth Connections"),this); ++ title_text->setStyleSheet("QLabel{\ ++ width: 200px;\ ++ height: 20px;\ ++ font-size: 14px;\ ++ font-family: Noto Sans CJK SC;\ ++ font-weight: 400;\ ++ line-height: 24px;\ ++ opacity: 1;}"); ++ title_text->adjustSize(); ++ ++ close_btn = new QPushButton(this); ++ QIcon icon = QIcon::fromTheme("window-close-symbolic"); ++ close_btn->setIcon(icon); ++ close_btn->setProperty("isWindowButton", 0x2); ++ close_btn->setProperty("useIconHighlightEffect", 0x8); ++ // close_btn->setProperty("setIconHighlightEffectDefaultColor", QColor(Qt::white)); ++ close_btn->setFlat(true); ++ connect(close_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_close_btn); ++ close_btn->setGeometry(480,8,30,30); + title_icon->setGeometry(8, 8, 22, 22); + title_text->setGeometry(38, 9, 160, 20); + PIN_label->setGeometry(25,90,207,36); + tip_label->setGeometry(25,56,437,40); +- //top_label->setGeometry(32,56,456,50); + accept_btn->setGeometry(362,152,116,36); + refuse_btn->setGeometry(238,152,116,36); + } ++ QList list = QGuiApplication::screens(); ++ this->move(list.at(0)->size().width()/2-this->width()/2,list.at(0)->size().height()/2-this->height()/2); + } + + PinCodeWidget::~PinCodeWidget() diff --git a/patches/fix_three_status_in_settings_label.patch b/patches/fix_three_status_in_settings_label.patch new file mode 100644 index 0000000..a66b1a3 --- /dev/null +++ b/patches/fix_three_status_in_settings_label.patch @@ -0,0 +1,71 @@ +diff --git a/ukui-bluetooth/component/bluetoothsettinglabel.cpp b/ukui-bluetooth/component/bluetoothsettinglabel.cpp +index d5387c9..a46fafb 100644 +--- a/ukui-bluetooth/component/bluetoothsettinglabel.cpp ++++ b/ukui-bluetooth/component/bluetoothsettinglabel.cpp +@@ -35,27 +35,22 @@ QColor BluetoothSettingLabel::getPainterBrushColor() + switch (_MStatus) { + case Status::Normal: + if(StyleSettings->get("style-name").toString() == "ukui-light") +- color = QColor(255,255,255,0); ++ color = QColor(0, 0, 0); + else { +- color = QColor(QPalette::Base); +- color.setAlpha(0); ++ color = QColor(255,255,255); + } + break; + case Status::Hover: +- color = QColor(217,217,217,tran); ++ color = QColor("#2FB3E8"); + break; + case Status::Click: +- if(StyleSettings->get("style-name").toString() == "ukui-light") +- color = QColor(209, 209, 209,tran); +- else +- color = QColor(102, 102, 102, tran); ++ color = QColor("#1699CF"); + break; + default: + if(StyleSettings->get("style-name").toString() == "ukui-light") +- color = QColor(255,255,255,0); ++ color = QColor(0, 0, 0); + else { +- color = QColor(QPalette::Base); +- color.setAlpha(0); ++ color = QColor(255,255,255); + } + break; + } +@@ -64,8 +59,8 @@ QColor BluetoothSettingLabel::getPainterBrushColor() + + void BluetoothSettingLabel::enterEvent(QEvent *event) { + Q_UNUSED(event); +- //_MStatus = Hover; +- _MStatus = Normal; ++ _MStatus = Hover; ++ setCursor(Qt::PointingHandCursor); + this->update(); + } + +@@ -93,14 +88,10 @@ void BluetoothSettingLabel::mouseReleaseEvent(QMouseEvent *ev) { + void BluetoothSettingLabel::paintEvent(QPaintEvent *event) + { + Q_UNUSED(event); +- QPalette pl; +- pl.setColor(QPalette::Background,getPainterBrushColor()); +- this->setPalette(pl); + QPainter painter(this); + painter.save(); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(QColor(Qt::transparent)); +- painter.setBrush(getPainterBrushColor()); + painter.drawRoundedRect(this->rect(),12,12,Qt::AbsoluteSize); + //painter.drawRect(this->rect()); + painter.restore(); +@@ -108,5 +99,6 @@ void BluetoothSettingLabel::paintEvent(QPaintEvent *event) + painter.setPen(QColor(Qt::black)); + else + painter.setPen(QColor(Qt::white)); ++ painter.setPen(getPainterBrushColor()); + painter.drawText(25,10,420,50,Qt::AlignLeft,tr("Bluetooth Settings")); + } diff --git a/patches/fix_transferwidget_has_wrong_show_on_details.patch b/patches/fix_transferwidget_has_wrong_show_on_details.patch new file mode 100644 index 0000000..e807efc --- /dev/null +++ b/patches/fix_transferwidget_has_wrong_show_on_details.patch @@ -0,0 +1,102 @@ +Index: upstream/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ upstream/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -93,7 +93,7 @@ BluetoothFileTransferWidget::BluetoothFi + color: #818181;\ + opacity: 1;\ + }"); +- target_size->setGeometry(112,88,65,30); ++ target_size->setGeometry(112,88,70,30); + + QFontMetrics fontMetrics(target_size->font()); + QString fileName; +@@ -239,19 +239,22 @@ void BluetoothFileTransferWidget::initFi + for (int i = 0; i < fileNums; i++) { + Get_fie_type(i); + } ++ qDebug() << Q_FUNC_INFO << __LINE__; + } + + void BluetoothFileTransferWidget::Get_fie_type(int i) + { + GError *error; + qDebug() << Q_FUNC_INFO << selectedFiles.at(i); +- GFile *file = g_file_new_for_path(selectedFiles.at(0).toStdString().c_str()); ++ GFile *file = g_file_new_for_path(selectedFiles.at(i).toStdString().c_str()); + GFileInfo *file_info = g_file_query_info(file,"*",G_FILE_QUERY_INFO_NONE,NULL,&error); + qDebug() << Q_FUNC_INFO << g_file_info_get_size(file_info) << g_file_info_get_content_type(file_info); ++ qDebug() << Q_FUNC_INFO << __LINE__; + + file_size.push_back(g_format_size_full(g_file_info_get_size(file_info),G_FORMAT_SIZE_IEC_UNITS)); + _filesize.push_back(g_file_info_get_size(file_info)); + QString str = g_file_info_get_content_type(file_info); ++ qDebug() << Q_FUNC_INFO << __LINE__; + QIcon fileicon; + if (str.split("/").at(0) == "image"){ + fileicon = QIcon(selectedFiles.at(i)); +@@ -271,6 +274,7 @@ void BluetoothFileTransferWidget::Get_fi + } + }else + fileicon = QIcon::fromTheme("text"); ++ qDebug() << Q_FUNC_INFO << __LINE__; + file_icon.push_back(fileicon); + } + +@@ -326,6 +330,27 @@ void BluetoothFileTransferWidget::get_tr + file_size.pop_front(); + file_icon.pop_front(); + _filesize.pop_front(); ++ if (selectedFiles.size() == 1) ++ target_name->setText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1)); ++ else if(selectedFiles.size() > 1) ++ { ++ target_name->setText("\"" ++ +selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1) ++ +"\"" ++ +tr(" and ") ++ +QString::number(selectedFiles.size() - 1) ++ +tr(" files more")); ++ } ++ else ++ { ++ tranfer_error(); ++ this->send_state = _SEND_FAILURE ; ++ } ++ init_m_progressbar_value(_filesize.at(0)); ++ target_size->setText(file_size.at(0)); ++ target_icon->setPixmap(file_icon.at(0).pixmap(64,64)); ++ int transfing = fileNums - selectedFiles.size() + 1; ++ transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); + return; + } + selectedFiles.clear(); +@@ -371,28 +396,6 @@ void BluetoothFileTransferWidget::get_tr + this->send_state = _SEND_COMPLETE ; + }else if(status == QString("Active")){ + this->send_state = _SENDING ; +- if (selectedFiles.size() == 1) +- target_name->setText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1)); +- else if(selectedFiles.size() > 1) +- { +- target_name->setText("\"" +- +selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1) +- +"\"" +- +tr(" and ") +- +QString::number(selectedFiles.size() - 1) +- +tr(" files more")); +- } +- else +- { +- tranfer_error(); +- this->send_state = _SEND_FAILURE ; +- } +- +- init_m_progressbar_value(_filesize.at(0)); +- target_size->setText(file_size.at(0)); +- target_icon->setPixmap(file_icon.at(0).pixmap(64,64)); +- int transfing = fileNums - selectedFiles.size() + 1; +- transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); + }else if(status == QString("Error")){ + tranfer_error(); + this->send_state = _SEND_FAILURE ; diff --git a/patches/fix_traywidget_window_frameless.patch b/patches/fix_traywidget_window_frameless.patch new file mode 100644 index 0000000..4286e2e --- /dev/null +++ b/patches/fix_traywidget_window_frameless.patch @@ -0,0 +1,12 @@ +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 67b293e..63e059b 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -11,6 +11,7 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + + // 窗管适配 + if (_Intel) { ++ setProperty("useStyleWindowManager", false); + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; + hints.functions = MWM_FUNC_ALL; diff --git a/patches/fix_ukbt_layout_when_scale_150%.patch b/patches/fix_ukbt_layout_when_scale_150%.patch new file mode 100644 index 0000000..10209c7 --- /dev/null +++ b/patches/fix_ukbt_layout_when_scale_150%.patch @@ -0,0 +1,104 @@ +diff --git a/service/config.cpp b/service/config.cpp +index 272c4ad..dad350b 100644 +--- a/service/config.cpp ++++ b/service/config.cpp +@@ -57,7 +57,9 @@ void Config::LaunchUI() + QProcess *process = new QProcess(); + QString cmd = UIExe; + qDebug() << Q_FUNC_INFO; +- process->startDetached(cmd); ++ QTimer::singleShot(700, process, [=]{ ++ process->startDetached(cmd); ++ }); + } + + QStringList Config::getDeviceConnectTimeList(QString path) +diff --git a/service/config.h b/service/config.h +index 40c2e54..387c8d4 100644 +--- a/service/config.h ++++ b/service/config.h +@@ -10,6 +10,7 @@ + #include + #include + #include ++#include + + class Config : public QObject + { +diff --git a/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm b/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm +index feff98a..cbb66c0 100644 +Binary files a/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm and b/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm differ +diff --git a/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.qm b/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.qm +index 79a3e04..b18d9fc 100644 +Binary files a/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.qm and b/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.qm differ +diff --git a/ukui-bluetooth/component/bluetoothsettinglabel.cpp b/ukui-bluetooth/component/bluetoothsettinglabel.cpp +index 44c6809..33ac0a3 100644 +--- a/ukui-bluetooth/component/bluetoothsettinglabel.cpp ++++ b/ukui-bluetooth/component/bluetoothsettinglabel.cpp +@@ -110,5 +110,5 @@ void BluetoothSettingLabel::paintEvent(QPaintEvent *event) + painter.setPen(QColor(Qt::black)); + else + painter.setPen(QColor(Qt::white)); +- painter.drawText(25,12,420,50,Qt::AlignLeft,tr("Bluetooth Settings")); ++ painter.drawText(25,10,420,50,Qt::AlignLeft,tr("Bluetooth Settings")); + } +diff --git a/ukui-bluetooth/main/main.cpp b/ukui-bluetooth/main/main.cpp +index fce2f06..57d4a1f 100644 +--- a/ukui-bluetooth/main/main.cpp ++++ b/ukui-bluetooth/main/main.cpp +@@ -16,6 +16,12 @@ int main(int argc, char *argv[]) + QtSingleApplication app(argc, argv); + // QApplication::setStyle(QStyleFactory::create("ukui-default")); + QApplication::setQuitOnLastWindowClosed(false); ++ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); ++ QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); ++ ++#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) ++ QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); ++#endif + + if (app.isRunning()) { + qDebug() << "ukui-bluetooth is Already running ! ! !"; +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index e557ada..27f069f 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -21,6 +21,20 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + connect(trayicon, &TrayIcon::openBluetoothSettings, this, [=]{ + _SessionDBus->openBluetoothSettings(); + }); ++ connect(QApplication::desktop(), &QDesktopWidget::resized, this, [=] { ++ setWidgetPosition(); ++ }); ++ connect(QApplication::desktop(), &QDesktopWidget::primaryScreenChanged, this, [=] { ++ setWidgetPosition(); ++ }); ++ ++ QGSettings *setttt = new QGSettings(QString("org.ukui.SettingsDaemon.plugins.xsettings").toLocal8Bit()); ++ connect(setttt,&QGSettings::changed, this, [=] (const QString &key) { ++ if (key == "scalingFactor") { ++ repaint(); ++ } ++ }); ++ + setProperty("useSystemStyleBlur", true); + this->setAttribute(Qt::WA_TranslucentBackground); + this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); +@@ -213,7 +227,7 @@ void TrayWidget::InitMemberVariables() + connect(_MBtn, SIGNAL(checkedChanged(bool)), this, SLOT(openBluetoothSlot(bool))); + + QHBoxLayout *topLayout = new QHBoxLayout(); +- topLayout->setContentsMargins(24,16,25,14); ++ topLayout->setContentsMargins(24,16,25,12); + topLayout->setSpacing(0); + + InitErrorWidget(); +@@ -225,7 +239,7 @@ void TrayWidget::InitMemberVariables() + _MStackedWidget->addWidget(_ErrorWidget); + _MStackedWidget->setCurrentIndex(0); + +- _MLabel->resize(60,28); ++ _MLabel->resize(60,32); + _MLabel->setText(tr("Bluetooth")); + if(StyleSettings->get("style-name").toString() == "ukui-light"){ + _MLabel->setStyleSheet("color:black;"); diff --git a/patches/fix_ukbt_segment_faulse_and_right_click_menu_cannot_open_bluetoothsetting.patch b/patches/fix_ukbt_segment_faulse_and_right_click_menu_cannot_open_bluetoothsetting.patch new file mode 100644 index 0000000..d76f1ca --- /dev/null +++ b/patches/fix_ukbt_segment_faulse_and_right_click_menu_cannot_open_bluetoothsetting.patch @@ -0,0 +1,86 @@ +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 11bf561..0a61b51 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -87,7 +87,8 @@ void BluetoothDbus::devConnectStatusSignalSLot(QString address, bool connected) + + void BluetoothDbus::devNameChangedSignalSLot(QString address, QString name) { + qDebug() << "devNameChangedSignalSLot" << address << name; +- ++ if (!pairedDevice.contains(address)) ++ return; + if (connectedDevice.values().contains(address) + && pairedDevice.keys().contains(address)) { + connectedDevice.remove(pairedDevice.value(address).at(0)); +diff --git a/ukui-bluetooth/mainwidget/trayicon.cpp b/ukui-bluetooth/mainwidget/trayicon.cpp +index dc8f111..197e6cb 100644 +--- a/ukui-bluetooth/mainwidget/trayicon.cpp ++++ b/ukui-bluetooth/mainwidget/trayicon.cpp +@@ -12,6 +12,9 @@ TrayIcon::TrayIcon(QWidget *parent) + tray_Menu = new QMenu(this); + QAction *settins_action = new QAction(QIcon::fromTheme("ukui-settings-symbolic"),tr("Set Bluetooth Item"),tray_Menu); + tray_Menu->addAction(settins_action); ++ connect(tray_Menu, &QMenu::triggered, this, [=]{ ++ emit openBluetoothSettings(); ++ }); + + //Create taskbar tray icon and connect to signal slot + //创建任务栏托盘图标,并连接信号槽 +diff --git a/ukui-bluetooth/mainwidget/trayicon.h b/ukui-bluetooth/mainwidget/trayicon.h +index 313f3bd..f384959 100644 +--- a/ukui-bluetooth/mainwidget/trayicon.h ++++ b/ukui-bluetooth/mainwidget/trayicon.h +@@ -18,6 +18,9 @@ + #include + #include + #include ++#include ++#include ++#include + + using namespace std; + +@@ -26,12 +29,21 @@ class TrayIcon : public QWidget + Q_OBJECT + + public: ++ enum PixmapColor { ++ WHITE = 0, ++ BLACK, ++ GRAY, ++ BLUE, ++ }; ++ Q_ENUM(PixmapColor) ++ + TrayIcon(QWidget *parent = nullptr); + ~TrayIcon(); + void InitTrayWidget(); + + signals: + void showTayWidget(); ++ void openBluetoothSettings(); + + public slots: + void GSettings_value_chanage(const QString &key); +@@ -40,6 +52,7 @@ public slots: + private: + QSystemTrayIcon *bluetooth_tray_icon = nullptr; + QMenu *tray_Menu = nullptr; ++ QGSettings *StyleSettings = nullptr; + QGSettings *settings = nullptr; + } ; + #endif // TRAYICON_H +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 0ee29f6..e557ada 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -18,6 +18,9 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + trayicon = new TrayIcon(); + connect(this, &TrayWidget::trayIconStatusChanged, trayicon, &TrayIcon::SetTrayIcon); + connect(trayicon, &TrayIcon::showTayWidget, this, &TrayWidget::showUI); ++ connect(trayicon, &TrayIcon::openBluetoothSettings, this, [=]{ ++ _SessionDBus->openBluetoothSettings(); ++ }); + setProperty("useSystemStyleBlur", true); + this->setAttribute(Qt::WA_TranslucentBackground); + this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); diff --git a/patches/fix_unsorted_table_in_traywidget_and_upgrade_the_speed_of_open_up.patch b/patches/fix_unsorted_table_in_traywidget_and_upgrade_the_speed_of_open_up.patch new file mode 100644 index 0000000..78675fb --- /dev/null +++ b/patches/fix_unsorted_table_in_traywidget_and_upgrade_the_speed_of_open_up.patch @@ -0,0 +1,238 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 7cb92e5..22fdc0e 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -10,11 +10,6 @@ QDevItem::QDevItem(QString address, QStringList deviceinfo, bool connected, QWid + _MType(deviceinfo.at(1)) + { + initMap(); +- +- if (isHuaWei()) +- _Battery = QString("-1"); +- else +- qDebug() << "This is Normal Machine in Normal Progress."; + qDebug() << " get dev Battery : " << deviceinfo.at(0) << _Battery; + + if(QGSettings::isSchemaInstalled("org.ukui.style")) { +@@ -45,21 +40,6 @@ QDevItem::~QDevItem() + + } + +-bool QDevItem::isHuaWei() { +- QProcess p; +- p.start("bash", QStringList() <<"-c" << "cat /proc/cpuinfo | grep Hardware"); +- p.waitForFinished(); +- QString strResult = p.readAllStandardOutput(); +- +- QString str = strResult.toLower(); +- if(str.length() == 0) +- return false; +- if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || +- str.indexOf("kirin") != -1) +- return true; +- return false; +-} +- + void QDevItem::initMap() { + typeMap = new QMap(); + typeMap->insert(QString("phone"), QIcon::fromTheme("phone-symbolic")); +diff --git a/ukui-bluetooth/component/qdevitem.h b/ukui-bluetooth/component/qdevitem.h +index 642efde..a7156d8 100644 +--- a/ukui-bluetooth/component/qdevitem.h ++++ b/ukui-bluetooth/component/qdevitem.h +@@ -58,7 +58,6 @@ private: + QColor getPainterBrushColor(); + QColor getDevStatusColor(); + QPixmap getDevTypeIcon(); +- bool isHuaWei(); + void initMap(); + void DrawBackground(QPainter &); + void DrawStatusIcon(QPainter &); +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp +index 9c8f208..09f7277 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -4,6 +4,7 @@ BluetoothDbus::BluetoothDbus(QObject *parent) + { + Q_UNUSED(parent); + qDebug() << Q_FUNC_INFO << __LINE__; ++ isHuaWeiFlag = isHuaWei(); + connectDBusSignals(); + getDefaultAdapterPower(); + getDefaultAdapterPairedDevices(); +@@ -84,11 +85,13 @@ void BluetoothDbus::defaultAdapterChangedSLot(QString value) { + void BluetoothDbus::devPairSignalSLot(QString address, bool paired) { + qDebug() << "devPairSignalSLot" << address << paired; + if (paired && !pairedDevice.contains(address)) { ++ pairedList.append(address); + addNewPairedDevice(address); + emit devPairSignal(pairedDevice.value(address).at(0),paired); + } + if (!paired && pairedDevice.contains(address)) { + QString name = pairedDevice.value(address).at(0); ++ pairedList.removeAll(address); + pairedDevice.remove(address); + emit devPairSignal(name, paired); + } +@@ -128,6 +131,8 @@ void BluetoothDbus::devNameChangedSignalSLot(QString address, QString name) { + } + + void BluetoothDbus::devBatteryChangedSignalSLot(QString address, QString battery) { ++ if (isHuaWeiFlag) ++ return; + qDebug() << "devBatteryChangedSignalSLot" << address << battery; + QStringList updateList; + updateList.append(pairedDevice.value(address).at(0)); +@@ -181,7 +186,10 @@ void BluetoothDbus::addNewPairedDevice(QString address) { + QDBusMessage _response3 = CALL_METHOD(_m3); + if (_response3.type() == QDBusMessage::ReplyMessage) + { +- device.append(_response3.arguments().takeFirst().toString()); ++ if (isHuaWeiFlag) ++ device.append(_response3.arguments().takeFirst().toString()); ++ else ++ device.append(QString("-1")); + } + pairedDevice.insert(address, device); + getDevConnectStatus(address); +@@ -386,8 +394,9 @@ void BluetoothDbus::getDefaultAdapterPairedDevices() { + if (response.type() == QDBusMessage::ReplyMessage) + { + QStringList ret = response.arguments().takeFirst().toStringList(); +- ++ qDebug() << ret; + for (int i = 0; i < ret.size(); i++) { ++ pairedList.append(ret.at(i)); + addNewPairedDevice(ret.at(i)); + } + qDebug() << "init paired devices over : " << pairedDevice; +@@ -400,8 +409,11 @@ bool BluetoothDbus::isPowered() { + return powered; + } + ++QList BluetoothDbus::getPairedDevicesList() { ++ return pairedList; ++} ++ + QMap BluetoothDbus::getPairedDevices() { +- getDefaultAdapterPairedDevices(); + return pairedDevice; + } + +@@ -409,3 +421,19 @@ bool BluetoothDbus::isConnected(QString name) { + qDebug() << connectedDevice; + return connectedDevice.keys().contains(name); + } ++ ++ ++bool BluetoothDbus::isHuaWei() { ++ QProcess p; ++ p.start("bash", QStringList() <<"-c" << "cat /proc/cpuinfo | grep Hardware"); ++ p.waitForFinished(); ++ QString strResult = p.readAllStandardOutput(); ++ ++ QString str = strResult.toLower(); ++ if(str.length() == 0) ++ return false; ++ if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || ++ str.indexOf("kirin") != -1) ++ return true; ++ return false; ++} +diff --git a/ukui-bluetooth/daemon/bluetoothdbus.h b/ukui-bluetooth/daemon/bluetoothdbus.h +index 365052f..ba93476 100644 +--- a/ukui-bluetooth/daemon/bluetoothdbus.h ++++ b/ukui-bluetooth/daemon/bluetoothdbus.h +@@ -10,6 +10,7 @@ + #include + #include + #include ++#include + #include + + #define SYSTEMD_SERVICE "com.ukui.bluetooth" +@@ -73,6 +74,7 @@ public: + bool isPowered(); + bool isConnected(QString name); + QMap getPairedDevices(); ++ QList getPairedDevicesList(); + + signals: + void showTrayIcon(bool); +@@ -101,6 +103,9 @@ private: + void connectDBusSignals(); + void addNewPairedDevice(QString address); + bool powered = false; ++ bool isHuaWeiFlag = false; ++ bool isHuaWei(); ++ QList pairedList; + QMap pairedDevice; + QMap connectedDevice; + +diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp +index 67b293e..bc5ae12 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.cpp ++++ b/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -81,7 +81,7 @@ TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("bluetooth")); + pairedDevices = _SessionDBus->getPairedDevices(); +- ++ pairedList = _SessionDBus->getPairedDevicesList(); + InitMemberVariables(); + connectUISignalAndSlot(); + layoutAddPairedDev(); +@@ -390,7 +390,7 @@ void TrayWidget::layoutAddPairedDev() + int count = 0; + qDebug() << Q_FUNC_INFO << pairedDevices.size() << __LINE__; + if (!_PairedWidget->findChildren().size()) { +- for (auto item : pairedDevices.keys()) { ++ for (auto item : pairedList) { + QString name = pairedDevices.value(item).at(0); + _SessionDBus->getDevConnectStatus(item); + QDevItem *dev = new QDevItem(item, pairedDevices.value(item), _SessionDBus->isConnected(name), _PairedWidget); +@@ -428,6 +428,7 @@ void TrayWidget::layoutAddPairedDev() + + void TrayWidget::updatePairedDev() { + pairedDevices = _SessionDBus->getPairedDevices(); ++ pairedList = _SessionDBus->getPairedDevicesList(); + clearPairedWidget(); + layoutAddPairedDev(); + } +@@ -467,8 +468,10 @@ void TrayWidget::clearPairedWidget() + *************************************************/ + void TrayWidget::removePairedDevUIByAddress(QString address) + { +- pairedDevices = _SessionDBus->getPairedDevices(); + qDebug() << Q_FUNC_INFO << pairedDevices << __LINE__; ++ if (!pairedList.contains(address)) ++ return; ++ pairedList.removeAll(address); + if (!pairedDevices.contains(address)) + return; + qDebug() << Q_FUNC_INFO << address << __LINE__; +@@ -480,12 +483,10 @@ void TrayWidget::removePairedDevUIByAddress(QString address) + item = nullptr; + } + pairedDevices.remove(address); +- updatePairedDev(); + } + + void TrayWidget::showUI() + { +- updatePairedDev(); + if (!_Intel) + setWidgetPosition(); + else { +diff --git a/ukui-bluetooth/mainwidget/traywidget.h b/ukui-bluetooth/mainwidget/traywidget.h +index 233910f..3de9ae7 100644 +--- a/ukui-bluetooth/mainwidget/traywidget.h ++++ b/ukui-bluetooth/mainwidget/traywidget.h +@@ -82,6 +82,7 @@ private: + QFrame *lineFrame = nullptr; + QFrame *lineFrame2 = nullptr; + QMap pairedDevices; ++ QList pairedList; + double tran =1; + bool _Intel; + int selfHeight = 0; diff --git a/patches/fix_when_transfer_fail_window_doesnt_activate.patch b/patches/fix_when_transfer_fail_window_doesnt_activate.patch new file mode 100644 index 0000000..64d8917 --- /dev/null +++ b/patches/fix_when_transfer_fail_window_doesnt_activate.patch @@ -0,0 +1,32 @@ +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index 79a27b2..b0a50d1 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -19,7 +19,6 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,&FileReceivingPopupWidget::GSettingsChanges); + } +- + this->setFixedSize(520,276); + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("Bluetooth file transfer")); +@@ -412,6 +411,7 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + file_source->setGeometry(12,150,505,24); + file_source->setAlignment(Qt::AlignCenter); + } ++ this->activateWindow(); + } + } + +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index abf51e9..dcb1262 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -490,6 +490,7 @@ void BluetoothFileTransferWidget::get_transfer_status(QString status) + }else if(status == QString("Error")){ + tranfer_error(); + this->send_state = _SEND_FAILURE ; ++ this->activateWindow(); + } + } + diff --git a/patches/fix_widget_font_size_change.patch b/patches/fix_widget_font_size_change.patch new file mode 100644 index 0000000..77a1389 --- /dev/null +++ b/patches/fix_widget_font_size_change.patch @@ -0,0 +1,436 @@ +diff --git a/debian/ukui-bluetooth.install b/debian/ukui-bluetooth.install +index ffb99d1..b1731a2 100644 +--- a/debian/ukui-bluetooth.install ++++ b/debian/ukui-bluetooth.install +@@ -1,4 +1,5 @@ + ukui-bluetooth/translations/*.qm /usr/share/ukui-bluetooth/translations/ ++data/ukui-bluetooth-tray.desktop /etc/xdg/autostart/ + data/ukui-bluetooth.desktop /etc/xdg/autostart/ + ukcc-bluetooth/translations/*.qm /usr/share/ukui-bluetooth/translations/ + ukcc-bluetooth/translations/*.ts /usr/share/ukui-bluetooth/translations/ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 6dc15a3..824b6c7 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -331,7 +331,7 @@ void Daemon::initBluezManager() + + _DefualtAdapter = this->getDefualtAdapter(); + launchDbusSignal(); +- launchTrayUI(); ++// launchTrayUI(); + + if (nullptr != _DefualtAdapter) + _DefualtAdapter.data()->setPowered(_mGsetting["switch"].toBool()); +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index 8dd0a27..1ec5122 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -83,11 +83,6 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + ft1.setPixelSize(18); + file_source->setFont(ft1); + file_source->setWordWrap(true); +- file_source->setStyleSheet("QLabel{\ +- font-size: 18px;\ +- font-family: PingFangSC-Medium, PingFang SC;\ +- font-weight: 500;\ +- line-height: 25px;}"); + file_source->setWordWrap(true); + + file_icon = new QLabel(this); +@@ -509,4 +504,14 @@ void FileReceivingPopupWidget::GSettingsChanges(const QString &key) + this->setPalette(palette); + this->update(); + } ++ if (key == "systemFontSize") { ++ int size = StyleSettings->get("system-font-size").toInt() - 11; ++ QFont ft; ++ ft.setPixelSize(18 + size); ++ file_source->setFont(ft); ++ ft.setPixelSize(14 + size); ++ file_name->setFont(ft); ++ file_size->setFont(ft); ++ window_Title->setFont(ft); ++ } + } +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index c34e513..9b155c6 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -45,14 +45,12 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + move((deskdop->width()-this->width())/2, (deskdop->height()-this->height())/2); + + tip_text = new QLabel(tr("Transferring to \"")+dev_name+"\"",this); +- tip_text->setStyleSheet("QLabel{\ +- width: 214px;\ +- height: 27px;\ +- font-size: 18px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 500;\ +- line-height: 24px;\ +- opacity: 1;}"); ++ QFont ft_18, ft_14; ++ ft_14.setPixelSize(14); ++ ft_18.setPixelSize(18); ++ ++ tip_text->setFont(ft_18); ++ tip_text->setWordWrap(true); + tip_text->setVisible(false); + + initFileInfo(); +@@ -61,15 +59,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + target_icon->setPixmap(file_icon.at(0).pixmap(64,64)); + + target_size = new QLabel(file_size.at(0),this); +- target_size->setStyleSheet("QLabel{\ +- width: 100px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: NotoSansCJKsc-Regular;\ +- line-height: 24px;\ +- color: #818181;\ +- opacity: 1;\ +- }"); ++ target_size->setFont(ft_14); + + QFontMetrics fontMetrics(target_size->font()); + QString fileName; +@@ -81,29 +71,13 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + }else + fileName = fontMetrics.elidedText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1), Qt::ElideMiddle, 280); + target_name = new QLabel(fileName,this); +- target_name->setStyleSheet("QLabel{\ +- width: 300px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;\ +- }"); ++ target_name->setFont(ft_14); + target_name->setWordWrap(true); + + + transNum = new QLabel("1/"+QString::number(fileNums), this); + transNum->setVisible(false); +- transNum->setStyleSheet("QLabel{\ +- width: 22px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 30px;\ +- opacity: 1;}"); +- ++ transNum->setFont(ft_14); + + m_progressbar = new QProgressBar(this); + m_progressbar->setOrientation(Qt::Horizontal); +@@ -112,14 +86,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + + Tiptop = new QLabel(tr("Select Device"),this); + Tiptop->setFixedSize(100,20); +- Tiptop->setStyleSheet("QLabel{\ +- width: 100px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;}"); ++ Tiptop->setFont(ft_14); + + dev_widget = new DeviceSeleterWidget(devicelist, this,dev_address); + +@@ -153,14 +120,7 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + tranfer_status_text = new QLabel(this); + tranfer_status_text->setText(tr("File Transmission Failed !")); + tranfer_status_text->setVisible(false); +- tranfer_status_text->setStyleSheet("QLabel{\ +- width: 126px;\ +- height: 27px;\ +- font-size: 18px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 500;\ +- line-height: 24px;\ +- opacity: 1;}"); ++ tranfer_status_text->setFont(ft_18); + + if (is_Intel) + initIntelLayout(); +@@ -176,20 +136,16 @@ BluetoothFileTransferWidget::~BluetoothFileTransferWidget() + } + + void BluetoothFileTransferWidget::initLayout() { ++ QFont ft_14; ++ ft_14.setPixelSize(14); ++ + this->setFixedSize(520,620); + title_icon = new QLabel(this); + title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); + title_icon->resize(22,22); + + title_text = new QLabel(tr("Bluetooth file transfer"),this); +- title_text->setStyleSheet("QLabel{\ +- width: 200px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;}"); ++ title_text->setFont(ft_14); + + close_btn = new QPushButton(this); + close_btn->setIcon(QIcon::fromTheme("window-close-symbolic")); +@@ -212,39 +168,27 @@ void BluetoothFileTransferWidget::initLayout() { + dev_widget->setGeometry(32,175,456,356); + Tiptop->setGeometry(32,144,100,20); + target_size->setGeometry(112,88,70,30); +- tip_text->setGeometry(32,52,452,28); ++ tip_text->setGeometry(32,52,452,56); + target_icon->setGeometry(32,56,64,64); + target_name->setGeometry(112,63,400,20); + transNum->setGeometry(459,168,52,20); + if (fileNums > 1) +- m_progressbar->setGeometry(32,175,406,8); ++ m_progressbar->setGeometry(32,185,406,8); + else +- m_progressbar->setGeometry(32,175,454,8); ++ m_progressbar->setGeometry(32,185,454,8); + } + + void BluetoothFileTransferWidget::initIntelLayout() { ++ QFont ft_14; ++ ft_14.setPixelSize(14); + this->setWindowFlags(Qt::Dialog); + this->setFixedSize(478,530); + cancel_btn->setFixedSize(112,56); + ok_btn->setFixedSize(112,56); + target_name->setFixedHeight(23); +- target_name->setStyleSheet("QLabel{\ +- width: 300px;\ +- height: 20px;\ +- font-size: 16px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;}"); ++ target_name->setFont(ft_14); + target_size->setFixedWidth(68); +- target_size->setStyleSheet("QLabel{\ +- width: 100px;\ +- height: 20px;\ +- font-size: 16px;\ +- font-family: NotoSansCJKsc-Regular;\ +- line-height: 24px;\ +- color: #818181;\ +- opacity: 1;}"); ++ target_size->setFont(ft_14); + dev_widget->resize(430,296); + ok_btn->setGeometry(342,450,112,56); + cancel_btn->setGeometry(214,450,112,56); +@@ -253,7 +197,7 @@ void BluetoothFileTransferWidget::initIntelLayout() { + dev_widget->setGeometry(24,139,430,296); + Tiptop->setGeometry(32,111,100,20); + target_size->setGeometry(104,60,70,30); +- tip_text->setGeometry(32,32,452,28); ++ tip_text->setGeometry(32,32,452,56); + target_icon->setGeometry(24,24,64,64); + target_name->setGeometry(104,28,400,20); + transNum->setGeometry(410,148,52,20); +@@ -350,9 +294,9 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + target_size->setGeometry(104,103,68,30); + } else { + cancel_btn->setGeometry(376, 213, 100, 36); +- target_icon->setGeometry(32,95,64,64); +- target_name->setGeometry(112,102,400,20); +- target_size->setGeometry(112,127,68,30); ++ target_icon->setGeometry(32,105,64,64); ++ target_name->setGeometry(112,112,400,20); ++ target_size->setGeometry(112,137,68,30); + } + + main_animation_group = new QParallelAnimationGroup(this); +@@ -448,9 +392,9 @@ void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { + m_progressbar->setGeometry(24,155,420,8); + else + if (fileNums > 1) +- m_progressbar->setGeometry(32,175,406,8); ++ m_progressbar->setGeometry(32,185,406,8); + else +- m_progressbar->setGeometry(32,175,454,8); ++ m_progressbar->setGeometry(32,185,454,8); + transNum->setVisible(fileNums - 1); + this->update(); + this->activateWindow(); +@@ -511,12 +455,9 @@ void BluetoothFileTransferWidget::get_transfer_status(QString status) + tranfer_status_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-success.svg")); + tranfer_status_text->setText(tr("File Transmition Succeed!")); + tranfer_status_text->setFixedWidth(500); +- tranfer_status_text->setStyleSheet("QLabel{\ +- font-family: NotoSansCJKsc;\ +- font-size: 16px;\ +- line-height: 19px;\ +- text-align: center;\ +- color: #0FCE75;}"); ++ QFont ft; ++ ft.setPixelSize(16); ++ tranfer_status_text->setFont(ft); + if (is_Intel) { + tranfer_status_icon->setGeometry(207,57,64,64); + tranfer_status_text->setGeometry(191,129,200,24); +@@ -561,12 +502,9 @@ void BluetoothFileTransferWidget::tranfer_error() + tranfer_status_icon->setFixedSize(64,64); + tranfer_status_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-failed.svg")); + tranfer_status_text->setFixedWidth(500); +- tranfer_status_text->setStyleSheet("QLabel{\ +- font-family: NotoSansCJKsc;\ +- font-size: 16px;\ +- line-height: 19px;\ +- text-align: center;\ +- color: #FB5050;}"); ++ QFont ft; ++ ft.setPixelSize(16); ++ tranfer_status_text->setFont(ft); + tranfer_status_icon->setGeometry(207,57,64,64); + tranfer_status_text->setGeometry(191,129,200,24); + } +@@ -606,6 +544,19 @@ void BluetoothFileTransferWidget::GSettingsChanges(const QString &key) + this->setPalette(palette); + this->update(); + } ++ if (key == "systemFontSize") { ++ int size = GSettings->get("system-font-size").toInt() - 11; ++ QFont ft; ++ ft.setPixelSize(14+size); ++ title_text->setFont(ft); ++ target_size->setFont(ft); ++ target_name->setFont(ft); ++ transNum->setFont(ft); ++ Tiptop->setFont(ft); ++ ft.setPixelSize(18+size); ++ tip_text->setFont(ft); ++ tranfer_status_text->setFont(ft); ++ } + } + + void BluetoothFileTransferWidget::onClicked_OK_Btn() +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index 7b2f0ca..6fa5890 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -57,21 +57,20 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + // line-height: 24px;}"); + //top_label->setWordWrap(true); + ++ QFont ft_14, ft_16, ft_20, ft_24, ft_40; ++ int ft_size = settings->get("system-font-size").toInt() - 11; ++ ft_14.setPixelSize(14 + ft_size); ++ ft_16.setPixelSize(16 + ft_size); ++ ft_20.setPixelSize(20 + ft_size); ++ ft_24.setPixelSize(24 + ft_size); ++ ft_40.setPixelSize(40 + ft_size); + tip_label = new QLabel(tip_text,this); +- tip_label->setStyleSheet("QLabel{\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;}"); ++ tip_label->setFont(ft_14); + tip_label->setWordWrap(true); + tip_label->setToolTip(dev_name); + + PIN_label = new QLabel(PINCode,this); +- PIN_label->setStyleSheet("QLabel{\ +- font-size: 24px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;}"); ++ PIN_label->setFont(ft_24); + + accept_btn = new QPushButton(tr("Connect"),this); + +@@ -84,25 +83,15 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + connect(accept_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_close_btn); + accept_btn->setText(tr("Confirm")); + accept_btn->adjustSize(); +- //accept_btn->setVisible(false); ++ //accept_btn->setddVisible(false); + refuse_btn->setVisible(false); + } + + if (is_Intel) { + this->setWindowFlags(Qt::Dialog); + this->setFixedSize(510, 239); +- tip_label->setStyleSheet("QLabel{\ +- font-size: 16px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;}"); +- +- PIN_label->setStyleSheet("QLabel{\ +- font-size: 40px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;}"); +- ++ tip_label->setFont(ft_16); ++ PIN_label->setFont(ft_40); + tip_label->setGeometry(24,24,450,40); + PIN_label->setGeometry(24,88,462,47); + accept_btn->setGeometry(374,159,112,56); +@@ -114,14 +103,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + title_icon->resize(22,22); + + title_text = new QLabel(tr("Bluetooth Connections"),this); +- title_text->setStyleSheet("QLabel{\ +- width: 200px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;}"); ++ title_text->setFont(ft_14); + title_text->adjustSize(); + + close_btn = new QPushButton(this); +@@ -136,7 +118,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + title_icon->setGeometry(8, 8, 22, 22); + title_text->setGeometry(38, 9, 160, 20); + PIN_label->setGeometry(25,90,207,36); +- tip_label->setGeometry(25,56,437,40); ++ tip_label->setGeometry(25,56,437,44); + accept_btn->setGeometry(388,152,108,36); + refuse_btn->setGeometry(264,152,108,36); + } +@@ -194,7 +176,10 @@ void PinCodeWidget::updateUIInfo(const QString &name, const QString &pin) + tip_label->setToolTip(name); + } + if(show_flag) +- tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); ++ if (is_Intel) ++ tip_text = tr("If the PIN on \'")+Name+tr("\' is the same as this PIN. Please press \'Connect\'"); ++ else ++ tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + else + tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair:")).arg(Name); + tip_label->setText(tip_text); +@@ -239,6 +224,16 @@ void PinCodeWidget::GSettingsChanges(const QString &key) + palette.setColor(QPalette::Background,QColor(Qt::black)); + } + } ++ if (key == "systemFontSize") { ++ int size = settings->get("system-font-size").toInt() - 11; ++ qDebug() << Q_FUNC_INFO << size; ++ QFont ft, ft1; ++ ft.setPixelSize(14 + size); ++ tip_label->setFont(ft); ++ title_text->setFont(ft); ++ ft1.setPixelSize(24 + size); ++ PIN_label->setFont(ft1); ++ } + this->setPalette(palette); + this->update(); + } diff --git a/patches/fix_wrong_click_color_in_circle_icon.patch b/patches/fix_wrong_click_color_in_circle_icon.patch new file mode 100644 index 0000000..a890223 --- /dev/null +++ b/patches/fix_wrong_click_color_in_circle_icon.patch @@ -0,0 +1,81 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 8f8ad08..a3c9611 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -76,7 +76,7 @@ void QDevItem::InitMemberVariables() + void QDevItem::enterEvent(QEvent *event) + { + Q_UNUSED(event); +- ++ _leaved = false; + _MStatus = Status::Hover; + update(); + } +@@ -84,7 +84,7 @@ void QDevItem::enterEvent(QEvent *event) + void QDevItem::leaveEvent(QEvent *event) + { + Q_UNUSED(event); +- ++ _leaved = true; + _MStatus = Status::Nomal; + update(); + } +@@ -94,12 +94,17 @@ void QDevItem::mousePressEvent(QMouseEvent *event) + if (event->button() == Qt::LeftButton) { + _pressFlag = true; + _MStatus = Status::Click; ++ this->update(); + } + } + + void QDevItem::mouseReleaseEvent(QMouseEvent *event) + { + if (event->button() == Qt::LeftButton && _pressFlag) { ++ if (_leaved) ++ _MStatus = Status::Nomal; ++ else ++ _MStatus = Status::Hover; + MouseClickedFunc(); + } + } +@@ -169,12 +174,23 @@ QColor QDevItem::getDevStatusColor() + { + QColor color; + if (_Connected) { +- color = QColor("#2FB3E8"); +- } else { +- if(StyleSettings->get("style-name").toString() == "ukui-light") +- color = QColor("#EBEBEB"); ++ if (_MStatus == Status::Click) ++ color = QColor("#1699CF"); + else +- color = QColor(55, 55, 59); ++ color = QColor("#2FB3E8"); ++ } else { ++ if(StyleSettings->get("style-name").toString() == "ukui-light") { ++ if (_MStatus == Status::Click) ++ color = QColor("#E0E0E0"); ++ else ++ color = QColor("#EFEFEF"); ++ } else { ++ if (_MStatus == Status::Click) ++ color = QColor("#444444"); ++ else ++ color = QColor("#666666"); ++ } ++ color.setAlpha(tran); + } + + return color; +diff --git a/ukui-bluetooth/component/qdevitem.h b/ukui-bluetooth/component/qdevitem.h +index c5d3b4d..837f992 100644 +--- a/ukui-bluetooth/component/qdevitem.h ++++ b/ukui-bluetooth/component/qdevitem.h +@@ -71,6 +71,7 @@ private: + bool _pressFlag; + int iconFlag = 7; + bool _Connected; ++ bool _leaved = false; + + QTimer *_iconTimer = nullptr; + BluezQt::DevicePtr _MDev = nullptr; diff --git a/patches/fix_wrong_icon_in_classic_icon_theme.patch b/patches/fix_wrong_icon_in_classic_icon_theme.patch new file mode 100644 index 0000000..d305bdd --- /dev/null +++ b/patches/fix_wrong_icon_in_classic_icon_theme.patch @@ -0,0 +1,19 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index a3c9611..adc2c9c 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -268,8 +268,12 @@ void QDevItem::DrawStatusIcon(QPainter &painter) + painter.setPen(QColor(Qt::black)); + batteryPixmap = getDevTypeIcon(); + } else { +- painter.setPen(QColor(Qt::white)); +- batteryPixmap = loadSvg(getDevTypeIcon(), PixmapColor::WHITE); ++ if (StyleSettings->get("icon-theme-name").toString() == "ukui-classical") ++ batteryPixmap = getDevTypeIcon(); ++ else { ++ painter.setPen(QColor(Qt::white)); ++ batteryPixmap = loadSvg(getDevTypeIcon(), PixmapColor::WHITE); ++ } + } + + style()->drawItemPixmap(&painter, QRect(25, 16, 18, 18), Qt::AlignCenter, batteryPixmap); diff --git a/patches/fixed_bug_101081.patch b/patches/fixed_bug_101081.patch new file mode 100644 index 0000000..f5531fa --- /dev/null +++ b/patches/fixed_bug_101081.patch @@ -0,0 +1,57 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index d02f9e2..84a63a9 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -19,6 +19,7 @@ const QString INTERFACE = "com.ukui.bluetooth"; + static qint64 blockChangeTime = 0; + qint64 powerChangeTime = 0; + bool resetFlag = false; ++bool rebootFlag = false; + + /************************************************ + * @brief 判断是否存在给定的程序启动参数 +@@ -272,6 +273,14 @@ void Daemon::initBluezManager() + if (operational) { + qInfo() << Q_FUNC_INFO << "Bluez Manager restart"; + registerBluezAgent(); ++ } else { ++ if (_DefualtAdapter) { ++ if (abs(QDateTime::currentMSecsSinceEpoch() - ::powerChangeTime) >= 300) { ++ ::rebootFlag = true; ++ } else { ++ ::rebootFlag = false; ++ } ++ } + } + }); + +diff --git a/service/daemon.h b/service/daemon.h +index 8a34d31..db57eab 100644 +--- a/service/daemon.h ++++ b/service/daemon.h +@@ -42,6 +42,7 @@ + + extern qint64 powerChangeTime; + extern bool resetFlag; ++extern bool rebootFlag; + + enum DevOperate { + PAIR = 0, +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index aef72e9..052bd6b 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -749,11 +749,12 @@ void SessionDbusRegister::connectSignal() + // if (powered) + Daemon::reconnectFunc(); + +- if (::resetFlag) { ++ if (::resetFlag || ::rebootFlag) { + QTimer::singleShot(100,this,[=]{ + Daemon::_DefualtAdapter.data()->setPowered(false); + }); + ::resetFlag = false; ++ ::rebootFlag = false; + } + + Config::gsetting->set("switch",QVariant(powered)); diff --git a/patches/fixed_bug_89263.patch b/patches/fixed_bug_89263.patch new file mode 100644 index 0000000..6b6d0f6 --- /dev/null +++ b/patches/fixed_bug_89263.patch @@ -0,0 +1,438 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 01aebcc..d029650 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -1,5 +1,7 @@ + #include "sessiondbusregister.h" + ++static bool isScan = false; ++ + static inline bool isAvailableAddress(QString addr) { + if (addr.isEmpty() || addr.isNull()) + return false; +@@ -42,12 +44,10 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << __LINE__; + +- static bool isScan = false; +- + if (dev) + { + if (Daemon::_DefualtAdapter.data()->isDiscovering()) { +- isScan = true; ++ ::isScan = true; + Daemon::_DefualtAdapter.data()->stopDiscovery(); + } + +@@ -65,7 +65,7 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + dev.data()->type() == BluezQt::Device::Headset ) { + + BluezQt::PendingCall *pending = dev.data()->disconnectFromDevice(); +- connect(pending,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *call){ ++ connect(pending,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ + if (!call->error()) { + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ +@@ -74,7 +74,7 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + emit devOperateErrorSignal(dev.data()->address()); + } + +- if (isScan) { ++ if (::isScan) { + Daemon::_DefualtAdapter.data()->startDiscovery(); + } + }); +@@ -88,13 +88,13 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + } + //当没有任何音频设备连接,最后再连接目标设备 + BluezQt::PendingCall *call = dev.data()->connectToDevice(); +- connect(call,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *callReturn){ ++ connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } + +- if (isScan) { ++ if (::isScan) { + Daemon::_DefualtAdapter.data()->startDiscovery(); + } + }); +@@ -103,13 +103,13 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + qDebug () << Q_FUNC_INFO << dev.data()->type() << __LINE__; + + BluezQt::PendingCall *call = dev.data()->connectToDevice(); +- connect(call,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *callReturn){ ++ connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } + +- if (isScan) { ++ if (::isScan) { + Daemon::_DefualtAdapter.data()->startDiscovery(); + } + +@@ -548,6 +548,7 @@ void SessionDbusRegister::connectSignal() + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoveringChanged,this,[=](bool status){ + qDebug() << Q_FUNC_INFO << "discoveringChanged" << __LINE__; ++// ::isScan = status; + emit defaultScanStatusChanged(status); + }); + +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index b7650fc..7bd5476 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -424,10 +424,12 @@ void BlueToothMain::refreshBluetoothAdapterInterfaceUI() + { + _MCentralWidget->setCurrentWidget(m_normal_main_widget); + } +- if(frame_2->isVisible()) ++ if(frame_2->isVisible()) { + frame_2->setVisible(false); +- frame_top->setMinimumSize(582,187); +- frame_top->setMaximumSize(1800,187); ++ line_frame2->setVisible(false); ++ } ++ frame_top->setMinimumSize(582,217); ++ frame_top->setMaximumSize(1800,217); + } + else if (m_adapter_address_list.size() > 1) + { +@@ -437,8 +439,8 @@ void BlueToothMain::refreshBluetoothAdapterInterfaceUI() + } + if(!frame_2->isVisible()) + frame_2->setVisible(true); +- frame_top->setMinimumSize(582,239); +- frame_top->setMaximumSize(1800,239); ++ frame_top->setMinimumSize(582,279); ++ frame_top->setMaximumSize(1800,279); + } + else + { +@@ -775,6 +777,8 @@ void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) + //setDefaultAdapterScanOn(true); + }); + m_myDev_show_flag = true; ++ ++ mDevFrameAddLineFrame("paired",device->getDevAddress()); + paired_dev_layout->addWidget(item,Qt::AlignTop); + } + return; +@@ -859,6 +863,7 @@ void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) + delayStartDiscover_timer->start(); + }); + ++ mDevFrameAddLineFrame("other",device->getDevAddress()); + device_list_layout->insertWidget(0,item,0,Qt::AlignTop); + + last_discovery_device_address << device->getDevAddress(); +@@ -1336,13 +1341,13 @@ void BlueToothMain::showBluetoothNormalMainWindow() + if ((m_adapter_address_list.size() > 1) && + (m_adapter_address_list.size() == m_adapter_name_list.size()))//用什么作为适配数量的判断 + { +- frame_top->setMinimumSize(582,239); +- frame_top->setMaximumSize(1800,239); ++ frame_top->setMinimumSize(582,279); ++ frame_top->setMaximumSize(1800,279); + } + else + { +- frame_top->setMinimumSize(582,187); +- frame_top->setMaximumSize(1800,187); ++ frame_top->setMinimumSize(582,217); ++ frame_top->setMaximumSize(1800,217); + } + + frame_middle = new QWidget(m_normal_main_widget); +@@ -1380,18 +1385,28 @@ void BlueToothMain::initMainWindowTopUI() + top_layout->setContentsMargins(0,0,0,0); + top_layout->addWidget(label_1); + +- QVBoxLayout *layout = new QVBoxLayout(); ++ QFrame *top_frame = new QFrame(frame_top); ++ top_frame->setMinimumWidth(582); ++ top_frame->setFrameShape(QFrame::Shape::Box); ++ top_layout->addWidget(top_frame); ++ ++ QVBoxLayout *layout = new QVBoxLayout(top_frame); + layout->setSpacing(2); + layout->setContentsMargins(0,0,0,0); +- top_layout->addLayout(layout); + +- QFrame *frame_1 = new QFrame(frame_top); ++ QFrame *frame_1 = new QFrame(top_frame); + frame_1->setMinimumWidth(582); + frame_1->setFrameShape(QFrame::Shape::Box); +- frame_1->setFixedHeight(50); ++ frame_1->setFixedHeight(60); + frame_1->setAutoFillBackground(true); + layout->addWidget(frame_1); + ++ QFrame *line_frame1 = new QFrame(top_frame); ++ line_frame1->setFixedHeight(1); ++ line_frame1->setMinimumWidth(582); ++ line_frame1->setFrameStyle(QFrame::HLine); ++ layout->addWidget(line_frame1); ++ + QHBoxLayout *frame_1_layout = new QHBoxLayout(frame_1); + frame_1_layout->setSpacing(10); + frame_1_layout->setContentsMargins(16,0,16,0); +@@ -1416,13 +1431,21 @@ void BlueToothMain::initMainWindowTopUI() + + frame_1_layout->addWidget(m_open_bluetooth_btn); + +- frame_2 = new QFrame(frame_top); ++ line_frame2 = new QFrame(top_frame); ++ line_frame2->setFixedHeight(1); ++ line_frame2->setMinimumWidth(582); ++ line_frame2->setFrameStyle(QFrame::HLine); ++ ++ frame_2 = new QFrame(top_frame); + frame_2->setMinimumWidth(582); + frame_2->setFrameShape(QFrame::Shape::Box); +- frame_2->setFixedHeight(50); +- if(m_adapter_address_list.size() <= 1) +- frame_2->setVisible(false); ++ frame_2->setFixedHeight(60); + layout->addWidget(frame_2); ++ layout->addWidget(line_frame2); ++ if(m_adapter_address_list.size() <= 1) { ++ frame_2->setVisible(false); ++ line_frame2->setVisible(false); ++ } + + QHBoxLayout *frame_2_layout = new QHBoxLayout(frame_2); + frame_2_layout->setSpacing(10); +@@ -1446,12 +1469,18 @@ void BlueToothMain::initMainWindowTopUI() + connect(m_adapter_list_cmbox,SIGNAL(currentIndexChanged(int)),this,SLOT(adapterComboxChanged(int))); + frame_2_layout->addWidget(m_adapter_list_cmbox); + +- QFrame *frame_3 = new QFrame(frame_top); ++ QFrame *frame_3 = new QFrame(top_frame); + frame_3->setMinimumWidth(582); + frame_3->setFrameShape(QFrame::Shape::Box); +- frame_3->setFixedHeight(50); ++ frame_3->setFixedHeight(60); + layout->addWidget(frame_3); + ++ QFrame *line_frame3 = new QFrame(top_frame); ++ line_frame3->setFixedHeight(1); ++ line_frame3->setMinimumWidth(582); ++ line_frame3->setFrameStyle(QFrame::HLine); ++ layout->addWidget(line_frame3); ++ + QHBoxLayout *frame_3_layout = new QHBoxLayout(frame_3); + frame_3_layout->setSpacing(10); + frame_3_layout->setContentsMargins(16,0,16,0); +@@ -1479,10 +1508,10 @@ void BlueToothMain::initMainWindowTopUI() + } + connect(m_show_panel_btn,&SwitchButton::checkedChanged,this,&BlueToothMain::setTrayVisible); + +- QFrame *frame_4 = new QFrame(frame_top); ++ QFrame *frame_4 = new QFrame(top_frame); + frame_4->setMinimumWidth(582); + frame_4->setFrameShape(QFrame::Shape::Box); +- frame_4->setFixedHeight(50); ++ frame_4->setFixedHeight(60); + layout->addWidget(frame_4); + + QHBoxLayout *frame_4_layout = new QHBoxLayout(frame_4); +@@ -1517,16 +1546,21 @@ void BlueToothMain::initMainWindowMiddleUI() + middle_layout->setSpacing(8); + middle_layout->setContentsMargins(0,0,0,0); + +- paired_dev_layout = new QVBoxLayout(); +- paired_dev_layout->setSpacing(2); +- paired_dev_layout->setContentsMargins(0,0,0,0); +- + TitleLabel *middle_label = new TitleLabel(frame_middle); + middle_label->setText(tr("My Devices")); + middle_label->resize(72,25); + ++ QFrame *mDev_frame = new QFrame(frame_middle); ++ mDev_frame->setObjectName("mDev_frame"); ++ mDev_frame->setMinimumWidth(582); ++ mDev_frame->setFrameShape(QFrame::Shape::Box); ++ ++ paired_dev_layout = new QVBoxLayout(mDev_frame); ++ paired_dev_layout->setSpacing(2); ++ paired_dev_layout->setContentsMargins(0,0,0,0); ++ + middle_layout->addWidget(middle_label,Qt::AlignTop); +- middle_layout->addLayout(paired_dev_layout,Qt::AlignTop); ++ middle_layout->addWidget(mDev_frame,Qt::AlignTop); + + frame_middle->setLayout(middle_layout); + } +@@ -1595,7 +1629,10 @@ void BlueToothMain::initMainWindowbottomUI() + bottom_layout->setContentsMargins(0,0,0,0); + bottom_layout->addLayout(title_layout); + +- device_list = new QWidget(); ++ device_list = new QFrame(); ++ device_list->setObjectName("device_list"); ++ device_list->setMinimumWidth(582); ++ device_list->setFrameShape(QFrame::Shape::Box); + + bottom_layout->addWidget(device_list); + +@@ -1722,10 +1759,20 @@ void BlueToothMain::changeDeviceParentWindow(const QString &address) + } + + DeviceInfoItem *item = device_list->findChild(address); ++ QFrame *line_item = device_list->findChild("line-"+address); + if(item){ + device_list_layout->removeWidget(item); + item->setParent(frame_middle); ++ ++ if(line_item) { ++ device_list_layout->removeWidget(line_item); ++ line_item->setParent(NULL); ++ line_item->deleteLater(); ++ } ++ ++ mDevFrameAddLineFrame("paired",address); + paired_dev_layout->addWidget(item); ++ + }else{ + return; + } +@@ -1797,11 +1844,18 @@ void BlueToothMain::removeDeviceItemUI(QString address) + //if(last_discovery_device_address.indexOf(address) != -1) + //{ + DeviceInfoItem *item = device_list->findChild(address); ++ QFrame *line_item = device_list->findChild("line-"+address); + if(item) + { + device_list_layout->removeWidget(item); + item->setParent(NULL); + item->deleteLater(); ++ ++ if(line_item) { ++ device_list_layout->removeWidget(line_item); ++ line_item->setParent(NULL); ++ line_item->deleteLater(); ++ } + //m_discovery_device_address_all_list.removeAll(address); + //last_discovery_device_address.removeAll(address); + } +@@ -1814,10 +1868,21 @@ void BlueToothMain::removeDeviceItemUI(QString address) + //}else{ + //DeviceInfoItem *item = frame_middle->findChild(address); + item = frame_middle->findChild(address); ++ line_item = frame_middle->findChild("line-"+address); + if(item){ ++ ++ + paired_dev_layout->removeWidget(item); + item->setParent(NULL); + item->deleteLater(); ++ ++ if (line_item) { ++ paired_dev_layout->removeWidget(line_item); ++ line_item->setParent(NULL); ++ line_item->deleteLater(); ++ } else ++ removeMDevFrameLineFrame("paired"); ++ + qDebug() << Q_FUNC_INFO << "frame_middle->children().size()" << frame_middle->children().size(); + if(frame_middle->children().size() == 2) + { +@@ -2024,6 +2089,67 @@ void BlueToothMain::adapterComboxChanged(int i) + qDebug() << Q_FUNC_INFO << "end"; + } + ++void BlueToothMain::mDevFrameAddLineFrame(QString str,QString addr) ++{ ++ qDebug() << Q_FUNC_INFO << "#########################" << addr; ++ ++ if ("paired" == str) { ++ ++ if (!frame_middle->findChildren().size()) { ++ return; ++ } ++ ++ QFrame *line_frame = new QFrame(mDev_frame); ++ line_frame->setObjectName("line-"+addr); ++ line_frame->setFixedHeight(1); ++ line_frame->setMinimumWidth(582); ++ line_frame->setFrameStyle(QFrame::HLine); ++ paired_dev_layout->addWidget(line_frame,Qt::AlignTop); ++ ++ } else if ("other" == str) { ++ ++ if (!frame_bottom->findChildren().size()) { ++ return; ++ } ++ ++ QFrame *line_frame = new QFrame(device_list); ++ line_frame->setObjectName("line-"+addr); ++ line_frame->setFixedHeight(1); ++ line_frame->setMinimumWidth(582); ++ line_frame->setFrameStyle(QFrame::HLine); ++ device_list_layout->insertWidget(0,line_frame,Qt::AlignTop); ++ ++ } else { ++ return; ++ } ++} ++ ++void BlueToothMain::removeMDevFrameLineFrame(QString str) ++{ ++ qDebug() << Q_FUNC_INFO ; ++ ++ if ("paired" == str) { ++ ++ if ((frame_middle->findChildren().size() - frame_middle->findChildren().size() - 2) == frame_middle->findChildren().size()) { ++ QLayoutItem *child; ++ if ((child = paired_dev_layout->takeAt(0)) != 0) { ++ if (child->widget()->objectName().startsWith("line-")) { ++ ++ child->widget()->setParent(NULL); ++ ++ delete child; ++ child = nullptr; ++ } ++ } ++ } ++ ++ } else if ("other" == str) { ++ ++ } else { ++ return; ++ } ++} ++ + void BlueToothMain::cleanPairDevices() + { + QLayoutItem *child; +diff --git a/ukcc-bluetooth/bluetoothmain.h b/ukcc-bluetooth/bluetoothmain.h +index 8cba45e..32de960 100644 +--- a/ukcc-bluetooth/bluetoothmain.h ++++ b/ukcc-bluetooth/bluetoothmain.h +@@ -115,8 +115,10 @@ private: + QVBoxLayout * errorWidgetLayout = nullptr; + QLabel * errorWidgetIcon = nullptr; + QLabel * errorWidgetTip0 = nullptr; ++ QFrame * line_frame2 = nullptr; ++ QFrame * mDev_frame = nullptr; + +- QWidget * device_list = nullptr; ++ QFrame * device_list = nullptr; + QWidget * paired_device_list = nullptr; + QVBoxLayout * device_list_layout = nullptr; + BluetoothNameLabel * bluetooth_name = nullptr; +@@ -175,7 +177,8 @@ private: + QTimer * delayStartDiscover_timer = nullptr; + + private: +- ++ void mDevFrameAddLineFrame(QString,QString); ++ void removeMDevFrameLineFrame(QString); + void monitorBluetoothDbusConnection(); + void removeDeviceItemUI(QString address); + void addMyDeviceItemUI(bluetoothdevice *); diff --git a/patches/fixed_bug_93037.patch b/patches/fixed_bug_93037.patch new file mode 100644 index 0000000..aa80ffd --- /dev/null +++ b/patches/fixed_bug_93037.patch @@ -0,0 +1,125 @@ +diff --git a/patches/series b/patches/series +index f389773..4a3f45a 100644 +--- a/patches/series ++++ b/patches/series +@@ -24,3 +24,4 @@ ukcc_bluetooth_more_adapter.patch + ukcc_bluetooth_ui_error.patch + huawei_connect_back_strategy.patch + fixed_bug_89263.patch ++fixed_bug_93037.patch +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 94e72db..9342c48 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -642,13 +642,14 @@ void Daemon::launchDbusSignal() + + void Daemon::reconnectFunc() + { +- if (!_mGsetting["switch"].toBool()) { +- qInfo() << Q_FUNC_INFO << "Adapter is power down;"; +- return; +- } +- + qInfo() << Q_FUNC_INFO << "START"; + QTimer::singleShot(400,this,[=]{ ++ ++ if (!_DefualtAdapter.data()->isPowered()) { ++ qInfo() << Q_FUNC_INFO << "Adapter is power down;"; ++ return; ++ } ++ + QStringList target_list = Config::getDeviceConnectTimeList(QString("/etc/pairDevice.list")); + qInfo() << "reconnect dev list" << target_list; + qDebug() << Q_FUNC_INFO << target_list; +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index d029650..e8f186b 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -42,7 +42,7 @@ bool SessionDbusRegister::InterfaceAlreadyExists() + + void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { +- qDebug () << Q_FUNC_INFO << __LINE__; ++ qDebug () << Q_FUNC_INFO << "START" << __LINE__; + + if (dev) + { +@@ -57,15 +57,19 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + + BluezQt::AdapterPtr MDevAdapter = dev.data()->adapter(); + +- for (auto dev : MDevAdapter.data()->devices()) { ++ for (auto tmpdev : MDevAdapter.data()->devices()) { ++ qDebug () << Q_FUNC_INFO << "=======================" << tmpdev.data()->name() << __LINE__; ++ if (tmpdev.data()->isConnected() && tmpdev.data()->isPaired()) { ++ if (tmpdev.data()->type() == BluezQt::Device::AudioVideo || ++ tmpdev.data()->type() == BluezQt::Device::Headphones || ++ tmpdev.data()->type() == BluezQt::Device::Headset ) { + +- if (dev.data()->isConnected() && dev.data()->isPaired()) { +- if (dev.data()->type() == BluezQt::Device::AudioVideo || +- dev.data()->type() == BluezQt::Device::Headphones || +- dev.data()->type() == BluezQt::Device::Headset ) { ++ qDebug () << Q_FUNC_INFO << "==================disconn=====" << tmpdev.data()->name() << __LINE__; + +- BluezQt::PendingCall *pending = dev.data()->disconnectFromDevice(); ++ BluezQt::PendingCall *pending = tmpdev.data()->disconnectFromDevice(); ++ qDebug () << Q_FUNC_INFO << "=======================" << __LINE__; + connect(pending,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ ++ qDebug () << Q_FUNC_INFO << "=================conn======" << dev.data()->name() << call << __LINE__; + if (!call->error()) { + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ +@@ -73,7 +77,7 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } +- ++ qDebug () << Q_FUNC_INFO << "===================conn====" << dev.data()->name() << " ok" << __LINE__; + if (::isScan) { + Daemon::_DefualtAdapter.data()->startDiscovery(); + } +@@ -88,6 +92,7 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + } + //当没有任何音频设备连接,最后再连接目标设备 + BluezQt::PendingCall *call = dev.data()->connectToDevice(); ++ + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { +@@ -116,6 +121,8 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + }); + } + } ++ ++ qDebug () << Q_FUNC_INFO << "END" << __LINE__; + } + + bool SessionDbusRegister::getBluetoothBlock() +@@ -548,7 +555,7 @@ void SessionDbusRegister::connectSignal() + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoveringChanged,this,[=](bool status){ + qDebug() << Q_FUNC_INFO << "discoveringChanged" << __LINE__; +-// ::isScan = status; ++ ::isScan = status; + emit defaultScanStatusChanged(status); + }); + +@@ -566,7 +573,7 @@ void SessionDbusRegister::connectSignal() + + connect(devPtr.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << devPtr.data()->address() << +- v << devPtr.data()->isPaired() << devPtr->isConnected(); ++ v << devPtr.data()->isPaired() << devPtr->isConnected() << devPtr.data()->name(); + emit devConnectStatusSignal(devPtr.data()->address(),v); + + if (v && devPtr.data()->isPaired()) { +@@ -606,7 +613,7 @@ void SessionDbusRegister::connectSignal() + + connect(dev.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << dev.data()->address() << +- v << dev.data()->isPaired() << dev->isConnected(); ++ v << dev.data()->isPaired() << dev->isConnected() << dev.data()->name(); + emit devConnectStatusSignal(dev.data()->address(),v); + + if (v && dev.data()->isPaired()) { diff --git a/patches/fixed_bug_94862_66894.patch b/patches/fixed_bug_94862_66894.patch new file mode 100644 index 0000000..0c5752e --- /dev/null +++ b/patches/fixed_bug_94862_66894.patch @@ -0,0 +1,116 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 9342c48..4c42016 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -319,7 +319,7 @@ void Daemon::initBluezManager() + + _DefualtAdapter = getDefualtAdapter(); + qDebug() << Q_FUNC_INFO << _DefualtAdapter.data()->name(); +- ++ launchDbusSignal(); + }); + + connect(_BluezManager,&BluezQt::Manager::bluetoothOperationalChanged,this,[=](bool operational){ +@@ -574,7 +574,6 @@ void Daemon::monitorSleepSlot(bool sleep) + QTimer::singleShot(200,this,[=]{ + _DefualtAdapter = getDefualtAdapter(); + launchDbusSignal(); +- + }); + + reconnectFunc(); +@@ -637,7 +636,6 @@ void Daemon::launchDbusSignal() + QDBusInterface interface(SERVICE,PATH,INTERFACE,QDBusConnection::sessionBus()); + interface.call("connectSignal"); + qDebug() << Q_FUNC_INFO << "end"; +- + } + + void Daemon::reconnectFunc() +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index e8f186b..99e140c 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -187,7 +187,8 @@ QString SessionDbusRegister::getAdapterNameByAddr(QString addr) + void SessionDbusRegister::setDefaultAdapterScanOn(bool scanon) + { + if (!Daemon::_DefualtAdapter.isNull()) { +- BluezQt::PendingCall *call = nullptr; ++// BluezQt::PendingCall *call = nullptr; ++ ::isScan = scanon; + if (scanon) { + Daemon::_DefualtAdapter.data()->startDiscovery(); + } else { +@@ -555,7 +556,6 @@ void SessionDbusRegister::connectSignal() + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoveringChanged,this,[=](bool status){ + qDebug() << Q_FUNC_INFO << "discoveringChanged" << __LINE__; +- ::isScan = status; + emit defaultScanStatusChanged(status); + }); + +@@ -565,7 +565,7 @@ void SessionDbusRegister::connectSignal() + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::deviceAdded,this,[=](BluezQt::DevicePtr devPtr){ +- qDebug() << Q_FUNC_INFO << "deviceAdded:" << devPtr->address() << ";line = "<< __LINE__ ; ++ qInfo() << Q_FUNC_INFO << "deviceAdded:" << devPtr->address() << ";line = "<< __LINE__ ; + emit deviceScanResult(devPtr.data()->address(),devPtr.data()->name(),BluezQt::Device::typeToString(devPtr.data()->type())); + + //清空信号,防止重复连接 +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 7bd5476..a88c72f 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -1546,10 +1546,17 @@ void BlueToothMain::initMainWindowMiddleUI() + middle_layout->setSpacing(8); + middle_layout->setContentsMargins(0,0,0,0); + ++ ++ QHBoxLayout *label_layout = new QHBoxLayout(); ++ label_layout->setSpacing(0); ++ label_layout->setContentsMargins(16,0,0,0); ++ + TitleLabel *middle_label = new TitleLabel(frame_middle); + middle_label->setText(tr("My Devices")); + middle_label->resize(72,25); + ++ label_layout->addWidget(middle_label); ++ + QFrame *mDev_frame = new QFrame(frame_middle); + mDev_frame->setObjectName("mDev_frame"); + mDev_frame->setMinimumWidth(582); +@@ -1559,7 +1566,7 @@ void BlueToothMain::initMainWindowMiddleUI() + paired_dev_layout->setSpacing(2); + paired_dev_layout->setContentsMargins(0,0,0,0); + +- middle_layout->addWidget(middle_label,Qt::AlignTop); ++ middle_layout->addLayout(label_layout,Qt::AlignTop); + middle_layout->addWidget(mDev_frame,Qt::AlignTop); + + frame_middle->setLayout(middle_layout); +@@ -1569,7 +1576,7 @@ void BlueToothMain::initMainWindowbottomUI() + { + QHBoxLayout *title_layout = new QHBoxLayout(); + title_layout->setSpacing(10); +- title_layout->setContentsMargins(0,0,10,0); ++ title_layout->setContentsMargins(16,0,16,0); + + TitleLabel *label_1 = new TitleLabel(frame_bottom); + //~ contents_path /bluetooth/Other Devices +diff --git a/ukcc-bluetooth/ukcc-bluetooth_zh_CN.qm b/ukcc-bluetooth/ukcc-bluetooth_zh_CN.qm +index 16fcf52..a0272fd 100644 +Binary files a/ukcc-bluetooth/ukcc-bluetooth_zh_CN.qm and b/ukcc-bluetooth/ukcc-bluetooth_zh_CN.qm differ +diff --git a/ukcc-bluetooth/ukcc-bluetooth_zh_CN.ts b/ukcc-bluetooth/ukcc-bluetooth_zh_CN.ts +index 9ca4f2e..1c9482c 100644 +--- a/ukcc-bluetooth/ukcc-bluetooth_zh_CN.ts ++++ b/ukcc-bluetooth/ukcc-bluetooth_zh_CN.ts +@@ -40,7 +40,7 @@ + + + Other Devices +- 蓝牙设备 ++ 其他设备 + /bluetooth/Other Devices + + diff --git a/patches/fixed_bug_97056.patch b/patches/fixed_bug_97056.patch new file mode 100644 index 0000000..f570676 --- /dev/null +++ b/patches/fixed_bug_97056.patch @@ -0,0 +1,26 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 4a1213e..9cafd28 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -756,7 +756,7 @@ void SessionDbusRegister::connectSignal() + ::resetFlag = false; + } + +- Config::gsetting->set("switch",QVariant(powered)); ++ Config::gsetting->set("switch",QVariant(powered)); + + emit defaultAdapterPowerChanged(powered); + }); +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index e243a86..0615cd3 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -2142,7 +2142,7 @@ void BlueToothMain::mDevFrameAddLineFrame(QString str,QString addr) + + if ("paired" == str) { + +- if (frame_middle->findChildren().size() < 1) { ++ if (frame_middle->findChildren().size() <= 1) { + return; + } + diff --git a/patches/font_size_shown_in_traywidget.patch b/patches/font_size_shown_in_traywidget.patch new file mode 100644 index 0000000..51c9a1a --- /dev/null +++ b/patches/font_size_shown_in_traywidget.patch @@ -0,0 +1,30 @@ +Index: upstream/ukui-bluetooth/component/qdevitem.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/component/qdevitem.cpp ++++ upstream/ukui-bluetooth/component/qdevitem.cpp +@@ -289,21 +289,21 @@ void QDevItem::DrawBattery(QPainter &pai + return; + + painter.save(); +- ++ battery = 100; + QString batteryIcon = QString("battery-level-") + QString::number(battery / 10 * 10) + QString("-symbolic"); + QString batteryString = _Battery + QString("%"); + QPixmap batteryPixmap; + + if(StyleSettings->get("style-name").toString() == "ukui-light") { + painter.setPen(QColor(Qt::black)); +- batteryPixmap = QIcon::fromTheme(batteryIcon).pixmap(20,20); ++ batteryPixmap = loadSvg(QIcon::fromTheme(batteryIcon).pixmap(20,20), PixmapColor::BLACK); + } else { + painter.setPen(QColor(Qt::white)); + batteryPixmap = loadSvg(QIcon::fromTheme(batteryIcon).pixmap(20,20), PixmapColor::WHITE); + } + +- painter.drawText(348,12,40,28,Qt::AlignLeft, batteryString); +- style()->drawItemPixmap(&painter, QRect(324, 14, 20, 20), Qt::AlignCenter, batteryPixmap); ++ painter.drawText(344,12,52,28,Qt::AlignLeft, batteryString); ++ style()->drawItemPixmap(&painter, QRect(320, 14, 20, 20), Qt::AlignCenter, batteryPixmap); + painter.restore(); + } + diff --git a/patches/huawei_connect_back_strategy.patch b/patches/huawei_connect_back_strategy.patch new file mode 100644 index 0000000..6e6a288 --- /dev/null +++ b/patches/huawei_connect_back_strategy.patch @@ -0,0 +1,97 @@ +diff --git a/data/org.ukui.bluetooth.gschema.xml b/data/org.ukui.bluetooth.gschema.xml +index 0ee300c..20da8c3 100644 +--- a/data/org.ukui.bluetooth.gschema.xml ++++ b/data/org.ukui.bluetooth.gschema.xml +@@ -1,7 +1,7 @@ + + + +- false ++ true + bluetooth switch + bluetooth switch + +diff --git a/qtsingleapplication/qtsingleapplication.pri b/qtsingleapplication/qtsingleapplication.pri +index 6f2bced..1d85285 100644 +--- a/qtsingleapplication/qtsingleapplication.pri ++++ b/qtsingleapplication/qtsingleapplication.pri +@@ -1,4 +1,3 @@ +-include(../common.pri) + INCLUDEPATH += $$PWD + DEPENDPATH += $$PWD + QT *= network +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 3debe7c..01aebcc 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -41,8 +41,16 @@ bool SessionDbusRegister::InterfaceAlreadyExists() + void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << __LINE__; ++ ++ static bool isScan = false; ++ + if (dev) + { ++ if (Daemon::_DefualtAdapter.data()->isDiscovering()) { ++ isScan = true; ++ Daemon::_DefualtAdapter.data()->stopDiscovery(); ++ } ++ + if (dev.data()->type() == BluezQt::Device::AudioVideo || + dev.data()->type() == BluezQt::Device::Headphones || + dev.data()->type() == BluezQt::Device::Headset ) { +@@ -65,6 +73,10 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } ++ ++ if (isScan) { ++ Daemon::_DefualtAdapter.data()->startDiscovery(); ++ } + }); + } + }); +@@ -76,22 +88,31 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + } + //当没有任何音频设备连接,最后再连接目标设备 + BluezQt::PendingCall *call = dev.data()->connectToDevice(); +- connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ connect(call,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } ++ ++ if (isScan) { ++ Daemon::_DefualtAdapter.data()->startDiscovery(); ++ } + }); + } else { + + qDebug () << Q_FUNC_INFO << dev.data()->type() << __LINE__; + + BluezQt::PendingCall *call = dev.data()->connectToDevice(); +- connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ connect(call,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } ++ ++ if (isScan) { ++ Daemon::_DefualtAdapter.data()->startDiscovery(); ++ } ++ + }); + } + } +@@ -378,7 +399,7 @@ qint64 SessionDbusRegister::getDevBattery(const QString addr) + #endif + + QString SessionDbusRegister::getDevName(const QString addr) +-{ ++{ + if (addr.isEmpty() || addr.isNull() || Daemon::_DefualtAdapter.isNull()) + return ""; + diff --git a/patches/modify_intel_UI.patch b/patches/modify_intel_UI.patch new file mode 100644 index 0000000..7b1cf0d --- /dev/null +++ b/patches/modify_intel_UI.patch @@ -0,0 +1,607 @@ +diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp +index 89d9655..87985ba 100644 +--- a/ukui-bluetooth/component/qdevitem.cpp ++++ b/ukui-bluetooth/component/qdevitem.cpp +@@ -209,7 +209,7 @@ QPixmap QDevItem::getDevTypeIcon() + } else { + switch (_Type) { + case BluezQt::Device::Phone: +- icon = QIcon::fromTheme("phone"); ++ icon = QIcon::fromTheme("phone-symbolic"); + break; + case BluezQt::Device::Computer: + icon = QIcon::fromTheme("computer-symbolic"); +@@ -230,7 +230,7 @@ QPixmap QDevItem::getDevTypeIcon() + icon = QIcon::fromTheme("input-mouse-symbolic"); + break; + default: +- icon = QIcon::fromTheme("bluetooth-active-symbolic"); ++ icon = QIcon::fromTheme("bluetooth-symbolic"); + break; + } + } +diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +index d229165..998611e 100644 +--- a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -72,7 +72,10 @@ FileReceivingPopupWidget::FileReceivingPopupWidget(QString devname, QString file + } + }else + fileicon = QIcon::fromTheme("text"); +- file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); ++ if (isIntel) ++ file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive..."),this); ++ else ++ file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); + file_source->setAlignment(Qt::AlignTop); + QFont ft; + ft.setPixelSize(14); +@@ -197,20 +200,20 @@ void FileReceivingPopupWidget::initLayout() { + + void FileReceivingPopupWidget::initIntelLayout() { + this->setWindowFlags(Qt::Dialog); +- this->setFixedSize(520,256); ++ this->setFixedSize(478,280); + QFont ft; + ft.setPixelSize(16); + file_size->setFont(ft); + file_name->setFont(ft); + +- accept_btn->setGeometry(390,185,112,56); +- cancel_btn->setGeometry(262,185,112,56); +- file_name->setGeometry(112,91,293,23); +- file_size->setGeometry(112,116,293,23); +- view_btn->setGeometry(390,195,120,36); +- file_source->setGeometry(32,32,460,54); +- file_icon->setGeometry(32,84,64,64); +- transfer_progress->setGeometry(32,164,454,8); ++ accept_btn->setGeometry(342,200,112,56); ++ cancel_btn->setGeometry(214,200,112,56); ++ file_name->setGeometry(104,71,293,23); ++ file_size->setGeometry(104,103,293,23); ++ view_btn->setGeometry(342,200,120,36); ++ file_source->setGeometry(24,24,460,54); ++ file_icon->setGeometry(24,67,64,64); ++ transfer_progress->setGeometry(24,155,430,8); + warn_icon->setGeometry(32,34,22,22); + } + +@@ -329,7 +332,7 @@ void FileReceivingPopupWidget::OnClickedAcceptBtn() + QPropertyAnimation *cancel_btn_action = new QPropertyAnimation(cancel_btn,"pos"); + cancel_btn_action->setStartValue(cancel_btn->geometry().topLeft()); + if (isIntel) +- cancel_btn_action->setEndValue(QPoint(374,205)); ++ cancel_btn_action->setEndValue(QPoint(342,200)); + else + cancel_btn_action->setEndValue(QPoint(390,215)); + cancel_btn_action->setDuration(100); +@@ -429,17 +432,15 @@ void FileReceivingPopupWidget::file_transfer_completed(QString status) + if (isIntel) { + warn_icon->setFixedSize(64,64); + warn_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-failed.svg")); +- warn_icon->setGeometry(220,66,64,64); + file_source->setText(tr("File Transmission Failed !")); +- file_source->setFixedWidth(505); + file_source->setStyleSheet("QLabel{\ + font-family: NotoSansCJKsc;\ + font-size: 16px;\ + line-height: 19px;\ + text-align: center;\ + color: #FB5050;}"); +- file_source->setGeometry(12,130,505,24); +- file_source->setAlignment(Qt::AlignCenter); ++ warn_icon->setGeometry(207,57,64,64); ++ file_source->setGeometry(191,129,200,24); + } + this->activateWindow(); + } +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index 68ccfc0..c34e513 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -122,7 +122,6 @@ BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap + opacity: 1;}"); + + dev_widget = new DeviceSeleterWidget(devicelist, this,dev_address); +- dev_widget->resize(456,356); + + ok_btn = new QPushButton(tr("OK"),this); + ok_btn->setFixedSize(100,36); +@@ -202,6 +201,7 @@ void BluetoothFileTransferWidget::initLayout() { + emit close_the_pre_session(); + this->close(); + }); ++ dev_widget->resize(456,356); + title_icon->setGeometry(8,8,22,22); + title_text->setGeometry(36,8,200,20); + close_btn->setGeometry(484,4,30,30); +@@ -224,7 +224,7 @@ void BluetoothFileTransferWidget::initLayout() { + + void BluetoothFileTransferWidget::initIntelLayout() { + this->setWindowFlags(Qt::Dialog); +- this->setFixedSize(520,600); ++ this->setFixedSize(478,530); + cancel_btn->setFixedSize(112,56); + ok_btn->setFixedSize(112,56); + target_name->setFixedHeight(23); +@@ -245,21 +245,22 @@ void BluetoothFileTransferWidget::initIntelLayout() { + line-height: 24px;\ + color: #818181;\ + opacity: 1;}"); +- ok_btn->setGeometry(376,525,112,56); +- cancel_btn->setGeometry(240,525,112,56); ++ dev_widget->resize(430,296); ++ ok_btn->setGeometry(342,450,112,56); ++ cancel_btn->setGeometry(214,450,112,56); + tranfer_status_text->setGeometry(62,33,376,27); + tranfer_status_icon->setGeometry(32,35,22,22); +- dev_widget->setGeometry(32,155,456,356); +- Tiptop->setGeometry(32,124,100,20); +- target_size->setGeometry(112,68,70,30); ++ dev_widget->setGeometry(24,139,430,296); ++ Tiptop->setGeometry(32,111,100,20); ++ target_size->setGeometry(104,60,70,30); + tip_text->setGeometry(32,32,452,28); +- target_icon->setGeometry(32,36,64,64); +- target_name->setGeometry(112,43,400,20); +- transNum->setGeometry(459,148,52,20); ++ target_icon->setGeometry(24,24,64,64); ++ target_name->setGeometry(104,28,400,20); ++ transNum->setGeometry(410,148,52,20); + if (fileNums > 1) +- m_progressbar->setGeometry(32,155,406,8); ++ m_progressbar->setGeometry(24,155,372,8); + else +- m_progressbar->setGeometry(32,155,454,8); ++ m_progressbar->setGeometry(24,155,420,8); + } + + void BluetoothFileTransferWidget::initFileInfo() { +@@ -343,10 +344,10 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + dev_widget->setVisible(false); + tip_text->setVisible(true); + if (is_Intel) { +- cancel_btn->setGeometry(376, 185, 112, 56); +- target_icon->setGeometry(32,75,64,64); +- target_name->setGeometry(112,62,400,20); +- target_size->setGeometry(112,107,68,30); ++ cancel_btn->setGeometry(342, 200, 112, 56); ++ target_icon->setGeometry(24,67,64,64); ++ target_name->setGeometry(104,71,400,20); ++ target_size->setGeometry(104,103,68,30); + } else { + cancel_btn->setGeometry(376, 213, 100, 36); + target_icon->setGeometry(32,95,64,64); +@@ -366,7 +367,10 @@ void BluetoothFileTransferWidget::Initialize_and_start_animation() + main_animation_group->addAnimation(progress_action); + main_animation_group->start(); + connect(main_animation_group,&QParallelAnimationGroup::finished,this,[=]{ +- this->setFixedSize(520,276); ++ if (is_Intel) ++ this->setFixedSize(478,280); ++ else ++ this->setFixedSize(520,276); + }); + } + +@@ -439,9 +443,9 @@ void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { + transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); + if (is_Intel) + if (fileNums > 1) +- m_progressbar->setGeometry(32,155,406,8); ++ m_progressbar->setGeometry(24,155,372,8); + else +- m_progressbar->setGeometry(32,155,454,8); ++ m_progressbar->setGeometry(24,155,420,8); + else + if (fileNums > 1) + m_progressbar->setGeometry(32,175,406,8); +@@ -513,10 +517,9 @@ void BluetoothFileTransferWidget::get_transfer_status(QString status) + line-height: 19px;\ + text-align: center;\ + color: #0FCE75;}"); +- tranfer_status_text->setAlignment(Qt::AlignCenter); + if (is_Intel) { +- tranfer_status_icon->setGeometry(220,66,64,64); +- tranfer_status_text->setGeometry(12,130,500,24); ++ tranfer_status_icon->setGeometry(207,57,64,64); ++ tranfer_status_text->setGeometry(191,129,200,24); + } else { + tranfer_status_icon->setGeometry(220,86,64,64); + tranfer_status_text->setGeometry(12,150,500,24); +@@ -557,7 +560,6 @@ void BluetoothFileTransferWidget::tranfer_error() + if (is_Intel){ + tranfer_status_icon->setFixedSize(64,64); + tranfer_status_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-failed.svg")); +- tranfer_status_icon->setGeometry(220,66,64,64); + tranfer_status_text->setFixedWidth(500); + tranfer_status_text->setStyleSheet("QLabel{\ + font-family: NotoSansCJKsc;\ +@@ -565,8 +567,8 @@ void BluetoothFileTransferWidget::tranfer_error() + line-height: 19px;\ + text-align: center;\ + color: #FB5050;}"); +- tranfer_status_text->setGeometry(12,130,500,24); +- tranfer_status_text->setAlignment(Qt::AlignCenter); ++ tranfer_status_icon->setGeometry(207,57,64,64); ++ tranfer_status_text->setGeometry(191,129,200,24); + } + + tranfer_status_icon->setVisible(true); +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index 2b2b899..b1e0951 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -43,7 +43,10 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + Name.append("..."); + } + if(show_flag) { +- tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); ++ if (is_Intel) ++ tip_text = tr("If the PIN on \'")+Name+tr("\' is the same as this PIN. Please press \'Connect\'"); ++ else ++ tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + } else + tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair:")).arg(Name); + //top_label = new QLabel(top_text,this); +@@ -87,7 +90,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + + if (is_Intel) { + this->setWindowFlags(Qt::Dialog); +- this->setFixedSize(510, 267); ++ this->setFixedSize(510, 239); + tip_label->setStyleSheet("QLabel{\ + font-size: 16px;\ + font-family: Noto Sans CJK SC;\ +@@ -100,10 +103,10 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + font-weight: 400;\ + line-height: 24px;}"); + +- tip_label->setGeometry(24,52,450,40); +- PIN_label->setGeometry(24,116,462,47); +- accept_btn->setGeometry(373,187,112,56); +- refuse_btn->setGeometry(246,187,112,56); ++ tip_label->setGeometry(24,24,450,40); ++ PIN_label->setGeometry(24,88,462,47); ++ accept_btn->setGeometry(374,159,112,56); ++ refuse_btn->setGeometry(246,159,112,56); + } else { + this->setFixedSize(520,212); + title_icon = new QLabel(this); +@@ -134,8 +137,8 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + title_text->setGeometry(38, 9, 160, 20); + PIN_label->setGeometry(25,90,207,36); + tip_label->setGeometry(25,56,437,40); +- accept_btn->setGeometry(362,152,116,36); +- refuse_btn->setGeometry(238,152,116,36); ++ accept_btn->setGeometry(400,152,116,36); ++ refuse_btn->setGeometry(288,152,116,36); + } + QList list = QGuiApplication::screens(); + this->move(list.at(0)->size().width()/2-this->width()/2,list.at(0)->size().height()/2-this->height()/2); +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm +index 93a563c..8ae5966 100644 +Binary files a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm and b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm differ +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +index 7eaba2d..76f0d1d 100644 +--- a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts ++++ b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +@@ -4,61 +4,61 @@ + + BluetoothFileTransferWidget + +- +- ++ ++ + Bluetooth file transfer + 蓝牙文件 + + +- +- ++ ++ + Transferring to " + 发送文件至 " + + +- +- +- ++ ++ ++ + and + + + +- +- +- ++ ++ ++ + files more + 个文件 + + +- ++ + Select Device + 选择设备 + + +- +- +- ++ ++ ++ + OK + 确定 + + +- ++ + Cancel + 取消 + + +- ++ + File Transmission Failed ! + 文件发送失败! + + +- +- ++ ++ + File Transmition Succeed! + 文件发送成功! + + +- ++ + Close + 关闭 + +@@ -66,7 +66,7 @@ + + BluetoothSettingLabel + +- ++ + Bluetooth Settings + 蓝牙设置 + +@@ -97,72 +97,78 @@ + + FileReceivingPopupWidget + +- ++ + Bluetooth file transfer + 蓝牙文件传输 + + +- ++ + Bluetooth File + 蓝牙文件 + + +- +- +- +- ++ ++ ++ ++ ++ + File from " + 文件来自 " + + +- ++ ++ ", waiting for receive... ++ ",等待接收... ++ ++ ++ + ", waiting for receive. + ",等待接收。 + + +- ++ + Cancel + 取消 + + +- ++ + Accept + 接收 + + +- ++ + View + 查看 + + +- ++ + ", is receiving... (has recieved + ",正在接收… (已接收 + + +- ++ + files) + 个文件) + + +- ++ + ", is receiving... + ",正在接收… + + +- ++ + OK + 确定 + + +- ++ + ", received failed ! + ",接收失败! + + +- ++ + File Transmission Failed ! +- 文件发送失败! ++ 文件传输失败! + + + +@@ -176,12 +182,12 @@ + + MainProgram + +- ++ + Warning + 提示 + + +- ++ + The selected file is empty, please select the file again ! + 所选文件为空,请重新选择! + +@@ -189,80 +195,58 @@ + + PinCodeWidget + +- ++ + Bluetooth pairing + 蓝牙设备配对 + + +- Bluetooth Connect Request From ' +- 蓝牙连接请求来自 " +- +- +- '. +- "。 +- +- +- If you want to pair with this device, please make sure the numbers below are the same with the devices. +- 若要连接此设备,请确认下面的数字与该设备上的一致。 +- +- +- Please make sure the PIN code displayed on ' +- 如果 " ++ ++ ' is the same as this PIN. Please press 'Connect' ++ ”上的数字与下面相同,请点击“连接” + + +- ' matches the number below. Please press 'Connect'. +- " 上的PIN码与此PIN码相同,请按 "连接"。 +- +- +- Please enter the following PIN code on the bluetooth device '%1' and press enter to pair ! +- 请在蓝牙设备 "%1" 上输入相同PIN,并按"Enter"确认: +- +- +- ++ + + If ' + 如果 " + + +- ++ + Bluetooth Connections + 蓝牙连接 + + +- ++ + + ' the PIN on is the same as this PIN. Please press 'Connect'. + " 上的PIN码与此PIN码相同,请按 "连接"。 + + +- ++ ++ If the PIN on ' ++ 如“ ++ ++ ++ + + Please enter the following PIN code on the bluetooth device '%1' and press enter to pair: + 请在蓝牙设备 "%1" 上输入相同PIN,并按"Enter"确认: + + +- ++ + Confirm + 确定 + + +- Please enter the following PIN code on the bluetooth device '%1' and press enter to pair +- 请在蓝牙设备 "%1" 上输入相同PIN,并按"Enter"确认: +- +- +- ++ + Connect + 连接 + + +- ++ + Refush + 取消 + +- +- confirm +- 确定 +- + + + +@@ -313,17 +297,17 @@ + + TrayWidget + +- ++ + bluetooth + 蓝牙 + + +- ++ + Bluetooth + 蓝牙 + + +- ++ + My Device + 我的设备 + diff --git a/patches/namechanged_error_and_fileReceive_wrong_UI.patch b/patches/namechanged_error_and_fileReceive_wrong_UI.patch new file mode 100644 index 0000000..13acd9d --- /dev/null +++ b/patches/namechanged_error_and_fileReceive_wrong_UI.patch @@ -0,0 +1,309 @@ +Index: ukui-bluetooth/ukui-bluetooth/daemon/bluetoothdbus.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ ukui-bluetooth/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -86,7 +86,13 @@ void BluetoothDbus::devConnectStatusSign + } + + void BluetoothDbus::devNameChangedSignalSLot(QString address, QString name) { +- qDebug() << "devNameChangedSignalSLot" << address << name ; ++ qDebug() << "devNameChangedSignalSLot" << address << name; ++ ++ if (connectedDevice.values().contains(address) ++ && pairedDevice.keys().contains(address)) { ++ connectedDevice.remove(pairedDevice.value(address).at(0)); ++ } ++ getDevConnectStatus(address); + QStringList updateList; + updateList.append(name); + updateList.append(pairedDevice.value(address).at(1)); +@@ -153,6 +159,7 @@ void BluetoothDbus::addNewPairedDevice(Q + device.append(_response3.arguments().takeFirst().toString()); + } + pairedDevice.insert(address, device); ++ getDevConnectStatus(address); + } + + void BluetoothDbus::sendFiles(QString address, QString filename) { +@@ -281,17 +288,18 @@ void BluetoothDbus::getDevConnectStatus( + if (response.type() == QDBusMessage::ReplyMessage) + { + bool connected = response.arguments().takeFirst().toBool(); +- if (connected +- && !connectedDevice.values().contains(address) +- && pairedDevice.keys().contains(address)) ++ if (connected && pairedDevice.keys().contains(address)) { ++ if (connectedDevice.values().contains(address)) ++ connectedDevice.remove(connectedDevice.key(address)); + connectedDevice.insert(pairedDevice.value(address).at(0), address); ++ } + if (!connected + && connectedDevice.values().contains(address) + && pairedDevice.keys().contains(address)) + connectedDevice.remove(pairedDevice.value(address).at(0)); +- qDebug() << "init powered over : " << powered; ++ qDebug() << "init connect status : " << connected << address; + } else { +- qDebug() << " powered method called failed!"; ++ qDebug() << " init connect status method called failed!"; + } + } + +@@ -372,5 +380,6 @@ QMap BluetoothDbus + } + + bool BluetoothDbus::isConnected(QString name) { ++ qDebug() << connectedDevice; + return connectedDevice.keys().contains(name); + } +Index: ukui-bluetooth/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ ukui-bluetooth/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -73,7 +73,7 @@ FileReceivingPopupWidget::FileReceivingP + }); + + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); +- file_source->setGeometry(32,52,500,54); ++ file_source->setGeometry(32,52,460,54); + file_source->setAlignment(Qt::AlignTop); + QFont ft1; + ft1.setPixelSize(18); +Index: ukui-bluetooth/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ ukui-bluetooth/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -37,6 +37,9 @@ BluetoothFileTransferWidget::BluetoothFi + this->setPalette(palette); + this->setAutoFillBackground(true); + ++ QDesktopWidget *deskdop = QApplication::desktop(); ++ move((deskdop->width()-this->width())/2, (deskdop->height()-this->height())/2); ++ + title_icon = new QLabel(this); + title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); + title_icon->resize(22,22); +Index: ukui-bluetooth/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h ++++ ukui-bluetooth/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h +@@ -15,6 +15,8 @@ + #include + #include "deviceseleterwidget.h" + ++#include ++#include + #include + #include + #include +Index: ukui-bluetooth/service/sessiondbusregister.cpp +=================================================================== +--- ukui-bluetooth.orig/service/sessiondbusregister.cpp ++++ ukui-bluetooth/service/sessiondbusregister.cpp +@@ -76,6 +76,7 @@ void SessionDbusRegister::AudioDevConnec + if (!call->error()) { + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } +@@ -91,6 +92,7 @@ void SessionDbusRegister::AudioDevConnec + //当没有任何音频设备连接,最后再连接目标设备 + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } +@@ -101,6 +103,7 @@ void SessionDbusRegister::AudioDevConnec + + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } +@@ -565,8 +568,8 @@ void SessionDbusRegister::connectSignal( + }); + + connect(devPtr.data(),&BluezQt::Device::rssiChanged,this,[=](bool v){ +- qDebug() << Q_FUNC_INFO << "rssiChanged" << devPtr.data()->address() << " val = " << +- devPtr->rssi() << ";line = "<< __LINE__ ; ++ //qDebug() << Q_FUNC_INFO << "rssiChanged" << devPtr.data()->address() << " val = " << ++ ;// devPtr->rssi() << ";line = "<< __LINE__ ; + }); + + connect(devPtr.data(),&BluezQt::Device::typeChanged,this,[=](BluezQt::Device::Type type){ +@@ -604,8 +607,8 @@ void SessionDbusRegister::connectSignal( + }); + + connect(dev.data(),&BluezQt::Device::rssiChanged,this,[=](bool v){ +- qDebug() << Q_FUNC_INFO << "rssiChanged" << dev.data()->address() << " val = " << +- dev->rssi() << ";line = "<< __LINE__ ; ++ //qDebug() << Q_FUNC_INFO << "rssiChanged" << dev.data()->address() << " val = " << ++ ;// dev->rssi() << ";line = "<< __LINE__ ; + }); + + connect(dev.data(),&BluezQt::Device::typeChanged,this,[=](BluezQt::Device::Type type){ +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -389,6 +389,8 @@ bluetoothadapter * BlueToothMain::create + qDebug () << Q_FUNC_INFO << adapter_address << __LINE__; + bluetoothadapter * adapter_dev = nullptr ; + ++ //将等待值修改为300ms ++ //建议基于事件定时获取,防止出现异常 + QString adapter_dev_name = getAdapterName(adapter_address); + qDebug() << Q_FUNC_INFO << adapter_dev_name << __LINE__; + if (adapter_dev_name.isEmpty()) +@@ -530,6 +532,11 @@ void BlueToothMain::reportAdapterRemoveS + void BlueToothMain::reportDefaultAdapterPowerChanged(bool isPower) + { + qDebug () << Q_FUNC_INFO << isPower << __LINE__; ++ if ("normalWidget" != this->centralWidget()->objectName()) ++ { ++ qDebug () << Q_FUNC_INFO << "is not normalWidget" << __LINE__; ++ return; ++ } + m_current_adapter_power_swtich = isPower; + if(m_settings) + m_settings->set("switch",QVariant::fromValue(isPower)); +@@ -691,7 +698,10 @@ bluetoothdevice * BlueToothMain::createO + void BlueToothMain::reportDeviceScanResult(QString devAddress,QString devName) + { + qDebug () << Q_FUNC_INFO << devName << devAddress << __LINE__; +- ++ if (delayStartDiscover_timer && delayStartDiscover_timer->isActive()) ++ { ++ delayStartDiscover_timer->stop(); ++ } + //设备列表已经存在该设备,添加到界面中去 + for (bluetoothdevice * tmpDev : m_default_bluetooth_adapter->m_bluetooth_device_list) + { +@@ -715,8 +725,16 @@ void BlueToothMain::reportDeviceScanResu + qDebug() << "effective device"; + device->setObjectName(devAddress); + m_default_bluetooth_adapter->m_bluetooth_device_list.append(device); +- if(whetherToAddCurrentInterface(device)) +- addOneBluetoothDeviceItemUi(device); ++ if(device->isPaired()) ++ { ++ this->addMyDeviceItemUI(device); ++ } ++ else ++ { ++ if(this->whetherToAddCurrentInterface(device)) ++ this->addOneBluetoothDeviceItemUi(device); ++ } ++ + + } + +@@ -931,7 +949,7 @@ bool BlueToothMain::getBluetoothBlock() + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getBluetoothBlock"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -946,7 +964,7 @@ QString BlueToothMain::getDefaultAdapter + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getDefaultAdapterAddress"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -961,7 +979,7 @@ QStringList BlueToothMain::getAdapterDev + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getAdapterDevAddressList"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -989,8 +1007,8 @@ QString BlueToothMain::getAdapterName(QS + PATH, + INTERFACE, + QDBusConnection::sessionBus()); +- //设置超时时间 +- iface.setTimeout(20); ++ //设置超时时间, 从20ms增加300ms,减少出现异常的几率 ++ iface.setTimeout(300); + QDBusReply reply=iface.call("getAdapterNameByAddr", adapterAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -1005,7 +1023,7 @@ bool BlueToothMain::getDefaultAdapterPow + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 ms +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getDefaultAdapterPower"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -1035,7 +1053,7 @@ bool BlueToothMain::getDefaultAdapterDis + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getDefaultAdapterDiscoverable"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -1048,8 +1066,8 @@ bool BlueToothMain::getDefaultAdapterSca + PATH, + INTERFACE, + QDBusConnection::sessionBus()); +- //设置超时时间 +- iface.setTimeout(20); ++ //设置超时时间,从20ms延迟至100ms ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getDefaultAdapterScanStatus"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -1063,8 +1081,8 @@ QString BlueToothMain::getDevName(QStrin + PATH, + INTERFACE, + QDBusConnection::sessionBus()); +- //设置超时时间 +- iface.setTimeout(20); ++ //设置超时时间,从20ms延长至300ms ++ iface.setTimeout(300); + QDBusReply reply=iface.call("getDevName",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -1078,7 +1096,7 @@ bool BlueToothMain::getDevPairStatus(QSt + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getDevPairStatus",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -1091,7 +1109,7 @@ bool BlueToothMain::getDevConnectStatus( + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getDevConnectStatus",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +@@ -1120,7 +1138,7 @@ QString BlueToothMain::getDevType(QStrin + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 +- iface.setTimeout(20); ++ iface.setTimeout(100); + QDBusReply reply=iface.call("getDevType",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + diff --git a/patches/optimum_101650.patch b/patches/optimum_101650.patch new file mode 100644 index 0000000..489ec73 --- /dev/null +++ b/patches/optimum_101650.patch @@ -0,0 +1,34 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 6f950ad..663dddf 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -80,12 +80,24 @@ void addDelay(BluezQt::DevicePtr dev) + { + if(nullptr != dev) + { +- QString key = dev->address(); +- //未找到 +- if(static_delays.find(key) == static_delays.end()) ++ //非手机、电脑没有必要延迟发送设备状态 ++ if(dev->type() != BluezQt::Device::Phone && dev->type() != BluezQt::Device::Computer) + { +- DelayStruct * p = new DelayStruct(dev); +- static_delays[key] = p; ++ qDebug() << Q_FUNC_INFO << __LINE__ << dev->address() << dev->isConnected(); ++ emit static_sess->devConnectStatusSignal(dev->address(), dev->isConnected()); ++ if (dev->isConnected() && dev->isPaired()) { ++ Config::writeKeyFile(dev->address(), dev->name(), dev->type()); ++ } ++ } ++ else ++ { ++ QString key = dev->address(); ++ //未找到 ++ if(static_delays.find(key) == static_delays.end()) ++ { ++ DelayStruct * p = new DelayStruct(dev); ++ static_delays[key] = p; ++ } + } + } + } diff --git a/patches/resolev_fix98561.patch b/patches/resolev_fix98561.patch new file mode 100644 index 0000000..81a583b --- /dev/null +++ b/patches/resolev_fix98561.patch @@ -0,0 +1,28 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 2421a9c..e243a86 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -1677,18 +1677,18 @@ void BlueToothMain::showBluetoothErrorMainWindow() + + QPalette pe; + pe.setColor(QPalette::WindowText,"#818181"); +- errorWidgetIcon->setFixedSize(56,56); ++ errorWidgetIcon->setFixedSize(54,88); + errorWidgetTip0->resize(200,30); + errorWidgetTip0->setFont(QFont("Noto Sans CJK SC",18,QFont::Medium)); + errorWidgetTip0->setPalette(pe); +- if (QIcon::hasThemeIcon("bluetooth-error")) { ++ if (QIcon::hasThemeIcon("bluetooth-disabled-symbolic")) { + if (isblack) +- errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56),"white")); ++ errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-disabled-symbolic").pixmap(54,88),"white")); + else +- errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56)); ++ errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-disabled-symbolic").pixmap(54,88)); + } + +- errorWidgetTip0->setText(tr("No Bluetooth adapter detected!")); ++ errorWidgetTip0->setText(tr("Bluetooth driver abnormal")); + + errorWidgetLayout->addStretch(7); + errorWidgetLayout->addWidget(errorWidgetIcon,1,Qt::AlignCenter); diff --git a/patches/resolve_100352and100295.patch b/patches/resolve_100352and100295.patch new file mode 100644 index 0000000..b744f1b --- /dev/null +++ b/patches/resolve_100352and100295.patch @@ -0,0 +1,25 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index aef72e9..c7f65d7 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -692,6 +692,7 @@ void SessionDbusRegister::connectSignal() + if(-1 != static_bluezreboot_power) + { + qDebug() << Q_FUNC_INFO << "setPowered" << bool(static_bluezreboot_power); ++ qDebug() << Q_FUNC_INFO << "name" << Daemon::_DefualtAdapter->name() << __LINE__; + Daemon::_DefualtAdapter->setPowered(bool(static_bluezreboot_power)); + static_bluezreboot_power = -1; + } +@@ -733,6 +734,12 @@ void SessionDbusRegister::connectSignal() + qDebug() << Q_FUNC_INFO << "static_bluezreboot_power" << static_bluezreboot_power << __LINE__; + }); + ++ connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::nameChanged,this,[=](const QString &name) ++ { ++ qDebug() << Q_FUNC_INFO << "nameChanged" << name << __LINE__; ++ emit defaultAdapterNameChanged(name); ++ }); ++ + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::deviceRemoved,this,[=](BluezQt::DevicePtr devPtr){ + qDebug() << Q_FUNC_INFO << "deviceRemoved" << devPtr->address()<<__LINE__; + emit devRemoveSignal(devPtr.data()->address()); diff --git a/patches/resolve_bluedevstatus.patch b/patches/resolve_bluedevstatus.patch new file mode 100644 index 0000000..4362c91 --- /dev/null +++ b/patches/resolve_bluedevstatus.patch @@ -0,0 +1,407 @@ +diff --git a/service/bluetoothagent.cpp b/service/bluetoothagent.cpp +index 71eff13..bb80f6d 100644 +--- a/service/bluetoothagent.cpp ++++ b/service/bluetoothagent.cpp +@@ -1,9 +1,11 @@ + #include "bluetoothagent.h" ++#include "globalsize.h" + + //取消发送蓝牙设备状态信号,在SessionDbusRegister定义 + extern int cancelEmitDevStatus(QString addr); + extern void addDelay(BluezQt::DevicePtr dev); + ++ + BluetoothAgent::BluetoothAgent(QObject *parent) + : Agent(parent) + , m_pinRequested(false) +@@ -55,21 +57,16 @@ void BluetoothAgent::replyRequestConfirmationFunc(bool v) + tmpRequestConfirmation.reject(); + + +- //增加蓝牙设备状态发送信号,仅在连接成功时发送 +- if(nullptr != m_device && m_device->isConnected()) ++ //发送蓝牙连接信号 ++ //条件:蓝牙设备未配对,蓝牙适配器配对,且蓝牙设备主动连接 ++ //约束条件: 点击确定、被动连接、连接成功、配对 ++ if(v && nullptr != m_device && !GlobalSize::IsBlueDevActive(m_device->address()) && ++ m_device->isConnected() && m_device->isPaired()) + { +- //QDBusMessage devConnectStatusSignal = QDBusMessage::createSignal("/com/ukui/bluetooth", +- // "com.ukui.bluetooth", +- // "devConnectStatusSignal"); +- +- //devConnectStatusSignal << m_device->address() << m_device->isConnected(); +- //QDBusConnection::sessionBus().send(devConnectStatusSignal); +- //延迟发送状态,当前机器匹配确定,对端机器匹配拒绝, 先-->后 +- //对端机器匹配拒绝,当前机器匹配确定,先-->后 +- //降低先发送连接成功马上发送断开的概率 ++ //若对端拒绝、超时等,会出现蓝牙设备状态发送异常情况,暂时无法避免 + addDelay(m_device); +- + } ++ + qDebug() << "BluetoothAgent::replyRequestConfirmationFunc--qk"; + } + +@@ -124,7 +121,6 @@ void BluetoothAgent::requestConfirmation(BluezQt::DevicePtr device, const QStrin + + cancelEmitDevStatus(device->address()); + +- + QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "requestConfirmation"); +diff --git a/service/globalsize.cpp b/service/globalsize.cpp +new file mode 100644 +index 0000000..4c358c2 +--- /dev/null ++++ b/service/globalsize.cpp +@@ -0,0 +1,42 @@ ++#include "globalsize.h" ++ ++QMap GlobalSize::m_static_devconnectcount; ++ ++ ++int GlobalSize::refBlueDevActive(QString key) ++{ ++ if(m_static_devconnectcount.contains(key)) ++ { ++ m_static_devconnectcount[key] = m_static_devconnectcount[key] + 1; ++ } ++ else ++ { ++ m_static_devconnectcount[key] = 1; ++ } ++ return m_static_devconnectcount[key]; ++} ++ ++int GlobalSize::unrefBlueDevActive(QString key) ++{ ++ if(m_static_devconnectcount.contains(key)) ++ { ++ m_static_devconnectcount[key] = m_static_devconnectcount[key] -1; ++ if(0 == m_static_devconnectcount[key]) ++ { ++ m_static_devconnectcount.remove(key); ++ return 0; ++ } ++ return m_static_devconnectcount[key]; ++ } ++ return 0; ++} ++ ++bool GlobalSize::IsBlueDevActive(QString key) ++{ ++ return m_static_devconnectcount.contains(key); ++} ++ ++int GlobalSize::BlueDevActiveSize(void) ++{ ++ return m_static_devconnectcount.size(); ++} +diff --git a/service/globalsize.h b/service/globalsize.h +new file mode 100644 +index 0000000..6f0f8e6 +--- /dev/null ++++ b/service/globalsize.h +@@ -0,0 +1,26 @@ ++#ifndef GLOBALSIZE_H ++#define GLOBALSIZE_H ++ ++#include ++#include ++#include ++ ++ ++class GlobalSize ++{ ++public: ++ static int refBlueDevActive(QString key); ++ ++ static int unrefBlueDevActive(QString key); ++ ++ static bool IsBlueDevActive(QString key); ++ ++ static int BlueDevActiveSize(void); ++ ++ ++protected: ++ //主动连接标志 ++ static QMap m_static_devconnectcount; ++}; ++ ++#endif // GLOBALSIZE_H +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index c1e5bd4..2a70f25 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -1,6 +1,8 @@ + #include "sessiondbusregister.h" + #include + ++#include "globalsize.h" ++ + #define TIMER_TIMEOUT (2*1000) + + +@@ -8,6 +10,7 @@ static bool isScan = false; + static SessionDbusRegister * static_sess = nullptr; + static QMap static_delays; + ++ + //仅适合单线程模式 + int cancelEmitDevStatus(QString addr) + { +@@ -152,29 +155,35 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + tmpdev.data()->type() == BluezQt::Device::Headset ) { + + qDebug () << Q_FUNC_INFO << "==================disconn=====" << tmpdev.data()->name() << __LINE__; +- + BluezQt::PendingCall *pending = tmpdev.data()->disconnectFromDevice(); + qDebug () << Q_FUNC_INFO << "=======================" << __LINE__; + connect(pending,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ + qDebug () << Q_FUNC_INFO << "=================conn======" << dev.data()->name() << call << __LINE__; ++ + if (!call->error()) { + BluezQt::PendingCall *call = dev.data()->connectToDevice(); ++ GlobalSize::refBlueDevActive(tmpdev->address()); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ GlobalSize::unrefBlueDevActive(tmpdev->address()); + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } + else + { +- //蔡涛连接延时方案中增加未匹配的情况下,不发送设备连接改变信号,导致的设备匹配前已连接成功, +- //匹配成功后,继续发起设备连接此时设备连接状态并没有改变,由于未接受到第一个设备连接信号,导致的控制面板显示未连接的情况 +- //临时方案--pair成功后,手动发送连接成功信号 +- emit devConnectStatusSignal(dev->address(),true); ++ //主动连接成功后,发送连接成功信号 ++ addDelay(dev); + } +- qDebug () << Q_FUNC_INFO << "===================conn====" << dev.data()->name() << " ok" << __LINE__; +- if (::isScan) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); ++ ++ //主动连接全部完成后,启动扫描 ++ if(GlobalSize::BlueDevActiveSize() == 0) ++ { ++ qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; ++ if (::isScan) { ++ Daemon::_DefualtAdapter.data()->startDiscovery(); ++ } + } ++ + }); + } + }); +@@ -186,46 +195,56 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + } + //当没有任何音频设备连接,最后再连接目标设备 + BluezQt::PendingCall *call = dev.data()->connectToDevice(); +- ++ GlobalSize::refBlueDevActive(dev->address()); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ GlobalSize::unrefBlueDevActive(dev->address()); + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } + else + { +- //蔡涛连接延时方案中增加未匹配的情况下,不发送设备连接改变信号,导致的设备匹配前已连接成功, +- //匹配成功后,继续发起设备连接此时设备连接状态并没有改变,由于未接受到第一个设备连接信号,导致的控制面板显示未连接的情况 +- //临时方案--pair成功后,手动发送连接成功信号 +- emit devConnectStatusSignal(dev->address(),true); ++ //主动连接成功后,发送连接成功信号 ++ addDelay(dev); + } + +- if (::isScan) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); ++ //不存在主动连接 ++ if(GlobalSize::BlueDevActiveSize() == 0) ++ { ++ qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; ++ if (::isScan) { ++ Daemon::_DefualtAdapter.data()->startDiscovery(); ++ } + } ++ + }); + } else { + + qDebug () << Q_FUNC_INFO << dev.data()->type() << __LINE__; + + BluezQt::PendingCall *call = dev.data()->connectToDevice(); ++ GlobalSize::refBlueDevActive(dev->address()); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ GlobalSize::unrefBlueDevActive(dev->address()); + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } + else + { +- //蔡涛连接延时方案中增加未匹配的情况下,不发送设备连接改变信号,导致的设备匹配前已连接成功, +- //匹配成功后,继续发起设备连接此时设备连接状态并没有改变,由于未接受到第一个设备连接信号,导致的控制面板显示未连接的情况 +- //临时方案--pair成功后,手动发送连接成功信号 +- emit devConnectStatusSignal(dev->address(),true); ++ //主动连接成功后,发送连接成功信号 ++ addDelay(dev); + } + +- if (::isScan) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); ++ if(GlobalSize::BlueDevActiveSize() == 0) ++ { ++ qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; ++ if (::isScan) { ++ Daemon::_DefualtAdapter.data()->startDiscovery(); ++ } + } + ++ + }); + } + } +@@ -679,38 +698,51 @@ void SessionDbusRegister::connectSignal() + connect(devPtr.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << devPtr.data()->address() << + v << devPtr.data()->isPaired() << devPtr->isConnected()<< devPtr.data()->type(); +- //已匹配设备,且改变为连接状态,延时发送,暂时定义2s +- if(devPtr->isPaired() && v) +- { +- addDelay(devPtr); +- } +- //未匹配,且为连接状态, 不发送 +- else if(!devPtr->isPaired() && v) +- { +- ; +- } +- else ++ ++ ++ //发送信号 ++ //主动连接,不发送信号 ++ //非主动连接情况下 ++ if(!GlobalSize::IsBlueDevActive(devPtr->address())) + { +- if(existDelay(devPtr->address())) ++ //条件: 蓝牙适配器:配对、连接, 且蓝牙设备主动连接 ++ if(devPtr->isPaired() && v) ++ { ++ addDelay(devPtr); ++ } ++ //未配对,且为连接状态, 不发送 ++ else if(!devPtr->isPaired() && v) + { +- qDebug() << Q_FUNC_INFO << __LINE__ << "existDelay " << devPtr->address(); ++ ; + } + else + { +- qDebug() << Q_FUNC_INFO<< __LINE__ << "emit " << devPtr->address() << v; +- emit devConnectStatusSignal(devPtr->address(),v); +- +- if (v && devPtr->isPaired()) { +- Config::writeKeyFile(devPtr->address(),devPtr->name(),devPtr->type()); ++ if(existDelay(devPtr->address())) ++ { ++ qDebug() << Q_FUNC_INFO << __LINE__ << "existDelay " << devPtr->address(); ++ } ++ else ++ { ++ qDebug() << Q_FUNC_INFO<< __LINE__ << "emit " << devPtr->address() << v; ++ emit devConnectStatusSignal(devPtr->address(),v); ++ ++ if (v && devPtr->isPaired()) { ++ Config::writeKeyFile(devPtr->address(),devPtr->name(),devPtr->type()); ++ } + } + } + } +- + }); + + connect(devPtr.data(),&BluezQt::Device::pairedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "pairedChanged" << devPtr.data()->address() << v; + emit devPairSignal(devPtr.data()->address(),v); ++ ++ //匹配成功 且 非主动连接情况下 且 蓝牙设备状态 连接 ++ if(v && !GlobalSize::IsBlueDevActive(devPtr->address()) && devPtr->isConnected()) ++ { ++ addDelay(devPtr); ++ } + }); + + connect(devPtr.data(),&BluezQt::Device::rssiChanged,this,[=](bool v){ +@@ -750,38 +782,48 @@ void SessionDbusRegister::connectSignal() + qDebug() << Q_FUNC_INFO << "connectedChanged" << dev.data()->address() << + v << dev.data()->isPaired() << dev->isConnected() << dev->type(); + +- //已匹配设备,且改变为连接状态,延时发送,暂时定义2s +- if(dev->isPaired() && v) +- { +- addDelay(dev); +- } +- //未匹配,且为连接状态, 不发送 +- else if(!dev->isPaired() && v) ++ //主动连接,在连接完成发送连接信号 ++ //非主动连接情况下,发送信号 ++ if(!GlobalSize::IsBlueDevActive(dev->address())) + { +- ; +- } +- else +- { +- if(existDelay(dev->address())) ++ //已匹配设备,且改变为连接状态,延时发送,暂时定义2s ++ if(dev->isPaired() && v) ++ { ++ addDelay(dev); ++ } ++ //未匹配,且为连接状态, 不发送 ++ else if(!dev->isPaired() && v) + { +- qDebug() << Q_FUNC_INFO << __LINE__ << "existDelay " << dev->address(); ++ ; + } + else + { +- qDebug() << Q_FUNC_INFO<< __LINE__ << "emit " << dev->address() << v; +- emit devConnectStatusSignal(dev.data()->address(),v); +- +- if (v && dev.data()->isPaired()) { +- Config::writeKeyFile(dev.data()->address(),dev.data()->name(),dev.data()->type()); ++ if(existDelay(dev->address())) ++ { ++ qDebug() << Q_FUNC_INFO << __LINE__ << "existDelay " << dev->address(); ++ } ++ else ++ { ++ qDebug() << Q_FUNC_INFO<< __LINE__ << "emit " << dev->address() << v; ++ emit devConnectStatusSignal(dev.data()->address(),v); ++ ++ if (v && dev.data()->isPaired()) { ++ Config::writeKeyFile(dev.data()->address(),dev.data()->name(),dev.data()->type()); ++ } + } + } + } +- + }); + + connect(dev.data(),&BluezQt::Device::pairedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "pairedChanged" << dev.data()->address(); + emit devPairSignal(dev.data()->address(),v); ++ ++ //匹配成功 且 非主动连接情况下 且 蓝牙设备状态 连接 ++ if(v && !GlobalSize::IsBlueDevActive(dev->address()) && dev->isConnected()) ++ { ++ addDelay(dev); ++ } + }); + + connect(dev.data(),&BluezQt::Device::rssiChanged,this,[=](bool v){ diff --git a/patches/resolve_bluesvr_crash.patch b/patches/resolve_bluesvr_crash.patch new file mode 100644 index 0000000..370beb0 --- /dev/null +++ b/patches/resolve_bluesvr_crash.patch @@ -0,0 +1,62 @@ +Index: ukui-bluetooth/service/sessiondbusregister.cpp +=================================================================== +--- ukui-bluetooth.orig/service/sessiondbusregister.cpp ++++ ukui-bluetooth/service/sessiondbusregister.cpp +@@ -65,7 +65,7 @@ void SessionDbusRegister::AudioDevConnec + dev.data()->type() == BluezQt::Device::Headset ) { + + BluezQt::PendingCall *pending = dev.data()->disconnectFromDevice(); +- connect(pending,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *call){ ++ connect(pending,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ + if (!call->error()) { + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ +@@ -88,7 +88,7 @@ void SessionDbusRegister::AudioDevConnec + } + //当没有任何音频设备连接,最后再连接目标设备 + BluezQt::PendingCall *call = dev.data()->connectToDevice(); +- connect(call,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *callReturn){ ++ connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); +@@ -103,7 +103,7 @@ void SessionDbusRegister::AudioDevConnec + qDebug () << Q_FUNC_INFO << dev.data()->type() << __LINE__; + + BluezQt::PendingCall *call = dev.data()->connectToDevice(); +- connect(call,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *callReturn){ ++ connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); +@@ -594,8 +594,14 @@ void SessionDbusRegister::connectSignal( + }); + + connect(devPtr.data(),&BluezQt::Device::batteryChanged,this,[=](BluezQt::BatteryPtr battery){ +- qDebug() << Q_FUNC_INFO << "batteryChanged" << battery.data()->percentage(); +- emit devBatteryChangedSignal(devPtr.data()->address(), QString::number(battery.data()->percentage())); ++ if(nullptr != battery){ ++ qDebug() << Q_FUNC_INFO << "batteryChanged" << battery.data()->percentage(); ++ emit devBatteryChangedSignal(devPtr.data()->address(), QString::number(battery.data()->percentage())); ++ } ++ else{ ++ qDebug() << Q_FUNC_INFO << "batteryChanged null " << devPtr.data()->address(); ++ } ++ + }); + }); + +@@ -634,8 +640,13 @@ void SessionDbusRegister::connectSignal( + }); + + connect(dev.data(),&BluezQt::Device::batteryChanged,this,[=](BluezQt::BatteryPtr battery){ ++ if(nullptr != battery){ + qDebug() << Q_FUNC_INFO << "batteryChanged" << battery.data()->percentage(); + emit devBatteryChangedSignal(dev.data()->address(), QString::number(battery.data()->percentage())); ++ } ++ else{ ++ qDebug() << Q_FUNC_INFO << "batteryChanged null " << dev.data()->address(); ++ } + }); + } + } diff --git a/patches/resolve_bluez_reboot.patch b/patches/resolve_bluez_reboot.patch new file mode 100644 index 0000000..9eebc82 --- /dev/null +++ b/patches/resolve_bluez_reboot.patch @@ -0,0 +1,64 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 3d2fc3e..5560b58 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -13,6 +13,9 @@ static bool isScan = false; + static SessionDbusRegister * static_sess = nullptr; + static QMap static_delays; + ++//检测bluez重启参数 ++//bluez重启(停止然后启动)后,关闭适配器蓝牙,移除蓝牙适配器,新增蓝牙适配器 ++static int static_bluezreboot_power = -1; + + //仅适合单线程模式 + int cancelEmitDevStatus(QString addr) +@@ -682,8 +685,14 @@ void SessionDbusRegister::connectSignal() + { + Daemon::_DefualtAdapter = adapter; + //移除设备后,信号消失,需要重新绑定信号 +- emit defaultAdapterPowerChanged(adapter->isPowered()); ++ //emit defaultAdapterPowerChanged(adapter->isPowered()); + this->connectSignal(); ++ if(-1 != static_bluezreboot_power) ++ { ++ Daemon::_DefualtAdapter->setPowered(bool(static_bluezreboot_power)); ++ static_bluezreboot_power = -1; ++ } ++ + } + else + { +@@ -697,6 +706,20 @@ void SessionDbusRegister::connectSignal() + emit adapterRemoveSignal(adapter.data()->address()); + }); + ++ connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::adapterRemoved,this,[=](BluezQt::AdapterPtr adapter){ ++ qDebug() << Q_FUNC_INFO << "adapterRemoved" << __LINE__; ++ emit adapterRemoveSignal(adapter.data()->address()); ++ ++ //bluez重启,可能出现蓝牙从开启变成关闭 ++ qint64 tmp = QDateTime::currentMSecsSinceEpoch() - ::powerChangeTime; ++ if(tmp <= 1000){ ++ static_bluezreboot_power = 1; ++ } ++ else{ ++ static_bluezreboot_power = 0; ++ } ++ }); ++ + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::deviceRemoved,this,[=](BluezQt::DevicePtr devPtr){ + qDebug() << Q_FUNC_INFO << "deviceRemoved" << __LINE__; + emit devRemoveSignal(devPtr.data()->address()); +diff --git a/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.ts b/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.ts +index c783c1e..dfd1ccd 100644 +--- a/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.ts ++++ b/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.ts +@@ -178,7 +178,7 @@ + + Click to change the device name + Double-click to change the device name +- 双击修改设备名称 ++ 点击修改设备名称 + + + diff --git a/patches/resolve_bluez_reboot1.patch b/patches/resolve_bluez_reboot1.patch new file mode 100644 index 0000000..af9381c --- /dev/null +++ b/patches/resolve_bluez_reboot1.patch @@ -0,0 +1,89 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 5560b58..7f08669 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -338,6 +338,7 @@ QString SessionDbusRegister::getAdapterNameByAddr(QString addr) + + void SessionDbusRegister::setDefaultAdapterScanOn(bool scanon) + { ++ qDebug () << Q_FUNC_INFO << scanon << __LINE__; + if (!Daemon::_DefualtAdapter.isNull()) { + // BluezQt::PendingCall *call = nullptr; + ::isScan = scanon; +@@ -673,7 +674,7 @@ void SessionDbusRegister::connectSignal() + qDebug() << Q_FUNC_INFO << __LINE__ << ": "<< Daemon::_DefualtAdapter->disconnect(); + + connect(Daemon::_BluezManager,&BluezQt::Manager::adapterAdded,this,[=](BluezQt::AdapterPtr adapter){ +- qDebug() << Q_FUNC_INFO << "adapterAdded" << __LINE__; ++ qDebug() << Q_FUNC_INFO << "adapterAdded" << adapter->address() << adapter->isPowered()<< __LINE__; + emit adapterAddSignal(adapter.data()->address()); + + //修改 +@@ -685,10 +686,10 @@ void SessionDbusRegister::connectSignal() + { + Daemon::_DefualtAdapter = adapter; + //移除设备后,信号消失,需要重新绑定信号 +- //emit defaultAdapterPowerChanged(adapter->isPowered()); + this->connectSignal(); + if(-1 != static_bluezreboot_power) + { ++ qDebug() << Q_FUNC_INFO << "setPowered" << bool(static_bluezreboot_power); + Daemon::_DefualtAdapter->setPowered(bool(static_bluezreboot_power)); + static_bluezreboot_power = -1; + } +@@ -713,15 +714,25 @@ void SessionDbusRegister::connectSignal() + //bluez重启,可能出现蓝牙从开启变成关闭 + qint64 tmp = QDateTime::currentMSecsSinceEpoch() - ::powerChangeTime; + if(tmp <= 1000){ ++ qDebug() << Q_FUNC_INFO << "time <= 1000" << __LINE__; + static_bluezreboot_power = 1; + } + else{ +- static_bluezreboot_power = 0; ++ if(adapter->isPowered()){ ++ qDebug() << Q_FUNC_INFO << "adapter->isPowered() true, emit false" << __LINE__; ++ static_bluezreboot_power = 1; ++ } ++ else{ ++ qDebug() << Q_FUNC_INFO << "adapter->isPowered() false" << __LINE__; ++ static_bluezreboot_power = 0; ++ } ++ + } ++ qDebug() << Q_FUNC_INFO << "static_bluezreboot_power" << static_bluezreboot_power << __LINE__; + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::deviceRemoved,this,[=](BluezQt::DevicePtr devPtr){ +- qDebug() << Q_FUNC_INFO << "deviceRemoved" << __LINE__; ++ qDebug() << Q_FUNC_INFO << "deviceRemoved" << devPtr->address()<<__LINE__; + emit devRemoveSignal(devPtr.data()->address()); + + if (devPtr.data()->isPaired()) +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 3b173ed..2421a9c 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -453,7 +453,7 @@ void BlueToothMain::refreshBluetoothAdapterInterfaceUI() + } + } + +- //refreshUIWhenAdapterChanged(); ++ refreshUIWhenAdapterChanged(); + } + + //void BlueToothMain::addBluetoothAdapterComboBox(QString adapterName) +@@ -516,10 +516,10 @@ void BlueToothMain::removeAdapterDataList(QString adapterAddress) + void BlueToothMain::reportAdapterAddSignal(QString adapterAddress) + { + qDebug () << Q_FUNC_INFO << adapterAddress << __LINE__; +- if("normalWidget" != this->centralWidget()->objectName()) +- { +- _MCentralWidget->setCurrentWidget(m_normal_main_widget); +- } ++// if("normalWidget" != this->centralWidget()->objectName()) ++// { ++// _MCentralWidget->setCurrentWidget(m_normal_main_widget); ++// } + + addAdapterDataList(adapterAddress); + refreshBluetoothAdapterInterfaceUI(); diff --git a/patches/resolve_delaybluestatus.patch b/patches/resolve_delaybluestatus.patch new file mode 100644 index 0000000..f1a86ae --- /dev/null +++ b/patches/resolve_delaybluestatus.patch @@ -0,0 +1,228 @@ +diff --git a/service/bluetoothagent.cpp b/service/bluetoothagent.cpp +index deda35a..52498a0 100644 +--- a/service/bluetoothagent.cpp ++++ b/service/bluetoothagent.cpp +@@ -1,5 +1,7 @@ + #include "bluetoothagent.h" + ++//取消发送蓝牙设备状态信号,在SessionDbusRegister定义 ++extern int cancelEmitDevStatus(QString addr); + + BluetoothAgent::BluetoothAgent(QObject *parent) + : Agent(parent) +@@ -51,8 +53,9 @@ void BluetoothAgent::replyRequestConfirmationFunc(bool v) + else + tmpRequestConfirmation.reject(); + +- //增加蓝牙设备状态发送信号 +- if(nullptr != m_device) ++ ++ //增加蓝牙设备状态发送信号,仅在连接成功时发送 ++ if(nullptr != m_device && m_device->isConnected()) + { + QDBusMessage devConnectStatusSignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", +@@ -110,17 +113,10 @@ void BluetoothAgent::displayPasskey(BluezQt::DevicePtr device, const QString &pa + + void BluetoothAgent::requestConfirmation(BluezQt::DevicePtr device, const QString &passkey, const BluezQt::Request<> &request) + { +- qDebug() << Q_FUNC_INFO << device->name() << passkey; ++ qDebug() << Q_FUNC_INFO << device->name() << passkey << device->isConnected() << device->isPaired(); + +- //发送蓝牙设备断开信号 +- { +- QDBusMessage devConnectStatusSignal = QDBusMessage::createSignal("/com/ukui/bluetooth", +- "com.ukui.bluetooth", +- "devConnectStatusSignal"); ++ cancelEmitDevStatus(device->address()); + +- devConnectStatusSignal << device->address() << false; +- QDBusConnection::sessionBus().send(devConnectStatusSignal); +- } + + QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 66da3f1..cb2db1a 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -1,6 +1,85 @@ + #include "sessiondbusregister.h" ++#include ++ ++#define TIMER_TIMEOUT (2*1000) ++ + + static bool isScan = false; ++static SessionDbusRegister * static_sess = nullptr; ++static QMap static_delays; ++ ++//仅适合单线程模式 ++int cancelEmitDevStatus(QString addr) ++{ ++ DelayStruct * p = static_delays.value(addr, nullptr); ++ if(nullptr != p) ++ { ++ p->close(); ++ //从qmap删除 ++ static_delays.remove(addr); ++ } ++ return 0; ++} ++ ++DelayStruct::DelayStruct(BluezQt::DevicePtr dev, QObject *parent /*= nullptr*/):QObject(parent) ++{ ++ m_dev = dev; ++ m_TimerID = this->startTimer(TIMER_TIMEOUT); ++} ++ ++DelayStruct::~DelayStruct() ++{ ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ m_dev = nullptr; ++} ++ ++void DelayStruct::close(void) ++{ ++ this->killTimer(m_TimerID); ++ this->deleteLater(); ++} ++ ++void DelayStruct::timerEvent( QTimerEvent *event) ++{ ++ if(nullptr != m_dev && nullptr != static_sess) ++ { ++ emit static_sess->devConnectStatusSignal(m_dev->address(), m_dev->isConnected()); ++ if (m_dev->isConnected() && m_dev->isPaired()) { ++ Config::writeKeyFile(m_dev->address(),m_dev->name(),m_dev->type()); ++ } ++ } ++ //从qmap删除 ++ if(nullptr != m_dev) ++ { ++ static_delays.remove(m_dev->address()); ++ } ++ ++ this->close(); ++} ++ ++ ++static void init_static_sess(SessionDbusRegister * p) ++{ ++ static_sess = p; ++} ++ ++static void addDelay(BluezQt::DevicePtr dev) ++{ ++ if(nullptr != dev) ++ { ++ QString key = dev->address(); ++ //未找到 ++ if(static_delays.find(key) == static_delays.end()) ++ { ++ DelayStruct * p = new DelayStruct(dev); ++ static_delays[key] = p; ++ } ++ } ++} ++ ++////////////////////////////////////////////SessionDbusRegister//////////////////////////////////// ++////////////////////////////////////////////SessionDbusRegister//////////////////////////////////// ++ + + static inline bool isAvailableAddress(QString addr) { + if (addr.isEmpty() || addr.isNull()) +@@ -12,7 +91,7 @@ static inline bool isAvailableAddress(QString addr) { + SessionDbusRegister::SessionDbusRegister(QObject *parent) : QObject(parent) + { + qInfo() << Q_FUNC_INFO ; +- ++ init_static_sess(this); + if (InterfaceAlreadyExists()) { + QDBusConnection sessionDbus = QDBusConnection::sessionBus(); + if (!sessionDbus.registerService("com.ukui.bluetooth")) { +@@ -573,12 +652,21 @@ void SessionDbusRegister::connectSignal() + + connect(devPtr.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << devPtr.data()->address() << +- v << devPtr.data()->isPaired() << devPtr->isConnected() << devPtr.data()->name(); +- emit devConnectStatusSignal(devPtr.data()->address(),v); ++ v << devPtr.data()->isPaired() << devPtr->isConnected(); ++ //已匹配设备,且改变为连接状态,延时发送,暂时定义2s ++ if(devPtr->isPaired() && v) ++ { ++ addDelay(devPtr); ++ } ++ else ++ { ++ emit devConnectStatusSignal(devPtr.data()->address(),v); + +- if (v && devPtr.data()->isPaired()) { +- Config::writeKeyFile(devPtr.data()->address(),devPtr.data()->name(),devPtr.data()->type()); ++ if (v && devPtr.data()->isPaired()) { ++ Config::writeKeyFile(devPtr.data()->address(),devPtr.data()->name(),devPtr.data()->type()); ++ } + } ++ + }); + + connect(devPtr.data(),&BluezQt::Device::pairedChanged,this,[=](bool v){ +@@ -619,12 +707,22 @@ void SessionDbusRegister::connectSignal() + + connect(dev.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << dev.data()->address() << +- v << dev.data()->isPaired() << dev->isConnected() << dev.data()->name(); +- emit devConnectStatusSignal(dev.data()->address(),v); ++ v << dev.data()->isPaired() << dev->isConnected(); + +- if (v && dev.data()->isPaired()) { +- Config::writeKeyFile(dev.data()->address(),dev.data()->name(),dev.data()->type()); ++ //已匹配设备,且改变为连接状态,延时发送,暂时定义2s ++ if(dev->isPaired() && v) ++ { ++ addDelay(dev); + } ++ else ++ { ++ emit devConnectStatusSignal(dev.data()->address(),v); ++ ++ if (v && dev.data()->isPaired()) { ++ Config::writeKeyFile(dev.data()->address(),dev.data()->name(),dev.data()->type()); ++ } ++ } ++ + }); + + connect(dev.data(),&BluezQt::Device::pairedChanged,this,[=](bool v){ +diff --git a/service/sessiondbusregister.h b/service/sessiondbusregister.h +index 849250e..2ddf8a7 100644 +--- a/service/sessiondbusregister.h ++++ b/service/sessiondbusregister.h +@@ -24,6 +24,27 @@ + #include + + ++ ++class DelayStruct : public QObject ++{ ++ Q_OBJECT ++ ++public: ++ DelayStruct(BluezQt::DevicePtr dev, QObject *parent = nullptr); ++ ~DelayStruct(); ++ ++ void close(void); //关闭并销毁函数 ++ ++protected: ++ ++ virtual void timerEvent( QTimerEvent *event); ++ ++private: ++ int m_TimerID = 0; ++ BluezQt::DevicePtr m_dev = nullptr; ++}; ++ ++ + class SessionDbusRegister : public QObject, protected QDBusContext + { + Q_OBJECT diff --git a/patches/resolve_fix97544.patch b/patches/resolve_fix97544.patch new file mode 100644 index 0000000..bef51ce --- /dev/null +++ b/patches/resolve_fix97544.patch @@ -0,0 +1,21 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 917eeec..1d2b5f3 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -810,13 +810,13 @@ void DeviceInfoItem::DrawFuncBtn(QPainter &painter) + if (_themeIsBlack) { + if (_inBtn) + style()->drawItemPixmap(&painter,QRect(this->width()-48,19,20,20), Qt::AlignCenter, +- ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"black")); ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(20),"black")); + else + style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, +- ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"white")); ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(20),"white")); + } else + style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, +- ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"black")); ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(20),"black")); + + painter.restore(); + } diff --git a/patches/resolve_keyboard_display.patch b/patches/resolve_keyboard_display.patch new file mode 100644 index 0000000..373587f --- /dev/null +++ b/patches/resolve_keyboard_display.patch @@ -0,0 +1,390 @@ +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index 06dd282..9f8cd43 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -19,7 +19,7 @@ MainProgram::MainProgram(bool intel, QObject *parent) : + connect(_sessionDbus, &BluetoothDbus::sendTransferFilesMesgSignal, this, &MainProgram::sendTransferFilesMesgSlot); + } + +- connect(_sessionDbus, &BluetoothDbus::displayPasskeySignal, this, &MainProgram::requestConfirmationSlot); ++ connect(_sessionDbus, &BluetoothDbus::displayPasskeySignal, this, &MainProgram::displayPasskeySlot); + connect(_sessionDbus, &BluetoothDbus::requestConfirmationSignal, this, &MainProgram::requestConfirmationSlot); + connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired) { + Q_UNUSED(_name); +@@ -272,21 +272,23 @@ void MainProgram::displayPasskeySlot(QString name, QString passkey) + Keypincodewidget = nullptr; + }); + ++ qDebug() << Q_FUNC_INFO << "disconnect pairAgentCanceledSignal: "<< disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); ++ qDebug() << Q_FUNC_INFO << "disconnect devPairSignal: "<< disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); ++ + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { +- Keypincodewidget->pairFailureShow(); ++ if(nullptr != Keypincodewidget) ++ Keypincodewidget->pairFailureShow(); + disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); + }); + connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired){ +- if (name != _name) ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ if (name != _name || nullptr == Keypincodewidget) + return; + if (paired) ++ { + Keypincodewidget->setHidden(true); +- else +- QTimer::singleShot(1000,this,[=]{ +- if (!_sessionDbus->isConnected(name)) { +- Keypincodewidget->pairFailureShow(); +- } +- }); ++ emit Keypincodewidget->msgShowedOver(); ++ } + disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); + }); + //保持在最前 +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index 7045ff9..c7a1605 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -60,7 +60,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + if(show_flag) { + tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + } else +- tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(Name); ++ tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair:")).arg(Name); + //top_label = new QLabel(top_text,this); + //top_label->setStyleSheet("QLabel{\ + // font-size: 18px;\ +@@ -93,7 +93,10 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + connect(accept_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_accept_btn); + connect(refuse_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_refuse_btn); + }else{ +- accept_btn->setVisible(false); ++ connect(accept_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_close_btn); ++ accept_btn->setText(tr("Confirm")); ++ accept_btn->adjustSize(); ++ //accept_btn->setVisible(false); + refuse_btn->setVisible(false); + } + +@@ -142,7 +145,7 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + + PinCodeWidget::~PinCodeWidget() + { +- ++ qDebug() << Q_FUNC_INFO << __LINE__ << dev_name << PINCode << show_flag; + } + + void PinCodeWidget::Connection_timed_out() +@@ -192,7 +195,7 @@ void PinCodeWidget::updateUIInfo(const QString &name, const QString &pin) + if(show_flag) + tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + else +- tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(Name); ++ tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair:")).arg(Name); + tip_label->setText(tip_text); + tip_label->update(); + +@@ -207,7 +210,7 @@ void PinCodeWidget::onClick_close_btn(bool) + emit this->rejected(); + this->close(); + } else { +- this->setHidden(true); ++ emit this->msgShowedOver(); + } + } + +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm +index a22748f..93a563c 100644 +Binary files a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm and b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm differ +diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +index 962d0ec..7eaba2d 100644 +--- a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts ++++ b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +@@ -11,54 +11,54 @@ + + + +- ++ + Transferring to " + 发送文件至 " + + + +- +- ++ ++ + and + + + + +- +- ++ ++ + files more + 个文件 + + +- ++ + Select Device + 选择设备 + + +- +- +- ++ ++ ++ + OK + 确定 + + +- ++ + Cancel + 取消 + + +- ++ + File Transmission Failed ! + 文件发送失败! + + +- +- ++ ++ + File Transmition Succeed! + 文件发送成功! + + +- ++ + Close + 关闭 + +@@ -66,8 +66,7 @@ + + BluetoothSettingLabel + +- +- ++ + Bluetooth Settings + 蓝牙设置 + +@@ -108,60 +107,60 @@ + 蓝牙文件 + + +- +- +- +- ++ ++ ++ ++ + File from " + 文件来自 " + + +- ++ + ", waiting for receive. + ",等待接收。 + + +- ++ + Cancel + 取消 + + +- ++ + Accept + 接收 + + +- ++ + View + 查看 + + +- ++ + ", is receiving... (has recieved + ",正在接收… (已接收 + + +- ++ + files) + 个文件) + + +- ++ + ", is receiving... + ",正在接收… + + +- ++ + OK + 确定 + + +- ++ + ", received failed ! + ",接收失败! + + +- ++ + File Transmission Failed ! + 文件发送失败! + +@@ -177,12 +176,12 @@ + + MainProgram + +- ++ + Warning + 提示 + + +- ++ + The selected file is empty, please select the file again ! + 所选文件为空,请重新选择! + +@@ -203,9 +202,8 @@ + "。 + + +- + If you want to pair with this device, please make sure the numbers below are the same with the devices. +- 若要连接此设备,请确认下面的数字与该设备上的一致。 ++ 若要连接此设备,请确认下面的数字与该设备上的一致。 + + + Please make sure the PIN code displayed on ' +@@ -216,14 +214,12 @@ + " 上的PIN码与此PIN码相同,请按 "连接"。 + + +- +- + Please enter the following PIN code on the bluetooth device '%1' and press enter to pair ! +- 请在蓝牙设备 "%1" 上输入下列PIN码,并按连接进行匹配! ++ 请在蓝牙设备 "%1" 上输入相同PIN,并按"Enter"确认: + + +- +- ++ ++ + If ' + 如果 " + +@@ -233,30 +229,49 @@ + 蓝牙连接 + + +- +- ++ ++ + ' the PIN on is the same as this PIN. Please press 'Connect'. + " 上的PIN码与此PIN码相同,请按 "连接"。 + + +- ++ ++ ++ Please enter the following PIN code on the bluetooth device '%1' and press enter to pair: ++ 请在蓝牙设备 "%1" 上输入相同PIN,并按"Enter"确认: ++ ++ ++ ++ Confirm ++ 确定 ++ ++ ++ Please enter the following PIN code on the bluetooth device '%1' and press enter to pair ++ 请在蓝牙设备 "%1" 上输入相同PIN,并按"Enter"确认: ++ ++ ++ + Connect + 连接 + + +- ++ + Refush + 取消 + + +- +- ++ confirm ++ 确定 ++ ++ ++ ++ + Pair + 配对 + + +- +- ++ ++ + Connection error !!! + 连接失败 !!! + +@@ -290,7 +305,7 @@ + 设置蓝牙项 + + +- ++ + Bluetooth + 蓝牙 + +@@ -298,17 +313,17 @@ + + TrayWidget + +- ++ + bluetooth + 蓝牙 + + +- ++ + Bluetooth + 蓝牙 + + +- ++ + My Device + 我的设备 + diff --git a/patches/resolve_keyboard_display1.patch b/patches/resolve_keyboard_display1.patch new file mode 100644 index 0000000..02533aa --- /dev/null +++ b/patches/resolve_keyboard_display1.patch @@ -0,0 +1,31 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 7f08669..b89cd61 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -670,8 +670,9 @@ void SessionDbusRegister::connectSignal() + qDebug() << Q_FUNC_INFO << "_DefualtAdapter is null!" ; + return; + } +- qDebug() << Q_FUNC_INFO << __LINE__ << ": "<< Daemon::_BluezManager->disconnect(this); +- qDebug() << Q_FUNC_INFO << __LINE__ << ": "<< Daemon::_DefualtAdapter->disconnect(); ++ ++ Daemon::_BluezManager->disconnect(this); ++ Daemon::_DefualtAdapter->disconnect(); + + connect(Daemon::_BluezManager,&BluezQt::Manager::adapterAdded,this,[=](BluezQt::AdapterPtr adapter){ + qDebug() << Q_FUNC_INFO << "adapterAdded" << adapter->address() << adapter->isPowered()<< __LINE__; +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index 9f8cd43..82b8340 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -272,8 +272,8 @@ void MainProgram::displayPasskeySlot(QString name, QString passkey) + Keypincodewidget = nullptr; + }); + +- qDebug() << Q_FUNC_INFO << "disconnect pairAgentCanceledSignal: "<< disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); +- qDebug() << Q_FUNC_INFO << "disconnect devPairSignal: "<< disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); ++ disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); ++ disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); + + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { + if(nullptr != Keypincodewidget) diff --git a/patches/resolve_nopair_status.patch b/patches/resolve_nopair_status.patch new file mode 100644 index 0000000..d25b82f --- /dev/null +++ b/patches/resolve_nopair_status.patch @@ -0,0 +1,69 @@ +Index: ukui-bluetooth/service/bluetoothagent.cpp +=================================================================== +--- ukui-bluetooth.orig/service/bluetoothagent.cpp ++++ ukui-bluetooth/service/bluetoothagent.cpp +@@ -102,6 +102,16 @@ void BluetoothAgent::requestConfirmation + { + qDebug() << Q_FUNC_INFO << device->name() << passkey; + ++ //发送蓝牙设备断开信号 ++ { ++ QDBusMessage devConnectStatusSignal = QDBusMessage::createSignal("/com/ukui/bluetooth", ++ "com.ukui.bluetooth", ++ "devConnectStatusSignal"); ++ ++ devConnectStatusSignal << device->address() << false; ++ QDBusConnection::sessionBus().send(devConnectStatusSignal); ++ } ++ + QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "requestConfirmation"); +Index: ukui-bluetooth/service/sessiondbusregister.cpp +=================================================================== +--- ukui-bluetooth.orig/service/sessiondbusregister.cpp ++++ ukui-bluetooth/service/sessiondbusregister.cpp +@@ -492,10 +492,19 @@ void SessionDbusRegister::connectSignal( + //为默认适配器赋值,daemon未提供接口 + //使用临时方案,只存在一个蓝牙适配器,则直接赋值 + //如存在多个蓝牙适配器情况下,需要进行修改 +- Daemon::_DefualtAdapter = adapter; +- //移除设备后,信号消失,需要重新绑定信号 +- emit defaultAdapterPowerChanged(adapter->isPowered()); +- this->connectSignal(); ++ //从无到有,以第一个适配器作为默认适配器 ++ if(Daemon::_BluezManager->adapters().size() == 1) ++ { ++ Daemon::_DefualtAdapter = adapter; ++ //移除设备后,信号消失,需要重新绑定信号 ++ emit defaultAdapterPowerChanged(adapter->isPowered()); ++ this->connectSignal(); ++ } ++ else ++ { ++ //不做任何处理 ++ } ++ + }); + + connect(Daemon::_BluezManager,&BluezQt::Manager::adapterRemoved,this,[=](BluezQt::AdapterPtr adapter){ +@@ -534,7 +543,8 @@ void SessionDbusRegister::connectSignal( + devPtr->disconnect(); + + connect(devPtr.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ +- qDebug() << Q_FUNC_INFO << "connectedChanged" << devPtr.data()->address() << v << devPtr.data()->isPaired(); ++ qDebug() << Q_FUNC_INFO << "connectedChanged" << devPtr.data()->address() << ++ v << devPtr.data()->isPaired() << devPtr->isConnected(); + emit devConnectStatusSignal(devPtr.data()->address(),v); + + if (v && devPtr.data()->isPaired()) { +@@ -573,7 +583,8 @@ void SessionDbusRegister::connectSignal( + dev->disconnect(); + + connect(dev.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ +- qDebug() << Q_FUNC_INFO << "connectedChanged" << dev.data()->address() << v << dev.data()->isPaired(); ++ qDebug() << Q_FUNC_INFO << "connectedChanged" << dev.data()->address() << ++ v << dev.data()->isPaired() << dev->isConnected(); + emit devConnectStatusSignal(dev.data()->address(),v); + + if (v && dev.data()->isPaired()) { diff --git a/patches/resolve_pinshow.patch b/patches/resolve_pinshow.patch new file mode 100644 index 0000000..53120f9 --- /dev/null +++ b/patches/resolve_pinshow.patch @@ -0,0 +1,130 @@ +Index: ukui-bluetooth/ukui-bluetooth/main/mainprogram.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/main/mainprogram.cpp ++++ ukui-bluetooth/ukui-bluetooth/main/mainprogram.cpp +@@ -14,7 +14,7 @@ MainProgram::MainProgram(bool intel, QOb + connect(_sessionDbus, &BluetoothDbus::receiveFilesSignal, this, &MainProgram::receiveFileSlot); + connect(_sessionDbus, &BluetoothDbus::sendTransferDeviceMesgSignal, this, &MainProgram::sendTransferDeviceMesgSlot); + connect(_sessionDbus, &BluetoothDbus::sendTransferFilesMesgSignal, this, &MainProgram::sendTransferFilesMesgSlot); +- connect(_sessionDbus, &BluetoothDbus::displayPasskeySignal, this, &MainProgram::displayPasskeySlot); ++ connect(_sessionDbus, &BluetoothDbus::displayPasskeySignal, this, &MainProgram::requestConfirmationSlot); + connect(_sessionDbus, &BluetoothDbus::requestConfirmationSignal, this, &MainProgram::requestConfirmationSlot); + connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired) { + Q_UNUSED(_name); +Index: ukui-bluetooth/ukui-bluetooth/pin/pincodewidget.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/pin/pincodewidget.cpp ++++ ukui-bluetooth/ukui-bluetooth/pin/pincodewidget.cpp +@@ -35,21 +35,21 @@ PinCodeWidget::PinCodeWidget(QString nam + + this->setPalette(palette); + this->setAutoFillBackground(true); +- title_icon = new QLabel(this); +- title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); +- title_icon->resize(22,22); +- +- title_text = new QLabel(tr("Bluetooth Connections"),this); +- title_text->setStyleSheet("QLabel{\ +- width: 200px;\ +- height: 20px;\ +- font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 24px;\ +- opacity: 1;}"); ++ //title_icon = new QLabel(this); ++ //title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); ++ //title_icon->resize(22,22); ++ ++ //title_text = new QLabel(tr("Bluetooth Connections"),this); ++ //title_text->setStyleSheet("QLabel{\ ++ // width: 200px;\ ++ // height: 20px;\ ++ // font-size: 14px;\ ++ // font-family: Noto Sans CJK SC;\ ++ // font-weight: 400;\ ++ // line-height: 24px;\ ++ // opacity: 1;}"); + +- QString top_text = tr("Bluetooth Connect Request From \'")+dev_name+tr("\'."); ++ //QString top_text = tr("Bluetooth Connect Request From \'")+dev_name+tr("\'."); + QString tip_text; + if(show_flag) { + if (is_Intel) +@@ -58,13 +58,13 @@ PinCodeWidget::PinCodeWidget(QString nam + tip_text = tr("Please make sure the PIN code displayed on \'")+dev_name+tr("\' matches the number below. Please press \'Connect\'."); + } else + tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair !")).arg(dev_name); +- top_label = new QLabel(top_text,this); +- top_label->setStyleSheet("QLabel{\ +- font-size: 18px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 500;\ +- line-height: 24px;}"); +- top_label->setWordWrap(true); ++ //top_label = new QLabel(top_text,this); ++ //top_label->setStyleSheet("QLabel{\ ++ // font-size: 18px;\ ++ // font-family: Noto Sans CJK SC;\ ++ // font-weight: 500;\ ++ // line-height: 24px;}"); ++ //top_label->setWordWrap(true); + + tip_label = new QLabel(tip_text,this); + tip_label->setStyleSheet("QLabel{\ +@@ -102,13 +102,13 @@ PinCodeWidget::PinCodeWidget(QString nam + close_btn->setFlat(true); + connect(close_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_close_btn); + +- title_text->setGeometry(36,12,200,20); +- title_icon->setGeometry(8,12,22,22); ++ //title_text->setGeometry(36,12,200,20); ++ //title_icon->setGeometry(8,12,22,22); + close_btn->setGeometry(480,8,30,30); + + if (is_Intel) { + this->setFixedSize(520, 328); +- top_label->setGeometry(24,60,456,50); ++ //top_label->setGeometry(24,60,456,50); + tip_label->setGeometry(24,118,450,40); + PIN_label->setGeometry(24,163,462,47); + accept_btn->setGeometry(373,248,112,56); +@@ -119,12 +119,12 @@ PinCodeWidget::PinCodeWidget(QString nam + font-weight: 400;\ + line-height: 24px;}"); + } else { +- this->setFixedSize(520,254); +- PIN_label->setGeometry(32,146,207,36); +- tip_label->setGeometry(32,106,450,40); +- top_label->setGeometry(32,56,456,50); +- accept_btn->setGeometry(392,195,96,36); +- refuse_btn->setGeometry(280,195,96,36); ++ this->setFixedSize(520,202); ++ PIN_label->setGeometry(32,75,207,36); ++ tip_label->setGeometry(32,40,430,20); ++ //top_label->setGeometry(32,56,456,50); ++ accept_btn->setGeometry(392,143,96,36); ++ refuse_btn->setGeometry(280,143,96,36); + } + } + +Index: ukui-bluetooth/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts ++++ ukui-bluetooth/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts +@@ -216,13 +216,13 @@ + + + Please make sure the PIN code displayed on ' +- 请确认设备 " ++ 如果 " + + + + + ' matches the number below. Please press 'Connect'. +- " 上的PIN码与显示的数字匹配,请按 "连接"。 ++ " 上的PIN码与此PIN码相同,请按 "连接"。 + + + diff --git a/patches/resolve_pinwiget_status.patch b/patches/resolve_pinwiget_status.patch new file mode 100644 index 0000000..9bce1cb --- /dev/null +++ b/patches/resolve_pinwiget_status.patch @@ -0,0 +1,217 @@ +diff --git a/service/bluetoothagent.cpp b/service/bluetoothagent.cpp +index 52498a0..71eff13 100644 +--- a/service/bluetoothagent.cpp ++++ b/service/bluetoothagent.cpp +@@ -2,6 +2,7 @@ + + //取消发送蓝牙设备状态信号,在SessionDbusRegister定义 + extern int cancelEmitDevStatus(QString addr); ++extern void addDelay(BluezQt::DevicePtr dev); + + BluetoothAgent::BluetoothAgent(QObject *parent) + : Agent(parent) +@@ -57,12 +58,17 @@ void BluetoothAgent::replyRequestConfirmationFunc(bool v) + //增加蓝牙设备状态发送信号,仅在连接成功时发送 + if(nullptr != m_device && m_device->isConnected()) + { +- QDBusMessage devConnectStatusSignal = QDBusMessage::createSignal("/com/ukui/bluetooth", +- "com.ukui.bluetooth", +- "devConnectStatusSignal"); ++ //QDBusMessage devConnectStatusSignal = QDBusMessage::createSignal("/com/ukui/bluetooth", ++ // "com.ukui.bluetooth", ++ // "devConnectStatusSignal"); ++ ++ //devConnectStatusSignal << m_device->address() << m_device->isConnected(); ++ //QDBusConnection::sessionBus().send(devConnectStatusSignal); ++ //延迟发送状态,当前机器匹配确定,对端机器匹配拒绝, 先-->后 ++ //对端机器匹配拒绝,当前机器匹配确定,先-->后 ++ //降低先发送连接成功马上发送断开的概率 ++ addDelay(m_device); + +- devConnectStatusSignal << m_device->address() << m_device->isConnected(); +- QDBusConnection::sessionBus().send(devConnectStatusSignal); + } + qDebug() << "BluetoothAgent::replyRequestConfirmationFunc--qk"; + } +@@ -101,6 +107,7 @@ void BluetoothAgent::requestPasskey(BluezQt::DevicePtr device, const BluezQt::Re + void BluetoothAgent::displayPasskey(BluezQt::DevicePtr device, const QString &passkey, const QString &entered) + { + qDebug() << Q_FUNC_INFO << ( m_device.isNull() ? "NULL" : m_device.data()->address() ) << entered << passkey; ++ cancelEmitDevStatus(device->address()); + if(m_displayedPasskey == passkey) + return; + +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index cb2db1a..813ef47 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -35,14 +35,17 @@ DelayStruct::~DelayStruct() + + void DelayStruct::close(void) + { ++ qDebug() << Q_FUNC_INFO << __LINE__; + this->killTimer(m_TimerID); + this->deleteLater(); + } + + void DelayStruct::timerEvent( QTimerEvent *event) + { ++ qDebug() << Q_FUNC_INFO << __LINE__; + if(nullptr != m_dev && nullptr != static_sess) + { ++ qDebug() << Q_FUNC_INFO << __LINE__ << m_dev->address() << m_dev->isConnected(); + emit static_sess->devConnectStatusSignal(m_dev->address(), m_dev->isConnected()); + if (m_dev->isConnected() && m_dev->isPaired()) { + Config::writeKeyFile(m_dev->address(),m_dev->name(),m_dev->type()); +@@ -63,7 +66,7 @@ static void init_static_sess(SessionDbusRegister * p) + static_sess = p; + } + +-static void addDelay(BluezQt::DevicePtr dev) ++void addDelay(BluezQt::DevicePtr dev) + { + if(nullptr != dev) + { +@@ -77,6 +80,11 @@ static void addDelay(BluezQt::DevicePtr dev) + } + } + ++static bool existDelay(QString key) ++{ ++ return (static_delays.find(key) != static_delays.end()); ++} ++ + ////////////////////////////////////////////SessionDbusRegister//////////////////////////////////// + ////////////////////////////////////////////SessionDbusRegister//////////////////////////////////// + +@@ -652,18 +660,31 @@ void SessionDbusRegister::connectSignal() + + connect(devPtr.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << devPtr.data()->address() << +- v << devPtr.data()->isPaired() << devPtr->isConnected(); ++ v << devPtr.data()->isPaired() << devPtr->isConnected()<< devPtr.data()->type(); + //已匹配设备,且改变为连接状态,延时发送,暂时定义2s + if(devPtr->isPaired() && v) + { + addDelay(devPtr); + } ++ //未匹配,且为连接状态, 不发送 ++ else if(!devPtr->isPaired() && v) ++ { ++ ; ++ } + else + { +- emit devConnectStatusSignal(devPtr.data()->address(),v); ++ if(existDelay(devPtr->address())) ++ { ++ qDebug() << Q_FUNC_INFO << __LINE__ << "existDelay " << devPtr->address(); ++ } ++ else ++ { ++ qDebug() << Q_FUNC_INFO<< __LINE__ << "emit " << devPtr->address() << v; ++ emit devConnectStatusSignal(devPtr->address(),v); + +- if (v && devPtr.data()->isPaired()) { +- Config::writeKeyFile(devPtr.data()->address(),devPtr.data()->name(),devPtr.data()->type()); ++ if (v && devPtr->isPaired()) { ++ Config::writeKeyFile(devPtr->address(),devPtr->name(),devPtr->type()); ++ } + } + } + +@@ -707,19 +728,32 @@ void SessionDbusRegister::connectSignal() + + connect(dev.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << dev.data()->address() << +- v << dev.data()->isPaired() << dev->isConnected(); ++ v << dev.data()->isPaired() << dev->isConnected() << dev->type(); + + //已匹配设备,且改变为连接状态,延时发送,暂时定义2s + if(dev->isPaired() && v) + { + addDelay(dev); + } ++ //未匹配,且为连接状态, 不发送 ++ else if(!dev->isPaired() && v) ++ { ++ ; ++ } + else + { +- emit devConnectStatusSignal(dev.data()->address(),v); ++ if(existDelay(dev->address())) ++ { ++ qDebug() << Q_FUNC_INFO << __LINE__ << "existDelay " << dev->address(); ++ } ++ else ++ { ++ qDebug() << Q_FUNC_INFO<< __LINE__ << "emit " << dev->address() << v; ++ emit devConnectStatusSignal(dev.data()->address(),v); + +- if (v && dev.data()->isPaired()) { +- Config::writeKeyFile(dev.data()->address(),dev.data()->name(),dev.data()->type()); ++ if (v && dev.data()->isPaired()) { ++ Config::writeKeyFile(dev.data()->address(),dev.data()->name(),dev.data()->type()); ++ } + } + } + +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index 54a1303..67fc32b 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -35,19 +35,20 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + + this->setPalette(palette); + this->setAutoFillBackground(true); +- //title_icon = new QLabel(this); +- //title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); +- //title_icon->resize(22,22); +- +- //title_text = new QLabel(tr("Bluetooth Connections"),this); +- //title_text->setStyleSheet("QLabel{\ +- // width: 200px;\ +- // height: 20px;\ +- // font-size: 14px;\ +- // font-family: Noto Sans CJK SC;\ +- // font-weight: 400;\ +- // line-height: 24px;\ +- // opacity: 1;}"); ++ title_icon = new QLabel(this); ++ title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); ++ title_icon->resize(22,22); ++ ++ title_text = new QLabel(tr("Bluetooth Connections"),this); ++ title_text->setStyleSheet("QLabel{\ ++ width: 200px;\ ++ height: 20px;\ ++ font-size: 14px;\ ++ font-family: Noto Sans CJK SC;\ ++ font-weight: 400;\ ++ line-height: 24px;\ ++ opacity: 1;}"); ++ title_text->adjustSize(); + + //QString top_text = tr("Bluetooth Connect Request From \'")+dev_name+tr("\'."); + QString tip_text; +@@ -125,12 +126,14 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + font-weight: 400;\ + line-height: 24px;}"); + } else { +- this->setFixedSize(520,202); +- PIN_label->setGeometry(32,75,207,36); +- tip_label->setGeometry(32,40,430,40); ++ this->setFixedSize(520,212); ++ title_icon->setGeometry(8, 8, 20, 22); ++ title_text->setGeometry(36, 9, 56, 20); ++ PIN_label->setGeometry(25,84,207,36); ++ tip_label->setGeometry(25,56,437,20); + //top_label->setGeometry(32,56,456,50); +- accept_btn->setGeometry(392,143,96,36); +- refuse_btn->setGeometry(280,143,96,36); ++ accept_btn->setGeometry(392,152,96,36); ++ refuse_btn->setGeometry(288,152,96,36); + } + } + diff --git a/patches/resolve_task_removeHuaeiSendfile.patch b/patches/resolve_task_removeHuaeiSendfile.patch new file mode 100644 index 0000000..3405c46 --- /dev/null +++ b/patches/resolve_task_removeHuaeiSendfile.patch @@ -0,0 +1,273 @@ +diff --git a/service/config.cpp b/service/config.cpp +index c9ad351..d96ac66 100644 +--- a/service/config.cpp ++++ b/service/config.cpp +@@ -122,3 +122,5 @@ void Config::removeKey(QString addr) + qDebug() << Q_FUNC_INFO << addr << response.errorMessage(); + + } ++ ++bool global_ishuawei = false; +diff --git a/service/config.h b/service/config.h +index 0d9087b..195e486 100644 +--- a/service/config.h ++++ b/service/config.h +@@ -12,6 +12,9 @@ + #include + #include + ++//全局变量,是否是华为机器, 默认false, 在config.cpp文件定义 ++extern bool global_ishuawei; ++ + class Config : public QObject + { + public: +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 26d5ebf..8de0ddc 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -192,7 +192,13 @@ void Daemon::rfkillStatusChange(int status) + qInfo() << Q_FUNC_INFO << "init defualt Adapter!!!" << _BluezManager->isBluetoothOperational(); + + if (findStartupOptions("-o") || findStartupOptions("--obex")) +- initObexManager(); ++ { ++ //非华为机器才存在文件传输功能 ++ if(!global_ishuawei) ++ { ++ initObexManager(); ++ } ++ } + + monitorDbusSignal(); + break; +diff --git a/service/main.cpp b/service/main.cpp +index 799718b..0903a3f 100644 +--- a/service/main.cpp ++++ b/service/main.cpp +@@ -19,10 +19,44 @@ void signalHandlerFunc(int signal) { + fprintf(stderr,"---------------------- %d",signal); + } + ++ ++static QString executeLinuxCmd(QString strCmd) ++{ ++ QProcess p; ++ p.start("bash", QStringList() <<"-c" << strCmd); ++ p.waitForFinished(); ++ QString strResult = p.readAllStandardOutput(); ++ return strResult.toLower(); ++} ++ ++static bool IsHuawei() ++{ ++ QString str = executeLinuxCmd("cat /proc/cpuinfo | grep Hardware"); ++ if(str.length() == 0) ++ { ++ return false; ++ } ++ ++ if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || ++ str.indexOf("kirin") != -1) ++ { ++ return true; ++ } ++ else ++ { ++ return false; ++ } ++ return false; ++} ++ + int main(int argc, char *argv[]) + { + fprintf(stdout,"Program running.....\n"); + initUkuiLog4qt(QString("bluetoothserver")); ++ ++ global_ishuawei = IsHuawei(); ++ qDebug() << "Ishuawei: "<< global_ishuawei; ++ + QtSingleCoreApplication a(argc, argv); + a.setOrganizationName("Kylin Team"); + a.setApplicationName("dbus-bluetooth-service"); +diff --git a/ukcc-bluetooth/bluetooth.cpp b/ukcc-bluetooth/bluetooth.cpp +index 396f7c3..a7da411 100644 +--- a/ukcc-bluetooth/bluetooth.cpp ++++ b/ukcc-bluetooth/bluetooth.cpp +@@ -4,8 +4,41 @@ + #include + #include + ++ ++static QString executeLinuxCmd(QString strCmd) ++{ ++ QProcess p; ++ p.start("bash", QStringList() <<"-c" << strCmd); ++ p.waitForFinished(); ++ QString strResult = p.readAllStandardOutput(); ++ return strResult.toLower(); ++} ++ ++static bool IsHuawei() ++{ ++ QString str = executeLinuxCmd("cat /proc/cpuinfo | grep Hardware"); ++ if(str.length() == 0) ++ { ++ return false; ++ } ++ ++ if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || ++ str.indexOf("kirin") != -1) ++ { ++ return true; ++ } ++ else ++ { ++ return false; ++ } ++ return false; ++} ++ + Bluetooth::Bluetooth() : mFirstLoad(true) { + ++ global_ishuawei = IsHuawei(); ++ qDebug() << "Ishuawei: "<< global_ishuawei; ++ + QTranslator * translator = new QTranslator(this);; + translator->load("/usr/share/ukui-bluetooth/translations/ukcc-bluetooth_" + QLocale::system().name() + ".qm"); + QApplication::installTranslator(translator); +@@ -105,4 +138,4 @@ void Bluetooth::plugin_leave() + pluginWidget->setbluetoothAdapterDiscoveringStatus(false); + } + +- ++bool global_ishuawei = false; +diff --git a/ukcc-bluetooth/config.h b/ukcc-bluetooth/config.h +index 02b49fb..92027f8 100644 +--- a/ukcc-bluetooth/config.h ++++ b/ukcc-bluetooth/config.h +@@ -11,4 +11,6 @@ const QString SERVICE = "com.ukui.bluetooth"; + const QString PATH = "/com/ukui/bluetooth"; + const QString INTERFACE = "com.ukui.bluetooth"; + ++//全局变量,是否是华为机器, 默认false, 在bluetooth.cpp文件里面定义 ++extern bool global_ishuawei; + #endif // CONFIG_H +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 1d2b5f3..581dde8 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -400,10 +400,14 @@ void DeviceInfoItem::MouseClickedDevFunc() + if (bluetoothdevice::DEVICE_TYPE::phone == _MDev->getDevType() || + bluetoothdevice::DEVICE_TYPE::computer == _MDev->getDevType()) + { +- QAction *sendfile = new QAction(dev_Menu); +- sendfile->setText(tr("send file")); +- dev_Menu->addAction(sendfile); +- dev_Menu->addSeparator(); ++ //非华为机器才存在文件传输功能 ++ if(!global_ishuawei) ++ { ++ QAction *sendfile = new QAction(dev_Menu); ++ sendfile->setText(tr("send file")); ++ dev_Menu->addAction(sendfile); ++ dev_Menu->addSeparator(); ++ } + } + + QAction *remove = new QAction(dev_Menu); +diff --git a/ukui-bluetooth/config/config.cpp b/ukui-bluetooth/config/config.cpp +index d93784d..6630a99 100644 +--- a/ukui-bluetooth/config/config.cpp ++++ b/ukui-bluetooth/config/config.cpp +@@ -42,3 +42,5 @@ void Config::OpenBluetoothSettings() + arg << "--bluetooth"; + process->start(cmd,arg); + } ++ ++bool global_ishuawei = false; +diff --git a/ukui-bluetooth/config/config.h b/ukui-bluetooth/config/config.h +index dddefdf..3e495f9 100644 +--- a/ukui-bluetooth/config/config.h ++++ b/ukui-bluetooth/config/config.h +@@ -8,6 +8,9 @@ + #include + #include + ++//全局变量,是否是华为机器, 默认false, 在config.cpp文件定义 ++extern bool global_ishuawei; ++ + class Config : public QObject + { + Q_OBJECT +diff --git a/ukui-bluetooth/main/main.cpp b/ukui-bluetooth/main/main.cpp +index 57d4a1f..13465c1 100644 +--- a/ukui-bluetooth/main/main.cpp ++++ b/ukui-bluetooth/main/main.cpp +@@ -9,10 +9,44 @@ + #include + #include + ++ ++static QString executeLinuxCmd(QString strCmd) ++{ ++ QProcess p; ++ p.start("bash", QStringList() <<"-c" << strCmd); ++ p.waitForFinished(); ++ QString strResult = p.readAllStandardOutput(); ++ return strResult.toLower(); ++} ++ ++static bool IsHuawei() ++{ ++ QString str = executeLinuxCmd("cat /proc/cpuinfo | grep Hardware"); ++ if(str.length() == 0) ++ { ++ return false; ++ } ++ ++ if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || ++ str.indexOf("kirin") != -1) ++ { ++ return true; ++ } ++ else ++ { ++ return false; ++ } ++ return false; ++} ++ ++ + int main(int argc, char *argv[]) + { + initUkuiLog4qt("ukui-bluetooth"); + ++ global_ishuawei = IsHuawei(); ++ qDebug() << "Ishuawei: "<< global_ishuawei; ++ + QtSingleApplication app(argc, argv); + // QApplication::setStyle(QStyleFactory::create("ukui-default")); + QApplication::setQuitOnLastWindowClosed(false); +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index 493f1e4..a09becb 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -11,9 +11,14 @@ MainProgram::MainProgram(bool intel, QObject *parent) : + if (!_mIntel) + UI->setWidgetPosition(); + +- connect(_sessionDbus, &BluetoothDbus::receiveFilesSignal, this, &MainProgram::receiveFileSlot); +- connect(_sessionDbus, &BluetoothDbus::sendTransferDeviceMesgSignal, this, &MainProgram::sendTransferDeviceMesgSlot); +- connect(_sessionDbus, &BluetoothDbus::sendTransferFilesMesgSignal, this, &MainProgram::sendTransferFilesMesgSlot); ++ //非华为机器才存在文件功能 ++ if(!global_ishuawei) ++ { ++ connect(_sessionDbus, &BluetoothDbus::receiveFilesSignal, this, &MainProgram::receiveFileSlot); ++ connect(_sessionDbus, &BluetoothDbus::sendTransferDeviceMesgSignal, this, &MainProgram::sendTransferDeviceMesgSlot); ++ connect(_sessionDbus, &BluetoothDbus::sendTransferFilesMesgSignal, this, &MainProgram::sendTransferFilesMesgSlot); ++ } ++ + connect(_sessionDbus, &BluetoothDbus::displayPasskeySignal, this, &MainProgram::requestConfirmationSlot); + connect(_sessionDbus, &BluetoothDbus::requestConfirmationSignal, this, &MainProgram::requestConfirmationSlot); + connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired) { diff --git a/patches/restart_bluez_traywidget_error.patch b/patches/restart_bluez_traywidget_error.patch new file mode 100644 index 0000000..9290f6a --- /dev/null +++ b/patches/restart_bluez_traywidget_error.patch @@ -0,0 +1,96 @@ +Index: upstream/ukui-bluetooth/daemon/bluetoothdbus.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/daemon/bluetoothdbus.cpp ++++ upstream/ukui-bluetooth/daemon/bluetoothdbus.cpp +@@ -36,11 +36,11 @@ void BluetoothDbus::connectDBusSignals() + + + //文件传输相关dbus ++ CONNECT_DBUS_SIGNAL("fileReceivingSignal", receiveFilesSlot(QString,QString,QString,quint64)); + TRANSFER_DBUS_SIGNAL("obexAgentCanceled", obexAgentCanceledSignal()); + TRANSFER_DBUS_SIGNAL("fileReceiveMore", fileReceiveMore(QString, quint64, QString)); + TRANSFER_DBUS_SIGNAL("sendTransferFilesMesg", sendTransferFilesMesgSignal(QStringList)); + TRANSFER_DBUS_SIGNAL("sendTransferDeviceMesg", sendTransferDeviceMesgSignal(QString)); +- TRANSFER_DBUS_SIGNAL("fileReceivingSignal", receiveFilesSlot(QString,QString,QString,quint64)); + TRANSFER_DBUS_SIGNAL("transferredChanged", transferredChangedSignal(quint64)); + TRANSFER_DBUS_SIGNAL("statusChanged", statusChangedSignal(QString)); + qDebug() << Q_FUNC_INFO << __LINE__; +Index: upstream/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp ++++ upstream/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp +@@ -23,7 +23,6 @@ FileReceivingPopupWidget::FileReceivingP + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("Bluetooth file transfer")); + this->setAttribute(Qt::WA_DeleteOnClose); +- this->setWindowFlag(Qt::WindowStaysOnTopHint); + + QPalette palette; + if(StyleSettings->get("style-name").toString() == "ukui-default" || StyleSettings->get("style-name").toString() == "ukui-light"){ +Index: upstream/ukui-bluetooth/main/mainprogram.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/main/mainprogram.cpp ++++ upstream/ukui-bluetooth/main/mainprogram.cpp +@@ -260,6 +260,7 @@ void MainProgram::displayPasskeySlot(QSt + + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { + Keypincodewidget->pairFailureShow(); ++ Keypincodewidget = nullptr; + disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); + }); + connect(_sessionDbus, &BluetoothDbus::devPairSignal, this, [=](QString _name, bool paired){ +@@ -269,8 +270,10 @@ void MainProgram::displayPasskeySlot(QSt + Keypincodewidget->setHidden(true); + else + QTimer::singleShot(1000,this,[=]{ +- if (!_sessionDbus->isConnected(name)) ++ if (!_sessionDbus->isConnected(name)) { + Keypincodewidget->pairFailureShow(); ++ Keypincodewidget = nullptr; ++ } + }); + disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); + }); +@@ -311,6 +314,7 @@ void MainProgram::requestConfirmationSlo + _sessionDbus->replyRequestConfirmation(false); + if (pincodewidget != nullptr) { + pincodewidget->close(); ++ pincodewidget = nullptr; + } + } + disconnect(_sessionDbus, &BluetoothDbus::devPairSignal, nullptr, nullptr); +Index: upstream/ukui-bluetooth/mainwidget/traywidget.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/mainwidget/traywidget.cpp ++++ upstream/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -84,13 +84,14 @@ void TrayWidget::openBluetoothSlot(bool + _SessionDBus->setDefaultAdapterPower(v); + if (!_Intel && !pairedDevices.size()) + return; +- if (v) { +- _MStackedWidget->setCurrentIndex(0); +- } else { +- _MStackedWidget->setCurrentIndex(1); +- } +- if (_Intel) ++ if (_Intel) { ++ if (v) { ++ _MStackedWidget->setCurrentIndex(0); ++ } else { ++ _MStackedWidget->setCurrentIndex(1); ++ } + return; ++ } + _MStackedWidget->setVisible(v); + lineFrame->setVisible(v); + if (_MSelf) +@@ -204,7 +205,8 @@ void TrayWidget::InitMemberVariables() + + _MStackedWidget->setFixedSize(420,445); + _MStackedWidget->addWidget(_NomalWidget); +- _MStackedWidget->addWidget(_ErrorWidget); ++ if (_Intel) ++ _MStackedWidget->addWidget(_ErrorWidget); + _MStackedWidget->setCurrentIndex(0); + + _MLabel->resize(60,24); diff --git a/patches/restart_state_synchronization.patch b/patches/restart_state_synchronization.patch new file mode 100644 index 0000000..2fdc641 --- /dev/null +++ b/patches/restart_state_synchronization.patch @@ -0,0 +1,111 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index ca0441c..94e72db 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -58,6 +58,8 @@ Daemon::Daemon(QObject *parent) : + qDebug() << Q_FUNC_INFO << QCoreApplication::arguments() << findStartupOptions("-d"); + qDebug() << "main currentThreadId:" << QThread::currentThreadId(); + ++ initGSettingInfo(); ++ + // ===== 创建rfkill的监听,并将监听逻辑放入子线程 ====== START ============= + _rfkill = new Rfkill(); + _rfkillThread = new QThread(this); +@@ -222,7 +224,6 @@ void Daemon::rfkillStatusChange(int status) + switch (status) { + case 0: + initBluezManager(); +- initGSettingInfo(); + + qInfo() << Q_FUNC_INFO << "init defualt Adapter!!!" << _BluezManager->isBluetoothOperational(); + +@@ -333,11 +334,16 @@ void Daemon::initBluezManager() + _DefualtAdapter = this->getDefualtAdapter(); + launchDbusSignal(); + launchTrayUI(); ++ ++ _DefualtAdapter.data()->setPowered(_mGsetting["switch"].toBool()); ++ + reconnectFunc(); + qInfo() << Q_FUNC_INFO << __LINE__; + +- + connect(_DefualtAdapter.data(),&BluezQt::Adapter::poweredChanged,this,[=](bool v){ ++ ++ _mConfig->gsetting->set("switch",QVariant(v)); ++ + if (v) + reconnectFunc(); + }); +@@ -636,6 +642,11 @@ void Daemon::launchDbusSignal() + + void Daemon::reconnectFunc() + { ++ if (!_mGsetting["switch"].toBool()) { ++ qInfo() << Q_FUNC_INFO << "Adapter is power down;"; ++ return; ++ } ++ + qInfo() << Q_FUNC_INFO << "START"; + QTimer::singleShot(400,this,[=]{ + QStringList target_list = Config::getDeviceConnectTimeList(QString("/etc/pairDevice.list")); +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 780d08a..094b42e 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -38,21 +38,6 @@ bool SessionDbusRegister::InterfaceAlreadyExists() + return reply.value() == ""; + } + +-void SessionDbusRegister::devConnectFunc(BluezQt::DevicePtr dev) +-{ +- qDebug () << Q_FUNC_INFO << __LINE__; +- if (dev.data()->isPaired()) { +- AudioDevConnectFunc(dev); +- } else { +- BluezQt::PendingCall *call = dev.data()->pair(); +- connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ +- if (callReturn->error() == 0) { +- AudioDevConnectFunc(dev); +- } +- }); +- } +-} +- + void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << __LINE__; +@@ -247,19 +232,14 @@ void SessionDbusRegister::devConnect(const QString addr) + return; + + if (devPtr.data()->isPaired()) { +- devConnectFunc(devPtr); ++ AudioDevConnectFunc(devPtr); + } else { + BluezQt::PendingCall *call = devPtr.data()->pair(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { + emit devOperateErrorSignal(devPtr.data()->address()); + } else +- //这里finished状态得到后,设备的pair状态平没有马上修改这里有个时间差 +- qDebug() << Q_FUNC_INFO << devPtr->isPaired() << __LINE__; +- QTimer::singleShot(500,this,[=]{ +- qDebug() << Q_FUNC_INFO << "time out send connect:" << devPtr->isPaired() << __LINE__; +- devConnectFunc(devPtr); +- }); ++ AudioDevConnectFunc(devPtr); + }); + } + } +diff --git a/service/sessiondbusregister.h b/service/sessiondbusregister.h +index 8ecd8cc..849250e 100644 +--- a/service/sessiondbusregister.h ++++ b/service/sessiondbusregister.h +@@ -34,7 +34,6 @@ public: + + private: + bool InterfaceAlreadyExists(); +- void devConnectFunc(BluezQt::DevicePtr); + void AudioDevConnectFunc(BluezQt::DevicePtr); + public slots: + // 蓝牙默认适配器信息处理dbus diff --git a/patches/send_file_widget_dark_theme_fixed.patch b/patches/send_file_widget_dark_theme_fixed.patch new file mode 100644 index 0000000..26b4fbf --- /dev/null +++ b/patches/send_file_widget_dark_theme_fixed.patch @@ -0,0 +1,120 @@ +Index: upstream/ukui-bluetooth/fileSend/deviceselectitem.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/fileSend/deviceselectitem.cpp ++++ upstream/ukui-bluetooth/fileSend/deviceselectitem.cpp +@@ -66,13 +66,21 @@ QColor DeviceSelectItem::getPainterBrush + color = QColor(0,0,0,0); + break; + case Status::Hover: +- color = QColor(217,217,217,tran); ++ if(StyleSettings->get("style-name").toString() == "ukui-default" ++ || StyleSettings->get("style-name").toString() == "ukui-light") ++ color = QColor(217,217,217,tran); ++ else ++ color = QColor(55, 55, 59, tran); + break; + case Status::Click: +- color = QColor(209, 209, 209,tran); ++ if(StyleSettings->get("style-name").toString() == "ukui-default" ++ || StyleSettings->get("style-name").toString() == "ukui-light") ++ color = QColor(209, 209, 209,tran); ++ else ++ color = QColor(102, 102, 102, tran); + break; + case Status::Choose: +- color = QColor(55, 144, 250,tran); ++ color = QColor(55, 144, 250,tran); + break; + default: + if(StyleSettings->get("style-name").toString() == "ukui-default" +@@ -85,6 +93,48 @@ QColor DeviceSelectItem::getPainterBrush + return color; + } + ++const QPixmap DeviceSelectItem::loadSvg(const QPixmap &source, const PixmapColor &cgColor) ++{ ++ QImage img = source.toImage(); ++ for (int x = 0; x < img.width(); x++) { ++ for (int y = 0; y < img.height(); y++) { ++ auto color = img.pixelColor(x, y); ++ if (color.alpha() > 0) { ++ switch (cgColor) { ++ case PixmapColor::WHITE: ++ color.setRed(255); ++ color.setGreen(255); ++ color.setBlue(255); ++ img.setPixelColor(x, y, color); ++ break; ++ case PixmapColor::BLACK: ++ color.setRed(0); ++ color.setGreen(0); ++ color.setBlue(0); ++ img.setPixelColor(x, y, color); ++ break; ++ case PixmapColor::GRAY: ++ color.setRed(152); ++ color.setGreen(163); ++ color.setBlue(164); ++ img.setPixelColor(x, y, color); ++ break; ++ case PixmapColor::BLUE: ++ color.setRed(61); ++ color.setGreen(107); ++ color.setBlue(229); ++ img.setPixelColor(x, y, color); ++ break; ++ default: ++ return source; ++ break; ++ } ++ } ++ } ++ } ++ return QPixmap::fromImage(img); ++} ++ + void DeviceSelectItem::enterEvent(QEvent *event) { + Q_UNUSED(event); + if (choosed) +@@ -132,10 +182,12 @@ void DeviceSelectItem::paintEvent(QPaint + painter.setBrush(getPainterBrushColor()); + painter.drawRoundedRect(this->rect(),6,6,Qt::AbsoluteSize); + painter.setRenderHint(QPainter::SmoothPixmapTransform); +- style()->drawItemPixmap(&painter, QRect(8, 13, 24, 24), Qt::AlignCenter, MIcon.pixmap(24,24)); +- if(StyleSettings->get("style-name").toString() == "ukui-default" || StyleSettings->get("style-name").toString() == "ukui-light") ++ if(StyleSettings->get("style-name").toString() == "ukui-default" || StyleSettings->get("style-name").toString() == "ukui-light") { + painter.setPen(QColor(Qt::black)); +- else ++ style()->drawItemPixmap(&painter, QRect(8, 13, 24, 24), Qt::AlignCenter, MIcon.pixmap(24,24)); ++ } else { + painter.setPen(QColor(Qt::white)); ++ style()->drawItemPixmap(&painter, QRect(8, 13, 24, 24), Qt::AlignCenter, loadSvg(MIcon.pixmap(24,24), PixmapColor::WHITE)); ++ } + painter.drawText(40,13,280,28,Qt::AlignLeft, MName); + } +Index: upstream/ukui-bluetooth/fileSend/deviceselectitem.h +=================================================================== +--- upstream.orig/ukui-bluetooth/fileSend/deviceselectitem.h ++++ upstream/ukui-bluetooth/fileSend/deviceselectitem.h +@@ -30,6 +30,13 @@ public: + }; + Q_ENUM(Status) + ++ enum PixmapColor { ++ WHITE = 0, ++ BLACK, ++ GRAY, ++ BLUE, ++ }; ++ Q_ENUM(PixmapColor) + private: + QIcon MIcon; + QString MName; +@@ -42,6 +49,7 @@ private: + bool choosed = false; + + QColor getPainterBrushColor(); ++ const QPixmap loadSvg(const QPixmap &source, const PixmapColor &cgColor); + + protected: + void enterEvent(QEvent *event); diff --git a/patches/send_multiple_files.patch b/patches/send_multiple_files.patch new file mode 100644 index 0000000..84237b4 --- /dev/null +++ b/patches/send_multiple_files.patch @@ -0,0 +1,19 @@ +Index: ukui-bluetooth/ukui-bluetooth/main/mainprogram.cpp +=================================================================== +--- ukui-bluetooth.orig/ukui-bluetooth/main/mainprogram.cpp ++++ ukui-bluetooth/ukui-bluetooth/main/mainprogram.cpp +@@ -198,7 +198,13 @@ void MainProgram::sendTransferDeviceMesg + void MainProgram::sendTransferFilesMesgSlot(QStringList targetList) + { + qDebug() << "Select file:" << targetList; +- selectedFiles = targetList; ++ //selectedFiles = targetList; ++ for (int i = 0 ; i < targetList.size() ; i++) ++ { ++ QString str = targetList.at(i); ++ str = str.replace(QString("file://"), QString("")); ++ selectedFiles.append(str); ++ } + qDebug() << "Select file:" << selectedFiles; + if(selectedFiles.size() != 0){ + if (BluetoothFileTransferWidget::isShow == false) { diff --git a/patches/sendfile_again_widget_doesnt_change.patch b/patches/sendfile_again_widget_doesnt_change.patch new file mode 100644 index 0000000..5932931 --- /dev/null +++ b/patches/sendfile_again_widget_doesnt_change.patch @@ -0,0 +1,46 @@ +diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +index a71d2e3..282c544 100644 +--- a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp ++++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp +@@ -407,7 +407,13 @@ void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { + } + int transfing = fileNums - selectedFiles.size() + 1; + transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); ++ if (fileNums > 1) ++ m_progressbar->setGeometry(32,175,406,8); ++ else ++ m_progressbar->setGeometry(32,175,454,8); ++ transNum->setVisible(fileNums - 1); + this->update(); ++ this->activateWindow(); + } + + +@@ -442,6 +448,7 @@ void BluetoothFileTransferWidget::get_transfer_status(QString status) + target_icon->setPixmap(file_icon.at(0).pixmap(64,64)); + int transfing = fileNums - selectedFiles.size() + 1; + transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); ++ this->activateWindow(); + return; + } + selectedFiles.clear(); +@@ -484,6 +491,7 @@ void BluetoothFileTransferWidget::get_transfer_status(QString status) + target_size->setVisible(false); + + cancel_btn->setText(tr("Close")); ++ this->activateWindow(); + this->send_state = _SEND_COMPLETE ; + }else if(status == QString("Active")){ + this->send_state = _SENDING ; +diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp +index 352b199..a241484 100644 +--- a/ukui-bluetooth/main/mainprogram.cpp ++++ b/ukui-bluetooth/main/mainprogram.cpp +@@ -317,6 +317,7 @@ void MainProgram::requestConfirmationSlot(QString name, QString passkey) + } + }); + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { ++ qDebug() << Q_FUNC_INFO << __LINE__; + if (pincodewidget != nullptr) { + if (pincodewidget->canceled) + return; diff --git a/patches/series b/patches/series new file mode 100644 index 0000000..0a056ce --- /dev/null +++ b/patches/series @@ -0,0 +1,135 @@ +fix_bluetooth_style.patch +fix_bluetooth_ukcc_crash.patch +fix_bluetoothService_crash.patch +send_multiple_files.patch +resolve_pinshow.patch +Icon_Transfer_to_White.patch +fix_bluetooth_show_bug.patch +bluetooth_pangguw_ukcc_cut.patch +resolve_bluezreboot.patch +transfer_file_ranslations.patch +cloes_bt_by_trayWidget_segment_fault.patch +restart_bluez_traywidget_error.patch +fix_transferwidget_has_wrong_show_on_details.patch +add_bo_zh_translations.patch +namechanged_error_and_fileReceive_wrong_UI.patch +ukcc_pullup_bluetoothService.patch +ukbt_label_size_and_translation_and_may_segmentfault.patch +resolve_nopair_status.patch +send_file_widget_dark_theme_fixed.patch +font_size_shown_in_traywidget.patch +resolve_ukcc_devview.patch +traywidget_label_size.patch +ukcc_bluetooth_more_adapter.patch +fix_background_transparency_calc.patch +fix_file_send_widget_file_num.patch +resolve_bluesvr_crash.patch +ukcc_bluetooth_93217and94720.patch +ukcc_bluetooth_delete_scan.patch +ukcc_bluetooth_ui_error.patch +huawei_connect_back_strategy.patch +fix_append_files_to_tail_of_query_when_sending_files.patch +fixed_bug_89263.patch +fix_send_file_no_type_icon.patch +fix_incorrect_modify.patch +fixed_bug_93037.patch +fix_2th_send_file_failed.patch +fix_segment_fault_in_send_non_type_file.patch +fix_send_file_when_delete_file.patch +resolve_delaybluestatus.patch +ukcc_bluetooth_s4_core.patch +fix_dev_name_label_size.patch +fixed_bug_94862_66894.patch +resolve_pinwiget_status.patch +fix_pin_code_layout_and_translations.patch +fix_chzn_show_and_tooltip_problem.patch +ukcc_bluetooth_fix_show_error.patch +Re-fix_Modify_back_link_and_layout.patch +ukcc_bluetooth_fix_zh_show_error.patch +resolve_bluedevstatus.patch +ukcc_bluetooth_conn_fail_show_error.patch +fix_ukbt_segment_faulse_and_right_click_menu_cannot_open_bluetoothsetting.patch +ukcc_bluetooth_ota_upgrade.patch +fix_pair_timeout_twice_segement_fualt_and_tray_menu_action_icon.patch +ukcc_bluetooth_clear_core.patch +fix_ukbt_layout_when_scale_150%.patch +0001-fixed-bug-97200-bug-97056-bug-91207.patch +ukcc_bluetooth_pin_time_connect_fail.patch +ukcc_bluetooth_optimize_device_connection_display.patch +resolve_bluez_reboot.patch +fileSend_and_fileReceive_filetype_show.patch +fix_label_show_on_file_send_progress_bar.patch +resolev_fix98561.patch +fix_send_file_widget_wrong_long_of_label.patch +resolve_fix97544.patch +fix_no_actions_when_remote_device_cancel_sending.patch +resolve_task_removeHuaeiSendfile.patch +fix_change_system_font_size_label_doesnt_change.patch +fix_when_transfer_fail_window_doesnt_activate.patch +resolve_keyboard_display.patch +resolve_keyboard_display1.patch +fix_first_time_connect_change_remote_device_name_segment_fault.patch +add_intel_tray_UI_open_interface.patch +ukcc_bluetooth_name_change_error.patch +delete_install_depend_conflict_blueman.patch +fix_pin_code_widget_title_and_intel_tray_icon_hide.patch +0001-fixed-bug-97561.patch +fixed_bug_97056.patch +fix_send_file_widget_label_width.patch +sendfile_again_widget_doesnt_change.patch +fix_wrong_click_color_in_circle_icon.patch +fix_three_status_in_settings_label.patch +fix_wrong_icon_in_classic_icon_theme.patch +ukcc_bluetooth_fix_zoom_device_name_show_error.patch +ukcc_bluetooth_fix_bug98646.patch +fix_different_gsetting_key.patch +ukcc_bluetooth_fix_remove_show_window.patch +Modify_interface_anomalies_and_compatibility_issues.patch +fix_bug101672and102290.patch +ukcc_bluetooth_fix_device_random_mac.patch +pmodify_intel_UI.patch +bluetoothService_fix_102535.patch +ukcc_bluetooth_fix_devConnect_signal.patch +ukcc_bluetooth_fix_optimize_error_info.patch +fixed_bug_101081.patch +resolve_100352and100295.patch +fix_audiovideo_icon_wrong.patch +delete_battery_shown_in_HUAWEI.patch +fix_102683.patch +ukcc_bluetooth_fix_more_adapter.patch +fix_receive_file_from_WINDOWS_icon_after_click_accept.patch +ukcc_bluetooth_show_state_error.patch +bluetoothService_before_pair_stop_discovery.patch +fix_bug103413.patch +the_interface_shows_a_line_problem.patch +ukcc_bluetooth_fix_bug103561.patch +add_intel_window_manager_protocol.patch +ukcc_bluetooth_huawei_disconnect.patch +sleep_state_problem.patch +bluetoothService_segmentation_fault.patch +ukcc_bluetooth_fix_cmpbug103927.patch +fix_lasted_mistake.patch +fix_unsorted_table_in_traywidget_and_upgrade_the_speed_of_open_up.patch +fix_widget_font_size_change.patch +fix_cannot_send_symbol_named_files.patch +ukcc_bluetooth_and_bluetoothService_scan_optimise.patch +ukcc_bleutooth_add_disconnect_btn.patch +fix_traywidget_window_frameless.patch +ukcc_bluetooth_fix_bug101654.patch +ukcc_bluetooth_fixbug105541.patch +ukcc_bluetooth_fix_widget_show_error.patch +ukcc_bluetooth_fix_bug104249.patch +ukcc_bluetooth_fixbug105687.patch +fix_file_send_widget_may_not_pop_out.patch +bluetoothService_fix_bug105897.patch +bluetoothService_modify_phone_only_connection_audio_source.patch +fix_segmentfault_and_clicked_active_icon.patch +ukcc_bluetooth_fix_probability_show_connectfail.patch +fix_init_font_size.patch +fix_signal_canceled_bind.patch +fix_external_screen_traywidget_show_geometry.patch +avoid_Intel_QT_MessageBox_Error.patch +optimum_101650.patch +fix_change_default_adapter_traywidget_changed_nothing.patch +fix_filesend_widget_file_name_label_height.patch +fix_huawei_scale_problem_and_remove_dev_without_notify.patch diff --git a/patches/sleep_state_problem.patch b/patches/sleep_state_problem.patch new file mode 100644 index 0000000..7374ebb --- /dev/null +++ b/patches/sleep_state_problem.patch @@ -0,0 +1,61 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 2736f5f..32b55bf 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -20,6 +20,7 @@ static qint64 blockChangeTime = 0; + qint64 powerChangeTime = 0; + bool resetFlag = false; + bool rebootFlag = false; ++bool sleepFlag = false; + + /************************************************ + * @brief 判断是否存在给定的程序启动参数 +@@ -583,6 +584,13 @@ void Daemon::monitorSleepSlot(bool sleep) + reconnectFunc(); + }else{ + qDebug() << "System goes to sleep !!!"; ++ if (_DefualtAdapter) { ++ if (abs(QDateTime::currentMSecsSinceEpoch() - ::powerChangeTime) >= 300) { ++ ::sleepFlag = false; ++ } else { ++ ::sleepFlag = true; ++ } ++ } + } + qDebug() << Q_FUNC_INFO << "end"; + +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 7a519b2..4acee4f 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -8,6 +8,7 @@ + + extern qint64 powerChangeTime; + extern bool resetFlag; ++extern bool sleepFlag; + + static bool isScan = false; + static SessionDbusRegister * static_sess = nullptr; +@@ -757,17 +758,18 @@ void SessionDbusRegister::connectSignal() + + ::powerChangeTime = QDateTime::currentMSecsSinceEpoch(); + +-// if (powered) ++ if (powered) + Daemon::reconnectFunc(); + +- if (::resetFlag || ::rebootFlag) { ++ if (::resetFlag || ::rebootFlag || ::sleepFlag) { + QTimer::singleShot(100,this,[=]{ + Daemon::_DefualtAdapter.data()->setPowered(false); + qDebug() << Q_FUNC_INFO << __LINE__; + }); +- qDebug() << Q_FUNC_INFO << __LINE__<< ::resetFlag << ::rebootFlag; +- ::resetFlag = false; ++ qDebug() << Q_FUNC_INFO << __LINE__<< ::resetFlag << ::rebootFlag << ::sleepFlag ; ++ ::resetFlag = false; + ::rebootFlag = false; ++ ::sleepFlag = false; + } + + Config::gsetting->set("switch",QVariant(powered)); diff --git a/patches/the_interface_shows_a_line_problem.patch b/patches/the_interface_shows_a_line_problem.patch new file mode 100644 index 0000000..2d6e631 --- /dev/null +++ b/patches/the_interface_shows_a_line_problem.patch @@ -0,0 +1,49 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index b6f387b..cd3020c 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -770,6 +770,9 @@ void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) + } + + if (device && device->isPaired()) { ++ ++ mDevFrameAddLineFrame("paired",device->getDevAddress()); ++ + DeviceInfoItem *item = new DeviceInfoItem(this,device); + item->setObjectName(device->getDevAddress()); + connect(item,SIGNAL(devPaired(QString)),this,SLOT(changeDeviceParentWindow(QString))); +@@ -783,7 +786,6 @@ void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) + }); + m_myDev_show_flag = true; + +- mDevFrameAddLineFrame("paired",device->getDevAddress()); + paired_dev_layout->addWidget(item,Qt::AlignTop); + } + return; +@@ -1798,6 +1800,9 @@ void BlueToothMain::changeDeviceParentWindow(const QString &address) + DeviceInfoItem *item = device_list->findChild(address); + QFrame *line_item = device_list->findChild("line-"+address); + if(item){ ++ ++ mDevFrameAddLineFrame("paired",address); ++ + device_list_layout->removeWidget(item); + item->setParent(frame_middle); + +@@ -1811,7 +1816,6 @@ void BlueToothMain::changeDeviceParentWindow(const QString &address) + bool isConnect = getDevConnectStatus(address); + reportDevConnectStatusSignal(address,isConnect); + +- mDevFrameAddLineFrame("paired",address); + paired_dev_layout->addWidget(item); + m_myDev_show_flag = true; + }else{ +@@ -2166,7 +2170,7 @@ void BlueToothMain::mDevFrameAddLineFrame(QString str,QString addr) + + if ("paired" == str) { + +- if (frame_middle->findChildren().size() <= 1) { ++ if (!frame_middle->findChildren().size()) { + return; + } + diff --git a/patches/traywidget_label_size.patch b/patches/traywidget_label_size.patch new file mode 100644 index 0000000..c11e28d --- /dev/null +++ b/patches/traywidget_label_size.patch @@ -0,0 +1,22 @@ +Index: upstream/ukui-bluetooth/mainwidget/traywidget.cpp +=================================================================== +--- upstream.orig/ukui-bluetooth/mainwidget/traywidget.cpp ++++ upstream/ukui-bluetooth/mainwidget/traywidget.cpp +@@ -95,7 +95,7 @@ void TrayWidget::openBluetoothSlot(bool + _MStackedWidget->setVisible(v); + lineFrame->setVisible(v); + if (_MSelf) +- _MSelf->setFixedHeight(v ? selfHeight : 100); ++ _MSelf->setFixedHeight(v ? selfHeight : 102); + setWidgetPosition(); + update(); + } +@@ -377,7 +377,7 @@ void TrayWidget::layoutAddPairedDev() + selfHeight =160 + count * 54; + if (count >= 7) + selfHeight = 515; +- _MSelf->setFixedHeight((isNull ? 100 : selfHeight)); ++ _MSelf->setFixedHeight((isNull ? 102 : selfHeight)); + } + update(); + } diff --git a/patches/ukcc_bleutooth_add_disconnect_btn.patch b/patches/ukcc_bleutooth_add_disconnect_btn.patch new file mode 100644 index 0000000..e2e058e --- /dev/null +++ b/patches/ukcc_bleutooth_add_disconnect_btn.patch @@ -0,0 +1,33 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 59a0c81..ea54e99 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -479,18 +479,19 @@ void DeviceInfoItem::MouseClickedDevFunc() + // dev_Menu->addAction(sendfile); + // dev_Menu->addSeparator(); + // } ++ ++ //华为机器增加断开按键 ++ if (global_ishuawei && _MDev->isConnected()) ++ { ++ QAction *disconnect = new QAction(dev_Menu); ++ disconnect->setText(tr("disconnect")); ++ dev_Menu->addAction(disconnect); ++ dev_Menu->addSeparator(); ++ } ++ + if (bluetoothdevice::DEVICE_TYPE::phone == _MDev->getDevType() || + bluetoothdevice::DEVICE_TYPE::computer == _MDev->getDevType()) + { +- //华为机器增加断开按键 +- if (global_ishuawei && _MDev->isConnected()) +- { +- QAction *disconnect = new QAction(dev_Menu); +- disconnect->setText(tr("disconnect")); +- dev_Menu->addAction(disconnect); +- dev_Menu->addSeparator(); +- } +- + //非华为机器才存在文件传输功能 + if(!global_ishuawei) + { diff --git a/patches/ukcc_bluetooth_93217and94720.patch b/patches/ukcc_bluetooth_93217and94720.patch new file mode 100644 index 0000000..0f44dfa --- /dev/null +++ b/patches/ukcc_bluetooth_93217and94720.patch @@ -0,0 +1,146 @@ +Index: ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/deviceinfoitem.cpp ++++ ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +@@ -270,9 +270,9 @@ bool DeviceInfoItem::mouseEventIntargetA + QRect DeviceInfoItem::getStatusTextRect(QRect rect) + { + if (_MDev && _MDev->isPaired()) { +- return QRect(this->width()-226,20,150,30); ++ return QRect(this->width()-226,16,150,30); + } else { +- return QRect(this->width()-120,20,105,30); ++ return QRect(this->width()-120,16,105,30); + } + } + +@@ -588,6 +588,96 @@ void DeviceInfoItem::DrawStatusIcon(QPai + painter.restore(); + } + ++//int DeviceInfoItem::NameTextWidthMax() ++//{ ++// qDebug()<< Q_FUNC_INFO << "=================================" << this->width() << __LINE__; ++// int name_width_max = this->width() - 226 - 70; ++// int width_offset = 0 ; ++// switch (_fontSize) ++// { ++// case 15: ++// case 14: ++// case 13: ++// case 12: ++// width_offset = 0; ++// case 11: ++// default: ++// width_offset = 0; ++// break; ++// } ++// return (name_width_max - width_offset); ++//} ++ ++int DeviceInfoItem::NameTextCoordinate_Y_offset() ++{ ++ int show_coordinate_text_Y_offset = 0 ; ++ switch (_fontSize) ++ { ++ case 15: ++ case 14: ++ case 13: ++ case 12: ++ show_coordinate_text_Y_offset = 0; ++ case 11: ++ case 10: ++ default: ++ show_coordinate_text_Y_offset = 0; ++ break; ++ } ++ return show_coordinate_text_Y_offset; ++} ++ ++QString DeviceInfoItem::getDeviceName(QString devName) ++{ ++ QString showRealName; ++ if(devName.length() > ShowNameTextNumberMax()) ++ { ++ showRealName = devName.left(ShowNameTextNumberMax()-3); ++ showRealName.append("..."); ++ toptipflag = true; ++ this->setToolTip(_MDev->getDevName()); ++ } ++ else ++ { ++ showRealName = devName; ++ toptipflag = false; ++ this->setToolTip(""); ++ } ++ qDebug() << Q_FUNC_INFO << "showRealName:" << showRealName << __LINE__; ++ ++ return showRealName; ++} ++ ++int DeviceInfoItem::ShowNameTextNumberMax() ++{ ++ float display_coefficient = (this->width() - 300)/500.00; ++ qDebug() << Q_FUNC_INFO << "display coefficient:" << display_coefficient << __LINE__; ++ int max_text_number = 0; ++ switch (_fontSize) ++ { ++ case 10: ++ max_text_number += 6 ; ++ case 11: ++ max_text_number += 5 ; ++ case 12: ++ max_text_number += 4 ; ++ case 13: ++ max_text_number += 3 ; ++ case 14: ++ max_text_number += 2 ; ++ case 15: ++ default: ++ max_text_number += 45 ; ++ break; ++ } ++ ++ int showMaxNameLength = max_text_number*display_coefficient; ++ qDebug() << Q_FUNC_INFO << "The max length :" << showMaxNameLength << __LINE__; ++ ++ return (45 > showMaxNameLength?45: showMaxNameLength); ++ ++} ++ + /************************************************ + * @brief DrawText + * @param painter +@@ -601,11 +691,12 @@ void DeviceInfoItem::DrawText(QPainter & + else + painter.setPen(QColor(Qt::black)); + +-// if (_MStatus == Status::Hover) { +-// painter.setPen(QColor(Qt::black)); +-// } ++ //qDebug()<< Q_FUNC_INFO << "=================================" << this->width() << __LINE__; ++ //qDebug()<< Q_FUNC_INFO << "=================================" << _fontSize << __LINE__; ++ //qDebug()<< Q_FUNC_INFO << "=================================" << _MDev->getDevName().length() << __LINE__; + +- painter.drawText(70,20,380,30,Qt::AlignLeft,_MDev? _MDev->getDevName(): QString("Example")); ++ //painter.drawText(70,20,this->width()-300,30,Qt::AlignLeft|Qt::AlignVCenter,_MDev? _MDev->getDevName(): QString("Example")); ++ painter.drawText(70,16,this->width()-300,30,Qt::AlignLeft|Qt::AlignVCenter,_MDev?getDeviceName( _MDev->getDevName() ): QString("Example")); + painter.restore(); + } + +Index: ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/deviceinfoitem.h ++++ ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.h +@@ -95,6 +95,11 @@ private: + QRect getStatusIconRect(QRect); + QRect getFontPixelQPoint(QString); + ++ //int NameTextWidthMax(); ++ QString getDeviceName(QString); ++ int ShowNameTextNumberMax(); ++ int NameTextCoordinate_Y_offset(); ++ bool toptipflag = false; + int iconFlag = 7; + + DEVSTATUS _DevStatus; diff --git a/patches/ukcc_bluetooth_and_bluetoothService_scan_optimise.patch b/patches/ukcc_bluetooth_and_bluetoothService_scan_optimise.patch new file mode 100644 index 0000000..a3d273a --- /dev/null +++ b/patches/ukcc_bluetooth_and_bluetoothService_scan_optimise.patch @@ -0,0 +1,135 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index afcf30a..9739e43 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -652,6 +652,21 @@ void Daemon::launchDbusSignal() + qDebug() << Q_FUNC_INFO << "end"; + } + ++void Daemon::devConnectSignalDbus(QString address) ++{ ++ //停止扫描,连接完成或连接超时后继续开启扫描 ++ //setDefaultAdapterScanOn(false); ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", ++ "/com/ukui/bluetooth", ++ "com.ukui.bluetooth", ++ "devConnect"); ++ m << address; ++ qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; ++ // 发送Message ++ QDBusConnection::sessionBus().call(m, QDBus::NoBlock); ++} ++ + void Daemon::reconnectFunc() + { + qInfo() << Q_FUNC_INFO << "START"; +@@ -687,7 +702,8 @@ void Daemon::reconnectFunc() + dev.data()->type() == BluezQt::Device::Headphones || + dev.data()->type() == BluezQt::Device::AudioVideo) { + +- dev->connectToDevice(); ++ devConnectSignalDbus(dev.data()->address()); ++ //dev->connectToDevice(); + } + } + } +diff --git a/service/daemon.h b/service/daemon.h +index db57eab..e65ceab 100644 +--- a/service/daemon.h ++++ b/service/daemon.h +@@ -68,6 +68,7 @@ public: + // static void sendDevSignal(DevOperate,QString); + static QDBusMessage createCustomSignalMsg(QString); + static void reconnectFunc(); ++ static void devConnectSignalDbus(QString); + Q_SIGNALS: + void startThread(); + +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 9c8f845..82a2863 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -235,7 +235,8 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); ++ if(!Daemon::_DefualtAdapter.data()->isDiscovering()) ++ Daemon::_DefualtAdapter.data()->startDiscovery(); + } + } + +@@ -264,11 +265,13 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { +- BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); +- +- connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ +- qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; +- }); ++ if (!Daemon::_DefualtAdapter.data()->isDiscovering()) ++ { ++ BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); ++ connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ }); ++ } + } + } + }); +@@ -345,10 +348,15 @@ void SessionDbusRegister::setDefaultAdapterScanOn(bool scanon) + if (!Daemon::_DefualtAdapter.isNull()) { + // BluezQt::PendingCall *call = nullptr; + ::isScan = scanon; +- if (scanon) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); +- } else { +- Daemon::_DefualtAdapter.data()->stopDiscovery(); ++ if (GlobalSize::BlueDevActiveSize() == 0) ++ { ++ if (scanon) { ++ if (!Daemon::_DefualtAdapter.data()->isDiscovering()) ++ Daemon::_DefualtAdapter.data()->startDiscovery(); ++ } else { ++ if (Daemon::_DefualtAdapter.data()->isDiscovering()) ++ Daemon::_DefualtAdapter.data()->stopDiscovery(); ++ } + } + } + } +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index cd3020c..e2d76ea 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -370,6 +370,9 @@ void BlueToothMain::reportDefaultScanStatusChanged(bool isScan) + loadLabel->setVisible(true); + if (!m_timer->isActive()) + m_timer->start(); ++ ++ if(delayStartDiscover_timer->isActive()) ++ delayStartDiscover_timer->stop(); + } + else + { +@@ -717,7 +720,10 @@ void BlueToothMain::reportDeviceScanResult(QString devAddress,QString devName) + } + + qDebug () << Q_FUNC_INFO << devName << devAddress << __LINE__; +- if (delayStartDiscover_timer && delayStartDiscover_timer->isActive()) ++ qDebug () << Q_FUNC_INFO << devName << "m_current_adapter_scan_status =========" << m_current_adapter_scan_status << __LINE__; ++ ++ //当前是扫描状态,且扫描延时也在计时 ++ if (m_current_adapter_scan_status && delayStartDiscover_timer && delayStartDiscover_timer->isActive()) + { + delayStartDiscover_timer->stop(); + } +@@ -1779,6 +1785,7 @@ void BlueToothMain::refreshUIWhenAdapterChanged() + + if (m_open_bluetooth_btn->isChecked()) + { ++ qDebug() << Q_FUNC_INFO << "m_open_bluetooth_btn->isChecked() == " << m_open_bluetooth_btn->isChecked() << "stary discover" ; + if (delayStartDiscover_timer->isActive()) + delayStartDiscover_timer->stop(); + delayStartDiscover_timer->start(); diff --git a/patches/ukcc_bluetooth_clear_core.patch b/patches/ukcc_bluetooth_clear_core.patch new file mode 100644 index 0000000..461c677 --- /dev/null +++ b/patches/ukcc_bluetooth_clear_core.patch @@ -0,0 +1,521 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 26e026a..54d7f6d 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -19,162 +19,162 @@ + + bool BlueToothMain::m_device_operating = false; + +-extern "C" { +- #include +- #include +- #include +- #include +- #include +-} +- +-enum { +- OPT_b = (1 << 0), /* must be = 1 */ +- OPT_u = (1 << 1), +- OPT_l = (1 << 2), +-}; +- +-static guint watch = 0; +-static bool spe_bt_node = false; // 判断是否有无法通过bluezQt进行unblock的蓝牙设备节点 +-static bool spe_bt_node_blk = false; // 判断例外蓝牙设备节点是否是unblock +- +-static gboolean rfkill_event(GIOChannel *chan, +- GIOCondition cond, gpointer data) +-{ +- unsigned char buf[32]; +- struct rfkill_event *event = (struct rfkill_event *)buf; +- char sysname[PATH_MAX]; +- ssize_t len; +- int fd, id; ++//extern "C" { ++// #include ++// #include ++// #include ++// #include ++// #include ++//} + +- if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) +- return FALSE; ++//enum { ++// OPT_b = (1 << 0), /* must be = 1 */ ++// OPT_u = (1 << 1), ++// OPT_l = (1 << 2), ++//}; + +- fd = g_io_channel_unix_get_fd(chan); ++//static guint watch = 0; ++//static bool spe_bt_node = false; // 判断是否有无法通过bluezQt进行unblock的蓝牙设备节点 ++//static bool spe_bt_node_blk = false; // 判断例外蓝牙设备节点是否是unblock + +- memset(buf, 0, sizeof(buf)); +- len = read(fd, buf, sizeof(buf)); +- if (len < 0) { +- if (errno == EAGAIN) +- return TRUE; +- return FALSE; +- } ++//static gboolean rfkill_event(GIOChannel *chan, ++// GIOCondition cond, gpointer data) ++//{ ++// unsigned char buf[32]; ++// struct rfkill_event *event = (struct rfkill_event *)buf; ++// char sysname[PATH_MAX]; ++// ssize_t len; ++// int fd, id; ++ ++// if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) ++// return FALSE; ++ ++// fd = g_io_channel_unix_get_fd(chan); ++ ++// memset(buf, 0, sizeof(buf)); ++// len = read(fd, buf, sizeof(buf)); ++// if (len < 0) { ++// if (errno == EAGAIN) ++// return TRUE; ++// return FALSE; ++// } + +- if (len != sizeof(struct rfkill_event)) +- return TRUE; ++// if (len != sizeof(struct rfkill_event)) ++// return TRUE; + +- qDebug("RFKILL event idx %u type %u op %u soft %u hard %u", +- event->idx, event->type, event->op, +- event->soft, event->hard); ++// qDebug("RFKILL event idx %u type %u op %u soft %u hard %u", ++// event->idx, event->type, event->op, ++// event->soft, event->hard); + +- if (event->type != RFKILL_TYPE_BLUETOOTH && +- event->type != RFKILL_TYPE_ALL) +- { +- qDebug() << Q_FUNC_INFO << "Not bt====" ; +- return TRUE; +- } +- memset(sysname, 0, sizeof(sysname)); +- snprintf(sysname, sizeof(sysname) - 1, +- "/sys/class/rfkill/rfkill%u/name", event->idx); ++// if (event->type != RFKILL_TYPE_BLUETOOTH && ++// event->type != RFKILL_TYPE_ALL) ++// { ++// qDebug() << Q_FUNC_INFO << "Not bt====" ; ++// return TRUE; ++// } ++// memset(sysname, 0, sizeof(sysname)); ++// snprintf(sysname, sizeof(sysname) - 1, ++// "/sys/class/rfkill/rfkill%u/name", event->idx); + +- fd = open(sysname, O_RDONLY); +- if (fd < 0) +- { +- qDebug () << Q_FUNC_INFO << __LINE__; +- return TRUE; +- } ++// fd = open(sysname, O_RDONLY); ++// if (fd < 0) ++// { ++// qDebug () << Q_FUNC_INFO << __LINE__; ++// return TRUE; ++// } + +- if (read(fd, sysname, sizeof(sysname) - 1) < 4) { +- close(fd); +- qDebug () << Q_FUNC_INFO << __LINE__; ++// if (read(fd, sysname, sizeof(sysname) - 1) < 4) { ++// close(fd); ++// qDebug () << Q_FUNC_INFO << __LINE__; + +- return TRUE; +- } ++// return TRUE; ++// } + +- close(fd); ++// close(fd); + +- if (g_str_has_prefix(sysname, "tpacpi_bluetooth_sw") == TRUE || +- g_str_has_prefix(sysname, "ideapad_bluetooth") == TRUE ) +- { +- spe_bt_node = true; +- qDebug () << Q_FUNC_INFO << "spe_bt_node:" << spe_bt_node << __LINE__; +- if (event->soft) +- { +- spe_bt_node_blk = true; +- qDebug () << Q_FUNC_INFO << "event->soft:" << event->soft << __LINE__; +- } +- else { +- spe_bt_node_blk = false; +- } +- } ++// if (g_str_has_prefix(sysname, "tpacpi_bluetooth_sw") == TRUE || ++// g_str_has_prefix(sysname, "ideapad_bluetooth") == TRUE ) ++// { ++// spe_bt_node = true; ++// qDebug () << Q_FUNC_INFO << "spe_bt_node:" << spe_bt_node << __LINE__; ++// if (event->soft) ++// { ++// spe_bt_node_blk = true; ++// qDebug () << Q_FUNC_INFO << "event->soft:" << event->soft << __LINE__; ++// } ++// else { ++// spe_bt_node_blk = false; ++// } ++// } + +- return TRUE; +-} ++// return TRUE; ++//} + +-void rfkill_init(void) +-{ +- qDebug () << Q_FUNC_INFO << __LINE__; ++//void rfkill_init(void) ++//{ ++// qDebug () << Q_FUNC_INFO << __LINE__; + +- int fd; +- GIOChannel *channel; ++// int fd; ++// GIOChannel *channel; + +- fd = open("/dev/rfkill", O_RDWR); +- if (fd < 0) { +- return; +- } ++// fd = open("/dev/rfkill", O_RDWR); ++// if (fd < 0) { ++// return; ++// } + +- channel = g_io_channel_unix_new(fd); +- g_io_channel_set_close_on_unref(channel, TRUE); ++// channel = g_io_channel_unix_new(fd); ++// g_io_channel_set_close_on_unref(channel, TRUE); + +- watch = g_io_add_watch(channel, +- GIOCondition(G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR), +- rfkill_event, NULL); ++// watch = g_io_add_watch(channel, ++// GIOCondition(G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR), ++// rfkill_event, NULL); + +- g_io_channel_unref(channel); +-} ++// g_io_channel_unref(channel); ++//} + +-void rfkill_set_idx(void) +-{ +- qDebug () << Q_FUNC_INFO << __LINE__; +- struct rfkill_event event; ++//void rfkill_set_idx(void) ++//{ ++// qDebug () << Q_FUNC_INFO << __LINE__; ++// struct rfkill_event event; + +- int rf_fd; +- int mode; +- int rf_type; +- int rf_idx; +- unsigned rf_opt = 0; ++// int rf_fd; ++// int mode; ++// int rf_type; ++// int rf_idx; ++// unsigned rf_opt = 0; + +- /* Must have one or two params */ +- mode = O_RDWR | O_NONBLOCK; ++// /* Must have one or two params */ ++// mode = O_RDWR | O_NONBLOCK; + +- rf_type = RFKILL_TYPE_BLUETOOTH; +- rf_idx = -1; ++// rf_type = RFKILL_TYPE_BLUETOOTH; ++// rf_idx = -1; + +- rf_fd = open("/dev/rfkill", mode); ++// rf_fd = open("/dev/rfkill", mode); + +- memset(&event, 0, sizeof(event)); +- if (rf_type >= 0) { +- event.type = rf_type; +- event.op = RFKILL_OP_CHANGE_ALL; +- } ++// memset(&event, 0, sizeof(event)); ++// if (rf_type >= 0) { ++// event.type = rf_type; ++// event.op = RFKILL_OP_CHANGE_ALL; ++// } + +- if (rf_idx >= 0) { +- event.idx = rf_idx; +- event.op = RFKILL_OP_CHANGE; +- } ++// if (rf_idx >= 0) { ++// event.idx = rf_idx; ++// event.op = RFKILL_OP_CHANGE; ++// } + +- /* Note: OPT_b == 1 */ +- event.soft = (rf_opt & OPT_b); ++// /* Note: OPT_b == 1 */ ++// event.soft = (rf_opt & OPT_b); + +- write(rf_fd, &event, sizeof(event)); +-} ++// write(rf_fd, &event, sizeof(event)); ++//} + +-void rfkill_exit(void) +-{ +- if (watch == 0) +- return; +- g_source_remove(watch); +- watch = 0; +-} ++//void rfkill_exit(void) ++//{ ++// if (watch == 0) ++// return; ++// g_source_remove(watch); ++// watch = 0; ++//} + + //dev-3.1 界面服务-分离 + BlueToothMain::BlueToothMain(QWidget *parent) +@@ -694,14 +694,21 @@ bluetoothdevice * BlueToothMain::createOneBluetoothDevice(QString devAddress) + } + } + ++// dev = new bluetoothdevice(dev_name, ++// devAddress, ++// dev_type, ++// isPaired?bluetoothdevice::DEVICE_STATUS::PairedAndUnlinked:bluetoothdevice::DEVICE_STATUS::UnpairAndUnlinked, ++// isPaired); + dev = new bluetoothdevice(dev_name, + devAddress, + dev_type, +- isPaired?bluetoothdevice::DEVICE_STATUS::PairedAndUnlinked:bluetoothdevice::DEVICE_STATUS::UnpairAndUnlinked, ++ isPaired, ++ isConnected, + isPaired); +- dev->devPairedChanged(isPaired); +- dev->devConnectedChanged(isConnected); +- dev->setObjectName(devAddress); ++ ++// dev->devPairedChanged(isPaired); ++// dev->devConnectedChanged(isConnected); ++ + + return dev; + } +diff --git a/ukcc-bluetooth/bluetoothmain.h b/ukcc-bluetooth/bluetoothmain.h +index fab7bff..9f25af3 100644 +--- a/ukcc-bluetooth/bluetoothmain.h ++++ b/ukcc-bluetooth/bluetoothmain.h +@@ -79,6 +79,7 @@ private slots: + void reportDefaultDiscoverableChanged(bool); + void reportDefaultScanStatusChanged(bool); + void reportDeviceScanResult(QString,QString); ++ //void reportDeviceScanResult(QString,QString,QString,bool.bool); + + void reportDevRemoveSignal(QString); + void reportDevPairSignal(QString,bool); +diff --git a/ukcc-bluetooth/devicebase.cpp b/ukcc-bluetooth/devicebase.cpp +index c1ce817..0304db2 100644 +--- a/ukcc-bluetooth/devicebase.cpp ++++ b/ukcc-bluetooth/devicebase.cpp +@@ -85,32 +85,37 @@ bool bluetoothadapter::getDevDiscoverable() + bluetoothdevice::bluetoothdevice(QString dev_name , + QString dev_address , + DEVICE_TYPE dev_type , +- DEVICE_STATUS dev_status , +- bool dev_trust) ++ bool dev_paired_status , ++ bool dev_connected_status , ++ //DEVICE_STATUS dev_status , ++ bool dev_trust) + :m_dev_name(dev_name) + ,m_dev_address(dev_address) + ,m_dev_type(dev_type) +- ,m_dev_status(dev_status) ++ ,m_dev_isPaired(dev_paired_status) ++ ,m_dev_isConnected(dev_connected_status) ++ //,m_dev_status(dev_status) + ,m_dev_trust(dev_trust) + { ++ this->setObjectName(dev_address); + //qDebug() << Q_FUNC_INFO << __LINE__; +- if (DEVICE_STATUS::PairedAndUnlinked == dev_status || +- DEVICE_STATUS::PairedAndLinked == dev_status ) +- { +- this->m_dev_isPaired = true ; +- this->m_dev_trust = true ; +- } +- else +- { +- this->m_dev_isPaired = false ; +- this->m_dev_trust = false ; +- } +- +- if (DEVICE_STATUS::UnpairAndLinked == dev_status || +- DEVICE_STATUS::PairedAndLinked == dev_status ) +- this->m_dev_isConnected = true ; +- else +- this->m_dev_isConnected = false ; ++// if (DEVICE_STATUS::PairedAndUnlinked == dev_status || ++// DEVICE_STATUS::PairedAndLinked == dev_status ) ++// { ++// this->m_dev_isPaired = true ; ++// this->m_dev_trust = true ; ++// } ++// else ++// { ++// this->m_dev_isPaired = false ; ++// this->m_dev_trust = false ; ++// } ++ ++// if (DEVICE_STATUS::UnpairAndLinked == dev_status || ++// DEVICE_STATUS::PairedAndLinked == dev_status ) ++// this->m_dev_isConnected = true ; ++// else ++// this->m_dev_isConnected = false ; + + } + +diff --git a/ukcc-bluetooth/devicebase.h b/ukcc-bluetooth/devicebase.h +index 493501b..bae0188 100644 +--- a/ukcc-bluetooth/devicebase.h ++++ b/ukcc-bluetooth/devicebase.h +@@ -129,11 +129,13 @@ public: + }; + Q_ENUM(DEVICE_STATUS) + +- bluetoothdevice(QString device_name , +- QString device_address , +- DEVICE_TYPE dev_type , +- DEVICE_STATUS dev_status , +- bool dev_trust); ++ bluetoothdevice(QString device_name , ++ QString device_address , ++ DEVICE_TYPE dev_type , ++ bool dev_paired_status , ++ bool dev_connected_status , ++ //DEVICE_STATUS dev_status , ++ bool dev_trust); + ~bluetoothdevice(){} + + void resetDeviceName(QString) Q_DECL_OVERRIDE ; +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 57d890b..664cd52 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -80,7 +80,7 @@ void DeviceInfoItem::InitMemberVariables() + }); + + _devConnTimer = new QTimer(this); +- _devConnTimer->setInterval(5000); ++ _devConnTimer->setInterval(8000); + connect(_devConnTimer,&QTimer::timeout,this,[=]{ + emit devConnectionComplete(); + _devConnTimer->stop(); +@@ -97,7 +97,7 @@ void DeviceInfoItem::InitMemberVariables() + update(); + + //错误信息显示超时后,显示错误操作后的设备状态 +- QTimer::singleShot(4000,this,[=]{ ++ QTimer::singleShot(8000,this,[=]{ + if (_MDev->isPaired()) + { + _DevStatus = DEVSTATUS::Paired; +diff --git a/ukcc-bluetooth/devrenamedialog.cpp b/ukcc-bluetooth/devrenamedialog.cpp +index 7256a12..2546ea0 100644 +--- a/ukcc-bluetooth/devrenamedialog.cpp ++++ b/ukcc-bluetooth/devrenamedialog.cpp +@@ -20,6 +20,9 @@ void DevRenameDialog::setDevName(const QString &str) + { + lineEdit->setText(str); + adapterOldName = str; ++ //test name ++ //lineEdit->setText("strdddd123456788991111000000"); ++ //adapterOldName = "strdddd123456788991111000000"; + } + + void DevRenameDialog::initGsettings() +@@ -90,7 +93,9 @@ void DevRenameDialog::initUI() + lineEdit = new QLineEdit(this); + lineEdit->setGeometry(100 + wigth,55,355 - wigth,36); + //lineEdit->setGeometry(100,55,355,36); +- connect(lineEdit,&QLineEdit::textChanged,this,&DevRenameDialog::lineEditSlot); ++ //connect(lineEdit,&QLineEdit::textChanged,this,&DevRenameDialog::lineEditSlot); ++ //输入变化时进行长度提示 ++ connect(lineEdit,&QLineEdit::textEdited,this,&DevRenameDialog::lineEditSlot); + + tipLabel = new QLabel(this); + tipLabel->setGeometry(96,94,300,20); +@@ -162,10 +167,12 @@ void DevRenameDialog::keyPressEvent(QKeyEvent * event) + { + case Qt::Key_Return: + case Qt::Key_Enter: +- emit acceptBtn->click(); ++ //if(acceptBtn->isEnabled())//setEnable状态后,emit click 信号不相应,无需判断 ++ emit acceptBtn->click(); + break; + case Qt::Key_Escape: +- emit rejectBtn->click(); ++ //if(rejectBtn->isEnabled())//setEnable状态后,emit click 信号不相应,无需判断 ++ emit rejectBtn->click(); + break; + } + +diff --git a/ukcc-bluetooth/ukcc-bluetooth.pro b/ukcc-bluetooth/ukcc-bluetooth.pro +index 0544a80..f79fa69 100644 +--- a/ukcc-bluetooth/ukcc-bluetooth.pro ++++ b/ukcc-bluetooth/ukcc-bluetooth.pro +@@ -2,15 +2,15 @@ QT += gui dbus + + include(../environment.pri) + +-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets dbus BluezQt ++greaterThan(QT_MAJOR_VERSION, 4): QT += widgets dbus + + TEMPLATE = lib + CONFIG += plugin \ + += c++11 \ + link_pkgconfig + +-PKGCONFIG += gsettings-qt gio-2.0 +-LIBS += -l KF5BluezQt -lgio-2.0 -lglib-2.0 -lukcc ++PKGCONFIG += gsettings-qt ++LIBS += -lukcc + + # The following define makes your compiler emit warnings if you use + # any Qt feature that has been marked deprecated (the exact warnings +@@ -27,7 +27,7 @@ SOURCES += \ + bluetooth.cpp \ + bluetoothdbusservice.cpp \ + bluetoothmain.cpp \ +- bluetoothmainwindow.cpp \ ++ #bluetoothmainwindow.cpp \ + bluetoothnamelabel.cpp \ + devicebase.cpp \ + deviceinfoitem.cpp \ +@@ -40,7 +40,7 @@ HEADERS += \ + bluetooth.h \ + bluetoothdbusservice.h \ + bluetoothmain.h \ +- bluetoothmainwindow.h \ ++ #bluetoothmainwindow.h \ + bluetoothnamelabel.h \ + config.h \ + devicebase.h \ diff --git a/patches/ukcc_bluetooth_conn_fail_show_error.patch b/patches/ukcc_bluetooth_conn_fail_show_error.patch new file mode 100644 index 0000000..4286fcb --- /dev/null +++ b/patches/ukcc_bluetooth_conn_fail_show_error.patch @@ -0,0 +1,62 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 5a94e9b..57d890b 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -82,18 +82,18 @@ void DeviceInfoItem::InitMemberVariables() + _devConnTimer = new QTimer(this); + _devConnTimer->setInterval(5000); + connect(_devConnTimer,&QTimer::timeout,this,[=]{ ++ emit devConnectionComplete(); + _devConnTimer->stop(); + _iconTimer->stop(); + _clicked = false; + _connDevTimeOutFlag = true ; + ++ qDebug() << Q_FUNC_INFO << "current dev status:" << _DevStatus ; + if (DEVSTATUS::Connecting == _DevStatus) { + _DevStatus = DEVSTATUS::ConnectFailed; + } else if (DEVSTATUS::DisConnecting == _DevStatus) { + _DevStatus = DEVSTATUS::DisConnectFailed; + } +- +- emit devConnectionComplete(); + update(); + + //错误信息显示超时后,显示错误操作后的设备状态 +@@ -656,16 +656,15 @@ QString DeviceInfoItem::getDeviceName(QString devName) + toptipflag = false; + this->setToolTip(""); + } +- qDebug() << Q_FUNC_INFO << "showRealName:" << showRealName << __LINE__; ++ //qDebug() << Q_FUNC_INFO << "showRealName:" << showRealName << __LINE__; + + return showRealName; + } + + int DeviceInfoItem::ShowNameTextNumberMax() + { +- + float display_coefficient = (this->width() - 300)/500.00; +- qDebug() << Q_FUNC_INFO << "display coefficient:" << display_coefficient << __LINE__; ++ //qDebug() << Q_FUNC_INFO << "display coefficient:" << display_coefficient << __LINE__; + int max_text_number = 0; + switch (_fontSize) + { +@@ -686,7 +685,7 @@ int DeviceInfoItem::ShowNameTextNumberMax() + } + + int showMaxNameLength = max_text_number*display_coefficient; +- qDebug() << Q_FUNC_INFO << "The max length :" << showMaxNameLength << __LINE__; ++ //qDebug() << Q_FUNC_INFO << "The max length :" << showMaxNameLength << __LINE__; + + return (45 > showMaxNameLength?45: showMaxNameLength); + +@@ -716,7 +715,7 @@ void DeviceInfoItem::DrawText(QPainter &painter) + + void DeviceInfoItem::DrawStatusText(QPainter &painter) + { +- setDeviceCurrentStatus(); ++ //setDeviceCurrentStatus(); + painter.save(); + if(_themeIsBlack) + painter.setPen(QColor(Qt::white)); diff --git a/patches/ukcc_bluetooth_delete_scan.patch b/patches/ukcc_bluetooth_delete_scan.patch new file mode 100644 index 0000000..9d683b7 --- /dev/null +++ b/patches/ukcc_bluetooth_delete_scan.patch @@ -0,0 +1,38 @@ +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -771,9 +771,9 @@ void BlueToothMain::addMyDeviceItemUI(bl + connect(item,SIGNAL(devSendFiles(QString)),this,SLOT(receiveSendFileSignal(QString))); + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { +- if (delayStartDiscover_timer->isActive()) +- delayStartDiscover_timer->stop(); +- delayStartDiscover_timer->start(); ++// if (delayStartDiscover_timer->isActive()) ++// delayStartDiscover_timer->stop(); ++// delayStartDiscover_timer->start(); + //setDefaultAdapterScanOn(true); + }); + m_myDev_show_flag = true; +@@ -1272,7 +1272,7 @@ void BlueToothMain::setDefaultAdapterSca + void BlueToothMain::receiveConnectsignal(QString address) + { + //停止扫描,连接完成或连接超时后继续开启扫描 +- setDefaultAdapterScanOn(false); ++ //setDefaultAdapterScanOn(false); + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, +@@ -1805,6 +1805,11 @@ void BlueToothMain::onClick_Open_Bluetoo + } + else + { ++ if (loadLabel->isVisible()) ++ loadLabel->setVisible(false); ++ if (m_timer->isActive()) ++ m_timer->stop(); ++ + stopAllTimer(); + } + diff --git a/patches/ukcc_bluetooth_errorUi_abnormality.patch b/patches/ukcc_bluetooth_errorUi_abnormality.patch new file mode 100644 index 0000000..766518b --- /dev/null +++ b/patches/ukcc_bluetooth_errorUi_abnormality.patch @@ -0,0 +1,91 @@ +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -1242,6 +1242,12 @@ void BlueToothMain::setDefaultAdapterDis + void BlueToothMain::setbluetoothAdapterDiscoveringStatus(bool isScan) + { + qDebug() << Q_FUNC_INFO << __LINE__; ++ ++ if ("normalWidget" != _MCentralWidget->currentWidget()->objectName()) ++ { ++ qDebug() << Q_FUNC_INFO << "errorWidget not open scan!!" << __LINE__; ++ return; ++ } + setDefaultAdapterScanOn(isScan); + } + +@@ -1318,7 +1324,7 @@ void BlueToothMain::receiveSendFileSigna + void BlueToothMain::showBluetoothNormalMainWindow() + { + qDebug() << Q_FUNC_INFO << __LINE__; +- m_normal_main_widget = new QWidget(this); ++ m_normal_main_widget = new QWidget(_MCentralWidget); + m_normal_main_widget->setObjectName("normalWidget"); + //this->setCentralWidget(m_normal_main_widget); + +@@ -1613,10 +1619,10 @@ void BlueToothMain::showBluetoothErrorMa + { + qDebug() << Q_FUNC_INFO << __LINE__; + stopAllTimer(); +- m_error_main_widget = new QWidget(); +- QVBoxLayout *errorWidgetLayout = new QVBoxLayout(m_error_main_widget); +- QLabel *errorWidgetIcon = new QLabel(m_error_main_widget); +- QLabel *errorWidgetTip0 = new QLabel(m_error_main_widget); ++ m_error_main_widget = new QWidget(_MCentralWidget); ++ errorWidgetLayout = new QVBoxLayout(m_error_main_widget); ++ errorWidgetIcon = new QLabel(m_error_main_widget); ++ errorWidgetTip0 = new QLabel(m_error_main_widget); + + m_error_main_widget->setObjectName("errorWidget"); + +@@ -1628,8 +1634,7 @@ void BlueToothMain::showBluetoothErrorMa + errorWidgetTip0->resize(200,30); + errorWidgetTip0->setFont(QFont("Noto Sans CJK SC",18,QFont::Bold)); + +- if (QIcon::hasThemeIcon("dialog-warning")) { +- ++ if (QIcon::hasThemeIcon("bluetooth-error")) { + if (isblack) + errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56),"white")); + else +@@ -2052,6 +2057,11 @@ void BlueToothMain::gSettingsChanged(con + isblack = true; + else + isblack = false; ++ ++ if (isblack) ++ errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56),"white")); ++ else ++ errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-error").pixmap(56,56)); + } + } + +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.h ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.h +@@ -112,6 +112,10 @@ private: + QWidget * frame_bottom = nullptr; + QWidget * m_normal_main_widget = nullptr; + QWidget * m_error_main_widget = nullptr; ++ QVBoxLayout * errorWidgetLayout = nullptr; ++ QLabel * errorWidgetIcon = nullptr; ++ QLabel * errorWidgetTip0 = nullptr; ++ + QWidget * device_list = nullptr; + QWidget * paired_device_list = nullptr; + QVBoxLayout * device_list_layout = nullptr; +Index: ukui-bluetooth/ukcc-bluetooth/config.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/config.h ++++ ukui-bluetooth/ukcc-bluetooth/config.h +@@ -2,7 +2,7 @@ + #define CONFIG_H + #include + +-#define BluetoothServiceExePath "/usr/bin/bluetoothService -o" ++#define BluetoothServiceExePath "/usr/bin/bluetoothService" + #define BluetoothTrayExePath "/usr/bin/ukui-bluetooth" + #define BluetoothServiceName "bluetoothService" + #define BluetoothTrayName "ukui-bluetooth" diff --git a/patches/ukcc_bluetooth_fix_big_font_show_error.patch b/patches/ukcc_bluetooth_fix_big_font_show_error.patch new file mode 100644 index 0000000..fabf33c --- /dev/null +++ b/patches/ukcc_bluetooth_fix_big_font_show_error.patch @@ -0,0 +1,285 @@ +diff --git a/ukcc-bluetooth/config.h b/ukcc-bluetooth/config.h +index 92027f8..623c493 100644 +--- a/ukcc-bluetooth/config.h ++++ b/ukcc-bluetooth/config.h +@@ -7,6 +7,11 @@ + #define BluetoothServiceName "bluetoothService" + #define BluetoothTrayName "ukui-bluetooth" + ++#define SYSTEMSTYLENAME "org.ukui.style" ++#define SYSTEMSTYLENAME "styleName" ++#define SYSTEMFONTSIZE "systemFontSize" ++#define SYSTEMFONT "systemFont" ++ + const QString SERVICE = "com.ukui.bluetooth"; + const QString PATH = "/com/ukui/bluetooth"; + const QString INTERFACE = "com.ukui.bluetooth"; +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 581dde8..5285a02 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -8,8 +8,6 @@ + #include "devremovedialog.h" + #include "bluetoothmain.h" + +-#define STYLENAME "org.ukui.style" +- + DeviceInfoItem::DeviceInfoItem(QWidget *parent, bluetoothdevice * dev): + QFrame(parent), + _MDev(dev) +@@ -68,8 +66,8 @@ void DeviceInfoItem::InitMemberVariables() + _DevStatus = DEVSTATUS::NoPaired; + } + +- if(QGSettings::isSchemaInstalled(STYLENAME)){ +- item_gsettings = new QGSettings(STYLENAME); ++ if(QGSettings::isSchemaInstalled(SYSTEMSTYLENAME)){ ++ item_gsettings = new QGSettings(SYSTEMSTYLENAME); + + connect(item_gsettings,&QGSettings::changed,this,&DeviceInfoItem::GSettingsChanges); + +@@ -79,7 +77,7 @@ void DeviceInfoItem::InitMemberVariables() + else + _themeIsBlack = false; + +- _fontFamily = item_gsettings->get("style-name").toString(); ++ _fontFamily = item_gsettings->get("system-font").toString(); + _fontSize = item_gsettings->get("system-font-size").toString().toInt(); + } + +@@ -92,9 +90,9 @@ void DeviceInfoItem::InitMemberVariables() + _iconTimer = new QTimer(this); + _iconTimer->setInterval(110); + connect(_iconTimer,&QTimer::timeout,this,[=]{ +-// if (iconFlag == 0) +-// iconFlag = 7; +-// iconFlag--; ++ if (iconFlag >= 7) ++ iconFlag = 0; ++ iconFlag++; + update(); + }); + +@@ -188,15 +186,15 @@ void DeviceInfoItem::setDeviceCurrentStatus() + void DeviceInfoItem::GSettingsChanges(const QString &key) + { + qDebug() << Q_FUNC_INFO << key; +- if("styleName" == key){ ++ if(SYSTEMSTYLENAME == key){ + if(item_gsettings->get("style-name").toString() == "ukui-black" || + item_gsettings->get("style-name").toString() == "ukui-dark") + _themeIsBlack = true; + else + _themeIsBlack = false; +- } else if ("systemFont" == key) { +- _fontFamily = item_gsettings->get("style-name").toString(); +- } else if ("systemFontSize" == key) { ++ } else if (SYSTEMFONT == key) { ++ _fontFamily = item_gsettings->get("system-font").toString(); ++ } else if (SYSTEMFONTSIZE == key) { + _fontSize = item_gsettings->get("system-font-size").toString().toInt(); + } + } +@@ -305,9 +303,11 @@ bool DeviceInfoItem::mouseEventIntargetAera(QPoint p) + QRect DeviceInfoItem::getStatusTextRect(QRect rect) + { + if (_MDev && _MDev->isPaired()) { ++ //return QRect(this->width()-226,16,150,30); + return QRect(this->width()-226,16,150,30); + } else { +- return QRect(this->width()-120,16,105,30); ++ //return QRect(this->width()-120,16,105,30); ++ return QRect(this->width()-140,16,125,30); + } + } + +@@ -700,7 +700,7 @@ QString DeviceInfoItem::getDeviceName(QString devName) + + int DeviceInfoItem::ShowNameTextNumberMax() + { +- float display_coefficient = (this->width() - 300)/500.00; ++ float display_coefficient = (this->width() - 350)/500.00; + //qDebug() << Q_FUNC_INFO << "display coefficient:" << display_coefficient << __LINE__; + int max_text_number = 0; + switch (_fontSize) +@@ -746,7 +746,7 @@ void DeviceInfoItem::DrawText(QPainter &painter) + //qDebug()<< Q_FUNC_INFO << "=================================" << _MDev->getDevName().length() << __LINE__; + + //painter.drawText(70,20,this->width()-300,30,Qt::AlignLeft|Qt::AlignVCenter,_MDev? _MDev->getDevName(): QString("Example")); +- painter.drawText(70,16,this->width()-300,30,Qt::AlignLeft|Qt::AlignVCenter,_MDev?getDeviceName( _MDev->getDevName() ): QString("Example")); ++ painter.drawText(70,16,this->width()-350,30,Qt::AlignLeft|Qt::AlignVCenter,_MDev?getDeviceName( _MDev->getDevName() ): QString("Example")); + painter.restore(); + } + +@@ -814,13 +814,13 @@ void DeviceInfoItem::DrawFuncBtn(QPainter &painter) + if (_themeIsBlack) { + if (_inBtn) + style()->drawItemPixmap(&painter,QRect(this->width()-48,19,20,20), Qt::AlignCenter, +- ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(20),"black")); ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(16),"black")); + else + style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, +- ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(20),"white")); ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(16),"white")); + } else + style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, +- ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(20),"black")); ++ ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(16),"black")); + + painter.restore(); + } +@@ -828,8 +828,8 @@ void DeviceInfoItem::DrawFuncBtn(QPainter &painter) + void DeviceInfoItem::DrawLoadingIcon(QPainter &painter) + { + painter.save(); +- if (iconFlag >= 7) +- iconFlag = 0; ++// if (iconFlag >= 7) ++// iconFlag = 0; + if (_themeIsBlack) + style()->drawItemPixmap(&painter, + getLoadIconRect(), +@@ -842,7 +842,7 @@ void DeviceInfoItem::DrawLoadingIcon(QPainter &painter) + ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("ukui-loading-"+QString::number(iconFlag)).pixmap(20),"default")); + + painter.restore(); +- iconFlag++; ++// iconFlag++; + + } + +diff --git a/ukcc-bluetooth/devremovedialog.cpp b/ukcc-bluetooth/devremovedialog.cpp +index 8f0a07a..2717a3c 100644 +--- a/ukcc-bluetooth/devremovedialog.cpp ++++ b/ukcc-bluetooth/devremovedialog.cpp +@@ -2,11 +2,12 @@ + + #include + #include ++#include + + DevRemoveDialog::DevRemoveDialog(QWidget *parent):QDialog(parent) + { + initGsettings(); +- this->setFixedSize(380,180); ++ this->setFixedSize(380,200); + this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + this->setAttribute(Qt::WA_TranslucentBackground); + +@@ -21,22 +22,33 @@ DevRemoveDialog::~DevRemoveDialog() + void DevRemoveDialog::initUI() + { + tipLabel = new QLabel(this); +- tipLabel->setGeometry(56,25,300,60); ++ tipLabel->setGeometry(56,25,320,60); + tipLabel->setAlignment(Qt::AlignVCenter|Qt::AlignLeft); + tipLabel->setWordWrap(true); + + + txtLabel = new QLabel(this); +- txtLabel->setGeometry(55,80,300,50); +- txtLabel->setWordWrap(true); ++ txtLabel->setGeometry(55,80,320,65); + txtLabel->setAlignment(Qt::AlignTop|Qt::AlignLeft); +- txtLabel->setText(tr("After it is removed, the PIN code must be matched for the next connection.")); +- txtLabel->setStyleSheet("font-size: 14px;\ +- font-family: Noto Sans CJK SC;\ +- font-weight: 400;\ +- line-height: 30px;\ +- color: #818181;\ +- opacity: 1;"); ++ txtLabel->setWordWrap(true); ++ ++ QPalette txtPal; ++ txtPal.setColor(QPalette::WindowText,QColor("#818181")); ++ txtLabel->setPalette(txtPal); ++ ++ QString txt = tr("After it is removed, the PIN code must be matched for the next connection."); ++ txt = QFontMetrics(this->font()).elidedText(txt,Qt::ElideRight,txtLabel->width()); ++ QFont txtFont ; ++ txtFont.setPointSize(this->fontInfo().pointSize()+3); ++ txtLabel->setFont(txtFont); ++ txtLabel->setText(txt); ++ ++// txtLabel->setStyleSheet("font-size: 14px;\ ++// font-family: Noto Sans CJK SC;\ ++// font-weight: 400;\ ++// line-height: 30px;\ ++// color: #818181;\ ++// opacity: 1;"); + + iconLabel = new QLabel(this); + iconLabel->setGeometry(16,45,22,22); +@@ -54,7 +66,7 @@ void DevRemoveDialog::initUI() + }); + + acceptBtn = new QPushButton(this); +- acceptBtn->setGeometry(252,128,96,36); ++ acceptBtn->setGeometry(242,148,120,36); + acceptBtn->setText(tr("Remove")); + connect(acceptBtn,&QPushButton::clicked,this,[=]{ + emit accepted(); +@@ -62,7 +74,7 @@ void DevRemoveDialog::initUI() + }); + + rejectBtn = new QPushButton(this); +- rejectBtn->setGeometry(140,128,96,36); ++ rejectBtn->setGeometry(110,148,120,36); + rejectBtn->setText(tr("Cancel")); + connect(rejectBtn,&QPushButton::clicked,this,[=]{ + this->close(); +@@ -88,8 +100,10 @@ void DevRemoveDialog::setDialogText(const QString &str) + { + QString txt = QString(tr("Are you sure to remove %1 ?")).arg(str); + +- txt = QFontMetrics(this->font()).elidedText(txt,Qt::ElideMiddle,tipLabel->width()); +- ++ txt = QFontMetrics(this->font()).elidedText(txt,Qt::ElideRight,tipLabel->width()); ++ QFont tipFont ; ++ tipFont.setPointSize(this->fontInfo().pointSize()+3); ++ tipLabel->setFont(tipFont); + tipLabel->setText(txt); + } + +diff --git a/ukcc-bluetooth/devrenamedialog.cpp b/ukcc-bluetooth/devrenamedialog.cpp +index 2fdfbbd..35bc574 100644 +--- a/ukcc-bluetooth/devrenamedialog.cpp ++++ b/ukcc-bluetooth/devrenamedialog.cpp +@@ -35,6 +35,9 @@ void DevRenameDialog::initGsettings() + isblack = false; + else + isblack = true; ++ ++ _fontSize = gsettings->get("system-font-size").toString().toInt(); ++ + } + + connect(gsettings,&QGSettings::changed,this,&DevRenameDialog::gsettingsSlot); +diff --git a/ukcc-bluetooth/devrenamedialog.h b/ukcc-bluetooth/devrenamedialog.h +index 7e3c84c..fbc5977 100644 +--- a/ukcc-bluetooth/devrenamedialog.h ++++ b/ukcc-bluetooth/devrenamedialog.h +@@ -41,6 +41,8 @@ signals: + private: + void initUI(); + ++ int _fontSize; ++ + bool isblack = false; + + QString adapterOldName; +diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp +index 7945bba..53d36ae 100644 +--- a/ukui-bluetooth/pin/pincodewidget.cpp ++++ b/ukui-bluetooth/pin/pincodewidget.cpp +@@ -140,8 +140,8 @@ PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + PIN_label->setGeometry(25,90,207,36); + tip_label->setGeometry(25,56,437,40); + //top_label->setGeometry(32,56,456,50); +- accept_btn->setGeometry(392,152,96,36); +- refuse_btn->setGeometry(288,152,96,36); ++ accept_btn->setGeometry(362,152,116,36); ++ refuse_btn->setGeometry(238,152,116,36); + } + } + diff --git a/patches/ukcc_bluetooth_fix_bug101654.patch b/patches/ukcc_bluetooth_fix_bug101654.patch new file mode 100644 index 0000000..c153bd6 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_bug101654.patch @@ -0,0 +1,85 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index e2d76ea..b6f107c 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -18,6 +18,7 @@ + #include + + bool BlueToothMain::m_device_operating = false; ++QString BlueToothMain::m_device_operating_address = ''; + bool BlueToothMain::m_device_pin_flag = false; + + //extern "C" { +@@ -598,6 +599,14 @@ void BlueToothMain::reportDevRemoveSignal(QString deviceAddress) + { + qDebug () << Q_FUNC_INFO << __LINE__; + removeDeviceItemUI(deviceAddress); ++ ++ if(!m_device_operating_address.isNull() && ++ m_device_operating && ++ (m_device_operating_address == deviceAddress)) ++ { ++ m_device_operating = false; ++ m_device_operating_address.clear(); ++ } + for (int i = 0 ; i < m_default_bluetooth_adapter->m_bluetooth_device_list.size() ; i++) + { + if(deviceAddress == m_default_bluetooth_adapter->m_bluetooth_device_list.at(i)->getDevAddress()) +@@ -789,6 +798,7 @@ void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { + m_device_operating = false; ++ m_device_operating_address.clear(); + }); + m_myDev_show_flag = true; + +@@ -873,6 +883,7 @@ void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { + m_device_operating = false; ++ m_device_operating_address.clear(); + // if (delayStartDiscover_timer->isActive()) + // delayStartDiscover_timer->stop(); + // delayStartDiscover_timer->start(); +diff --git a/ukcc-bluetooth/bluetoothmain.h b/ukcc-bluetooth/bluetoothmain.h +index e002858..2306c05 100644 +--- a/ukcc-bluetooth/bluetoothmain.h ++++ b/ukcc-bluetooth/bluetoothmain.h +@@ -64,6 +64,8 @@ protected: + + public: + static bool m_device_operating ; ++ static QString m_device_operating_address ; ++ + static bool m_device_pin_flag ; + void setbluetoothAdapterDiscoveringStatus(bool); + signals: +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index ea54e99..e5cc958 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -413,9 +413,12 @@ void DeviceInfoItem::mouseReleaseEvent(QMouseEvent *event) + { + return; + } ++ qDebug() << Q_FUNC_INFO << "BlueToothMain::m_device_operating:" << BlueToothMain::m_device_operating; ++ + if (!BlueToothMain::m_device_operating) + { + BlueToothMain::m_device_operating = true; ++ BlueToothMain::m_device_operating_address = _MDev->getDevAddress(); + MouseClickedFunc(); + _pressFlag = false; + _MStatus = Status::Hover; +diff --git a/ukcc-bluetooth/deviceinfoitem.h b/ukcc-bluetooth/deviceinfoitem.h +index e453611..25962a7 100644 +--- a/ukcc-bluetooth/deviceinfoitem.h ++++ b/ukcc-bluetooth/deviceinfoitem.h +@@ -106,6 +106,7 @@ private: + + bool toptipflag = false; + int iconFlag = 7; ++ int m_devConnect_fail_count = 0; + + DEVSTATUS _DevStatus; + Status _MStatus; diff --git a/patches/ukcc_bluetooth_fix_bug103561.patch b/patches/ukcc_bluetooth_fix_bug103561.patch new file mode 100644 index 0000000..6ec28e6 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_bug103561.patch @@ -0,0 +1,42 @@ +diff --git a/ukcc-bluetooth/devremovedialog.cpp b/ukcc-bluetooth/devremovedialog.cpp +index a4b3aab..b858f15 100644 +--- a/ukcc-bluetooth/devremovedialog.cpp ++++ b/ukcc-bluetooth/devremovedialog.cpp +@@ -37,12 +37,14 @@ void DevRemoveDialog::initUI() + txtPal.setColor(QPalette::WindowText,QColor("#818181")); + txtLabel->setPalette(txtPal); + +- QString txt = tr("After it is removed, the PIN code must be matched for the next connection."); +- txt = QFontMetrics(this->font()).elidedText(txt,Qt::ElideRight,txtLabel->width()); ++ QString txtStr = tr("After it is removed, the PIN code must be matched for the next connection."); ++ QString newTxtStr = QFontMetrics(this->font()).elidedText(txtStr,Qt::ElideRight,txtLabel->width()); + QFont txtFont ; + txtFont.setPointSize(this->fontInfo().pointSize()+3); + txtLabel->setFont(txtFont); +- txtLabel->setText(txt); ++ txtLabel->setText(newTxtStr); ++ if (newTxtStr != txtStr) ++ txtLabel->setToolTip(tr("After it is removed, the PIN code must be matched for the next connection.")); + } + + // txtLabel->setStyleSheet("font-size: 14px;\ +@@ -100,13 +102,16 @@ void DevRemoveDialog::initGsettings() + + void DevRemoveDialog::setDialogText(const QString &str) + { +- QString txt = QString(tr("Are you sure to remove %1 ?")).arg(str); ++ QString txtStr = QString(tr("Are you sure to remove %1 ?")).arg(str); + +- txt = QFontMetrics(this->font()).elidedText(txt,Qt::ElideRight,tipLabel->width()); ++ QString newTxtStr = QFontMetrics(this->font()).elidedText(txtStr,Qt::ElideRight,tipLabel->width()); + QFont tipFont ; + tipFont.setPointSize(this->fontInfo().pointSize()+3); + tipLabel->setFont(tipFont); +- tipLabel->setText(txt); ++ tipLabel->setText(newTxtStr); ++ ++ if (newTxtStr != txtStr) ++ tipLabel->setToolTip(tr("Are you sure to remove %1 ?").arg(str)); + } + + void DevRemoveDialog::gsettingsSlot(const QString &key) diff --git a/patches/ukcc_bluetooth_fix_bug104249.patch b/patches/ukcc_bluetooth_fix_bug104249.patch new file mode 100644 index 0000000..a6fa7a6 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_bug104249.patch @@ -0,0 +1,33 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index fee7a54..725d8fa 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -518,11 +518,17 @@ void BlueToothMain::removeAdapterDataList(QString adapterAddress) + m_adapter_address_list.removeAll(adapterAddress); + m_bluetooth_adapter_list.removeAt(i); + +- if (m_adapter_address_list.size()) ++ //if (m_adapter_address_list.size()) ++ //{ ++ disconnect(m_adapter_list_cmbox,SIGNAL(currentIndexChanged(int)),NULL,NULL); ++ if(m_adapter_list_cmbox != nullptr) + { +- if(m_adapter_list_cmbox != nullptr) +- m_adapter_list_cmbox->removeItem(i); ++ m_adapter_list_cmbox->clear(); ++ m_adapter_list_cmbox->addItems(m_adapter_name_list); ++ //m_adapter_list_cmbox->removeItem(i); ++ connect(m_adapter_list_cmbox,SIGNAL(currentIndexChanged(int)),this,SLOT(adapterComboxChanged(int))); + } ++ //} + } + void BlueToothMain::reportAdapterAddSignal(QString adapterAddress) + { +@@ -934,6 +940,7 @@ void BlueToothMain::getDefaultAdapterData(QString adapter_address) + dev->setObjectName(deviceAddress); + m_default_bluetooth_adapter->m_bluetooth_device_list.append(dev); + } ++ qDebug () << Q_FUNC_INFO << "end" << __LINE__; + + } + diff --git a/patches/ukcc_bluetooth_fix_bug98646.patch b/patches/ukcc_bluetooth_fix_bug98646.patch new file mode 100644 index 0000000..88360c1 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_bug98646.patch @@ -0,0 +1,30 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index bbd50e8..57cac75 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -196,6 +196,9 @@ void DeviceInfoItem::GSettingsChanges(const QString &key) + _themeIsBlack = true; + else + _themeIsBlack = false; ++ ++ //if (item_gsettings->get("icon-theme-name").toString() == "ukui-icon-theme-classical") ++ // batteryPixmap = getDevTypeIcon(); + } else if (SYSTEMFONT == key) { + _fontFamily = item_gsettings->get("system-font").toString(); + } else if (SYSTEMFONTSIZE == key) { +@@ -596,11 +599,13 @@ QPixmap DeviceInfoItem::getDevTypeIcon() + iconName = "input-mouse-symbolic"; + break; + default: +- iconName = "bluetooth-active-symbolic"; ++ //iconName = "bluetooth-active-symbolic"; ++ iconName = "bluetooth-symbolic"; + break; + } + } else { +- iconName = "bluetooth-active-symbolic"; ++ //iconName = "bluetooth-active-symbolic"; ++ iconName = "bluetooth-symbolic"; + } + + //if (_themeIsBlack && (Status::Nomal == _MStatus)) { diff --git a/patches/ukcc_bluetooth_fix_cmpbug103927.patch b/patches/ukcc_bluetooth_fix_cmpbug103927.patch new file mode 100644 index 0000000..d59c684 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_cmpbug103927.patch @@ -0,0 +1,24 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 7bc3cca..59a0c81 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -506,10 +506,16 @@ void DeviceInfoItem::MouseClickedDevFunc() + remove->setText(tr("remove")); + dev_Menu->addAction(remove); + +- //qDebug () << this->x() << this->y() << "======x ======y"; +- dev_Menu->move(qAbs(sreenPoint.x())+this->width()-200,qAbs(sreenPoint.y())+this->y()+40); +- dev_Menu->exec(); ++ qDebug () << this->x() << this->y() << "======x ======y"; ++ qDebug () << sreenPoint.x() << sreenPoint.y() << "======sreenPoint.x ======sreenPoint.y"; ++ ++ //int testY = ((sreenPoint.y()>0)?(-1)*qAbs(sreenPoint.y())+40:qAbs(sreenPoint.y())+40)+this->y(); ++ int testY = (-1)*sreenPoint.y()+40+this->y(); ++ qDebug () << Q_FUNC_INFO << " test Y =======================" << testY; + ++ //dev_Menu->move(qAbs(sreenPoint.x())+this->width()-200,testY); ++ dev_Menu->move(qAbs(sreenPoint.x())+this->width()-200,(-1)*sreenPoint.y()+40+this->y()); ++ dev_Menu->exec(); + } + + void DeviceInfoItem::mouseMoveEvent(QMouseEvent *event) diff --git a/patches/ukcc_bluetooth_fix_devConnect_signal.patch b/patches/ukcc_bluetooth_fix_devConnect_signal.patch new file mode 100644 index 0000000..e14bc2c --- /dev/null +++ b/patches/ukcc_bluetooth_fix_devConnect_signal.patch @@ -0,0 +1,20 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 1a962ca..efd52a7 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -287,6 +287,7 @@ void DeviceInfoItem::setDeviceConnectSignals() + connect(_MDev,&bluetoothdevice::errorInfoRefresh,this,[=](int errorId , QString errorText) + { + qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; ++ emit devConnectionComplete(); + if (errorId) + { + if(_devConnTimer->isActive()) +@@ -298,7 +299,6 @@ void DeviceInfoItem::setDeviceConnectSignals() + qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; + //BlueToothMain::m_device_pin_flag = false; + _DevStatus = DEVSTATUS::ConnectFailed; +- emit devConnectionComplete(); + update(); + TimedRestoreConnectionErrorDisplay(); + } diff --git a/patches/ukcc_bluetooth_fix_device_random_mac.patch b/patches/ukcc_bluetooth_fix_device_random_mac.patch new file mode 100644 index 0000000..3dc715d --- /dev/null +++ b/patches/ukcc_bluetooth_fix_device_random_mac.patch @@ -0,0 +1,72 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 94b8bb9..aef72e9 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -779,6 +779,9 @@ void SessionDbusRegister::connectSignal() + { + emit deviceScanResult(devPtr.data()->address(),devPtr.data()->name(), + BluezQt::Device::typeToString(devPtr.data()->type())); ++ //添加mac前3位和名称一致的判断,过滤掉扫描列表中mac地址会变化的设备 ++ clearDeviceScanList(devPtr); ++ + } + + +@@ -977,6 +980,43 @@ void SessionDbusRegister::connectSignal() + } + } + ++bool SessionDbusRegister::deviceMacAddressContrast(QString newMacAddress , QString oldMacAddress) ++{ ++ //判断mac前三位是否一致 ++ QString newStr = newMacAddress.left(8); ++ QString oldStr = oldMacAddress.left(8); ++ if (newStr == oldStr) ++ return true; ++ else ++ return false; ++} ++ ++void SessionDbusRegister::clearDeviceScanList(BluezQt::DevicePtr devPtr) ++{ ++ ++ if (nullptr == devPtr) ++ { ++ return; ++ } ++ ++ foreach (auto dev, Daemon::_DefualtAdapter.data()->devices()) ++ { ++ if( nullptr != dev && ++ !dev.data()->isPaired() && ++ !dev.data()->isConnected() && ++ (devPtr.data()->name() == dev.data()->name()) && ++ (devPtr.data()->address() != dev.data()->address()) && ++ deviceMacAddressContrast(devPtr.data()->address(),dev.data()->address())) ++ { ++ qDebug() << Q_FUNC_INFO << devPtr.data()->name() << devPtr.data()->name() ; ++ qDebug() << Q_FUNC_INFO << dev.data()->name() << dev.data()->name() ; ++ ++ Daemon::_DefualtAdapter.data()->removeDevice(dev); ++ break; ++ } ++ } ++} ++ + void SessionDbusRegister::sendReplyFileReceivingSignal(bool v) + { + qDebug() << "SessionDbusRegister::sendReplyFileReceivingSignal"; +diff --git a/service/sessiondbusregister.h b/service/sessiondbusregister.h +index a5225ef..b2894ac 100644 +--- a/service/sessiondbusregister.h ++++ b/service/sessiondbusregister.h +@@ -56,6 +56,9 @@ public: + private: + bool InterfaceAlreadyExists(); + void AudioDevConnectFunc(BluezQt::DevicePtr); ++ ++ void clearDeviceScanList(BluezQt::DevicePtr); ++ bool deviceMacAddressContrast(QString,QString); + public slots: + // 蓝牙默认适配器信息处理dbus + bool getBluetoothBlock(); diff --git a/patches/ukcc_bluetooth_fix_more_adapter.patch b/patches/ukcc_bluetooth_fix_more_adapter.patch new file mode 100644 index 0000000..300fcca --- /dev/null +++ b/patches/ukcc_bluetooth_fix_more_adapter.patch @@ -0,0 +1,99 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 2b38703..7a519b2 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -359,7 +359,9 @@ void SessionDbusRegister::setDefaultAdapter(QString addr) + + BluezQt::AdapterPtr adapter = Daemon::_BluezManager->adapterForAddress(addr); + if (!adapter.isNull()) { ++ Daemon::_DefualtAdapter->disconnect(); + Daemon::_DefualtAdapter = adapter; ++ this->connectSignal(); + emit this->defaultAdapterChanged(addr); + } + } +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index f212edf..b6f387b 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -887,6 +887,13 @@ void BlueToothMain::getDefaultAdapterData(QString adapter_address) + m_default_adapter_name = getAdapterName(adapter_address); + m_current_adapter_power_swtich = getDefaultAdapterPower(); + m_current_adapter_scan_status = getDefaultAdapterScanStatus(); ++ //当前扫描状态是开启,则关闭扫描状态,并清除所有未匹配的蓝牙设备, ++ if (m_current_adapter_scan_status) ++ { ++ setDefaultAdapterScanOn(false); ++ clearAllUnPairedDevicelist(); ++ } ++ + m_current_adapter_disconvery_swtich = getDefaultAdapterDiscoverable(); + + +@@ -1716,7 +1723,7 @@ void BlueToothMain::refreshUIWhenAdapterChanged() + { + qDebug() << Q_FUNC_INFO << __LINE__; + // =============清空我的设备和蓝牙发现设备栏布局下的所有设备item================= +- //cleanPairDevices(); ++ cleanPairDevices(); + m_default_adapter_address = getDefaultAdapterAddress(); + getDefaultAdapterData(m_default_adapter_address); + // ========================END=========================================== +@@ -1742,8 +1749,6 @@ void BlueToothMain::refreshUIWhenAdapterChanged() + //==============初始化蓝牙信息和基础信息==================================== + bluetooth_name->set_dev_name(m_default_adapter_name); + +- +- + qDebug() << Q_FUNC_INFO << "m_current_adapter_power_swtich:" << m_current_adapter_power_swtich ; + if(m_current_adapter_power_swtich) + { +@@ -1766,7 +1771,6 @@ void BlueToothMain::refreshUIWhenAdapterChanged() + m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(false); + } +-// bluetooth_name->setVisible(false); + frame_bottom->setVisible(false); + frame_middle->setVisible(false); + } +@@ -2145,7 +2149,9 @@ void BlueToothMain::adapterComboxChanged(int i) + if(m_open_bluetooth_btn->isChecked()){ + qDebug() << __FUNCTION__<< "index - i : "<< i << __LINE__ ; + m_open_bluetooth_btn->setChecked(false); ++#ifndef DEVICE_IS_INTEL + m_open_bluetooth_btn->setDisabledFlag(false); ++#endif + } + if(frame_middle->isVisible()){ + frame_middle->setVisible(false); +@@ -2229,6 +2235,7 @@ void BlueToothMain::cleanPairDevices() + { + child->widget()->setParent(NULL); + } ++ paired_dev_layout->removeItem(child); + delete child; + child = nullptr; + } +@@ -2239,6 +2246,7 @@ void BlueToothMain::cleanPairDevices() + { + child->widget()->setParent(NULL); + } ++ device_list_layout->removeItem(child); + delete child; + child = nullptr; + } +diff --git a/ukcc-bluetooth/ukcc-bluetooth.pro b/ukcc-bluetooth/ukcc-bluetooth.pro +index f79fa69..9715569 100644 +--- a/ukcc-bluetooth/ukcc-bluetooth.pro ++++ b/ukcc-bluetooth/ukcc-bluetooth.pro +@@ -17,6 +17,10 @@ LIBS += -lukcc + # depend on your compiler). Please consult the documentation of the + # deprecated API in order to know how to port your code away from it. + DEFINES += QT_DEPRECATED_WARNINGS ++exists(/etc/apt/ota_version) ++{ ++ DEFINES += DEVICE_IS_INTEL ++} + + # You can also make your code fail to compile if it uses deprecated APIs. + # In order to do so, uncomment the following line. diff --git a/patches/ukcc_bluetooth_fix_optimize_error_info.patch b/patches/ukcc_bluetooth_fix_optimize_error_info.patch new file mode 100644 index 0000000..a51eba7 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_optimize_error_info.patch @@ -0,0 +1,227 @@ +diff --git a/service/bluetoothagent.cpp b/service/bluetoothagent.cpp +index c6de8a5..3d2a498 100644 +--- a/service/bluetoothagent.cpp ++++ b/service/bluetoothagent.cpp +@@ -110,7 +110,7 @@ void BluetoothAgent::displayPasskey(BluezQt::DevicePtr device, const QString &pa + QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "displayPasskey"); +- displayPasskeySignal << device.data()->name() << passkey << device.data()->address();; ++ displayPasskeySignal << device.data()->name() << passkey; + QDBusConnection::sessionBus().send(displayPasskeySignal); + } + +@@ -134,7 +134,7 @@ void BluetoothAgent::requestConfirmation(BluezQt::DevicePtr device, const QStrin + QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "requestConfirmation"); +- displayPasskeySignal << device.data()->name() << passkey << device.data()->address(); ++ displayPasskeySignal << device.data()->name() << passkey; + QDBusConnection::sessionBus().send(displayPasskeySignal); + + tmpRequestConfirmation = request; +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index d3b22f2..6fa20f2 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -313,6 +313,13 @@ void BlueToothMain::monitorBluetoothDbusConnection() + INTERFACE, + "requestConfirmation",this, SLOT(reportRequestConfirmation(QString,QString))); + ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, ++ "replyRequestConfirmation",this, SLOT(reportReplyRequestConfirmation(bool))); ++ ++ ++ + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, +@@ -632,11 +639,15 @@ void BlueToothMain::reportRequestConfirmation(QString deviceName,QString disPinC + qDebug() << Q_FUNC_INFO << deviceName << disPinCode << __LINE__; + m_device_pin_flag = true; + } +- ++void BlueToothMain::reportReplyRequestConfirmation(bool userCheck) ++{ ++ qDebug() << Q_FUNC_INFO << "User check:" << userCheck << __LINE__; ++ m_device_pin_flag = false; ++} + void BlueToothMain::reportDevOperateErrorSignal(QString deviceAddress , int ErrorId , QString ErrorText) + { + qDebug() << Q_FUNC_INFO << deviceAddress << ErrorId << ErrorText << __LINE__; +- m_device_pin_flag = false; ++ //m_device_pin_flag = false; + for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (deviceAddress == dev->getDevAddress()) +@@ -1599,16 +1610,18 @@ void BlueToothMain::initMainWindowbottomUI() + { + qDebug() << "delay Start Discover time out:" << __LINE__; + delayStartDiscover_timer->stop(); +- setDefaultAdapterScanOn(true); +- +- QTimer::singleShot(500,this,[=] ++ if (!m_current_adapter_scan_status) + { +- if (!m_current_adapter_scan_status) +- { +- delayStartDiscover_timer->start(); +- } +- }); +- ++ setDefaultAdapterScanOn(true); ++ ++ //QTimer::singleShot(500,this,[=] ++ //{ ++ // if (!m_current_adapter_scan_status) ++ // { ++ // delayStartDiscover_timer->start(); ++ // } ++ //}); ++ } + }); + + title_layout->addWidget(label_1); +@@ -2113,19 +2126,11 @@ void BlueToothMain::adapterComboxChanged(int i) + if(i != -1) + { + qDebug() << Q_FUNC_INFO << "=================3" << __LINE__; ++ setDefaultAdapterScanOn(false); ++ clearAllUnPairedDevicelist(); + + setDefaultAdapter(m_bluetooth_adapter_list.at(i)->getDevAddress()); +- +-// m_default_bluetooth_adapter = m_bluetooth_adapter_list.at(i); +-// if (nullptr == m_default_bluetooth_adapter) +-// { +-// return; +-// } + refreshUIWhenAdapterChanged(); +- +-// if(m_settings) +-// m_settings->set("adapter-address",QVariant::fromValue(m_adapter_address_list.at(i))); +-// Default_Adapter = m_adapter_address_list.at(i); + }else{ + if(m_open_bluetooth_btn->isChecked()){ + qDebug() << __FUNCTION__<< "index - i : "<< i << __LINE__ ; +diff --git a/ukcc-bluetooth/bluetoothmain.h b/ukcc-bluetooth/bluetoothmain.h +index 6a39def..108d86c 100644 +--- a/ukcc-bluetooth/bluetoothmain.h ++++ b/ukcc-bluetooth/bluetoothmain.h +@@ -87,7 +87,8 @@ private slots: + void reportDevConnectStatusSignal(QString,bool); + void reportDevNameChangedSignal(QString,QString); + void reportDevTypeChangedSignal(QString,QString); +- void reportRequestConfirmation(QString,QString); ++ void reportRequestConfirmation(QString,QString,QString); ++ void reportReplyRequestConfirmation(bool); + void reportDevOperateErrorSignal(QString,int,QString); + + //receive +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index efd52a7..14fd624 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -38,17 +38,20 @@ void DeviceInfoItem::TimedRestoreConnectionErrorDisplay() + qDebug() << Q_FUNC_INFO << __LINE__; + //错误信息显示超时后,显示错误操作后的设备状态 + QTimer::singleShot(8000,this,[=]{ +- if (_MDev->isPaired()) ++ if((_DevStatus != DEVSTATUS::Connecting) && (_DevStatus != DEVSTATUS::DisConnecting)) + { +- _DevStatus = DEVSTATUS::Paired; ++ if (_MDev->isPaired()) ++ { ++ _DevStatus = DEVSTATUS::Paired; + +- if (_MDev->isConnected()) +- _DevStatus = DEVSTATUS::Connected; ++ if (_MDev->isConnected()) ++ _DevStatus = DEVSTATUS::Connected; + +- } else { +- _DevStatus = DEVSTATUS::NoPaired; ++ } else { ++ _DevStatus = DEVSTATUS::NoPaired; ++ } ++ update(); + } +- update(); + }); + } + +@@ -99,12 +102,12 @@ void DeviceInfoItem::InitMemberVariables() + _devConnTimer = new QTimer(this); + _devConnTimer->setInterval(30000); + connect(_devConnTimer,&QTimer::timeout,this,[=]{ +- if(BlueToothMain::m_device_pin_flag) +- { +- _devConnTimer->stop(); +- _devConnTimer->start(); +- return; +- } ++// if(BlueToothMain::m_device_pin_flag) ++// { ++// _devConnTimer->stop(); ++// _devConnTimer->start(); ++// return; ++// } + + emit devConnectionComplete(); + _devConnTimer->stop(); +@@ -233,7 +236,7 @@ void DeviceInfoItem::setDeviceConnectSignals() + connect(_MDev,&bluetoothdevice::pairedChanged,this,[=](bool paired) + { + qDebug() << Q_FUNC_INFO << "pairedChanged" << __LINE__; +- BlueToothMain::m_device_pin_flag = false; ++ //BlueToothMain::m_device_pin_flag = false; + if(_devConnTimer->isActive()) + _devConnTimer->stop(); + if (_iconTimer->isActive()) +@@ -262,7 +265,7 @@ void DeviceInfoItem::setDeviceConnectSignals() + + connect(_MDev,&bluetoothdevice::connectedChanged,this,[=](bool connected) + { +- BlueToothMain::m_device_pin_flag = false; ++ //BlueToothMain::m_device_pin_flag = false; + if(_devConnTimer->isActive()) + _devConnTimer->stop(); + if (_iconTimer->isActive()) +@@ -274,9 +277,18 @@ void DeviceInfoItem::setDeviceConnectSignals() + } else if (!_MDev->isPaired() && connected) { + _DevStatus = DEVSTATUS::Connecting; + } else if (_MDev->isPaired() && !connected){ +- _DevStatus = DEVSTATUS::Paired; ++ if (_DevStatus == DEVSTATUS::Connecting) ++ _DevStatus = DEVSTATUS::ConnectFailed; ++ else if (_DevStatus != DEVSTATUS::ConnectFailed && ++ _DevStatus != DEVSTATUS::DisConnectFailed) ++ _DevStatus = DEVSTATUS::Paired; + } else { +- _DevStatus = DEVSTATUS::ConnectFailed; ++ if (_DevStatus == DEVSTATUS::Connecting && !connected) ++ _DevStatus = DEVSTATUS::ConnectFailed; ++ else if (_DevStatus == DEVSTATUS::DisConnecting && connected) ++ _DevStatus = DEVSTATUS::DisConnectFailed; ++ else ++ _DevStatus = DEVSTATUS::ConnectFailed; + } + + emit devConnectionComplete(); +@@ -296,9 +308,12 @@ void DeviceInfoItem::setDeviceConnectSignals() + _iconTimer->stop(); + _clicked = false; + +- qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; ++ //qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; + //BlueToothMain::m_device_pin_flag = false; +- _DevStatus = DEVSTATUS::ConnectFailed; ++ if (_MDev->isConnected()) ++ _DevStatus = DEVSTATUS::DisConnectFailed; ++ else ++ _DevStatus = DEVSTATUS::ConnectFailed; + update(); + TimedRestoreConnectionErrorDisplay(); + } diff --git a/patches/ukcc_bluetooth_fix_probability_show_connectfail.patch b/patches/ukcc_bluetooth_fix_probability_show_connectfail.patch new file mode 100644 index 0000000..1fc4d0c --- /dev/null +++ b/patches/ukcc_bluetooth_fix_probability_show_connectfail.patch @@ -0,0 +1,19 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index ce5b714..6094332 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -322,9 +322,12 @@ void DeviceInfoItem::setDeviceConnectSignals() + //if (_MDev->isConnected()) + // _DevStatus = DEVSTATUS::DisConnectFailed; + //else ++ if(!_MDev->isConnected()) ++ { + _DevStatus = DEVSTATUS::ConnectFailed; +- update(); +- TimedRestoreConnectionErrorDisplay(); ++ update(); ++ TimedRestoreConnectionErrorDisplay(); ++ } + } + }); + } diff --git a/patches/ukcc_bluetooth_fix_remove_show_window.patch b/patches/ukcc_bluetooth_fix_remove_show_window.patch new file mode 100644 index 0000000..e91729a --- /dev/null +++ b/patches/ukcc_bluetooth_fix_remove_show_window.patch @@ -0,0 +1,120 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 57cac75..1a962ca 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -144,9 +144,18 @@ void DeviceInfoItem::MenuSignalDeviceFunction(QAction *action) + } + } + ++bool DeviceInfoItem::isDisplayPINCodeWidget() ++{ ++ if (bluetoothdevice::DEVICE_TYPE::phone == _MDev->getDevType() || ++ bluetoothdevice::DEVICE_TYPE::computer == _MDev->getDevType()) ++ return true; ++ else ++ return false; ++} ++ + void DeviceInfoItem::showDeviceRemoveWidget() + { +- DevRemoveDialog *mesgBox = new DevRemoveDialog(); ++ DevRemoveDialog *mesgBox = new DevRemoveDialog(isDisplayPINCodeWidget()?1:0); + mesgBox->setModal(true); + mesgBox->setDialogText(_MDev->getDevName()); + +diff --git a/ukcc-bluetooth/deviceinfoitem.h b/ukcc-bluetooth/deviceinfoitem.h +index c9a7148..fdb128a 100644 +--- a/ukcc-bluetooth/deviceinfoitem.h ++++ b/ukcc-bluetooth/deviceinfoitem.h +@@ -101,7 +101,7 @@ private: + int NameTextCoordinate_Y_offset(); + void TimedRestoreConnectionErrorDisplay(); + void showDeviceRemoveWidget(); +- ++ bool isDisplayPINCodeWidget(); + + bool toptipflag = false; + int iconFlag = 7; +diff --git a/ukcc-bluetooth/devremovedialog.cpp b/ukcc-bluetooth/devremovedialog.cpp +index 2717a3c..a4b3aab 100644 +--- a/ukcc-bluetooth/devremovedialog.cpp ++++ b/ukcc-bluetooth/devremovedialog.cpp +@@ -4,13 +4,13 @@ + #include + #include + +-DevRemoveDialog::DevRemoveDialog(QWidget *parent):QDialog(parent) ++DevRemoveDialog::DevRemoveDialog(int mode,QWidget *parent):QDialog(parent) + { + initGsettings(); + this->setFixedSize(380,200); + this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + this->setAttribute(Qt::WA_TranslucentBackground); +- ++ this->m_mode = mode; + initUI(); + } + +@@ -26,22 +26,24 @@ void DevRemoveDialog::initUI() + tipLabel->setAlignment(Qt::AlignVCenter|Qt::AlignLeft); + tipLabel->setWordWrap(true); + +- +- txtLabel = new QLabel(this); +- txtLabel->setGeometry(55,80,320,65); +- txtLabel->setAlignment(Qt::AlignTop|Qt::AlignLeft); +- txtLabel->setWordWrap(true); +- +- QPalette txtPal; +- txtPal.setColor(QPalette::WindowText,QColor("#818181")); +- txtLabel->setPalette(txtPal); +- +- QString txt = tr("After it is removed, the PIN code must be matched for the next connection."); +- txt = QFontMetrics(this->font()).elidedText(txt,Qt::ElideRight,txtLabel->width()); +- QFont txtFont ; +- txtFont.setPointSize(this->fontInfo().pointSize()+3); +- txtLabel->setFont(txtFont); +- txtLabel->setText(txt); ++ if (this->m_mode) ++ { ++ txtLabel = new QLabel(this); ++ txtLabel->setGeometry(55,80,320,65); ++ txtLabel->setAlignment(Qt::AlignTop|Qt::AlignLeft); ++ txtLabel->setWordWrap(true); ++ ++ QPalette txtPal; ++ txtPal.setColor(QPalette::WindowText,QColor("#818181")); ++ txtLabel->setPalette(txtPal); ++ ++ QString txt = tr("After it is removed, the PIN code must be matched for the next connection."); ++ txt = QFontMetrics(this->font()).elidedText(txt,Qt::ElideRight,txtLabel->width()); ++ QFont txtFont ; ++ txtFont.setPointSize(this->fontInfo().pointSize()+3); ++ txtLabel->setFont(txtFont); ++ txtLabel->setText(txt); ++ } + + // txtLabel->setStyleSheet("font-size: 14px;\ + // font-family: Noto Sans CJK SC;\ +diff --git a/ukcc-bluetooth/devremovedialog.h b/ukcc-bluetooth/devremovedialog.h +index 3cb932a..6a82ee9 100644 +--- a/ukcc-bluetooth/devremovedialog.h ++++ b/ukcc-bluetooth/devremovedialog.h +@@ -15,7 +15,7 @@ class DevRemoveDialog final : public QDialog + { + Q_OBJECT + public: +- explicit DevRemoveDialog(QWidget *parent = nullptr); ++ explicit DevRemoveDialog(int mode , QWidget *parent = nullptr); + + ~DevRemoveDialog(); + +@@ -47,6 +47,8 @@ private: + QPushButton *acceptBtn = nullptr; + + QPushButton *rejectBtn = nullptr; ++ ++ int m_mode = 1; + }; + + #endif // DEVREMOVEDIALOG_H diff --git a/patches/ukcc_bluetooth_fix_show_error.patch b/patches/ukcc_bluetooth_fix_show_error.patch new file mode 100644 index 0000000..0c601ad --- /dev/null +++ b/patches/ukcc_bluetooth_fix_show_error.patch @@ -0,0 +1,965 @@ +diff --git a/debian/ukui-bluetooth.install b/debian/ukui-bluetooth.install +index a488bb2..ffb99d1 100644 +--- a/debian/ukui-bluetooth.install ++++ b/debian/ukui-bluetooth.install +@@ -1,3 +1,4 @@ + ukui-bluetooth/translations/*.qm /usr/share/ukui-bluetooth/translations/ + data/ukui-bluetooth.desktop /etc/xdg/autostart/ +-ukcc-bluetooth/*.qm /usr/share/ukui-bluetooth/translations/ ++ukcc-bluetooth/translations/*.qm /usr/share/ukui-bluetooth/translations/ ++ukcc-bluetooth/translations/*.ts /usr/share/ukui-bluetooth/translations/ +diff --git a/environment.pri b/environment.pri +index 53ad5bc..713b2fd 100644 +--- a/environment.pri ++++ b/environment.pri +@@ -5,3 +5,4 @@ BIN_INSTALL_DIR = /usr/bin/ + ACTIONS_INSTALL_DIR = /usr/share/polkit-1/actions/ + SERVICE_INSTALL_DIR = /usr/share/dbus-1/system-services/ + CONF_INSTALL_DIR = /etc/dbus-1/system.d/ ++SHARE_TRANSLATIONS_INSTALL_DIR = /usr/share/ukui-bluetooth/translations +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 2cb54a8..c164364 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -472,26 +472,23 @@ void SessionDbusRegister::clearAllUnPairedDevicelist() + } + } + +-#ifdef BATTERY + qint64 SessionDbusRegister::getDevBattery(const QString addr) + { + if (addr.isEmpty() || addr.isNull()) + return -1; + ++#ifdef BATTERY + if (!Daemon::_DefualtAdapter.isNull()) { + BluezQt::DevicePtr dev = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!dev.isNull()) { + if (dev.data()->battery().isNull()) + return -1; + return dev.data()->battery().data()->percentage(); +- } else { +- return -1; + } +- } else { +- return -1; + } +-} + #endif ++ return -1; ++} + + QString SessionDbusRegister::getDevName(const QString addr) + { +@@ -707,9 +704,10 @@ void SessionDbusRegister::connectSignal() + + connect(devPtr.data(),&BluezQt::Device::nameChanged,this,[=](const QString &name){ + qDebug() << Q_FUNC_INFO << "nameChanged" << devPtr.data()->address(); +- emit devTypeChangedSignal(devPtr.data()->address(),name); ++ emit devNameChangedSignal(devPtr.data()->address(),name); + }); + ++#ifdef BATTERY + connect(devPtr.data(),&BluezQt::Device::batteryChanged,this,[=](BluezQt::BatteryPtr battery){ + if(nullptr != battery){ + qDebug() << Q_FUNC_INFO << "batteryChanged" << battery.data()->percentage(); +@@ -720,6 +718,7 @@ void SessionDbusRegister::connectSignal() + } + + }); ++#endif + }); + + foreach (auto dev, Daemon::_DefualtAdapter.data()->devices()) { +@@ -778,7 +777,7 @@ void SessionDbusRegister::connectSignal() + qDebug() << Q_FUNC_INFO << "nameChanged" << dev.data()->address(); + emit devTypeChangedSignal(dev.data()->address(),name); + }); +- ++#ifdef BATTERY + connect(dev.data(),&BluezQt::Device::batteryChanged,this,[=](BluezQt::BatteryPtr battery){ + if(nullptr != battery){ + qDebug() << Q_FUNC_INFO << "batteryChanged" << battery.data()->percentage(); +@@ -788,6 +787,7 @@ void SessionDbusRegister::connectSignal() + qDebug() << Q_FUNC_INFO << "batteryChanged null " << dev.data()->address(); + } + }); ++#endif + } + } + +diff --git a/service/sessiondbusregister.h b/service/sessiondbusregister.h +index 2ddf8a7..3b5af6e 100644 +--- a/service/sessiondbusregister.h ++++ b/service/sessiondbusregister.h +@@ -121,9 +121,9 @@ public slots: + + void cancelFileReceiving(); + +-#ifdef BATTERY ++//#ifdef BATTERY + qint64 getDevBattery(const QString); +-#endif ++//#endif + + //文件传输dbus + void sendFiles(QString,QString);//test +diff --git a/ukcc-bluetooth/bluetooth.h b/ukcc-bluetooth/bluetooth.h +index 796d68b..434bf74 100644 +--- a/ukcc-bluetooth/bluetooth.h ++++ b/ukcc-bluetooth/bluetooth.h +@@ -29,6 +29,12 @@ public: + + void plugin_leave() Q_DECL_OVERRIDE; + ++ //static bool isIntel_bt = CommonInterface::isIntel(); ++ //注意:ukcc-bluetooth_%1.ts ++ QString translationPath() const { // 获取多语言文件路径,用于搜索 ++ qDebug() << Q_FUNC_INFO << QStringLiteral("/usr/share/ukui-bluetooth/translations/%1.ts"); ++ return QStringLiteral("/usr/share/ukui-bluetooth/translations/ukcc-bluetooth_%1.ts"); ++ } + private: + QString pluginName; + int pluginType; +diff --git a/ukcc-bluetooth/bluetoothdbusservice.cpp b/ukcc-bluetooth/bluetoothdbusservice.cpp +index 2904783..574a2a1 100644 +--- a/ukcc-bluetooth/bluetoothdbusservice.cpp ++++ b/ukcc-bluetooth/bluetoothdbusservice.cpp +@@ -12,7 +12,7 @@ BlueToothDBusService::~BlueToothDBusService() + + } + +-bool BlueToothDBusService::getAdapterPower() ++bool BlueToothDBusService::getDefaultAdapterPower() + { + QDBusReply reply = interface.call("getDefaultAdapterPower"); + if (reply.isValid()) { +diff --git a/ukcc-bluetooth/bluetoothdbusservice.h b/ukcc-bluetooth/bluetoothdbusservice.h +index 7cf38c5..3ce5d3b 100644 +--- a/ukcc-bluetooth/bluetoothdbusservice.h ++++ b/ukcc-bluetooth/bluetoothdbusservice.h +@@ -18,7 +18,7 @@ public: + ~BlueToothDBusService(); + + static QDBusInterface interface; +- static bool getAdapterPower(); ++ static bool getDefaultAdapterPower(); + static bool getBluetoothBlock(); + static bool getAdapterDiscoverable(); + static QStringList getAdapterList(); +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index e026131..b5b2593 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -450,7 +450,7 @@ void BlueToothMain::refreshBluetoothAdapterInterfaceUI() + } + } + +- refreshUIWhenAdapterChanged(); ++ //refreshUIWhenAdapterChanged(); + } + + //void BlueToothMain::addBluetoothAdapterComboBox(QString adapterName) +@@ -778,6 +778,7 @@ void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) + connect(item,SIGNAL(devSendFiles(QString)),this,SLOT(receiveSendFileSignal(QString))); + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { ++ m_device_operating = false; + // if (delayStartDiscover_timer->isActive()) + // delayStartDiscover_timer->stop(); + // delayStartDiscover_timer->start(); +@@ -865,6 +866,7 @@ void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) + connect(item,SIGNAL(devSendFiles(QString)),this,SLOT(receiveSendFileSignal(QString))); + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { ++ m_device_operating = false; + if (delayStartDiscover_timer->isActive()) + delayStartDiscover_timer->stop(); + delayStartDiscover_timer->start(); +@@ -1457,7 +1459,7 @@ void BlueToothMain::initMainWindowTopUI() + QHBoxLayout *frame_2_layout = new QHBoxLayout(frame_2); + frame_2_layout->setSpacing(10); + frame_2_layout->setContentsMargins(16,0,16,0); +- ++ //~ contents_path /Bluetooth/Bluetooth adapter + QLabel *label_3 = new QLabel(tr("Bluetooth adapter"),frame_2); + label_3->setStyleSheet("QLabel{\ + width: 56px;\ +diff --git a/ukcc-bluetooth/bluetoothnamelabel.cpp b/ukcc-bluetooth/bluetoothnamelabel.cpp +index fa2dcfb..d4d0aff 100644 +--- a/ukcc-bluetooth/bluetoothnamelabel.cpp ++++ b/ukcc-bluetooth/bluetoothnamelabel.cpp +@@ -21,7 +21,7 @@ BluetoothNameLabel::BluetoothNameLabel(QWidget *parent, int x, int y): + icon_pencil = new QLabel(this); + icon_pencil->setGeometry(this->width()-200,2,43,this->height()-3); + icon_pencil->setPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20)); +- icon_pencil->setToolTip(tr("Double-click to change the device name")); ++ icon_pencil->setToolTip(tr("Click to change the device name")); + hLayout->addWidget(icon_pencil); + hLayout->addStretch(1); + +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 1605d93..3ff0aed 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -3,8 +3,10 @@ + #include + #include + #include ++#include + + #include "devremovedialog.h" ++#include "bluetoothmain.h" + + #define STYLENAME "org.ukui.style" + +@@ -298,8 +300,10 @@ QRect DeviceInfoItem::getFontPixelQPoint(QString str) + void DeviceInfoItem::enterEvent(QEvent *event) + { + Q_UNUSED(event); +- +- _MStatus = Status::Hover; ++ if (!BlueToothMain::m_device_operating) ++ _MStatus = Status::Hover; ++ else ++ _MStatus = Status::Nomal; + update(); + } + +@@ -317,8 +321,11 @@ void DeviceInfoItem::mousePressEvent(QMouseEvent *event) + if (mouseEventIntargetAera(event->pos())) { + _pressBtnFlag = true; + } else { +- _pressFlag = true; +- _MStatus = Status::Check; ++ if (!BlueToothMain::m_device_operating) ++ { ++ _pressFlag = true; ++ _MStatus = Status::Check; ++ } + } + } + update(); +@@ -384,10 +391,13 @@ void DeviceInfoItem::mouseReleaseEvent(QMouseEvent *event) + MouseClickedDevFunc(); + _pressBtnFlag = false; + } else { +- MouseClickedFunc(); +- _pressFlag = false; +- _MStatus = Status::Hover; +- ++ if (!BlueToothMain::m_device_operating) ++ { ++ BlueToothMain::m_device_operating = true; ++ MouseClickedFunc(); ++ _pressFlag = false; ++ _MStatus = Status::Hover; ++ } + } + } + update(); +@@ -588,26 +598,6 @@ void DeviceInfoItem::DrawStatusIcon(QPainter &painter) + painter.restore(); + } + +-//int DeviceInfoItem::NameTextWidthMax() +-//{ +-// qDebug()<< Q_FUNC_INFO << "=================================" << this->width() << __LINE__; +-// int name_width_max = this->width() - 226 - 70; +-// int width_offset = 0 ; +-// switch (_fontSize) +-// { +-// case 15: +-// case 14: +-// case 13: +-// case 12: +-// width_offset = 0; +-// case 11: +-// default: +-// width_offset = 0; +-// break; +-// } +-// return (name_width_max - width_offset); +-//} +- + int DeviceInfoItem::NameTextCoordinate_Y_offset() + { + int show_coordinate_text_Y_offset = 0 ; +@@ -630,9 +620,32 @@ int DeviceInfoItem::NameTextCoordinate_Y_offset() + QString DeviceInfoItem::getDeviceName(QString devName) + { + QString showRealName; +- if(devName.length() > ShowNameTextNumberMax()) ++ int nCount = devName.count(); ++ qDebug() << Q_FUNC_INFO << "DevName Count:" << nCount << __LINE__; ++ ++ int zhCount = 0; ++ int charMCount = 0; ++ for(int i = 0; i < nCount; i++) ++ { ++ QChar ch = devName.at(i); ++ ushort uNum = ch.unicode(); ++ if(uNum >= 0x4E00 && uNum <= 0x9FA5) ++ { ++ // 这个字符是中文 ++ zhCount ++; ++ qDebug() << Q_FUNC_INFO << "this is zh:" << uNum << zhCount << __LINE__; ++ } ++ ++ if (uNum == 0x004D || uNum == 0x006D) ++ { ++ // 这个字符是m/M ++ charMCount++; ++ qDebug() << Q_FUNC_INFO << "this is char m/M:" << uNum << charMCount << __LINE__; ++ } ++ } ++ if(devName.length() > (ShowNameTextNumberMax() - zhCount - charMCount/2)) /*减去中文长度 或者 m字符显示长度*/ + { +- showRealName = devName.left(ShowNameTextNumberMax()-3); ++ showRealName = devName.left(ShowNameTextNumberMax()- zhCount - charMCount/2 - 3); + showRealName.append("..."); + toptipflag = true; + this->setToolTip(_MDev->getDevName()); +@@ -650,6 +663,7 @@ QString DeviceInfoItem::getDeviceName(QString devName) + + int DeviceInfoItem::ShowNameTextNumberMax() + { ++ + float display_coefficient = (this->width() - 300)/500.00; + qDebug() << Q_FUNC_INFO << "display coefficient:" << display_coefficient << __LINE__; + int max_text_number = 0; +@@ -761,15 +775,15 @@ void DeviceInfoItem::DrawFuncBtn(QPainter &painter) + pixmap = ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"default"); + } + +- painter.drawRoundRect(this->width()-55,14,36,36,30,30); ++ painter.drawRoundRect(this->width()-55,10,36,36,30,30); + + painter.setRenderHint(QPainter::SmoothPixmapTransform); + + + if (_themeIsBlack && (Status::Hover != _MStatus)) +- style()->drawItemPixmap(&painter, QRect(this->width()-48,23,20,20), Qt::AlignCenter, ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"blue")); ++ style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("image-loading-symbolic").pixmap(20),"blue")); + else +- style()->drawItemPixmap(&painter, QRect(this->width()-48,23,20,20), Qt::AlignCenter, pixmap); ++ style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, pixmap); + + painter.restore(); + } +diff --git a/ukcc-bluetooth/ukcc-bluetooth.pro b/ukcc-bluetooth/ukcc-bluetooth.pro +index 812dbb6..0544a80 100644 +--- a/ukcc-bluetooth/ukcc-bluetooth.pro ++++ b/ukcc-bluetooth/ukcc-bluetooth.pro +@@ -50,18 +50,30 @@ HEADERS += \ + loadinglabel.h \ + ukccbluetoothconfig.h + ++DISTFILES += ukcc-bluetooth.json ++ + TRANSLATIONS += \ +- ukcc-bluetooth_zh_CN.ts \ +- ukcc-bluetooth_bo_CN.ts ++ translations/ukcc-bluetooth_zh_CN.ts \ ++ translations/ukcc-bluetooth_bo_CN.ts + +-DISTFILES += ukcc-bluetooth.json ++system("lrelease translations/*.ts") + + # Default rules for deployment. + unix { + # target.path = $$[QT_INSTALL_PLUGINS]/generic + target.path = $$FILES_INSTALL_DIR + } +-!isEmpty(target.path): INSTALLS += target ++ ++qm_files.files += translations/*.qm ++qm_files.path += $${SHARE_TRANSLATIONS_INSTALL_DIR} ++ ++ts_files.files += translations/*.ts ++ts_files.path += $${SHARE_TRANSLATIONS_INSTALL_DIR} ++ ++INSTALLS += qm_files \ ++ ts_files \ ++ target + + RESOURCES += \ + ukcc-bluetooth.qrc ++ +diff --git a/ukcc-bluetooth/ukcc-bluetooth_bo_CN.qm b/ukcc-bluetooth/ukcc-bluetooth_bo_CN.qm +deleted file mode 100644 +index 07fe64c..0000000 +Binary files a/ukcc-bluetooth/ukcc-bluetooth_bo_CN.qm and /dev/null differ +diff --git a/ukcc-bluetooth/ukcc-bluetooth_bo_CN.ts b/ukcc-bluetooth/ukcc-bluetooth_bo_CN.ts +deleted file mode 100644 +index 5206f78..0000000 +--- a/ukcc-bluetooth/ukcc-bluetooth_bo_CN.ts ++++ /dev/null +@@ -1,240 +0,0 @@ +- +- +- +- +- BlueToothMain +- +- Show icon on taskbar +- འགན་བྱང་དུ་སོ་སྔོན་རིས་རྟགས་འཆར་བ། +- /bluetooth/Show icon on taskbar +- +- +- Discoverable by nearby Bluetooth devices +- ཉེ་འཁོར་གྱི་སོ་སྔོན་སྒྲིག་ཆས་ཀྱི་བཤེར་རུང་བ། +- /bluetooth/Discoverable +- +- +- My Devices +- སྒྲིག་ཆས། +- +- +- Bluetooth +- སོ་སྔོན། +- +- +- Other Devices +- སྒྲིག་ཆས་གཞན་དག +- /bluetooth/Other Devices +- +- +- Bluetooth adapter +- སོ་སྔོན་འཚམ་སྒྲིག་ཆས། +- +- +- Turn on +- སྒོ་འབྱེད། +- /bluetooth/Turn on Bluetooth +- +- +- All +- +- +- +- Audio +- དྲ་བྱང་། +- +- +- Peripherals +- +- +- +- PC +- +- +- +- Phone +- +- +- +- Other +- གཞན་དག +- +- +- No Bluetooth adapter detected! +- +- +- +- +- BlueToothMainWindow +- +- Bluetooth adapter is abnormal ! +- སོ་སྔོན་བཀོད་སྒྲིག་ཡོ་ཆས་རྒྱུན་ལྡན་མིན། +- +- +- Bluetooth adapter not detected ! +- +- +- +- Bluetooth +- སོ་སྔོན། +- +- +- Turn on : +- སྒོ་འབྱེད། +- +- +- Adapter List +- +- +- +- Show icon on taskbar +- འགན་བྱང་དུ་སོ་སྔོན་རིས་རྟགས་འཆར་བ། +- +- +- Discoverable by nearby Bluetooth devices +- ཉེ་འཁོར་གྱི་སོ་སྔོན་སྒྲིག་ཆས་ཀྱི་བཤེར་རུང་བ། +- +- +- My Devices +- སྒྲིག་ཆས། +- +- +- Other Devices +- སྒྲིག་ཆས་གཞན་དག +- +- +- All +- +- +- +- Audio +- དྲ་བྱང་། +- +- +- Peripherals +- +- +- +- PC +- +- +- +- Phone +- +- +- +- Other +- གཞན་དག +- +- +- +- Bluetooth +- +- Bluetooth +- སོ་སྔོན། +- +- +- +- BluetoothNameLabel +- +- Tip +- གསལ་འདེབས། +- +- +- Double-click to change the device name +- ཟུང་རྡེབ་བྱས་ཏེ་སྒྲིག་ཆས་ཀྱི་མིང་བཅོས་རོགས། +- +- +- The length of the device name does not exceed %1 characters ! +- སྒྲིག་ཆས་ཀྱི་མིང་གི་རིང་ཚད་ཡིག་རྟགས་ཀྱི %1 ལས་བརྒལ་མི་རུང་། +- +- +- Can now be found as "%1" +- "%1" ལ་མ་གཏོགས་གཟིགས་དབང་མི་འདུག +- +- +- +- DevRemoveDialog +- +- After it is removed, the PIN code must be matched for the next connection. +- +- +- +- Remove +- བསུབ་པ། +- +- +- Cancel +- མེད་པར་བཟོ་བ +- +- +- Are you sure to remove %1 ? +- +- +- +- +- DevRenameDialog +- +- Rename +- མིང་བསྐྱར་འདོགས། +- +- +- Name +- མིང་། +- +- +- The input character length exceeds the limit +- +- +- +- OK +- གཏན་འཁེལ་བྱེད་པ། +- +- +- Cancel +- མེད་པར་བཟོ་བ +- +- +- +- DeviceInfoItem +- +- Connecting +- +- +- +- Disconnecting +- +- +- +- Connected +- འབྲེལ་མཐུད་བྱས་ཟིན། +- +- +- Connect fail +- +- +- +- Disconnect fail +- +- +- +- send file +- +- +- +- remove +- +- +- +- Not Connected +- +- +- +- +- MainWidget +- +- +- མེད། +- +- +- +diff --git a/ukcc-bluetooth/ukcc-bluetooth_zh_CN.qm b/ukcc-bluetooth/ukcc-bluetooth_zh_CN.qm +deleted file mode 100644 +index a0272fd..0000000 +Binary files a/ukcc-bluetooth/ukcc-bluetooth_zh_CN.qm and /dev/null differ +diff --git a/ukcc-bluetooth/ukcc-bluetooth_zh_CN.ts b/ukcc-bluetooth/ukcc-bluetooth_zh_CN.ts +deleted file mode 100644 +index 1c9482c..0000000 +--- a/ukcc-bluetooth/ukcc-bluetooth_zh_CN.ts ++++ /dev/null +@@ -1,317 +0,0 @@ +- +- +- +- +- BlueToothMain +- +- +- Bluetooth +- 蓝牙 +- +- +- +- Turn on +- Turn on : +- 开启 +- /bluetooth/Turn on Bluetooth +- +- +- +- Bluetooth adapter +- 蓝牙适配器 +- +- +- +- Show icon on taskbar +- 在任务栏显示蓝牙图标 +- /bluetooth/Show icon on taskbar +- +- +- +- Discoverable by nearby Bluetooth devices +- 可被附近的蓝牙设备发现 +- /bluetooth/Discoverable +- +- +- +- My Devices +- 我的设备 +- +- +- +- Other Devices +- 其他设备 +- /bluetooth/Other Devices +- +- +- +- No Bluetooth adapter detected! +- 未检测到蓝牙适配器! +- +- +- +- All +- 所有 +- +- +- +- Audio +- 音频设备 +- +- +- +- Peripherals +- 键鼠设备 +- +- +- +- PC +- 电脑 +- +- +- +- Phone +- 手机 +- +- +- +- Other +- 其他 +- +- +- Bluetooth adapter is not detected! +- 未检测到蓝牙适配器! +- +- +- +- BlueToothMainWindow +- +- +- Bluetooth adapter is abnormal ! +- 蓝牙适配器异常! +- +- +- +- Bluetooth adapter not detected ! +- 未检测到蓝牙适配器! +- +- +- +- Bluetooth +- 蓝牙 +- +- +- +- Turn on : +- Turn on +- 开启 +- +- +- +- Adapter List +- 蓝牙适配器 +- +- +- +- Show icon on taskbar +- 在任务栏显示蓝牙图标 +- +- +- +- Discoverable by nearby Bluetooth devices +- 可被附近的蓝牙设备发现 +- +- +- +- My Devices +- 我的设备 +- +- +- +- Other Devices +- 蓝牙设备 +- +- +- +- All +- 所有 +- +- +- +- Audio +- 音频设备 +- +- +- +- Peripherals +- 键鼠设备 +- +- +- +- PC +- 电脑 +- +- +- +- Phone +- 手机 +- +- +- +- Other +- 其他 +- +- +- +- Bluetooth +- +- +- Bluetooth +- 蓝牙 +- +- +- +- BluetoothNameLabel +- +- +- Double-click to change the device name +- 双击修改设备名称 +- +- +- +- +- Can now be found as "%1" +- 现在可被发现为"%1" +- +- +- +- Tip +- 提示 +- +- +- +- The length of the device name does not exceed %1 characters ! +- 设备名称的长度不超过 %1 个字符! +- +- +- +- DevRemoveDialog +- +- +- After it is removed, the PIN code must be matched for the next connection. +- 移除后,下一次连接需匹配PIN码。 +- +- +- +- Remove +- 移除 +- +- +- +- Cancel +- 取消 +- +- +- +- Are you sure to remove %1 ? +- 确定移除"%1"? +- +- +- +- DevRenameDialog +- +- +- Rename +- 修改名称 +- +- +- +- Name +- 设备名称 +- +- +- +- The input character length exceeds the limit +- 输入字符长度超过限制! +- +- +- +- OK +- 确定 +- +- +- +- Cancel +- 取消 +- +- +- +- DeviceInfoItem +- +- +- Connecting +- 正在连接 +- +- +- +- Disconnecting +- 正在断连 +- +- +- +- Connected +- 已连接 +- +- +- +- Not Connected +- 未连接 +- +- +- Paired +- 已匹配 +- +- +- +- Connect fail +- 连接失败 +- +- +- +- Disconnect fail +- 断连失败 +- +- +- Send files +- 发送文件 +- +- +- Remove +- 移除 +- +- +- cancel +- 取消 +- +- +- +- +- remove +- 移除 +- +- +- +- +- send file +- 发送文件 +- +- +- Sure to remove, +- 确定删除, +- +- +- After removal, the next connection requires matching PIN code! +- 移除后,下一次连接需要匹配的PIN码! +- +- +- diff --git a/patches/ukcc_bluetooth_fix_widget_show_error.patch b/patches/ukcc_bluetooth_fix_widget_show_error.patch new file mode 100644 index 0000000..248f504 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_widget_show_error.patch @@ -0,0 +1,59 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 76e9197..fee7a54 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -2252,6 +2252,8 @@ void BlueToothMain::removeMDevFrameLineFrame(QString str) + + void BlueToothMain::cleanPairDevices() + { ++ qDebug() << Q_FUNC_INFO << "=============111111111" ; ++ + QLayoutItem *child; + while ((child = paired_dev_layout->takeAt(0)) != 0) + { +@@ -2261,9 +2263,22 @@ void BlueToothMain::cleanPairDevices() + child->widget()->setParent(NULL); + } + paired_dev_layout->removeItem(child); ++ ++ QFrame *line_item = frame_middle->findChild("line-"+child->widget()->objectName()); ++ if(line_item) { ++ paired_dev_layout->removeWidget(line_item); ++ line_item->setParent(NULL); ++ line_item->deleteLater(); ++ }else ++ removeMDevFrameLineFrame("paired"); ++ + delete child; + child = nullptr; ++ ++ + } ++ qDebug() << Q_FUNC_INFO << "=============22222222" ; ++ + while ((child = device_list_layout->takeAt(0)) != 0) + { + qDebug() << Q_FUNC_INFO << __LINE__; +@@ -2272,10 +2287,22 @@ void BlueToothMain::cleanPairDevices() + child->widget()->setParent(NULL); + } + device_list_layout->removeItem(child); ++ ++ QFrame *line_item = device_list->findChild("line-"+child->widget()->objectName()); ++ if(line_item) { ++ device_list_layout->removeWidget(line_item); ++ line_item->setParent(NULL); ++ line_item->deleteLater(); ++ } ++ + delete child; + child = nullptr; ++ ++ + } + device_list->setVisible(false); ++ qDebug() << Q_FUNC_INFO << "=============33333333" ; ++ + } + + void BlueToothMain::gSettingsChanged(const QString &key) diff --git a/patches/ukcc_bluetooth_fix_zh_show_error.patch b/patches/ukcc_bluetooth_fix_zh_show_error.patch new file mode 100644 index 0000000..de1cca6 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_zh_show_error.patch @@ -0,0 +1,180 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index c164364..d35474a 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -185,6 +185,13 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address()); + } ++ else ++ { ++ //蔡涛连接延时方案中增加未匹配的情况下,不发送设备连接改变信号,导致的设备匹配前已连接成功, ++ //匹配成功后,继续发起设备连接此时设备连接状态并没有改变,由于未接受到第一个设备连接信号,导致的控制面板显示未连接的情况 ++ //临时方案--pair成功后,手动发送连接成功信号 ++ emit devConnectStatusSignal(dev->address(),true); ++ } + + if (::isScan) { + Daemon::_DefualtAdapter.data()->startDiscovery(); +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 11334c1..8cfb347 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -224,8 +224,8 @@ BlueToothMain::~BlueToothMain() + + delete m_settings; + m_settings = nullptr; +- delete paired_device_list; +- paired_device_list = nullptr; ++ //delete paired_device_list; ++ //paired_device_list = nullptr; + delete device_list; + device_list = nullptr; + +@@ -1788,7 +1788,7 @@ void BlueToothMain::changeDeviceParentWindow(const QString &address) + + mDevFrameAddLineFrame("paired",address); + paired_dev_layout->addWidget(item); +- ++ m_myDev_show_flag = true; + }else{ + return; + } +@@ -1811,7 +1811,12 @@ void BlueToothMain::onClick_Open_Bluetooth(bool ischeck) + frame_middle->setVisible(ischeck); + else + frame_middle->setVisible(false); ++ + frame_bottom->setVisible(ischeck); ++ if(ischeck && loadLabel->isVisible()) ++ { ++ loadLabel->setVisible(false); ++ } + + if(ischeck) + { +@@ -1879,6 +1884,7 @@ void BlueToothMain::removeDeviceItemUI(QString address) + } + //m_discovery_device_address_all_list.removeAll(address); + //last_discovery_device_address.removeAll(address); ++ + } + //else + //{ +@@ -1904,11 +1910,22 @@ void BlueToothMain::removeDeviceItemUI(QString address) + } else + removeMDevFrameLineFrame("paired"); + +- qDebug() << Q_FUNC_INFO << "frame_middle->children().size()" << frame_middle->children().size(); +- if(frame_middle->children().size() == 2) +- { ++ qDebug() << Q_FUNC_INFO << "paired_dev_layout->count():" << paired_dev_layout->count() <<__LINE__; ++ if(!paired_dev_layout->count()){ ++ m_myDev_show_flag = false; + frame_middle->setVisible(false); + } ++ else ++ { ++ m_myDev_show_flag = true; ++ } ++ ++// qDebug() << Q_FUNC_INFO << " frame_middle->children().size() :"<children().size() <<__LINE__; ++ ++// if(frame_middle->children().size() == 3) ++// { ++// frame_middle->setVisible(false); ++// } + } + else + { +diff --git a/ukcc-bluetooth/bluetoothmain.h b/ukcc-bluetooth/bluetoothmain.h +index 32de960..fab7bff 100644 +--- a/ukcc-bluetooth/bluetoothmain.h ++++ b/ukcc-bluetooth/bluetoothmain.h +@@ -105,7 +105,7 @@ private slots: + void adapterComboxChanged(int i); + + private: +- QStackedWidget *_MCentralWidget = nullptr; ++ QStackedWidget * _MCentralWidget = nullptr; + + QWidget * frame_top = nullptr; + QWidget * frame_middle = nullptr; +@@ -119,7 +119,7 @@ private: + QFrame * mDev_frame = nullptr; + + QFrame * device_list = nullptr; +- QWidget * paired_device_list = nullptr; ++ //QWidget * paired_device_list = nullptr; + QVBoxLayout * device_list_layout = nullptr; + BluetoothNameLabel * bluetooth_name = nullptr; + +@@ -130,7 +130,7 @@ private: + QLabel * label_2 = nullptr; + QLabel * loadLabel = nullptr; + +- QString Default_Adapter; ++ //QString Default_Adapter; + QGSettings * m_settings = nullptr; + QGSettings * styleSettings = nullptr; + +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 3ff0aed..5a94e9b 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -281,9 +281,9 @@ QRect DeviceInfoItem::getStatusTextRect(QRect rect) + QRect DeviceInfoItem::getLoadIconRect() + { + if (_MDev &&_MDev->isPaired()) { +- return QRect(this->width()-98,23,20,20); ++ return QRect(this->width()-98,19,20,20); + } else { +- return QRect(this->width()-35,23,20,20); ++ return QRect(this->width()-35,19,20,20); + } + } + +@@ -621,7 +621,7 @@ QString DeviceInfoItem::getDeviceName(QString devName) + { + QString showRealName; + int nCount = devName.count(); +- qDebug() << Q_FUNC_INFO << "DevName Count:" << nCount << __LINE__; ++ //qDebug() << Q_FUNC_INFO << "DevName Count:" << nCount << __LINE__; + + int zhCount = 0; + int charMCount = 0; +@@ -633,14 +633,14 @@ QString DeviceInfoItem::getDeviceName(QString devName) + { + // 这个字符是中文 + zhCount ++; +- qDebug() << Q_FUNC_INFO << "this is zh:" << uNum << zhCount << __LINE__; ++ //qDebug() << Q_FUNC_INFO << "this is zh:" << uNum << zhCount << __LINE__; + } + + if (uNum == 0x004D || uNum == 0x006D) + { + // 这个字符是m/M + charMCount++; +- qDebug() << Q_FUNC_INFO << "this is char m/M:" << uNum << charMCount << __LINE__; ++ //qDebug() << Q_FUNC_INFO << "this is char m/M:" << uNum << charMCount << __LINE__; + } + } + if(devName.length() > (ShowNameTextNumberMax() - zhCount - charMCount/2)) /*减去中文长度 或者 m字符显示长度*/ +diff --git a/ukcc-bluetooth/devremovedialog.cpp b/ukcc-bluetooth/devremovedialog.cpp +index 24efaf4..d9e3041 100644 +--- a/ukcc-bluetooth/devremovedialog.cpp ++++ b/ukcc-bluetooth/devremovedialog.cpp +@@ -2,12 +2,12 @@ + + DevRemoveDialog::DevRemoveDialog(QWidget *parent):QDialog(parent) + { ++ initGsettings(); + this->setFixedSize(380,180); + this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + this->setAttribute(Qt::WA_TranslucentBackground); + + initUI(); +- initGsettings(); + } + + DevRemoveDialog::~DevRemoveDialog() diff --git a/patches/ukcc_bluetooth_fix_zoom_device_name_show_error.patch b/patches/ukcc_bluetooth_fix_zoom_device_name_show_error.patch new file mode 100644 index 0000000..6da34e8 --- /dev/null +++ b/patches/ukcc_bluetooth_fix_zoom_device_name_show_error.patch @@ -0,0 +1,262 @@ +diff --git a/ukcc-bluetooth/config.h b/ukcc-bluetooth/config.h +index 623c493..1a88f9a 100644 +--- a/ukcc-bluetooth/config.h ++++ b/ukcc-bluetooth/config.h +@@ -12,6 +12,12 @@ + #define SYSTEMFONTSIZE "systemFontSize" + #define SYSTEMFONT "systemFont" + ++#define MAX_DEVICE_CONECTIONS_TIMES 3 ++ ++#define DELAYED_SCANNING_TIME_S (2*1000) ++#define DEVICE_CONNECTION_TIMEOUT_S (30*1000) ++#define LOADING_ICON_TIMEOUT_INTERVAL_MS 110 ++ + const QString SERVICE = "com.ukui.bluetooth"; + const QString PATH = "/com/ukui/bluetooth"; + const QString INTERFACE = "com.ukui.bluetooth"; +diff --git a/ukcc-bluetooth/devicebase.cpp b/ukcc-bluetooth/devicebase.cpp +index 7a953d7..05a3a66 100644 +--- a/ukcc-bluetooth/devicebase.cpp ++++ b/ukcc-bluetooth/devicebase.cpp +@@ -99,6 +99,7 @@ bluetoothdevice::bluetoothdevice(QString dev_name , + ,m_dev_trust(dev_trust) + { + this->setObjectName(dev_address); ++ clearErrorInfo(); + //qDebug() << Q_FUNC_INFO << __LINE__; + // if (DEVICE_STATUS::PairedAndUnlinked == dev_status || + // DEVICE_STATUS::PairedAndLinked == dev_status ) +@@ -151,16 +152,16 @@ bluetoothdevice::DEVICE_TYPE bluetoothdevice::getDevType() + return this->m_dev_type; + + } +-void bluetoothdevice::setDevStatus(DEVICE_STATUS status) +-{ +- //qDebug() << Q_FUNC_INFO << __LINE__; ++//void bluetoothdevice::setDevStatus(DEVICE_STATUS status) ++//{ ++// //qDebug() << Q_FUNC_INFO << __LINE__; + +-} +-bluetoothdevice::DEVICE_STATUS bluetoothdevice::getDevStatus() +-{ +- //qDebug() << Q_FUNC_INFO << __LINE__; ++//} ++//bluetoothdevice::DEVICE_STATUS bluetoothdevice::getDevStatus() ++//{ ++// //qDebug() << Q_FUNC_INFO << __LINE__; + +-} ++//} + + void bluetoothdevice::setDevTrust(bool value) + { +@@ -205,5 +206,11 @@ void bluetoothdevice::setErrorInfo(int errorId,QString errorText) + emit errorInfoRefresh(errorId,errorText); + } + ++void bluetoothdevice::clearErrorInfo() ++{ ++ this->m_errorId = 0; ++ this->m_errorText = ""; ++} ++ + //bluetoothdevice end + +diff --git a/ukcc-bluetooth/devicebase.h b/ukcc-bluetooth/devicebase.h +index e567b61..543281f 100644 +--- a/ukcc-bluetooth/devicebase.h ++++ b/ukcc-bluetooth/devicebase.h +@@ -119,15 +119,69 @@ public: + Q_ENUM(DEVICE_TYPE) + + +- enum DEVICE_STATUS{ +- Unkown = 0, +- UnpairAndUnlinked, // +- UnpairAndLinked, +- PairedAndUnlinked, +- PairedAndLinked, +- Error ++// enum DEVICE_STATUS{ ++// Unkown = 0, ++// UnpairAndUnlinked, // ++// UnpairAndLinked, ++// PairedAndUnlinked, ++// PairedAndLinked, ++// Error ++// }; ++// Q_ENUM(DEVICE_STATUS) ++ ++ enum Error { ++ /** Indicates there is no error. */ ++ NoError = 0, ++ /** Indicates that the device is not ready. */ ++ NotReady = 1, ++ /** Indicates that the action have failed. */ ++ Failed = 2, ++ /** Indicates that the action was rejected. */ ++ Rejected = 3, ++ /** Indicates that the action was canceled. */ ++ Canceled = 4, ++ /** Indicates that invalid arguments were passed. */ ++ InvalidArguments = 5, ++ /** Indicates that an agent or pairing record already exists. */ ++ AlreadyExists = 6, ++ /** Indicates that an agent, service or pairing operation does not exists. */ ++ DoesNotExist = 7, ++ /** Indicates that the action is already in progress. */ ++ InProgress = 8, ++ /** Indicates that the action is not in progress. */ ++ NotInProgress = 9, ++ /** Indicates that the device is already connected. */ ++ AlreadyConnected = 10, ++ /** Indicates that the connection to the device have failed. */ ++ ConnectFailed = 11, ++ /** Indicates that the device is not connected. */ ++ NotConnected = 12, ++ /** Indicates that the action is not supported. */ ++ NotSupported = 13, ++ /** Indicates that the caller is not authorized to do the action. */ ++ NotAuthorized = 14, ++ /** Indicates that the authentication was canceled. */ ++ AuthenticationCanceled = 15, ++ /** Indicates that the authentication have failed. */ ++ AuthenticationFailed = 16, ++ /** Indicates that the authentication was rejected. */ ++ AuthenticationRejected = 17, ++ /** Indicates that the authentication timed out. */ ++ AuthenticationTimeout = 18, ++ /** Indicates that the connection attempt have failed. */ ++ ConnectionAttemptFailed = 19, ++ /** Indicates that the data provided generates a data packet which is too long. */ ++ InvalidLength = 20, ++ /** Indicates that the action is not permitted (e.g. maximum reached or socket locked). */ ++ NotPermitted = 21, ++ /** Indicates an error with D-Bus. */ ++ DBusError = 98, ++ /** Indicates an internal error. */ ++ InternalError = 99, ++ /** Indicates an unknown error. */ ++ UnknownError = 100 + }; +- Q_ENUM(DEVICE_STATUS) ++ Q_ENUM(Error) + + bluetoothdevice(QString device_name , + QString device_address , +@@ -144,8 +198,8 @@ public: + + void setDevType(DEVICE_TYPE); + DEVICE_TYPE getDevType(); +- void setDevStatus(DEVICE_STATUS); +- DEVICE_STATUS getDevStatus(); ++ //void setDevStatus(DEVICE_STATUS); ++ //DEVICE_STATUS getDevStatus(); + + bool isPaired(); + void devPairedChanged(bool); +@@ -155,6 +209,7 @@ public: + void setDevTrust(bool); + bool getDevTrust(); + void setErrorInfo(int,QString); ++ void clearErrorInfo(); + + signals: + +@@ -170,7 +225,7 @@ private: + QString m_dev_name; + QString m_dev_address; + DEVICE_TYPE m_dev_type; +- DEVICE_STATUS m_dev_status; ++ //DEVICE_STATUS m_dev_status; + bool m_dev_trust ; + bool m_dev_isPaired; + bool m_dev_isConnected; +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 5285a02..bbd50e8 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -140,19 +140,23 @@ void DeviceInfoItem::MenuSignalDeviceFunction(QAction *action) + } + else if(action->text() == tr("remove")) + { +- DevRemoveDialog *mesgBox = new DevRemoveDialog(); +- mesgBox->setModal(true); +- mesgBox->setDialogText(_MDev->getDevName()); +- +- connect(mesgBox,&DevRemoveDialog::accepted,this,[=]{ +- qDebug() << Q_FUNC_INFO << "To :" << _MDev->getDevName() << "Remove" << __LINE__; +- emit devRemove(_MDev->getDevAddress()); +- }); +- +- mesgBox->exec(); ++ showDeviceRemoveWidget(); + } + } + ++void DeviceInfoItem::showDeviceRemoveWidget() ++{ ++ DevRemoveDialog *mesgBox = new DevRemoveDialog(); ++ mesgBox->setModal(true); ++ mesgBox->setDialogText(_MDev->getDevName()); ++ ++ connect(mesgBox,&DevRemoveDialog::accepted,this,[=]{ ++ qDebug() << Q_FUNC_INFO << "To :" << _MDev->getDevName() << "Remove" << __LINE__; ++ emit devRemove(_MDev->getDevAddress()); ++ }); ++ ++ mesgBox->exec(); ++} + + void DeviceInfoItem::setDeviceCurrentStatus() + { +@@ -700,7 +704,7 @@ QString DeviceInfoItem::getDeviceName(QString devName) + + int DeviceInfoItem::ShowNameTextNumberMax() + { +- float display_coefficient = (this->width() - 350)/500.00; ++ float display_coefficient = (this->width() - 350)/450.00; + //qDebug() << Q_FUNC_INFO << "display coefficient:" << display_coefficient << __LINE__; + int max_text_number = 0; + switch (_fontSize) +@@ -717,14 +721,14 @@ int DeviceInfoItem::ShowNameTextNumberMax() + max_text_number += 2 ; + case 15: + default: +- max_text_number += 45 ; ++ max_text_number += 35 ; + break; + } + + int showMaxNameLength = max_text_number*display_coefficient; + //qDebug() << Q_FUNC_INFO << "The max length :" << showMaxNameLength << __LINE__; + +- return (45 > showMaxNameLength?45: showMaxNameLength); ++ return (showMaxNameLength); + + } + +@@ -858,6 +862,8 @@ void DeviceInfoItem::MouseClickedFunc() + _pressFlag = false; + + if (_MDev) { ++ //清理错误信息 ++ _MDev->clearErrorInfo(); + if (_MDev->isConnected()) { + //_MDev->disconnectFromDevice(); + emit devDisconnect(_MDev->getDevAddress()); +diff --git a/ukcc-bluetooth/deviceinfoitem.h b/ukcc-bluetooth/deviceinfoitem.h +index f69a89f..c9a7148 100644 +--- a/ukcc-bluetooth/deviceinfoitem.h ++++ b/ukcc-bluetooth/deviceinfoitem.h +@@ -100,6 +100,8 @@ private: + int ShowNameTextNumberMax(); + int NameTextCoordinate_Y_offset(); + void TimedRestoreConnectionErrorDisplay(); ++ void showDeviceRemoveWidget(); ++ + + bool toptipflag = false; + int iconFlag = 7; diff --git a/patches/ukcc_bluetooth_fixbug105541.patch b/patches/ukcc_bluetooth_fixbug105541.patch new file mode 100644 index 0000000..4d696e4 --- /dev/null +++ b/patches/ukcc_bluetooth_fixbug105541.patch @@ -0,0 +1,28 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 8800a08..76e9197 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -799,6 +799,7 @@ void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) + { + m_device_operating = false; + m_device_operating_address.clear(); ++ cacheDevTypeList->setEnabled(true); + }); + m_myDev_show_flag = true; + +@@ -884,6 +885,7 @@ void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) + { + m_device_operating = false; + m_device_operating_address.clear(); ++ cacheDevTypeList->setEnabled(true); + // if (delayStartDiscover_timer->isActive()) + // delayStartDiscover_timer->stop(); + // delayStartDiscover_timer->start(); +@@ -1310,6 +1312,7 @@ void BlueToothMain::receiveConnectsignal(QString address) + { + //停止扫描,连接完成或连接超时后继续开启扫描 + //setDefaultAdapterScanOn(false); ++ cacheDevTypeList->setEnabled(false); + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, diff --git a/patches/ukcc_bluetooth_fixbug105687.patch b/patches/ukcc_bluetooth_fixbug105687.patch new file mode 100644 index 0000000..7a03905 --- /dev/null +++ b/patches/ukcc_bluetooth_fixbug105687.patch @@ -0,0 +1,142 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 725d8fa..912053d 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -662,6 +662,7 @@ void BlueToothMain::reportReplyRequestConfirmation(bool userCheck) + qDebug() << Q_FUNC_INFO << "User check:" << userCheck << __LINE__; + m_device_pin_flag = false; + } ++ + void BlueToothMain::reportDevOperateErrorSignal(QString deviceAddress , int ErrorId , QString ErrorText) + { + qDebug() << Q_FUNC_INFO << deviceAddress << ErrorId << ErrorText << __LINE__; +@@ -1933,74 +1934,55 @@ void BlueToothMain::refreshLoadLabelIcon() + void BlueToothMain::removeDeviceItemUI(QString address) + { + qDebug() << Q_FUNC_INFO << address << __LINE__; +- //qDebug() << Q_FUNC_INFO << address << last_discovery_device_address.indexOf(address) <<__LINE__; + +- //if(last_discovery_device_address.indexOf(address) != -1) +- //{ +- DeviceInfoItem *item = device_list->findChild(address); +- QFrame *line_item = device_list->findChild("line-"+address); +- if(item) +- { +- device_list_layout->removeWidget(item); +- item->setParent(NULL); +- item->deleteLater(); +- +- if(line_item) { +- device_list_layout->removeWidget(line_item); +- line_item->setParent(NULL); +- line_item->deleteLater(); +- } +- //m_discovery_device_address_all_list.removeAll(address); +- //last_discovery_device_address.removeAll(address); ++ //移除蓝牙设备列表的设备 ++ DeviceInfoItem *item = device_list->findChild(address); ++ QFrame *line_item = device_list->findChild("line-"+address); ++ if(item) ++ { ++ device_list_layout->removeWidget(item); ++ item->setParent(NULL); ++ item->deleteLater(); + ++ if(line_item) { ++ device_list_layout->removeWidget(line_item); ++ line_item->setParent(NULL); ++ line_item->deleteLater(); + } +- //else +- //{ +- // qDebug() << Q_FUNC_INFO << "NULL"<<__LINE__; +- // return; +- //} +- +- //}else{ +- //DeviceInfoItem *item = frame_middle->findChild(address); +- item = frame_middle->findChild(address); +- line_item = frame_middle->findChild("line-"+address); +- if(item){ +- +- +- paired_dev_layout->removeWidget(item); +- item->setParent(NULL); +- item->deleteLater(); +- +- if (line_item) { +- paired_dev_layout->removeWidget(line_item); +- line_item->setParent(NULL); +- line_item->deleteLater(); +- } else +- removeMDevFrameLineFrame("paired"); +- +- qDebug() << Q_FUNC_INFO << "paired_dev_layout->count():" << paired_dev_layout->count() <<__LINE__; +- if(!paired_dev_layout->count()){ +- m_myDev_show_flag = false; +- frame_middle->setVisible(false); +- } +- else +- { +- m_myDev_show_flag = true; +- } ++ } + +-// qDebug() << Q_FUNC_INFO << " frame_middle->children().size() :"<children().size() <<__LINE__; ++ //移除已配对设备列表的设备 ++ item = frame_middle->findChild(address); ++ line_item = frame_middle->findChild("line-"+address); ++ if(item) ++ { ++ paired_dev_layout->removeWidget(item); ++ item->setParent(NULL); ++ item->deleteLater(); ++ ++ if (line_item) { ++ paired_dev_layout->removeWidget(line_item); ++ line_item->setParent(NULL); ++ line_item->deleteLater(); ++ } else ++ removeMDevFrameLineFrame("paired"); + +-// if(frame_middle->children().size() == 3) +-// { +-// frame_middle->setVisible(false); +-// } ++ qDebug() << Q_FUNC_INFO << "paired_dev_layout->count():" << paired_dev_layout->count() <<__LINE__; ++ if(!paired_dev_layout->count()){ ++ m_myDev_show_flag = false; ++ frame_middle->setVisible(false); + } + else + { +- qDebug() << Q_FUNC_INFO << "NULL"<<__LINE__; +- return; ++ m_myDev_show_flag = true; + } +- //} ++ } ++ else ++ { ++ qDebug() << Q_FUNC_INFO << "NULL"<<__LINE__; ++ return; ++ } ++ + qDebug() << Q_FUNC_INFO << "remove Item UI end" <<__LINE__; + + } +@@ -2020,6 +2002,14 @@ void BlueToothMain::changeListOfDiscoveredDevices(int index) + { + child->widget()->setParent(NULL); + } ++ ++ QFrame *line_item = device_list->findChild("line-"+child->widget()->objectName()); ++ if(line_item) { ++ device_list_layout->removeWidget(line_item); ++ line_item->setParent(NULL); ++ line_item->deleteLater(); ++ } ++ + delete child; + child = nullptr; + } diff --git a/patches/ukcc_bluetooth_huawei_disconnect.patch b/patches/ukcc_bluetooth_huawei_disconnect.patch new file mode 100644 index 0000000..eb4c764 --- /dev/null +++ b/patches/ukcc_bluetooth_huawei_disconnect.patch @@ -0,0 +1,140 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 46df2f9..7bc3cca 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -145,6 +145,11 @@ void DeviceInfoItem::MenuSignalDeviceFunction(QAction *action) + { + showDeviceRemoveWidget(); + } ++ else if(action->text() == tr("disconnect")) ++ { ++ qDebug() << Q_FUNC_INFO << "To :" << _MDev->getDevName() << "disconnect" << __LINE__; ++ emit devDisconnect(_MDev->getDevAddress()); ++ } + } + + bool DeviceInfoItem::isDisplayPINCodeWidget() +@@ -383,8 +388,50 @@ void DeviceInfoItem::leaveEvent(QEvent *event) + update(); + } + ++void DeviceInfoItem::mouseReleaseEvent(QMouseEvent *event) ++{ ++ long long _releaseCurrentTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); ++ qDebug() << Q_FUNC_INFO << "_releaseCurrentTime" << _releaseCurrentTime << "_pressCurrentTime:" << _pressCurrentTime; ++ if((_releaseCurrentTime - _pressCurrentTime) >= 200) ++ { ++ qDebug() << Q_FUNC_INFO << "press to release time too long!!!!!!!"; ++ _pressBtnFlag = false; ++ ++ _pressFlag = false; ++ _MStatus = Status::Hover; ++ return; ++ } ++ ++ if (event->button() == Qt::LeftButton) { ++ qDebug() << Q_FUNC_INFO << mouseEventIntargetAera(event->pos()); ++ if (mouseEventIntargetAera(event->pos()) && _pressBtnFlag && !BlueToothMain::m_device_operating) { ++ MouseClickedDevFunc(); ++ _pressBtnFlag = false; ++ } else { ++ //华为机器主界面无单击断开操作 ++ if (global_ishuawei && _MDev->isConnected()) ++ { ++ return; ++ } ++ if (!BlueToothMain::m_device_operating) ++ { ++ BlueToothMain::m_device_operating = true; ++ MouseClickedFunc(); ++ _pressFlag = false; ++ _MStatus = Status::Hover; ++ } ++ } ++ } ++ update(); ++ ++} ++ + void DeviceInfoItem::mousePressEvent(QMouseEvent *event) + { ++ //获取当前时间 ++ _pressCurrentTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); ++ qDebug() << Q_FUNC_INFO << _pressCurrentTime; ++ + if (event->button() == Qt::LeftButton) { + if (mouseEventIntargetAera(event->pos())) { + _pressBtnFlag = true; +@@ -435,6 +482,15 @@ void DeviceInfoItem::MouseClickedDevFunc() + if (bluetoothdevice::DEVICE_TYPE::phone == _MDev->getDevType() || + bluetoothdevice::DEVICE_TYPE::computer == _MDev->getDevType()) + { ++ //华为机器增加断开按键 ++ if (global_ishuawei && _MDev->isConnected()) ++ { ++ QAction *disconnect = new QAction(dev_Menu); ++ disconnect->setText(tr("disconnect")); ++ dev_Menu->addAction(disconnect); ++ dev_Menu->addSeparator(); ++ } ++ + //非华为机器才存在文件传输功能 + if(!global_ishuawei) + { +@@ -443,6 +499,7 @@ void DeviceInfoItem::MouseClickedDevFunc() + dev_Menu->addAction(sendfile); + dev_Menu->addSeparator(); + } ++ + } + + QAction *remove = new QAction(dev_Menu); +@@ -455,27 +512,6 @@ void DeviceInfoItem::MouseClickedDevFunc() + + } + +-void DeviceInfoItem::mouseReleaseEvent(QMouseEvent *event) +-{ +- if (event->button() == Qt::LeftButton) { +- qDebug() << Q_FUNC_INFO << mouseEventIntargetAera(event->pos()); +- if (mouseEventIntargetAera(event->pos()) && _pressBtnFlag) { +- MouseClickedDevFunc(); +- _pressBtnFlag = false; +- } else { +- if (!BlueToothMain::m_device_operating) +- { +- BlueToothMain::m_device_operating = true; +- MouseClickedFunc(); +- _pressFlag = false; +- _MStatus = Status::Hover; +- } +- } +- } +- update(); +- +-} +- + void DeviceInfoItem::mouseMoveEvent(QMouseEvent *event) + { + if (mouseEventIntargetAera(event->pos())) { +diff --git a/ukcc-bluetooth/deviceinfoitem.h b/ukcc-bluetooth/deviceinfoitem.h +index fdb128a..e453611 100644 +--- a/ukcc-bluetooth/deviceinfoitem.h ++++ b/ukcc-bluetooth/deviceinfoitem.h +@@ -10,6 +10,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -120,7 +121,7 @@ private: + bool _removeDevFlag ; + bool _pressBtnFlag = false; + bool _themeIsBlack = false; +- ++ long long _pressCurrentTime; + + QMenu *dev_Menu = nullptr; + diff --git a/patches/ukcc_bluetooth_more_adapter.patch b/patches/ukcc_bluetooth_more_adapter.patch new file mode 100644 index 0000000..4f67d66 --- /dev/null +++ b/patches/ukcc_bluetooth_more_adapter.patch @@ -0,0 +1,621 @@ +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -174,22 +174,10 @@ void rfkill_exit(void) + watch = 0; + } + +-const QString SERVICE = "com.ukui.bluetooth"; +-const QString PATH = "/com/ukui/bluetooth"; +-const QString INTERFACE = "com.ukui.bluetooth"; +- + //dev-3.1 界面服务-分离 + BlueToothMain::BlueToothMain(QWidget *parent) + : QMainWindow(parent) + { +- //qDebug() << Q_FUNC_INFO ; +- //rfkill_init(); +- +-// QTranslator translator = new QTranslator(); +-// translator.load("/usr/share/ukui-bluetooth/translations/ukcc-bluetooth_" + QLocale::system().name() + ".qm"); +-// QApplication::installTranslator(&translator); +- +- + if(QGSettings::isSchemaInstalled("org.ukui.bluetooth")) + { + m_settings = new QGSettings("org.ukui.bluetooth"); +@@ -197,55 +185,48 @@ BlueToothMain::BlueToothMain(QWidget *pa + + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + styleSettings = new QGSettings("org.ukui.style"); +- + if(styleSettings->get("style-name").toString() == "ukui-black" || + styleSettings->get("style-name").toString() == "ukui-dark") + isblack = true; + else + isblack = false; +- + connect(styleSettings,&QGSettings::changed,this,&BlueToothMain::gSettingsChanged); +- + } + +- //手动发起蓝牙服务连接 +- //connectBluetoothServiceSignal(); +- + getAllAdapterData(); + ++ _MCentralWidget = new QStackedWidget(this); ++ this->setCentralWidget(_MCentralWidget); ++ showBluetoothNormalMainWindow(); ++ showBluetoothErrorMainWindow(); ++ + qDebug() << "adapter (addresss/name) size:" << m_adapter_address_list.size() << m_adapter_name_list.size(); +-// if (spe_bt_node && spe_bt_node_blk) +-// { +-// showBluetoothNormalMainWindow(); +-// bluetooth_name->setVisible(false); +-// frame_middle->setVisible(false); +-// frame_bottom->setVisible(false); +-// } +-// else +-// { +-// if ((m_default_bluetooth_adapter != nullptr) || +-// (m_adapter_address_list.size() > 0 && m_adapter_name_list.size() == m_adapter_address_list.size())) +- if (m_adapter_address_list.size() > 0 && m_adapter_name_list.size() == m_adapter_address_list.size()) +- showBluetoothNormalMainWindow(); +- else +- showBluetoothErrorMainWindow(); +-// } + ++ if (m_adapter_address_list.size() > 0 && m_adapter_name_list.size() == m_adapter_address_list.size()) ++ { ++ _MCentralWidget->setCurrentWidget(m_normal_main_widget); ++ refreshUIWhenAdapterChanged(); ++ } ++ else ++ { ++ _MCentralWidget->setCurrentWidget(m_error_main_widget); ++ } + monitorBluetoothDbusConnection(); +- monitorSleepSignal(); +- return ; + } + + BlueToothMain::~BlueToothMain() + { +- rfkill_exit(); ++ //rfkill_exit(); + setDefaultAdapterScanOn(false); + clearAllUnPairedDevicelist(); + + delete m_settings; + m_settings = nullptr; ++ delete paired_device_list; ++ paired_device_list = nullptr; + delete device_list; + device_list = nullptr; ++ + } + + void BlueToothMain::leaveEvent(QEvent *event) +@@ -361,7 +342,6 @@ void BlueToothMain::reportDefaultDiscove + qDebug () << Q_FUNC_INFO << discoverable << __LINE__; + m_current_adapter_disconvery_swtich = discoverable; + m_discover_switch_btn->setChecked(discoverable); +- + } + + void BlueToothMain::reportDefaultScanStatusChanged(bool isScan) +@@ -437,10 +417,10 @@ void BlueToothMain::refreshBluetoothAdap + if(1 == m_adapter_address_list.size())// || + //(m_adapter_address_list.size() > 0 && m_adapter_address_list.size() != m_adapter_name_list.size())) + { +- m_default_bluetooth_adapter = m_bluetooth_adapter_list.at(0); +- if("normalWidget" != this->centralWidget()->objectName()) ++ //m_default_bluetooth_adapter = m_bluetooth_adapter_list.at(0); ++ if("normalWidget" != _MCentralWidget->currentWidget()->objectName()) + { +- showBluetoothNormalMainWindow(); ++ _MCentralWidget->setCurrentWidget(m_normal_main_widget); + } + if(frame_2->isVisible()) + frame_2->setVisible(false); +@@ -449,9 +429,9 @@ void BlueToothMain::refreshBluetoothAdap + } + else if (m_adapter_address_list.size() > 1) + { +- if("normalWidget" != this->centralWidget()->objectName()) ++ if("normalWidget" != _MCentralWidget->currentWidget()->objectName()) + { +- showBluetoothNormalMainWindow(); ++ _MCentralWidget->setCurrentWidget(m_normal_main_widget); + } + if(!frame_2->isVisible()) + frame_2->setVisible(true); +@@ -460,15 +440,25 @@ void BlueToothMain::refreshBluetoothAdap + } + else + { +- if("errorWidget" != this->centralWidget()->objectName()) ++ if("errorWidget" != _MCentralWidget->currentWidget()->objectName()) + { +- showBluetoothErrorMainWindow(); ++ _MCentralWidget->setCurrentWidget(m_error_main_widget); + } + } + +- //refreshUIWhenAdapterChanged(); ++ refreshUIWhenAdapterChanged(); + } + ++//void BlueToothMain::addBluetoothAdapterComboBox(QString adapterName) ++//{ ++ ++//} ++ ++//void BlueToothMain::removeBluetoothAdapterComboBox(int index) ++//{ ++ ++//} ++ + void BlueToothMain::addAdapterDataList(QString adapterAddress) + { + qDebug () << Q_FUNC_INFO << adapterAddress << __LINE__; +@@ -486,8 +476,9 @@ void BlueToothMain::addAdapterDataList(Q + { + m_adapter_address_list << adapterAddress; + m_adapter_name_list << getAdapterName(adapterAddress); +- //if(m_adapter_list_cmbox) +- // m_adapter_list_cmbox->insertItem(m_adapter_name_list.size()-1,m_adapter_name_list.last()); ++ ++ if(m_adapter_list_cmbox) ++ m_adapter_list_cmbox->addItem(m_adapter_name_list.last()); + } + qDebug () << Q_FUNC_INFO << m_adapter_address_list << m_adapter_name_list << __LINE__; + +@@ -511,13 +502,18 @@ void BlueToothMain::removeAdapterDataLis + + if (m_adapter_address_list.size()) + { +- m_adapter_list_cmbox->removeItem(i); ++ if(m_adapter_list_cmbox != nullptr) ++ m_adapter_list_cmbox->removeItem(i); + } + + } + void BlueToothMain::reportAdapterAddSignal(QString adapterAddress) + { + qDebug () << Q_FUNC_INFO << adapterAddress << __LINE__; ++ if("normalWidget" != this->centralWidget()->objectName()) ++ { ++ _MCentralWidget->setCurrentWidget(m_normal_main_widget); ++ } + + addAdapterDataList(adapterAddress); + refreshBluetoothAdapterInterfaceUI(); +@@ -533,49 +529,57 @@ void BlueToothMain::reportAdapterRemoveS + void BlueToothMain::reportDefaultAdapterPowerChanged(bool isPower) + { + qDebug () << Q_FUNC_INFO << isPower << __LINE__; +- if ("normalWidget" != this->centralWidget()->objectName()) ++ if("normalWidget" != _MCentralWidget->currentWidget()->objectName()) + { + qDebug () << Q_FUNC_INFO << "is not normalWidget" << __LINE__; + return; + } ++ + m_current_adapter_power_swtich = isPower; +- if(m_settings) +- m_settings->set("switch",QVariant::fromValue(isPower)); + +- if(isPower) +- { +- bluetooth_name->set_dev_name(m_default_adapter_name); +- bluetooth_name->setVisible(true); +- frame_bottom->setVisible(true); ++ if (isPower && !m_open_bluetooth_btn->isChecked()) ++ m_open_bluetooth_btn->setChecked(true); + +- frame_middle->setVisible(m_myDev_show_flag); ++ if (!isPower && m_open_bluetooth_btn->isChecked()) ++ m_open_bluetooth_btn->setChecked(false); + +- if (!m_open_bluetooth_btn->isChecked()) +- m_open_bluetooth_btn->setChecked(true); ++// if(m_settings) ++// m_settings->set("switch",QVariant::fromValue(isPower)); + +- delayStartDiscover_timer->start(); ++// if(isPower) ++// { ++// bluetooth_name->set_dev_name(m_default_adapter_name); ++// bluetooth_name->setVisible(true); ++// frame_bottom->setVisible(true); + +- this->refreshBluetoothAdapterInterfaceUI(); +- } +- else +- { +-// if (bluetooth_name->isVisible()) +-// bluetooth_name->setVisible(false); ++// frame_middle->setVisible(m_myDev_show_flag); + +- if (m_open_bluetooth_btn->isChecked()) +- m_open_bluetooth_btn->setChecked(false); ++// if (!m_open_bluetooth_btn->isChecked()) ++// m_open_bluetooth_btn->setChecked(true); + +- if (frame_bottom->isVisible()) +- frame_bottom->setVisible(false); ++// delayStartDiscover_timer->start(); + +- if(frame_middle->isVisible()) +- frame_middle->setVisible(false); ++// //this->refreshBluetoothAdapterInterfaceUI(); ++// } ++// else ++// { ++//// if (bluetooth_name->isVisible()) ++//// bluetooth_name->setVisible(false); + +- if (!paired_dev_layout->isEmpty()) +- m_myDev_show_flag = true ; +- else +- m_myDev_show_flag = false ; +- } ++// if (m_open_bluetooth_btn->isChecked()) ++// m_open_bluetooth_btn->setChecked(false); ++ ++// if (frame_bottom->isVisible()) ++// frame_bottom->setVisible(false); ++ ++// if(frame_middle->isVisible()) ++// frame_middle->setVisible(false); ++ ++// if (!paired_dev_layout->isEmpty()) ++// m_myDev_show_flag = true ; ++// else ++// m_myDev_show_flag = false ; ++// } + } + + +@@ -748,6 +752,7 @@ void BlueToothMain::addMyDeviceItemUI(bl + DeviceInfoItem *item = frame_middle->findChild(device->getDevAddress()); + if (item) + { ++ m_myDev_show_flag = true; + qDebug () << Q_FUNC_INFO << "device is exist" << __LINE__; + return; + } +@@ -1207,6 +1212,19 @@ void BlueToothMain::setDefaultAdapterPow + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + } + ++void BlueToothMain::setDefaultAdapter(QString adapterAddress) ++{ ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, ++ PATH, ++ INTERFACE, ++ "setDefaultAdapter"); ++ m << adapterAddress; ++ qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; ++ // 发送Message ++ QDBusConnection::sessionBus().call(m, QDBus::NoBlock); ++} ++ + void BlueToothMain::setDefaultAdapterDiscoverable(bool value) + { + qDebug() << Q_FUNC_INFO << __LINE__; +@@ -1300,7 +1318,7 @@ void BlueToothMain::showBluetoothNormalM + qDebug() << Q_FUNC_INFO << __LINE__; + m_normal_main_widget = new QWidget(this); + m_normal_main_widget->setObjectName("normalWidget"); +- this->setCentralWidget(m_normal_main_widget); ++ //this->setCentralWidget(m_normal_main_widget); + + main_layout = new QVBoxLayout(m_normal_main_widget); + main_layout->setSpacing(40); +@@ -1335,8 +1353,7 @@ void BlueToothMain::showBluetoothNormalM + initMainWindowMiddleUI(); + initMainWindowbottomUI(); + this->setLayout(main_layout); +- monitorSleepSignal(); +- refreshUIWhenAdapterChanged(); ++ _MCentralWidget->addWidget(m_normal_main_widget); + } + + +@@ -1387,6 +1404,7 @@ void BlueToothMain::initMainWindowTopUI( + frame_1_layout->addStretch(); + + m_open_bluetooth_btn = new SwitchButton(frame_1); ++ connect(m_open_bluetooth_btn,SIGNAL(checkedChanged(bool)),this,SLOT(onClick_Open_Bluetooth(bool))); + + frame_1_layout->addWidget(m_open_bluetooth_btn); + +@@ -1478,11 +1496,7 @@ void BlueToothMain::initMainWindowTopUI( + //switch_discover->setChecked(m_localDevice->isDiscoverable()); + m_discover_switch_btn->setChecked(m_current_adapter_disconvery_swtich); + connect(m_discover_switch_btn,&SwitchButton::checkedChanged,this,&BlueToothMain::setDefaultAdapterDiscoverable); +- //connect(m_localDevice.data(), &BluezQt::Adapter::discoverableChanged, this, [=](bool discoverable){ +- // switch_discover->setChecked(discoverable); +- //}); + +- connect(m_open_bluetooth_btn,SIGNAL(checkedChanged(bool)),this,SLOT(onClick_Open_Bluetooth(bool))); + frame_top->setLayout(top_layout); + qDebug() << Q_FUNC_INFO << "end" << __LINE__; + +@@ -1534,6 +1548,7 @@ void BlueToothMain::initMainWindowbottom + delayStartDiscover_timer->setInterval(2000); + connect(delayStartDiscover_timer,&QTimer::timeout,this,[=] + { ++ qDebug() << "delay Start Discover time out:" << __LINE__; + delayStartDiscover_timer->stop(); + setDefaultAdapterScanOn(true); + +@@ -1596,12 +1611,12 @@ void BlueToothMain::showBluetoothErrorMa + { + qDebug() << Q_FUNC_INFO << __LINE__; + stopAllTimer(); +- QWidget *errorWidget = new QWidget(); +- QVBoxLayout *errorWidgetLayout = new QVBoxLayout(errorWidget); +- QLabel *errorWidgetIcon = new QLabel(errorWidget); +- QLabel *errorWidgetTip0 = new QLabel(errorWidget); ++ m_error_main_widget = new QWidget(); ++ QVBoxLayout *errorWidgetLayout = new QVBoxLayout(m_error_main_widget); ++ QLabel *errorWidgetIcon = new QLabel(m_error_main_widget); ++ QLabel *errorWidgetTip0 = new QLabel(m_error_main_widget); + +- errorWidget->setObjectName("errorWidget"); ++ m_error_main_widget->setObjectName("errorWidget"); + + errorWidgetLayout->setSpacing(10); + errorWidgetLayout->setMargin(0); +@@ -1626,22 +1641,17 @@ void BlueToothMain::showBluetoothErrorMa + errorWidgetLayout->addWidget(errorWidgetTip0,1,Qt::AlignCenter); + errorWidgetLayout->addStretch(10); + +- this->setCentralWidget(errorWidget); +- delete m_normal_main_widget; +- m_normal_main_widget = NULL; ++ _MCentralWidget->addWidget(m_error_main_widget); + } + + + void BlueToothMain::refreshUIWhenAdapterChanged() + { + qDebug() << Q_FUNC_INFO << __LINE__; +- if("normalWidget" != this->centralWidget()->objectName()) +- { +- return; +- } +- + // =============清空我的设备和蓝牙发现设备栏布局下的所有设备item================= +- cleanPairDevices(); ++ //cleanPairDevices(); ++ m_default_adapter_address = getDefaultAdapterAddress(); ++ getDefaultAdapterData(m_default_adapter_address); + // ========================END=========================================== + m_myDev_show_flag = false; + m_discovery_device_address_all_list.clear(); +@@ -1668,7 +1678,8 @@ void BlueToothMain::refreshUIWhenAdapter + qDebug() << Q_FUNC_INFO << "m_current_adapter_power_swtich:" << m_current_adapter_power_swtich ; + if(m_current_adapter_power_swtich) + { +- m_open_bluetooth_btn->setChecked(true); ++ if (!m_open_bluetooth_btn->isChecked()) ++ m_open_bluetooth_btn->setChecked(true); + // bluetooth_name->setVisible(true); + frame_middle->setVisible(m_myDev_show_flag); + if (!frame_bottom->isVisible()) +@@ -1676,7 +1687,8 @@ void BlueToothMain::refreshUIWhenAdapter + } + else + { +- m_open_bluetooth_btn->setChecked(false); ++ if (m_open_bluetooth_btn->isChecked()) ++ m_open_bluetooth_btn->setChecked(false); + // bluetooth_name->setVisible(false); + frame_bottom->setVisible(false); + frame_middle->setVisible(false); +@@ -1725,7 +1737,6 @@ void BlueToothMain::onClick_Open_Bluetoo + setDefaultAdapterPower(ischeck); + // bluetooth_name->setVisible(ischeck); + } +- + if(ischeck && m_myDev_show_flag) + frame_middle->setVisible(ischeck); + else +@@ -1743,7 +1754,6 @@ void BlueToothMain::onClick_Open_Bluetoo + stopAllTimer(); + } + +- + return; + } + +@@ -1758,7 +1768,7 @@ bool BlueToothMain::isInvalidDevice(QStr + + void BlueToothMain::refreshLoadLabelIcon() + { +- if(this->centralWidget()->objectName() == "normalWidget") ++ if("normalWidget" == _MCentralWidget->currentWidget()->objectName()) + { + if(i == 0) + i = 7; +@@ -1912,8 +1922,8 @@ void BlueToothMain::monitorSleepSlot(boo + if (!value) { + if (sleep_status) + { +- if (this->centralWidget()->objectName() == "normalWidget") +- adapterPoweredChanged(true); ++// if (this->centralWidget()->objectName() == "normalWidget") ++// adapterPoweredChanged(true); + } + } else { + sleep_status = m_current_adapter_power_swtich; +@@ -1980,19 +1990,20 @@ void BlueToothMain::adapterComboxChanged + + if(i != -1) + { +- m_default_bluetooth_adapter = m_bluetooth_adapter_list.at(i); +- if (nullptr == m_default_bluetooth_adapter) +- { +- return; +- } +- getDefaultAdapterData(m_adapter_address_list.at(i)); +- m_bluetooth_adapter_list.at(i)->setDevPower(m_current_adapter_power_swtich); +- m_bluetooth_adapter_list.at(i)->setDevDiscovering(m_current_adapter_scan_status); +- m_bluetooth_adapter_list.at(i)->setDevDiscoverable(m_current_adapter_disconvery_swtich); +- //refreshUIWhenAdapterChanged(); +- if(m_settings) +- m_settings->set("adapter-address",QVariant::fromValue(m_adapter_address_list.at(i))); +- Default_Adapter = m_adapter_address_list.at(i); ++ qDebug() << Q_FUNC_INFO << "=================3" << __LINE__; ++ ++ setDefaultAdapter(m_bluetooth_adapter_list.at(i)->getDevAddress()); ++ ++// m_default_bluetooth_adapter = m_bluetooth_adapter_list.at(i); ++// if (nullptr == m_default_bluetooth_adapter) ++// { ++// return; ++// } ++ refreshUIWhenAdapterChanged(); ++ ++// if(m_settings) ++// m_settings->set("adapter-address",QVariant::fromValue(m_adapter_address_list.at(i))); ++// Default_Adapter = m_adapter_address_list.at(i); + }else{ + if(m_open_bluetooth_btn->isChecked()){ + qDebug() << __FUNCTION__<< "index - i : "<< i << __LINE__ ; +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.h ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.h +@@ -34,9 +34,12 @@ + #include + #include + ++#include ++ + #include "deviceinfoitem.h" + #include "bluetoothnamelabel.h" + #include "devicebase.h" ++#include "config.h" + + class BlueToothMain : public QMainWindow + { +@@ -101,12 +104,15 @@ private slots: + void adapterComboxChanged(int i); + + private: ++ QStackedWidget *_MCentralWidget = nullptr; ++ + QWidget * frame_top = nullptr; + QWidget * frame_middle = nullptr; + QWidget * frame_bottom = nullptr; + QWidget * m_normal_main_widget = nullptr; + QWidget * m_error_main_widget = nullptr; + QWidget * device_list = nullptr; ++ QWidget * paired_device_list = nullptr; + QVBoxLayout * device_list_layout = nullptr; + BluetoothNameLabel * bluetooth_name = nullptr; + +@@ -139,19 +145,18 @@ private: + + QStringList last_discovery_device_address; + QStringList m_discovery_device_address_all_list; //所有device mac list +- QStringList m_discovery_device_address_effective_list; //有效device mac list +- QStringList m_paired_device_address_list; //已配对device mac list +- QStringList m_paired_device_name_list; ++ //QStringList m_discovery_device_address_effective_list; //有效device mac list ++ //QStringList m_paired_device_address_list; //已配对device mac list ++ //QStringList m_paired_device_name_list; + +- QWidget * m_all_device_list = nullptr; ++ //QWidget * m_all_device_list = nullptr; + //QWidget * m_audio_device_list = nullptr; // include : +- QWidget * m_other_device_list = nullptr; ++ //QWidget * m_other_device_list = nullptr; + + SwitchButton * m_open_bluetooth_btn = nullptr; + SwitchButton * m_show_panel_btn = nullptr; + SwitchButton * m_discover_switch_btn = nullptr; + +- + QComboBox * m_adapter_list_cmbox = nullptr; + QComboBox * m_cache_dev_type_list_cmbox = nullptr; + +@@ -199,6 +204,7 @@ private: + + void setBluetoothBlock(bool); + void setDefaultAdapterPower(bool); ++ void setDefaultAdapter(QString); + void setDefaultAdapterName(QString); + void setDefaultAdapterDiscoverable(bool); + void setDefaultAdapterScanOn(bool); +Index: ukui-bluetooth/ukcc-bluetooth/config.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/config.h ++++ ukui-bluetooth/ukcc-bluetooth/config.h +@@ -1,9 +1,14 @@ + #ifndef CONFIG_H + #define CONFIG_H ++#include + +-#define BluetoothServiceExePath "/usr/bin/bluetoothService" ++#define BluetoothServiceExePath "/usr/bin/bluetoothService -o" + #define BluetoothTrayExePath "/usr/bin/ukui-bluetooth" + #define BluetoothServiceName "bluetoothService" + #define BluetoothTrayName "ukui-bluetooth" + ++const QString SERVICE = "com.ukui.bluetooth"; ++const QString PATH = "/com/ukui/bluetooth"; ++const QString INTERFACE = "com.ukui.bluetooth"; ++ + #endif // CONFIG_H +Index: ukui-bluetooth/ukcc-bluetooth/devicebase.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/devicebase.cpp ++++ ukui-bluetooth/ukcc-bluetooth/devicebase.cpp +@@ -38,7 +38,7 @@ QString bluetoothadapter::getDevName() + QString bluetoothadapter::getDevAddress() + { + qDebug() << Q_FUNC_INFO << __LINE__; +- return this->m_dev_name; ++ return this->m_dev_address; + } + + +Index: ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/deviceinfoitem.cpp ++++ ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +@@ -250,7 +250,6 @@ void DeviceInfoItem::setDeviceConnectSig + _DevStatus = DEVSTATUS::ConnectFailed; + } + +- //if (_MDev->isPaired()) + emit devConnectionComplete(); + + update(); +@@ -473,6 +472,8 @@ QColor DeviceInfoItem::getPainterBrushCo + //color = QColor(Qt::white);//("#EBEBEB"); + break; + } ++ if (_MStatus == Status::Hover || _themeIsBlack) ++ color.setAlpha(50); + return color; + } + +@@ -494,7 +495,6 @@ QColor DeviceInfoItem::getDevStatusColor + } else { + color = QColor("#F4F4F4"); + } +- + return color; + } + diff --git a/patches/ukcc_bluetooth_name_change_error.patch b/patches/ukcc_bluetooth_name_change_error.patch new file mode 100644 index 0000000..ca3b1f5 --- /dev/null +++ b/patches/ukcc_bluetooth_name_change_error.patch @@ -0,0 +1,13 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index f0c69a0..0fd4798 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -917,7 +917,7 @@ void SessionDbusRegister::connectSignal() + + connect(dev.data(),&BluezQt::Device::nameChanged,this,[=](const QString &name){ + qDebug() << Q_FUNC_INFO << "nameChanged" << dev.data()->address(); +- emit devTypeChangedSignal(dev.data()->address(),name); ++ emit devNameChangedSignal(dev.data()->address(),name); + }); + #ifdef BATTERY + connect(dev.data(),&BluezQt::Device::batteryChanged,this,[=](BluezQt::BatteryPtr battery){ diff --git a/patches/ukcc_bluetooth_optimize_device_connection_display.patch b/patches/ukcc_bluetooth_optimize_device_connection_display.patch new file mode 100644 index 0000000..cfc0b88 --- /dev/null +++ b/patches/ukcc_bluetooth_optimize_device_connection_display.patch @@ -0,0 +1,592 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 63bfdc1..3d2fc3e 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -141,7 +141,15 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + if (Daemon::_DefualtAdapter.data()->isDiscovering()) { + ::isScan = true; +- Daemon::_DefualtAdapter.data()->stopDiscovery(); ++ BluezQt::PendingCall * stop_call = Daemon::_DefualtAdapter.data()->stopDiscovery(); ++ connect(stop_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn) ++ { ++ qDebug() << Q_FUNC_INFO << "stopDiscovery:" << callReturn->error() << callReturn->errorText() << __LINE__; ++ }); ++ //qDebug() << Q_FUNC_INFO << "stopDiscovery:111111111111111111" << __LINE__; ++ stop_call->waitForFinished(); ++ //qDebug() << Q_FUNC_INFO << "stopDiscovery:222222222222222222" << __LINE__; ++ + } + + if (dev.data()->type() == BluezQt::Device::AudioVideo || +@@ -185,7 +193,10 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); ++ BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); ++ connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ }); + } + } + +@@ -249,11 +260,13 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); ++ BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); ++ ++ connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ }); + } + } +- +- + }); + } + } +@@ -710,12 +723,12 @@ void SessionDbusRegister::connectSignal() + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoveringChanged,this,[=](bool status){ +- qDebug() << Q_FUNC_INFO << "discoveringChanged" << __LINE__; ++ qDebug() << Q_FUNC_INFO << "discoveringChanged" << status << __LINE__; + emit defaultScanStatusChanged(status); + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoverableChanged,this,[=](bool discoverable){ +- qDebug() << Q_FUNC_INFO << "discoverableChanged" << __LINE__; ++ qDebug() << Q_FUNC_INFO << "discoverableChanged" << discoverable << __LINE__; + emit defaultDiscoverableChanged(discoverable); + }); + +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index d2ff887..4181c0f 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -512,7 +512,6 @@ void BlueToothMain::removeAdapterDataList(QString adapterAddress) + if(m_adapter_list_cmbox != nullptr) + m_adapter_list_cmbox->removeItem(i); + } +- + } + void BlueToothMain::reportAdapterAddSignal(QString adapterAddress) + { +@@ -638,6 +637,14 @@ void BlueToothMain::reportDevOperateErrorSignal(QString deviceAddress , int Erro + { + qDebug() << Q_FUNC_INFO << deviceAddress << ErrorId << ErrorText << __LINE__; + m_device_pin_flag = false; ++ for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) ++ { ++ if (deviceAddress == dev->getDevAddress()) ++ { ++ dev->setErrorInfo(ErrorId,ErrorText); ++ return; ++ } ++ } + } + + bluetoothdevice * BlueToothMain::createOneBluetoothDevice(QString devAddress) +@@ -762,10 +769,6 @@ void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { + m_device_operating = false; +-// if (delayStartDiscover_timer->isActive()) +-// delayStartDiscover_timer->stop(); +-// delayStartDiscover_timer->start(); +- //setDefaultAdapterScanOn(true); + }); + m_myDev_show_flag = true; + +@@ -823,6 +826,7 @@ bool BlueToothMain::whetherToAddCurrentInterface(bluetoothdevice * device) + return true; + } + } ++ + void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) + { + DeviceInfoItem * item = frame_middle->findChild(device->getDevAddress()); +@@ -850,9 +854,9 @@ void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { + m_device_operating = false; +- if (delayStartDiscover_timer->isActive()) +- delayStartDiscover_timer->stop(); +- delayStartDiscover_timer->start(); ++// if (delayStartDiscover_timer->isActive()) ++// delayStartDiscover_timer->stop(); ++// delayStartDiscover_timer->start(); + }); + + mDevFrameAddLineFrame("other",device->getDevAddress()); +@@ -2190,7 +2194,6 @@ void BlueToothMain::removeMDevFrameLineFrame(QString str) + } + } + } +- + } else if ("other" == str) { + + } else { +diff --git a/ukcc-bluetooth/devicebase.cpp b/ukcc-bluetooth/devicebase.cpp +index 4279e7a..7a953d7 100644 +--- a/ukcc-bluetooth/devicebase.cpp ++++ b/ukcc-bluetooth/devicebase.cpp +@@ -197,5 +197,13 @@ void bluetoothdevice::devConnectedChanged(bool value) + this->m_dev_isConnected = value; + emit connectedChanged(value); + } ++ ++void bluetoothdevice::setErrorInfo(int errorId,QString errorText) ++{ ++ this->m_errorId = errorId; ++ this->m_errorText = errorText; ++ emit errorInfoRefresh(errorId,errorText); ++} ++ + //bluetoothdevice end + +diff --git a/ukcc-bluetooth/devicebase.h b/ukcc-bluetooth/devicebase.h +index bae0188..aa72810 100644 +--- a/ukcc-bluetooth/devicebase.h ++++ b/ukcc-bluetooth/devicebase.h +@@ -154,6 +154,7 @@ public: + + void setDevTrust(bool); + bool getDevTrust(); ++ void setErrorInfo(int,QString); + + signals: + +@@ -162,17 +163,19 @@ signals: + void pairedChanged(bool); + void connectedChanged(bool); + void trustChanged(bool); ++ void errorInfoRefresh(int,QString); + + private: + +- QString m_dev_name; +- QString m_dev_address; +- DEVICE_TYPE m_dev_type; +- DEVICE_STATUS m_dev_status; +- bool m_dev_trust ; +- bool m_dev_isPaired; +- bool m_dev_isConnected; +- ++ QString m_dev_name; ++ QString m_dev_address; ++ DEVICE_TYPE m_dev_type; ++ DEVICE_STATUS m_dev_status; ++ bool m_dev_trust ; ++ bool m_dev_isPaired; ++ bool m_dev_isConnected; ++ int m_errorId; ++ QString m_errorText; + }; + //bluetoothdevice end + +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 6b64e36..917eeec 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -35,6 +35,25 @@ DeviceInfoItem::~DeviceInfoItem() + + } + ++void DeviceInfoItem::TimedRestoreConnectionErrorDisplay() ++{ ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ //错误信息显示超时后,显示错误操作后的设备状态 ++ QTimer::singleShot(8000,this,[=]{ ++ if (_MDev->isPaired()) ++ { ++ _DevStatus = DEVSTATUS::Paired; ++ ++ if (_MDev->isConnected()) ++ _DevStatus = DEVSTATUS::Connected; ++ ++ } else { ++ _DevStatus = DEVSTATUS::NoPaired; ++ } ++ update(); ++ }); ++} ++ + + void DeviceInfoItem::InitMemberVariables() + { +@@ -80,7 +99,7 @@ void DeviceInfoItem::InitMemberVariables() + }); + + _devConnTimer = new QTimer(this); +- _devConnTimer->setInterval(5000); ++ _devConnTimer->setInterval(30000); + connect(_devConnTimer,&QTimer::timeout,this,[=]{ + if(BlueToothMain::m_device_pin_flag) + { +@@ -102,22 +121,7 @@ void DeviceInfoItem::InitMemberVariables() + _DevStatus = DEVSTATUS::DisConnectFailed; + } + update(); +- +- //错误信息显示超时后,显示错误操作后的设备状态 +- QTimer::singleShot(8000,this,[=]{ +- if (_MDev->isPaired()) +- { +- _DevStatus = DEVSTATUS::Paired; +- +- if (_MDev->isConnected()) +- _DevStatus = DEVSTATUS::Connected; +- +- } else { +- _DevStatus = DEVSTATUS::NoPaired; +- } +- update(); +- }); +- ++ TimedRestoreConnectionErrorDisplay(); + }); + + dev_Menu = new QMenu(this); +@@ -262,8 +266,28 @@ void DeviceInfoItem::setDeviceConnectSignals() + } + + emit devConnectionComplete(); +- + update(); ++ TimedRestoreConnectionErrorDisplay(); ++ }); ++ ++ connect(_MDev,&bluetoothdevice::errorInfoRefresh,this,[=](int errorId , QString errorText) ++ { ++ qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; ++ if (errorId) ++ { ++ if(_devConnTimer->isActive()) ++ _devConnTimer->stop(); ++ if (_iconTimer->isActive()) ++ _iconTimer->stop(); ++ _clicked = false; ++ ++ qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; ++ //BlueToothMain::m_device_pin_flag = false; ++ _DevStatus = DEVSTATUS::ConnectFailed; ++ emit devConnectionComplete(); ++ update(); ++ TimedRestoreConnectionErrorDisplay(); ++ } + }); + } + } +diff --git a/ukcc-bluetooth/deviceinfoitem.h b/ukcc-bluetooth/deviceinfoitem.h +index 9ec99a1..f69a89f 100644 +--- a/ukcc-bluetooth/deviceinfoitem.h ++++ b/ukcc-bluetooth/deviceinfoitem.h +@@ -99,6 +99,8 @@ private: + QString getDeviceName(QString); + int ShowNameTextNumberMax(); + int NameTextCoordinate_Y_offset(); ++ void TimedRestoreConnectionErrorDisplay(); ++ + bool toptipflag = false; + int iconFlag = 7; + +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 63bfdc1..3d2fc3e 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -141,7 +141,15 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + if (Daemon::_DefualtAdapter.data()->isDiscovering()) { + ::isScan = true; +- Daemon::_DefualtAdapter.data()->stopDiscovery(); ++ BluezQt::PendingCall * stop_call = Daemon::_DefualtAdapter.data()->stopDiscovery(); ++ connect(stop_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn) ++ { ++ qDebug() << Q_FUNC_INFO << "stopDiscovery:" << callReturn->error() << callReturn->errorText() << __LINE__; ++ }); ++ //qDebug() << Q_FUNC_INFO << "stopDiscovery:111111111111111111" << __LINE__; ++ stop_call->waitForFinished(); ++ //qDebug() << Q_FUNC_INFO << "stopDiscovery:222222222222222222" << __LINE__; ++ + } + + if (dev.data()->type() == BluezQt::Device::AudioVideo || +@@ -185,7 +193,10 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); ++ BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); ++ connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ }); + } + } + +@@ -249,11 +260,13 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { +- Daemon::_DefualtAdapter.data()->startDiscovery(); ++ BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); ++ ++ connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ ++ qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; ++ }); + } + } +- +- + }); + } + } +@@ -710,12 +723,12 @@ void SessionDbusRegister::connectSignal() + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoveringChanged,this,[=](bool status){ +- qDebug() << Q_FUNC_INFO << "discoveringChanged" << __LINE__; ++ qDebug() << Q_FUNC_INFO << "discoveringChanged" << status << __LINE__; + emit defaultScanStatusChanged(status); + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoverableChanged,this,[=](bool discoverable){ +- qDebug() << Q_FUNC_INFO << "discoverableChanged" << __LINE__; ++ qDebug() << Q_FUNC_INFO << "discoverableChanged" << discoverable << __LINE__; + emit defaultDiscoverableChanged(discoverable); + }); + +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index d2ff887..4181c0f 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -512,7 +512,6 @@ void BlueToothMain::removeAdapterDataList(QString adapterAddress) + if(m_adapter_list_cmbox != nullptr) + m_adapter_list_cmbox->removeItem(i); + } +- + } + void BlueToothMain::reportAdapterAddSignal(QString adapterAddress) + { +@@ -638,6 +637,14 @@ void BlueToothMain::reportDevOperateErrorSignal(QString deviceAddress , int Erro + { + qDebug() << Q_FUNC_INFO << deviceAddress << ErrorId << ErrorText << __LINE__; + m_device_pin_flag = false; ++ for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) ++ { ++ if (deviceAddress == dev->getDevAddress()) ++ { ++ dev->setErrorInfo(ErrorId,ErrorText); ++ return; ++ } ++ } + } + + bluetoothdevice * BlueToothMain::createOneBluetoothDevice(QString devAddress) +@@ -762,10 +769,6 @@ void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { + m_device_operating = false; +-// if (delayStartDiscover_timer->isActive()) +-// delayStartDiscover_timer->stop(); +-// delayStartDiscover_timer->start(); +- //setDefaultAdapterScanOn(true); + }); + m_myDev_show_flag = true; + +@@ -823,6 +826,7 @@ bool BlueToothMain::whetherToAddCurrentInterface(bluetoothdevice * device) + return true; + } + } ++ + void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) + { + DeviceInfoItem * item = frame_middle->findChild(device->getDevAddress()); +@@ -850,9 +854,9 @@ void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { + m_device_operating = false; +- if (delayStartDiscover_timer->isActive()) +- delayStartDiscover_timer->stop(); +- delayStartDiscover_timer->start(); ++// if (delayStartDiscover_timer->isActive()) ++// delayStartDiscover_timer->stop(); ++// delayStartDiscover_timer->start(); + }); + + mDevFrameAddLineFrame("other",device->getDevAddress()); +@@ -2190,7 +2194,6 @@ void BlueToothMain::removeMDevFrameLineFrame(QString str) + } + } + } +- + } else if ("other" == str) { + + } else { +diff --git a/ukcc-bluetooth/devicebase.cpp b/ukcc-bluetooth/devicebase.cpp +index 4279e7a..7a953d7 100644 +--- a/ukcc-bluetooth/devicebase.cpp ++++ b/ukcc-bluetooth/devicebase.cpp +@@ -197,5 +197,13 @@ void bluetoothdevice::devConnectedChanged(bool value) + this->m_dev_isConnected = value; + emit connectedChanged(value); + } ++ ++void bluetoothdevice::setErrorInfo(int errorId,QString errorText) ++{ ++ this->m_errorId = errorId; ++ this->m_errorText = errorText; ++ emit errorInfoRefresh(errorId,errorText); ++} ++ + //bluetoothdevice end + +diff --git a/ukcc-bluetooth/devicebase.h b/ukcc-bluetooth/devicebase.h +index bae0188..aa72810 100644 +--- a/ukcc-bluetooth/devicebase.h ++++ b/ukcc-bluetooth/devicebase.h +@@ -154,6 +154,7 @@ public: + + void setDevTrust(bool); + bool getDevTrust(); ++ void setErrorInfo(int,QString); + + signals: + +@@ -162,17 +163,19 @@ signals: + void pairedChanged(bool); + void connectedChanged(bool); + void trustChanged(bool); ++ void errorInfoRefresh(int,QString); + + private: + +- QString m_dev_name; +- QString m_dev_address; +- DEVICE_TYPE m_dev_type; +- DEVICE_STATUS m_dev_status; +- bool m_dev_trust ; +- bool m_dev_isPaired; +- bool m_dev_isConnected; +- ++ QString m_dev_name; ++ QString m_dev_address; ++ DEVICE_TYPE m_dev_type; ++ DEVICE_STATUS m_dev_status; ++ bool m_dev_trust ; ++ bool m_dev_isPaired; ++ bool m_dev_isConnected; ++ int m_errorId; ++ QString m_errorText; + }; + //bluetoothdevice end + +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 6b64e36..917eeec 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -35,6 +35,25 @@ DeviceInfoItem::~DeviceInfoItem() + + } + ++void DeviceInfoItem::TimedRestoreConnectionErrorDisplay() ++{ ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ //错误信息显示超时后,显示错误操作后的设备状态 ++ QTimer::singleShot(8000,this,[=]{ ++ if (_MDev->isPaired()) ++ { ++ _DevStatus = DEVSTATUS::Paired; ++ ++ if (_MDev->isConnected()) ++ _DevStatus = DEVSTATUS::Connected; ++ ++ } else { ++ _DevStatus = DEVSTATUS::NoPaired; ++ } ++ update(); ++ }); ++} ++ + + void DeviceInfoItem::InitMemberVariables() + { +@@ -80,7 +99,7 @@ void DeviceInfoItem::InitMemberVariables() + }); + + _devConnTimer = new QTimer(this); +- _devConnTimer->setInterval(5000); ++ _devConnTimer->setInterval(30000); + connect(_devConnTimer,&QTimer::timeout,this,[=]{ + if(BlueToothMain::m_device_pin_flag) + { +@@ -102,22 +121,7 @@ void DeviceInfoItem::InitMemberVariables() + _DevStatus = DEVSTATUS::DisConnectFailed; + } + update(); +- +- //错误信息显示超时后,显示错误操作后的设备状态 +- QTimer::singleShot(8000,this,[=]{ +- if (_MDev->isPaired()) +- { +- _DevStatus = DEVSTATUS::Paired; +- +- if (_MDev->isConnected()) +- _DevStatus = DEVSTATUS::Connected; +- +- } else { +- _DevStatus = DEVSTATUS::NoPaired; +- } +- update(); +- }); +- ++ TimedRestoreConnectionErrorDisplay(); + }); + + dev_Menu = new QMenu(this); +@@ -262,8 +266,28 @@ void DeviceInfoItem::setDeviceConnectSignals() + } + + emit devConnectionComplete(); +- + update(); ++ TimedRestoreConnectionErrorDisplay(); ++ }); ++ ++ connect(_MDev,&bluetoothdevice::errorInfoRefresh,this,[=](int errorId , QString errorText) ++ { ++ qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; ++ if (errorId) ++ { ++ if(_devConnTimer->isActive()) ++ _devConnTimer->stop(); ++ if (_iconTimer->isActive()) ++ _iconTimer->stop(); ++ _clicked = false; ++ ++ qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; ++ //BlueToothMain::m_device_pin_flag = false; ++ _DevStatus = DEVSTATUS::ConnectFailed; ++ emit devConnectionComplete(); ++ update(); ++ TimedRestoreConnectionErrorDisplay(); ++ } + }); + } + } +diff --git a/ukcc-bluetooth/deviceinfoitem.h b/ukcc-bluetooth/deviceinfoitem.h +index 9ec99a1..f69a89f 100644 +--- a/ukcc-bluetooth/deviceinfoitem.h ++++ b/ukcc-bluetooth/deviceinfoitem.h +@@ -99,6 +99,8 @@ private: + QString getDeviceName(QString); + int ShowNameTextNumberMax(); + int NameTextCoordinate_Y_offset(); ++ void TimedRestoreConnectionErrorDisplay(); ++ + bool toptipflag = false; + int iconFlag = 7; + diff --git a/patches/ukcc_bluetooth_ota_upgrade.patch b/patches/ukcc_bluetooth_ota_upgrade.patch new file mode 100644 index 0000000..42e9657 --- /dev/null +++ b/patches/ukcc_bluetooth_ota_upgrade.patch @@ -0,0 +1,95 @@ +diff --git a/ukcc-bluetooth/ukccbluetoothconfig.cpp b/ukcc-bluetooth/ukccbluetoothconfig.cpp +index 1818e63..e4e7732 100644 +--- a/ukcc-bluetooth/ukccbluetoothconfig.cpp ++++ b/ukcc-bluetooth/ukccbluetoothconfig.cpp +@@ -35,7 +35,7 @@ bool ukccbluetoothconfig::checkProcessRunning(const QString &processName, QList< + qDebug() << Q_FUNC_INFO << __LINE__; + + bool res(false); +- QString strCommand = "ps -ef|grep " + processName + " |grep -v grep |awk '{print $2}'"; ++ QString strCommand = "ps -ef|grep '" + processName + " -o' |grep -v grep |awk '{print $2}'"; + QByteArray ba = strCommand.toLatin1(); + const char* strFind_ComName = ba.data(); + //const char* strFind_ComName = convertQString2char(strCommand); +diff --git a/ukcc-bluetooth/bluetooth.cpp b/ukcc-bluetooth/bluetooth.cpp +index 049e696..396f7c3 100644 +--- a/ukcc-bluetooth/bluetooth.cpp ++++ b/ukcc-bluetooth/bluetooth.cpp +@@ -33,10 +33,15 @@ Bluetooth::Bluetooth() : mFirstLoad(true) { + qDebug () << Q_FUNC_INFO << BluetoothTrayExePath << "is Running" ; + for (quint64 processId:btTrayProcessId) + { ++ qDebug () << Q_FUNC_INFO << "ProcessId:" << btTrayProcessId << "is Running" ; + ukccbluetoothconfig::killAppProcess(processId); + } + } +- ukccbluetoothconfig::launchBluetoothServiceStart(); ++ else ++ { ++ qDebug () << Q_FUNC_INFO << BluetoothTrayExePath << "is not Running" ; ++ } ++ ukccbluetoothconfig::launchBluetoothServiceStart(BluetoothServiceExePath); + } + + +diff --git a/ukcc-bluetooth/config.h b/ukcc-bluetooth/config.h +index 6bf4a2b..02b49fb 100644 +--- a/ukcc-bluetooth/config.h ++++ b/ukcc-bluetooth/config.h +@@ -2,7 +2,7 @@ + #define CONFIG_H + #include + +-#define BluetoothServiceExePath "/usr/bin/bluetoothService" ++#define BluetoothServiceExePath "/usr/bin/bluetoothService -o" + #define BluetoothTrayExePath "/usr/bin/ukui-bluetooth" + #define BluetoothServiceName "bluetoothService" + #define BluetoothTrayName "ukui-bluetooth" +diff --git a/ukcc-bluetooth/ukccbluetoothconfig.cpp b/ukcc-bluetooth/ukccbluetoothconfig.cpp +index e4e7732..b687b17 100644 +--- a/ukcc-bluetooth/ukccbluetoothconfig.cpp ++++ b/ukcc-bluetooth/ukccbluetoothconfig.cpp +@@ -7,12 +7,13 @@ ukccbluetoothconfig::ukccbluetoothconfig() + + } + +-void ukccbluetoothconfig::launchBluetoothServiceStart() ++void ukccbluetoothconfig::launchBluetoothServiceStart(const QString &processName) + { + qDebug () << Q_FUNC_INFO << __LINE__; + QProcess *process = new QProcess(); +- QString cmd = BluetoothServiceExePath; +- qDebug() << Q_FUNC_INFO; ++ QString cmd = processName; ++ //cmd.append(" -o"); ++ qDebug () << Q_FUNC_INFO << cmd << __LINE__; + process->startDetached(cmd); + } + +@@ -35,7 +36,12 @@ bool ukccbluetoothconfig::checkProcessRunning(const QString &processName, QList< + qDebug() << Q_FUNC_INFO << __LINE__; + + bool res(false); +- QString strCommand = "ps -ef|grep '" + processName + " -o' |grep -v grep |awk '{print $2}'"; ++ QString strCommand; ++ //if(processName == BluetoothServiceExePath) ++ // strCommand = "ps -ef|grep '" + processName + " -o' |grep -v grep |awk '{print $2}'"; ++ //else ++ strCommand = "ps -ef|grep '" + processName + "' |grep -v grep |awk '{print $2}'"; ++ + QByteArray ba = strCommand.toLatin1(); + const char* strFind_ComName = ba.data(); + //const char* strFind_ComName = convertQString2char(strCommand); +diff --git a/ukcc-bluetooth/ukccbluetoothconfig.h b/ukcc-bluetooth/ukccbluetoothconfig.h +index f2000ef..172ab93 100644 +--- a/ukcc-bluetooth/ukccbluetoothconfig.h ++++ b/ukcc-bluetooth/ukccbluetoothconfig.h +@@ -11,7 +11,7 @@ class ukccbluetoothconfig + public: + ukccbluetoothconfig(); + +- static void launchBluetoothServiceStart(); ++ static void launchBluetoothServiceStart(const QString &processName); + static void killAppProcess(const quint64 &processId); + static bool checkProcessRunning(const QString &processName, QList &listProcessId); + }; diff --git a/patches/ukcc_bluetooth_pin_time_connect_fail.patch b/patches/ukcc_bluetooth_pin_time_connect_fail.patch new file mode 100644 index 0000000..98a2c09 --- /dev/null +++ b/patches/ukcc_bluetooth_pin_time_connect_fail.patch @@ -0,0 +1,194 @@ +diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp +index 13f2035..63bfdc1 100644 +--- a/service/sessiondbusregister.cpp ++++ b/service/sessiondbusregister.cpp +@@ -170,7 +170,9 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + GlobalSize::unrefBlueDevActive(tmpdev->address()); + if (callReturn->error()) { +- emit devOperateErrorSignal(dev.data()->address()); ++ emit devOperateErrorSignal(dev.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); + } + else + { +@@ -203,7 +205,9 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + GlobalSize::unrefBlueDevActive(dev->address()); + if (callReturn->error()) { +- emit devOperateErrorSignal(dev.data()->address()); ++ emit devOperateErrorSignal(dev.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); + } + else + { +@@ -231,7 +235,9 @@ void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + GlobalSize::unrefBlueDevActive(dev->address()); + if (callReturn->error()) { +- emit devOperateErrorSignal(dev.data()->address()); ++ emit devOperateErrorSignal(dev.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); + } + else + { +@@ -375,7 +381,9 @@ void SessionDbusRegister::devPair(const QString addr) + BluezQt::PendingCall *call = devPtr.data()->pair(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { +- emit devOperateErrorSignal(devPtr.data()->address()); ++ emit devOperateErrorSignal(devPtr.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); + } + }); + } +@@ -396,7 +404,9 @@ void SessionDbusRegister::devConnect(const QString addr) + BluezQt::PendingCall *call = devPtr.data()->pair(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { +- emit devOperateErrorSignal(devPtr.data()->address()); ++ emit devOperateErrorSignal(devPtr.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); + } else + AudioDevConnectFunc(devPtr); + }); +@@ -415,7 +425,9 @@ void SessionDbusRegister::devDisconnect(const QString addr) + BluezQt::PendingCall *call = devPtr.data()->disconnectFromDevice(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { +- emit devOperateErrorSignal(devPtr.data()->address()); ++ emit devOperateErrorSignal(devPtr.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); + } + }); + } +@@ -432,7 +444,9 @@ void SessionDbusRegister::devRemove(const QString addr) + BluezQt::PendingCall *call = Daemon::_DefualtAdapter.data()->removeDevice(devPtr); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { +- emit devOperateErrorSignal(devPtr.data()->address()); ++ emit devOperateErrorSignal(devPtr.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); + } else { + Config::removeKey(addr); + } +@@ -451,7 +465,9 @@ void SessionDbusRegister::devTrust(const QString addr,const bool trust) + BluezQt::PendingCall *call = devPtr.data()->setTrusted(trust); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { +- emit devOperateErrorSignal(devPtr.data()->address()); ++ emit devOperateErrorSignal(devPtr.data()->address(), ++ callReturn->error(), ++ callReturn->errorText()); + } + }); + } +diff --git a/service/sessiondbusregister.h b/service/sessiondbusregister.h +index 0cfcddf..92a2e41 100644 +--- a/service/sessiondbusregister.h ++++ b/service/sessiondbusregister.h +@@ -173,7 +173,7 @@ signals: + + void devRemoveSignal(QString); + +- void devOperateErrorSignal(QString); ++ void devOperateErrorSignal(QString,int,QString); + + //代理相关信号 + void sendFile(QString,QString); +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index 1a9c1a7..d2ff887 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -311,7 +311,12 @@ void BlueToothMain::monitorBluetoothDbusConnection() + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, +- "devStatusChange",this, SLOT(reportDevStatusChange(QString))); ++ "requestConfirmation",this, SLOT(reportRequestConfirmation(QString,QString))); ++ ++ QDBusConnection::sessionBus().connect(SERVICE, ++ PATH, ++ INTERFACE, ++ "devOperateErrorSignal",this, SLOT(reportDevOperateErrorSignal(QString,int,QString))); + + } + +@@ -622,6 +627,19 @@ void BlueToothMain::reportDevTypeChangedSignal(QString deviceAddress,QString cha + } + } + ++ ++void BlueToothMain::reportRequestConfirmation(QString deviceName,QString disPinCode) ++{ ++ qDebug() << Q_FUNC_INFO << deviceName << disPinCode << __LINE__; ++ m_device_pin_flag = true; ++} ++ ++void BlueToothMain::reportDevOperateErrorSignal(QString deviceAddress , int ErrorId , QString ErrorText) ++{ ++ qDebug() << Q_FUNC_INFO << deviceAddress << ErrorId << ErrorText << __LINE__; ++ m_device_pin_flag = false; ++} ++ + bluetoothdevice * BlueToothMain::createOneBluetoothDevice(QString devAddress) + { + qDebug() << Q_FUNC_INFO << devAddress << __LINE__; +diff --git a/ukcc-bluetooth/bluetoothmain.h b/ukcc-bluetooth/bluetoothmain.h +index 8502a5b..6a39def 100644 +--- a/ukcc-bluetooth/bluetoothmain.h ++++ b/ukcc-bluetooth/bluetoothmain.h +@@ -87,6 +87,9 @@ private slots: + void reportDevConnectStatusSignal(QString,bool); + void reportDevNameChangedSignal(QString,QString); + void reportDevTypeChangedSignal(QString,QString); ++ void reportRequestConfirmation(QString,QString); ++ void reportDevOperateErrorSignal(QString,int,QString); ++ + //receive + void receiveConnectsignal(QString); + void receiveDisConnectSignal(QString); +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 6e69886..6b64e36 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -80,8 +80,15 @@ void DeviceInfoItem::InitMemberVariables() + }); + + _devConnTimer = new QTimer(this); +- _devConnTimer->setInterval(8000); ++ _devConnTimer->setInterval(5000); + connect(_devConnTimer,&QTimer::timeout,this,[=]{ ++ if(BlueToothMain::m_device_pin_flag) ++ { ++ _devConnTimer->stop(); ++ _devConnTimer->start(); ++ return; ++ } ++ + emit devConnectionComplete(); + _devConnTimer->stop(); + _iconTimer->stop(); +@@ -208,6 +215,7 @@ void DeviceInfoItem::setDeviceConnectSignals() + connect(_MDev,&bluetoothdevice::pairedChanged,this,[=](bool paired) + { + qDebug() << Q_FUNC_INFO << "pairedChanged" << __LINE__; ++ BlueToothMain::m_device_pin_flag = false; + if(_devConnTimer->isActive()) + _devConnTimer->stop(); + if (_iconTimer->isActive()) +@@ -236,6 +244,7 @@ void DeviceInfoItem::setDeviceConnectSignals() + + connect(_MDev,&bluetoothdevice::connectedChanged,this,[=](bool connected) + { ++ BlueToothMain::m_device_pin_flag = false; + if(_devConnTimer->isActive()) + _devConnTimer->stop(); + if (_iconTimer->isActive()) diff --git a/patches/ukcc_bluetooth_power_refresh_error.patch b/patches/ukcc_bluetooth_power_refresh_error.patch new file mode 100644 index 0000000..45c38a7 --- /dev/null +++ b/patches/ukcc_bluetooth_power_refresh_error.patch @@ -0,0 +1,278 @@ +diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp +index c38f086..d2e1c17 100644 +--- a/ukcc-bluetooth/bluetoothmain.cpp ++++ b/ukcc-bluetooth/bluetoothmain.cpp +@@ -18,6 +18,7 @@ + #include + + bool BlueToothMain::m_device_operating = false; ++bool BlueToothMain::m_device_pin_flag = false; + + //extern "C" { + // #include +@@ -403,11 +404,8 @@ bluetoothadapter * BlueToothMain::createOneBluetoothAdapter(QString adapter_addr + false, + false); + +- adapter_dev->setObjectName(adapter_address); + qDebug () << Q_FUNC_INFO << adapter_address << "create ok!" << __LINE__; +- + return adapter_dev; +- + } + + +@@ -542,48 +540,15 @@ void BlueToothMain::reportDefaultAdapterPowerChanged(bool isPower) + m_current_adapter_power_swtich = isPower; + + if (isPower && !m_open_bluetooth_btn->isChecked()) ++ { ++ m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(true); +- ++ } + if (!isPower && m_open_bluetooth_btn->isChecked()) ++ { ++ m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(false); +- +-// if(m_settings) +-// m_settings->set("switch",QVariant::fromValue(isPower)); +- +-// if(isPower) +-// { +-// bluetooth_name->set_dev_name(m_default_adapter_name); +-// bluetooth_name->setVisible(true); +-// frame_bottom->setVisible(true); +- +-// frame_middle->setVisible(m_myDev_show_flag); +- +-// if (!m_open_bluetooth_btn->isChecked()) +-// m_open_bluetooth_btn->setChecked(true); +- +-// delayStartDiscover_timer->start(); +- +-// //this->refreshBluetoothAdapterInterfaceUI(); +-// } +-// else +-// { +-//// if (bluetooth_name->isVisible()) +-//// bluetooth_name->setVisible(false); +- +-// if (m_open_bluetooth_btn->isChecked()) +-// m_open_bluetooth_btn->setChecked(false); +- +-// if (frame_bottom->isVisible()) +-// frame_bottom->setVisible(false); +- +-// if(frame_middle->isVisible()) +-// frame_middle->setVisible(false); +- +-// if (!paired_dev_layout->isEmpty()) +-// m_myDev_show_flag = true ; +-// else +-// m_myDev_show_flag = false ; +-// } ++ } + } + + +@@ -694,11 +659,6 @@ bluetoothdevice * BlueToothMain::createOneBluetoothDevice(QString devAddress) + } + } + +-// dev = new bluetoothdevice(dev_name, +-// devAddress, +-// dev_type, +-// isPaired?bluetoothdevice::DEVICE_STATUS::PairedAndUnlinked:bluetoothdevice::DEVICE_STATUS::UnpairAndUnlinked, +-// isPaired); + dev = new bluetoothdevice(dev_name, + devAddress, + dev_type, +@@ -706,8 +666,6 @@ bluetoothdevice * BlueToothMain::createOneBluetoothDevice(QString devAddress) + isConnected, + isPaired); + +-// dev->devPairedChanged(isPaired); +-// dev->devConnectedChanged(isConnected); + + + return dev; +@@ -1800,6 +1758,10 @@ void BlueToothMain::changeDeviceParentWindow(const QString &address) + line_item->deleteLater(); + } + ++ //设备配对成功后,先读取设备的连接状态,设置对应的设备状态 ++ bool isConnect = getDevConnectStatus(address); ++ reportDevConnectStatusSignal(address,isConnect); ++ + mDevFrameAddLineFrame("paired",address); + paired_dev_layout->addWidget(item); + m_myDev_show_flag = true; +@@ -1812,14 +1774,20 @@ void BlueToothMain::onClick_Open_Bluetooth(bool ischeck) + { + qDebug() << Q_FUNC_INFO << ischeck << (dynamic_cast(sender()) == nullptr); + ++// if (m_service_dbus_adapter_power_change_flag) ++// disconnect(m_open_bluetooth_btn,SIGNAL(checkedChanged(bool)),nullptr,nullptr); ++ + if (dynamic_cast(sender()) == nullptr) + { + m_open_bluetooth_btn->setChecked(ischeck); + } + else + { +- setDefaultAdapterPower(ischeck); +-// bluetooth_name->setVisible(ischeck); ++ if (!m_service_dbus_adapter_power_change_flag) //不由服务发送的设置 ++ { ++ setDefaultAdapterPower(ischeck); ++ } ++ // bluetooth_name->setVisible(ischeck); + } + if(ischeck && m_myDev_show_flag) + frame_middle->setVisible(ischeck); +@@ -1848,6 +1816,11 @@ void BlueToothMain::onClick_Open_Bluetooth(bool ischeck) + stopAllTimer(); + } + ++ if (m_service_dbus_adapter_power_change_flag) ++ { ++ m_service_dbus_adapter_power_change_flag = false; ++ } ++ + return; + } + +@@ -1864,15 +1837,15 @@ void BlueToothMain::refreshLoadLabelIcon() + { + if("normalWidget" == _MCentralWidget->currentWidget()->objectName()) + { +- if(i == 0) +- i = 7; ++ if(i > 7) ++ i = 0; + if (isblack) + loadLabel->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("ukui-loading-"+QString::number(i,10)).pixmap(18,18),"white")); + else + loadLabel->setPixmap(QIcon::fromTheme("ukui-loading-"+QString::number(i,10)).pixmap(18,18)); + + loadLabel->update(); +- i--; ++ i++; + } + } + +@@ -2056,9 +2029,9 @@ void BlueToothMain::monitorSleepSlot(bool value) + + void BlueToothMain::adapterPoweredChanged(bool value) + { +- qDebug() << Q_FUNC_INFO <set("switch",QVariant::fromValue(value)); ++ qDebug() << Q_FUNC_INFO << value; ++// if(m_settings) ++// m_settings->set("switch",QVariant::fromValue(value)); + + if(value) + { +diff --git a/ukcc-bluetooth/bluetoothmain.h b/ukcc-bluetooth/bluetoothmain.h +index 9f25af3..8502a5b 100644 +--- a/ukcc-bluetooth/bluetoothmain.h ++++ b/ukcc-bluetooth/bluetoothmain.h +@@ -64,6 +64,7 @@ protected: + + public: + static bool m_device_operating ; ++ static bool m_device_pin_flag ; + void setbluetoothAdapterDiscoveringStatus(bool); + signals: + void sendAdapterNameChangeSignal(const QString &value); +@@ -140,6 +141,9 @@ private: + bool m_myDev_show_flag = false; + bool isblack = false; + ++ ++ bool m_service_dbus_adapter_power_change_flag = false; ++ + bool m_current_adapter_power_swtich; + bool m_current_adapter_disconvery_swtich; + bool m_current_bluetooth_block_status; +diff --git a/ukcc-bluetooth/devicebase.cpp b/ukcc-bluetooth/devicebase.cpp +index 0304db2..4279e7a 100644 +--- a/ukcc-bluetooth/devicebase.cpp ++++ b/ukcc-bluetooth/devicebase.cpp +@@ -20,6 +20,7 @@ bluetoothadapter::bluetoothadapter(QString dev_name , + ,m_dev_discoverable(dev_discoverable) + { + qDebug() << Q_FUNC_INFO << __LINE__; ++ this->setObjectName(dev_address); + + } + +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 664cd52..a82c9ef 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -73,9 +73,9 @@ void DeviceInfoItem::InitMemberVariables() + _iconTimer = new QTimer(this); + _iconTimer->setInterval(110); + connect(_iconTimer,&QTimer::timeout,this,[=]{ +- if (iconFlag == 0) +- iconFlag = 7; +- iconFlag--; ++// if (iconFlag == 0) ++// iconFlag = 7; ++// iconFlag--; + update(); + }); + +@@ -564,9 +564,9 @@ QPixmap DeviceInfoItem::getDevTypeIcon() + + //if (_themeIsBlack && (Status::Nomal == _MStatus)) { + if (_themeIsBlack) { +- icon = ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme(iconName).pixmap(18,18),"white"); ++ icon = ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme(iconName).pixmap(16,16),"white"); + } else { +- icon = QIcon::fromTheme(iconName).pixmap(18,18); ++ icon = QIcon::fromTheme(iconName).pixmap(16,16); + } + + return icon; +@@ -790,7 +790,8 @@ void DeviceInfoItem::DrawFuncBtn(QPainter &painter) + void DeviceInfoItem::DrawLoadingIcon(QPainter &painter) + { + painter.save(); +- ++ if (iconFlag >= 7) ++ iconFlag = 0; + if (_themeIsBlack) + style()->drawItemPixmap(&painter, + getLoadIconRect(), +@@ -803,6 +804,8 @@ void DeviceInfoItem::DrawLoadingIcon(QPainter &painter) + ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("ukui-loading-"+QString::number(iconFlag)).pixmap(20),"default")); + + painter.restore(); ++ iconFlag++; ++ + } + + /************************************************ +diff --git a/ukcc-bluetooth/devrenamedialog.cpp b/ukcc-bluetooth/devrenamedialog.cpp +index 2546ea0..2fdfbbd 100644 +--- a/ukcc-bluetooth/devrenamedialog.cpp ++++ b/ukcc-bluetooth/devrenamedialog.cpp +@@ -77,7 +77,12 @@ void DevRenameDialog::initUI() + + closeBtn = new QPushButton(this); + closeBtn->setGeometry(453,8,20,20); +- closeBtn->setIcon(QIcon::fromTheme("application-exit-symbolic")); ++ //closeBtn->setIcon(QIcon::fromTheme("application-exit-symbolic")); ++ closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic")); ++ closeBtn->setFlat(true); ++ //closeBtn->setFixedSize(QSize(20,20)); ++ closeBtn->setProperty("isWindowButton",0x2); ++ closeBtn->setProperty("useIconHighlihtEffect",0x8); + connect(closeBtn,&QPushButton::clicked,this,[=]{ + this->close(); + }); diff --git a/patches/ukcc_bluetooth_s4_core.patch b/patches/ukcc_bluetooth_s4_core.patch new file mode 100644 index 0000000..eb921e1 --- /dev/null +++ b/patches/ukcc_bluetooth_s4_core.patch @@ -0,0 +1,32 @@ +diff --git a/service/daemon.cpp b/service/daemon.cpp +index 16b52fe..ebdd877 100644 +--- a/service/daemon.cpp ++++ b/service/daemon.cpp +@@ -658,7 +658,13 @@ void Daemon::launchDbusSignal() + void Daemon::reconnectFunc() + { + qInfo() << Q_FUNC_INFO << "START"; +- QTimer::singleShot(400,this,[=]{ ++ QTimer::singleShot(1000,this,[=]{ ++ ++ if (nullptr == _DefualtAdapter) ++ { ++ qInfo() << Q_FUNC_INFO << "_DefualtAdapter is null!!"; ++ return ; ++ } + + if (!_DefualtAdapter.data()->isPowered()) { + qInfo() << Q_FUNC_INFO << "Adapter is power down;"; +diff --git a/ukcc-bluetooth/bluetoothnamelabel.cpp b/ukcc-bluetooth/bluetoothnamelabel.cpp +index 29a299d..fa2dcfb 100644 +--- a/ukcc-bluetooth/bluetoothnamelabel.cpp ++++ b/ukcc-bluetooth/bluetoothnamelabel.cpp +@@ -45,7 +45,7 @@ BluetoothNameLabel::BluetoothNameLabel(QWidget *parent, int x, int y): + style_flag = false; + icon_pencil->setPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20)); + } +- switch (settings->get("systemFontSize").toInt()) { ++ switch (settings->get("system-font-size").toInt()) { + case 11: + case 12: + case 13: diff --git a/patches/ukcc_bluetooth_show_state_error.patch b/patches/ukcc_bluetooth_show_state_error.patch new file mode 100644 index 0000000..ea7a74e --- /dev/null +++ b/patches/ukcc_bluetooth_show_state_error.patch @@ -0,0 +1,63 @@ +diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp +index 8de3b66..29eb44d 100644 +--- a/ukcc-bluetooth/deviceinfoitem.cpp ++++ b/ukcc-bluetooth/deviceinfoitem.cpp +@@ -237,10 +237,14 @@ void DeviceInfoItem::setDeviceConnectSignals() + { + qDebug() << Q_FUNC_INFO << "pairedChanged" << __LINE__; + //BlueToothMain::m_device_pin_flag = false; +- if(_devConnTimer->isActive()) +- _devConnTimer->stop(); +- if (_iconTimer->isActive()) +- _iconTimer->stop(); ++ if(paired && _MDev->isConnected()) ++ { ++ if(_devConnTimer->isActive()) ++ _devConnTimer->stop(); ++ if (_iconTimer->isActive()) ++ _iconTimer->stop(); ++ } ++ + if (paired) + { + qDebug() << Q_FUNC_INFO << "pairedChanged" << __LINE__; +@@ -277,17 +281,17 @@ void DeviceInfoItem::setDeviceConnectSignals() + } else if (!_MDev->isPaired() && connected) { + _DevStatus = DEVSTATUS::Connecting; + } else if (_MDev->isPaired() && !connected){ +- if (_DevStatus == DEVSTATUS::Connecting) +- _DevStatus = DEVSTATUS::ConnectFailed; +- else if (_DevStatus != DEVSTATUS::ConnectFailed && +- _DevStatus != DEVSTATUS::DisConnectFailed) ++// if (_DevStatus == DEVSTATUS::Connecting) ++// _DevStatus = DEVSTATUS::ConnectFailed; ++// else if (_DevStatus != DEVSTATUS::ConnectFailed && ++// _DevStatus != DEVSTATUS::DisConnectFailed) + _DevStatus = DEVSTATUS::Paired; + } else { +- if (_DevStatus == DEVSTATUS::Connecting && !connected) +- _DevStatus = DEVSTATUS::ConnectFailed; +- else if (_DevStatus == DEVSTATUS::DisConnecting && connected) +- _DevStatus = DEVSTATUS::DisConnectFailed; +- else ++// if (_DevStatus == DEVSTATUS::Connecting && !connected) ++// _DevStatus = DEVSTATUS::ConnectFailed; ++// else if (_DevStatus == DEVSTATUS::DisConnecting && connected) ++// _DevStatus = DEVSTATUS::DisConnectFailed; ++// else + _DevStatus = DEVSTATUS::ConnectFailed; + } + +@@ -310,9 +314,9 @@ void DeviceInfoItem::setDeviceConnectSignals() + + //qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; + //BlueToothMain::m_device_pin_flag = false; +- if (_MDev->isConnected()) +- _DevStatus = DEVSTATUS::DisConnectFailed; +- else ++ //if (_MDev->isConnected()) ++ // _DevStatus = DEVSTATUS::DisConnectFailed; ++ //else + _DevStatus = DEVSTATUS::ConnectFailed; + update(); + TimedRestoreConnectionErrorDisplay(); diff --git a/patches/ukcc_bluetooth_ui_error.patch b/patches/ukcc_bluetooth_ui_error.patch new file mode 100644 index 0000000..a810422 --- /dev/null +++ b/patches/ukcc_bluetooth_ui_error.patch @@ -0,0 +1,139 @@ +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -17,6 +17,8 @@ + #include + #include + ++bool BlueToothMain::m_device_operating = false; ++ + extern "C" { + #include + #include +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.h ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.h +@@ -63,6 +63,7 @@ protected: + //dev-3.1 界面服务分离 + + public: ++ static bool m_device_operating ; + void setbluetoothAdapterDiscoveringStatus(bool); + signals: + void sendAdapterNameChangeSignal(const QString &value); +Index: ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/deviceinfoitem.cpp ++++ ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.cpp +@@ -20,7 +20,7 @@ DeviceInfoItem::DeviceInfoItem(QWidget * + m_str_dev_connecting = tr("Connecting"); + m_str_dev_disconnecting = tr("Disconnecting"); + m_str_dev_connected = tr("Connected"); +- m_str_dev_ununited = tr("Paired"); ++ m_str_dev_ununited = tr("Not Connected"); + m_str_dev_conn_fail = tr("Connect fail"); + m_str_dev_disconn_fail = tr("Disconnect fail"); + +@@ -318,8 +318,10 @@ void DeviceInfoItem::mousePressEvent(QMo + _pressBtnFlag = true; + } else { + _pressFlag = true; ++ _MStatus = Status::Check; + } + } ++ update(); + } + + void DeviceInfoItem::MouseClickedDevFunc() +@@ -384,8 +386,12 @@ void DeviceInfoItem::mouseReleaseEvent(Q + } else { + MouseClickedFunc(); + _pressFlag = false; ++ _MStatus = Status::Hover; ++ + } + } ++ update(); ++ + } + + void DeviceInfoItem::mouseMoveEvent(QMouseEvent *event) +@@ -461,9 +467,17 @@ QColor DeviceInfoItem::getPainterBrushCo + + break; + case Status::Hover: +- color = QColor("#D7D7D7"); ++ if(_themeIsBlack) ++ color = QColor("#37373B"); ++ else ++ color = QColor("#D1D1D1"); ++ break; ++ case Status::Check: ++ if(_themeIsBlack) ++ color = QColor("#4B4B4F"); ++ else ++ color = QColor("#D9D9D9"); + break; +- + default: + if(_themeIsBlack) + color = QColor("#1F2022");//("#EBEBEB"); +@@ -472,7 +486,7 @@ QColor DeviceInfoItem::getPainterBrushCo + //color = QColor(Qt::white);//("#EBEBEB"); + break; + } +- if (_MStatus == Status::Hover || _themeIsBlack) ++ if (_MStatus == Status::Hover || _MStatus == Status::Check || _themeIsBlack) + color.setAlpha(50); + return color; + } +@@ -538,7 +552,8 @@ QPixmap DeviceInfoItem::getDevTypeIcon() + iconName = "bluetooth-active-symbolic"; + } + +- if (_themeIsBlack && (Status::Nomal == _MStatus)) { ++ //if (_themeIsBlack && (Status::Nomal == _MStatus)) { ++ if (_themeIsBlack) { + icon = ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme(iconName).pixmap(18,18),"white"); + } else { + icon = QIcon::fromTheme(iconName).pixmap(18,18); +@@ -586,9 +601,9 @@ void DeviceInfoItem::DrawText(QPainter & + else + painter.setPen(QColor(Qt::black)); + +- if (_MStatus == Status::Hover) { +- painter.setPen(QColor(Qt::black)); +- } ++// if (_MStatus == Status::Hover) { ++// painter.setPen(QColor(Qt::black)); ++// } + + painter.drawText(70,20,380,30,Qt::AlignLeft,_MDev? _MDev->getDevName(): QString("Example")); + painter.restore(); +@@ -613,6 +628,7 @@ void DeviceInfoItem::DrawStatusText(QPai + switch (_DevStatus) { + case DEVSTATUS::Paired: + str = m_str_dev_ununited; ++ painter.setPen(QColor("#818181")); + break; + case DEVSTATUS::Connected: + str = m_str_dev_connected; +@@ -757,3 +773,4 @@ void DeviceInfoItem::DevConnectFunc() + // } + } + } ++ +Index: ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/deviceinfoitem.h ++++ ukui-bluetooth/ukcc-bluetooth/deviceinfoitem.h +@@ -33,6 +33,7 @@ public: + enum Status{ + Hover = 0, + Nomal, ++ Check, + }; + Q_ENUM(Status) + diff --git a/patches/ukcc_pullup_bluetoothService.patch b/patches/ukcc_pullup_bluetoothService.patch new file mode 100644 index 0000000..abc69c1 --- /dev/null +++ b/patches/ukcc_pullup_bluetoothService.patch @@ -0,0 +1,341 @@ +Index: ukui-bluetooth/ukcc-bluetooth/bluetooth.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetooth.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetooth.cpp +@@ -10,6 +10,37 @@ Bluetooth::Bluetooth() : mFirstLoad(true + translator->load("/usr/share/ukui-bluetooth/translations/ukcc-bluetooth_" + QLocale::system().name() + ".qm"); + QApplication::installTranslator(translator); + ++ QList btServiceProcessId; ++ bool m_bluetooth_service_process_flag = ukccbluetoothconfig::checkProcessRunning(BluetoothServiceExePath/*"bluetoothService"*/,btServiceProcessId); ++ ++ for(quint64 tempId : btServiceProcessId) ++ { ++ qDebug () << Q_FUNC_INFO << "========================" << tempId; ++ } ++ ++ if (m_bluetooth_service_process_flag) ++ { ++ qDebug () << Q_FUNC_INFO << BluetoothServiceExePath << "is Running" ; ++ } ++ else ++ { ++ qDebug () << Q_FUNC_INFO << BluetoothServiceExePath << "is not Running" ; ++ ++ QList btTrayProcessId; ++ bool m_ukui_bluetooth_process_flag = ukccbluetoothconfig::checkProcessRunning(BluetoothTrayExePath,btTrayProcessId); ++ if (m_ukui_bluetooth_process_flag) ++ { ++ qDebug () << Q_FUNC_INFO << BluetoothTrayExePath << "is Running" ; ++ for (quint64 processId:btTrayProcessId) ++ { ++ ukccbluetoothconfig::killAppProcess(processId); ++ } ++ } ++ ukccbluetoothconfig::launchBluetoothServiceStart(); ++ } ++ ++ ++ + pluginName = tr("Bluetooth"); + bool intel = QFile::exists("/etc/apt/ota_version"); + if (intel) +Index: ukui-bluetooth/ukcc-bluetooth/bluetooth.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetooth.h ++++ ukui-bluetooth/ukcc-bluetooth/bluetooth.h +@@ -8,7 +8,7 @@ + + #include "bluetoothmain.h" + #include "bluetoothmainwindow.h" +- ++#include "ukccbluetoothconfig.h" + + class Bluetooth : public QObject, CommonInterface + { +Index: ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/bluetoothmain.cpp ++++ ukui-bluetooth/ukcc-bluetooth/bluetoothmain.cpp +@@ -189,6 +189,7 @@ BlueToothMain::BlueToothMain(QWidget *pa + // translator.load("/usr/share/ukui-bluetooth/translations/ukcc-bluetooth_" + QLocale::system().name() + ".qm"); + // QApplication::installTranslator(&translator); + ++ + if(QGSettings::isSchemaInstalled("org.ukui.bluetooth")) + { + m_settings = new QGSettings("org.ukui.bluetooth"); +@@ -465,7 +466,7 @@ void BlueToothMain::refreshBluetoothAdap + } + } + +- refreshUIWhenAdapterChanged(); ++ //refreshUIWhenAdapterChanged(); + } + + void BlueToothMain::addAdapterDataList(QString adapterAddress) +@@ -1988,7 +1989,7 @@ void BlueToothMain::adapterComboxChanged + m_bluetooth_adapter_list.at(i)->setDevPower(m_current_adapter_power_swtich); + m_bluetooth_adapter_list.at(i)->setDevDiscovering(m_current_adapter_scan_status); + m_bluetooth_adapter_list.at(i)->setDevDiscoverable(m_current_adapter_disconvery_swtich); +- refreshUIWhenAdapterChanged(); ++ //refreshUIWhenAdapterChanged(); + if(m_settings) + m_settings->set("adapter-address",QVariant::fromValue(m_adapter_address_list.at(i))); + Default_Adapter = m_adapter_address_list.at(i); +Index: ukui-bluetooth/ukcc-bluetooth/config.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/config.h ++++ ukui-bluetooth/ukcc-bluetooth/config.h +@@ -1,57 +1,9 @@ + #ifndef CONFIG_H + #define CONFIG_H + +-//enum DEVICE_TYPE{ +-// /** The device is a phone. */ +-// Phone = 0, +-// /** The device is a modem. */ +-// Modem, +-// /** The device is a computer. */ +-// Computer, +-// /** The device is a network. */ +-// Network, +-// /** The device is a headset. */ +-// Headset, +-// /** The device is a headphones. */ +-// Headphones, +-// /** The device is an uncategorized audio video device. */ +-// AudioVideo, +-// /** The device is a keyboard. */ +-// Keyboard, +-// /** The device is a mouse. */ +-// Mouse, +-// /** The device is a joypad. */ +-// Joypad, +-// /** The device is a graphics tablet (input device). */ +-// Tablet, +-// /** The deivce is an uncategorized peripheral device. */ +-// Peripheral, +-// /** The device is a camera. */ +-// Camera, +-// /** The device is a printer. */ +-// Printer, +-// /** The device is an uncategorized imaging device. */ +-// Imaging, +-// /** The device is a wearable device. */ +-// Wearable, +-// /** The device is a toy. */ +-// Toy, +-// /** The device is a health device. */ +-// Health, +-// /** The device is not of any of the known types. */ +-// Uncategorized +-//}; +-//Q_ENUM(DEVICE_TYPE); +- +- +-//enum DEVICE_STATUS{ +-// Unkown = 0, +-// UnpairAndUnlinked, // +-// UnpairAndLinked, +-// PairedAndUnlinked, +-// PairedAndLinked, +-// Error +-//}; +-////Q_ENUM(DEVICE_STATUS); ++#define BluetoothServiceExePath "/usr/bin/bluetoothService" ++#define BluetoothTrayExePath "/usr/bin/ukui-bluetooth" ++#define BluetoothServiceName "bluetoothService" ++#define BluetoothTrayName "ukui-bluetooth" + + #endif // CONFIG_H +Index: ukui-bluetooth/ukcc-bluetooth/devrenamedialog.cpp +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/devrenamedialog.cpp ++++ ukui-bluetooth/ukcc-bluetooth/devrenamedialog.cpp +@@ -118,6 +118,21 @@ void DevRenameDialog::initUI() + }); + } + ++ ++void DevRenameDialog::lineEditSlot(const QString &str) ++{ ++ if (str.length() > 0 && str.length() < 21) { ++ acceptBtn->setDisabled(false); ++ tipLabel->setVisible(false); ++ } else if (0 == str.length()) { ++ acceptBtn->setDisabled(true); ++ tipLabel->setVisible(false); ++ }else { ++ tipLabel->setVisible(true); ++ acceptBtn->setDisabled(true); ++ } ++} ++ + void DevRenameDialog::paintEvent(QPaintEvent *event) + { + Q_UNUSED(event) +@@ -135,16 +150,17 @@ void DevRenameDialog::paintEvent(QPaintE + painter.drawRoundedRect(this->rect(),12,12); + } + +-void DevRenameDialog::lineEditSlot(const QString &str) ++void DevRenameDialog::keyPressEvent(QKeyEvent * event) + { +- if (str.length() > 0 && str.length() < 21) { +- acceptBtn->setDisabled(false); +- tipLabel->setVisible(false); +- } else if (0 == str.length()) { +- acceptBtn->setDisabled(true); +- tipLabel->setVisible(false); +- }else { +- tipLabel->setVisible(true); +- acceptBtn->setDisabled(true); ++ Q_UNUSED(event) ++ switch(event->key()) ++ { ++ case Qt::Key_Enter: ++ emit acceptBtn->click(); ++ break; ++ case Qt::Key_Escape: ++ emit rejectBtn->click(); ++ break; + } ++ + } +Index: ukui-bluetooth/ukcc-bluetooth/devrenamedialog.h +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/devrenamedialog.h ++++ ukui-bluetooth/ukcc-bluetooth/devrenamedialog.h +@@ -11,6 +11,7 @@ + #include + #include + #include ++#include + + class DevRenameDialog : public QDialog + { +@@ -29,6 +30,7 @@ private slots: + + protected: + void paintEvent(QPaintEvent *); ++ void keyPressEvent(QKeyEvent *); + + public slots: + void lineEditSlot(const QString &); +Index: ukui-bluetooth/ukcc-bluetooth/ukcc-bluetooth.pro +=================================================================== +--- ukui-bluetooth.orig/ukcc-bluetooth/ukcc-bluetooth.pro ++++ ukui-bluetooth/ukcc-bluetooth/ukcc-bluetooth.pro +@@ -33,7 +33,8 @@ SOURCES += \ + deviceinfoitem.cpp \ + devremovedialog.cpp \ + devrenamedialog.cpp \ +- loadinglabel.cpp ++ loadinglabel.cpp \ ++ ukccbluetoothconfig.cpp + + HEADERS += \ + bluetooth.h \ +@@ -46,7 +47,8 @@ HEADERS += \ + deviceinfoitem.h \ + devremovedialog.h \ + devrenamedialog.h \ +- loadinglabel.h ++ loadinglabel.h \ ++ ukccbluetoothconfig.h + + TRANSLATIONS += \ + ukcc-bluetooth_zh_CN.ts \ +Index: ukui-bluetooth/ukcc-bluetooth/ukccbluetoothconfig.cpp +=================================================================== +--- /dev/null ++++ ukui-bluetooth/ukcc-bluetooth/ukccbluetoothconfig.cpp +@@ -0,0 +1,63 @@ ++#include "ukccbluetoothconfig.h" ++ ++ ++ ++ukccbluetoothconfig::ukccbluetoothconfig() ++{ ++ ++} ++ ++void ukccbluetoothconfig::launchBluetoothServiceStart() ++{ ++ qDebug () << Q_FUNC_INFO << __LINE__; ++ QProcess *process = new QProcess(); ++ QString cmd = BluetoothServiceExePath; ++ qDebug() << Q_FUNC_INFO; ++ process->startDetached(cmd); ++} ++ ++void ukccbluetoothconfig::killAppProcess(const quint64 &processId) ++{ ++// QString strCommand = "ps -ef|grep " + processName + " |grep -v grep |awk '{print $2}'"; ++// QList processId; ++// checkProcessRunning(processName,processId); ++// for(quint64 tempId : processId) ++// { ++ qDebug () << Q_FUNC_INFO << "========================" << processId; ++ QProcess *process = new QProcess(); ++ QString cmd = QString("kill -9 %1").arg(processId); ++ process->startDetached(cmd); ++// } ++} ++ ++bool ukccbluetoothconfig::checkProcessRunning(const QString &processName, QList &listProcessId) ++{ ++ qDebug() << Q_FUNC_INFO << __LINE__; ++ ++ bool res(false); ++ QString strCommand = "ps -ef|grep " + processName + " |grep -v grep |awk '{print $2}'"; ++ QByteArray ba = strCommand.toLatin1(); ++ const char* strFind_ComName = ba.data(); ++ //const char* strFind_ComName = convertQString2char(strCommand); ++ FILE * pPipe = popen(strFind_ComName, "r"); ++ if (pPipe) ++ { ++ std::string com; ++ char name[512] = { 0 }; ++ while (fgets(name, sizeof(name), pPipe) != NULL) ++ { ++ int nLen = strlen(name); ++ if (nLen > 0 ++ && name[nLen - 1] == '\n') ++ //&& name[0] == '/') ++ { ++ name[nLen - 1] = '\0'; ++ listProcessId.append(atoi(name)); ++ res = true; ++ break; ++ } ++ } ++ pclose(pPipe); ++ } ++ return res; ++} +Index: ukui-bluetooth/ukcc-bluetooth/ukccbluetoothconfig.h +=================================================================== +--- /dev/null ++++ ukui-bluetooth/ukcc-bluetooth/ukccbluetoothconfig.h +@@ -0,0 +1,19 @@ ++#ifndef UKCCBLUETOOTHCONFIG_H ++#define UKCCBLUETOOTHCONFIG_H ++ ++#include ++#include ++ ++#include "config.h" ++ ++class ukccbluetoothconfig ++{ ++public: ++ ukccbluetoothconfig(); ++ ++ static void launchBluetoothServiceStart(); ++ static void killAppProcess(const quint64 &processId); ++ static bool checkProcessRunning(const QString &processName, QList &listProcessId); ++}; ++ ++#endif // UKCCBLUETOOTHCONFIG_H diff --git a/profileDaemon/main.cpp b/profileDaemon/main.cpp new file mode 100644 index 0000000..f9956c5 --- /dev/null +++ b/profileDaemon/main.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +#include "sysdbusregister.h" + +int main(int argc, char *argv[]) +{ + QtSingleCoreApplication a(argc, argv); + a.setOrganizationName("Kylin Team"); + a.setApplicationName("system-bus-bluetooth-service"); + + if (a.isRunning()) { + qDebug() << "system-bus-bluetooth-service is Already running ! ! !"; + return EXIT_SUCCESS; + } else { + QDBusConnection systemBus = QDBusConnection::systemBus(); + if (!systemBus.registerService("com.bluetooth.systemdbus")){ + qCritical() << "QDbus register service failed reason:" << systemBus.lastError(); + //exit(1); + } + + if (!systemBus.registerObject("/", "com.bluetooth.interface", new SysDbusRegister(), QDBusConnection::ExportAllSlots)){ + qCritical() << "QDbus register object failed reason:" << systemBus.lastError(); + //exit(2); + } + // qDebug() << "ok"; + return a.exec(); + } +} + diff --git a/profileDaemon/profileDaemon.pro b/profileDaemon/profileDaemon.pro new file mode 100644 index 0000000..ad75fac --- /dev/null +++ b/profileDaemon/profileDaemon.pro @@ -0,0 +1,53 @@ +###################################################################### +# Automatically generated by qmake (3.1) Thu Mar 4 18:08:23 2021 +###################################################################### + +TEMPLATE = app +TARGET = profileDaemon +INCLUDEPATH += . + +include(../qtsingleapplication/qtsinglecoreapplication.pri) +include(../environment.pri) + +QT += core dbus +QT -= gui + +CONFIG += c++11 link_pkgconfig + +PKGCONFIG += gio-2.0 + +LIBS += -lglib-2.0 + +QMAKE_LFLAGS += -D_FORTIFY_SOURCE=2 -O2 + +ins1.files += ../data/com.bluetooth.systemdbus.conf +ins1.path = $$CONF_INSTALL_DIR +ins2.files += ../data/com.bluetooth.systemdbus.service +ins2.path = $$SERVICE_INSTALL_DIR +ins3.files += ../data/com.bluetooth.systemdbus.policy +ins3.path = $$ACTIONS_INSTALL_DIR +target.source += $$TARGET +target.path = $$BIN_INSTALL_DIR +INSTALLS += ins1 \ + ins2 \ + ins3 \ + target + +# The following define makes your compiler warn you if you use any +# feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +# Input +#HEADERS += +SOURCES += main.cpp \ + sysdbusregister.cpp + +HEADERS += \ + sysdbusregister.h diff --git a/profileDaemon/sysdbusregister.cpp b/profileDaemon/sysdbusregister.cpp new file mode 100644 index 0000000..32f3866 --- /dev/null +++ b/profileDaemon/sysdbusregister.cpp @@ -0,0 +1,124 @@ +#include "sysdbusregister.h" + +extern "C" { +#include +#include +#include +} + +SysDbusRegister::SysDbusRegister() +{ + qInfo() << Q_FUNC_INFO ; + + if (InterfaceAlreadyExists()) { + QDBusConnection systemBus = QDBusConnection::systemBus(); + if (!systemBus.registerService("com.bluetooth.systemdbus")) { + qCritical() << "QDbus register service failed reason:" << systemBus.lastError(); + } + + if (!systemBus.registerObject("/", "com.bluetooth.interface", this, QDBusConnection::ExportAllSlots)){ + qCritical() << "QDbus register object failed reason:" << systemBus.lastError(); + } + } +} + +SysDbusRegister::~SysDbusRegister() +{ + +} + +int SysDbusRegister::exitService() +{ + qApp->exit(0); + return 0; +} + +QString SysDbusRegister::writeKeyFile(QString devAddress, QString devName, qint32 type) +{ + qDebug() << Q_FUNC_INFO ; + if(devAddress.isNull()) + return QString("Address can not be empty ! ! !"); + if(devName.isNull()) + return QString("Name can not be empty ! ! !"); + if(devAddress.at(2) != ":" || + devAddress.at(5) != ":" || + devAddress.at(8) != ":" || + devAddress.at(11) != ":" || + devAddress.at(14) != ":") + return QString("arg0 is not an address ! ! !"); + + qDebug() << Q_FUNC_INFO << QFile::exists(LIST_PATH); + if(!QFile::exists(LIST_PATH)){ + QFile file(LIST_PATH); + file.open(QIODevice::WriteOnly|QIODevice::Text); + file.close(); + } + + GKeyFile *key_file = nullptr; + key_file = g_key_file_new(); + char *data; + gsize length = 0; + g_key_file_load_from_file(key_file,QString(LIST_PATH).toStdString().c_str(),G_KEY_FILE_NONE,NULL); + g_key_file_set_string(key_file,devAddress.toStdString().c_str(),"Name",devName.toStdString().c_str()); + g_key_file_set_string(key_file,devAddress.toStdString().c_str(),"Type",QString("%1").arg(type).toStdString().c_str()); + g_key_file_set_string(key_file,devAddress.toStdString().c_str(),"ConnectTime",QString::number(QDateTime::currentMSecsSinceEpoch() / 1000).toStdString().c_str()); + + + data = g_key_file_to_data(key_file,&length,NULL); + g_file_set_contents(QString(LIST_PATH).toStdString().c_str(),data,length,NULL); + g_free(data); + + g_key_file_free(key_file); + + return QString("Key write ok!!!"); +} + +QString SysDbusRegister::removeKeyFile(QString devAddress) +{ + qDebug() << Q_FUNC_INFO ; + if(devAddress.isNull()) + return QString("Address can not be empty ! ! !"); + if(devAddress.at(2) != ":" || + devAddress.at(5) != ":" || + devAddress.at(8) != ":" || + devAddress.at(11) != ":" || + devAddress.at(14) != ":") + return QString("arg0 is not an address ! ! !"); + + if(!QFile::exists(LIST_PATH)){ + QFile file(LIST_PATH); + file.open(QIODevice::WriteOnly|QIODevice::Text); + file.close(); + } + + GKeyFile *key_file = nullptr; + char *data; + gsize length = 0; + GError *error; + key_file = g_key_file_new(); + g_key_file_load_from_file(key_file,QString(LIST_PATH).toStdString().c_str(),G_KEY_FILE_NONE,NULL); + if(g_key_file_has_group(key_file,devAddress.toStdString().c_str())){ + g_key_file_remove_group(key_file,devAddress.toStdString().c_str(),&error); + data = g_key_file_to_data(key_file,&length,NULL); + g_file_set_contents(QString(LIST_PATH).toStdString().c_str(),data,length,NULL); + g_free(data); + } + g_key_file_free(key_file); + + return QString("Key remove ok!!!"); +} + +QString SysDbusRegister::getKeyFilePath() +{ + return QString(LIST_PATH); +} + +bool SysDbusRegister::InterfaceAlreadyExists() +{ + QDBusConnection conn = QDBusConnection::systemBus(); + if (!conn.isConnected()) + return 0; + + QDBusReply reply = conn.interface()->call("GetNameOwner", "com.ukui.bluetooth"); + return reply.value() == ""; +} diff --git a/profileDaemon/sysdbusregister.h b/profileDaemon/sysdbusregister.h new file mode 100644 index 0000000..585233f --- /dev/null +++ b/profileDaemon/sysdbusregister.h @@ -0,0 +1,33 @@ +#ifndef SYSDBUSREGISTER_H +#define SYSDBUSREGISTER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LIST_PATH "/etc/pairDevice.list" + +class SysDbusRegister : public QObject, protected QDBusContext +{ + Q_OBJECT + + Q_CLASSINFO("D-Bus Interface", "com.bluetooth.interface") +public: + SysDbusRegister(); + ~SysDbusRegister(); +private: + bool InterfaceAlreadyExists(); +public slots: + Q_SCRIPTABLE int exitService(); + Q_SCRIPTABLE QString writeKeyFile(QString,QString,qint32); + Q_SCRIPTABLE QString removeKeyFile(QString); + Q_SCRIPTABLE QString getKeyFilePath(); +}; + +#endif // SYSDBUSREGISTER_H diff --git a/qtsingleapplication/QtLockedFile b/qtsingleapplication/QtLockedFile new file mode 100644 index 0000000..16b48ba --- /dev/null +++ b/qtsingleapplication/QtLockedFile @@ -0,0 +1 @@ +#include "qtlockedfile.h" diff --git a/qtsingleapplication/QtSingleApplication b/qtsingleapplication/QtSingleApplication new file mode 100644 index 0000000..d111bf7 --- /dev/null +++ b/qtsingleapplication/QtSingleApplication @@ -0,0 +1 @@ +#include "qtsingleapplication.h" diff --git a/qtsingleapplication/QtSingleCoreApplication b/qtsingleapplication/QtSingleCoreApplication new file mode 100644 index 0000000..bf8e6c0 --- /dev/null +++ b/qtsingleapplication/QtSingleCoreApplication @@ -0,0 +1 @@ +#include "qtsinglecoreapplication.h" diff --git a/qtsingleapplication/qtlocalpeer.cpp b/qtsingleapplication/qtlocalpeer.cpp new file mode 100644 index 0000000..f3c4546 --- /dev/null +++ b/qtsingleapplication/qtlocalpeer.cpp @@ -0,0 +1,213 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qtlocalpeer.h" +#include +#include +#include + +#if defined(Q_OS_WIN) +#include +#include +typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*); +static PProcessIdToSessionId pProcessIdToSessionId = 0; +#endif +#if defined(Q_OS_UNIX) +#include +#include +#include +#endif + +namespace QtLP_Private { +#include "qtlockedfile.cpp" +#if defined(Q_OS_WIN) +#include "qtlockedfile_win.cpp" +#else +#include "qtlockedfile_unix.cpp" +#endif +} + +const char* QtLocalPeer::ack = "ack"; + +QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) + : QObject(parent), id(appId) +{ + QString prefix = id; + if (id.isEmpty()) { + id = QCoreApplication::applicationFilePath(); +#if defined(Q_OS_WIN) + id = id.toLower(); +#endif + prefix = id.section(QLatin1Char('/'), -1); + } + prefix.remove(QRegExp("[^a-zA-Z]")); + prefix.truncate(6); + + QByteArray idc = id.toUtf8(); + quint16 idNum = qChecksum(idc.constData(), idc.size()); + socketName = QLatin1String("qtsingleapp-") + prefix + + QLatin1Char('-') + QString::number(idNum, 16); + +#if defined(Q_OS_WIN) + if (!pProcessIdToSessionId) { + QLibrary lib("kernel32"); + pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId"); + } + if (pProcessIdToSessionId) { + DWORD sessionId = 0; + pProcessIdToSessionId(GetCurrentProcessId(), &sessionId); + socketName += QLatin1Char('-') + QString::number(sessionId, 16); + } +#else + socketName += QLatin1Char('-') + QString::number(::getuid(), 16); +#endif + + server = new QLocalServer(this); + QString lockName = QDir(QDir::tempPath()).absolutePath() + + QLatin1Char('/') + socketName + + QLatin1String("-lockfile"); + lockFile.setFileName(lockName); + lockFile.open(QIODevice::ReadWrite); +} + + + +bool QtLocalPeer::isClient() +{ + if (lockFile.isLocked()) + return false; + + if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) + return true; + + bool res = server->listen(socketName); +#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) + // ### Workaround + if (!res && server->serverError() == QAbstractSocket::AddressInUseError) { + QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName); + res = server->listen(socketName); + } +#endif + if (!res) + qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); + QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection())); + return false; +} + + +bool QtLocalPeer::sendMessage(const QString &message, int timeout) +{ + if (!isClient()) + return false; + + QLocalSocket socket; + bool connOk = false; + for(int i = 0; i < 2; i++) { + // Try twice, in case the other instance is just starting up + socket.connectToServer(socketName); + connOk = socket.waitForConnected(timeout/2); + if (connOk || i) + break; + int ms = 250; +#if defined(Q_OS_WIN) + Sleep(DWORD(ms)); +#else + struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; + nanosleep(&ts, NULL); +#endif + } + if (!connOk) + return false; + + QByteArray uMsg(message.toUtf8()); + QDataStream ds(&socket); + ds.writeBytes(uMsg.constData(), uMsg.size()); + bool res = socket.waitForBytesWritten(timeout); + if (res) { + res &= socket.waitForReadyRead(timeout); // wait for ack + if (res) + res &= (socket.read(qstrlen(ack)) == ack); + } + return res; +} + + +void QtLocalPeer::receiveConnection() +{ + QLocalSocket* socket = server->nextPendingConnection(); + if (!socket) + return; + + while (true) { + if (socket->state() == QLocalSocket::UnconnectedState) { + qWarning("QtLocalPeer: Peer disconnected"); + delete socket; + return; + } + if (socket->bytesAvailable() >= qint64(sizeof(quint32))) + break; + socket->waitForReadyRead(); + } + + QDataStream ds(socket); + QByteArray uMsg; + quint32 remaining; + ds >> remaining; + uMsg.resize(remaining); + int got = 0; + char* uMsgBuf = uMsg.data(); + do { + got = ds.readRawData(uMsgBuf, remaining); + remaining -= got; + uMsgBuf += got; + } while (remaining && got >= 0 && socket->waitForReadyRead(2000)); + if (got < 0) { + qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData()); + delete socket; + return; + } + QString message(QString::fromUtf8(uMsg)); + socket->write(ack, qstrlen(ack)); + socket->waitForBytesWritten(1000); + socket->waitForDisconnected(1000); // make sure client reads ack + delete socket; + emit messageReceived(message); //### (might take a long time to return) +} diff --git a/qtsingleapplication/qtlocalpeer.h b/qtsingleapplication/qtlocalpeer.h new file mode 100644 index 0000000..1b533b1 --- /dev/null +++ b/qtsingleapplication/qtlocalpeer.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTLOCALPEER_H +#define QTLOCALPEER_H + +#include +#include +#include + +#include "qtlockedfile.h" + +class QtLocalPeer : public QObject +{ + Q_OBJECT + +public: + QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); + bool isClient(); + bool sendMessage(const QString &message, int timeout); + QString applicationId() const + { return id; } + +Q_SIGNALS: + void messageReceived(const QString &message); + +protected Q_SLOTS: + void receiveConnection(); + +protected: + QString id; + QString socketName; + QLocalServer* server; + QtLP_Private::QtLockedFile lockFile; + +private: + static const char* ack; +}; + +#endif // QTLOCALPEER_H diff --git a/qtsingleapplication/qtlockedfile.cpp b/qtsingleapplication/qtlockedfile.cpp new file mode 100644 index 0000000..c142a86 --- /dev/null +++ b/qtsingleapplication/qtlockedfile.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtlockedfile.h" + +/*! + \class QtLockedFile + + \brief The QtLockedFile class extends QFile with advisory locking + functions. + + A file may be locked in read or write mode. Multiple instances of + \e QtLockedFile, created in multiple processes running on the same + machine, may have a file locked in read mode. Exactly one instance + may have it locked in write mode. A read and a write lock cannot + exist simultaneously on the same file. + + The file locks are advisory. This means that nothing prevents + another process from manipulating a locked file using QFile or + file system functions offered by the OS. Serialization is only + guaranteed if all processes that access the file use + QLockedFile. Also, while holding a lock on a file, a process + must not open the same file again (through any API), or locks + can be unexpectedly lost. + + The lock provided by an instance of \e QtLockedFile is released + whenever the program terminates. This is true even when the + program crashes and no destructors are called. +*/ + +/*! \enum QtLockedFile::LockMode + + This enum describes the available lock modes. + + \value ReadLock A read lock. + \value WriteLock A write lock. + \value NoLock Neither a read lock nor a write lock. +*/ + +/*! + Constructs an unlocked \e QtLockedFile object. This constructor + behaves in the same way as \e QFile::QFile(). + + \sa QFile::QFile() +*/ +QtLockedFile::QtLockedFile() + : QFile() +{ +#ifdef Q_OS_WIN + wmutex = 0; + rmutex = 0; +#endif + m_lock_mode = NoLock; +} + +/*! + Constructs an unlocked QtLockedFile object with file \a name. This + constructor behaves in the same way as \e QFile::QFile(const + QString&). + + \sa QFile::QFile() +*/ +QtLockedFile::QtLockedFile(const QString &name) + : QFile(name) +{ +#ifdef Q_OS_WIN + wmutex = 0; + rmutex = 0; +#endif + m_lock_mode = NoLock; +} + +/*! + Opens the file in OpenMode \a mode. + + This is identical to QFile::open(), with the one exception that the + Truncate mode flag is disallowed. Truncation would conflict with the + advisory file locking, since the file would be modified before the + write lock is obtained. If truncation is required, use resize(0) + after obtaining the write lock. + + Returns true if successful; otherwise false. + + \sa QFile::open(), QFile::resize() +*/ +bool QtLockedFile::open(OpenMode mode) +{ + if (mode & QIODevice::Truncate) { + qWarning("QtLockedFile::open(): Truncate mode not allowed."); + return false; + } + return QFile::open(mode); +} + +/*! + Returns \e true if this object has a in read or write lock; + otherwise returns \e false. + + \sa lockMode() +*/ +bool QtLockedFile::isLocked() const +{ + return m_lock_mode != NoLock; +} + +/*! + Returns the type of lock currently held by this object, or \e + QtLockedFile::NoLock. + + \sa isLocked() +*/ +QtLockedFile::LockMode QtLockedFile::lockMode() const +{ + return m_lock_mode; +} + +/*! + \fn bool QtLockedFile::lock(LockMode mode, bool block = true) + + Obtains a lock of type \a mode. The file must be opened before it + can be locked. + + If \a block is true, this function will block until the lock is + aquired. If \a block is false, this function returns \e false + immediately if the lock cannot be aquired. + + If this object already has a lock of type \a mode, this function + returns \e true immediately. If this object has a lock of a + different type than \a mode, the lock is first released and then a + new lock is obtained. + + This function returns \e true if, after it executes, the file is + locked by this object, and \e false otherwise. + + \sa unlock(), isLocked(), lockMode() +*/ + +/*! + \fn bool QtLockedFile::unlock() + + Releases a lock. + + If the object has no lock, this function returns immediately. + + This function returns \e true if, after it executes, the file is + not locked by this object, and \e false otherwise. + + \sa lock(), isLocked(), lockMode() +*/ + +/*! + \fn QtLockedFile::~QtLockedFile() + + Destroys the \e QtLockedFile object. If any locks were held, they + are released. +*/ diff --git a/qtsingleapplication/qtlockedfile.h b/qtsingleapplication/qtlockedfile.h new file mode 100644 index 0000000..84c18e5 --- /dev/null +++ b/qtsingleapplication/qtlockedfile.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTLOCKEDFILE_H +#define QTLOCKEDFILE_H + +#include +#ifdef Q_OS_WIN +#include +#endif + +#if defined(Q_OS_WIN) +# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT) +# define QT_QTLOCKEDFILE_EXPORT +# elif defined(QT_QTLOCKEDFILE_IMPORT) +# if defined(QT_QTLOCKEDFILE_EXPORT) +# undef QT_QTLOCKEDFILE_EXPORT +# endif +# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport) +# elif defined(QT_QTLOCKEDFILE_EXPORT) +# undef QT_QTLOCKEDFILE_EXPORT +# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport) +# endif +#else +# define QT_QTLOCKEDFILE_EXPORT +#endif + +namespace QtLP_Private { + +class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile +{ +public: + enum LockMode { NoLock = 0, ReadLock, WriteLock }; + + QtLockedFile(); + QtLockedFile(const QString &name); + ~QtLockedFile(); + + bool open(OpenMode mode); + + bool lock(LockMode mode, bool block = true); + bool unlock(); + bool isLocked() const; + LockMode lockMode() const; + +private: +#ifdef Q_OS_WIN + Qt::HANDLE wmutex; + Qt::HANDLE rmutex; + QVector rmutexes; + QString mutexname; + + Qt::HANDLE getMutexHandle(int idx, bool doCreate); + bool waitMutex(Qt::HANDLE mutex, bool doBlock); + +#endif + LockMode m_lock_mode; +}; +} +#endif diff --git a/qtsingleapplication/qtlockedfile_unix.cpp b/qtsingleapplication/qtlockedfile_unix.cpp new file mode 100644 index 0000000..976c1b9 --- /dev/null +++ b/qtsingleapplication/qtlockedfile_unix.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#include "qtlockedfile.h" + +bool QtLockedFile::lock(LockMode mode, bool block) +{ + if (!isOpen()) { + qWarning("QtLockedFile::lock(): file is not opened"); + return false; + } + + if (mode == NoLock) + return unlock(); + + if (mode == m_lock_mode) + return true; + + if (m_lock_mode != NoLock) + unlock(); + + struct flock fl; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; + int cmd = block ? F_SETLKW : F_SETLK; + int ret = fcntl(handle(), cmd, &fl); + + if (ret == -1) { + if (errno != EINTR && errno != EAGAIN) + qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); + return false; + } + + + m_lock_mode = mode; + return true; +} + + +bool QtLockedFile::unlock() +{ + if (!isOpen()) { + qWarning("QtLockedFile::unlock(): file is not opened"); + return false; + } + + if (!isLocked()) + return true; + + struct flock fl; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + fl.l_type = F_UNLCK; + int ret = fcntl(handle(), F_SETLKW, &fl); + + if (ret == -1) { + qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); + return false; + } + + m_lock_mode = NoLock; + return true; +} + +QtLockedFile::~QtLockedFile() +{ + if (isOpen()) + unlock(); +} + diff --git a/qtsingleapplication/qtlockedfile_win.cpp b/qtsingleapplication/qtlockedfile_win.cpp new file mode 100644 index 0000000..5e21262 --- /dev/null +++ b/qtsingleapplication/qtlockedfile_win.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtlockedfile.h" +#include +#include + +#define MUTEX_PREFIX "QtLockedFile mutex " +// Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS +#define MAX_READERS MAXIMUM_WAIT_OBJECTS + +#if QT_VERSION >= 0x050000 +#define QT_WA(unicode, ansi) unicode +#endif + +Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) +{ + if (mutexname.isEmpty()) { + QFileInfo fi(*this); + mutexname = QString::fromLatin1(MUTEX_PREFIX) + + fi.absoluteFilePath().toLower(); + } + QString mname(mutexname); + if (idx >= 0) + mname += QString::number(idx); + + Qt::HANDLE mutex; + if (doCreate) { + QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, + { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } ); + if (!mutex) { + qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); + return 0; + } + } + else { + QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, + { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } ); + if (!mutex) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) + qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); + return 0; + } + } + return mutex; +} + +bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock) +{ + Q_ASSERT(mutex); + DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0); + switch (res) { + case WAIT_OBJECT_0: + case WAIT_ABANDONED: + return true; + break; + case WAIT_TIMEOUT: + break; + default: + qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed"); + } + return false; +} + + + +bool QtLockedFile::lock(LockMode mode, bool block) +{ + if (!isOpen()) { + qWarning("QtLockedFile::lock(): file is not opened"); + return false; + } + + if (mode == NoLock) + return unlock(); + + if (mode == m_lock_mode) + return true; + + if (m_lock_mode != NoLock) + unlock(); + + if (!wmutex && !(wmutex = getMutexHandle(-1, true))) + return false; + + if (!waitMutex(wmutex, block)) + return false; + + if (mode == ReadLock) { + int idx = 0; + for (; idx < MAX_READERS; idx++) { + rmutex = getMutexHandle(idx, false); + if (!rmutex || waitMutex(rmutex, false)) + break; + CloseHandle(rmutex); + } + bool ok = true; + if (idx >= MAX_READERS) { + qWarning("QtLockedFile::lock(): too many readers"); + rmutex = 0; + ok = false; + } + else if (!rmutex) { + rmutex = getMutexHandle(idx, true); + if (!rmutex || !waitMutex(rmutex, false)) + ok = false; + } + if (!ok && rmutex) { + CloseHandle(rmutex); + rmutex = 0; + } + ReleaseMutex(wmutex); + if (!ok) + return false; + } + else { + Q_ASSERT(rmutexes.isEmpty()); + for (int i = 0; i < MAX_READERS; i++) { + Qt::HANDLE mutex = getMutexHandle(i, false); + if (mutex) + rmutexes.append(mutex); + } + if (rmutexes.size()) { + DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(), + TRUE, block ? INFINITE : 0); + if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) { + if (res != WAIT_TIMEOUT) + qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed"); + m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky + unlock(); + return false; + } + } + } + + m_lock_mode = mode; + return true; +} + +bool QtLockedFile::unlock() +{ + if (!isOpen()) { + qWarning("QtLockedFile::unlock(): file is not opened"); + return false; + } + + if (!isLocked()) + return true; + + if (m_lock_mode == ReadLock) { + ReleaseMutex(rmutex); + CloseHandle(rmutex); + rmutex = 0; + } + else { + foreach(Qt::HANDLE mutex, rmutexes) { + ReleaseMutex(mutex); + CloseHandle(mutex); + } + rmutexes.clear(); + ReleaseMutex(wmutex); + } + + m_lock_mode = QtLockedFile::NoLock; + return true; +} + +QtLockedFile::~QtLockedFile() +{ + if (isOpen()) + unlock(); + if (wmutex) + CloseHandle(wmutex); +} diff --git a/qtsingleapplication/qtsingleapplication.cpp b/qtsingleapplication/qtsingleapplication.cpp new file mode 100644 index 0000000..d0fb15d --- /dev/null +++ b/qtsingleapplication/qtsingleapplication.cpp @@ -0,0 +1,347 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qtsingleapplication.h" +#include "qtlocalpeer.h" +#include + + +/*! + \class QtSingleApplication qtsingleapplication.h + \brief The QtSingleApplication class provides an API to detect and + communicate with running instances of an application. + + This class allows you to create applications where only one + instance should be running at a time. I.e., if the user tries to + launch another instance, the already running instance will be + activated instead. Another usecase is a client-server system, + where the first started instance will assume the role of server, + and the later instances will act as clients of that server. + + By default, the full path of the executable file is used to + determine whether two processes are instances of the same + application. You can also provide an explicit identifier string + that will be compared instead. + + The application should create the QtSingleApplication object early + in the startup phase, and call isRunning() to find out if another + instance of this application is already running. If isRunning() + returns false, it means that no other instance is running, and + this instance has assumed the role as the running instance. In + this case, the application should continue with the initialization + of the application user interface before entering the event loop + with exec(), as normal. + + The messageReceived() signal will be emitted when the running + application receives messages from another instance of the same + application. When a message is received it might be helpful to the + user to raise the application so that it becomes visible. To + facilitate this, QtSingleApplication provides the + setActivationWindow() function and the activateWindow() slot. + + If isRunning() returns true, another instance is already + running. It may be alerted to the fact that another instance has + started by using the sendMessage() function. Also data such as + startup parameters (e.g. the name of the file the user wanted this + new instance to open) can be passed to the running instance with + this function. Then, the application should terminate (or enter + client mode). + + If isRunning() returns true, but sendMessage() fails, that is an + indication that the running instance is frozen. + + Here's an example that shows how to convert an existing + application to use QtSingleApplication. It is very simple and does + not make use of all QtSingleApplication's functionality (see the + examples for that). + + \code + // Original + int main(int argc, char **argv) + { + QApplication app(argc, argv); + + MyMainWidget mmw; + mmw.show(); + return app.exec(); + } + + // Single instance + int main(int argc, char **argv) + { + QtSingleApplication app(argc, argv); + + if (app.isRunning()) + return !app.sendMessage(someDataString); + + MyMainWidget mmw; + app.setActivationWindow(&mmw); + mmw.show(); + return app.exec(); + } + \endcode + + Once this QtSingleApplication instance is destroyed (normally when + the process exits or crashes), when the user next attempts to run the + application this instance will not, of course, be encountered. The + next instance to call isRunning() or sendMessage() will assume the + role as the new running instance. + + For console (non-GUI) applications, QtSingleCoreApplication may be + used instead of this class, to avoid the dependency on the QtGui + library. + + \sa QtSingleCoreApplication +*/ + + +void QtSingleApplication::sysInit(const QString &appId) +{ + actWin = 0; + peer = new QtLocalPeer(this, appId); + connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); +} + + +/*! + Creates a QtSingleApplication object. The application identifier + will be QCoreApplication::applicationFilePath(). \a argc, \a + argv, and \a GUIenabled are passed on to the QAppliation constructor. + + If you are creating a console application (i.e. setting \a + GUIenabled to false), you may consider using + QtSingleCoreApplication instead. +*/ + +QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled) + : QApplication(argc, argv, GUIenabled) +{ + sysInit(); +} + + +/*! + Creates a QtSingleApplication object with the application + identifier \a appId. \a argc and \a argv are passed on to the + QAppliation constructor. +*/ + +QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv) + : QApplication(argc, argv) +{ + sysInit(appId); +} + +#if QT_VERSION < 0x050000 + +/*! + Creates a QtSingleApplication object. The application identifier + will be QCoreApplication::applicationFilePath(). \a argc, \a + argv, and \a type are passed on to the QAppliation constructor. +*/ +QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) + : QApplication(argc, argv, type) +{ + sysInit(); +} + + +# if defined(Q_WS_X11) +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be QCoreApplication::applicationFilePath(). \a dpy, \a visual, + and \a cmap are passed on to the QApplication constructor. +*/ +QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, visual, cmap) +{ + sysInit(); +} + +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a + argv, \a visual, and \a cmap are passed on to the QApplication + constructor. +*/ +QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, argc, argv, visual, cmap) +{ + sysInit(); +} + +/*! + Special constructor for X11, ref. the documentation of + QApplication's corresponding constructor. The application identifier + will be \a appId. \a dpy, \a argc, \a + argv, \a visual, and \a cmap are passed on to the QApplication + constructor. +*/ +QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) + : QApplication(dpy, argc, argv, visual, cmap) +{ + sysInit(appId); +} +# endif // Q_WS_X11 +#endif // QT_VERSION < 0x050000 + + +/*! + Returns true if another instance of this application is running; + otherwise false. + + This function does not find instances of this application that are + being run by a different user (on Windows: that are running in + another session). + + \sa sendMessage() +*/ + +bool QtSingleApplication::isRunning() +{ + return peer->isClient(); +} + + +/*! + Tries to send the text \a message to the currently running + instance. The QtSingleApplication object in the running instance + will emit the messageReceived() signal when it receives the + message. + + This function returns true if the message has been sent to, and + processed by, the current instance. If there is no instance + currently running, or if the running instance fails to process the + message within \a timeout milliseconds, this function return false. + + \sa isRunning(), messageReceived() +*/ +bool QtSingleApplication::sendMessage(const QString &message, int timeout) +{ + return peer->sendMessage(message, timeout); +} + + +/*! + Returns the application identifier. Two processes with the same + identifier will be regarded as instances of the same application. +*/ +QString QtSingleApplication::id() const +{ + return peer->applicationId(); +} + + +/*! + Sets the activation window of this application to \a aw. The + activation window is the widget that will be activated by + activateWindow(). This is typically the application's main window. + + If \a activateOnMessage is true (the default), the window will be + activated automatically every time a message is received, just prior + to the messageReceived() signal being emitted. + + \sa activateWindow(), messageReceived() +*/ + +void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) +{ + actWin = aw; + if (activateOnMessage) + connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); + else + disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); +} + + +/*! + Returns the applications activation window if one has been set by + calling setActivationWindow(), otherwise returns 0. + + \sa setActivationWindow() +*/ +QWidget* QtSingleApplication::activationWindow() const +{ + return actWin; +} + + +/*! + De-minimizes, raises, and activates this application's activation window. + This function does nothing if no activation window has been set. + + This is a convenience function to show the user that this + application instance has been activated when he has tried to start + another instance. + + This function should typically be called in response to the + messageReceived() signal. By default, that will happen + automatically, if an activation window has been set. + + \sa setActivationWindow(), messageReceived(), initialize() +*/ +void QtSingleApplication::activateWindow() +{ + if (actWin) { + actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized); + actWin->raise(); + actWin->activateWindow(); + } +} + + +/*! + \fn void QtSingleApplication::messageReceived(const QString& message) + + This signal is emitted when the current instance receives a \a + message from another instance of this application. + + \sa sendMessage(), setActivationWindow(), activateWindow() +*/ + + +/*! + \fn void QtSingleApplication::initialize(bool dummy = true) + + \obsolete +*/ diff --git a/qtsingleapplication/qtsingleapplication.h b/qtsingleapplication/qtsingleapplication.h new file mode 100644 index 0000000..049406f --- /dev/null +++ b/qtsingleapplication/qtsingleapplication.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTSINGLEAPPLICATION_H +#define QTSINGLEAPPLICATION_H + +#include + +class QtLocalPeer; + +#if defined(Q_OS_WIN) +# if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) +# define QT_QTSINGLEAPPLICATION_EXPORT +# elif defined(QT_QTSINGLEAPPLICATION_IMPORT) +# if defined(QT_QTSINGLEAPPLICATION_EXPORT) +# undef QT_QTSINGLEAPPLICATION_EXPORT +# endif +# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport) +# elif defined(QT_QTSINGLEAPPLICATION_EXPORT) +# undef QT_QTSINGLEAPPLICATION_EXPORT +# define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport) +# endif +#else +# define QT_QTSINGLEAPPLICATION_EXPORT +#endif + +class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication +{ + Q_OBJECT + +public: + QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); + QtSingleApplication(const QString &id, int &argc, char **argv); +#if QT_VERSION < 0x050000 + QtSingleApplication(int &argc, char **argv, Type type); +# if defined(Q_WS_X11) + QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); + QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); + QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); +# endif // Q_WS_X11 +#endif // QT_VERSION < 0x050000 + + bool isRunning(); + QString id() const; + + void setActivationWindow(QWidget* aw, bool activateOnMessage = true); + QWidget* activationWindow() const; + + // Obsolete: + void initialize(bool dummy = true) + { isRunning(); Q_UNUSED(dummy) } + +public Q_SLOTS: + bool sendMessage(const QString &message, int timeout = 5000); + void activateWindow(); + + +Q_SIGNALS: + void messageReceived(const QString &message); + + +private: + void sysInit(const QString &appId = QString()); + QtLocalPeer *peer; + QWidget *actWin; +}; + +#endif // QTSINGLEAPPLICATION_H diff --git a/qtsingleapplication/qtsingleapplication.pri b/qtsingleapplication/qtsingleapplication.pri new file mode 100644 index 0000000..1d85285 --- /dev/null +++ b/qtsingleapplication/qtsingleapplication.pri @@ -0,0 +1,16 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD +QT *= network +greaterThan(QT_MAJOR_VERSION, 4): QT *= widgets + +qtsingleapplication-uselib:!qtsingleapplication-buildlib { + LIBS += -L$$QTSINGLEAPPLICATION_LIBDIR -l$$QTSINGLEAPPLICATION_LIBNAME +} else { + SOURCES += $$PWD/qtsingleapplication.cpp $$PWD/qtlocalpeer.cpp + HEADERS += $$PWD/qtsingleapplication.h $$PWD/qtlocalpeer.h +} + +win32 { + contains(TEMPLATE, lib):contains(CONFIG, shared):DEFINES += QT_QTSINGLEAPPLICATION_EXPORT + else:qtsingleapplication-uselib:DEFINES += QT_QTSINGLEAPPLICATION_IMPORT +} diff --git a/qtsingleapplication/qtsinglecoreapplication.cpp b/qtsingleapplication/qtsinglecoreapplication.cpp new file mode 100644 index 0000000..5634537 --- /dev/null +++ b/qtsingleapplication/qtsinglecoreapplication.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qtsinglecoreapplication.h" +#include "qtlocalpeer.h" + +/*! + \class QtSingleCoreApplication qtsinglecoreapplication.h + \brief A variant of the QtSingleApplication class for non-GUI applications. + + This class is a variant of QtSingleApplication suited for use in + console (non-GUI) applications. It is an extension of + QCoreApplication (instead of QApplication). It does not require + the QtGui library. + + The API and usage is identical to QtSingleApplication, except that + functions relating to the "activation window" are not present, for + obvious reasons. Please refer to the QtSingleApplication + documentation for explanation of the usage. + + A QtSingleCoreApplication instance can communicate to a + QtSingleApplication instance if they share the same application + id. Hence, this class can be used to create a light-weight + command-line tool that sends commands to a GUI application. + + \sa QtSingleApplication +*/ + +/*! + Creates a QtSingleCoreApplication object. The application identifier + will be QCoreApplication::applicationFilePath(). \a argc and \a + argv are passed on to the QCoreAppliation constructor. +*/ + +QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv) + : QCoreApplication(argc, argv) +{ + peer = new QtLocalPeer(this); + connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); +} + + +/*! + Creates a QtSingleCoreApplication object with the application + identifier \a appId. \a argc and \a argv are passed on to the + QCoreAppliation constructor. +*/ +QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv) + : QCoreApplication(argc, argv) +{ + peer = new QtLocalPeer(this, appId); + connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); +} + + +/*! + Returns true if another instance of this application is running; + otherwise false. + + This function does not find instances of this application that are + being run by a different user (on Windows: that are running in + another session). + + \sa sendMessage() +*/ + +bool QtSingleCoreApplication::isRunning() +{ + return peer->isClient(); +} + + +/*! + Tries to send the text \a message to the currently running + instance. The QtSingleCoreApplication object in the running instance + will emit the messageReceived() signal when it receives the + message. + + This function returns true if the message has been sent to, and + processed by, the current instance. If there is no instance + currently running, or if the running instance fails to process the + message within \a timeout milliseconds, this function return false. + + \sa isRunning(), messageReceived() +*/ + +bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout) +{ + return peer->sendMessage(message, timeout); +} + + +/*! + Returns the application identifier. Two processes with the same + identifier will be regarded as instances of the same application. +*/ + +QString QtSingleCoreApplication::id() const +{ + return peer->applicationId(); +} + + +/*! + \fn void QtSingleCoreApplication::messageReceived(const QString& message) + + This signal is emitted when the current instance receives a \a + message from another instance of this application. + + \sa sendMessage() +*/ diff --git a/qtsingleapplication/qtsinglecoreapplication.h b/qtsingleapplication/qtsinglecoreapplication.h new file mode 100644 index 0000000..b87fffe --- /dev/null +++ b/qtsingleapplication/qtsinglecoreapplication.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Solutions component. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTSINGLECOREAPPLICATION_H +#define QTSINGLECOREAPPLICATION_H + +#include + +class QtLocalPeer; + +class QtSingleCoreApplication : public QCoreApplication +{ + Q_OBJECT + +public: + QtSingleCoreApplication(int &argc, char **argv); + QtSingleCoreApplication(const QString &id, int &argc, char **argv); + + bool isRunning(); + QString id() const; + +public Q_SLOTS: + bool sendMessage(const QString &message, int timeout = 5000); + + +Q_SIGNALS: + void messageReceived(const QString &message); + + +private: + QtLocalPeer* peer; +}; + +#endif // QTSINGLECOREAPPLICATION_H diff --git a/qtsingleapplication/qtsinglecoreapplication.pri b/qtsingleapplication/qtsinglecoreapplication.pri new file mode 100644 index 0000000..d2d6cc3 --- /dev/null +++ b/qtsingleapplication/qtsinglecoreapplication.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD +HEADERS += $$PWD/qtsinglecoreapplication.h $$PWD/qtlocalpeer.h +SOURCES += $$PWD/qtsinglecoreapplication.cpp $$PWD/qtlocalpeer.cpp + +QT *= network + +win32:contains(TEMPLATE, lib):contains(CONFIG, shared) { + DEFINES += QT_QTSINGLECOREAPPLICATION_EXPORT=__declspec(dllexport) +} diff --git a/service/bluetoothagent.cpp b/service/bluetoothagent.cpp new file mode 100644 index 0000000..3d2a498 --- /dev/null +++ b/service/bluetoothagent.cpp @@ -0,0 +1,189 @@ +#include "bluetoothagent.h" +#include "globalsize.h" + +//取消发送蓝牙设备状态信号,在SessionDbusRegister定义 +extern int cancelEmitDevStatus(QString addr); +extern void addDelay(BluezQt::DevicePtr dev); + + +BluetoothAgent::BluetoothAgent(QObject *parent) + : Agent(parent) + , m_pinRequested(false) + , m_passkeyRequested(false) + , m_authorizationRequested(false) + , m_cancelCalled(false) + , m_releaseCalled(false) + , m_hasClosePinCode(false) +{ + qDebug() << Q_FUNC_INFO; + if(daemonIsNotRunning()){ + //QDBusConnection bus = QDBusConnection::systemBus(); + // 在session bus上注册名为"org.bluez.Agent1"的service + + //if (!bus.registerService("org.bluez.Agent1")) { //注意命名规则-和_ + // qDebug() << bus.lastError().message(); + // exit(1); + //} + // "QDBusConnection::ExportAllSlots"表示把类Hotel的所有Slot都导出为这个Object的method + //bus.registerObject("/", this ,QDBusConnection::ExportAllContents); + } + + QDBusConnection::sessionBus().connect("com.ukui.bluetooth", + "/com/ukui/bluetooth", + "com.ukui.bluetooth", + "replyRequestConfirmation", + this, + SLOT(replyRequestConfirmationFunc(bool))); +} + +void BluetoothAgent::emitRemoveSignal(BluezQt::DevicePtr device) { + if (device.data()->isPaired()) { + QTimer::singleShot(100,this,[=]{ + emit agentRemoveDevice(device); + }); + + } +} + +void BluetoothAgent::replyRequestConfirmationFunc(bool v) +{ + qDebug() << Q_FUNC_INFO << v; + //if (tmpRequestConfirmation == NULL) + // qDebug() << "BluetoothAgent::replyRequestConfirmationFunc--qk-0"; + //qDebug() << "BluetoothAgent::replyRequestConfirmationFunc--qk-01"; + if (v) + tmpRequestConfirmation.accept(); + else + tmpRequestConfirmation.reject(); + + + //发送蓝牙连接信号 + //条件:蓝牙设备未配对,蓝牙适配器配对,且蓝牙设备主动连接 + //约束条件: 点击确定、被动连接、连接成功、配对 + if(v && nullptr != m_device && !GlobalSize::IsBlueDevActive(m_device->address()) && + m_device->isConnected() && m_device->isPaired()) + { + //若对端拒绝、超时等,会出现蓝牙设备状态发送异常情况,暂时无法避免 + addDelay(m_device); + } + + qDebug() << "BluetoothAgent::replyRequestConfirmationFunc--qk"; +} + +QDBusObjectPath BluetoothAgent::objectPath() const +{ + return QDBusObjectPath(QStringLiteral("/BluetoothAgent")); +} + +void BluetoothAgent::requestPinCode(BluezQt::DevicePtr device, const BluezQt::Request &request) +{ + qDebug() << Q_FUNC_INFO; + m_device = device; + m_pinRequested = true; + + request.accept(QString()); + +} + +void BluetoothAgent::displayPinCode(BluezQt::DevicePtr device, const QString &pinCode) +{ + m_device = device; + m_displayedPinCode = pinCode; + qDebug() << Q_FUNC_INFO; +} + +void BluetoothAgent::requestPasskey(BluezQt::DevicePtr device, const BluezQt::Request &request) +{ + qDebug() << Q_FUNC_INFO; + m_device = device; + m_passkeyRequested = true; + + request.accept(0); +} + +void BluetoothAgent::displayPasskey(BluezQt::DevicePtr device, const QString &passkey, const QString &entered) +{ + qDebug() << Q_FUNC_INFO << ( m_device.isNull() ? "NULL" : m_device.data()->address() ) << entered << passkey; + cancelEmitDevStatus(device->address()); + if(m_displayedPasskey == passkey) + return; + QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "displayPasskey"); + displayPasskeySignal << device.data()->name() << passkey; + QDBusConnection::sessionBus().send(displayPasskeySignal); +} + +void BluetoothAgent::requestConfirmation(BluezQt::DevicePtr device, const QString &passkey, const BluezQt::Request<> &request) +{ + qDebug() << Q_FUNC_INFO << device->name() << passkey << device->isConnected() << device->isPaired(); + + cancelEmitDevStatus(device->address()); + + m_device = device; + //规避设备类型为耳机、音响设备时还会弹出pin窗口的问题 + if ((nullptr != m_device) && + (m_device.data()->type() == BluezQt::Device::AudioVideo || + m_device.data()->type() == BluezQt::Device::Headphones || + m_device.data()->type() == BluezQt::Device::Headset )) + { + request.accept(); + } + else + { + QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "requestConfirmation"); + displayPasskeySignal << device.data()->name() << passkey; + QDBusConnection::sessionBus().send(displayPasskeySignal); + + tmpRequestConfirmation = request; + } +} + +void BluetoothAgent::requestAuthorization(BluezQt::DevicePtr device, const BluezQt::Request<> &request) +{ + qDebug() << Q_FUNC_INFO << device->name(); + m_device = device; + m_authorizationRequested = true; + + request.accept(); +} + +void BluetoothAgent::authorizeService(BluezQt::DevicePtr device, const QString &uuid, const BluezQt::Request<> &request) +{ + qDebug() << Q_FUNC_INFO << device->name(); + m_device = device; + m_authorizedUuid = uuid; + + request.accept(); +} + +void BluetoothAgent::cancel() +{ + qDebug() << Q_FUNC_INFO; + if (m_cancelCalled) + return; + + QDBusMessage pairAgentCanceled = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "pairAgentCanceled"); + + QDBusConnection::sessionBus().send(pairAgentCanceled); +} + +void BluetoothAgent::release() +{ + qDebug() << Q_FUNC_INFO; + m_releaseCalled = true; +} + +int BluetoothAgent::daemonIsNotRunning() +{ + QDBusConnection conn = QDBusConnection::systemBus(); + if (!conn.isConnected()) + return 0; + + QDBusReply reply = conn.interface()->call("GetNameOwner", "org.bluez.Agent1"); + return reply.value() == ""; +} diff --git a/service/bluetoothagent.h b/service/bluetoothagent.h new file mode 100644 index 0000000..8bba12e --- /dev/null +++ b/service/bluetoothagent.h @@ -0,0 +1,85 @@ +#ifndef BLUETOOTHAGENT_H +#define BLUETOOTHAGENT_H + +#include "../ukui-bluetooth/pin/pincodewidget.h" + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +//#include +#include +#include + +class BluetoothAgent : public BluezQt::Agent +{ + Q_OBJECT + +public: + explicit BluetoothAgent(QObject *parent = nullptr); + + QDBusObjectPath objectPath() const override; + + void requestPinCode(BluezQt::DevicePtr device, const BluezQt::Request &request) override; + void displayPinCode(BluezQt::DevicePtr device, const QString &pinCode) override; + void requestPasskey(BluezQt::DevicePtr device, const BluezQt::Request &request) override; + void displayPasskey(BluezQt::DevicePtr device, const QString &passkey, const QString &entered) override; + void requestConfirmation(BluezQt::DevicePtr device, const QString &passkey, const BluezQt::Request<> &request) override; + void requestAuthorization(BluezQt::DevicePtr device, const BluezQt::Request<> &request) override; + void authorizeService(BluezQt::DevicePtr device, const QString &uuid, const BluezQt::Request<> &request) override; + + void cancel() override; + void release() override; + int daemonIsNotRunning(); + void emitRemoveSignal(BluezQt::DevicePtr device); + +private slots: + void replyRequestConfirmationFunc(bool); + +Q_SIGNALS: + void requestAccept(); + void requestReject(); + void stopNotifyTimer(BluezQt::DevicePtr); + void startNotifyTimer(BluezQt::DevicePtr); + void agentRemoveDevice(BluezQt::DevicePtr); +private: + + BluezQt::DevicePtr m_device; + // requestPinCode + bool m_pinRequested; + // displayPinCode + QString m_displayedPinCode; + // requestPasskey + bool m_passkeyRequested; + // displayPasskey + QString m_displayedPasskey; + QString m_enteredPasskey; + // requestConfirmation + QString m_requestedPasskey; + // requestAuthorization + bool m_authorizationRequested; + // authorizeService + QString m_authorizedUuid; + // cancel + bool m_cancelCalled; + // release + bool m_releaseCalled; + + bool m_hasClosePinCode; + + BluezQt::Request<> tmpRequestConfirmation; + + PinCodeWidget *pincodewidget = nullptr; + PinCodeWidget *Keypincodewidget = nullptr; +}; + +#endif // BLUETOOTHAGENT_H diff --git a/service/bluetoothobexagent.cpp b/service/bluetoothobexagent.cpp new file mode 100644 index 0000000..2ee3240 --- /dev/null +++ b/service/bluetoothobexagent.cpp @@ -0,0 +1,175 @@ +#include "bluetoothobexagent.h" + +BluetoothObexAgent::BluetoothObexAgent(QObject *parent):ObexAgent(parent) +{ + if(daemonIsNotRunning()) + { + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusConnection bus = QDBusConnection::sessionBus(); + if (!bus.registerService("com.ukui.bluetooth")) { //注意命名规则-和_ + qDebug() << bus.lastError().message(); + exit(1); + } + // "QDBusConnection::ExportAllSlots"表示把类Hotel的所有Slot都导出为这个Object的method + //qDebug() << Q_FUNC_INFO << bus.registerObject("/", "org.bluez.obex.Agent1", this, QDBusConnection::ExportAllContents); + bus.registerObject("/", "org.bluez.obex.Agent1", this, QDBusConnection::ExportAllContents); + } + QDBusConnection::sessionBus().connect("com.ukui.bluetooth", + "/com/ukui/bluetooth", + "com.ukui.bluetooth", + "clearOldSession", + this, + SLOT(clearOldSession())); + QDBusConnection::sessionBus().connect("com.ukui.bluetooth", + "/com/ukui/bluetooth", + "com.ukui.bluetooth", + "replyFileReceivingSignal", + this, + SLOT(replyFileReceivingSignalFunc(bool))); + QDBusConnection::sessionBus().connect("com.ukui.bluetooth", + "/com/ukui/bluetooth", + "com.ukui.bluetooth", + "cancelFileReceivingSignal", + this, + SLOT(cancelFileReceivingSignalFunc())); +} + +void BluetoothObexAgent::authorizePush(BluezQt::ObexTransferPtr transfer, BluezQt::ObexSessionPtr session, const BluezQt::Request &request) +{ + qDebug() << Q_FUNC_INFO << transfer->status() << transfer->fileName() << transfer->name() <objectPath().path() << transfer->transferred() << transfer->objectName(); + qDebug() << session->source() << session->destination(); + if (oldSession == session && transfer->status() != BluezQt::ObexTransfer::Error) { + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage fileReviceMore = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "fileReceiveMore"); + fileReviceMore << transfer->name() << transfer->size() << transfer->type(); + QDBusConnection::sessionBus().send(fileReviceMore); + request.accept(transfer->name()); + qDebug() << Q_FUNC_INFO << __LINE__; + return; + } + qDebug() << Q_FUNC_INFO << __LINE__; + if(transfer->status() == BluezQt::ObexTransfer::Queued ){//|| transfer->status() == BluezQt::ObexTransfer::Complete + + QDBusMessage statusChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "statusChanged"); + QMetaEnum metaEnum = QMetaEnum::fromType(); + statusChanged << metaEnum.valueToKey(transfer->status()) << session.data()->destination() << transfer.data()->objectPath().path(); + QDBusConnection::sessionBus().send(statusChanged); + + QDBusMessage fileReceivingSignal = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "fileReceivingSignal"); + fileReceivingSignal << session->destination() << transfer->name() << transfer->type() << session->source() << transfer.data()->size(); + QDBusConnection::sessionBus().send(fileReceivingSignal); + qDebug() << Q_FUNC_INFO << __LINE__; + + _Mtransfer = transfer; + _Mrequest = &request; + _Msession = session; + } + qDebug() << Q_FUNC_INFO << transfer->status() << transfer->type() << transfer->fileName() << transfer->transferred(); +} + +QDBusObjectPath BluetoothObexAgent::objectPath() const +{ + qDebug() << Q_FUNC_INFO; + return QDBusObjectPath(QStringLiteral("/org/bluez/obex/Agent1")); +} + +void BluetoothObexAgent::cancel() +{ + qDebug() << Q_FUNC_INFO; + + statusChangedSlot(BluezQt::ObexTransfer::Error); + + QDBusMessage obexAgentCanceled = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "obexAgentCanceled"); + + QDBusConnection::sessionBus().send(obexAgentCanceled); + oldSession = nullptr; +} + +void BluetoothObexAgent::release() +{ + qDebug() << Q_FUNC_INFO; +} + +int BluetoothObexAgent::daemonIsNotRunning() +{ + QDBusConnection conn = QDBusConnection::sessionBus(); + if (!conn.isConnected()) + return 0; + + QDBusReply reply = conn.interface()->call("GetNameOwner", "org.bluez.obex.Agent1"); + return reply.value() == ""; +} + +void BluetoothObexAgent::receiveDisConnectSignal(QString address) +{ + qDebug() << Q_FUNC_INFO << address << __LINE__; + + QDBusMessage m = QDBusMessage::createMethodCall("org.ukui.bluetooth","/org/ukui/bluetooth","org.ukui.bluetooth","disConnectToDevice"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusMessage response = QDBusConnection::sessionBus().call(m); +} + +void BluetoothObexAgent::replyFileReceivingSignalFunc(bool value) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + if (value) { + qDebug() << Q_FUNC_INFO << __LINE__; + _Mrequest->accept(_Mtransfer.data()->name()); + oldSession = _Msession; + qDebug() << Q_FUNC_INFO << __LINE__; + + QDBusMessage initTransferPath = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "initTransferPath"); + initTransferPath << _Mtransfer.data()->objectPath().path(); + + QDBusConnection::sessionBus().send(initTransferPath); + + connect(_Mtransfer.data(), &BluezQt::ObexTransfer::transferredChanged, this, &BluetoothObexAgent::transferredChangedSlot); + connect(_Mtransfer.data(), &BluezQt::ObexTransfer::statusChanged, this, &BluetoothObexAgent::statusChangedSlot); + } else { + + statusChangedSlot(BluezQt::ObexTransfer::Error); + + _Mrequest->reject(); + clearOldSession(); + } +} + +void BluetoothObexAgent::cancelFileReceivingSignalFunc() { + _Mtransfer.data()->cancel(); + qDebug() << Q_FUNC_INFO << __LINE__; +} + +void BluetoothObexAgent::transferredChangedSlot(quint64 size) { + QDBusMessage transferredChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "transferredChanged"); + transferredChanged << QVariant::fromValue(size) << _Mtransfer.data()->objectPath().path(); + + QDBusConnection::sessionBus().send(transferredChanged); +} + +void BluetoothObexAgent::statusChangedSlot(BluezQt::ObexTransfer::Status status) { + QDBusMessage statusChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "statusChanged"); + QMetaEnum metaEnum = QMetaEnum::fromType(); + statusChanged << metaEnum.valueToKey(status) << _Msession.data()->destination() << _Mtransfer.data()->objectPath().path(); + QDBusConnection::sessionBus().send(statusChanged); +} + +void BluetoothObexAgent::clearOldSession() { + + oldSession = nullptr; +} diff --git a/service/bluetoothobexagent.h b/service/bluetoothobexagent.h new file mode 100644 index 0000000..1f60d00 --- /dev/null +++ b/service/bluetoothobexagent.h @@ -0,0 +1,52 @@ +#ifndef BLUETOOTHOBEXAGENT_H +#define BLUETOOTHOBEXAGENT_H + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include + + +class BluetoothObexAgent : public BluezQt::ObexAgent +{ + Q_OBJECT +public: + explicit BluetoothObexAgent(QObject *parent = nullptr); + void authorizePush (BluezQt::ObexTransferPtr transfer,BluezQt::ObexSessionPtr session, const BluezQt::Request &request); + QDBusObjectPath objectPath() const override; + void cancel (); + void release (); + + int daemonIsNotRunning(); + QString getTansferDev(); + void receiveDisConnectSignal(QString address); + +private slots: + void replyFileReceivingSignalFunc(bool); + void clearOldSession(); + void cancelFileReceivingSignalFunc(); + void transferredChangedSlot(quint64 size); + void statusChangedSlot(BluezQt::ObexTransfer::Status status); + +private: + BluezQt::ObexTransferPtr _Mtransfer; + const BluezQt::Request *_Mrequest; + BluezQt::ObexSessionPtr _Msession; + BluezQt::ObexSessionPtr oldSession; +}; + +#endif // BLUETOOTHOBEXAGENT_H diff --git a/service/config.cpp b/service/config.cpp new file mode 100644 index 0000000..dedf82c --- /dev/null +++ b/service/config.cpp @@ -0,0 +1,129 @@ +#include "config.h" + +extern "C" { +#include +#include +#include +} + +Environment envPC = Environment::NOMAL; + +const QString UIExe = "/usr/bin/ukui-bluetooth"; + +QGSettings* Config::gsetting = new QGSettings(GSETTING_SCHEMA_UKUIBLUETOOH); +QGSettings* Config::ukccGsetting = new QGSettings(GSETTING_SCHEMA_UKCC,GSETTING_PACH_UKCC); + +Config::Config(QObject *parent) + :QObject(parent) +{ +} + +Config::~Config() +{ + delete gsetting; +} + +void Config::SendNotifyMessage(QString message) +{ + QDBusInterface iface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + QDBusConnection::sessionBus()); + QList args; + args<startDetached(cmd,arg); +} + +void Config::LaunchUI() +{ + QProcess *process = new QProcess(); + QString cmd = UIExe; + qDebug() << Q_FUNC_INFO; + QTimer::singleShot(700, process, [=]{ + process->startDetached(cmd); + }); +} + +QStringList Config::getDeviceConnectTimeList(QString path) +{ + QStringList pair_device_list; + pair_device_list.clear(); + if(!QFile::exists(path)) + return pair_device_list; + + QVector pair_device_time_list; + pair_device_time_list.clear(); + GKeyFile *key_file = nullptr; + key_file = g_key_file_new(); + g_key_file_load_from_file(key_file,QString(path).toStdString().c_str(),G_KEY_FILE_NONE,NULL); + gchar **list; + bool ok; + list = g_key_file_get_groups(key_file,NULL); + for(int i = 0; list[i] != NULL; i++){ + pair_device_list.append(QString::fromUtf8(list[i])); + pair_device_time_list.append(QString::fromUtf8(g_key_file_get_string(key_file,list[i],"ConnectTime",NULL)).toInt(&ok,10)); + } + + //*****************给从配置文件中得到的设备列表和设备对应的最后连接时间列表排序***********START************** + for(int i = 0; i < pair_device_time_list.length(); i++){ + for(int j = 0; j < pair_device_time_list.length()-i-1; j++){ + if(pair_device_time_list.at(j) < pair_device_time_list.at(j+1)){ + int max = pair_device_time_list.at(j); + pair_device_time_list.replace(j,pair_device_time_list.at(j+1)); + pair_device_time_list.replace(j+1,max); + QString target = pair_device_list.at(j); + pair_device_list.removeAt(j); + pair_device_list.insert(j+1,target); + } + } + } + //************************************ END ****************************************************** + + g_key_file_free(key_file); + + return pair_device_list; +} + +void Config::writeKeyFile(QString addr, QString name, qint32 type) +{ + qDebug() << Q_FUNC_INFO << addr << name << type; + QDBusMessage m = QDBusMessage::createMethodCall("com.bluetooth.systemdbus", "/", "com.bluetooth.interface", "writeKeyFile"); + m << addr << name << type; + QDBusMessage response = QDBusConnection::systemBus().call(m); + qDebug() << Q_FUNC_INFO << addr << name << type << response.errorMessage(); +} + +void Config::removeKey(QString addr) +{ + qDebug() << Q_FUNC_INFO << addr; + QDBusMessage m = QDBusMessage::createMethodCall("com.bluetooth.systemdbus", "/", "com.bluetooth.interface", "removeKeyFile"); + m << addr; + QDBusMessage response = QDBusConnection::systemBus().call(m); + qDebug() << Q_FUNC_INFO << addr << response.errorMessage(); + +} diff --git a/service/config.h b/service/config.h new file mode 100644 index 0000000..7095c6e --- /dev/null +++ b/service/config.h @@ -0,0 +1,60 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//全局变量,是否是华为机器, 默认false, 在config.cpp文件定义 +enum Environment +{ + NOMAL = 0, + HUAWEI, + INTER, +}; + +//gsetting name define + +//名称请勿随意改动,会导致升级时获取的gsetting值不一致, +#define GSETTING_STR_BLUETOOTH_POWER_SWTICH "switch" +#define GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH "bluetooth-discoverable-switch" +#define GSETTING_STR_FINALLY_CONNECT_THE_DEVICE "finally-connect-the-device" +#define GSETTING_STR_ADAPTER_ADDRESS "adapter-address" +#define GSETTING_STR_FILE_SAVE_PATH "file-save-path" +#define GSETTING_STR_ADAPTER_ADDRESS_LIST "adapter-address-list" +#define GSETTING_STR_ACTIVE_CONNECTION "active-connection" +#define GSETTING_STR_ACTIVE_CONNECTION_TRAN "activeConnection" + +#define GSETTING_SCHEMA_UKUIBLUETOOH "org.ukui.bluetooth" +#define GSETTING_SCHEMA_UKCC "org.ukui.control-center.plugins" +#define GSETTING_PACH_UKCC "/org/ukui/control-center/plugins/Bluetooth/" + +extern Environment envPC; + +class Config : public QObject +{ +public: + Config(QObject *parent = nullptr); + ~Config(); + + static QGSettings *gsetting; + static QGSettings *ukccGsetting; + + static void SendNotifyMessage(QString); + static void OpenBluetoothSettings(); + static void LaunchUI(); + static QStringList getDeviceConnectTimeList(QString); + static void writeKeyFile(QString,QString,qint32); + static void removeKey(QString); +private: + QString setting_name; +}; + +#endif // CONFIG_H diff --git a/service/daemon.cpp b/service/daemon.cpp new file mode 100644 index 0000000..d2a83f5 --- /dev/null +++ b/service/daemon.cpp @@ -0,0 +1,805 @@ +#include "daemon.h" +#include + +namespace BluezQt +{ + extern void bluezqt_initFakeBluezTestRun(); +} + + +extern "C" { + #include + #include +} + +extern bool global_activeconn_switch; + +const QString SERVICE = "com.ukui.bluetooth"; +const QString PATH = "/com/ukui/bluetooth"; +const QString INTERFACE = "com.ukui.bluetooth"; + +static qint64 blockChangeTime = 0; +qint64 powerChangeTime = 0; +bool resetFlag = false; +bool rebootFlag = false; +bool sleepFlag = false; +bool systemSleepFlag = false; //系统睡眠标志 +bool adapterRemoveFlag = false; + +/************************************************ + * @brief 判断是否存在给定的程序启动参数 + * @param option 启动参数 + * @return 存在返回true,否则返回false +*************************************************/ +static inline bool findStartupOptions(const QString option) +{ + if (QCoreApplication::arguments().size() == 1) + return false; + + return !(QCoreApplication::arguments().indexOf(option) == -1); +} + +static inline void PendingCallProcessingFunc(BluezQt::PendingCall *call) +{ + QObject::connect(call,&BluezQt::PendingCall::finished,[=](BluezQt::PendingCall *newCall){ + if (newCall->error() != 0) + qWarning() << newCall->errorText(); + }); +} + +/************************************************ + * @brief 判断传入的str是否是有效的mac地址 + * @param str 需要判断的字符串 + * @return 有效mac地址返回true,否则返回false +*************************************************/ +static bool isAddress(const QString str) +{ + + return true; +} + +BluezQt::AdapterPtr Daemon::_DefualtAdapter = nullptr; +BluezQt::Manager* Daemon::_BluezManager = nullptr; + +Daemon::Daemon(QObject *parent) : + QObject(parent), + _mConfig(new Config(this)) +{ + //BluezQt::bluezqt_initFakeBluezTestRun(); + + qDebug() << Q_FUNC_INFO << QCoreApplication::arguments() << findStartupOptions("-d"); + qDebug() << "main currentThreadId:" << QThread::currentThreadId(); + + initGSettingInfo(); + + // ===== 创建rfkill的监听,并将监听逻辑放入子线程 ====== START ============= + _rfkill = new Rfkill(); + _rfkillThread = new QThread(this); + _rfkill->moveToThread(_rfkillThread); + connect(_rfkill,&Rfkill::rfkillStatusChanged,this,&Daemon::rfkillStatusChange); + connect(this,&Daemon::startThread,_rfkill,&Rfkill::init); + _rfkillThread->start(); + emit startThread(); + // ============================= END ================================== +} + +Daemon::~Daemon() +{ + qInfo() << Q_FUNC_INFO << "Daemon program exit!!!!"; + if (_rfkillThread) { + _rfkillThread->quit(); + _rfkillThread->wait(); + _rfkillThread->deleteLater(); + } + if (_rfkill) + _rfkill->deleteLater(); +} + +void Daemon::sendFile(QString addr,QString filename) +{ + qInfo() << Q_FUNC_INFO << QString("%1 : Send file : %2").arg(addr).arg(filename); + if (filename.isNull()|| + filename.isEmpty()|| + addr.isEmpty()|| + addr.isNull()) + return; + + if (!_ObexManager) + initObexManager(); + + if (!_ObexManager->isOperational()) + registerObexAgent(); + + if (isAddress(addr)) { + selected_file = filename; + qInfo() << Q_FUNC_INFO << QString("Send file : %1").arg(selected_file); + if(!selected_file.isNull()){ + fileTransferSessionCreator(addr, selected_file); + } + } else { + + } +} + +void Daemon::test(bool v) +{ + qDebug() << Q_FUNC_INFO << v; +} + +void Daemon::test1(QString v,QString t) +{ + qDebug() << Q_FUNC_INFO << v <set_m_progressbar_value(value.value()); +// }else if(it.key() == "Status"){ +// QVariant value = it.value(); +// if(value.value() == "active"){ +// transfer_widget->init_m_progressbar_value(transfer_file_size); +// }else if(value.value() == "error"){ +// qDebug() << Q_FUNC_INFO << __LINE__; +// filePtr->cancel(); +// } +// transfer_widget->get_transfer_status(value.value()); +// } +// } +// for (const auto& element : list) { +// qDebug() << "list element: " << element; +// } +//} + +void Daemon::closeSession() +{ + if(pre_session.path() != ""){ + if (nullptr != filePtr) + { + qDebug() << Q_FUNC_INFO << pre_session.path() << filePtr->objectPath().path(); + //防止因连接失败而导致间隙时间置为Queued状态无法回归正常状态 + QDBusMessage statusChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "statusChanged"); + QMetaEnum metaEnum = QMetaEnum::fromType(); + statusChanged << metaEnum.valueToKey(BluezQt::ObexTransfer::Error) << transferDev << filePtr->objectPath().path(); + QDBusConnection::sessionBus().send(statusChanged); + + BluezQt::PendingCall * stopFileSend = filePtr->cancel(); + connect(stopFileSend,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *q){ + qDebug() << Q_FUNC_INFO << q->errorText() << __LINE__; + _ObexManager->removeSession(pre_session); + }); + } else { + _ObexManager->removeSession(pre_session); + } + } +} + +void Daemon::setBluetoothBlock(bool) +{ + +} + +/************************************************ + * @brief 监听gsetting key的改变,并同步更新对应的value + * @param key value改变的键名 + * @return null +*************************************************/ +void Daemon::gsettingsChangedSlot(const QString &key) +{ + if (_mGsetting.keys().contains(key)) { + qInfo() << Q_FUNC_INFO << QString("%1 changed, old value %2, new value %3").arg(key).arg(_mGsetting[key].toString()).arg(Config::gsetting->get(key).toString()); + _mGsetting[key] = Config::gsetting->get(key); + + } + if(GSETTING_STR_ACTIVE_CONNECTION_TRAN == key || GSETTING_STR_ACTIVE_CONNECTION == key) + { + _mGsetting[GSETTING_STR_ACTIVE_CONNECTION] = Config::gsetting->get(key); + global_activeconn_switch = Config::gsetting->get(key).toBool(); + qInfo() << Q_FUNC_INFO << GSETTING_STR_ACTIVE_CONNECTION << global_activeconn_switch; + } +} + +void Daemon::rfkillStatusChange(int status) +{ + qInfo() << Q_FUNC_INFO << "rfkill status changed" << status; + + switch (status) { + case 0: + initBluezManager(); + + qInfo() << Q_FUNC_INFO << "init defualt Adapter!!!" << _BluezManager->isBluetoothOperational(); + + if (findStartupOptions("-o") || findStartupOptions("--obex")) + { + //非华为机器才存在文件传输功能 + if(Environment::HUAWEI != envPC) + { + initObexManager(); + } + } + + monitorDbusSignal(); + break; + case 1: + break; + default: + break; + } +} + +/************************************************ + * @brief 将gsettings配置存入map统一管理 + * @param null + * @return null +*************************************************/ +void Daemon::initGSettingInfo() +{ + _mGsetting.clear(); + _mGsetting[GSETTING_STR_BLUETOOTH_POWER_SWTICH] = Config::gsetting->get(GSETTING_STR_BLUETOOTH_POWER_SWTICH); + _mGsetting[GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH] = Config::gsetting->get(GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH); + _mGsetting[GSETTING_STR_FINALLY_CONNECT_THE_DEVICE] = Config::gsetting->get(GSETTING_STR_FINALLY_CONNECT_THE_DEVICE); + _mGsetting[GSETTING_STR_ADAPTER_ADDRESS] = Config::gsetting->get(GSETTING_STR_ADAPTER_ADDRESS); + _mGsetting[GSETTING_STR_FILE_SAVE_PATH] = Config::gsetting->get(GSETTING_STR_FILE_SAVE_PATH); + _mGsetting[GSETTING_STR_ADAPTER_ADDRESS_LIST] = Config::gsetting->get(GSETTING_STR_ADAPTER_ADDRESS_LIST); + _mGsetting[GSETTING_STR_ACTIVE_CONNECTION] = Config::gsetting->get(GSETTING_STR_ACTIVE_CONNECTION); + global_activeconn_switch = _mGsetting[GSETTING_STR_ACTIVE_CONNECTION].toBool(); + connect(Config::gsetting,SIGNAL(changed(QString)),this,SLOT(gsettingsChangedSlot(QString))); + +} + +/************************************************ + * @brief 初始系统蓝牙服务,设置设备授权代理 + * @param null + * @return null +*************************************************/ +void Daemon::initBluezManager() +{ + if (_BluezManager) + return; + + //启动_BluezManager, 直到成功启动退出循环 + while(true) + { + _BluezManager = new BluezQt::Manager(this); + BluezQt::InitManagerJob *job = _BluezManager->init(); + job->exec(); + + if(!_BluezManager->isOperational()){ + qWarning("BlueZ system daemon is not running"); + delete _BluezManager; + _BluezManager = nullptr; + qWarning("BlueZ system daemon restart"); + QThread::sleep(5); + } + else + { + qInfo("BlueZ system daemon start suc"); + break; + } + } + + + _BluezManager = new BluezQt::Manager(this); + BluezQt::InitManagerJob *job = _BluezManager->init(); + job->exec(); + + if(!_BluezManager->isInitialized()){ + qWarning("BluezQt::Manager init failed !!!"); + return; + } + + connect(_BluezManager,&BluezQt::Manager::operationalChanged,this,[=](bool operational){ + qInfo() << Q_FUNC_INFO << "operationalChanged" << operational; + if (operational) { + qInfo() << Q_FUNC_INFO << "Bluez Manager restart"; + registerBluezAgent(); + }/* else { + if (_DefualtAdapter) { + if (abs(QDateTime::currentMSecsSinceEpoch() - ::powerChangeTime) >= 300) { + ::rebootFlag = true; + } else { + ::rebootFlag = false; + } + } + qDebug() << Q_FUNC_INFO << __LINE__ << " ::rebootFlag " << ::rebootFlag; + }*/ + }); + + connect(_BluezManager,&BluezQt::Manager::adapterAdded,this,[=](BluezQt::AdapterPtr ptr){ + Q_UNUSED(ptr) + qInfo() << Q_FUNC_INFO << "adapterAdded"; + + if(Daemon::_BluezManager->adapters().size() == 1) + { + Daemon::_DefualtAdapter = ptr; + } + }); + + connect(_BluezManager,&BluezQt::Manager::usableAdapterChanged,this,[=](BluezQt::AdapterPtr ptr){ + Q_UNUSED(ptr) + qInfo() << Q_FUNC_INFO << "usableAdapterChanged" ; + _DefualtAdapter = getDefualtAdapter(); + qDebug() << Q_FUNC_INFO << _DefualtAdapter.data()->name(); + + launchDbusSignal(); + + }); + + connect(_BluezManager,&BluezQt::Manager::adapterChanged,this,[=](BluezQt::AdapterPtr ptr){ + Q_UNUSED(ptr) + qInfo() << Q_FUNC_INFO << "adapterChanged"; + }); + + connect(_BluezManager,&BluezQt::Manager::bluetoothOperationalChanged,this,[=](bool operational){ + qInfo() << Q_FUNC_INFO << "bluetoothOperationalChanged" << operational << resetFlag << QDateTime::currentMSecsSinceEpoch(); + + }); + + connect(_BluezManager,&BluezQt::Manager::bluetoothBlockedChanged,this,[=](bool operational){ + + ::blockChangeTime = QDateTime::currentMSecsSinceEpoch(); + + qInfo() << Q_FUNC_INFO << "bluetoothBlockedChanged" << operational; + + if (operational) { +// qDebug() << Q_FUNC_INFO << "====================="<< blockChangeTime << powerChangeTime << abs(blockChangeTime - powerChangeTime); + if (abs(::blockChangeTime - ::powerChangeTime) >= 300) + ::resetFlag = true; + else + ::resetFlag = false; + } + qDebug() << Q_FUNC_INFO << __LINE__ << " ::resetFlag " << ::resetFlag; + }); + + registerBluezAgent(); + + _DefualtAdapter = this->getDefualtAdapter(); + launchDbusSignal(); + launchTrayUI(); + + if (!_DefualtAdapter.isNull()) + { + _DefualtAdapter.data()->setPowered(_mGsetting[GSETTING_STR_BLUETOOTH_POWER_SWTICH].toBool()); + + //intel机型和主线需要安装启动时为开启, + //if ((Environment::INTER == envPC) || (envPC == Environment::NOMAL)) + //{ + _DefualtAdapter.data()->setDiscoverable(_mGsetting[GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH].toBool()); + //} + } + reconnectFunc(); + qInfo() << Q_FUNC_INFO << __LINE__; +} + +void Daemon::continueSendFiles(QString filename) { + qDebug() << Q_FUNC_INFO << filename << __LINE__; + BluezQt::PendingCall *transfer = opp->sendFile(filename); + qDebug() << Q_FUNC_INFO << transfer->error() << transfer->errorText(); + connect(transfer,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ + qDebug() << Q_FUNC_INFO << __LINE__; + QVariant v = call->value(); + filePtr = v.value(); + QString transferPath; + if(!filePtr.isNull()){ + transferPath = filePtr->objectPath().path(); + transfer_file_size = filePtr->size(); + qDebug() << Q_FUNC_INFO << "Sending file size:" << transfer_file_size << filePtr->type() << filePtr->name() <<__LINE__; + + QDBusMessage initTransferPath = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "initTransferPath"); + initTransferPath << transferPath; + + QDBusConnection::sessionBus().send(initTransferPath); + + connect(filePtr.data(),&BluezQt::ObexTransfer::transferredChanged,this,[=](quint64 vl){ + qDebug() << Q_FUNC_INFO << "Sending file size:" << vl << __LINE__; + QDBusMessage transferredChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "transferredChanged"); + transferredChanged << vl << transferPath; + + QDBusConnection::sessionBus().send(transferredChanged); + }); + connect(filePtr.data(),&BluezQt::ObexTransfer::statusChanged,this,[=](BluezQt::ObexTransfer::Status status){ + qDebug() << Q_FUNC_INFO << "Sending file size:" << status << __LINE__; + QDBusMessage statusChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "statusChanged"); + QMetaEnum metaEnum = QMetaEnum::fromType(); + statusChanged << QString(metaEnum.valueToKey(status)) << transferDev << transferPath; + QDBusConnection::sessionBus().send(statusChanged); + }); + }else{ + QDBusMessage statusChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "statusChanged"); + statusChanged << QString("Error") << transferDev << transferPath; + + QDBusConnection::sessionBus().send(statusChanged); + } + }); +} + +/************************************************ + * @brief 初始化自定义设备授权代理, 并将初始化的代理设置为默认的设备授权代理 + * @param null + * @return null +*************************************************/ +void Daemon::registerBluezAgent() +{ + qInfo() << Q_FUNC_INFO << "register Bluez Agent"; + if (!_BluezAgent) + _BluezAgent = new BluetoothAgent(this); + + PendingCallProcessingFunc(_BluezManager->registerAgent(_BluezAgent)); +} + +void Daemon::fileTransferSessionCreator(QString address,QString filename) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QMap map; + + map["Source"] = _DefualtAdapter->address(); + map["Target"] = "OPP"; + + if (!_ObexManager->isOperational()) { + connect(_ObexManager, &BluezQt::ObexManager::operationalChanged, this, [=](bool operational) { + Q_UNUSED(operational) + fileTransferSessionCreator(address, filename); + qDebug() << Q_FUNC_INFO << __LINE__; + disconnect(_ObexManager, &BluezQt::ObexManager::operationalChanged, nullptr, nullptr); + }); + return; + } + + transferDev = address; + + BluezQt::PendingCall *target = _ObexManager->createSession(address,map); + qDebug() << Q_FUNC_INFO << target->error() << target->errorText(); + connect(target,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ + QVariant v = call->value(); + QDBusObjectPath session = v.value(); + + pre_session = session; + opp = new BluezQt::ObexObjectPush(session); + if (QDBusConnection::sessionBus().connect(SERVICE, PATH, + INTERFACE, "continueSendFilesSignal", this, + SLOT(continueSendFiles(QString)))) { + qDebug() << "devConnectStatusSignal signal connected successfully to slot"; + } else { + qDebug() << "devConnectStatusSignal signal connection was not successful"; + } + + //将点击发送到设备连接之间的时间设置为queued状态,防止间隙异常操作 + QDBusMessage statusChanged = QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + "statusChanged"); + QMetaEnum metaEnum = QMetaEnum::fromType(); + statusChanged << metaEnum.valueToKey(BluezQt::ObexTransfer::Queued) << transferDev << QString(""); + QDBusConnection::sessionBus().send(statusChanged); + + continueSendFiles(filename); + }); +} + +/************************************************ + * @brief 初始文件传输服务,设置文件传输代理 + * @param null + * @return null +*************************************************/ +void Daemon::initObexManager() +{ + if (_ObexManager) + return; + + _ObexManager = new BluezQt::ObexManager(this); + BluezQt::InitObexManagerJob *obex_job = _ObexManager->init(); + obex_job->exec(); + + registerObexAgent(); +} + +/************************************************ + * @brief 初始化自定义文件传输代理 , 并将初始化的代理设置为默认的文件传输代理 + * @param null + * @return null +*************************************************/ +void Daemon::registerObexAgent() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + if (!_ObexAgent) + _ObexAgent = new BluetoothObexAgent(this); + + qInfo() << Q_FUNC_INFO << __LINE__; + if(!_ObexManager->isOperational()){ + BluezQt::PendingCall *call = _ObexManager->startService(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *q){ + QTimer::singleShot(1000,this,[=]{ + PendingCallProcessingFunc(_ObexManager->registerAgent(_ObexAgent)); + }); + }); + }else{ + PendingCallProcessingFunc(_ObexManager->registerAgent(_ObexAgent)); + } +} + +void Daemon::launchTrayUI() +{ + Config::LaunchUI(); +} + +/************************************************ + * @brief 从系统的gsetting和自定义逻辑中返回默认的配置器 + * @param null + * @return 默认适配器共享指针 BluezQt::AdapterPtr +*************************************************/ +BluezQt::AdapterPtr Daemon::getDefualtAdapter() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + //设置控制面板默认显示窗口状态 + Config::ukccGsetting->set("show",QVariant(!(_BluezManager->adapters().size() == 0))); + + if(_BluezManager->adapters().size() == 0){ + + qWarning("No bluetooth adapter !!!"); + return nullptr; + + }else if(_BluezManager->adapters().size() == 1){ + + return _BluezManager->adapters().at(0); + //_DefualtAdapter isNull + //Config::gsetting->set(GSETTING_STR_ADAPTER_ADDRESS,QVariant::fromValue(_DefualtAdapter->address())); + + }else{ + if(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS_LIST].toStringList().indexOf(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS].toString()) != -1){ + return _BluezManager->adapterForAddress(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS].toString()); + }else{ + //这里adapter-address-list的数据不一定存在 + if (_mGsetting[GSETTING_STR_ADAPTER_ADDRESS_LIST].toStringList().size() > 0) + { + return _BluezManager->adapterForAddress(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS_LIST].toStringList().at(0)); + } + else + { + return _BluezManager->adapterForAddress(_mGsetting[GSETTING_STR_ADAPTER_ADDRESS].toString()); + } + } + } + qWarning("get bluetooth adapter nullptr!!! adaptersize<%d>", _BluezManager->adapters().size()); + return nullptr; + +} + +/************************************************ + * @brief 默认适配器属性变化信号与自定义dbus信号关联 + * @param null + * @return null +*************************************************/ +//void Daemon::connectDefualtSignal() +//{ +// qInfo() << Q_FUNC_INFO << __LINE__; +// devScanSignal = createCustomSignalMsg("deviceScanResult"); +// adapterPowerSignal = createCustomSignalMsg("defaultAdapterPowerChanged"); +// adapterScanStatusSignal = createCustomSignalMsg("defaultScanStatusChanged"); +// adapterDiscoverableSignal = createCustomSignalMsg("defaultDiscoverableChanged"); + +// qDebug() << Q_FUNC_INFO << this->receivers(SIGNAL(poweredChanged(bool))); + +// connect(_DefualtAdapter.data(),&BluezQt::Adapter::deviceAdded,this,[=](BluezQt::DevicePtr devPtr){ +// devScanSignal << devPtr.data()->address() << devPtr.data()->name(); +// QDBusConnection::sessionBus().send(devScanSignal); +// },Qt::UniqueConnection); + +// connect(_DefualtAdapter.data(),&BluezQt::Adapter::poweredChanged,this,[=](bool powered){ +// qDebug() << Q_FUNC_INFO << __LINE__; +// adapterPowerSignal << powered; +// qDebug() << Q_FUNC_INFO << QDBusConnection::sessionBus().send(adapterPowerSignal) << __LINE__; +// },Qt::UniqueConnection); + +// connect(_DefualtAdapter.data(),&BluezQt::Adapter::discoveringChanged,this,[=](bool powered){ +// adapterScanStatusSignal << powered; +// QDBusConnection::sessionBus().send(adapterScanStatusSignal); +// },Qt::UniqueConnection); + +// connect(_DefualtAdapter.data(),&BluezQt::Adapter::discoverableChanged,this,[=](bool discoverable){ +// adapterDiscoverableSignal << discoverable; +// QDBusConnection::sessionBus().send(adapterDiscoverableSignal); +// },Qt::UniqueConnection); +// qInfo() << Q_FUNC_INFO << __LINE__; +//} + + +/************************************************ + * @brief 创建QDBusMessage工厂函数 + * @param signalName 需要创建的 QDBusMessage 名字 + * @return 返回类型为 QDBusMessage +*************************************************/ +QDBusMessage Daemon::createCustomSignalMsg(QString signalName) +{ + return QDBusMessage::createSignal("/com/ukui/bluetooth", + "com.ukui.bluetooth", + signalName); +} + +/************************************************ + * @brief 创建QDBusMessage工厂函数 + * @param signalName 需要创建的 QDBusMessage 名字 + * @return 返回类型为 QDBusMessage +*************************************************/ +void Daemon::monitorSleepSlot(bool sleep) +{ + qDebug () << __FUNCTION__ << "app is sleep: " << sleep << __LINE__; + ::systemSleepFlag = sleep; + if(!sleep) + { + qDebug() << "System wakes up from sleep !!!"; + + if (adapterRemoveFlag) { + QEventLoop eventloop; + connect(_BluezManager,&BluezQt::Manager::adapterAdded,&eventloop,&QEventLoop::quit); + eventloop.exec(); + } + + _DefualtAdapter = getDefualtAdapter(); + launchDbusSignal(); + + reconnectFunc(); + + } + else + { + qDebug() << "System goes to sleep !!!"; + if (_DefualtAdapter) { + if (abs(QDateTime::currentMSecsSinceEpoch() - ::powerChangeTime) >= 300) { + ::sleepFlag = false; + } else { + ::sleepFlag = true; + } + } + } + qDebug() << Q_FUNC_INFO << "end"; + +} + +/************************************************ + * @brief 监听dbus信号 + * @param null + * @return null +*************************************************/ +void Daemon::monitorDbusSignal() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + //部分机器在系统s3/s4会对蓝牙适配器进行移除添加操作 + if (QDBusConnection::systemBus().connect("org.freedesktop.login1", "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", "PrepareForSleep", this, + SLOT(monitorSleepSlot(bool)))) { + qDebug() << "PrepareForSleep signal connected successfully to slot"; + } else { + qDebug() << "PrepareForSleep signal connection was not successful"; + } + + if (QDBusConnection::sessionBus().connect(SERVICE, PATH, + INTERFACE, "sendFile", this, + SLOT(sendFile(QString,QString)))) { + qDebug() << "sendFile signal connected successfully to slot"; + } else { + qDebug() << "sendFile signal connection was not successful"; + } + if (QDBusConnection::sessionBus().connect(SERVICE, PATH, + INTERFACE, "defaultAdapterPowerChanged", this, + SLOT(test(bool)))) { + qDebug() << "defaultAdapterPowerChanged signal connected successfully to slot"; + } else { + qDebug() << "defaultAdapterPowerChanged signal connection was not successful"; + } + if (QDBusConnection::sessionBus().connect(SERVICE, PATH, + INTERFACE, "requestConfirmation", this, + SLOT(test1(QString,QString)))) { + qDebug() << "devConnectStatusSignal signal connected successfully to slot"; + } else { + qDebug() << "devConnectStatusSignal signal connection was not successful"; + } + if (QDBusConnection::sessionBus().connect(SERVICE, PATH, + INTERFACE, "closeSessionSignal", this, + SLOT(closeSession()))) { + qDebug() << "closeSessionSignal signal connected successfully to slot"; + } else { + qDebug() << "closeSessionSignal signal connection was not successful"; + } +} + +void Daemon::launchDbusSignal() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusInterface interface(SERVICE,PATH,INTERFACE,QDBusConnection::sessionBus()); + interface.call("connectSignal"); + qDebug() << Q_FUNC_INFO << "end"; +} + +void Daemon::devConnectSignalDbus(QString address) +{ + //停止扫描,连接完成或连接超时后继续开启扫描 + //setDefaultAdapterScanOn(false); + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall("com.ukui.bluetooth", + "/com/ukui/bluetooth", + "com.ukui.bluetooth", + "devConnect"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void Daemon::reconnectFunc() +{ + qInfo() << Q_FUNC_INFO << "START"; + + if (_DefualtAdapter.isNull() || !_DefualtAdapter.data()->isPowered()) { + qInfo() << Q_FUNC_INFO << "Adapter is null or power down;"; + return; + } + + QStringList target_list = Config::getDeviceConnectTimeList(QString("/etc/pairDevice.list")); + qInfo() << "reconnect dev list" << target_list; + qDebug() << Q_FUNC_INFO << target_list; + foreach (QString dev_address, target_list) { + if (nullptr == _DefualtAdapter) + { + qInfo() << Q_FUNC_INFO << "_DefualtAdapter is null!!"; + return ; + } + BluezQt::DevicePtr dev = _DefualtAdapter->deviceForAddress(dev_address); + + if (dev != nullptr) { + if (dev.data()->isConnected()) + break; + + if (dev.data()->type() == BluezQt::Device::Headset || + dev.data()->type() == BluezQt::Device::Headphones || + dev.data()->type() == BluezQt::Device::AudioVideo) { + + devConnectSignalDbus(dev.data()->address()); + //dev->connectToDevice(); + } + } + } + + qInfo() << Q_FUNC_INFO << "END"; +} + +/*void Daemon::sendDevSignal(DevOperate vlaue,const QString addr) +{ + QDBusMessage sendSignal; + + switch (vlaue) { + case DevOperate::PAIR: + sendSignal = createCustomSignalMsg("devPairSignal"); + break; + case DevOperate::CONNECT: + sendSignal = createCustomSignalMsg("devConnectSignal"); + break; + case DevOperate::DISCONNECT: + sendSignal = createCustomSignalMsg("devDisconnectSignal"); + break; + case DevOperate::REMOVE: + sendSignal = createCustomSignalMsg("devRemoveSignal"); + break; + case DevOperate::TRUST: + + break; + default: + sendSignal = createCustomSignalMsg("devOperateErrorSignal"); + break; + } + + sendSignal << addr; + + QDBusConnection::sessionBus().send(sendSignal); +}*/ diff --git a/service/daemon.h b/service/daemon.h new file mode 100644 index 0000000..f581dcb --- /dev/null +++ b/service/daemon.h @@ -0,0 +1,127 @@ +#ifndef DAEMON_H +#define DAEMON_H + +#include "bluetoothagent.h" +#include "bluetoothobexagent.h" +#include "config.h" +#include "rfkill.h" +//#include "../ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h" + +#ifdef BATTERY +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern qint64 powerChangeTime; +extern bool resetFlag; +extern bool rebootFlag; +extern bool adapterRemoveFlag; + +enum DevOperate { + PAIR = 0, + CONNECT, + DISCONNECT, + REMOVE, + TRUST, + ERROR, +}; + +class Daemon : public QObject +{ + Q_OBJECT +public: + explicit Daemon(QObject *parent = nullptr); + ~Daemon(); + + static BluezQt::AdapterPtr _DefualtAdapter; + static BluezQt::Manager *_BluezManager; + + static void setBluetoothBlock(bool); +// static void devOperateFunc(const QString,const DevOperate,const bool value = false); +// static void sendDevSignal(DevOperate,QString); + static QDBusMessage createCustomSignalMsg(QString); + static void reconnectFunc(); + static void devConnectSignalDbus(QString); + + +Q_SIGNALS: + void startThread(); + +private slots: + void gsettingsChangedSlot(const QString &); + void rfkillStatusChange(int); + void sendFile(QString,QString); + void test(bool); + void test1(QString,QString); + void closeSession(); + void continueSendFiles(QString filename); + void monitorSleepSlot(bool); + +private: + void initGSettingInfo(); + void initBluezManager(); + void registerBluezAgent(); + void fileTransferSessionCreator(QString,QString); + void initObexManager(); + void registerObexAgent(); + void launchTrayUI(); + BluezQt::AdapterPtr getDefualtAdapter(); +// void connectDefualtSignal(); + void monitorDbusSignal(); + void launchDbusSignal(); + + QString getFileName(); + + Rfkill *_rfkill = nullptr; + QThread *_rfkillThread = nullptr; + Config *_mConfig = nullptr; + QMap _mGsetting; + +// QDBusMessage devScanSignal; +// QDBusMessage adapterPowerSignal; +// QDBusMessage adapterDiscoverableSignal; +// QDBusMessage adapterScanStatusSignal; + + QString selected_file; + QDBusObjectPath pre_session; + quint64 transfer_file_size = 0; + + BluezQt::ObexObjectPush *opp = nullptr; + BluezQt::ObexTransferPtr filePtr = nullptr; + BluezQt::ObexManager *_ObexManager = nullptr; + BluetoothAgent *_BluezAgent = nullptr; + BluetoothObexAgent *_ObexAgent = nullptr; + QString transferDev; +// BluetoothFileTransferWidget *transfer_widget = nullptr; +}; + +#endif // DAEMON_H diff --git a/service/globalsize.cpp b/service/globalsize.cpp new file mode 100644 index 0000000..4c358c2 --- /dev/null +++ b/service/globalsize.cpp @@ -0,0 +1,42 @@ +#include "globalsize.h" + +QMap GlobalSize::m_static_devconnectcount; + + +int GlobalSize::refBlueDevActive(QString key) +{ + if(m_static_devconnectcount.contains(key)) + { + m_static_devconnectcount[key] = m_static_devconnectcount[key] + 1; + } + else + { + m_static_devconnectcount[key] = 1; + } + return m_static_devconnectcount[key]; +} + +int GlobalSize::unrefBlueDevActive(QString key) +{ + if(m_static_devconnectcount.contains(key)) + { + m_static_devconnectcount[key] = m_static_devconnectcount[key] -1; + if(0 == m_static_devconnectcount[key]) + { + m_static_devconnectcount.remove(key); + return 0; + } + return m_static_devconnectcount[key]; + } + return 0; +} + +bool GlobalSize::IsBlueDevActive(QString key) +{ + return m_static_devconnectcount.contains(key); +} + +int GlobalSize::BlueDevActiveSize(void) +{ + return m_static_devconnectcount.size(); +} diff --git a/service/globalsize.h b/service/globalsize.h new file mode 100644 index 0000000..6f0f8e6 --- /dev/null +++ b/service/globalsize.h @@ -0,0 +1,26 @@ +#ifndef GLOBALSIZE_H +#define GLOBALSIZE_H + +#include +#include +#include + + +class GlobalSize +{ +public: + static int refBlueDevActive(QString key); + + static int unrefBlueDevActive(QString key); + + static bool IsBlueDevActive(QString key); + + static int BlueDevActiveSize(void); + + +protected: + //主动连接标志 + static QMap m_static_devconnectcount; +}; + +#endif // GLOBALSIZE_H diff --git a/service/main.cpp b/service/main.cpp new file mode 100644 index 0000000..4808e0b --- /dev/null +++ b/service/main.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include "daemon.h" +#include "sessiondbusregister.h" + + +extern "C" { + #include + #include +} + +void signalHandlerFunc(int signal) { + fprintf(stderr,"---------------------- %d",signal); +} + + +static QString executeLinuxCmd(QString strCmd) +{ + QProcess p; + p.start("bash", QStringList() <<"-c" << strCmd); + p.waitForFinished(); + QString strResult = p.readAllStandardOutput(); + return strResult.toLower(); +} + +static void setEnvPCValue() +{ + envPC = Environment::NOMAL; + + QString str = executeLinuxCmd("cat /proc/cpuinfo | grep Hardware"); + if(str.length() == 0) + { + goto FuncEnd; + } + + if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || + str.indexOf("kirin") != -1) + { + envPC = Environment::HUAWEI; + } + +FuncEnd: + if (QFile::exists("/etc/apt/ota_version")) + envPC = Environment::INTER; + +} + +int main(int argc, char *argv[]) +{ + fprintf(stdout,"Program running.....\n"); + initUkuiLog4qt(QString("bluetoothserver")); + + setEnvPCValue(); + qDebug() << "envPC: "<< envPC; + + QtSingleCoreApplication a(argc, argv); + a.setOrganizationName("Kylin Team"); + a.setApplicationName("dbus-bluetooth-service"); + a.setApplicationVersion("1.0.0"); + + if (a.isRunning()) { + qDebug() << "bus-bluetooth-service is Already running ! ! !"; + return EXIT_SUCCESS; + } else { +// signal(SIGKILL,signalHandlerFunc); +// signal(SIGQUIT,signalHandlerFunc); + + QCommandLineParser parser; + parser.addHelpOption(); + parser.addVersionOption(); + parser.addOptions({{{"o","obex"},QCoreApplication::translate("main","Load the Bluetooth file transfer agent")}}); + + parser.setApplicationDescription(QCoreApplication::translate("main","UKUI bluetooth daemon")); + parser.process(a); + + // QDBusConnection systemBus = QDBusConnection::systemBus(); + // if (!systemBus.registerService("com.bluetooth.systemdbus")){ + // qCritical() << "QDbus register service failed reason:" << systemBus.lastError(); + // //exit(1); + // } + + // if (!systemBus.registerObject("/", "com.bluetooth.interface", new SysDbusRegister(), QDBusConnection::ExportAllSlots)){ + // qCritical() << "QDbus register object failed reason:" << systemBus.lastError(); + // //exit(2); + // } + // qDebug() << "ok"; + SessionDbusRegister *sessionDbus = new SessionDbusRegister(); + Q_UNUSED(sessionDbus); + + Daemon *daemon = new Daemon(); + Q_UNUSED(daemon); + + int quitValue = a.exec(); + + delete sessionDbus; + delete daemon; + + qInfo() << Q_FUNC_INFO << "Daemon program exit!!!!"; + + return quitValue; + } +} diff --git a/service/rfkill.cpp b/service/rfkill.cpp new file mode 100644 index 0000000..cc19ee3 --- /dev/null +++ b/service/rfkill.cpp @@ -0,0 +1,212 @@ +#include "rfkill.h" + +enum rfkill_type { + RFKILL_TYPE_ALL = 0, + RFKILL_TYPE_WLAN, + RFKILL_TYPE_BLUETOOTH, + RFKILL_TYPE_UWB, + RFKILL_TYPE_WIMAX, + RFKILL_TYPE_WWAN +}; + +enum rfkill_operation { + RFKILL_OP_ADD = 0, + RFKILL_OP_DEL, + RFKILL_OP_CHANGE, + RFKILL_OP_CHANGE_ALL +}; + +struct rfkill_event { + quint32 idx; + quint8 type; + quint8 op; + quint8 soft; + quint8 hard; +}; + +Rfkill::Rfkill(QObject *parent) : + QObject(parent), + _mReadFd(-1), + _mWriteFd(-1), + _mState(Unknown) +{ +// init(); +} + +Rfkill::~Rfkill() +{ + if (_mReadFd != -1) { + close(_mReadFd); + } + + if (_mWriteFd != -1) { + close(_mWriteFd); + } +} + +Rfkill::State Rfkill::state() const +{ + return _mState; +} + +bool Rfkill::block() +{ + if (_mState == SoftBlocked || _mState == HardBlocked) { + return true; + } + + if (_mState != Unblocked) { + return false; + } + + return setSoftBlock(1); +} + +bool Rfkill::unblock() +{ + if (_mState == Unblocked) { + return true; + } + + if (_mState != SoftBlocked) { + return false; + } + + return setSoftBlock(0); +} + +void Rfkill::init() +{ + _mReadFd = open("/dev/rfkill", O_RDONLY | O_CLOEXEC); + + if (_mReadFd == -1) { + qDebug() << Q_FUNC_INFO << "Cannot open /dev/rfkill for reading!"; + return; + } + + if (fcntl(_mReadFd, F_SETFL, O_NONBLOCK) < 0) { + close(_mReadFd); + _mReadFd = -1; + return; + } + + updateRfkillDevices(); + + QSocketNotifier *notifier = new QSocketNotifier(_mReadFd, QSocketNotifier::Read, this); + connect(notifier, &QSocketNotifier::activated, this, &Rfkill::devReadyRead); +} + +void Rfkill::devReadyRead() +{ + State oldState = _mState; + + updateRfkillDevices(); + + if (_mState != oldState) { + emit stateChanged(_mState); + } +} + +static Rfkill::State getState(rfkill_event event) +{ + if (event.hard) { + return Rfkill::HardBlocked; + } else if (event.soft) { + return Rfkill::SoftBlocked; + } + return Rfkill::Unblocked; +} + +void Rfkill::updateRfkillDevices() +{ + if (_mReadFd == -1) { + return; + } + + rfkill_event event; + while (read(_mReadFd, &event, sizeof(event)) == sizeof(event)) { + qDebug() << Q_FUNC_INFO << QString("idx %1 type %2 op %3 soft %4 hard %5").arg(event.idx).arg(event.type).arg(event.op).arg(event.soft).arg(event.hard); + if (event.type != RFKILL_TYPE_BLUETOOTH) { + continue; + } + + switch (event.op) { + case RFKILL_OP_ADD: + emit rfkillStatusChanged(RFKILL_OP_ADD); + _mDevices[event.idx] = getState(event); + break; + case RFKILL_OP_CHANGE: + _mDevices[event.idx] = getState(event); + break; + + case RFKILL_OP_DEL: + emit rfkillStatusChanged(RFKILL_OP_DEL); + _mDevices.remove(event.idx); + break; + + case RFKILL_OP_CHANGE_ALL: + for (auto it = _mDevices.begin(); it != _mDevices.end(); ++it) { + it.value() = getState(event); + } + break; + + default: + break; + } + } + + // Update global state + _mState = Unknown; + + for (State state : qAsConst(_mDevices)) { + Q_ASSERT(state != Unknown); + + if (_mState == Unknown) { + _mState = state; + } else if (state > _mState) { + _mState = state; + } + } + + qDebug() << "Rfkill global state changed:" << _mState; + qDebug() << "Rfkill currentThreadId :" << QThread::currentThreadId(); +} + +bool Rfkill::openForWriting() +{ + if (_mWriteFd != -1) { + return true; + } + + _mWriteFd = open("/dev/rfkill", O_WRONLY | O_CLOEXEC); + + if (_mWriteFd == -1) { + qDebug() << "Cannot open /dev/rfkill for writing!"; + return false; + } + + if (fcntl(_mWriteFd, F_SETFL, O_NONBLOCK) < 0) { + close(_mWriteFd); + _mWriteFd = -1; + return false; + } + + return true; +} + +bool Rfkill::setSoftBlock(quint8 soft) +{ + if (!openForWriting()) { + return false; + } + + rfkill_event event; + memset(&event, 0, sizeof(event)); + event.op = RFKILL_OP_CHANGE_ALL; + event.type = RFKILL_TYPE_BLUETOOTH; + event.soft = soft; + + bool ret = write(_mWriteFd, &event, sizeof(event)) == sizeof(event); + qDebug() << "Setting Rfkill soft block succeeded:" << ret; + return ret; +} diff --git a/service/rfkill.h b/service/rfkill.h new file mode 100644 index 0000000..f7d01bf --- /dev/null +++ b/service/rfkill.h @@ -0,0 +1,49 @@ +#ifndef RFKILL_H +#define RFKILL_H + +#include +#include +#include +#include + +extern "C" { + #include + #include +} + +class Rfkill : public QObject +{ + Q_OBJECT +public: + enum State { + Unblocked = 0, + SoftBlocked = 1, + HardBlocked = 2, + Unknown = 3 + }; + + explicit Rfkill(QObject *parent = nullptr); + ~Rfkill(); + State state() const; + bool block(); + bool unblock(); +public slots: + void init(); + +private: + void devReadyRead(); + void updateRfkillDevices(); + bool openForWriting(); + bool setSoftBlock(quint8); +signals: + void stateChanged(State); + void rfkillStatusChanged(quint64); + +private: + State _mState; + int _mReadFd; + int _mWriteFd; + QHash _mDevices; +}; + +#endif // RFKILL_H diff --git a/service/service.pro b/service/service.pro new file mode 100644 index 0000000..060cfb3 --- /dev/null +++ b/service/service.pro @@ -0,0 +1,87 @@ +###################################################################### +# Automatically generated by qmake (3.1) Thu Mar 4 18:08:23 2021 +###################################################################### + +TEMPLATE = app +TARGET = bluetoothService +INCLUDEPATH += . + +include(../qtsingleapplication/qtsinglecoreapplication.pri) +include(../environment.pri) + +QT += core gui dbus + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 link_pkgconfig + +PKGCONFIG += gsettings-qt gio-2.0 +LIBS +=-lpthread +#LIBS +=-lX11 -lXrandr -lXinerama -lXi -lXcursor + +LIBS += -lglib-2.0 -lKF5BluezQt -lukui-log4qt + +QMAKE_LFLAGS += -D_FORTIFY_SOURCE=2 -O2 + +#ins1.files += ../data/com.bluetooth.systemdbus.conf +#ins1.path = $$CONF_INSTALL_DIR +#ins2.files += ../data/com.bluetooth.systemdbus.service +#ins2.path = /usr/share/dbus-1/system-services/ +#ins3.files += ../data/com.bluetooth.systemdbus.policy +#ins3.path = /usr/share/polkit-1/actions/ +target.source += $$TARGET +target.path = $$BIN_INSTALL_DIR +inst1.files += ../data/org.ukui.log4qt.bluetoothserver.gschema.xml +inst1.path = $$SCHEMAS_INSTALL_DIR +INSTALLS += target + +# The following define makes your compiler warn you if you use any +# feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +exists(/usr/include/KF5/BluezQt/bluezqt/battery.h){DEFINES += BATTERY} + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +# Input +#HEADERS += +SOURCES += main.cpp \ +# ../ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp \ +# ../ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp \ +# ../ukui-bluetooth/fileSend/deviceseleterwidget.cpp \ +# ../ukui-bluetooth/pin/pincodewidget.cpp \ +# ../ukui-bluetooth/config/xatom-helper.cpp \ + bluetoothagent.cpp \ + bluetoothobexagent.cpp \ + config.cpp \ + daemon.cpp \ + globalsize.cpp \ + rfkill.cpp \ + sessiondbusregister.cpp\ + tmpdevclear.cpp + + +HEADERS += \ +# ../ukui-bluetooth/fileReceive/filereceivingpopupwidget.h \ +# ../ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h \ +# ../ukui-bluetooth/fileSend/deviceseleterwidget.h \ +# ../ukui-bluetooth/pin/pincodewidget.h \ +# ../ukui-bluetooth/config/xatom-helper.h \ + bluetoothagent.h \ + bluetoothobexagent.h \ + config.h \ + daemon.h \ + globalsize.h \ + rfkill.h \ + sessiondbusregister.h \ + tmpdevclear.h + +TRANSLATIONS += ../translations/ukui-bluetooth_zh_CN.ts + +OBJECTS_DIR = ./obj/ +MOC_DIR = ./moc/ diff --git a/service/sessiondbusregister.cpp b/service/sessiondbusregister.cpp new file mode 100644 index 0000000..f4f45bb --- /dev/null +++ b/service/sessiondbusregister.cpp @@ -0,0 +1,1671 @@ +#include "sessiondbusregister.h" +#include +#include +#include + +#include "tmpdevclear.h" +#include "globalsize.h" + +#define TIMER_TIMEOUT (2*1000) + +extern qint64 powerChangeTime; +extern bool resetFlag; +extern bool sleepFlag; +extern bool systemSleepFlag; + + + +QString global_active_connection_dev = ""; +bool global_activeconn_switch = true; +static QTimer * static_active_timer = nullptr; +static QSet static_black_activeconn_dev; + +bool static_DefaultAdapterPower = true; + +static bool isScan = false; +static SessionDbusRegister * static_sess = nullptr; +static QMap static_delays; +static QMap devConnectAgainMap; + +//检测bluez重启参数 +//bluez重启(停止然后启动)后,关闭适配器蓝牙,移除蓝牙适配器,新增蓝牙适配器 +static int static_bluezreboot_power = -1; + +//仅适合单线程模式 +int cancelEmitDevStatus(QString addr) +{ + DelayStruct * p = static_delays.value(addr, nullptr); + if(nullptr != p) + { + p->close(); + //从qmap删除 + static_delays.remove(addr); + } + return 0; +} + +DelayStruct::DelayStruct(BluezQt::DevicePtr dev, QObject *parent /*= nullptr*/):QObject(parent) +{ + m_dev = dev; + m_TimerID = this->startTimer(TIMER_TIMEOUT); +} + +DelayStruct::~DelayStruct() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + m_dev = nullptr; +} + +void DelayStruct::close(void) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + this->killTimer(m_TimerID); + this->deleteLater(); +} + +void DelayStruct::timerEvent( QTimerEvent *event) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + if(nullptr != m_dev && nullptr != static_sess) + { + qDebug() << Q_FUNC_INFO << __LINE__ << m_dev->address() << m_dev->isConnected(); + emit static_sess->devConnectStatusSignal(m_dev->address(), m_dev->isConnected()); + if (m_dev->isConnected() && m_dev->isPaired()) { + Config::writeKeyFile(m_dev->address(),m_dev->name(),m_dev->type()); + } + } + //从qmap删除 + if(nullptr != m_dev) + { + static_delays.remove(m_dev->address()); + } + + this->close(); +} + + +static void init_static_sess(SessionDbusRegister * p) +{ + static_sess = p; +} + +void addDelay(BluezQt::DevicePtr dev) +{ + if(nullptr != dev) + { + //非手机、电脑没有必要延迟发送设备状态 + if(dev->type() != BluezQt::Device::Phone && dev->type() != BluezQt::Device::Computer) + { + qDebug() << Q_FUNC_INFO << __LINE__ << dev->address() << dev->isConnected(); + emit static_sess->devConnectStatusSignal(dev->address(), dev->isConnected()); + if (dev->isConnected() && dev->isPaired()) { + Config::writeKeyFile(dev->address(), dev->name(), dev->type()); + } + } + else + { + QString key = dev->address(); + //未找到 + if(static_delays.find(key) == static_delays.end()) + { + DelayStruct * p = new DelayStruct(dev); + static_delays[key] = p; + } + } + } +} + +static bool existDelay(QString key) +{ + return (static_delays.find(key) != static_delays.end()); +} + +////////////////////////////////////////////SessionDbusRegister//////////////////////////////////// +////////////////////////////////////////////SessionDbusRegister//////////////////////////////////// + + +static inline bool isAvailableAddress(QString addr) { + if (addr.isEmpty() || addr.isNull()) + return false; + + return true; +} + +SessionDbusRegister::SessionDbusRegister(QObject *parent) : QObject(parent) +{ + qInfo() << Q_FUNC_INFO ; + init_static_sess(this); + if (InterfaceAlreadyExists()) { + QDBusConnection sessionDbus = QDBusConnection::sessionBus(); + if (!sessionDbus.registerService("com.ukui.bluetooth")) { + qCritical() << "QDbus register service failed reason:" << sessionDbus.lastError(); + } + + if (!sessionDbus.registerObject("/com/ukui/bluetooth", "com.ukui.bluetooth", this, QDBusConnection::ExportAllSlots|QDBusConnection::ExportAllSignals)){ + qCritical() << "QDbus register object failed reason:" << sessionDbus.lastError(); + } + } + //控制面板文件发送设备和状态信号改变的记录监听 + QDBusConnection::sessionBus().connect("com.ukui.bluetooth", + "/com/ukui/bluetooth", + "com.ukui.bluetooth", + "statusChanged", + this, + SLOT(dealStatusChanged(QString, QString,QString))); +} + +SessionDbusRegister::~SessionDbusRegister() +{ + +} + +bool SessionDbusRegister::InterfaceAlreadyExists() +{ + QDBusConnection conn = QDBusConnection::sessionBus(); + if (!conn.isConnected()) + return 0; + + QDBusReply reply = conn.interface()->call("GetNameOwner", "com.ukui.bluetooth"); + return reply.value() == ""; +} + +void SessionDbusRegister::AudioDevConnectFunc(BluezQt::DevicePtr dev) +{ + qDebug () << Q_FUNC_INFO << "START" << __LINE__; + + if (dev) + { +// if (Daemon::_DefualtAdapter.data()->isDiscovering()) { +// ::isScan = true; +// BluezQt::PendingCall * stop_call = Daemon::_DefualtAdapter.data()->stopDiscovery(); +// connect(stop_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn) +// { +// qDebug() << Q_FUNC_INFO << "stopDiscovery:" << callReturn->error() << callReturn->errorText() << __LINE__; +// }); +// //qDebug() << Q_FUNC_INFO << "stopDiscovery:111111111111111111" << __LINE__; +// stop_call->waitForFinished(); +// //qDebug() << Q_FUNC_INFO << "stopDiscovery:222222222222222222" << __LINE__; + +// } + + if (dev.data()->type() == BluezQt::Device::AudioVideo || + dev.data()->type() == BluezQt::Device::Headphones || + dev.data()->type() == BluezQt::Device::Headset ) { + + BluezQt::AdapterPtr MDevAdapter = dev.data()->adapter(); + + for (auto tmpdev : MDevAdapter.data()->devices()) { + //id 相同,跳过,避免出现配对后发送断开连接请求 + if (tmpdev->address() == dev->address()) + continue; + + qDebug () << Q_FUNC_INFO << "=======================" << tmpdev.data()->name() << __LINE__; + if (tmpdev.data()->isConnected() && tmpdev.data()->isPaired()) { + if (tmpdev.data()->type() == BluezQt::Device::AudioVideo || + tmpdev.data()->type() == BluezQt::Device::Headphones || + tmpdev.data()->type() == BluezQt::Device::Headset ) { + + qDebug () << Q_FUNC_INFO << "==================disconn=====" << tmpdev.data()->name() << __LINE__; + BluezQt::PendingCall *pending = tmpdev.data()->disconnectFromDevice(); + qDebug () << Q_FUNC_INFO << "=======================" << __LINE__; + connect(pending,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *call){ + qDebug () << Q_FUNC_INFO << "=================conn======" << dev.data()->name() << call << __LINE__; + + if (!call->error()) { + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + GlobalSize::refBlueDevActive(dev->address()); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + GlobalSize::unrefBlueDevActive(dev->address()); + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address(), + callReturn->error(), + callReturn->errorText()); + } + else + { + //主动连接成功后,发送连接成功信号 + addDelay(dev); + } + + //主动连接全部完成后,启动扫描 + if(GlobalSize::BlueDevActiveSize() == 0) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { + BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); + connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + }); + } + } + + }); + } + }); + //如果有正在连接的音频设备,做完以上流程后,直接退出函数体 + //因为流程解决定了只有一个音频设备连接,而不需要判断后面是否有音频设备连接;提高代码执行效率 + return; + } + } + } + //当没有任何音频设备连接,最后再连接目标设备 + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + GlobalSize::refBlueDevActive(dev->address()); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + GlobalSize::unrefBlueDevActive(dev->address()); + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address(), + callReturn->error(), + callReturn->errorText()); + } + else + { + //主动连接成功后,发送连接成功信号 + addDelay(dev); + } + + //不存在主动连接 + if(GlobalSize::BlueDevActiveSize() == 0) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { + if(!Daemon::_DefualtAdapter.data()->isDiscovering()) + Daemon::_DefualtAdapter.data()->startDiscovery(); + } + } + + }); + } + //Dt-test phone只连接媒体音频 + else if(Environment::HUAWEI == envPC && dev.data()->type() == BluezQt::Device::Phone) + { + qDebug () << Q_FUNC_INFO << + dev.data()->name() << + dev.data()->address() << + dev.data()->type() << __LINE__; + //华为 + qDebug () << Q_FUNC_INFO << "Environment::HUAWEI"<< envPC; + //主动连接全部完成后,启动扫描 + if(GlobalSize::BlueDevActiveSize() == 0) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { + BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); + connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + }); + } + } + return; + +// if (Environment::HUAWEI == envPC) +// { +// //华为 +// qDebug () << Q_FUNC_INFO << "Environment::HUAWEI??"<< envPC; +// return; +// } + //背景:PC连接手机后,PC端播放音频无法从手机端输出 + //手机移动设备只连接媒体音频,可通过手机端发送音频至PC播放.将PC设备作为一个输出设备。 + //UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb) + //BluezQt::PendingCall *call = dev.data()->connectProfile("0000110a-0000-1000-8000-00805f9b34fb"); +// BluezQt::PendingCall *call = dev.data()->connectToDevice(); +// GlobalSize::refBlueDevActive(dev->address()); +// connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ +// qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; +// GlobalSize::unrefBlueDevActive(dev->address()); +// if (callReturn->error()) { +// emit devOperateErrorSignal(dev.data()->address(), +// callReturn->error(), +// callReturn->errorText()); +// } +// else +// { +// //主动连接成功后,发送连接成功信号 +// addDelay(dev); +// } + +// //不存在主动连接 +// if(GlobalSize::BlueDevActiveSize() == 0) +// { +// qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; +// if (::isScan) { +// if(!Daemon::_DefualtAdapter.data()->isDiscovering()) +// Daemon::_DefualtAdapter.data()->startDiscovery(); +// } +// } +// }); + } + else + { + + qDebug () << Q_FUNC_INFO << dev.data()->type() << __LINE__; + + BluezQt::PendingCall *call = dev.data()->connectToDevice(); + GlobalSize::refBlueDevActive(dev->address()); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + GlobalSize::unrefBlueDevActive(dev->address()); + if (callReturn->error()) { + emit devOperateErrorSignal(dev.data()->address(), + callReturn->error(), + callReturn->errorText()); + } + else + { + //主动连接成功后,发送连接成功信号 + addDelay(dev); + } + + if(GlobalSize::BlueDevActiveSize() == 0) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { + if (!Daemon::_DefualtAdapter.data()->isDiscovering()) + { + BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); + connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + }); + } + } + } + }); + } + } + + qDebug () << Q_FUNC_INFO << "END" << __LINE__; +} + +bool SessionDbusRegister::getBluetoothBlock() +{ + if (Daemon::_BluezManager) + return Daemon::_BluezManager->isBluetoothBlocked(); +} + +QString SessionDbusRegister::getDefaultAdapterAddress() +{ + if (!Daemon::_DefualtAdapter.isNull()) + return Daemon::_DefualtAdapter.data()->address(); + else + return ""; +} + +bool SessionDbusRegister::getDefaultAdapterPower() +{ + if (!Daemon::_DefualtAdapter.isNull()) + return Daemon::_DefualtAdapter.data()->isPowered(); + else + return false; +} + +void SessionDbusRegister::setDefaultAdapterPower(bool v) +{ + static_DefaultAdapterPower = v; + if (!Daemon::_DefualtAdapter.isNull()) { + //遇到长城机器在关闭蓝牙时不停止扫描动作,会造成下次开启后,扫描无法拉起的问题,增加关闭蓝牙时先停止蓝牙适配器扫描的动作 + if (!v && Daemon::_DefualtAdapter->isDiscovering()) + { + BluezQt::PendingCall * stop_call = Daemon::_DefualtAdapter.data()->stopDiscovery(); + connect(stop_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn) + { + qDebug() << Q_FUNC_INFO << "stopDiscovery:" << callReturn->error() << callReturn->errorText() << __LINE__; + qDebug() << Q_FUNC_INFO << "setDefaultAdapterPower" << v << __LINE__; + Daemon::_DefualtAdapter.data()->setPowered(v)->errorText(); + + }); + stop_call->waitForFinished(); + } + else + { + //关闭bt时先下电,在进行软阻塞 + qDebug() << Q_FUNC_INFO << "setDefaultAdapterPower" << v << __LINE__; + Daemon::_DefualtAdapter.data()->setPowered(v)->errorText(); + + //是否需要延时?? + QTimer::singleShot(100,this,[=]{ + if (Daemon::_BluezManager && Daemon::_BluezManager->isBluetoothBlocked()) + Daemon::_BluezManager->setBluetoothBlocked(false); + }); + + huawei_scan_interval_flag = true; + QTimer::singleShot(2500,this,[=]{ + huawei_scan_interval_flag = false; + qDebug() << Q_FUNC_INFO << huawei_scan_interval_flag << __LINE__; + }); + + } + } +} + +bool SessionDbusRegister::getDefaultAdapterScanStatus() +{ + if (!Daemon::_DefualtAdapter.isNull()) { + return Daemon::_DefualtAdapter.data()->isDiscovering(); + } + return false; +} + +bool SessionDbusRegister::getDefaultAdapterDiscoverable() +{ + if (!Daemon::_DefualtAdapter.isNull()) { + return Daemon::_DefualtAdapter.data()->isDiscoverable(); + } + return false; +} + +QString SessionDbusRegister::getAdapterNameByAddr(QString addr) +{ + qDebug() << Q_FUNC_INFO << addr << __LINE__; + if (addr.isEmpty() || addr.isNull() || !Daemon::_BluezManager) + { + qDebug() << Q_FUNC_INFO << "addr isEmpty or isNull / Daemon::_BluezManager isNull" << __LINE__; + return ""; + } + BluezQt::AdapterPtr adapter = Daemon::_BluezManager->adapterForAddress(addr); + if (adapter.isNull()) + { + qDebug() << Q_FUNC_INFO << "from Daemon::_BluezManager find this adapter!!!" << __LINE__; + return ""; + } + return adapter.data()->name(); +} + +void SessionDbusRegister::setDefaultAdapterScanOn(bool scanon) +{ + qDebug () << Q_FUNC_INFO << scanon << __LINE__; + if (!Daemon::_DefualtAdapter.isNull()) { +// BluezQt::PendingCall *call = nullptr; + ::isScan = scanon; + if (GlobalSize::BlueDevActiveSize() == 0) + { + if (scanon) + { + if (Environment::HUAWEI == envPC && huawei_scan_interval_flag) + { + if (scanOnTimer == nullptr) + { + scanOnCount = 0; + scanOnTimer = new QTimer(); + scanOnTimer->disconnect(); + connect(scanOnTimer,&QTimer::timeout,this,[=] + { + qDebug () << Q_FUNC_INFO << "scanOnCount:" << scanOnCount << __LINE__; + qDebug () << Q_FUNC_INFO << "!Daemon::_DefualtAdapter.isNull():" << !Daemon::_DefualtAdapter.isNull() << __LINE__; + if (!Daemon::_DefualtAdapter.isNull()) + qDebug () << Q_FUNC_INFO << "Daemon::_DefualtAdapter->isPowered():" << Daemon::_DefualtAdapter->isPowered() << __LINE__; + if (!Daemon::_DefualtAdapter.isNull() && Daemon::_DefualtAdapter->isPowered()) + { + if (scanOnCount%2 == 0) + { + if (Daemon::_DefualtAdapter.data()->isDiscovering()) + Daemon::_DefualtAdapter.data()->stopDiscovery(); + } + else + { + if (!Daemon::_DefualtAdapter.data()->isDiscovering()) + Daemon::_DefualtAdapter.data()->startDiscovery(); + } + scanOnCount++; + if (scanOnCount > 3) + { + if (!Daemon::_DefualtAdapter.data()->isDiscovering()) + Daemon::_DefualtAdapter.data()->startDiscovery(); + scanOnCount = 0; + scanOnTimer->stop(); + scanOnTimer->disconnect(); + scanOnTimer->deleteLater(); + scanOnTimer = nullptr; + qDebug () << Q_FUNC_INFO << ((scanOnTimer==nullptr)?"111":"222") << __LINE__; + + } + } + else + { + scanOnTimer->stop(); + scanOnTimer->disconnect(); + scanOnTimer->deleteLater(); + scanOnTimer = nullptr; + qDebug () << Q_FUNC_INFO << ((scanOnTimer==nullptr)?"333":"444") << __LINE__; + + } + }); + scanOnTimer->start(2000); + } + } + + if (!Daemon::_DefualtAdapter.data()->isDiscovering()) + Daemon::_DefualtAdapter.data()->startDiscovery(); + } + else + { + if (Daemon::_DefualtAdapter.data()->isDiscovering()) + Daemon::_DefualtAdapter.data()->stopDiscovery(); + } + } + } +} + +void SessionDbusRegister::setDefaultAdapter(QString addr) +{ + if (addr.isEmpty() || addr.isNull() || !Daemon::_BluezManager) + return; + + BluezQt::AdapterPtr adapter = Daemon::_BluezManager->adapterForAddress(addr); + if (!adapter.isNull()) { + Daemon::_DefualtAdapter->disconnect(); + Daemon::_DefualtAdapter = adapter; + this->connectSignal(); + emit this->defaultAdapterChanged(addr); + } +} + +void SessionDbusRegister::setDefaultAdapterDiscoverable(bool value) +{ + if (!Daemon::_DefualtAdapter.isNull()) { + qInfo() << Q_FUNC_INFO << Daemon::_DefualtAdapter.data()->discoverableTimeout(); + if (value) { + Daemon::_DefualtAdapter.data()->setDiscoverableTimeout(0); + } + + Daemon::_DefualtAdapter.data()->setDiscoverable(value); + Config::gsetting->set(GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH,QVariant(value)); + } +} + +void SessionDbusRegister::setBluetoothBlock(bool) +{ + +} + +void SessionDbusRegister::setDefaultAdapterName(QString bluetoothName) +{ + if (Daemon::_DefualtAdapter.isNull()) + return; + Daemon::_DefualtAdapter.data()->setName(bluetoothName); + +} + +void SessionDbusRegister::devPair(const QString addr) +{ + if (!isAvailableAddress(addr)) + return; + + BluezQt::DevicePtr devPtr = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!devPtr) + return; + + BluezQt::PendingCall *call = devPtr.data()->pair(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { + emit devOperateErrorSignal(devPtr.data()->address(), + callReturn->error(), + callReturn->errorText()); + } + }); +} + +void SessionDbusRegister::devConnect(const QString addr) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + if (!isAvailableAddress(addr)) + return; + + BluezQt::DevicePtr devPtr = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!devPtr) + return; + + + if (Daemon::_DefualtAdapter.data()->isDiscovering()) { + ::isScan = true; + BluezQt::PendingCall * stop_call = Daemon::_DefualtAdapter.data()->stopDiscovery(); + connect(stop_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn) + { + qDebug() << Q_FUNC_INFO << "stopDiscovery:" << callReturn->error() << callReturn->errorText() << __LINE__; + }); + stop_call->waitForFinished(); + } + + if (devPtr.data()->isPaired()) { + AudioDevConnectFunc(devPtr); + } else { + BluezQt::PendingCall *call = devPtr.data()->pair(); + //设置可信任设备后,适配器会相应来自设备的回连。当前验证鼠标和键盘是如此。 + devPtr.data()->setTrusted(true); + + GlobalSize::refBlueDevActive(devPtr->address()); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + GlobalSize::unrefBlueDevActive(devPtr->address()); + if (callReturn->error()) { + emit devOperateErrorSignal(devPtr.data()->address(), + callReturn->error(), + callReturn->errorText()); + //主动连接全部完成后,启动扫描 + if(GlobalSize::BlueDevActiveSize() == 0) + { + qDebug () << Q_FUNC_INFO << ::isScan << "===================startDiscovery====" << ::isScan << __LINE__; + if (::isScan) { + BluezQt::PendingCall * start_call = Daemon::_DefualtAdapter.data()->startDiscovery(); + connect(start_call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + qDebug () << Q_FUNC_INFO << callReturn->error() << " " << callReturn->errorText() << __LINE__; + }); + } + } + } else + AudioDevConnectFunc(devPtr); + }); + } +} + +void SessionDbusRegister::devDisconnect(const QString addr) +{ + if (!isAvailableAddress(addr)) + return; + + BluezQt::DevicePtr devPtr = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!devPtr) + return; + + BluezQt::PendingCall *call = devPtr.data()->disconnectFromDevice(); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { + emit devOperateErrorSignal(devPtr.data()->address(), + callReturn->error(), + callReturn->errorText()); + } + }); +} + +void SessionDbusRegister::devRemove(const QString addr) +{ + if (!isAvailableAddress(addr)) + return; + + BluezQt::DevicePtr devPtr = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!devPtr) + return; + + BluezQt::PendingCall *call = Daemon::_DefualtAdapter.data()->removeDevice(devPtr); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { + emit devOperateErrorSignal(devPtr.data()->address(), + callReturn->error(), + callReturn->errorText()); + } else { + Config::removeKey(addr); + } + }); +} + +void SessionDbusRegister::devTrust(const QString addr,const bool trust) +{ + if (!isAvailableAddress(addr)) + return; + + BluezQt::DevicePtr devPtr = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!devPtr) + return; + + BluezQt::PendingCall *call = devPtr.data()->setTrusted(trust); + connect(call,&BluezQt::PendingCall::finished,this,[=](BluezQt::PendingCall *callReturn){ + if (callReturn->error()) { + emit devOperateErrorSignal(devPtr.data()->address(), + callReturn->error(), + callReturn->errorText()); + } + }); +} + +bool SessionDbusRegister::getDevPairStatus(const QString addr) +{ + if (addr.isEmpty() || addr.isNull()) + return false; + + if (!Daemon::_DefualtAdapter.isNull()) { + BluezQt::DevicePtr dev = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!dev.isNull()) + return dev.data()->isPaired(); + else + return false; + } else { + return false; + } +} + +bool SessionDbusRegister::getDevConnectStatus(const QString addr) +{ + if (addr.isEmpty() || addr.isNull()) + return false; + + if (!Daemon::_DefualtAdapter.isNull()) { + BluezQt::DevicePtr dev = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!dev.isNull()) + return dev.data()->isConnected(); + else + return false; + } else { + return false; + } +} + +QString SessionDbusRegister::getDevType(const QString addr) +{ + if (addr.isEmpty() || addr.isNull()) + return ""; + + if (!Daemon::_DefualtAdapter.isNull()) { + BluezQt::DevicePtr dev = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!dev.isNull()) + { + if (Environment::HUAWEI == envPC && dev.data()->type() == BluezQt::Device::AudioVideo) + return BluezQt::Device::typeToString(BluezQt::Device::Headphones); + else + return BluezQt::Device::typeToString(dev.data()->type()); + } + else + return ""; + } else { + return ""; + } +} + +void SessionDbusRegister::clearAllUnPairedDevicelist() +{ + if (!Daemon::_DefualtAdapter.isNull()) { + for (auto dev : Daemon::_DefualtAdapter.data()->devices()) { + if (!dev.data()->isPaired()) { + Daemon::_DefualtAdapter.data()->removeDevice(dev); + } + } + } +} + +qint64 SessionDbusRegister::getDevBattery(const QString addr) +{ + if (addr.isEmpty() || addr.isNull()) + return -1; + +#ifdef BATTERY + if (!Daemon::_DefualtAdapter.isNull()) { + BluezQt::DevicePtr dev = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!dev.isNull()) { + if (dev.data()->battery().isNull()) + return -1; + return dev.data()->battery().data()->percentage(); + } + } +#endif + return -1; +} + +QString SessionDbusRegister::getDevName(const QString addr) +{ + qDebug() << Q_FUNC_INFO << "Get device name address:" << addr<< __LINE__; + if (addr.isEmpty() || addr.isNull() || Daemon::_DefualtAdapter.isNull()) + { + qDebug() << Q_FUNC_INFO << "addr isEmpty or isNull / _DefualtAdapter isNull" << __LINE__; + return ""; + } + BluezQt::DevicePtr devpter = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (devpter.isNull()) + { + qDebug() << Q_FUNC_INFO << "devpter isNull" << __LINE__; + + return ""; + } + return devpter.data()->name(); +} + +QStringList SessionDbusRegister::getDefaultAdapterPairedDevAddress() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + QStringList pairDev; + pairDev.clear(); + if (!Daemon::_DefualtAdapter.isNull()) { + for (auto item : Daemon::_DefualtAdapter.data()->devices()) { + if(item.data()->isPaired()) { + pairDev.append(item.data()->address()); + } + } + } + return pairDev; +} + +QStringList SessionDbusRegister::getDefaultAdapterTrustedDevAddress() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + QStringList TrusteDev; + TrusteDev.clear(); + if (!Daemon::_DefualtAdapter.isNull()) { + for (auto item : Daemon::_DefualtAdapter.data()->devices()) { + if(item.data()->isTrusted()) { + TrusteDev.append(item.data()->address()); + } + } + } + return TrusteDev; +} + +QStringList SessionDbusRegister::getDefaultAdapterCacheDevAddress() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + QStringList CacheDevList; + CacheDevList.clear(); + if (!Daemon::_DefualtAdapter.isNull()) { + for (auto item : Daemon::_DefualtAdapter.data()->devices()) { + CacheDevList.append(item.data()->address()); + } + } + return CacheDevList; +} + +QStringList SessionDbusRegister::getAdapterDevAddressList() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + QStringList AdapterList; + AdapterList.clear(); + if (Daemon::_BluezManager) { + for (auto item : Daemon::_BluezManager->adapters()) { + AdapterList.append(item.data()->address()); + } + } + return AdapterList; +} + +void SessionDbusRegister::sendFiles(QString addr,QString filename) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + if (filename.isEmpty() || filename.isNull()) + return; + + emit sendFile(addr,filename); +} + +void SessionDbusRegister::exit() +{ + qApp->exit(0); +} + +void SessionDbusRegister::sendNotifyMessage(QString message) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + if (message.isEmpty() || message.isNull()) + return; + + Config::SendNotifyMessage(message); +} + +void SessionDbusRegister::openBluetoothSettings() +{ + Config::OpenBluetoothSettings(); +} + +void SessionDbusRegister::connectSignal() +{ + qDebug() << Q_FUNC_INFO ; + if (nullptr == Daemon::_BluezManager) + { + qDebug() << Q_FUNC_INFO << "btManaher is null!" ; + return; + } + + if (nullptr == Daemon::_DefualtAdapter) + { + qDebug() << Q_FUNC_INFO << "_DefualtAdapter is null!" ; + return; + } + + Daemon::_BluezManager->disconnect(this); + Daemon::_DefualtAdapter->disconnect(); + + TmpDevClear* test = TmpDevClear::getInstant(); + test->init(); + + if(global_activeconn_switch) + { + this->setDefaultAdapterScanOn(true); + } + + connect(Daemon::_BluezManager,&BluezQt::Manager::adapterAdded,this,[=](BluezQt::AdapterPtr adapter){ + qDebug() << Q_FUNC_INFO << "adapterAdded" << adapter->address() << adapter->isPowered()<< __LINE__; + emit adapterAddSignal(adapter.data()->address()); + + //修改 + //为默认适配器赋值,daemon未提供接口 + //使用临时方案,只存在一个蓝牙适配器,则直接赋值 + //如存在多个蓝牙适配器情况下,需要进行修改 + //从无到有,以第一个适配器作为默认适配器 + if(Daemon::_BluezManager->adapters().size() == 1) + { + Daemon::_DefualtAdapter = adapter; + //移除设备后,信号消失,需要重新绑定信号 + this->connectSignal(); +// if(-1 != static_bluezreboot_power) +// { +// qDebug() << Q_FUNC_INFO << "setPowered" << bool(static_bluezreboot_power); +// qDebug() << Q_FUNC_INFO << "name" << Daemon::_DefualtAdapter->name() << __LINE__; +// Daemon::_DefualtAdapter->setPowered(bool(static_bluezreboot_power)); +// static_bluezreboot_power = -1; +// } + + } + else + { + //不做任何处理 + } + + + adapterRemoveFlag = false; + + Config::ukccGsetting->set("show",QVariant(true)); + + },Qt::UniqueConnection); + + connect(Daemon::_BluezManager,&BluezQt::Manager::adapterRemoved,this,[=](BluezQt::AdapterPtr adapter){ + qDebug() << Q_FUNC_INFO << "adapterRemoved" << __LINE__; + emit adapterRemoveSignal(adapter.data()->address()); + + adapterRemoveFlag = true; + qDebug() << Q_FUNC_INFO << "systemSleepFlag::"<< ::systemSleepFlag << __LINE__; + if (!::systemSleepFlag && !Daemon::_BluezManager->adapters().size()) + Config::ukccGsetting->trySet("show",QVariant(false)); + + },Qt::UniqueConnection); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::adapterRemoved,this,[=](BluezQt::AdapterPtr adapter){ + qDebug() << Q_FUNC_INFO << "adapterRemoved" << __LINE__; + emit adapterRemoveSignal(adapter.data()->address()); + + adapterRemoveFlag = true; + + qDebug() << Q_FUNC_INFO << "systemSleepFlag::"<<::systemSleepFlag << __LINE__; + if (!::systemSleepFlag && !Daemon::_BluezManager->adapters().size()) + Config::ukccGsetting->set("show",QVariant(false)); + + + //bluez重启,可能出现蓝牙从开启变成关闭 + qint64 tmp = QDateTime::currentMSecsSinceEpoch() - ::powerChangeTime; + if(tmp <= 1000){ + qDebug() << Q_FUNC_INFO << "time <= 1000" << __LINE__; + static_bluezreboot_power = 1; + } + else{ + if(adapter->isPowered()){ + qDebug() << Q_FUNC_INFO << "adapter->isPowered() true" << __LINE__; + static_bluezreboot_power = 1; + } + else{ + qDebug() << Q_FUNC_INFO << "adapter->isPowered() false" << __LINE__; + static_bluezreboot_power = 0; + } + + } + qDebug() << Q_FUNC_INFO << "static_bluezreboot_power" << static_bluezreboot_power << __LINE__; + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::nameChanged,this,[=](const QString &name) + { + qDebug() << Q_FUNC_INFO << "nameChanged" << name << __LINE__; + emit defaultAdapterNameChanged(name); + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::deviceRemoved,this,[=](BluezQt::DevicePtr devPtr){ + qDebug() << Q_FUNC_INFO << "deviceRemoved" << devPtr->address() << devPtr->type() <<__LINE__; + emit devRemoveSignal(devPtr.data()->address()); + + if (devPtr.data()->isPaired() && !::systemSleepFlag) + Config::removeKey(devPtr.data()->address()); + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::poweredChanged,this,[=](bool powered){ + qDebug() << Q_FUNC_INFO << "poweredChanged" << powered <<__LINE__; + + ::powerChangeTime = QDateTime::currentMSecsSinceEpoch(); + + if (powered) + Daemon::reconnectFunc(); + + if (::resetFlag || ::sleepFlag || !::static_bluezreboot_power) { + QTimer::singleShot(100,this,[=]{ + if( !static_DefaultAdapterPower) + { + Daemon::_DefualtAdapter.data()->setPowered(false); + qDebug() << Q_FUNC_INFO << __LINE__; + } + }); + qDebug() << Q_FUNC_INFO << __LINE__<< " resetFlag:"<<::resetFlag << " sleepFlag:"<<::sleepFlag + << " static_bluezreboot_power:" <set(GSETTING_STR_BLUETOOTH_POWER_SWTICH,QVariant(powered)); + + emit defaultAdapterPowerChanged(powered); + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoveringChanged,this,[=](bool status){ + qDebug() << Q_FUNC_INFO << "discoveringChanged" << status << __LINE__; + emit defaultScanStatusChanged(status); + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::discoverableChanged,this,[=](bool discoverable){ + qDebug() << Q_FUNC_INFO << "discoverableChanged" << discoverable << __LINE__; + + //这里是否需要增加intel机型判断,intel默认可被发状态为开启 + Config::gsetting->set(GSETTING_STR_BLUETOOTH_DISCOVERABLE_SWTICH,QVariant(discoverable)); + + emit defaultDiscoverableChanged(discoverable); + }); + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::deviceAdded,this,[=](BluezQt::DevicePtr devPtr){ + //qInfo() << Q_FUNC_INFO << "deviceAdded:" << devPtr->address() << devPtr->rssi() << ";line = "<< __LINE__ ; + + + + //设备类型正常,才发送信号 + if(devPtr->type() != BluezQt::Device::Type::Uncategorized) + { + if (!deviceMacAddressChanged(devPtr)) + { + if (Environment::HUAWEI == envPC && devPtr->type() == BluezQt::Device::AudioVideo) + emit deviceScanResult(devPtr.data()->address(), + devPtr.data()->name(), + BluezQt::Device::typeToString(BluezQt::Device::Headphones), + devPtr.data()->uuids().contains("00001105-0000-1000-8000-00805f9b34fb",Qt::CaseInsensitive) + ); + else + emit deviceScanResult(devPtr.data()->address(), + devPtr.data()->name(), + BluezQt::Device::typeToString(devPtr.data()->type()), + (devPtr.data()->type() == BluezQt::Device::Computer ? + true : + devPtr.data()->uuids().contains("00001105-0000-1000-8000-00805f9b34fb",Qt::CaseInsensitive)) + ); + } + //添加mac前3位和名称一致的判断,过滤掉扫描列表中mac地址会变化的设备 + //clearDeviceScanList(devPtr); + + //主动连接 + this->deal_active_connection(devPtr); + } + + + //清空信号,防止重复连接 + devPtr->disconnect(); + + connect(devPtr.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << devPtr.data()->address() << + v << devPtr.data()->isPaired() << devPtr->isConnected()<< devPtr.data()->type(); + + //增加设备连接成功后在1秒内有连接失败的流程中,增加再次连接的操作 + if (devPtr.data()->isPaired()) + { + deviceConnectAgain(devPtr,v); + } + //发送信号 + //主动连接,不发送信号 + //非主动连接情况下 + if(!GlobalSize::IsBlueDevActive(devPtr->address())) + { + //条件: 蓝牙适配器:配对、连接, 且蓝牙设备主动连接 + if(devPtr->isPaired() && v) + { + addDelay(devPtr); + } + //未配对,且为连接状态, 不发送 + else if(!devPtr->isPaired() && v) + { + ; + } + else + { + if(existDelay(devPtr->address())) + { + qDebug() << Q_FUNC_INFO << __LINE__ << "existDelay " << devPtr->address(); + } + else + { + qDebug() << Q_FUNC_INFO<< __LINE__ << "emit " << devPtr->address() << v; + emit devConnectStatusSignal(devPtr->address(),v); + + if (v && devPtr->isPaired()) { + Config::writeKeyFile(devPtr->address(),devPtr->name(),devPtr->type()); + } + } + } + } + }); + + connect(devPtr.data(),&BluezQt::Device::rssiChanged,this,[=](qint16 v){ + this->deal_active_connection(devPtr); + + }); + + connect(devPtr.data(),&BluezQt::Device::pairedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "pairedChanged" << devPtr.data()->address() << v; + emit devPairSignal(devPtr.data()->address(),v); + + //匹配成功 且 非主动连接情况下 且 蓝牙设备状态 连接 + if(v && !GlobalSize::IsBlueDevActive(devPtr->address()) && devPtr->isConnected()) + { + addDelay(devPtr); + } + }); + + connect(devPtr.data(),&BluezQt::Device::typeChanged,this,[=](BluezQt::Device::Type type){ + qDebug() << Q_FUNC_INFO << "typeChanged" << devPtr.data()->address(); + + //设备类型正常,才发送信号 + if(devPtr->type() != BluezQt::Device::Type::Uncategorized) + { + if (Environment::HUAWEI == envPC && devPtr->type() == BluezQt::Device::AudioVideo) + emit deviceScanResult(devPtr.data()->address(), + devPtr.data()->name(), + BluezQt::Device::typeToString(BluezQt::Device::Headphones), + devPtr.data()->uuids().contains("00001105-0000-1000-8000-00805f9b34fb",Qt::CaseInsensitive) + ); + else + emit deviceScanResult(devPtr.data()->address(), + devPtr.data()->name(), + BluezQt::Device::typeToString(devPtr.data()->type()), + (devPtr.data()->type() == BluezQt::Device::Computer ? + true : + devPtr.data()->uuids().contains("00001105-0000-1000-8000-00805f9b34fb",Qt::CaseInsensitive)) + ); + + QTimer::singleShot(500, this, [=] + { + emit devTypeChangedSignal(devPtr->address(),BluezQt::Device::typeToString(devPtr->type())); + }); + } + //无蓝牙设备类型,删除设备 + else + { + emit devRemoveSignal(devPtr->address()); + } + + }); + + connect(devPtr.data(),&BluezQt::Device::nameChanged,this,[=](const QString &name){ + qDebug() << Q_FUNC_INFO << "nameChanged" << devPtr.data()->address(); + emit devNameChangedSignal(devPtr.data()->address(),name); + }); + +#ifdef BATTERY + connect(devPtr.data(),&BluezQt::Device::batteryChanged,this,[=](BluezQt::BatteryPtr battery){ + if(nullptr != battery){ + qDebug() << Q_FUNC_INFO << "batteryChanged" << battery.data()->percentage(); + emit devBatteryChangedSignal(devPtr.data()->address(), QString::number(battery.data()->percentage())); + } + else{ + qDebug() << Q_FUNC_INFO << "batteryChanged null " << devPtr.data()->address(); + } + + }); +#endif + }); + + foreach (auto dev, Daemon::_DefualtAdapter.data()->devices()) { + //清空信号,防止重复连接 + dev->disconnect(); + + connect(dev.data(),&BluezQt::Device::connectedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "connectedChanged" << dev.data()->address() << + v << dev.data()->isPaired() << dev->isConnected() << dev->type(); + + //增加设备连接成功后在1秒内有连接失败的流程中,增加再次连接的操作 + if (dev.data()->isPaired()) + { + deviceConnectAgain(dev,v); + } + //主动连接,在连接完成发送连接信号 + //非主动连接情况下,发送信号 + if(!GlobalSize::IsBlueDevActive(dev->address())) + { + //已匹配设备,且改变为连接状态,延时发送,暂时定义2s + if(dev->isPaired() && v) + { + addDelay(dev); + } + //未匹配,且为连接状态, 不发送 + else if(!dev->isPaired() && v) + { + ; + } + else + { + if(existDelay(dev->address())) + { + qDebug() << Q_FUNC_INFO << __LINE__ << "existDelay " << dev->address(); + } + else + { + qDebug() << Q_FUNC_INFO<< __LINE__ << "emit " << dev->address() << v; + emit devConnectStatusSignal(dev.data()->address(),v); + + if (v && dev.data()->isPaired()) { + Config::writeKeyFile(dev.data()->address(),dev.data()->name(),dev.data()->type()); + } + } + } + } + }); + + connect(dev.data(),&BluezQt::Device::pairedChanged,this,[=](bool v){ + qDebug() << Q_FUNC_INFO << "pairedChanged" << dev.data()->address(); + emit devPairSignal(dev.data()->address(),v); + + //匹配成功 且 非主动连接情况下 且 蓝牙设备状态 连接 + if(v && !GlobalSize::IsBlueDevActive(dev->address()) && dev->isConnected()) + { + addDelay(dev); + } + }); + + connect(dev.data(),&BluezQt::Device::rssiChanged,this,[=](qint16 v){ + //无需任何处理 + }); + + connect(dev.data(),&BluezQt::Device::typeChanged,this,[=](BluezQt::Device::Type type){ + qDebug() << Q_FUNC_INFO << "typeChanged" << dev.data()->address(); + //设备类型正常,才发送信号 + if(dev->type() != BluezQt::Device::Type::Uncategorized) + { + if (Environment::HUAWEI == envPC && dev->type() == BluezQt::Device::AudioVideo) + emit deviceScanResult(dev.data()->address(), + dev.data()->name(), + BluezQt::Device::typeToString(BluezQt::Device::Headphones), + dev.data()->uuids().contains("00001105-0000-1000-8000-00805f9b34fb",Qt::CaseInsensitive) + ); + else + emit deviceScanResult(dev.data()->address(), + dev.data()->name(), + BluezQt::Device::typeToString(dev.data()->type()), + (dev.data()->type() == BluezQt::Device::Computer ? + true : + dev.data()->uuids().contains("00001105-0000-1000-8000-00805f9b34fb",Qt::CaseInsensitive)) + ); + + QTimer::singleShot(500, this, [=] + { + emit devTypeChangedSignal(dev->address(),BluezQt::Device::typeToString(dev->type())); + }); + + } + //无蓝牙设备类型,删除设备 + else + { + emit devRemoveSignal(dev->address()); + } + }); + + connect(dev.data(),&BluezQt::Device::nameChanged,this,[=](const QString &name){ + qDebug() << Q_FUNC_INFO << "nameChanged" << dev.data()->address(); + emit devNameChangedSignal(dev.data()->address(),name); + }); +#ifdef BATTERY + connect(dev.data(),&BluezQt::Device::batteryChanged,this,[=](BluezQt::BatteryPtr battery){ + if(nullptr != battery){ + qDebug() << Q_FUNC_INFO << "batteryChanged" << battery.data()->percentage(); + emit devBatteryChangedSignal(dev.data()->address(), QString::number(battery.data()->percentage())); + } + else{ + qDebug() << Q_FUNC_INFO << "batteryChanged null " << dev.data()->address(); + } + }); +#endif + } +} + + +void SessionDbusRegister::deal_active_connection(BluezQt::DevicePtr devPtr) +{ + if(global_activeconn_switch && nullptr != devPtr) + { + int v = devPtr->rssi(); + //qInfo() << devPtr->address() << devPtr->type() << v; + if(devPtr->type() != BluezQt::Device::Type::Headphones && devPtr->type() != BluezQt::Device::Type::Headset + && devPtr->type() != BluezQt::Device::Type::AudioVideo) + { + qDebug() << Q_FUNC_INFO << devPtr->address() << devPtr->type(); + return; + } + if( static_black_activeconn_dev.find(devPtr->address()) != static_black_activeconn_dev.end()) + { + qInfo() << "black list in" << devPtr->address() << " rssi: " << devPtr->rssi(); + return; + } + + if( devPtr->isPaired()) + return; + if(!global_active_connection_dev.isEmpty()) + return; + + int timeout = 15; + + //耳机且未配对设备,且未处于发起主动连接过程中,进行主动连接流程 + //信号强 0dBm ~ -50dBm + //信号中 -50dBm ~ -70dBm + if(abs(v) <= 60) + { + global_active_connection_dev = devPtr->address(); + emit ActiveConnection(devPtr->address(), devPtr->name(), + BluezQt::Device::typeToString(devPtr->type()), v, timeout); + + if(nullptr == static_active_timer) + { + static_active_timer = new QTimer(this); + } + else + { + static_active_timer->disconnect(); + } + connect(static_active_timer, &QTimer::timeout, this, [=](void) + { + global_active_connection_dev = ""; + qInfo() << Q_FUNC_INFO << "active connection timeout"; + static_active_timer->stop(); + }); + static_active_timer->start(timeout * 1000); + + qInfo() << Q_FUNC_INFO << "start active conection" << devPtr->address() + <<" rssi: "<< devPtr->rssi() << " timeout:" << timeout + <<" type: " << BluezQt::Device::typeToString(devPtr->type()) + <<" name: " << devPtr->name(); + } + else + { + qInfo() << Q_FUNC_INFO << "not start active conection" << devPtr->address() + << " rssi: "<< devPtr->rssi() << " timeout:" << timeout + <<" type: "<< BluezQt::Device::typeToString(devPtr->type()) + <<" name: " << devPtr->name(); + } + + } +} + +void SessionDbusRegister::activeConnectionReply(QString dev, bool v) +{ + qInfo() << Q_FUNC_INFO << dev << v; + if(nullptr != static_active_timer) + { + static_active_timer->stop(); + } + if(dev == global_active_connection_dev) + { + if(v) + { + devConnect(dev); + } + else + { + static_black_activeconn_dev.insert(global_active_connection_dev); + } + global_active_connection_dev = ""; + } + else + { + global_active_connection_dev = ""; + } +} + + +//针对已配对的音频设备,发起连后设备立马断开的设备再发起一次连接操作 +void SessionDbusRegister::deviceConnectAgain(BluezQt::DevicePtr devPtr, bool connectChangedValue) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + if (devPtr.isNull()) + { + qDebug () << Q_FUNC_INFO << "device is nullptr!!!" << __LINE__; + return; + } + + //只针对音频设备进行再次连接 + if (BluezQt::Device::AudioVideo == devPtr.data()->type() || + BluezQt::Device::Headset == devPtr.data()->type() || + BluezQt::Device::Headphones == devPtr.data()->type() + ) + { + if(connectChangedValue) + { + if(devConnectAgainMap.contains(devPtr->address())) + { + devConnectAgainMap[devPtr->address()] = QDateTime::currentMSecsSinceEpoch(); + } + else + { + devConnectAgainMap.insert(devPtr->address(),QDateTime::currentMSecsSinceEpoch()); + } + } + else + { + if (devConnectAgainMap.contains(devPtr->address())) + { + qint64 timeDiff = QDateTime::currentMSecsSinceEpoch() - devConnectAgainMap.value(devPtr->address()); + if (timeDiff < 1000)//时间差在1s以内则再次发发起连接 + { + //非主动连接情况下,发起主动连接前,上报状态,预防重连失败后,控制面板/托盘还处于连接状态 + if(!GlobalSize::IsBlueDevActive(devPtr->address())) + { + addDelay(devPtr); + } + + AudioDevConnectFunc(devPtr); + //devConnect(devPtr->address()); + } + devConnectAgainMap.remove(devPtr->address()); + } + } + } + +} + +bool SessionDbusRegister::deviceMacAddressContrast(QString newMacAddress , QString oldMacAddress,int compareLength) +{ + //判断mac前三位是否一致 + QString newStr = newMacAddress.left(compareLength); + QString oldStr = oldMacAddress.left(compareLength); + if (newStr == oldStr) + return true; + else + return false; +} + +bool SessionDbusRegister::deviceMacAddressChanged(BluezQt::DevicePtr devPtr) +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + //华为机型不做该功能处理 + if(Environment::HUAWEI == envPC) + return false; + + if (devPtr.isNull()) + { + qDebug() << Q_FUNC_INFO << "devPtr isNull !!!" << __LINE__; + return false; + } + + foreach (auto dev, Daemon::_DefualtAdapter.data()->devices()) + { + //现象部分设备在多次开启配对后,会产生设备名称相同但mac地址接近的另一个外的设备 + //已配对的设置中, + if( nullptr != dev && + dev.data()->isPaired() && + !dev.data()->isConnected() && + (devPtr.data()->name() == dev.data()->name()) && + (devPtr.data()->address() != dev.data()->address()) && + deviceMacAddressContrast(devPtr.data()->address(),dev.data()->address(),15) + ) + { + qDebug() << Q_FUNC_INFO << devPtr.data()->name() << devPtr.data()->name() ; + qDebug() << Q_FUNC_INFO << dev.data()->name() << dev.data()->name() ; + + emit devMacAddressChangedSignal(dev.data()->address(),devPtr.data()->address()); + + QTimer::singleShot(3000,this,[=]{ + Daemon::_DefualtAdapter.data()->removeDevice(dev); + qDebug() << Q_FUNC_INFO << __LINE__; + }); + return true; + } + } + return false; +} + +void SessionDbusRegister::clearDeviceScanList(BluezQt::DevicePtr devPtr) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + if (devPtr.isNull()) + { + return; + } + + foreach (auto dev, Daemon::_DefualtAdapter.data()->devices()) + { + if( nullptr != dev && + !dev.data()->isPaired() && + !dev.data()->isConnected() && + (devPtr.data()->name() == dev.data()->name()) && + (devPtr.data()->address() != dev.data()->address()) && + deviceMacAddressContrast(devPtr.data()->address(),dev.data()->address(),8) + ) + { + qDebug() << Q_FUNC_INFO << devPtr.data()->name() << devPtr.data()->name() ; + qDebug() << Q_FUNC_INFO << dev.data()->name() << dev.data()->name() ; + //删除老的设备 + Daemon::_DefualtAdapter.data()->removeDevice(dev); + break; + } + } +} + +void SessionDbusRegister::sendReplyFileReceivingSignal(bool v) +{ + qDebug() << "SessionDbusRegister::sendReplyFileReceivingSignal"; + emit replyFileReceivingSignal(v); +} + +void SessionDbusRegister::sendCloseSession() +{ + qDebug() << "SessionDbusRegister::sendCloseSession"; + emit closeSessionSignal(); +} + + +void SessionDbusRegister::sendReplyRequestConfirmation(bool v) +{ + qDebug() << "SessionDbusRegister::sendReplyRequestConfirmation"; + emit replyRequestConfirmation(v); +} + +void SessionDbusRegister::setSendTransferFileMesg(QStringList files) +{ + qDebug() << "SessionDbusRegister::setSendTransferFileMesg"; + emit sendTransferFilesMesg(files); +} + +void SessionDbusRegister::setSendTransferDeviceMesg(QString address) +{ + qDebug() << "SessionDbusRegister::setSendTransferDeviceMesg"; + emit sendTransferDeviceMesg(address); +} + +void SessionDbusRegister::setclearOldSession() { + qDebug() << "SessionDbusRegister::clearOldSession"; + emit clearOldSession(); +} + +void SessionDbusRegister::continueSendFiles(QString filename) { + emit continueSendFilesSignal(filename); +} + +void SessionDbusRegister::cancelFileReceiving() { + qDebug() << "SessionDbusRegister::cancelFileReceiving"; + emit cancelFileReceivingSignal(); +} + +void SessionDbusRegister::showTrayWidgetUI() { + qDebug() << "SessionDbusRegister::showTrayWidgetUI"; + emit showTrayWidgetUISignal(); +} + +bool SessionDbusRegister::getDevSupportFileSend(const QString addr) +{ + if (addr.isEmpty() || addr.isNull()) + return false; + + if (!Daemon::_DefualtAdapter.isNull()) { + BluezQt::DevicePtr dev = Daemon::_DefualtAdapter.data()->deviceForAddress(addr); + if (!dev.isNull()) + { + if (BluezQt::Device::Phone != dev.data()->type() && BluezQt::Device::Computer != dev.data()->type()) + return false; + if (BluezQt::Device::Computer == dev.data()->type()) + return true; + return dev.data()->uuids().contains("00001105-0000-1000-8000-00805f9b34fb",Qt::CaseInsensitive); + } + } + return false; +} + +//服务记录当前文件传输状态 +void SessionDbusRegister::dealStatusChanged(QString status, QString dev, QString path) { + qDebug() << Q_FUNC_INFO << dev << sessionList < temp = sessionList.value(dev); + temp.remove(path); + temp.insert(path, status); + sessionList.remove(dev); + sessionList.insert(dev, temp); + return; + } + if (status == "Error" || status == "Complete") { + QMap temp = sessionList.value(dev); + temp.remove(path); + sessionList.remove(dev); + if (temp.size() != 0) + sessionList.insert(dev,temp); + return; + } + QMap temp = sessionList.value(dev); + temp.remove(path); + temp.insert(path,status); + sessionList.remove(dev); + sessionList.insert(dev, temp); + return; + } + if (status == "Error") + return; + QMap temp; + temp.insert(path, status); + sessionList.insert(dev, temp); + qDebug() << Q_FUNC_INFO << __LINE__ << sessionList; +} + +//服务返回记录的文件传输状态 +bool SessionDbusRegister::getTransferDevAndStatus(QString dev) { + qDebug() << Q_FUNC_INFO << sessionList << sessionList.keys().contains(dev); + //特殊判断间隙操作Queued + if (tmpDevCord != QString("")) + return tmpDevCord == dev; + if (sessionList.size() == 0) + return true; + return sessionList.keys().contains(dev); +} diff --git a/service/sessiondbusregister.h b/service/sessiondbusregister.h new file mode 100644 index 0000000..2a797b6 --- /dev/null +++ b/service/sessiondbusregister.h @@ -0,0 +1,254 @@ +#ifndef SESSIONDBUSREGISTER_H +#define SESSIONDBUSREGISTER_H + +#include "daemon.h" +#include "config.h" + + +#include +#include +#include +#include + +#ifdef BATTERY +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +class DelayStruct : public QObject +{ + Q_OBJECT + +public: + DelayStruct(BluezQt::DevicePtr dev, QObject *parent = nullptr); + ~DelayStruct(); + + void close(void); //关闭并销毁函数 + +protected: + + virtual void timerEvent( QTimerEvent *event); + +private: + int m_TimerID = 0; + BluezQt::DevicePtr m_dev = nullptr; +}; + + +class SessionDbusRegister : public QObject, protected QDBusContext +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "com.ukui.bluetooth") +public: + explicit SessionDbusRegister(QObject *parent = nullptr); + ~SessionDbusRegister(); + +private: + QMap> sessionList; + + int scanOnCount = 0; + QTimer * scanOnTimer = nullptr; + bool huawei_scan_interval_flag = false; + QString tmpDevCord = QString(""); + + bool InterfaceAlreadyExists(); + + void AudioDevConnectFunc(BluezQt::DevicePtr); + + void clearDeviceScanList(BluezQt::DevicePtr); + + bool deviceMacAddressContrast(QString,QString,int); + + bool deviceMacAddressChanged(BluezQt::DevicePtr); + + void deviceConnectAgain(BluezQt::DevicePtr,bool); + + void deal_active_connection(BluezQt::DevicePtr); +private slots: + + void dealStatusChanged(QString status, QString dev, QString path); + +public slots: + // 蓝牙默认适配器信息处理dbus + bool getBluetoothBlock(); + + QString getDefaultAdapterAddress(); + + bool getDefaultAdapterPower(); + + bool getDefaultAdapterScanStatus(); + + bool getDefaultAdapterDiscoverable(); + + QString getAdapterNameByAddr(QString); + + QStringList getDefaultAdapterPairedDevAddress(); + + QStringList getDefaultAdapterTrustedDevAddress(); + + QStringList getDefaultAdapterCacheDevAddress(); + + QStringList getAdapterDevAddressList(); + + void setDefaultAdapterPower(bool); + + void setDefaultAdapterScanOn(bool); + + void setDefaultAdapter(QString); + + void setDefaultAdapterDiscoverable(bool); + + void setBluetoothBlock(bool); + + void setDefaultAdapterName(QString); + + //蓝牙设备处理dbus + void devPair(const QString); + + void devConnect(const QString); + + void devDisconnect(const QString); + + void devRemove(const QString); + + void devTrust(const QString,const bool); + + bool getDevPairStatus(const QString); + + bool getDevConnectStatus(const QString); + + QString getDevName(const QString); + + QString getDevType(const QString); + + void clearAllUnPairedDevicelist(); + + void setSendTransferDeviceMesg(QString); + + void setSendTransferFileMesg(QStringList files); + + void setclearOldSession(); + + void continueSendFiles(QString filename); + + void cancelFileReceiving(); + +//#ifdef BATTERY + qint64 getDevBattery(const QString); +//#endif + //设备是否支持文件发送 + bool getDevSupportFileSend(const QString); + //文件传输dbus + void sendFiles(QString,QString);//test + + void exit(); + + //其他dbus + void sendNotifyMessage(QString); + + void openBluetoothSettings(); + + void connectSignal(); + + void showTrayWidgetUI(); + + bool getTransferDevAndStatus(QString dev); + + //test + void sendReplyRequestConfirmation(bool); + void sendReplyFileReceivingSignal(bool v); + void sendCloseSession(); + + //主动连接请求, v: 接受/拒绝 + void activeConnectionReply(QString dev, bool v); + +signals: + //适配器相关信号 + void defaultAdapterPowerChanged(bool); + + void defaultAdapterChanged(QString); + + void defaultScanStatusChanged(bool); + + void defaultDiscoverableChanged(bool); + + void adapterAddSignal(QString); + + void adapterRemoveSignal(QString); + + void defaultAdapterNameChanged(QString); + + //设备相关信号 + void deviceScanResult(QString,QString,QString,bool); + + void devPairSignal(QString,bool); + + void devTypeChangedSignal(QString,QString); + + void devBatteryChangedSignal(QString, QString); + + void devNameChangedSignal(QString,QString); + + void devConnectStatusSignal(QString,bool); + + void devRemoveSignal(QString); + + void devOperateErrorSignal(QString,int,QString); + + void devMacAddressChangedSignal(QString,QString); + //代理相关信号 + void sendFile(QString,QString); + + void continueSendFilesSignal(QString); + + void displayPasskey(QString,QString); + +// void replyDisplayPasskey(bool); + + void requestConfirmation(QString,QString); + + void replyRequestConfirmation(bool); + + void transferredChanged(quint64,QString); + + void statusChanged(QString,QString,QString); + + void fileReceivingSignal(QString,QString,QString,QString,quint64); + + void replyFileReceivingSignal(bool); + + void closeSessionSignal(); + + void pairAgentCanceled(); + + void obexAgentCanceled(); + + void propertyChanged(quint64); + + void sendTransferDeviceMesg(QString); + + void sendTransferFilesMesg(QStringList); + + void clearOldSession(); + + void cancelFileReceivingSignal(); + + void showTrayWidgetUISignal(); + + void initTransferPath(QString); + + //id, name , type, rssi, timeout + void ActiveConnection(QString, QString, QString, int, int); +}; + +#endif // SESSIONDBUSREGISTER_H diff --git a/service/tmpdevclear.cpp b/service/tmpdevclear.cpp new file mode 100644 index 0000000..d355f14 --- /dev/null +++ b/service/tmpdevclear.cpp @@ -0,0 +1,104 @@ +#include "tmpdevclear.h" +#include "daemon.h" + +#include +#include +#include +#include +#include +#include +#include + +extern QString global_active_connection_dev; + +//间隔清理不可见设备时间 +const qint64 interval = 12*1000; + +TmpDevClear* TmpDevClear::_instant = nullptr; + +TmpDevClear *TmpDevClear::getInstant() +{ + if (nullptr == _instant) { + _instant = new TmpDevClear(); + } + + return _instant; +} + +void TmpDevClear::init() +{ + if (!baseTime) { + baseTime = new QTimer(this); + baseTime->setInterval(interval); + connect(baseTime,&QTimer::timeout,this,&TmpDevClear::removeConnectionFromMap); + } + qDebug() << "TmpDevClear currentThreadId :" << QThread::currentThreadId(); + + + for (auto dev : Daemon::_DefualtAdapter.data()->devices()) { + qDebug() << Q_FUNC_INFO <address() << dev.data()->name(); + if (connections.end() != connections.find(dev.data()->address())) { + QObject::disconnect(connections[dev.data()->address()]); + } + + devUpdates[dev.data()->address()] = QDateTime::currentMSecsSinceEpoch(); + connections[dev.data()->address()] = connect(dev.data(),&BluezQt::Device::deviceChanged,this,&TmpDevClear::rssiChanaged); + } + + connect(Daemon::_DefualtAdapter.data(),&BluezQt::Adapter::deviceAdded,this,[=](BluezQt::DevicePtr devAdd){ + if (connections.end() != connections.find(devAdd.data()->address())) { + QObject::disconnect(connections[devAdd.data()->address()]); + } + + devUpdates[devAdd.data()->address()] = QDateTime::currentMSecsSinceEpoch(); + connections[devAdd.data()->address()] = connect(devAdd.data(),&BluezQt::Device::deviceChanged,this,&TmpDevClear::rssiChanaged); + }); + + baseTime->start(); +} + +TmpDevClear::TmpDevClear(QObject *parent): QObject(parent) +{ + +} + +void TmpDevClear::removeConnectionFromMap() +{ + qDebug() << Q_FUNC_INFO << "start" << devUpdates.size() << connections.size(); + + for (QMap::iterator iter = devUpdates.begin(); iter != devUpdates.end();) { + if ((iter.value()+interval) <= QDateTime::currentMSecsSinceEpoch()) { + + BluezQt::DevicePtr devptr = Daemon::_DefualtAdapter.data()->deviceForAddress(iter.key()); + //发起配对时,设备非pair状态但是是连接状态 且 非主动连接设备 + if (!devptr.isNull() && !devptr.data()->isPaired() && !devptr.data()->isConnected() && + devptr->address() != global_active_connection_dev) + { + disconnect(connections[iter.key()]); + connections.remove(iter.key()); + + Daemon::_DefualtAdapter.data()->removeDevice(devptr); + iter = devUpdates.erase(iter); + } else { + iter++; + } + } else { + iter++; + } + } + +} + +void TmpDevClear::rssiChanaged(BluezQt::DevicePtr dev) +{ + Q_UNUSED(dev); + + devUpdates[dev.data()->address()] = QDateTime::currentMSecsSinceEpoch(); +} + +TmpDevClear::~TmpDevClear() +{ + +} + + diff --git a/service/tmpdevclear.h b/service/tmpdevclear.h new file mode 100644 index 0000000..cf7e067 --- /dev/null +++ b/service/tmpdevclear.h @@ -0,0 +1,38 @@ +#ifndef TMPDEVCLEAR_H +#define TMPDEVCLEAR_H + +#include +#include +#include +#include + +class QTimer; + +class TmpDevClear final : public QObject +{ + Q_OBJECT +public: + static TmpDevClear* getInstant(); + + void init(); + + TmpDevClear(TmpDevClear&&) = delete; + TmpDevClear(const TmpDevClear&) = delete; + TmpDevClear& operator =(TmpDevClear&) = delete; + ~TmpDevClear(); +private: + explicit TmpDevClear(QObject *parent = nullptr); + + void removeConnectionFromMap(); + + static TmpDevClear*_instant; + + QMap connections; + QMap devUpdates; + QTimer* baseTime = nullptr; + +public slots: + void rssiChanaged(BluezQt::DevicePtr); +}; + +#endif // TMPDEVCLEAR_H diff --git a/ukcc-bluetooth/bluetooth.cpp b/ukcc-bluetooth/bluetooth.cpp new file mode 100644 index 0000000..bbbb915 --- /dev/null +++ b/ukcc-bluetooth/bluetooth.cpp @@ -0,0 +1,166 @@ +#include "bluetooth.h" + +#include +#include +#include + + +static QString executeLinuxCmd(QString strCmd) +{ + QProcess p; + p.start("bash", QStringList() <<"-c" << strCmd); + p.waitForFinished(); + QString strResult = p.readAllStandardOutput(); + return strResult.toLower(); +} + +static bool IsHuawei() +{ + QString str = executeLinuxCmd("cat /proc/cpuinfo | grep Hardware"); + if(str.length() == 0) + { + return false; + } + + if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || + str.indexOf("kirin") != -1) + { + return true; + } + else + { + return false; + } + return false; +} + +Bluetooth::Bluetooth() : mFirstLoad(true) { + + qDebug() << Q_FUNC_INFO << "++ukccBluetooth========================" << __LINE__; + global_ishuawei = IsHuawei(); + qDebug() << "Ishuawei: "<< global_ishuawei; + + QTranslator * translator = new QTranslator(this);; + translator->load("/usr/share/ukui-bluetooth/translations/ukcc-bluetooth_" + QLocale::system().name() + ".qm"); + QApplication::installTranslator(translator); + + QList btServiceProcessId; + bool m_bluetooth_service_process_flag = ukccbluetoothconfig::checkProcessRunning(BluetoothServiceExePath/*"bluetoothService"*/,btServiceProcessId); + + for(quint64 tempId : btServiceProcessId) + { + qDebug () << Q_FUNC_INFO << "========================" << tempId; + } + + if (m_bluetooth_service_process_flag) + { + qDebug () << Q_FUNC_INFO << BluetoothServiceExePath << "is Running" ; + } + else + { + qDebug () << Q_FUNC_INFO << BluetoothServiceExePath << "is not Running" ; + + QList btTrayProcessId; + bool m_ukui_bluetooth_process_flag = ukccbluetoothconfig::checkProcessRunning(BluetoothTrayExePath,btTrayProcessId); + if (m_ukui_bluetooth_process_flag) + { + qDebug () << Q_FUNC_INFO << BluetoothTrayExePath << "is Running" ; + for (quint64 processId:btTrayProcessId) + { + qDebug () << Q_FUNC_INFO << "ProcessId:" << btTrayProcessId << "is Running" ; + ukccbluetoothconfig::killAppProcess(processId); + } + } + else + { + qDebug () << Q_FUNC_INFO << BluetoothTrayExePath << "is not Running" ; + } + ukccbluetoothconfig::launchBluetoothServiceStart(BluetoothServiceExePath); + } + + + + pluginName = tr("Bluetooth"); + bool intel = QFile::exists("/etc/apt/ota_version"); + if (intel) + { + pluginType = NETWORK; + ukccbluetoothconfig::m_isIntel = true; + } + else + { + pluginType = DEVICES; + ukccbluetoothconfig::m_isIntel = false; + } +} + +Bluetooth::~Bluetooth() { + if (!mFirstLoad) { +// delete pluginWidget; + } +} + +QString Bluetooth::plugini18nName() { + return pluginName; +} + +int Bluetooth::pluginTypes() { + return pluginType; +} + +QWidget *Bluetooth::pluginUi() { + + if (mFirstLoad) { + mFirstLoad = false; + pluginWidget = new BlueToothMain; +// pluginWidget = new BlueToothMainWindow; + } + if (!mFirstLoad && (nullptr != pluginWidget)) + { + QTimer::singleShot(2000,this,[=] + { + pluginWidget->setbluetoothAdapterDiscoveringStatus(true); + }); + } + + return pluginWidget; +} + +const QString Bluetooth::name() const { + return QStringLiteral("Bluetooth"); +} + +bool Bluetooth::isShowOnHomePage() const +{ + return true; +} + +QIcon Bluetooth::icon() const +{ + return QIcon::fromTheme("bluetooth-active-symbolic"); +} + + +bool Bluetooth::isEnable() const +{ + QProcess process; + process.start("rfkill list"); + process.waitForFinished(); + QByteArray output = process.readAllStandardOutput(); + QString str_output = output; + bool isHciDevice = str_output.contains(QString("hci"), Qt::CaseInsensitive); + bool isBluetoothDevice = str_output.contains(QString("Bluetooth"), Qt::CaseInsensitive); + + return (isHciDevice||isBluetoothDevice); +} + +void Bluetooth::plugin_leave() +{ + if (nullptr != pluginWidget) + { + pluginWidget->setbluetoothAdapterDiscoveringStatus(false); + //pluginWidget->update(); + } +} + +bool global_ishuawei = false; diff --git a/ukcc-bluetooth/bluetooth.h b/ukcc-bluetooth/bluetooth.h new file mode 100644 index 0000000..2fe4a79 --- /dev/null +++ b/ukcc-bluetooth/bluetooth.h @@ -0,0 +1,47 @@ +#ifndef BLUETOOTH_H +#define BLUETOOTH_H + +#include +#include +#include +#include + +#include "bluetoothmain.h" +#include "bluetoothmainwindow.h" +#include "ukccbluetoothconfig.h" + +class Bluetooth : public QObject, CommonInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface") + Q_INTERFACES(CommonInterface) +public: + Bluetooth(); + ~Bluetooth(); + + QString plugini18nName() Q_DECL_OVERRIDE; + int pluginTypes() Q_DECL_OVERRIDE; + QWidget * pluginUi() Q_DECL_OVERRIDE; + const QString name() const Q_DECL_OVERRIDE; + bool isShowOnHomePage() const Q_DECL_OVERRIDE; + QIcon icon() const Q_DECL_OVERRIDE; + bool isEnable() const Q_DECL_OVERRIDE; + + void plugin_leave() Q_DECL_OVERRIDE; + + //static bool isIntel_bt = CommonInterface::isIntel(); + //注意:ukcc-bluetooth_%1.ts + QString translationPath() const { // 获取多语言文件路径,用于搜索 + qDebug() << Q_FUNC_INFO << QStringLiteral("/usr/share/ukui-bluetooth/translations/%1.ts"); + return QStringLiteral("/usr/share/ukui-bluetooth/translations/ukcc-bluetooth_%1.ts"); + } +private: + QString pluginName; + int pluginType; + BlueToothMain * pluginWidget; +// BlueToothMainWindow *pluginWidget; + bool mFirstLoad; + +}; + +#endif // BLUETOOTH_H diff --git a/ukcc-bluetooth/bluetoothdbusservice.cpp b/ukcc-bluetooth/bluetoothdbusservice.cpp new file mode 100644 index 0000000..b3be13f --- /dev/null +++ b/ukcc-bluetooth/bluetoothdbusservice.cpp @@ -0,0 +1,139 @@ +#include "bluetoothdbusservice.h" + +QDBusInterface BlueToothDBusService::interface(DBUSSERVICE,DBUSPATH,DBUSINTERFACE); + +BlueToothDBusService::BlueToothDBusService(QObject *parent) +{ + +} + +BlueToothDBusService::~BlueToothDBusService() +{ + +} + +bool BlueToothDBusService::getDefaultAdapterPower() +{ + QDBusReply reply = interface.call("getDefaultAdapterPower"); + if (reply.isValid()) { + return reply.value(); + } else { + return false; + } +} + +bool BlueToothDBusService::getBluetoothBlock() +{ + QDBusReply reply = interface.call("getBluetoothBlock"); + if (reply.isValid()) { + return reply.value(); + } else { + return false; + } +} + +bool BlueToothDBusService::getAdapterDiscoverable() +{ + QDBusReply reply = interface.call("getDefaultAdapterDiscoverable"); + if (reply.isValid()) { + return reply.value(); + } else { + return false; + } +} + +QStringList BlueToothDBusService::getAdapterList() +{ + QDBusReply reply = interface.call("getAdapterDevAddressList"); + if (reply.isValid()) { + return reply.value(); + } else { + return QStringList(); + } +} + +QString BlueToothDBusService::getDefaultAdapterAddr() +{ + QDBusReply reply = interface.call("getDefaultAdapterAddress"); + if (reply.isValid()) { + return reply.value(); + } else { + return ""; + } +} + +QString BlueToothDBusService::getAdapterNameByAddr(QString addr) +{ + QDBusReply reply = interface.call("getAdapterNameByAddr",addr); + if (reply.isValid()) { + return reply.value(); + } else { + return ""; + } +} + +QString BlueToothDBusService::getDevNameByAddr(QString addr) +{ + QDBusReply reply = interface.call("getDevName",addr); + if (reply.isValid()) { + return reply.value(); + } else { + return ""; + } +} + +void BlueToothDBusService::setAdapterPower(bool v) +{ + interface.call("setDefaultAdapterPower",v); +} + +void BlueToothDBusService::setAdapterDiscoverable(bool v) +{ + interface.call("setDefaultAdapterDiscoverable",v); +} + +bool BlueToothDBusService::getDevPairedByAddr(QString addr) +{ + QDBusReply reply = interface.call("getDevPairStatus",addr); + if (reply.isValid()) { + return reply.value(); + } else { + return false; + } +} + +bool BlueToothDBusService::getDevSupportFileSend(QString address) { + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "getDevSupportFileSend"); + m << address; + QDBusMessage response = QDBusConnection::sessionBus().call(m); + if (response.type() == QDBusMessage::ReplyMessage) + { + //qDebug() << "<<______>>"; + return response.arguments().takeFirst().toBool(); + } + return false; +} + +QString BlueToothDBusService::getDevTypeByAddr(QString) +{ + +} + +bool BlueToothDBusService::getTransferInfo(QString dev) { + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "getTransferDevAndStatus"); + m << dev; + QDBusMessage response = QDBusConnection::sessionBus().call(m); + if (response.type() == QDBusMessage::ReplyMessage) + { + //qDebug() << "<<______>>"; + return response.arguments().takeFirst().toBool(); + } + //默认暴露文件发送接口 + return true; +} diff --git a/ukcc-bluetooth/bluetoothdbusservice.h b/ukcc-bluetooth/bluetoothdbusservice.h new file mode 100644 index 0000000..9178671 --- /dev/null +++ b/ukcc-bluetooth/bluetoothdbusservice.h @@ -0,0 +1,43 @@ +#ifndef BLUETOOTHDBUSSERVICE_H +#define BLUETOOTHDBUSSERVICE_H + +#include +#include +#include +#include +#include "config.h" + +#define DBUSSERVICE "com.ukui.bluetooth" +#define DBUSPATH "/com/ukui/bluetooth" +#define DBUSINTERFACE "com.ukui.bluetooth" + +class BlueToothDBusService : public QObject +{ + Q_OBJECT +public: + BlueToothDBusService(QObject *parent = nullptr); + ~BlueToothDBusService(); + + static QDBusInterface interface; + static bool getDefaultAdapterPower(); + static bool getBluetoothBlock(); + static bool getAdapterDiscoverable(); + static QStringList getAdapterList(); + static QString getDefaultAdapterAddr(); + static QString getAdapterNameByAddr(QString); + + static void setAdapterPower(bool); + static void setAdapterDiscoverable(bool); + + static bool getDevPairedByAddr(QString); + static QString getDevTypeByAddr(QString); + static QString getDevNameByAddr(QString); + + static bool getDevSupportFileSend(QString); + static bool getTransferInfo(QString dev); +private: + + +}; + +#endif // BLUETOOTHDBUSSERVICE_H diff --git a/ukcc-bluetooth/bluetoothmain.cpp b/ukcc-bluetooth/bluetoothmain.cpp new file mode 100644 index 0000000..1e28d3f --- /dev/null +++ b/ukcc-bluetooth/bluetoothmain.cpp @@ -0,0 +1,2396 @@ +#include "bluetoothmain.h" + +bool BlueToothMain::m_device_operating = false; +QString BlueToothMain::m_device_operating_address = ""; +bool BlueToothMain::m_device_pin_flag = false; + +//dev-3.1 界面服务-分离 +BlueToothMain::BlueToothMain(QWidget *parent) + : QMainWindow(parent) +{ + if(QGSettings::isSchemaInstalled("org.ukui.bluetooth")) + { + m_settings = new QGSettings("org.ukui.bluetooth"); + QStringList btGsettingStrList = m_settings->keys(); + qDebug() << Q_FUNC_INFO << btGsettingStrList <<__LINE__; + if (btGsettingStrList.contains(GSETTING_STR_ACTIVE_CONNECTION_TRAN)) + m_current_active_connection_status = m_settings->get(GSETTING_STR_ACTIVE_CONNECTION).toBool(); + qDebug() << Q_FUNC_INFO << "m_current_active_connection_status:" << m_current_active_connection_status << __LINE__; + connect(m_settings,&QGSettings::changed,this,&BlueToothMain::gSettingsBluetoothChanged); + } + + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + styleSettings = new QGSettings("org.ukui.style"); + if(styleSettings->get("style-name").toString() == "ukui-black" || + styleSettings->get("style-name").toString() == "ukui-dark") + isblack = true; + else + isblack = false; + connect(styleSettings,&QGSettings::changed,this,&BlueToothMain::gSettingsChanged); + } + + getAllAdapterData(); + + _MCentralWidget = new QStackedWidget(this); + this->setCentralWidget(_MCentralWidget); + showBluetoothNormalMainWindow(); + showBluetoothErrorMainWindow(); + + qDebug() << "adapter (addresss/name) size:" << m_adapter_address_list.size() << m_adapter_name_list.size(); + + if ((global_ishuawei && !m_default_adapter_address.isEmpty()) || + (m_adapter_address_list.size() > 0 && m_adapter_name_list.size() == m_adapter_address_list.size())) + { + _MCentralWidget->setCurrentWidget(m_normal_main_widget); + refreshUIWhenAdapterChanged(); + } + else + { + _MCentralWidget->setCurrentWidget(m_error_main_widget); + } + monitorBluetoothDbusConnection(); +} + +BlueToothMain::~BlueToothMain() +{ + //rfkill_exit(); + qDebug() << Q_FUNC_INFO << __LINE__; + setDefaultAdapterScanOn(false); + //clearAllUnPairedDevicelist(); + + delete m_settings; + m_settings = nullptr; + //delete paired_device_list; + //paired_device_list = nullptr; + delete device_list; + device_list = nullptr; + +} + +void BlueToothMain::leaveEvent(QEvent *event) +{ + //qDebug() << Q_FUNC_INFO; +} + +void BlueToothMain::monitorBluetoothDbusConnection() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + // bool connect(const QString &service, const QString &path, const QString &interface, + // const QString &name, QObject *receiver, const char *slot); + //1.适配器数据上报 + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "defaultAdapterChanged",this, SLOT(reportDefaultAdapterChanged(QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "defaultAdapterNameChanged",this, SLOT(reportDefaultAdapterNameChanged(QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "adapterAddSignal",this, SLOT(reportAdapterAddSignal(QString))); + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "adapterRemoveSignal",this, SLOT(reportAdapterRemoveSignal(QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "defaultAdapterPowerChanged",this, SLOT(reportDefaultAdapterPowerChanged(bool))); + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "defaultDiscoverableChanged",this, SLOT(reportDefaultDiscoverableChanged(bool))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "defaultScanStatusChanged",this, SLOT(reportDefaultScanStatusChanged(bool))); + + //2.蓝牙设备数据上报 + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "deviceScanResult",this, SLOT(reportDeviceScanResult(QString,QString,QString,bool))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "devPairSignal",this, SLOT(reportDevPairSignal(QString,bool))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "devConnectStatusSignal",this, SLOT(reportDevConnectStatusSignal(QString,bool))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "devRemoveSignal",this, SLOT(reportDevRemoveSignal(QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "devMacAddressChangedSignal",this, SLOT(reportDevMacAddressChangedSignal(QString,QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "devNameChangedSignal",this, SLOT(reportDevNameChangedSignal(QString,QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "devTypeChangedSignal",this, SLOT(reportDevTypeChangedSignal(QString,QString))); + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "requestConfirmation",this, SLOT(reportRequestConfirmation(QString,QString))); + + //PIN窗口是否操作 + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "replyRequestConfirmation",this, SLOT(reportReplyRequestConfirmation(bool))); + + + + QDBusConnection::sessionBus().connect(SERVICE, + PATH, + INTERFACE, + "devOperateErrorSignal",this, SLOT(reportDevOperateErrorSignal(QString,int,QString))); + +} + +//adapter report start +void BlueToothMain::reportDefaultAdapterChanged(QString ) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + +} + +void BlueToothMain::reportDefaultAdapterNameChanged(QString adapter_name) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + if(nullptr != m_default_bluetooth_adapter) + { + m_default_bluetooth_adapter->resetDeviceName(adapter_name); + for(bluetoothadapter * adapter_dev : m_bluetooth_adapter_list) + { + if (adapter_dev->getDevAddress() == m_default_bluetooth_adapter->getDevAddress()) + { + adapter_dev->resetDeviceName(adapter_name); + break; + } + } + emit defaultAdapterNameChanged(adapter_name); + } +} + +void BlueToothMain::reportDefaultDiscoverableChanged(bool discoverable) +{ + qDebug () << Q_FUNC_INFO << discoverable << __LINE__; + m_current_adapter_disconvery_swtich = discoverable; + m_discover_switch_btn->setChecked(discoverable); +} + +void BlueToothMain::reportDefaultScanStatusChanged(bool isScan) +{ + qDebug () << Q_FUNC_INFO << isScan << __LINE__; + m_current_adapter_scan_status = isScan; + + if (isScan) + { + if(!loadLabel->isVisible()) + loadLabel->setVisible(true); + if (!m_timer->isActive()) + m_timer->start(); + + if(delayStartDiscover_timer->isActive()) + delayStartDiscover_timer->stop(); + } + else + { + //if(loadLabel->isVisible())//设置为隐藏时无需判断,若夫窗口设置为false后界面下所有控件均为false + loadLabel->setVisible(false); + + if (m_timer->isActive()) + m_timer->stop(); + } +} + +bluetoothadapter * BlueToothMain::createOneBluetoothAdapter(QString adapter_address) +{ + qDebug () << Q_FUNC_INFO << adapter_address << __LINE__; + bluetoothadapter * adapter_dev = nullptr ; + + //将等待值修改为300ms + //建议基于事件定时获取,防止出现异常 + QString adapter_dev_name = getAdapterName(adapter_address); + qDebug() << Q_FUNC_INFO << adapter_dev_name << __LINE__; + if (adapter_dev_name.isEmpty()) + { + if (adapter_dev_name.isEmpty()) + { + qDebug() << Q_FUNC_INFO << "name is null!" << __LINE__; + adapter_dev->deleteLater(); + return nullptr; + } + } + + //设备列表已经存在该设备 + for (bluetoothadapter * tmpDev : m_bluetooth_adapter_list) + { + if (adapter_address == tmpDev->getDevAddress()) + { + qDebug() << Q_FUNC_INFO << "device existing!" << __LINE__; + adapter_dev->deleteLater(); + return nullptr; + } + } + + adapter_dev = new bluetoothadapter(adapter_dev_name, + adapter_address, + false, + false, + false); + + qDebug () << Q_FUNC_INFO << adapter_address << "create ok!" << __LINE__; + return adapter_dev; +} + + +void BlueToothMain::refreshBluetoothAdapterInterfaceUI() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + qDebug () << Q_FUNC_INFO << m_adapter_address_list << m_adapter_name_list << __LINE__; + + if(1 == m_adapter_address_list.size())// || + //(m_adapter_address_list.size() > 0 && m_adapter_address_list.size() != m_adapter_name_list.size())) + { + //m_default_bluetooth_adapter = m_bluetooth_adapter_list.at(0); + if("normalWidget" != _MCentralWidget->currentWidget()->objectName()) + { + _MCentralWidget->setCurrentWidget(m_normal_main_widget); + } + if(frame_2->isVisible()) { + frame_2->setVisible(false); + line_frame2->setVisible(false); + } + if(ukccbluetoothconfig::m_isIntel) + { + //frame_top->setMinimumSize(582,153); + //frame_top->setMaximumSize(1800,153); + frame_top->setMinimumSize(582,217); + frame_top->setMaximumSize(1800,217); + } + else + { + //frame_top->setMinimumSize(582,217); + //frame_top->setMaximumSize(1800,217); + frame_top->setMinimumSize(582,279); + frame_top->setMaximumSize(1800,279); + } + } + else if (m_adapter_address_list.size() > 1) + { + if("normalWidget" != _MCentralWidget->currentWidget()->objectName()) + { + _MCentralWidget->setCurrentWidget(m_normal_main_widget); + } + if(!frame_2->isVisible()) + frame_2->setVisible(true); + if(ukccbluetoothconfig::m_isIntel) + { + frame_top->setMinimumSize(582,279); + frame_top->setMaximumSize(1800,279); + //frame_top->setMinimumSize(582,215); + //frame_top->setMaximumSize(1800,215); + } + else + { + //frame_top->setMinimumSize(582,279); + //frame_top->setMaximumSize(1800,279); + frame_top->setMinimumSize(582,343); + frame_top->setMaximumSize(1800,343); + } + } + else + { + if("errorWidget" != _MCentralWidget->currentWidget()->objectName()) + { + _MCentralWidget->setCurrentWidget(m_error_main_widget); + } + } + + refreshUIWhenAdapterChanged(); +} + +//void BlueToothMain::addBluetoothAdapterComboBox(QString adapterName) +//{ + +//} + +//void BlueToothMain::removeBluetoothAdapterComboBox(int index) +//{ + +//} + +void BlueToothMain::addAdapterDataList(QString adapterAddress) +{ + qDebug () << Q_FUNC_INFO << adapterAddress << __LINE__; + + bluetoothadapter * adapter_dev = createOneBluetoothAdapter(adapterAddress); + if (nullptr == adapter_dev) + { + qDebug () << Q_FUNC_INFO << "adapter dev not add!" << __LINE__; + return; + } + qDebug () << Q_FUNC_INFO << "what's =======?" << __LINE__; + qDebug () << Q_FUNC_INFO << m_adapter_address_list << m_adapter_name_list << __LINE__; + + if (m_adapter_address_list.indexOf(adapterAddress) == -1) + { + m_adapter_address_list << adapterAddress; + m_adapter_name_list << getAdapterName(adapterAddress); + + if(m_adapter_list_cmbox) + m_adapter_list_cmbox->addItem(m_adapter_name_list.last()); + } + qDebug () << Q_FUNC_INFO << m_adapter_address_list << m_adapter_name_list << __LINE__; + + + m_bluetooth_adapter_list.append(adapter_dev); +} + +void BlueToothMain::removeAdapterDataList(QString adapterAddress) +{ + qDebug () << Q_FUNC_INFO << adapterAddress << __LINE__; + int i = m_adapter_address_list.indexOf(adapterAddress); + if (-1 == i) + { + qDebug () << Q_FUNC_INFO << "Not device :" << adapterAddress << __LINE__; + return; + } + qDebug() << Q_FUNC_INFO << __LINE__ << m_adapter_address_list << m_adapter_name_list << i; + m_adapter_name_list.removeAt(i); + m_adapter_address_list.removeAll(adapterAddress); + m_bluetooth_adapter_list.removeAt(i); + + //if (m_adapter_address_list.size()) + //{ + disconnect(m_adapter_list_cmbox,SIGNAL(currentIndexChanged(int)),NULL,NULL); + if(m_adapter_list_cmbox != nullptr) + { + m_adapter_list_cmbox->clear(); + m_adapter_list_cmbox->addItems(m_adapter_name_list); + //m_adapter_list_cmbox->removeItem(i); + connect(m_adapter_list_cmbox,SIGNAL(currentIndexChanged(int)),this,SLOT(adapterComboxChanged(int))); + } + //} +} +void BlueToothMain::reportAdapterAddSignal(QString adapterAddress) +{ + qDebug () << Q_FUNC_INFO << adapterAddress << __LINE__; +// if("normalWidget" != this->centralWidget()->objectName()) +// { +// _MCentralWidget->setCurrentWidget(m_normal_main_widget); +// } + + addAdapterDataList(adapterAddress); + refreshBluetoothAdapterInterfaceUI(); +} + +void BlueToothMain::reportAdapterRemoveSignal(QString adapterAddress) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + removeAdapterDataList(adapterAddress); + refreshBluetoothAdapterInterfaceUI(); +} + +void BlueToothMain::reportDefaultAdapterPowerChanged(bool isPower) +{ + qDebug () << Q_FUNC_INFO << isPower << __LINE__; + if("normalWidget" != _MCentralWidget->currentWidget()->objectName()) + { + qDebug () << Q_FUNC_INFO << "is not normalWidget" << __LINE__; + return; + } + + m_current_adapter_power_swtich = isPower; + + if (isPower && !m_open_bluetooth_btn->isChecked()) + { + m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(true); + } + if (!isPower && m_open_bluetooth_btn->isChecked()) + { + m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(false); + } +} + + +//device report start +void BlueToothMain::reportDevPairSignal(QString deviceAddress,bool isPaired) +{ + qDebug() << Q_FUNC_INFO << deviceAddress << "isPaired:"<< isPaired << __LINE__; + bool isNotExist = true ; + for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) + { + qDebug() << Q_FUNC_INFO << dev->getDevAddress() << __LINE__; + if (deviceAddress == dev->getDevAddress()) + { + dev->devPairedChanged(isPaired); + isNotExist = false; + break; + } + } + qDebug() << Q_FUNC_INFO << deviceAddress << "isPaired:"<< isPaired << isNotExist << __LINE__; + + if (isPaired && isNotExist) + { + bluetoothdevice * dev = createOneBluetoothDeviceFromMacAddress(deviceAddress); + + if (nullptr != dev) + { + m_default_bluetooth_adapter->m_bluetooth_device_list.append(dev); + addMyDeviceItemUI(dev); + } + } +} + +void BlueToothMain::reportDevConnectStatusSignal(QString deviceAddress,bool isConnected) +{ + qDebug() << Q_FUNC_INFO << deviceAddress << "isConnected:"<< isConnected << __LINE__; + for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (deviceAddress == dev->getDevAddress()) + { + qDebug() << Q_FUNC_INFO << "find deviceAddress ok!" << __LINE__; + dev->devConnectedChanged(isConnected); + return; + } + } +} + +void BlueToothMain::reportDevRemoveSignal(QString deviceAddress) +{ + qDebug () << Q_FUNC_INFO << deviceAddress << __LINE__; + removeDeviceItemUI(deviceAddress); + + if(!m_device_operating_address.isNull() && + m_device_operating && + (m_device_operating_address == deviceAddress)) + { + m_device_operating = false; + m_device_operating_address.clear(); + } + for (int i = 0 ; i < m_default_bluetooth_adapter->m_bluetooth_device_list.size() ; i++) + { + if(deviceAddress == m_default_bluetooth_adapter->m_bluetooth_device_list.at(i)->getDevAddress()) + { + //m_default_bluetooth_adapter->m_bluetooth_device_list.removeAll(m_default_bluetooth_adapter->m_bluetooth_device_list.at(i)); + m_default_bluetooth_adapter->m_bluetooth_device_list.removeAt(i); + break ; + } + } +} + +void BlueToothMain::reportDevMacAddressChangedSignal(QString sourceMacAddress ,QString newMacAddress) +{ + qDebug() << Q_FUNC_INFO << "sourceMacAddress:" << sourceMacAddress << "newMacAddress:"<< newMacAddress << __LINE__; + for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (sourceMacAddress == dev->getDevAddress() && !dev->isConnected()) + { + dev->devMacAddressChanged(newMacAddress); + qDebug() << Q_FUNC_INFO << "dev->getDevAddress:" << dev->getDevAddress() << __LINE__; + DeviceInfoItem *item = frame_middle->findChild(sourceMacAddress); + qDebug() << Q_FUNC_INFO << "new item ok!" << __LINE__; + if (item) + { + qDebug() << Q_FUNC_INFO << "item->setObjectName:" << item->objectName() << __LINE__; + item->setObjectName(newMacAddress); + qDebug() << Q_FUNC_INFO << "item->setObjectName:" << item->objectName() << __LINE__; + } + QFrame * line_item = frame_middle->findChild("line-"+sourceMacAddress); + qDebug() << Q_FUNC_INFO << "new line_item ok!" << __LINE__; + + if (line_item) + { + qDebug() << Q_FUNC_INFO << "line_item->setObjectName:" << line_item->objectName() << __LINE__; + line_item->setObjectName("line-"+newMacAddress); + qDebug() << Q_FUNC_INFO << "line_item->setObjectName:" << line_item->objectName() << __LINE__; + } + + //delete item; + //delete line_item; + return; + } + } +} + +void BlueToothMain::reportDevNameChangedSignal(QString deviceAddress,QString changedName) +{ + qDebug() << Q_FUNC_INFO << deviceAddress << "changedName:"<< changedName << __LINE__; + for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (deviceAddress == dev->getDevAddress()) + { + dev->resetDeviceName(changedName); + return; + } + } +} + +void BlueToothMain::reportDevTypeChangedSignal(QString deviceAddress,QString changedType) +{ + qDebug() << Q_FUNC_INFO << deviceAddress << "changedType:"<< changedType << __LINE__; + for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (deviceAddress == dev->getDevAddress()) + { + bluetoothdevice::DEVICE_TYPE devType = getDeviceType(deviceAddress,changedType); + dev->setDevType(devType); + return; + } + } +} + + +void BlueToothMain::reportRequestConfirmation(QString deviceName,QString disPinCode) +{ + qDebug() << Q_FUNC_INFO << deviceName << disPinCode << __LINE__; + m_device_pin_flag = true; +} +void BlueToothMain::reportReplyRequestConfirmation(bool userCheck) +{ + qDebug() << Q_FUNC_INFO << "User check:" << userCheck << __LINE__; + m_device_pin_flag = false; +} + +void BlueToothMain::reportDevOperateErrorSignal(QString deviceAddress , int ErrorId , QString ErrorText) +{ + qDebug() << Q_FUNC_INFO << deviceAddress << ErrorId << ErrorText << __LINE__; + //m_device_pin_flag = false; + for (bluetoothdevice * dev :m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (deviceAddress == dev->getDevAddress()) + { + dev->setErrorInfo(ErrorId,ErrorText); + return; + } + } +} + +bluetoothdevice * BlueToothMain::createOneBluetoothDeviceFromBluetoothService(QString devAddress,QString devName,QString type ,bool isSupportFileSend) +{ + qDebug() << Q_FUNC_INFO << devName << devAddress << type << isSupportFileSend << __LINE__; + bluetoothdevice * dev = nullptr ; + if (devAddress.isEmpty() || devName.isEmpty()) + { + qDebug() << Q_FUNC_INFO << "address or name is null!" << __LINE__; + dev->deleteLater(); + return nullptr; + } + + bluetoothdevice::DEVICE_TYPE dev_type = getDeviceType(devAddress,type); + bool isPaired = getDevPairStatus(devAddress); + bool isConnected = getDevConnectStatus(devAddress); + if(isInvalidDevice(devName,dev_type)) + { + qDebug() << Q_FUNC_INFO << "isInvalidDevice!" << __LINE__; + dev->deleteLater(); + return nullptr; + } + //设备列表已经存在该设备 + for (bluetoothdevice * tmpDev : m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (devAddress == tmpDev->getDevAddress()) + { + qDebug() << Q_FUNC_INFO << "device existing!" << __LINE__; + dev->deleteLater(); + return nullptr; + } + } + + dev = new bluetoothdevice(devName, + devAddress, + dev_type, + isPaired, + isConnected, + isPaired); + + dev->setDevSendFileMark(isSupportFileSend); + + return dev; +} + + +bluetoothdevice * BlueToothMain::createOneBluetoothDeviceFromMacAddress(QString devAddress) +{ + qDebug() << Q_FUNC_INFO << devAddress << __LINE__; + bluetoothdevice * dev = nullptr ; + + QString dev_name = getDevName(devAddress); + if (dev_name.isEmpty()) + { + dev_name = "Bluez 5.53"; + } + qDebug() << Q_FUNC_INFO << dev_name << __LINE__; + if (dev_name.isEmpty()) + { + qDebug() << Q_FUNC_INFO << "name is null!" << __LINE__; + dev->deleteLater(); + return nullptr; + } + + bluetoothdevice::DEVICE_TYPE dev_type = getDeviceType(devAddress,""); + bool isPaired = getDevPairStatus(devAddress); + bool isConnected = getDevConnectStatus(devAddress); + qDebug() << Q_FUNC_INFO << devAddress << isPaired << isConnected << __LINE__; + + if(isInvalidDevice(dev_name,dev_type)) + { + qDebug() << Q_FUNC_INFO << "isInvalidDevice!" << __LINE__; + dev->deleteLater(); + return nullptr; + } + + //设备列表已经存在该设备 + for (bluetoothdevice * tmpDev : m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (devAddress == tmpDev->getDevAddress()) + { + qDebug() << Q_FUNC_INFO << "device existing!" << __LINE__; + dev->deleteLater(); + return nullptr; + } + } + + dev = new bluetoothdevice(dev_name, + devAddress, + dev_type, + isPaired, + isConnected, + isPaired); + + if (bluetoothdevice::computer == dev->getDevType() || + bluetoothdevice::phone == dev->getDevType()) + { + bool isSupportFileSend = getDevSupportFileSend(devAddress); + dev->setDevSendFileMark(isSupportFileSend); + } + else + { + dev->setDevSendFileMark(false); + } + return dev; +} + +void BlueToothMain::reportDeviceScanResult(QString devAddress,QString devName,QString type ,bool isSupportFileSend) +{ + qDebug () << Q_FUNC_INFO << devName << devAddress << type <currentWidget()->objectName()) + { + qDebug() << Q_FUNC_INFO << "errorWidget not add device!!" << __LINE__; + return; + } + + qDebug () << Q_FUNC_INFO << devName << "m_current_adapter_scan_status =========" << m_current_adapter_scan_status << __LINE__; + + //当前是扫描状态,且扫描延时也在计时 + if (m_current_adapter_scan_status && delayStartDiscover_timer && delayStartDiscover_timer->isActive()) + { + delayStartDiscover_timer->stop(); + } + //设备列表已经存在该设备,添加到界面中去 + for (bluetoothdevice * tmpDev : m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (devAddress == tmpDev->getDevAddress()) + { + if(whetherToAddCurrentInterface(tmpDev)) + { + addOneBluetoothDeviceItemUi(tmpDev); + qDebug () << Q_FUNC_INFO << "device list is exist,add item ui!"; + return; + } + } + } + + bluetoothdevice * device = createOneBluetoothDeviceFromBluetoothService(devAddress,devName,type,isSupportFileSend); + if (device == nullptr) + { + qDebug () << Q_FUNC_INFO << "device not add!"; + return; + } + + qDebug() << "effective device"; + device->setObjectName(devAddress); + m_default_bluetooth_adapter->m_bluetooth_device_list.append(device); + if(device->isPaired()) + { + this->addMyDeviceItemUI(device); + } + else + { + if(this->whetherToAddCurrentInterface(device)) + this->addOneBluetoothDeviceItemUi(device); + } + + +} + +void BlueToothMain::addMyDeviceItemUI(bluetoothdevice * device) +{ + qDebug() << __FUNCTION__ << device->getDevName() << device->getDevAddress() << device->getDevType() << __LINE__; + + DeviceInfoItem *item = frame_middle->findChild(device->getDevAddress()); + if (item) + { + m_myDev_show_flag = true; + qDebug () << Q_FUNC_INFO << "device is exist" << __LINE__; + return; + } + + if (device && device->isPaired()) { + + mDevFrameAddLineFrame("paired",device->getDevAddress()); + + DeviceInfoItem *item = new DeviceInfoItem(this,device); + item->setObjectName(device->getDevAddress()); + connect(item,SIGNAL(devPaired(QString)),this,SLOT(changeDeviceParentWindow(QString))); + connect(item,SIGNAL(devConnect(QString)),this,SLOT(receiveConnectsignal(QString))); + connect(item,SIGNAL(devDisconnect(QString)),this,SLOT(receiveDisConnectSignal(QString))); + connect(item,SIGNAL(devRemove(QString)),this,SLOT(receiveRemoveSignal(QString))); + connect(item,SIGNAL(devSendFiles(QString)),this,SLOT(receiveSendFileSignal(QString))); + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { + m_device_operating = false; + m_device_operating_address.clear(); + cacheDevTypeList->setEnabled(true); + }); + m_myDev_show_flag = true; + + paired_dev_layout->addWidget(item,Qt::AlignTop); + } + return; +} +bool BlueToothMain::whetherToAddCurrentInterface(bluetoothdevice * device) +{ + switch (discoverDevFlag) { + case DevTypeShow::All: + return true; + case DevTypeShow::Audio: + if (device->getDevType() == bluetoothdevice::DEVICE_TYPE::headset || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::headphones || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::audiovideo) { + return true; + } else { + return false; + } + break; + case DevTypeShow::Peripherals: + if (device->getDevType() == bluetoothdevice::DEVICE_TYPE::mouse || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::keyboard) { + return true; + } else { + return false; + } + break; + case DevTypeShow::PC: + if (device->getDevType() == bluetoothdevice::DEVICE_TYPE::computer) { + return true; + } else { + return false; + } + break; + case DevTypeShow::Phone: + if (device->getDevType() == bluetoothdevice::DEVICE_TYPE::phone) { + return true; + } else { + return false; + } + break; + default: + if (device->getDevType() == bluetoothdevice::DEVICE_TYPE::headset || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::headphones || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::audiovideo || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::phone || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::mouse || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::keyboard || + device->getDevType() == bluetoothdevice::DEVICE_TYPE::computer) { + return false; + } + return true; + } +} + +void BlueToothMain::addOneBluetoothDeviceItemUi(bluetoothdevice * device) +{ + DeviceInfoItem * item = frame_middle->findChild(device->getDevAddress()); + if (item) + { + qDebug () << Q_FUNC_INFO << "device is exist" << __LINE__; + return; + } + + item = device_list->findChild(device->getDevAddress()); + if (item) + { + qDebug () << Q_FUNC_INFO << "device is exist" << __LINE__; + return ; + } + + + item = new DeviceInfoItem(device_list,device); + item->setObjectName(device->getDevAddress()); + connect(item,SIGNAL(devPaired(QString)),this,SLOT(changeDeviceParentWindow(QString))); + connect(item,SIGNAL(devConnect(QString)),this,SLOT(receiveConnectsignal(QString))); + connect(item,SIGNAL(devDisconnect(QString)),this,SLOT(receiveDisConnectSignal(QString))); + connect(item,SIGNAL(devRemove(QString)),this,SLOT(receiveRemoveSignal(QString))); + connect(item,SIGNAL(devSendFiles(QString)),this,SLOT(receiveSendFileSignal(QString))); + connect(item,&DeviceInfoItem::devConnectionComplete,this,[=] + { + m_device_operating = false; + m_device_operating_address.clear(); + cacheDevTypeList->setEnabled(true); +// if (delayStartDiscover_timer->isActive()) +// delayStartDiscover_timer->stop(); +// delayStartDiscover_timer->start(); + }); + + mDevFrameAddLineFrame("other",device->getDevAddress()); + + if (!device_list->isVisible()) + device_list->setVisible(true); + + device_list_layout->insertWidget(0,item,0,Qt::AlignTop); + + last_discovery_device_address << device->getDevAddress(); +} + +void BlueToothMain::getDefaultAdapterData(QString adapter_address) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + m_current_bluetooth_block_status = getBluetoothBlock(); + m_default_adapter_name = getAdapterName(adapter_address); + m_current_adapter_power_swtich = getDefaultAdapterPower(); + m_current_adapter_scan_status = getDefaultAdapterScanStatus(); + //当前扫描状态是开启,则关闭扫描状态,并清除所有未匹配的蓝牙设备, + if (m_current_adapter_scan_status) + { + setDefaultAdapterScanOn(false); + //clearAllUnPairedDevicelist(); + } + + m_current_adapter_disconvery_swtich = getDefaultAdapterDiscoverable(); + + + m_default_bluetooth_adapter = new bluetoothadapter(m_default_adapter_name, + m_default_adapter_address, + m_current_adapter_power_swtich, + m_current_adapter_scan_status, + m_current_adapter_disconvery_swtich); + m_default_bluetooth_adapter->m_bluetooth_device_list.clear(); + m_discovery_device_address_all_list = getDefaultAdapterCacheDevAddress(); + //qDebug () << Q_FUNC_INFO << "m_discovery_device_address_all_list:" << m_discovery_device_address_all_list ; + for (auto deviceAddress: m_discovery_device_address_all_list) + { + bluetoothdevice * dev = createOneBluetoothDeviceFromMacAddress(deviceAddress); + if (nullptr == dev) + continue ; + dev->setObjectName(deviceAddress); + m_default_bluetooth_adapter->m_bluetooth_device_list.append(dev); + } + qDebug () << Q_FUNC_INFO << "end" << __LINE__; + +} + +void BlueToothMain::connectBluetoothServiceSignal() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + iface.setTimeout(300); + iface.call("connectSignal"); +} + +void BlueToothMain::getAllAdapterData() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + m_default_bluetooth_adapter = nullptr; + + m_default_adapter_address = getDefaultAdapterAddress(); + if(m_default_adapter_address.isEmpty()) + { + m_default_bluetooth_adapter = nullptr; + return; + } + + getDefaultAdapterData(m_default_adapter_address); + + qDebug () << Q_FUNC_INFO << "m_default_bluetooth_adapter->m_bluetooth_device_list.size():" << m_default_bluetooth_adapter->m_bluetooth_device_list.size(); + + m_adapter_address_list = getAdapterDevAddressList(); + m_adapter_name_list = getAdapterDevNameList(); + + //m_adapter_address_list << m_default_adapter_address; + //m_adapter_name_list << m_default_adapter_name; + + qDebug () << Q_FUNC_INFO << "m_adapter_address_list size :" << m_adapter_address_list.size() << __LINE__; + for(QString adapterAddress:m_adapter_address_list) + { + QString adapterName = getAdapterName(adapterAddress); + if(adapterAddress == m_default_adapter_address) + m_bluetooth_adapter_list.append(m_default_bluetooth_adapter); + else + { + bluetoothadapter * adapterdev = new bluetoothadapter(adapterName,adapterAddress,false,false,false); + m_bluetooth_adapter_list.append(adapterdev); + } + //m_adapter_address_list << adapterAddress; + //m_adapter_name_list << adapterName; + } + + qDebug () << Q_FUNC_INFO << "m_current_bluetooth_block_status: " << m_current_bluetooth_block_status << __LINE__; + qDebug () << Q_FUNC_INFO << "m_default_adapter_address: " << m_default_adapter_address << __LINE__; + qDebug () << Q_FUNC_INFO << "m_adapter_address_list: " << m_adapter_address_list << __LINE__; + qDebug () << Q_FUNC_INFO << "m_default_adapter_name: " << m_default_adapter_name << __LINE__; + qDebug () << Q_FUNC_INFO << "m_adapter_name_list: " << m_adapter_name_list << __LINE__; + qDebug () << Q_FUNC_INFO << "m_current_adapter_power_swtich: " << m_current_adapter_power_swtich << __LINE__; + qDebug () << Q_FUNC_INFO << "m_current_adapter_disconvery_swtich: " << m_current_adapter_disconvery_swtich << __LINE__; + qDebug () << Q_FUNC_INFO << "m_current_adapter_scan_status: " << m_current_adapter_scan_status << __LINE__; +} + +bool BlueToothMain::getBluetoothBlock() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(300); + QDBusReply reply=iface.call("getBluetoothBlock"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +QString BlueToothMain::getDefaultAdapterAddress() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(300); + QDBusReply reply=iface.call("getDefaultAdapterAddress"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +QStringList BlueToothMain::getAdapterDevAddressList() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(300); + QDBusReply reply=iface.call("getAdapterDevAddressList"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +QStringList BlueToothMain::getAdapterDevNameList() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + + QStringList adapterNameList ; + adapterNameList.clear(); + for (QString adapterAddress : m_adapter_address_list) + { + adapterNameList << getAdapterName(adapterAddress); + } + qDebug () << Q_FUNC_INFO << adapterNameList << __LINE__; + return adapterNameList; +} + +QString BlueToothMain::getAdapterName(QString adapterAddress) +{ + qDebug () << Q_FUNC_INFO << "get adapter name address:" << adapterAddress << __LINE__; + + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间, 从20ms增加300ms,减少出现异常的几率 + iface.setTimeout(300); + QDBusReply reply=iface.call("getAdapterNameByAddr", adapterAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +bool BlueToothMain::getDefaultAdapterPower() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 ms + iface.setTimeout(300); + QDBusReply reply=iface.call("getDefaultAdapterPower"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +QStringList BlueToothMain::getDefaultAdapterCacheDevAddress() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间, ms + iface.setTimeout(300); + QDBusReply reply=iface.call("getDefaultAdapterCacheDevAddress"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +bool BlueToothMain::getDefaultAdapterDiscoverable() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(300); + QDBusReply reply=iface.call("getDefaultAdapterDiscoverable"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +bool BlueToothMain::getDefaultAdapterScanStatus() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间,从20ms延迟至300ms + iface.setTimeout(300); + QDBusReply reply=iface.call("getDefaultAdapterScanStatus"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + + +QString BlueToothMain::getDevName(QString deviceAddress) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间,从20ms延长至300ms + iface.setTimeout(300); + QDBusReply reply=iface.call("getDevName",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +bool BlueToothMain::getDevPairStatus(QString deviceAddress) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(300); + QDBusReply reply=iface.call("getDevPairStatus",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} +bool BlueToothMain::getDevConnectStatus(QString deviceAddress) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(300); + QDBusReply reply=iface.call("getDevConnectStatus",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +bool BlueToothMain::getDevSupportFileSend(QString deviceAddress) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(300); + QDBusReply reply=iface.call("getDevSupportFileSend",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + return reply; +} + +bluetoothdevice::DEVICE_TYPE BlueToothMain::getDeviceType(QString deviceAddress , QString devType) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QString dev_type_str = devType ; + if (dev_type_str.isEmpty()) + dev_type_str = getDevType(deviceAddress); + + qDebug() << Q_FUNC_INFO << "Type:" << dev_type_str << __LINE__; + QByteArray enum_str_to_char = dev_type_str.toLatin1(); + const char * enum_char = enum_str_to_char.data(); + QMetaEnum metaEnum = QMetaEnum::fromType(); + qDebug() << Q_FUNC_INFO << "enum index:" << metaEnum.keysToValue(enum_char); + + return (metaEnum.keysToValue(enum_char) == -1 ? bluetoothdevice::DEVICE_TYPE::uncategorized : bluetoothdevice::DEVICE_TYPE(metaEnum.keysToValue(enum_char))); +} +QString BlueToothMain::getDevType(QString deviceAddress) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.setTimeout(300); + QDBusReply reply=iface.call("getDevType",deviceAddress); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + + return reply; +} + +void BlueToothMain::clearAllUnPairedDevicelist() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + + QDBusInterface iface(SERVICE, + PATH, + INTERFACE, + QDBusConnection::sessionBus()); + //设置超时时间 + iface.call(QDBus::NoBlock, "clearAllUnPairedDevicelist"); + //qDebug () << Q_FUNC_INFO << "==========================" << reply << __LINE__; + //return reply; +} + +void BlueToothMain::setTrayVisible(bool value) +{ + qDebug() << Q_FUNC_INFO << "user check: " << value << __LINE__; + m_settings->set("tray-show",QVariant::fromValue(value)); +} + +void BlueToothMain::setBluetoothBlock(bool value) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "setBluetoothBlock"); + m << value; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BlueToothMain::setDefaultAdapterName(QString adapterName) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "setDefaultAdapterName");//setBluetoothName + m << adapterName; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + +} + +void BlueToothMain::setDefaultAdapterPower(bool value) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "setDefaultAdapterPower"); + m << value; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BlueToothMain::setDefaultAdapter(QString adapterAddress) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "setDefaultAdapter"); + m << adapterAddress; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BlueToothMain::setDefaultAdapterDiscoverable(bool value) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "setDefaultAdapterDiscoverable"); + m << value; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} +void BlueToothMain::setbluetoothAdapterDiscoveringStatus(bool isScan) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + if ("normalWidget" != _MCentralWidget->currentWidget()->objectName()) + { + qDebug() << Q_FUNC_INFO << "errorWidget not open scan!!" << __LINE__; + return; + } + setDefaultAdapterScanOn(isScan); +} + +void BlueToothMain::setDefaultAdapterScanOn(bool value) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + if(m_current_active_connection_status && !value) + { + qDebug() << Q_FUNC_INFO << "open active connection ,can't off scan" << __LINE__; + return; + } + + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "setDefaultAdapterScanOn"); + m << value; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BlueToothMain::receiveConnectsignal(QString address) +{ + //停止扫描,连接完成或连接超时后继续开启扫描 + //setDefaultAdapterScanOn(false); + cacheDevTypeList->setEnabled(false); + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "devConnect"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BlueToothMain::receiveDisConnectSignal(QString address) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "devDisconnect"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BlueToothMain::receiveRemoveSignal(QString address) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "devRemove"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + + removeDeviceItemUI(address); +} + +void BlueToothMain::receiveSendFileSignal(QString address) +{ + qDebug() << Q_FUNC_INFO << address; + QDBusMessage m = QDBusMessage::createMethodCall(SERVICE, + PATH, + INTERFACE, + "setSendTransferDeviceMesg"); + m << address; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__; + // 发送Message + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + +} + +void BlueToothMain::showBluetoothNormalMainWindow() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + m_normal_main_widget = new QWidget(_MCentralWidget); + m_normal_main_widget->setObjectName("normalWidget"); + //this->setCentralWidget(m_normal_main_widget); + + main_layout = new QVBoxLayout(m_normal_main_widget); + main_layout->setSpacing(40); + main_layout->setContentsMargins(0,0,0,10); + frame_top = new QWidget(m_normal_main_widget); + frame_top->setObjectName("frame_top"); + if ((m_adapter_address_list.size() > 1) && + (m_adapter_address_list.size() == m_adapter_name_list.size()))//用什么作为适配数量的判断 + { + if(ukccbluetoothconfig::m_isIntel) + { + //frame_top->setMinimumSize(582,215); + //frame_top->setMaximumSize(1800,215); + frame_top->setMinimumSize(582,279); + frame_top->setMaximumSize(1800,279); + } + else + { + //frame_top->setMinimumSize(582,279); + //frame_top->setMaximumSize(1800,279); + frame_top->setMinimumSize(582,343); + frame_top->setMaximumSize(1800,343); + } + } + else + { + if(ukccbluetoothconfig::m_isIntel) + { + //frame_top->setMinimumSize(582,153); + //frame_top->setMaximumSize(1800,153); + frame_top->setMinimumSize(582,217); + frame_top->setMaximumSize(1800,217); + } + else + { + //frame_top->setMinimumSize(582,217); + //frame_top->setMaximumSize(1800,217); + frame_top->setMinimumSize(582,279); + frame_top->setMaximumSize(1800,279); + } + } + + frame_middle = new QWidget(m_normal_main_widget); + frame_middle->setObjectName("frame_middle"); + frame_bottom = new QWidget(m_normal_main_widget); + frame_bottom->setObjectName("frame_bottom"); + frame_bottom->setMinimumWidth(582); + frame_bottom->setMaximumWidth(1800); + + main_layout->addWidget(frame_top,1,Qt::AlignTop); + main_layout->addWidget(frame_middle,1,Qt::AlignTop); + main_layout->addWidget(frame_bottom,1,Qt::AlignTop); + main_layout->addStretch(10); + + initMainWindowTopUI(); + initMainWindowMiddleUI(); + initMainWindowbottomUI(); + this->setLayout(main_layout); + _MCentralWidget->addWidget(m_normal_main_widget); +} + + +void BlueToothMain::initMainWindowTopUI() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + //~ contents_path /bluetooth/Bluetooth + TitleLabel *label_1 = new TitleLabel(frame_top); + label_1->setText(tr("Bluetooth")); + label_1->resize(100,25); + + + QVBoxLayout *top_layout = new QVBoxLayout(); + top_layout->setSpacing(8); + top_layout->setContentsMargins(0,0,0,0); + top_layout->addWidget(label_1); + + QFrame *top_frame = new QFrame(frame_top); + top_frame->setMinimumWidth(582); + top_frame->setFrameShape(QFrame::Shape::Box); + top_layout->addWidget(top_frame); + + QVBoxLayout *layout = new QVBoxLayout(top_frame); + layout->setSpacing(2); + layout->setContentsMargins(0,0,0,0); + + QFrame *frame_1 = new QFrame(top_frame); + frame_1->setMinimumWidth(582); + frame_1->setFrameShape(QFrame::Shape::Box); + frame_1->setFixedHeight(60); + frame_1->setAutoFillBackground(true); + layout->addWidget(frame_1); + + QFrame *line_frame1 = new QFrame(top_frame); + line_frame1->setFixedHeight(1); + line_frame1->setMinimumWidth(582); + line_frame1->setFrameStyle(QFrame::HLine); + layout->addWidget(line_frame1); + + QHBoxLayout *frame_1_layout = new QHBoxLayout(frame_1); + frame_1_layout->setSpacing(10); + frame_1_layout->setContentsMargins(16,0,16,0); + + //~ contents_path /bluetooth/Turn on Bluetooth + label_2 = new QLabel(tr("Turn on"),frame_1); + label_2->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + frame_1_layout->addWidget(label_2); + + bluetooth_name = new BluetoothNameLabel(frame_1,300,38); + connect(bluetooth_name,&BluetoothNameLabel::sendAdapterName,this,&BlueToothMain::setDefaultAdapterName); + connect(this,&BlueToothMain::defaultAdapterNameChanged,bluetooth_name,&BluetoothNameLabel::setLabelText); + frame_1_layout->addWidget(bluetooth_name); + frame_1_layout->addStretch(); + + m_open_bluetooth_btn = new KSwitchButton(frame_1); + connect(m_open_bluetooth_btn,SIGNAL(stateChanged(bool)),this,SLOT(onClick_Open_Bluetooth(bool))); + + frame_1_layout->addWidget(m_open_bluetooth_btn); + + line_frame2 = new QFrame(top_frame); + line_frame2->setFixedHeight(1); + line_frame2->setMinimumWidth(582); + line_frame2->setFrameStyle(QFrame::HLine); + + frame_2 = new QFrame(top_frame); + frame_2->setMinimumWidth(582); + frame_2->setFrameShape(QFrame::Shape::Box); + frame_2->setFixedHeight(60); + layout->addWidget(frame_2); + layout->addWidget(line_frame2); + if(m_adapter_address_list.size() <= 1) { + frame_2->setVisible(false); + line_frame2->setVisible(false); + } + + QHBoxLayout *frame_2_layout = new QHBoxLayout(frame_2); + frame_2_layout->setSpacing(10); + frame_2_layout->setContentsMargins(16,0,16,0); + //~ contents_path /Bluetooth/Bluetooth adapter + QLabel *label_3 = new QLabel(tr("Bluetooth adapter"),frame_2); + label_3->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + frame_2_layout->addWidget(label_3); + frame_2_layout->addStretch(); + + m_adapter_list_cmbox = new QComboBox(frame_2); + m_adapter_list_cmbox->clear(); + m_adapter_list_cmbox->setMinimumWidth(300); + m_adapter_list_cmbox->addItems(m_adapter_name_list); + //m_adapter_list_cmbox->setCurrentIndex(adapter_address_list.indexOf(m_default_adapter_address)); + m_adapter_list_cmbox->setCurrentIndex(m_adapter_name_list.indexOf(m_default_adapter_name)); + connect(m_adapter_list_cmbox,SIGNAL(currentIndexChanged(int)),this,SLOT(adapterComboxChanged(int))); + frame_2_layout->addWidget(m_adapter_list_cmbox); + + if(!ukccbluetoothconfig::m_isIntel) + { + QFrame *frame_3 = new QFrame(top_frame); + frame_3->setMinimumWidth(582); + frame_3->setFrameShape(QFrame::Shape::Box); + frame_3->setFixedHeight(60); + layout->addWidget(frame_3); + + QFrame *line_frame3 = new QFrame(top_frame); + line_frame3->setFixedHeight(1); + line_frame3->setMinimumWidth(582); + line_frame3->setFrameStyle(QFrame::HLine); + layout->addWidget(line_frame3); + + QHBoxLayout *frame_3_layout = new QHBoxLayout(frame_3); + frame_3_layout->setSpacing(10); + frame_3_layout->setContentsMargins(16,0,16,0); + + //~ contents_path /bluetooth/Show icon on taskbar + QLabel *label_4 = new QLabel(tr("Show icon on taskbar"),frame_3); + label_4->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + frame_3_layout->addWidget(label_4); + frame_3_layout->addStretch(); + + m_show_panel_btn = new KSwitchButton(frame_3); + frame_3_layout->addWidget(m_show_panel_btn); + if(m_settings) + { + m_show_panel_btn->setChecked(m_settings->get("tray-show").toBool()); + } + else + { + m_show_panel_btn->setChecked(false); + //m_show_panel_btn->setDisabledFlag(false); + } + connect(m_show_panel_btn,&KSwitchButton::stateChanged,this,&BlueToothMain::setTrayVisible); + } + + QFrame *frame_4 = new QFrame(top_frame); + frame_4->setMinimumWidth(582); + frame_4->setFrameShape(QFrame::Shape::Box); + frame_4->setFixedHeight(60); + layout->addWidget(frame_4); + + QFrame *line_frame4 = new QFrame(top_frame); + line_frame4->setFixedHeight(1); + line_frame4->setMinimumWidth(582); + line_frame4->setFrameStyle(QFrame::HLine); + layout->addWidget(line_frame4); + + QHBoxLayout *frame_4_layout = new QHBoxLayout(frame_4); + frame_4_layout->setSpacing(10); + frame_4_layout->setContentsMargins(16,0,16,0); + + //~ contents_path /bluetooth/Discoverable + QLabel *label_5 = new QLabel(tr("Discoverable by nearby Bluetooth devices"),frame_4); + label_5->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + frame_4_layout->addWidget(label_5); + frame_4_layout->addStretch(); + + m_discover_switch_btn = new KSwitchButton(frame_4); + frame_4_layout->addWidget(m_discover_switch_btn); + + //switch_discover->setChecked(m_localDevice->isDiscoverable()); + m_discover_switch_btn->setChecked(m_current_adapter_disconvery_swtich); + connect(m_discover_switch_btn,&KSwitchButton::stateChanged,this,&BlueToothMain::setDefaultAdapterDiscoverable); + + + QFrame *frame_5 = new QFrame(top_frame); + frame_5->setMinimumWidth(582); + frame_5->setFrameShape(QFrame::Shape::Box); + frame_5->setFixedHeight(60); + layout->addWidget(frame_5); + + QHBoxLayout *frame_5_layout = new QHBoxLayout(frame_5); + frame_5_layout->setSpacing(10); + frame_5_layout->setContentsMargins(16,0,16,0); + + //~ contents_path /bluetooth/Automatically discover Bluetooth audio devices + QLabel *label_6 = new QLabel(tr("Auto discover Bluetooth audio devices"),frame_5); + label_6->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + frame_5_layout->addWidget(label_6); + frame_5_layout->addStretch(); + + m_active_scan_switch_btn = new KSwitchButton(frame_5); + frame_5_layout->addWidget(m_active_scan_switch_btn); + m_active_scan_switch_btn->setChecked(m_current_active_connection_status); + connect(m_active_scan_switch_btn,&KSwitchButton::stateChanged,this,&BlueToothMain::setGSettingsActiveConnectionStatus); + + frame_top->setLayout(top_layout); + qDebug() << Q_FUNC_INFO << "end" << __LINE__; + +} + + +void BlueToothMain::initMainWindowMiddleUI() +{ + QVBoxLayout *middle_layout = new QVBoxLayout(frame_middle); + middle_layout->setSpacing(8); + middle_layout->setContentsMargins(0,0,0,0); + + + QHBoxLayout *label_layout = new QHBoxLayout(); + label_layout->setSpacing(0); + label_layout->setContentsMargins(16,0,0,0); + + TitleLabel *middle_label = new TitleLabel(frame_middle); + middle_label->setText(tr("My Devices")); + middle_label->resize(72,25); + + label_layout->addWidget(middle_label); + + QFrame *mDev_frame = new QFrame(frame_middle); + mDev_frame->setObjectName("mDev_frame"); + mDev_frame->setMinimumWidth(582); + mDev_frame->setFrameShape(QFrame::Shape::Box); + + paired_dev_layout = new QVBoxLayout(mDev_frame); + paired_dev_layout->setSpacing(2); + paired_dev_layout->setContentsMargins(0,0,0,0); + + middle_layout->addLayout(label_layout,Qt::AlignTop); + middle_layout->addWidget(mDev_frame,Qt::AlignTop); + + frame_middle->setLayout(middle_layout); +} + +void BlueToothMain::initMainWindowbottomUI() +{ + QHBoxLayout *title_layout = new QHBoxLayout(); + title_layout->setSpacing(10); + title_layout->setContentsMargins(16,0,16,0); + + TitleLabel *label_1 = new TitleLabel(frame_bottom); + //~ contents_path /bluetooth/Other Devices + label_1->setText(tr("Other Devices")); + label_1->resize(72,25); + + loadLabel = new QLabel(frame_bottom); + loadLabel->setFixedSize(18,18); + + if (!m_timer) { + m_timer = new QTimer(this); + m_timer->setInterval(100); + connect(m_timer,&QTimer::timeout,this,&BlueToothMain::refreshLoadLabelIcon); + } + + //开启时延迟1.8s后开启扫描,留点设备回连时间 + delayStartDiscover_timer = new QTimer(this); + delayStartDiscover_timer->setInterval(2000); + connect(delayStartDiscover_timer,&QTimer::timeout,this,[=] + { + qDebug() << "delay Start Discover time out:" << __LINE__; + delayStartDiscover_timer->stop(); + if (!m_current_adapter_scan_status) + { + setDefaultAdapterScanOn(true); + + //QTimer::singleShot(500,this,[=] + //{ + // if (!m_current_adapter_scan_status) + // { + // delayStartDiscover_timer->start(); + // } + //}); + } + }); + + title_layout->addWidget(label_1); + title_layout->addWidget(loadLabel); + title_layout->addStretch(); + + cacheDevTypeList = new QComboBox(frame_bottom); + cacheDevTypeList->clear(); + cacheDevTypeList->setMinimumWidth(120); + QStringList devStrList; + devStrList << tr("All"); + devStrList << tr("Audio"); + devStrList << tr("Peripherals"); + devStrList << tr("PC"); + devStrList << tr("Phone"); + devStrList << tr("Other"); + + cacheDevTypeList->addItems(devStrList); + + connect(cacheDevTypeList,SIGNAL(currentIndexChanged(int)),this,SLOT(changeListOfDiscoveredDevices(int))); + title_layout->addWidget(cacheDevTypeList); + + QVBoxLayout *bottom_layout = new QVBoxLayout(frame_bottom); + bottom_layout->setSpacing(8); + bottom_layout->setContentsMargins(0,0,0,0); + bottom_layout->addLayout(title_layout); + + device_list = new QFrame(); + device_list->setObjectName("device_list"); + device_list->setMinimumWidth(582); + device_list->setFrameShape(QFrame::Shape::Box); + device_list->setVisible(false); + + bottom_layout->addWidget(device_list); + + device_list_layout = new QVBoxLayout(device_list); + device_list_layout->setSpacing(2); + device_list_layout->setContentsMargins(0,0,0,0); + device_list_layout->setAlignment(Qt::AlignTop); + device_list->setLayout(device_list_layout); + + frame_bottom->setLayout(bottom_layout); +} + +void BlueToothMain::stopAllTimer() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + if (delayStartDiscover_timer && delayStartDiscover_timer->isActive()) + delayStartDiscover_timer->stop(); +} + +void BlueToothMain::showBluetoothErrorMainWindow() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + stopAllTimer(); + m_error_main_widget = new QWidget(_MCentralWidget); + errorWidgetLayout = new QVBoxLayout(m_error_main_widget); + errorWidgetIcon = new QLabel(m_error_main_widget); + errorWidgetTip0 = new QLabel(m_error_main_widget); + + m_error_main_widget->setObjectName("errorWidget"); + + errorWidgetLayout->setSpacing(10); + errorWidgetLayout->setMargin(0); + errorWidgetLayout->setContentsMargins(0,0,0,0); + + QPalette pe; + pe.setColor(QPalette::WindowText,"#818181"); + errorWidgetIcon->setFixedSize(54,88); + errorWidgetTip0->resize(200,30); + errorWidgetTip0->setFont(QFont("Noto Sans CJK SC",18,QFont::Medium)); + errorWidgetTip0->setPalette(pe); + if (QIcon::hasThemeIcon("bluetooth-disabled-symbolic")) { + if (isblack) + errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-disabled-symbolic").pixmap(54,88),"white")); + else + errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-disabled-symbolic").pixmap(54,88)); + } + + errorWidgetTip0->setText(tr("Bluetooth driver abnormal")); + + errorWidgetLayout->addStretch(7); + errorWidgetLayout->addWidget(errorWidgetIcon,1,Qt::AlignCenter); + errorWidgetLayout->addWidget(errorWidgetTip0,1,Qt::AlignCenter); + errorWidgetLayout->addStretch(10); + + _MCentralWidget->addWidget(m_error_main_widget); +} + + +void BlueToothMain::refreshUIWhenAdapterChanged() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + // =============清空我的设备和蓝牙发现设备栏布局下的所有设备item================= + cleanPairDevices(); + m_default_adapter_address = getDefaultAdapterAddress(); + getDefaultAdapterData(m_default_adapter_address); + // ========================END=========================================== + m_myDev_show_flag = false; + m_discovery_device_address_all_list.clear(); + + for (int i = 0 ; i < m_default_bluetooth_adapter->m_bluetooth_device_list.size(); i++) + { + if(m_default_bluetooth_adapter->m_bluetooth_device_list.at(i)->isPaired()) + addMyDeviceItemUI(m_default_bluetooth_adapter->m_bluetooth_device_list.at(i)); + else + addOneBluetoothDeviceItemUi(m_default_bluetooth_adapter->m_bluetooth_device_list.at(i)); + } + + if (m_current_adapter_scan_status) + { + if(!loadLabel->isVisible()) + loadLabel->setVisible(true); + if (!m_timer->isActive()) + m_timer->start(); + } + + //==============初始化蓝牙信息和基础信息==================================== + bluetooth_name->set_dev_name(m_default_adapter_name); + + qDebug() << Q_FUNC_INFO << "m_current_adapter_power_swtich:" << m_current_adapter_power_swtich ; + if(m_current_adapter_power_swtich) + { + if (!m_open_bluetooth_btn->isChecked()) + { + //添加标识,从蓝牙服务获取的数据 + m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(true); + } +// bluetooth_name->setVisible(true); + frame_middle->setVisible(m_myDev_show_flag); + if (!frame_bottom->isVisible() && frame_bottom->children().size()) + frame_bottom->setVisible(true); + } + else + { + if (m_open_bluetooth_btn->isChecked()) + { + //添加标识,从蓝牙服务获取的数据 + m_service_dbus_adapter_power_change_flag = true; + m_open_bluetooth_btn->setChecked(false); + } + frame_bottom->setVisible(false); + frame_middle->setVisible(false); + } + + if (m_open_bluetooth_btn->isChecked()) + { + qDebug() << Q_FUNC_INFO << "m_open_bluetooth_btn->isChecked() == " << m_open_bluetooth_btn->isChecked() << "stary discover" ; + if (delayStartDiscover_timer->isActive()) + delayStartDiscover_timer->stop(); + delayStartDiscover_timer->start(); + } + + //===========================END========================================== + qDebug() << Q_FUNC_INFO << "end" << __LINE__; + + //return ; +} + +void BlueToothMain::changeDeviceParentWindow(const QString &address) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + if(!frame_middle->isVisible()){ + frame_middle->setVisible(true); + } + + DeviceInfoItem *item = device_list->findChild(address); + QFrame *line_item = device_list->findChild("line-"+address); + if(item){ + + mDevFrameAddLineFrame("paired",address); + + device_list_layout->removeWidget(item); + item->setParent(frame_middle); + + if(line_item) { + device_list_layout->removeWidget(line_item); + line_item->setParent(NULL); + line_item->deleteLater(); + } + + //设备配对成功后,先读取设备的连接状态,设置对应的设备状态 + bool isConnect = getDevConnectStatus(address); + reportDevConnectStatusSignal(address,isConnect); + + paired_dev_layout->addWidget(item); + m_myDev_show_flag = true; + }else{ + return; + } +} + +void BlueToothMain::onClick_Open_Bluetooth(bool ischeck) +{ + qDebug() << Q_FUNC_INFO << ischeck << (dynamic_cast(sender()) == nullptr); + +// if (m_service_dbus_adapter_power_change_flag) +// disconnect(m_open_bluetooth_btn,SIGNAL(checkedChanged(bool)),nullptr,nullptr); + + if (dynamic_cast(sender()) == nullptr) + { + m_open_bluetooth_btn->setChecked(ischeck); + } + else + { + if (!m_service_dbus_adapter_power_change_flag) //不由服务发送的设置 + { + setDefaultAdapterPower(ischeck); + } + // bluetooth_name->setVisible(ischeck); + } + if(ischeck && m_myDev_show_flag) + frame_middle->setVisible(ischeck); + else + frame_middle->setVisible(false); + + frame_bottom->setVisible(ischeck); + if(ischeck && loadLabel->isVisible()) + { + loadLabel->setVisible(false); + } + + if(ischeck) + { + if(delayStartDiscover_timer->isActive()) + delayStartDiscover_timer->stop(); + delayStartDiscover_timer->start(); + } + else + { + //if (loadLabel->isVisible()) + loadLabel->setVisible(false); + if (m_timer->isActive()) + m_timer->stop(); + + stopAllTimer(); + } + + if (m_service_dbus_adapter_power_change_flag) + { + m_service_dbus_adapter_power_change_flag = false; + } + + return; +} + +bool BlueToothMain::isInvalidDevice(QString devName , bluetoothdevice::DEVICE_TYPE devType) +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + if (devName.split("-").length() == 6 && bluetoothdevice::DEVICE_TYPE::uncategorized == devType) + return true; + else + return false; +} + +void BlueToothMain::refreshLoadLabelIcon() +{ + if("normalWidget" == _MCentralWidget->currentWidget()->objectName()) + { + if(i > 7) + i = 0; + if (isblack) + loadLabel->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("ukui-loading-"+QString::number(i,10)).pixmap(18,18),"white")); + else + loadLabel->setPixmap(QIcon::fromTheme("ukui-loading-"+QString::number(i,10)).pixmap(18,18)); + + loadLabel->update(); + i++; + } +} + +void BlueToothMain::removeDeviceItemUI(QString address) +{ + qDebug() << Q_FUNC_INFO << address << __LINE__; + + //移除蓝牙设备列表的设备 + DeviceInfoItem *item = device_list->findChild(address); + QFrame *line_item = device_list->findChild("line-"+address); + if(item) + { + device_list_layout->removeWidget(item); + item->setParent(NULL); + item->deleteLater(); + + if(line_item) { + device_list_layout->removeWidget(line_item); + line_item->setParent(NULL); + line_item->deleteLater(); + } + } + else + { + qDebug() << Q_FUNC_INFO << "bluetooth device list NULL!!"<<__LINE__; + } + + //移除已配对设备列表的设备 + item = frame_middle->findChild(address); + line_item = frame_middle->findChild("line-"+address); + if(item) + { + paired_dev_layout->removeWidget(item); + item->setParent(NULL); + item->deleteLater(); + + if (line_item) { + paired_dev_layout->removeWidget(line_item); + line_item->setParent(NULL); + line_item->deleteLater(); + } else + removeMDevFrameLineFrame("paired"); + + qDebug() << Q_FUNC_INFO << "paired_dev_layout->count():" << paired_dev_layout->count() <<__LINE__; + if(!paired_dev_layout->count()){ + m_myDev_show_flag = false; + frame_middle->setVisible(false); + } + else + { + m_myDev_show_flag = true; + } + } + else + { + qDebug() << Q_FUNC_INFO << "pair list is NULL"<<__LINE__; + return; + } + + qDebug() << Q_FUNC_INFO << "remove Item UI end" <<__LINE__; + +} + + +void BlueToothMain::changeListOfDiscoveredDevices(int index) +{ + //qDebug() << Q_FUNC_INFO << index << m_discovery_device_address_all_list; + qDebug() << Q_FUNC_INFO << index << __LINE__; + discoverDevFlag = DevTypeShow(index); + + //清空列表数据 + QLayoutItem *child; + while ((child = device_list_layout->takeAt(0)) != 0) + { + if(child->widget()) + { + child->widget()->setParent(NULL); + } + + QFrame *line_item = device_list->findChild("line-"+child->widget()->objectName()); + if(line_item) { + device_list_layout->removeWidget(line_item); + line_item->setParent(NULL); + line_item->deleteLater(); + } + + delete child; + child = nullptr; + } + + device_list->setVisible(false); + + addDiscoverDevListByFlag(discoverDevFlag); +} + + +void BlueToothMain::addDiscoverDevListByFlag(BlueToothMain::DevTypeShow flag) +{ + qDebug() << Q_FUNC_INFO << flag; + for (bluetoothdevice *dev : m_default_bluetooth_adapter->m_bluetooth_device_list) + { + if (isInvalidDevice(dev->getDevName(),dev->getDevType())) + continue; + switch (flag) { + case DevTypeShow::All: + addOneBluetoothDeviceItemUi(dev); + break; + case DevTypeShow::Audio: + if (dev->getDevType() == bluetoothdevice::DEVICE_TYPE::headset || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::headphones || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::audiovideo) { + addOneBluetoothDeviceItemUi(dev); + } + break; + case DevTypeShow::Peripherals: + if (dev->getDevType() == bluetoothdevice::DEVICE_TYPE::mouse || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::keyboard) { + addOneBluetoothDeviceItemUi(dev); + } + break; + case DevTypeShow::PC: + if (dev->getDevType() == bluetoothdevice::DEVICE_TYPE::computer) { + addOneBluetoothDeviceItemUi(dev); + } + break; + case DevTypeShow::Phone: + if (dev->getDevType() == bluetoothdevice::DEVICE_TYPE::phone) { + addOneBluetoothDeviceItemUi(dev); + } + break; + case DevTypeShow::Other: + if (dev->getDevType() == bluetoothdevice::DEVICE_TYPE::headset || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::headphones || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::audiovideo || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::phone || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::mouse || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::keyboard || + dev->getDevType() == bluetoothdevice::DEVICE_TYPE::computer) + break; + else + addOneBluetoothDeviceItemUi(dev); + break; + default: + addOneBluetoothDeviceItemUi(dev); + break; + } + } +} + +void BlueToothMain::monitorSleepSignal() +{ + if (QDBusConnection::systemBus().connect("org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "PrepareForSleep", + this, + SLOT(monitorSleepSlot(bool)))){ + qDebug() << Q_FUNC_INFO << "PrepareForSleep signal connected successfully to slot"; + } else { + qDebug() << Q_FUNC_INFO << "PrepareForSleep signal connected was not successful"; + } +} + +void BlueToothMain::monitorSleepSlot(bool value) +{ + //connectBluetoothServiceSignal(); + if (!value) { + if (sleep_status) + { +// if (this->centralWidget()->objectName() == "normalWidget") +// adapterPoweredChanged(true); + } + } else { + sleep_status = m_current_adapter_power_swtich; + } +} + +void BlueToothMain::adapterPoweredChanged(bool value) +{ + qDebug() << Q_FUNC_INFO << value; +// if(m_settings) +// m_settings->set("switch",QVariant::fromValue(value)); + + if(value) + { + bluetooth_name->set_dev_name(m_default_adapter_name); + bluetooth_name->setVisible(true); + frame_bottom->setVisible(true); + + if(m_myDev_show_flag) + frame_middle->setVisible(true); + +// if(!frame_middle->isVisible()) +// { +// frame_middle->setVisible(true); +// } + if (!m_open_bluetooth_btn->isChecked()) + m_open_bluetooth_btn->setChecked(true); + + //延时2S开启扫描,给用户回连缓冲 + delayStartDiscover_timer->start(); + + } + else + { +// if (bluetooth_name->isVisible()) +// bluetooth_name->setVisible(false); + + if (m_open_bluetooth_btn->isChecked()) + m_open_bluetooth_btn->setChecked(false); + + if (frame_bottom->isVisible()) + frame_bottom->setVisible(false); + + if(frame_middle->isVisible()) + frame_middle->setVisible(false); + + if (!paired_dev_layout->isEmpty()) + m_myDev_show_flag = true ; + else + m_myDev_show_flag = false ; + } +} + +void BlueToothMain::adapterComboxChanged(int i) +{ + qDebug() << Q_FUNC_INFO << i + << m_adapter_address_list.at(i) + << m_adapter_name_list.at(i) + << m_adapter_address_list + << m_adapter_name_list; + + if(m_adapter_address_list.size() != m_adapter_name_list.size()) + return; + + if(i != -1) + { + qDebug() << Q_FUNC_INFO << "=================3" << __LINE__; + setDefaultAdapterScanOn(false); + //clearAllUnPairedDevicelist(); + + if(i < m_bluetooth_adapter_list.size()) + setDefaultAdapter(m_bluetooth_adapter_list.at(i)->getDevAddress()); + + refreshUIWhenAdapterChanged(); + }else{ + if(m_open_bluetooth_btn->isChecked()){ + qDebug() << __FUNCTION__<< "index - i : "<< i << __LINE__ ; + m_open_bluetooth_btn->setChecked(false); +#ifndef DEVICE_IS_INTEL + m_open_bluetooth_btn->setDisabledFlag(false); +#endif + } + if(frame_middle->isVisible()){ + frame_middle->setVisible(false); + } + } + qDebug() << Q_FUNC_INFO << "end"; +} + +void BlueToothMain::mDevFrameAddLineFrame(QString str,QString addr) +{ + qDebug() << Q_FUNC_INFO << "#########################" << str << addr; + + if ("paired" == str) { + + if (!frame_middle->findChildren().size()) { + return; + } + + QFrame *line_frame = new QFrame(mDev_frame); + line_frame->setObjectName("line-"+addr); + line_frame->setFixedHeight(1); + line_frame->setMinimumWidth(582); + line_frame->setFrameStyle(QFrame::HLine); + paired_dev_layout->addWidget(line_frame,Qt::AlignTop); + + } else if ("other" == str) { + + if (frame_bottom->findChildren().size() <= 1) { + return; + } + + QFrame *line_frame = new QFrame(device_list); + line_frame->setObjectName("line-"+addr); + line_frame->setFixedHeight(1); + line_frame->setMinimumWidth(582); + line_frame->setFrameStyle(QFrame::HLine); + + + if (!device_list->isVisible()) + device_list->setVisible(true); + + device_list_layout->insertWidget(0,line_frame,Qt::AlignTop); + + } else { + return; + } +} + +void BlueToothMain::removeMDevFrameLineFrame(QString str) +{ + qDebug() << Q_FUNC_INFO ; + + if ("paired" == str) { + + if ((frame_middle->findChildren().size() - frame_middle->findChildren().size() - 2) == frame_middle->findChildren().size()) { + QLayoutItem *child; + if ((child = paired_dev_layout->takeAt(0)) != 0) { + if (child->widget()->objectName().startsWith("line-")) { + + child->widget()->setParent(NULL); + + delete child; + child = nullptr; + } + } + } + } else if ("other" == str) { + + } else { + return; + } +} + +void BlueToothMain::cleanPairDevices() +{ + qDebug() << Q_FUNC_INFO << "=============111111111" ; + + QLayoutItem *child; + while ((child = paired_dev_layout->takeAt(0)) != 0) + { + qDebug() << Q_FUNC_INFO << __LINE__; + if(child->widget()) + { + child->widget()->setParent(NULL); + } + paired_dev_layout->removeItem(child); + + QFrame *line_item = frame_middle->findChild("line-"+child->widget()->objectName()); + if(line_item) { + paired_dev_layout->removeWidget(line_item); + line_item->setParent(NULL); + line_item->deleteLater(); + }else + removeMDevFrameLineFrame("paired"); + + delete child; + child = nullptr; + } + qDebug() << Q_FUNC_INFO << "=============22222222" ; + + while ((child = device_list_layout->takeAt(0)) != 0) + { + qDebug() << Q_FUNC_INFO << __LINE__; + if(child->widget()) + { + child->widget()->setParent(NULL); + } + device_list_layout->removeItem(child); + + QFrame *line_item = device_list->findChild("line-"+child->widget()->objectName()); + if(line_item) { + device_list_layout->removeWidget(line_item); + line_item->setParent(NULL); + line_item->deleteLater(); + } + + delete child; + child = nullptr; + + + } + //device_list->setVisible(false); + qDebug() << Q_FUNC_INFO << "=============33333333" ; + +} + +void BlueToothMain::gSettingsChanged(const QString &key) +{ + if ("styleName" == key) { + if(styleSettings->get("style-name").toString() == "ukui-black" || + styleSettings->get("style-name").toString() == "ukui-dark") + isblack = true; + else + isblack = false; + + if (isblack) + errorWidgetIcon->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("bluetooth-disabled-symbolic").pixmap(54,88),"white")); + else + errorWidgetIcon->setPixmap(QIcon::fromTheme("bluetooth-disabled-symbolic").pixmap(54,88)); + } +} + +void BlueToothMain::gSettingsBluetoothChanged(const QString &key) +{ + qDebug()<< Q_FUNC_INFO << key <<__LINE__; + + if (GSETTING_STR_ACTIVE_CONNECTION_TRAN == key || GSETTING_STR_ACTIVE_CONNECTION == key) + { + m_current_active_connection_status = m_settings->get(GSETTING_STR_ACTIVE_CONNECTION).toBool(); + m_active_scan_switch_btn->setChecked(m_current_active_connection_status); + qDebug()<< Q_FUNC_INFO << "m_current_active_connection_status:" + << m_current_active_connection_status; + + } +} + +void BlueToothMain::setGSettingsActiveConnectionStatus(bool state) +{ + qDebug() << Q_FUNC_INFO << "set curr state:" << state << __LINE__; + m_settings->set(GSETTING_STR_ACTIVE_CONNECTION,QVariant(state)); + qInfo() << Q_FUNC_INFO << m_settings->keys(); +} +//add function before diff --git a/ukcc-bluetooth/bluetoothmain.h b/ukcc-bluetooth/bluetoothmain.h new file mode 100644 index 0000000..7f32599 --- /dev/null +++ b/ukcc-bluetooth/bluetoothmain.h @@ -0,0 +1,283 @@ +#ifndef BLUETOOTHMAIN_H +#define BLUETOOTHMAIN_H + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "devicebase.h" +#include "deviceinfoitem.h" +#include "bluetoothnamelabel.h" +#include "ukccbluetoothconfig.h" +#include "bluetoothdbusservice.h" + +#include "kswitchbutton.h" +using namespace kdk; + +#define GSETTING_STR_ACTIVE_CONNECTION "active-connection" +#define GSETTING_STR_ACTIVE_CONNECTION_TRAN "activeConnection" + +class BlueToothMain : public QMainWindow +{ + Q_OBJECT +public: + enum DevTypeShow { + All = 0, + Audio, + Peripherals, + PC, + Phone, + Other, + }; + Q_ENUM(DevTypeShow) + + BlueToothMain(QWidget *parent = nullptr); + ~BlueToothMain(); +protected: + void leaveEvent(QEvent *event); + +//dev-3.1 界面服务分离 + +public: + static bool m_device_operating ; + static QString m_device_operating_address ; + + static bool m_device_pin_flag ; + void setbluetoothAdapterDiscoveringStatus(bool); +signals: + void sendAdapterNameChangeSignal(const QString &value); + void defaultAdapterNameChanged(const QString &name); + +private slots: + //report + void reportDefaultAdapterChanged(QString); + void reportDefaultAdapterNameChanged(QString); + void reportAdapterAddSignal(QString ); + void reportAdapterRemoveSignal(QString); + void reportDefaultAdapterPowerChanged(bool); + void reportDefaultDiscoverableChanged(bool); + void reportDefaultScanStatusChanged(bool); + void reportDeviceScanResult(QString,QString,QString,bool); + + void reportDevRemoveSignal(QString); + void reportDevPairSignal(QString,bool); + void reportDevConnectStatusSignal(QString,bool); + void reportDevNameChangedSignal(QString,QString); + void reportDevTypeChangedSignal(QString,QString); + void reportRequestConfirmation(QString,QString); + void reportReplyRequestConfirmation(bool); + void reportDevOperateErrorSignal(QString,int,QString); + + void reportDevMacAddressChangedSignal(QString,QString); + + //receive + void receiveConnectsignal(QString); + void receiveDisConnectSignal(QString); + void receiveRemoveSignal(QString); + + //gsetting + void setTrayVisible(bool); + void onClick_Open_Bluetooth(bool); + + void changeDeviceParentWindow(const QString &address); + void refreshLoadLabelIcon(); + + void monitorSleepSlot(bool value); + void changeListOfDiscoveredDevices(int); + void receiveSendFileSignal(QString); + void gSettingsChanged(const QString &); + void adapterPoweredChanged(bool value); + void adapterComboxChanged(int i); + + void gSettingsBluetoothChanged(const QString &); + +private: + QStackedWidget * _MCentralWidget = nullptr; + + QWidget * frame_top = nullptr; + QWidget * frame_middle = nullptr; + QWidget * frame_bottom = nullptr; + QWidget * m_normal_main_widget = nullptr; + QWidget * m_error_main_widget = nullptr; + QVBoxLayout * errorWidgetLayout = nullptr; + QLabel * errorWidgetIcon = nullptr; + QLabel * errorWidgetTip0 = nullptr; + QFrame * line_frame2 = nullptr; + QFrame * mDev_frame = nullptr; + + QFrame * device_list = nullptr; + //QWidget * paired_device_list = nullptr; + QVBoxLayout * device_list_layout = nullptr; + BluetoothNameLabel * bluetooth_name = nullptr; + + QVBoxLayout * paired_dev_layout = nullptr; + QVBoxLayout * main_layout = nullptr; + QFrame * frame_2 = nullptr; + QComboBox * cacheDevTypeList = nullptr; + QLabel * label_2 = nullptr; + QLabel * loadLabel = nullptr; + + //QString Default_Adapter; + QGSettings * m_settings = nullptr; + QGSettings * styleSettings = nullptr; + + int i = 7; + bool sleep_status = false; + bool m_myDev_show_flag = false; + bool isblack = false; + + + bool m_service_dbus_adapter_power_change_flag = false; + + bool m_current_adapter_power_swtich; + bool m_current_adapter_disconvery_swtich; + bool m_current_bluetooth_block_status; + bool m_current_adapter_scan_status; //正在扫描:true,否则false + bool m_current_active_connection_status = false; + + QString m_default_adapter_name; + QString m_default_adapter_address; + + QStringList m_adapter_name_list; + QStringList m_adapter_address_list; + + QStringList last_discovery_device_address; + QStringList m_discovery_device_address_all_list; //所有device mac list + //QStringList m_discovery_device_address_effective_list; //有效device mac list + //QStringList m_paired_device_address_list; //已配对device mac list + //QStringList m_paired_device_name_list; + + //QWidget * m_all_device_list = nullptr; + //QWidget * m_audio_device_list = nullptr; // include : + //QWidget * m_other_device_list = nullptr; + + KSwitchButton * m_open_bluetooth_btn = nullptr; + KSwitchButton * m_show_panel_btn = nullptr; + KSwitchButton * m_discover_switch_btn = nullptr; + KSwitchButton * m_active_scan_switch_btn = nullptr; + + QComboBox * m_adapter_list_cmbox = nullptr; + QComboBox * m_cache_dev_type_list_cmbox = nullptr; + + bluetoothadapter * m_default_bluetooth_adapter = nullptr ; + QList m_bluetooth_adapter_list; + //QList m_bluetooth_device_list; + + DevTypeShow discoverDevFlag = DevTypeShow::All; + + QTimer * m_timer = nullptr; + QTimer * delayStartDiscover_timer = nullptr; + +private: + void mDevFrameAddLineFrame(QString,QString); + void removeMDevFrameLineFrame(QString); + void monitorBluetoothDbusConnection(); + void removeDeviceItemUI(QString address); + void addMyDeviceItemUI(bluetoothdevice *); + void monitorSleepSignal(); + void cleanPairDevices(); + void addDiscoverDevListByFlag(DevTypeShow); + + //get adapter data + void connectBluetoothServiceSignal(); + void getAllAdapterData(); + void getDefaultAdapterData(QString); + QStringList getAdapterDevAddressList(); + QStringList getAdapterDevNameList(); + + QString getDefaultAdapterAddress(); + QString getAdapterName(QString); + + bool getBluetoothBlock(); + bool getDefaultAdapterPower(); + bool getDefaultAdapterDiscoverable(); + bool getDefaultAdapterScanStatus(); + + QStringList getDefaultAdapterCacheDevAddress(); + QString getDevName(QString); + bluetoothdevice::DEVICE_TYPE getDeviceType(QString,QString); + QString getDevType(QString); + bool getDevPairStatus(QString); + bool getDevConnectStatus(QString); + bool getDevSupportFileSend(QString); + void clearAllUnPairedDevicelist(); + //QStringList getAdapterNameList(); + + void setBluetoothBlock(bool); + void setDefaultAdapterPower(bool); + void setDefaultAdapter(QString); + void setDefaultAdapterName(QString); + void setDefaultAdapterDiscoverable(bool); + void setDefaultAdapterScanOn(bool); + + // + void showBluetoothNormalMainWindow(); + void initMainWindowTopUI(); + void initMainWindowMiddleUI(); + void initMainWindowbottomUI(); + + void showBluetoothErrorMainWindow(); + + void refreshUIWhenAdapterChanged(); + void refreshBluetoothAdapterInterfaceUI(); + bool isInvalidDevice(QString , bluetoothdevice::DEVICE_TYPE); + + bluetoothdevice * createOneBluetoothDeviceFromMacAddress(QString); + bluetoothdevice * createOneBluetoothDeviceFromBluetoothService(QString,QString,QString,bool); + bluetoothadapter * createOneBluetoothAdapter(QString); + bool whetherToAddCurrentInterface(bluetoothdevice *); + void addOneBluetoothDeviceItemUi(bluetoothdevice *); + + void addAdapterDataList(QString); + void removeAdapterDataList(QString); + void stopAllTimer(); + + void setGSettingsActiveConnectionStatus(bool); +}; + +#endif // BLUETOOTHMAIN_H diff --git a/ukcc-bluetooth/bluetoothmainwindow.cpp b/ukcc-bluetooth/bluetoothmainwindow.cpp new file mode 100644 index 0000000..cfdfec2 --- /dev/null +++ b/ukcc-bluetooth/bluetoothmainwindow.cpp @@ -0,0 +1,317 @@ +#include "bluetoothmainwindow.h" +#include + +BlueToothMainWindow::BlueToothMainWindow(QWidget *parent): + QMainWindow(parent) +{ + InitMainWindow(); +} + +BlueToothMainWindow::~BlueToothMainWindow() +{ + +} + +void BlueToothMainWindow::InitMainWindow() +{ + _MCentralWidget = new QStackedWidget(this); + this->setCentralWidget(_MCentralWidget); + + InitError0Widget(); + InitError1Widget(); + InitNormalWidget(); + + _MCentralWidget->setCurrentIndex(2); +} + +void BlueToothMainWindow::InitError0Widget() +{ + _MError0Widget = new QWidget(_MCentralWidget); + QVBoxLayout *errorWidgetLayout = new QVBoxLayout(_MError0Widget); + QLabel *errorWidgetIcon = new QLabel(_MError0Widget); + QLabel *errorWidgetTip = new QLabel(_MError0Widget); + + _MError0Widget->setObjectName("error0Widget"); + + errorWidgetLayout->setSpacing(10); + errorWidgetLayout->setMargin(0); + errorWidgetLayout->setContentsMargins(0,0,0,0); + + errorWidgetIcon->setFixedSize(56,56); + errorWidgetTip->resize(200,30); + errorWidgetTip->setFont(QFont("Noto Sans CJK SC",18,QFont::Bold)); + + errorWidgetLayout->addStretch(10); + + if (QIcon::hasThemeIcon("dialog-warning")) { + errorWidgetIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(56,56)); + errorWidgetLayout->addWidget(errorWidgetIcon,1,Qt::AlignCenter); + } + + errorWidgetTip->setText(tr("Bluetooth adapter is abnormal !")); + errorWidgetLayout->addWidget(errorWidgetTip,1,Qt::AlignCenter); + errorWidgetLayout->addStretch(10); + + _MCentralWidget->addWidget(_MError0Widget); +} + +void BlueToothMainWindow::InitError1Widget() +{ + _MError1Widget = new QWidget(_MCentralWidget); + QVBoxLayout *errorWidgetLayout = new QVBoxLayout(_MError1Widget); + QLabel *errorWidgetIcon = new QLabel(_MError1Widget); + QLabel *errorWidgetTip = new QLabel(_MError1Widget); + + _MError1Widget->setObjectName("error1Widget"); + + errorWidgetLayout->setSpacing(10); + errorWidgetLayout->setMargin(0); + errorWidgetLayout->setContentsMargins(0,0,0,0); + + errorWidgetIcon->setFixedSize(56,56); + errorWidgetTip->resize(200,30); + errorWidgetTip->setFont(QFont("Noto Sans CJK SC",18,QFont::Bold)); + + errorWidgetLayout->addStretch(10); + + if (QIcon::hasThemeIcon("dialog-warning")) { + errorWidgetIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(56,56)); + errorWidgetLayout->addWidget(errorWidgetIcon,1,Qt::AlignCenter); + } + + errorWidgetTip->setText(tr("Bluetooth adapter not detected !")); + errorWidgetLayout->addWidget(errorWidgetTip,1,Qt::AlignCenter); + errorWidgetLayout->addStretch(10); + + _MCentralWidget->addWidget(_MError1Widget); +} + +void BlueToothMainWindow::InitNormalWidget() +{ + _MNormalWidget = new QWidget(_MCentralWidget); + _MNormalWidget->setObjectName("normalWidget"); + + _NormalWidgetMainLayout = new QVBoxLayout(_MNormalWidget); + _NormalWidgetMainLayout->setSpacing(40); + _NormalWidgetMainLayout->setContentsMargins(0,0,30,10); + + _MNormalWidgetTop = new QWidget(_MNormalWidget); + _MNormalWidgetTop->setObjectName("NormalWidgetTop"); + _MNormalWidgetTop->setMinimumSize(582,239); + _MNormalWidgetTop->setMaximumSize(1000,239); +// _MNormalWidgetTop->setStyleSheet("background:red;"); + + _MNormalWidgetTopMiddle = new QWidget(_MNormalWidget); + _MNormalWidgetTopMiddle->setObjectName("NormalWidgetTopMiddle"); + + _MNormalWidgetTopBottom = new QWidget(_MNormalWidget); + _MNormalWidgetTopBottom->setObjectName("frame_bottom"); + _MNormalWidgetTopBottom->setMinimumWidth(582); + _MNormalWidgetTopBottom->setMaximumWidth(1000); +// _MNormalWidgetTopBottom->setStyleSheet("background:white;"); + + InitNormalWidgetTop(); + InitNormalWidgetMiddle(); + InitNormalWidgetBottom(); + + _NormalWidgetMainLayout->addWidget(_MNormalWidgetTop,1,Qt::AlignTop); + _NormalWidgetMainLayout->addWidget(_MNormalWidgetTopMiddle,1,Qt::AlignTop); + _NormalWidgetMainLayout->addWidget(_MNormalWidgetTopBottom,1,Qt::AlignTop); + _NormalWidgetMainLayout->addStretch(10); + + _MCentralWidget->addWidget(_MNormalWidget); +} + +void BlueToothMainWindow::InitNormalWidgetTop() +{ + QVBoxLayout *NormalWidgetTopLayout = new QVBoxLayout(_MNormalWidgetTop); + NormalWidgetTopLayout->setSpacing(10); + NormalWidgetTopLayout->setContentsMargins(0,0,0,0); + + TitleLabel *label_1 = new TitleLabel(_MNormalWidgetTop); + label_1->setText(tr("Bluetooth")); + label_1->resize(100,25); + + NormalWidgetTopLayout->addWidget(label_1,1,Qt::AlignTop); + + QVBoxLayout *NormalWidgetFrameLayout = new QVBoxLayout(_MNormalWidgetTop); + NormalWidgetFrameLayout->setSpacing(2); + NormalWidgetFrameLayout->setContentsMargins(0,0,0,0); + + NormalWidgetTopLayout->addLayout(NormalWidgetFrameLayout); + + //================================ init BtSwitchFrame ======================================= + QFrame *BtSwitchFrame = new QFrame(_MNormalWidgetTop); + BtSwitchFrame->setMinimumWidth(582); + BtSwitchFrame->setFrameShape(QFrame::Shape::Box); + BtSwitchFrame->setFixedHeight(50); + BtSwitchFrame->setAutoFillBackground(true); + NormalWidgetFrameLayout->addWidget(BtSwitchFrame,1,Qt::AlignTop); + + QHBoxLayout *BtSwitchFrameLayout = new QHBoxLayout(BtSwitchFrame); + BtSwitchFrameLayout->setSpacing(0); + BtSwitchFrameLayout->setContentsMargins(16,0,16,0); + + QLabel *label_2 = new QLabel(tr("Turn on :"),BtSwitchFrame); + label_2->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + BtSwitchFrameLayout->addWidget(label_2,1,Qt::AlignLeft); + + _BtNameLabel = new BluetoothNameLabel(BtSwitchFrame,300,38); + BtSwitchFrameLayout->addWidget(_BtNameLabel,1,Qt::AlignLeft); + + _BtSwitchBtn = new SwitchButton(BtSwitchFrame); + BtSwitchFrameLayout->addStretch(10); + BtSwitchFrameLayout->addWidget(_BtSwitchBtn); + //================================ end init BtSwitchFrame ======================================= + + + //================================ init BtAdapterListFrame =========================================== + QFrame *BtAdapterListFrame = new QFrame(_MNormalWidgetTop); + BtAdapterListFrame->setMinimumWidth(582); + BtAdapterListFrame->setFrameShape(QFrame::Shape::Box); + BtAdapterListFrame->setFixedHeight(50); + BtAdapterListFrame->setAutoFillBackground(true); + NormalWidgetFrameLayout->addWidget(BtAdapterListFrame,1,Qt::AlignTop); + + QHBoxLayout *BtAdapterListFrameLayout = new QHBoxLayout(BtAdapterListFrame); + BtAdapterListFrameLayout->setSpacing(0); + BtAdapterListFrameLayout->setContentsMargins(16,0,16,0); + + QLabel *label_3 = new QLabel(tr("Adapter List"),BtAdapterListFrame); + label_3->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + BtAdapterListFrameLayout->addWidget(label_3); + + _AdapterListSelect = new QComboBox(BtAdapterListFrame); + _AdapterListSelect->clear(); + _AdapterListSelect->setMinimumWidth(300); + BtAdapterListFrameLayout->addWidget(_AdapterListSelect); + //================================ end init BtAdapterListFrame ======================================= + + + //================================ init BtTrayIconShowFrame =========================================== + QFrame *BtTrayIconShowFrame = new QFrame(_MNormalWidgetTop); + BtTrayIconShowFrame->setMinimumWidth(582); + BtTrayIconShowFrame->setFrameShape(QFrame::Shape::Box); + BtTrayIconShowFrame->setFixedHeight(50); + BtTrayIconShowFrame->setAutoFillBackground(true); + NormalWidgetFrameLayout->addWidget(BtTrayIconShowFrame,1,Qt::AlignTop); + + QHBoxLayout *BtTrayIconShowFrameLayout = new QHBoxLayout(BtTrayIconShowFrame); + BtTrayIconShowFrameLayout->setSpacing(0); + BtTrayIconShowFrameLayout->setContentsMargins(16,0,16,0); + + QLabel *label_4 = new QLabel(tr("Show icon on taskbar"),BtTrayIconShowFrame); + label_4->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + BtTrayIconShowFrameLayout->addWidget(label_4); + + + _BtTrayIconShow = new SwitchButton(BtTrayIconShowFrame); + BtTrayIconShowFrameLayout->addWidget(_BtTrayIconShow); + //================================ end init BtTrayIconShowFrame ======================================= + + + //================================ init BtDiscoverableFrame =========================================== + QFrame *BtDiscoverableFrame = new QFrame(_MNormalWidgetTop); + BtDiscoverableFrame->setMinimumWidth(582); + BtDiscoverableFrame->setFrameShape(QFrame::Shape::Box); + BtDiscoverableFrame->setFixedHeight(50); + BtDiscoverableFrame->setAutoFillBackground(true); + NormalWidgetFrameLayout->addWidget(BtDiscoverableFrame,1,Qt::AlignTop); + + QHBoxLayout *BtDiscoverableFrameLayout = new QHBoxLayout(BtDiscoverableFrame); + BtDiscoverableFrameLayout->setSpacing(0); + BtDiscoverableFrameLayout->setContentsMargins(16,0,16,0); + + QLabel *label_5 = new QLabel(tr("Discoverable by nearby Bluetooth devices"),BtDiscoverableFrame); + label_5->setStyleSheet("QLabel{\ + width: 56px;\ + height: 20px;\ + font-weight: 400;\ + line-height: 20px;}"); + BtDiscoverableFrameLayout->addWidget(label_5); + + + _BtDiscoverable = new SwitchButton(BtDiscoverableFrame); + BtDiscoverableFrameLayout->addWidget(_BtDiscoverable); + //================================ end init BtDiscoverableFrame ======================================= + + NormalWidgetTopLayout->addStretch(10); +} + +void BlueToothMainWindow::InitNormalWidgetMiddle() +{ + QVBoxLayout *NormalWidgetMiddleLayout = new QVBoxLayout(_MNormalWidgetTopMiddle); + NormalWidgetMiddleLayout->setSpacing(10); + NormalWidgetMiddleLayout->setContentsMargins(0,0,0,0); + + _NormalWidgetPairedDevLayout = new QVBoxLayout(); + _NormalWidgetPairedDevLayout->setSpacing(2); + _NormalWidgetPairedDevLayout->setContentsMargins(0,0,0,0); + + TitleLabel *middle_label = new TitleLabel(_MNormalWidgetTopMiddle); + middle_label->setText(tr("My Devices")); + middle_label->resize(72,25); + + NormalWidgetMiddleLayout->addWidget(middle_label,Qt::AlignTop); + NormalWidgetMiddleLayout->addLayout(_NormalWidgetPairedDevLayout,Qt::AlignTop); +} + +void BlueToothMainWindow::InitNormalWidgetBottom() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QVBoxLayout *_MNormalWidgetTopBottomLayout = new QVBoxLayout(_MNormalWidgetTopBottom); + _MNormalWidgetTopBottomLayout->setSpacing(10); + _MNormalWidgetTopBottomLayout->setContentsMargins(0,0,0,0); + + QHBoxLayout *titleLayout = new QHBoxLayout(_MNormalWidgetTopBottom); + titleLayout->setSpacing(10); + titleLayout->setContentsMargins(0,0,0,0); + + //~ contents_path /bluetooth/Other Devices + TitleLabel *label_1 = new TitleLabel(_MNormalWidgetTopBottom); + label_1->setText(tr("Other Devices")); + label_1->resize(72,25); + titleLayout->addWidget(label_1, 1, Qt::AlignLeft); + + _LoadIcon = new LoadingLabel(_MNormalWidgetTopBottom); + _LoadIcon->setFixedSize(24,24); + _LoadIcon->setTimerStart(); + titleLayout->addWidget(_LoadIcon, 1, Qt::AlignLeft); + + _AdapterListSelect = new QComboBox(_MNormalWidgetTopBottom); + _AdapterListSelect->clear(); + _AdapterListSelect->setMinimumWidth(120); + _AdapterListSelect->addItem(tr("All")); + _AdapterListSelect->addItem(tr("Audio")); + _AdapterListSelect->addItem(tr("Peripherals")); + _AdapterListSelect->addItem(tr("PC")); + _AdapterListSelect->addItem(tr("Phone")); + _AdapterListSelect->addItem(tr("Other")); + titleLayout->addStretch(10); + titleLayout->addWidget(_AdapterListSelect, 1, Qt::AlignRight); + + _NormalWidgetCacheDevLayout = new QVBoxLayout(_MNormalWidgetTopBottom); + _NormalWidgetCacheDevLayout->setSpacing(2); + _NormalWidgetCacheDevLayout->setContentsMargins(0,0,0,0); + _NormalWidgetCacheDevLayout->setAlignment(Qt::AlignTop); + + _MNormalWidgetTopBottomLayout->addLayout(titleLayout); + _MNormalWidgetTopBottomLayout->addLayout(_NormalWidgetCacheDevLayout); +} + +void BlueToothMainWindow::InitInterfaceUIStatus() +{ + +} diff --git a/ukcc-bluetooth/bluetoothmainwindow.h b/ukcc-bluetooth/bluetoothmainwindow.h new file mode 100644 index 0000000..61e6f74 --- /dev/null +++ b/ukcc-bluetooth/bluetoothmainwindow.h @@ -0,0 +1,77 @@ +#ifndef BLUETOOTHMAINWINDOW_H +#define BLUETOOTHMAINWINDOW_H + +#include + +#include "bluetoothnamelabel.h" +#include "loadinglabel.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kswitchbutton.h" +using namespace kdk; + +class BlueToothMainWindow : public QMainWindow +{ + Q_OBJECT +public: + enum DEVTYPESHOW { + All = 0, + Audio, + Peripherals, + Computer, + Phone, + Other, + }; + Q_ENUM(DEVTYPESHOW); + + explicit BlueToothMainWindow(QWidget *parent = nullptr); + ~BlueToothMainWindow(); +protected: + void InitMainWindow(); + void InitError0Widget(); + void InitError1Widget(); + void InitNormalWidget(); + void InitNormalWidgetTop(); + void InitNormalWidgetMiddle(); + void InitNormalWidgetBottom(); + + void InitInterfaceUIStatus(); + +private: + QStackedWidget *_MCentralWidget = nullptr; + QWidget *_MError0Widget = nullptr; + QWidget *_MError1Widget = nullptr; + QWidget *_MNormalWidget = nullptr; + + QVBoxLayout *_NormalWidgetMainLayout = nullptr; + QVBoxLayout *_NormalWidgetPairedDevLayout = nullptr; + QVBoxLayout *_NormalWidgetCacheDevLayout = nullptr; + + QWidget *_MNormalWidgetTop = nullptr; + QWidget *_MNormalWidgetTopMiddle = nullptr; + QWidget *_MNormalWidgetTopBottom = nullptr; + QWidget *_CacheDevWidget = nullptr; + + SwitchButton *_BtSwitchBtn = nullptr; + SwitchButton *_BtTrayIconShow = nullptr; + LoadingLabel *_LoadIcon = nullptr; + SwitchButton *_BtDiscoverable = nullptr; + BluetoothNameLabel *_BtNameLabel = nullptr; + QComboBox *_AdapterListSelect = nullptr; + QComboBox *_DevTypeSelect = nullptr; +}; + +#endif // BLUETOOTHMAINWINDOW_H diff --git a/ukcc-bluetooth/bluetoothnamelabel.cpp b/ukcc-bluetooth/bluetoothnamelabel.cpp new file mode 100644 index 0000000..d4d0aff --- /dev/null +++ b/ukcc-bluetooth/bluetoothnamelabel.cpp @@ -0,0 +1,251 @@ +#include "bluetoothnamelabel.h" + +#include "devrenamedialog.h" + +BluetoothNameLabel::BluetoothNameLabel(QWidget *parent, int x, int y): + QWidget(parent) +{ + this->setAutoFillBackground(true); + this->setObjectName("BluetoothNameLabel"); + this->setStyleSheet("QWidget{border: none;border-radius:2px;}"); + this->setFixedSize(x,y); + hLayout = new QHBoxLayout(this); + hLayout->setContentsMargins(5,0,5,0); + hLayout->setSpacing(0); + + m_label = new QLabel(this); + m_label->resize(10,10); + m_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); + + hLayout->addWidget(m_label); + icon_pencil = new QLabel(this); + icon_pencil->setGeometry(this->width()-200,2,43,this->height()-3); + icon_pencil->setPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20)); + icon_pencil->setToolTip(tr("Click to change the device name")); + hLayout->addWidget(icon_pencil); + hLayout->addStretch(1); + + m_lineedit = new QLineEdit(this); + m_lineedit->setEchoMode(QLineEdit::Normal); + //m_lineedit->setAlignment(Qt::AlignCenter); + m_lineedit->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); + connect(m_lineedit,&QLineEdit::editingFinished,this,&BluetoothNameLabel::LineEdit_Input_Complete); + m_lineedit->setGeometry(2,2,this->width()-3,this->height()-3); + m_lineedit->setVisible(false); + + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + settings = new QGSettings("org.ukui.style"); + if(settings->get("style-name").toString() == "ukui-black" || settings->get("style-name").toString() == "ukui-dark") + { + style_flag = true; + icon_pencil->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20),"white")); + } + else + { + style_flag = false; + icon_pencil->setPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20)); + } + switch (settings->get("system-font-size").toInt()) { + case 11: + case 12: + case 13: + font_width = 100; + break; + case 14: + font_width = 70; + break; + case 15: + case 16: + font_width = 50; + break; + default: + break; + } + qDebug() << Q_FUNC_INFO << connect(settings,&QGSettings::changed,this,&BluetoothNameLabel::settings_changed); + } +} + +BluetoothNameLabel::~BluetoothNameLabel() +{ + +} + +void BluetoothNameLabel::set_dev_name(const QString &dev_name) +{ + QFont ft; + QFontMetrics fm(ft); + //QString text = fm.elidedText(dev_name, Qt::ElideMiddle, font_width); + QString text = fm.elidedText(dev_name, Qt::ElideMiddle, this->width()); + //m_label->setText(tr("Can now be found as \"%1\"").arg(text)); + m_label->setText(text); + m_label->setToolTip(tr("Can now be found as \"%1\"").arg(dev_name)); + //m_label->adjustSize(); + m_label->update(); + + device_name = dev_name; +} + +void BluetoothNameLabel::dev_name_limit_fun() +{ + if (!messagebox) { + messagebox = new QMessageBox(QMessageBox::NoIcon, + tr("Tip"), + tr("The length of the device name does not exceed %1 characters !").arg(QString::number(DEVNAMELENGTH)), + QMessageBox::Ok); + + if (messagebox->exec() == QMessageBox::Ok || messagebox->exec() == QMessageBox::Close) { + setLabelText(device_name); + delete messagebox; + messagebox = NULL; + } + } +} +void BluetoothNameLabel::mousePressEvent(QMouseEvent *event) +{ + Q_UNUSED(event); + +// m_label->setVisible(false); +// icon_pencil->setVisible(false); + +// m_lineedit->setText(device_name); +// m_lineedit->setVisible(true); +// m_lineedit->setFocus(); + + DevRenameDialog *renameDialog = new DevRenameDialog(); + renameDialog->setDevName(device_name); + + connect(renameDialog,&DevRenameDialog::nameChanged,this,[=](QString name){ + m_label->setText(name); + device_name = name; + emit sendAdapterName(name); + }); + + renameDialog->exec(); +} + +void BluetoothNameLabel::mouseDoubleClickEvent(QMouseEvent *event) +{ + Q_UNUSED(event); + +// m_label->setVisible(false); +// icon_pencil->setVisible(false); + +// m_lineedit->setText(device_name); +// m_lineedit->setVisible(true); +// m_lineedit->setFocus(); + + DevRenameDialog *renameDialog = new DevRenameDialog(); + renameDialog->setDevName(device_name); + + connect(renameDialog,&DevRenameDialog::nameChanged,this,[=](QString name){ + m_label->setText(name); + device_name = name; + emit sendAdapterName(name); + }); + + renameDialog->exec(); +} + +void BluetoothNameLabel::leaveEvent(QEvent *event) +{ + Q_UNUSED(event); + + if(!m_lineedit->isVisible()) + this->setStyleSheet("QWidget{border:none;border-radius:2px;}"); +} + +void BluetoothNameLabel::enterEvent(QEvent *event) +{ + Q_UNUSED(event); +// QPalette palette; +// palette.setColor(QPalette::Background, QColor(Qt::white)); +// this->setPalette(palette); +// this->update(); + + if(style_flag) + this->setStyleSheet("QWidget#BluetoothNameLabel{background-color:black;border:none;border-radius:2px;}"); + else + this->setStyleSheet("QWidget#BluetoothNameLabel{background-color:white;border:none;border-radius:2px;}"); +} + +void BluetoothNameLabel::LineEdit_Input_Complete() +{ + qDebug() << Q_FUNC_INFO; + if (m_lineedit->text().isEmpty()) + { + m_lineedit->setText(device_name); + m_lineedit->update(); + this->setStyleSheet("QWidget{border:none;border-radius:2px;}"); + } + + if(device_name == m_lineedit->text()){ + setLabelText(device_name); + }else{ + if (m_lineedit->text().length() > DEVNAMELENGTH) { + dev_name_limit_fun(); + } else { + device_name = m_lineedit->text(); + emit this->sendAdapterName(m_lineedit->text()); + } + } + this->setStyleSheet("QWidget{border:none;border-radius:2px;}"); +} + +void BluetoothNameLabel::setLabelText(const QString &value) +{ + m_lineedit->setVisible(false); + + QFont ft; + QFontMetrics fm(ft); + //QString text = fm.elidedText(m_lineedit->text(), Qt::ElideMiddle, font_width); + QString text = fm.elidedText(value, Qt::ElideMiddle, this->width()); + //m_label->setText(tr("Can now be found as \"%1\"").arg(text)); + m_label->setText(text); + m_label->setToolTip(tr("Can now be found as \"%1\"").arg(device_name)); + + m_label->setVisible(true); + icon_pencil->setVisible(true); +} + +void BluetoothNameLabel::settings_changed(const QString &key) +{ + qDebug() << Q_FUNC_INFO <get("style-name").toString() == "ukui-black" || settings->get("style-name").toString() == "ukui-dark") + { + style_flag = true; + icon_pencil->setPixmap(ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20),"white")); + } + else + { + style_flag = false; + icon_pencil->setPixmap(QIcon::fromTheme("document-edit-symbolic").pixmap(20,20)); + } + }else if(key == "systemFontSize"){ + QFont ft; + ft.setPixelSize(settings->get("systemFontSize").toInt()); + switch (settings->get("systemFontSize").toInt()) { + case 11: + case 12: + case 13: + font_width = 100; + break; + case 14: + font_width = 70; + break; + case 15: + case 16: + font_width = 50; + break; + default: + break; + } + QFontMetrics fm(ft); + //QString text = fm.elidedText(device_name, Qt::ElideMiddle, font_width); + QString text = fm.elidedText(device_name, Qt::ElideMiddle,this->width()); + m_label->setText(text); + //m_label->setText(tr("Can now be found as \"%1\"").arg(text)); + m_label->setVisible(true); + icon_pencil->setVisible(true); + } +} diff --git a/ukcc-bluetooth/bluetoothnamelabel.h b/ukcc-bluetooth/bluetoothnamelabel.h new file mode 100644 index 0000000..e5d0d5c --- /dev/null +++ b/ukcc-bluetooth/bluetoothnamelabel.h @@ -0,0 +1,58 @@ +#ifndef BLUETOOTHNAMELABEL_H +#define BLUETOOTHNAMELABEL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEVNAMELENGTH 30 + +class BluetoothNameLabel : public QWidget +{ + Q_OBJECT +public: + BluetoothNameLabel(QWidget *parent = nullptr, int x = 200,int y = 40); + ~BluetoothNameLabel(); + void set_dev_name(const QString &dev_name); + void dev_name_limit_fun(); +protected: + void mousePressEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void leaveEvent(QEvent *event); + void enterEvent(QEvent *event); + +signals: + void sendAdapterName(const QString &value); + +public slots: + void LineEdit_Input_Complete(); + void setLabelText(const QString &value); + void settings_changed(const QString &key); + +private: + QGSettings *settings; + bool style_flag = false; + + QLabel *m_label = nullptr; + QLabel *icon_pencil=nullptr; + + QLineEdit *m_lineedit = nullptr; + QString device_name; + int font_width; + + QMessageBox *messagebox = nullptr; + QHBoxLayout *hLayout = nullptr; +}; + +#endif // BLUETOOTHNAMELABEL_H diff --git a/ukcc-bluetooth/config.h b/ukcc-bluetooth/config.h new file mode 100644 index 0000000..3bfb084 --- /dev/null +++ b/ukcc-bluetooth/config.h @@ -0,0 +1,27 @@ +#ifndef CONFIG_H +#define CONFIG_H +#include + +#define BluetoothServiceExePath "/usr/bin/bluetoothService -o" +#define BluetoothTrayExePath "/usr/bin/ukui-bluetooth" +#define BluetoothServiceName "bluetoothService" +#define BluetoothTrayName "ukui-bluetooth" + +#define SYSTEMSTYLESCHEMA "org.ukui.style" +#define SYSTEMSTYLENAME "styleName" +#define SYSTEMFONTSIZE "systemFontSize" +#define SYSTEMFONT "systemFont" + +#define MAX_DEVICE_CONECTIONS_TIMES 3 + +#define DELAYED_SCANNING_TIME_S (2*1000) +#define DEVICE_CONNECTION_TIMEOUT_S (30*1000) +#define LOADING_ICON_TIMEOUT_INTERVAL_MS 110 + +const QString SERVICE = "com.ukui.bluetooth"; +const QString PATH = "/com/ukui/bluetooth"; +const QString INTERFACE = "com.ukui.bluetooth"; + +//全局变量,是否是华为机器, 默认false, 在bluetooth.cpp文件里面定义 +extern bool global_ishuawei; +#endif // CONFIG_H diff --git a/ukcc-bluetooth/devicebase.cpp b/ukcc-bluetooth/devicebase.cpp new file mode 100644 index 0000000..e35b05c --- /dev/null +++ b/ukcc-bluetooth/devicebase.cpp @@ -0,0 +1,240 @@ +#include "devicebase.h" + +//devicebase +devicebase::devicebase() +{ + +} +//devicebase end + +//bluetoothadapter +bluetoothadapter::bluetoothadapter(QString dev_name , + const QString dev_address , + bool dev_power , + bool dev_discovering , + bool dev_discoverable) + :m_dev_name(dev_name) + ,m_dev_address(dev_address) + ,m_dev_power(dev_power) + ,m_dev_discovering(dev_discovering) + ,m_dev_discoverable(dev_discoverable) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + this->setObjectName(dev_address); + +} + +void bluetoothadapter::resetDeviceName(QString new_dev_name) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + this->m_dev_name = new_dev_name; +} + +QString bluetoothadapter::getDevName() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + return this->m_dev_name; +} + +QString bluetoothadapter::getDevAddress() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + return this->m_dev_address; +} + + +void bluetoothadapter::setDevPower(bool value) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + this->m_dev_power = value; +} + +bool bluetoothadapter::getDevPower() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + return this->m_dev_power; +} + +void bluetoothadapter::setDevDiscovering(bool value) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + this->m_dev_discovering = value; +} + +bool bluetoothadapter::getDevDiscovering() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + return this->m_dev_discovering; +} + +void bluetoothadapter::setDevDiscoverable(bool value) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + this->m_dev_discoverable = value; +} + +bool bluetoothadapter::getDevDiscoverable() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + return this->m_dev_discoverable; +} + +//bluetoothadapter end + + +//bluetoothdevice +bluetoothdevice::bluetoothdevice(QString dev_name , + QString dev_address , + DEVICE_TYPE dev_type , + bool dev_paired_status , + bool dev_connected_status , + //DEVICE_STATUS dev_status , + bool dev_trust + ) + :m_dev_name(dev_name) + ,m_dev_address(dev_address) + ,m_dev_type(dev_type) + ,m_dev_isPaired(dev_paired_status) + ,m_dev_isConnected(dev_connected_status) + //,m_dev_status(dev_status) + ,m_dev_trust(dev_trust) +{ + this->setObjectName(dev_address); + clearErrorInfo(); + //qDebug() << Q_FUNC_INFO << __LINE__; +// if (DEVICE_STATUS::PairedAndUnlinked == dev_status || +// DEVICE_STATUS::PairedAndLinked == dev_status ) +// { +// this->m_dev_isPaired = true ; +// this->m_dev_trust = true ; +// } +// else +// { +// this->m_dev_isPaired = false ; +// this->m_dev_trust = false ; +// } + +// if (DEVICE_STATUS::UnpairAndLinked == dev_status || +// DEVICE_STATUS::PairedAndLinked == dev_status ) +// this->m_dev_isConnected = true ; +// else +// this->m_dev_isConnected = false ; + +} + +void bluetoothdevice::resetDeviceName(QString new_dev_name) +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + this->m_dev_name = new_dev_name; + emit nameChanged(new_dev_name); +} + +void bluetoothdevice::devMacAddressChanged(QString macAddress) +{ + if(this->m_dev_address != macAddress) + { + this->m_dev_address = macAddress; + //emit macAddressChanged(value); + } +} + +QString bluetoothdevice::getDevName() +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + return this->m_dev_name; +} + +QString bluetoothdevice::getDevAddress() +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + return this->m_dev_address; +} + +void bluetoothdevice::setDevType(DEVICE_TYPE type) +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + this->m_dev_type = type; + emit typeChanged(type); +} +bluetoothdevice::DEVICE_TYPE bluetoothdevice::getDevType() +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + return this->m_dev_type; + +} +//void bluetoothdevice::setDevStatus(DEVICE_STATUS status) +//{ +// //qDebug() << Q_FUNC_INFO << __LINE__; + +//} +//bluetoothdevice::DEVICE_STATUS bluetoothdevice::getDevStatus() +//{ +// //qDebug() << Q_FUNC_INFO << __LINE__; + +//} + +void bluetoothdevice::setDevTrust(bool value) +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + this->m_dev_trust = value; + emit trustChanged(value); + +} +bool bluetoothdevice::getDevTrust() +{ + //qDebug() << Q_FUNC_INFO << __LINE__; +} + +bool bluetoothdevice::isPaired() +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + return m_dev_isPaired; +} +void bluetoothdevice::devPairedChanged(bool value) +{ + qDebug() << Q_FUNC_INFO << value << __LINE__; + if(this->m_dev_isPaired != value) + { + this->m_dev_isPaired = value; + emit pairedChanged(value); + } +} + +bool bluetoothdevice::isConnected() +{ + //qDebug() << Q_FUNC_INFO << __LINE__; + return m_dev_isConnected; +} + +void bluetoothdevice::devConnectedChanged(bool value) +{ + if(this->m_dev_isConnected != value) + { + this->m_dev_isConnected = value; + emit connectedChanged(value); + } +} + +void bluetoothdevice::setErrorInfo(int errorId,QString errorText) +{ + this->m_errorId = errorId; + this->m_errorText = errorText; + emit errorInfoRefresh(errorId,errorText); +} + +void bluetoothdevice::clearErrorInfo() +{ + this->m_errorId = 0; + this->m_errorText = ""; +} +void bluetoothdevice::setDevSendFileMark(bool isSupport) +{ + this->m_dev_support_sendFile = isSupport; +} +bool bluetoothdevice::getDevSendFileMark() +{ + return this->m_dev_support_sendFile; +} + +//bluetoothdevice end + diff --git a/ukcc-bluetooth/devicebase.h b/ukcc-bluetooth/devicebase.h new file mode 100644 index 0000000..54bb838 --- /dev/null +++ b/ukcc-bluetooth/devicebase.h @@ -0,0 +1,243 @@ +#ifndef DEVICEBASE_H +#define DEVICEBASE_H + +#include +#include +#include +#include +#include + +#include + +class devicebase; +class bluetoothadapter; +class bluetoothdevice; + +//devicebase +class devicebase : public QObject +{ + Q_OBJECT +public: + devicebase(); + virtual ~devicebase(){} + + virtual void resetDeviceName(QString) = 0 ; + virtual QString getDevName() = 0; + virtual QString getDevAddress() = 0; + +//signals: +// void deviceNameChanged(); + +}; +//devicebase end + + +//bluetoothadapter +class bluetoothadapter : public devicebase +{ + Q_OBJECT +public: + bluetoothadapter(QString dev_name , + QString dev_address, + bool dev_power , + bool dev_discovering, + bool dev_discoverable); + + ~bluetoothadapter(){} + + void resetDeviceName(QString) Q_DECL_OVERRIDE ; + QString getDevName() Q_DECL_OVERRIDE ; + QString getDevAddress() Q_DECL_OVERRIDE ; + + void setDevPower(bool); + bool getDevPower(); + void setDevDiscovering(bool); + bool getDevDiscovering(); + void setDevDiscoverable(bool); + bool getDevDiscoverable(); + + QList m_bluetooth_device_list; + QList m_bluetooth_device_paired_list; + +private: + QString m_dev_name; + QString m_dev_address; + bool m_dev_power; + bool m_dev_discovering; + bool m_dev_discoverable; + + +}; +//bluetoothadapter end + +//bluetoothdevice +class bluetoothdevice : public devicebase +{ + Q_OBJECT + +public: + enum DEVICE_TYPE{ + /** The device is a phone. */ + phone = 0, + /** The device is a modem. */ + modem, + /** The device is a computer. */ + computer, + /** The device is a network. */ + network, + /** The device is a headset. */ + headset, + /** The device is a headphones. */ + headphones, + /** The device is an uncategorized audio video device. */ + audiovideo, + /** The device is a keyboard. */ + keyboard, + /** The device is a mouse. */ + mouse, + /** The device is a joypad. */ + joypad, + /** The device is a graphics tablet (input device). */ + tablet, + /** The deivce is an uncategorized peripheral device. */ + peripheral, + /** The device is a camera. */ + camera, + /** The device is a printer. */ + printer, + /** The device is an uncategorized imaging device. */ + imaging, + /** The device is a wearable device. */ + wearable, + /** The device is a toy. */ + toy, + /** The device is a health device. */ + health, + /** The device is not of any of the known types. */ + uncategorized + }; + Q_ENUM(DEVICE_TYPE) + + +// enum DEVICE_STATUS{ +// Unkown = 0, +// UnpairAndUnlinked, // +// UnpairAndLinked, +// PairedAndUnlinked, +// PairedAndLinked, +// Error +// }; +// Q_ENUM(DEVICE_STATUS) + + enum Error { + /** Indicates there is no error. */ + NoError = 0, + /** Indicates that the device is not ready. */ + NotReady = 1, + /** Indicates that the action have failed. */ + Failed = 2, + /** Indicates that the action was rejected. */ + Rejected = 3, + /** Indicates that the action was canceled. */ + Canceled = 4, + /** Indicates that invalid arguments were passed. */ + InvalidArguments = 5, + /** Indicates that an agent or pairing record already exists. */ + AlreadyExists = 6, + /** Indicates that an agent, service or pairing operation does not exists. */ + DoesNotExist = 7, + /** Indicates that the action is already in progress. */ + InProgress = 8, + /** Indicates that the action is not in progress. */ + NotInProgress = 9, + /** Indicates that the device is already connected. */ + AlreadyConnected = 10, + /** Indicates that the connection to the device have failed. */ + ConnectFailed = 11, + /** Indicates that the device is not connected. */ + NotConnected = 12, + /** Indicates that the action is not supported. */ + NotSupported = 13, + /** Indicates that the caller is not authorized to do the action. */ + NotAuthorized = 14, + /** Indicates that the authentication was canceled. */ + AuthenticationCanceled = 15, + /** Indicates that the authentication have failed. */ + AuthenticationFailed = 16, + /** Indicates that the authentication was rejected. */ + AuthenticationRejected = 17, + /** Indicates that the authentication timed out. */ + AuthenticationTimeout = 18, + /** Indicates that the connection attempt have failed. */ + ConnectionAttemptFailed = 19, + /** Indicates that the data provided generates a data packet which is too long. */ + InvalidLength = 20, + /** Indicates that the action is not permitted (e.g. maximum reached or socket locked). */ + NotPermitted = 21, + /** Indicates an error with D-Bus. */ + DBusError = 98, + /** Indicates an internal error. */ + InternalError = 99, + /** Indicates an unknown error. */ + UnknownError = 100 + }; + Q_ENUM(Error) + + bluetoothdevice(QString device_name , + QString device_address , + DEVICE_TYPE dev_type , + bool dev_paired_status , + bool dev_connected_status , + //DEVICE_STATUS dev_status , + bool dev_trust + ); + ~bluetoothdevice(){} + + void resetDeviceName(QString) Q_DECL_OVERRIDE ; + QString getDevName() Q_DECL_OVERRIDE ; + QString getDevAddress() Q_DECL_OVERRIDE ; + + void setDevType(DEVICE_TYPE); + DEVICE_TYPE getDevType(); + //void setDevStatus(DEVICE_STATUS); + //DEVICE_STATUS getDevStatus(); + + bool isPaired(); + void devPairedChanged(bool); + bool isConnected(); + void devConnectedChanged(bool); + + void devMacAddressChanged(QString); + + void setDevTrust(bool); + bool getDevTrust(); + void setErrorInfo(int,QString); + void clearErrorInfo(); + void setDevSendFileMark(bool); + bool getDevSendFileMark(); + +signals: + + void nameChanged(QString); + void typeChanged(DEVICE_TYPE); + void pairedChanged(bool); + void connectedChanged(bool); + void trustChanged(bool); + void errorInfoRefresh(int,QString); + +private: + + QString m_dev_name; + QString m_dev_address; + DEVICE_TYPE m_dev_type; + //DEVICE_STATUS m_dev_status; + bool m_dev_trust ; + bool m_dev_isPaired; + bool m_dev_isConnected; + bool m_dev_support_sendFile; + int m_errorId; + QString m_errorText; +}; +//bluetoothdevice end + +#endif // DEVICEBASE_H diff --git a/ukcc-bluetooth/deviceinfoitem.cpp b/ukcc-bluetooth/deviceinfoitem.cpp new file mode 100644 index 0000000..ac93bfc --- /dev/null +++ b/ukcc-bluetooth/deviceinfoitem.cpp @@ -0,0 +1,1033 @@ +#include "deviceinfoitem.h" + + +DeviceInfoItem::DeviceInfoItem(QWidget *parent, bluetoothdevice * dev): + QFrame(parent), + _MDev(dev) +{ + this->setMinimumSize(580,64); + this->setMaximumSize(1800,64); + //this->setObjectName(_MDev? _MDev.data()->address(): "null"); + this->setObjectName(_MDev? _MDev->getDevAddress() : "null"); + + m_str_dev_connecting = tr("Connecting"); + m_str_dev_disconnecting = tr("Disconnecting"); + m_str_dev_connected = tr("Connected"); + m_str_dev_ununited = tr("Not Connected"); + m_str_dev_conn_fail = tr("Connect fail"); + m_str_dev_disconn_fail = tr("Disconnect fail"); + + InitMemberVariables(); + setDeviceConnectSignals(); + + _devConnErrorClearTimer = new QTimer(this); + _devConnErrorClearTimer->setInterval(CONNECT_ERROR_TIMER_CLEAR); + connect(_devConnErrorClearTimer,&QTimer::timeout,this,[=]{ + m_devConnect_error_count = 0; + _devConnErrorClearTimer->stop(); + }); + +} + +DeviceInfoItem::~DeviceInfoItem() +{ + +} + +void DeviceInfoItem::TimedRestoreConnectionErrorDisplay() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + //错误信息显示超时后,显示错误操作后的设备状态 + QTimer::singleShot(8000,this,[=]{ + if((_DevStatus != DEVSTATUS::Connecting) && (_DevStatus != DEVSTATUS::DisConnecting)) + { + if (_MDev->isPaired()) + { + _DevStatus = DEVSTATUS::Paired; + + if (_MDev->isConnected()) + _DevStatus = DEVSTATUS::Connected; + + } else { + _DevStatus = DEVSTATUS::NoPaired; + } + update(); + } + }); +} + + +void DeviceInfoItem::InitMemberVariables() +{ + if (_MDev->isPaired()) { + + _DevStatus = DEVSTATUS::Paired; + + if (_MDev->isConnected()) { + _DevStatus = DEVSTATUS::Connected; + } + } else { + _DevStatus = DEVSTATUS::NoPaired; + } + + if(QGSettings::isSchemaInstalled(SYSTEMSTYLESCHEMA)){ + item_gsettings = new QGSettings(SYSTEMSTYLESCHEMA); + + connect(item_gsettings,&QGSettings::changed,this,&DeviceInfoItem::GSettingsChanges); + + if(item_gsettings->get("style-name").toString() == "ukui-black" || + item_gsettings->get("style-name").toString() == "ukui-dark") + _themeIsBlack = true; + else + _themeIsBlack = false; + + _fontFamily = item_gsettings->get("system-font").toString(); + _fontSize = item_gsettings->get("system-font-size").toString().toInt(); + } + + devName = _MDev->getDevName(); + _MStatus = Status::Nomal; + _clicked = false; + _pressFlag = false; + _connDevTimeOutFlag = false; + + _iconTimer = new QTimer(this); + _iconTimer->setInterval(110); + connect(_iconTimer,&QTimer::timeout,this,[=]{ + if (iconFlag >= 7) + iconFlag = 0; + iconFlag++; + update(); + }); + + _devConnTimer = new QTimer(this); + _devConnTimer->setInterval(30000); + connect(_devConnTimer,&QTimer::timeout,this,[=]{ + + emit devConnectionComplete(); + _devConnTimer->stop(); + _iconTimer->stop(); + _clicked = false; + _connDevTimeOutFlag = true ; + + qDebug() << Q_FUNC_INFO << "current dev status:" << _DevStatus ; + if (DEVSTATUS::Connecting == _DevStatus) { + _DevStatus = DEVSTATUS::ConnectFailed; + } else if (DEVSTATUS::DisConnecting == _DevStatus) { + _DevStatus = DEVSTATUS::DisConnectFailed; + } + update(); + TimedRestoreConnectionErrorDisplay(); + }); + + dev_Menu = new QMenu(this); + connect(dev_Menu,&QMenu::triggered,this,&DeviceInfoItem::MenuSignalDeviceFunction); + +} + +void DeviceInfoItem::MenuSignalDeviceFunction(QAction *action) +{ + if(NULL == _MDev) + return; + qDebug() << Q_FUNC_INFO << action->text() ; + if(action->text() == tr("send file")) + { + qDebug() << Q_FUNC_INFO << "To :" << _MDev->getDevName() << "send file" << __LINE__; + emit devSendFiles(_MDev->getDevAddress()); + //Send_files_by_address(action->statusTip()); + } + else if(action->text() == tr("remove")) + { + DevRemoveDialog::REMOVE_INTERFACE_TYPE mode ; + if (bluetoothdevice::DEVICE_TYPE::phone == _MDev->getDevType() || + bluetoothdevice::DEVICE_TYPE::computer == _MDev->getDevType()) + mode = DevRemoveDialog::REMOVE_HAS_PIN_DEV; + else + mode = DevRemoveDialog::REMOVE_NO_PIN_DEV; + + showDeviceRemoveWidget(mode); + } + else if(action->text() == tr("disconnect")) + { + qDebug() << Q_FUNC_INFO << "To :" << _MDev->getDevName() << "disconnect" << __LINE__; + emit devDisconnect(_MDev->getDevAddress()); + } +} + +//bool DeviceInfoItem::isDisplayPINCodeWidget() +//{ +// if (bluetoothdevice::DEVICE_TYPE::phone == _MDev->getDevType() || +// bluetoothdevice::DEVICE_TYPE::computer == _MDev->getDevType()) +// return true; +// else +// return false; +//} + +void DeviceInfoItem::showDeviceRemoveWidget(DevRemoveDialog::REMOVE_INTERFACE_TYPE mode) +{ + DevRemoveDialog *mesgBox = new DevRemoveDialog(mode); + mesgBox->setModal(true); + mesgBox->setDialogText(_MDev->getDevName()); + + connect(mesgBox,&DevRemoveDialog::accepted,this,[=]{ + qDebug() << Q_FUNC_INFO << "To :" << _MDev->getDevName() << "Remove" << __LINE__; + emit devRemove(_MDev->getDevAddress()); + }); + + mesgBox->exec(); +} + +void DeviceInfoItem::setDeviceCurrentStatus() +{ + if (NULL != _MDev) + { + if (_connDevTimeOutFlag) + { + _DevStatus = DEVSTATUS::Error; + QTimer::singleShot(8000,this,[=]{ + _connDevTimeOutFlag = false ; + update(); + }); + } + else + { + if(_MDev->isPaired()) + { + _DevStatus = DEVSTATUS::Paired; + if (_MDev->isConnected()) + _DevStatus = DEVSTATUS::Connected; + } + else + { + _DevStatus = DEVSTATUS::None; + } + } + } +} + + +void DeviceInfoItem::GSettingsChanges(const QString &key) +{ + qDebug() << Q_FUNC_INFO << key; + if(SYSTEMSTYLENAME == key){ + if(item_gsettings->get("style-name").toString() == "ukui-black" || + item_gsettings->get("style-name").toString() == "ukui-dark") + _themeIsBlack = true; + else + _themeIsBlack = false; + + //if (item_gsettings->get("icon-theme-name").toString() == "ukui-icon-theme-classical") + // batteryPixmap = getDevTypeIcon(); + } else if (SYSTEMFONT == key) { + _fontFamily = item_gsettings->get("system-font").toString(); + } else if (SYSTEMFONTSIZE == key) { + _fontSize = item_gsettings->get("system-font-size").toString().toInt(); + } +} + +void DeviceInfoItem::setDeviceConnectSignals() +{ + if (_MDev) + { + connect(_MDev,&bluetoothdevice::nameChanged,this,[=](const QString &name) + { + devName = name ; + update(); + }); + + connect(_MDev,&bluetoothdevice::typeChanged,this,[=](bluetoothdevice::DEVICE_TYPE type) + { + update(); + }); + + connect(_MDev,&bluetoothdevice::pairedChanged,this,[=](bool paired) + { + qDebug() << Q_FUNC_INFO << "pairedChanged" << __LINE__; + //BlueToothMain::m_device_pin_flag = false; + if(paired && _MDev->isConnected()) + { + if(_devConnTimer->isActive()) + _devConnTimer->stop(); + if (_iconTimer->isActive()) + _iconTimer->stop(); + } + + if (paired) + { + qDebug() << Q_FUNC_INFO << "pairedChanged" << __LINE__; + emit devPaired(_MDev->getDevAddress()); + } + _clicked = false; + + if (paired) + { + _DevStatus = DEVSTATUS::Paired; + emit devPaired(_MDev->getDevAddress()); + + if (_MDev->isConnected()) + _DevStatus = DEVSTATUS::Connected; + + } else { + _DevStatus = DEVSTATUS::NoPaired; + } + + update(); + }); + + connect(_MDev,&bluetoothdevice::connectedChanged,this,[=](bool connected) + { + //BlueToothMain::m_device_pin_flag = false; + if(_devConnTimer->isActive()) + _devConnTimer->stop(); + if (_iconTimer->isActive()) + _iconTimer->stop(); + _clicked = false; + + if (_MDev->isPaired() && connected) { + _DevStatus = DEVSTATUS::Connected; + //连接成功后,清除连接失败的计数,以及计时器 + m_devConnect_error_count = 0; + _devConnErrorClearTimer->stop(); + } else if (!_MDev->isPaired() && connected) { + _DevStatus = DEVSTATUS::Connecting; + } else if (_MDev->isPaired() && !connected){ +// if (_DevStatus == DEVSTATUS::Connecting) +// _DevStatus = DEVSTATUS::ConnectFailed; +// else if (_DevStatus != DEVSTATUS::ConnectFailed && +// _DevStatus != DEVSTATUS::DisConnectFailed) + _DevStatus = DEVSTATUS::Paired; + } else { +// if (_DevStatus == DEVSTATUS::Connecting && !connected) +// _DevStatus = DEVSTATUS::ConnectFailed; +// else if (_DevStatus == DEVSTATUS::DisConnecting && connected) +// _DevStatus = DEVSTATUS::DisConnectFailed; +// else + _DevStatus = DEVSTATUS::ConnectFailed; + } + + emit devConnectionComplete(); + update(); + TimedRestoreConnectionErrorDisplay(); + }); + + connect(_MDev,&bluetoothdevice::errorInfoRefresh,this,[=](int errorId , QString errorText) + { + qDebug () << Q_FUNC_INFO << "error:" << errorId << errorText << __LINE__; + emit devConnectionComplete(); + if (errorId) + { + if(_devConnTimer->isActive()) + _devConnTimer->stop(); + if (_iconTimer->isActive()) + _iconTimer->stop(); + _clicked = false; + + if(!_MDev->isConnected()) + { + _DevStatus = DEVSTATUS::ConnectFailed; + update(); + TimedRestoreConnectionErrorDisplay(); + } + + //在配对列表中,且连接未成功 + if (_MDev->isPaired() && !_MDev->isConnected()) + { + m_devConnect_error_count ++; + _devConnErrorClearTimer->start(); + if (m_devConnect_error_count > CONNECT_ERROR_COUNT) + { + _devConnErrorClearTimer->stop(); + m_devConnect_error_count = 0; + showDeviceRemoveWidget(DevRemoveDialog::REMOVE_MANY_TIMES_CONN_FAIL_DEV); + } + } + } + }); + } +} + +bool DeviceInfoItem::mouseEventIntargetAera(QPoint p) +{ + QRect *targte = new QRect(this->width()-55,14,36,36); + if (targte->contains(p)) { + return true; + } else { + return false; + } +} + +QRect DeviceInfoItem::getStatusTextRect(QRect rect) +{ + if (_MDev && _MDev->isPaired()) { + //return QRect(this->width()-226,16,150,30); + return QRect(this->width()-226,16,150,30); + } else { + //return QRect(this->width()-120,16,105,30); + return QRect(this->width()-140,16,125,30); + } +} + +QRect DeviceInfoItem::getLoadIconRect() +{ + if (_MDev &&_MDev->isPaired()) { + return QRect(this->width()-98,19,20,20); + } else { + return QRect(this->width()-35,19,20,20); + } +} + +QRect DeviceInfoItem::getFontPixelQPoint(QString str) +{ + QFont font; + font.setFamily(_fontFamily); + font.setPointSize(_fontSize); + QFontMetrics fm(font); + + return fm.boundingRect(str); +} + +void DeviceInfoItem::enterEvent(QEvent *event) +{ + Q_UNUSED(event); + if (!BlueToothMain::m_device_operating) + _MStatus = Status::Hover; + else + _MStatus = Status::Nomal; + update(); +} + +void DeviceInfoItem::leaveEvent(QEvent *event) +{ + Q_UNUSED(event); + + _MStatus = Status::Nomal; + update(); +} + +void DeviceInfoItem::mouseReleaseEvent(QMouseEvent *event) +{ + long long _releaseCurrentTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + qDebug() << Q_FUNC_INFO << "_releaseCurrentTime" << _releaseCurrentTime << "_pressCurrentTime:" << _pressCurrentTime; + if((_releaseCurrentTime - _pressCurrentTime) >= 200) + { + qDebug() << Q_FUNC_INFO << "press to release time too long!!!!!!!"; + _pressBtnFlag = false; + + _pressFlag = false; + _MStatus = Status::Hover; + return; + } + + if (event->button() == Qt::LeftButton) { + qDebug() << Q_FUNC_INFO << mouseEventIntargetAera(event->pos()); + if (mouseEventIntargetAera(event->pos()) && _pressBtnFlag && !BlueToothMain::m_device_operating) { + MouseClickedDevFunc(); + _pressBtnFlag = false; + } else { + //华为机器主界面无单击断开操作 + if (global_ishuawei && _MDev->isConnected()) + { + return; + } + qDebug() << Q_FUNC_INFO << "BlueToothMain::m_device_operating:" << BlueToothMain::m_device_operating; + + if (!BlueToothMain::m_device_operating) + { + BlueToothMain::m_device_operating = true; + BlueToothMain::m_device_operating_address = _MDev->getDevAddress(); + MouseClickedFunc(); + _pressFlag = false; + _MStatus = Status::Hover; + } + } + } + update(); + +} + +void DeviceInfoItem::mousePressEvent(QMouseEvent *event) +{ + //获取当前时间 + _pressCurrentTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + qDebug() << Q_FUNC_INFO << _pressCurrentTime; + + if (event->button() == Qt::LeftButton) { + if (mouseEventIntargetAera(event->pos())) { + _pressBtnFlag = true; + } else { + if (!BlueToothMain::m_device_operating) + { + _pressFlag = true; + _MStatus = Status::Check; + } + } + } + update(); +} + +void DeviceInfoItem::MouseClickedDevFunc() +{ + qDebug () << Q_FUNC_INFO << __LINE__; + if (!_MDev->isPaired()) + return; + + dev_Menu->clear(); + QPoint currentWPoint = this->pos(); + QPoint sreenPoint = QWidget::mapFromGlobal(currentWPoint); + //qDebug () <setProperty("setIconHighlightEffectDefaultColor", dev_Menu->palette().color(QPalette::Active, QPalette::Base)); + dev_Menu->setPalette(palette); + dev_Menu->setMinimumWidth(180); + +// if (-1 != _MDev.data()->uuids().indexOf(BluezQt::Services::ObexObjectPush)) { +// QAction *sendfile = new QAction(dev_Menu); +// sendfile->setText(tr("Send files")); +// dev_Menu->addAction(sendfile); +// dev_Menu->addSeparator(); +// } + + //华为机器增加断开按键 + if (global_ishuawei && _MDev->isConnected()) + { + QAction *disconnect = new QAction(dev_Menu); + disconnect->setText(tr("disconnect")); + dev_Menu->addAction(disconnect); + dev_Menu->addSeparator(); + } + + bool isSupportFileSend = _MDev->getDevSendFileMark(); + if (!global_ishuawei) + { + isSupportFileSend = BlueToothDBusService::getTransferInfo(_MDev->getDevAddress()) + && BlueToothDBusService::getDevSupportFileSend(_MDev->getDevAddress()); + qDebug() << Q_FUNC_INFO << _MDev->getDevAddress() << isSupportFileSend; + _MDev->setDevSendFileMark(isSupportFileSend); + } + + if (_MDev->getDevSendFileMark() && + (bluetoothdevice::DEVICE_TYPE::phone == _MDev->getDevType() || + bluetoothdevice::DEVICE_TYPE::computer == _MDev->getDevType()) + ) + { + //非华为机器才存在文件传输功能 + if(!global_ishuawei) + { + QAction *sendfile = new QAction(dev_Menu); + sendfile->setText(tr("send file")); + dev_Menu->addAction(sendfile); + dev_Menu->addSeparator(); + } + + } + + QAction *remove = new QAction(dev_Menu); + remove->setText(tr("remove")); + dev_Menu->addAction(remove); + + qDebug () << this->x() << this->y() << "======x ======y"; + qDebug () << sreenPoint.x() << sreenPoint.y() << "======sreenPoint.x ======sreenPoint.y"; + + //int testY = ((sreenPoint.y()>0)?(-1)*qAbs(sreenPoint.y())+40:qAbs(sreenPoint.y())+40)+this->y(); + int testY = (-1)*sreenPoint.y()+40+this->y(); + qDebug () << Q_FUNC_INFO << " test Y =======================" << testY; + + //dev_Menu->move(qAbs(sreenPoint.x())+this->width()-200,testY); + dev_Menu->move(qAbs(sreenPoint.x())+this->width()-200,(-1)*sreenPoint.y()+40+this->y()); + dev_Menu->exec(); +} + +void DeviceInfoItem::mouseMoveEvent(QMouseEvent *event) +{ + if (mouseEventIntargetAera(event->pos())) { + _inBtn = true; + this->update(); + } else { + if (_inBtn) { + _inBtn = false; + this->update(); + } + } + +} + +void DeviceInfoItem::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(QColor(Qt::transparent)); + + DrawBackground(painter); + DrawStatusIcon(painter); + DrawText(painter); + + if (_iconTimer->isActive()) + DrawLoadingIcon(painter); + else + DrawStatusText(painter); + + if (_MDev->isPaired()) + { + this->setMouseTracking(true); + DrawFuncBtn(painter); + } +} + +/************************************************ + * @brief getPainterBrushColor + * @param null + * @return QColor +*************************************************/ +QColor DeviceInfoItem::getPainterBrushColor() +{ +// QColor color; +// switch (_MStatus) { +// case Status::Nomal: +// color = QColor(Qt::white);//("#EBEBEB"); +// break; +// case Status::Hover: +// color = QColor("#D7D7D7"); +// break; +// default: +// color = QColor(Qt::white);//("#EBEBEB"); +// break; +// } +// return color; + + QColor color; + switch (_MStatus) { + case Status::Nomal: + + if(_themeIsBlack) + //color = QColor("#1F2022");//("#EBEBEB"); + color = QColor(Qt::black);//("#EBEBEB"); + else + color = QColor(Qt::white);//("#EBEBEB"); + + //color = QColor(Qt::black);//("#EBEBEB"); + + break; + case Status::Hover: + if(_themeIsBlack) + color = _inBtn?QColor(Qt::black):QColor("#37373B"); + else + color = _inBtn?QColor(Qt::white):QColor("#D1D1D1"); + break; + case Status::Check: + if(_themeIsBlack) + color = QColor("#4B4B4F"); + else + color = QColor("#D9D9D9"); + break; + default: + if(_themeIsBlack) + color = QColor("#1F2022");//("#EBEBEB"); + else + color = QColor(Qt::white);//("#EBEBEB"); + //color = QColor(Qt::white);//("#EBEBEB"); + break; + } + if (_MStatus == Status::Hover || _MStatus == Status::Check || _themeIsBlack) + color.setAlpha(50); + return color; +} + +/************************************************ + * @brief getDevStatusColor + * @param null + * @return QColor +*************************************************/ +QColor DeviceInfoItem::getDevStatusColor() +{ + QColor color; + + if (_MDev) { + if (_MDev->isConnected()) { + color = QColor("#2FB3E8"); + } else { + color = QColor("#F4F4F4"); + } + } else { + color = QColor("#F4F4F4"); + } + return color; +} + +/************************************************ + * @brief getDevTypeIcon + * @param null + * @return QPixmap +*************************************************/ +QPixmap DeviceInfoItem::getDevTypeIcon() +{ + QPixmap icon; + QString iconName; + if (_MDev) { + switch (_MDev->getDevType()) { + case bluetoothdevice::DEVICE_TYPE::phone: + iconName = "phone-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::computer: + iconName = "video-display-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::headset: + iconName = "audio-headset-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::headphones: + iconName = "audio-headphones-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::audiovideo: + iconName = "audio-speakers-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::keyboard: + iconName = "input-keyboard-symbolic"; + break; + case bluetoothdevice::DEVICE_TYPE::mouse: + iconName = "input-mouse-symbolic"; + break; + default: + //iconName = "bluetooth-active-symbolic"; + iconName = "bluetooth-symbolic"; + break; + } + } else { + //iconName = "bluetooth-active-symbolic"; + iconName = "bluetooth-symbolic"; + } + + //if (_themeIsBlack && (Status::Nomal == _MStatus)) { + if (_themeIsBlack) { + icon = ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme(iconName).pixmap(16,16),"white"); + } else { + icon = QIcon::fromTheme(iconName).pixmap(16,16); + } + + return icon; +} + +/************************************************ + * @brief DrawBackground + * @param painter + * @return null +*************************************************/ +void DeviceInfoItem::DrawBackground(QPainter &painter) +{ + painter.save(); + painter.setBrush(getPainterBrushColor()); + painter.drawRoundedRect(this->rect(),6,6,Qt::AbsoluteSize); + painter.restore(); +} + +/************************************************ + * @brief DrawStatusIcon + * @param painter + * @return null +*************************************************/ +void DeviceInfoItem::DrawStatusIcon(QPainter &painter) +{ + painter.save(); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + style()->drawItemPixmap(&painter, QRect(20, 14, 35, 35), Qt::AlignCenter, getDevTypeIcon()); + painter.restore(); +} + +int DeviceInfoItem::NameTextCoordinate_Y_offset() +{ + int show_coordinate_text_Y_offset = 0 ; + switch (_fontSize) + { + case 15: + case 14: + case 13: + case 12: + show_coordinate_text_Y_offset = 0; + case 11: + case 10: + default: + show_coordinate_text_Y_offset = 0; + break; + } + return show_coordinate_text_Y_offset; +} + +QString DeviceInfoItem::getDeviceName(QString devName) +{ + QString showRealName; + int nCount = devName.count(); + //qDebug() << Q_FUNC_INFO << "DevName Count:" << nCount << __LINE__; + + int zhCount = 0; + int charMCount = 0; + for(int i = 0; i < nCount; i++) + { + QChar ch = devName.at(i); + ushort uNum = ch.unicode(); + if(uNum >= 0x4E00 && uNum <= 0x9FA5) + { + // 这个字符是中文 + zhCount ++; + //qDebug() << Q_FUNC_INFO << "this is zh:" << uNum << zhCount << __LINE__; + } + + if (uNum == 0x004D || uNum == 0x006D) + { + // 这个字符是m/M + charMCount++; + //qDebug() << Q_FUNC_INFO << "this is char m/M:" << uNum << charMCount << __LINE__; + } + } + if(devName.length() > (ShowNameTextNumberMax() - zhCount - charMCount/2)) /*减去中文长度 或者 m字符显示长度*/ + { + showRealName = devName.left(ShowNameTextNumberMax()- zhCount - charMCount/2 - 3); + showRealName.append("..."); + toptipflag = true; + this->setToolTip(_MDev->getDevName()); + } + else + { + showRealName = devName; + toptipflag = false; + this->setToolTip(""); + } + //qDebug() << Q_FUNC_INFO << "showRealName:" << showRealName << __LINE__; + + return showRealName; +} + +int DeviceInfoItem::ShowNameTextNumberMax() +{ + float display_coefficient = (this->width() - 350)/450.00; + //qDebug() << Q_FUNC_INFO << "display coefficient:" << display_coefficient << __LINE__; + int max_text_number = 0; + switch (_fontSize) + { + case 10: + max_text_number += 6 ; + case 11: + max_text_number += 5 ; + case 12: + max_text_number += 4 ; + case 13: + max_text_number += 3 ; + case 14: + max_text_number += 2 ; + case 15: + default: + max_text_number += 35 ; + break; + } + + int showMaxNameLength = max_text_number*display_coefficient; + //qDebug() << Q_FUNC_INFO << "The max length :" << showMaxNameLength << __LINE__; + + return (showMaxNameLength); + +} + +/************************************************ + * @brief DrawText + * @param painter + * @return null +*************************************************/ +void DeviceInfoItem::DrawText(QPainter &painter) +{ + painter.save(); + if(_themeIsBlack) + painter.setPen(QColor(Qt::white)); + else + painter.setPen(QColor(Qt::black)); + + //qDebug()<< Q_FUNC_INFO << "=================================" << this->width() << __LINE__; + //qDebug()<< Q_FUNC_INFO << "=================================" << _fontSize << __LINE__; + //qDebug()<< Q_FUNC_INFO << "=================================" << _MDev->getDevName().length() << __LINE__; + + //painter.drawText(70,20,this->width()-300,30,Qt::AlignLeft|Qt::AlignVCenter,_MDev? _MDev->getDevName(): QString("Example")); + painter.drawText(70,16,this->width()-350,30,Qt::AlignLeft|Qt::AlignVCenter,_MDev?getDeviceName( _MDev->getDevName() ): QString("Example")); + painter.restore(); +} + +void DeviceInfoItem::DrawStatusText(QPainter &painter) +{ + //setDeviceCurrentStatus(); + painter.save(); + if(_themeIsBlack) + painter.setPen(QColor(Qt::white)); + else + painter.setPen(QColor(Qt::black)); + +// if(Status::Hover == _MStatus) +// painter.setPen(QColor(Qt::black)); +// else +// painter.setPen(QColor(Qt::white)); + + QString str; + + switch (_DevStatus) { + case DEVSTATUS::Paired: + str = m_str_dev_ununited; + painter.setPen(QColor("#818181")); + break; + case DEVSTATUS::Connected: + str = m_str_dev_connected; + break; + case DEVSTATUS::Connecting: + str = m_str_dev_connecting; + break; + case DEVSTATUS::DisConnecting: + str = m_str_dev_disconnecting; + break; + case DEVSTATUS::DisConnectFailed: + str = m_str_dev_disconn_fail; + break; + case DEVSTATUS::ConnectFailed: + str = m_str_dev_conn_fail; + break; + default: + break; + } + + QRect rect = getFontPixelQPoint(str); + + painter.drawText(getStatusTextRect(rect),Qt::AlignRight,str); + + painter.restore(); +} + +void DeviceInfoItem::DrawFuncBtn(QPainter &painter) +{ + painter.save(); + + if (_inBtn) { + painter.setPen(QColor("#D1CFCF")); + painter.setBrush(QColor("#D1CFCF")); + } + + painter.drawRoundRect(this->width()-55,10,36,36,30,30); + + painter.setRenderHint(QPainter::SmoothPixmapTransform); + + + if (_themeIsBlack) { + if (_inBtn) + style()->drawItemPixmap(&painter,QRect(this->width()-48,19,20,20), Qt::AlignCenter, + ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(16),"black")); + else + style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, + ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(16),"white")); + } else + style()->drawItemPixmap(&painter, QRect(this->width()-48,19,20,20), Qt::AlignCenter, + ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("view-more-horizontal-symbolic").pixmap(16),"black")); + + painter.restore(); +} + +void DeviceInfoItem::DrawLoadingIcon(QPainter &painter) +{ + painter.save(); +// if (iconFlag >= 7) +// iconFlag = 0; + if (_themeIsBlack) + style()->drawItemPixmap(&painter, + getLoadIconRect(), + Qt::AlignCenter, + ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("ukui-loading-"+QString::number(iconFlag)).pixmap(20),"white")); + else + style()->drawItemPixmap(&painter, + getLoadIconRect(), + Qt::AlignCenter, + ImageUtil::drawSymbolicColoredPixmap(QIcon::fromTheme("ukui-loading-"+QString::number(iconFlag)).pixmap(20),"default")); + + painter.restore(); +// iconFlag++; + +} + +/************************************************ + * @brief MouseClickedFunc + * @param null + * @return null +*************************************************/ +void DeviceInfoItem::MouseClickedFunc() +{ + qDebug() << Q_FUNC_INFO ; + _clicked = true; + _pressFlag = false; + + if (_MDev) { + //清理错误信息 + _MDev->clearErrorInfo(); + if (_MDev->isConnected()) { + //_MDev->disconnectFromDevice(); + emit devDisconnect(_MDev->getDevAddress()); + _DevStatus = DEVSTATUS::DisConnecting; + } else { + //DevConnectFunc(); + emit devConnect(_MDev->getDevAddress()); + _DevStatus = DEVSTATUS::Connecting; + } + } + + //_iconTimer loading + if (!_iconTimer->isActive()) + { + _iconTimer->start(); + _devConnTimer->start(); + } +} + +/************************************************ + * @brief 该函数意义是当设备为音频设备时,断开已经连接的音频设备 + * @param null + * @return null +*************************************************/ +void DeviceInfoItem::DevConnectFunc() +{ + if (_MDev) + { +// if (_MDev->getDevType() == devAudioVideo || +// _MDev->getDevType() == BluezQt::Device::Headphones || +// _MDev->getDevType() == BluezQt::Device::Headset ) { + +// BluezQt::AdapterPtr MDevAdapter = _MDev.data()->adapter(); + +// for (auto dev : MDevAdapter.data()->devices()) { + +// if (dev.data()->isConnected() && dev.data()->isPaired()) { +// if (dev.data()->type() == BluezQt::Device::AudioVideo || +// dev.data()->type() == BluezQt::Device::Headphones || +// dev.data()->type() == BluezQt::Device::Headset ) { + +// BluezQt::PendingCall *pending = dev.data()->disconnectFromDevice(); +// connect(pending,&BluezQt::PendingCall::finished,this,[&](BluezQt::PendingCall *call){ +// if (!call->error()) { +// _MDev.data()->connectToDevice(); +// } +// }); +// //如果有正在连接的音频设备,做完以上流程后,直接退出函数体 +// //因为流程解决定了只有一个音频设备连接,而不需要判断后面是否有音频设备连接;提高代码执行效率 +// return; +// } +// } +// } +// //当没有任何音频设备连接,最后再连接目标设备 +// _MDev.data()->connectToDevice(); +// } else { +// _MDev.data()->connectToDevice(); +// } + } +} + diff --git a/ukcc-bluetooth/deviceinfoitem.h b/ukcc-bluetooth/deviceinfoitem.h new file mode 100644 index 0000000..13dd721 --- /dev/null +++ b/ukcc-bluetooth/deviceinfoitem.h @@ -0,0 +1,158 @@ +#ifndef DEVICEINFOITEM_H +#define DEVICEINFOITEM_H + +#include "devicebase.h" +#include "devremovedialog.h" +#include "bluetoothmain.h" +#include "bluetoothdbusservice.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CONNECT_ERROR_COUNT 3 +#define CONNECT_ERROR_TIMER_CLEAR (3*60*1000) //3分钟内用户来连接失败超过3次,提示用户是否移除后重新配对连接 + +class DeviceInfoItem : public QFrame +{ + Q_OBJECT +public: + DeviceInfoItem(QWidget *parent = nullptr,bluetoothdevice * dev = nullptr); + ~DeviceInfoItem(); + + void refresh_device_icon(bluetoothdevice::DEVICE_TYPE changeType); + void setDeviceCurrentStatus(); + + enum Status{ + Hover = 0, + Nomal, + Check, + }; + Q_ENUM(Status) + + enum DEVSTATUS{ + None, + Connected, + Connecting, + DisConnecting, + ConnectFailed, + DisConnectFailed, + NoPaired, + Paired, + Error + }; + Q_ENUM(DEVSTATUS) + + void InitMemberVariables(); + +protected: + void enterEvent(QEvent *); + void leaveEvent(QEvent *); + void mousePressEvent(QMouseEvent *); + void mouseReleaseEvent(QMouseEvent *); + void mouseMoveEvent(QMouseEvent *); + void paintEvent(QPaintEvent *); + +private slots: + void GSettingsChanges(const QString &key); + void MenuSignalDeviceFunction(QAction *action); + +signals: + + void devPaired(QString); + void devConnect(QString); + void devDisconnect(QString); + void devRemove(QString); + void devSendFiles(QString); + void devConnectionComplete(); + +private: + QColor getPainterBrushColor(); + QColor getDevStatusColor(); + QPixmap getDevTypeIcon(); + + void DrawBackground(QPainter &); + void DrawStatusIcon(QPainter &); + void DrawText(QPainter &); + void DrawStatusText(QPainter &); + void DrawFuncBtn(QPainter &); + void DrawLoadingIcon(QPainter &); + + void MouseClickedFunc(); + void MouseClickedDevFunc(); + bool mouseEventIntargetAera(QPoint); + void DevConnectFunc(); + void setDeviceConnectSignals(); + QRect getStatusTextRect(QRect); + QRect getLoadIconRect(); + QRect getStatusIconRect(QRect); + QRect getFontPixelQPoint(QString); + + //int NameTextWidthMax(); + QString getDeviceName(QString); + int ShowNameTextNumberMax(); + int NameTextCoordinate_Y_offset(); + void TimedRestoreConnectionErrorDisplay(); + void showDeviceRemoveWidget(DevRemoveDialog::REMOVE_INTERFACE_TYPE); + //bool isDisplayPINCodeWidget(); + + bool toptipflag = false; + int iconFlag = 7; + int m_devConnect_error_count = 0; + + DEVSTATUS _DevStatus; + Status _MStatus; + QString devName; + QString _fontFamily; + + int _fontSize; + bool _inBtn = false; + bool _clicked; + bool _pressFlag ; + bool _connDevTimeOutFlag ; + bool _rightFlag ; + bool _removeDevFlag ; + bool _pressBtnFlag = false; + bool _themeIsBlack = false; + long long _pressCurrentTime; + + QMenu *dev_Menu = nullptr; + + + QTimer *_iconTimer = nullptr; + QTimer *_devConnTimer = nullptr; + QTimer *_devConnErrorClearTimer = nullptr; + bluetoothdevice * _MDev = nullptr; + + QGSettings *item_gsettings = nullptr; + + //#define DEV_CONNECTING_TEXT "Connecting" + QString m_str_dev_connecting ; + //#define DEV_DISCONNECTING_TEXT "Disconnecting" + QString m_str_dev_disconnecting ; + //#define DEV_CONNECTED_TEXT "Connected" + QString m_str_dev_connected ; + //#define DEV_UNUNITED_TEXT "Ununited" + QString m_str_dev_ununited ; + //#define DEV_CONNECTION_FAIL_TEXT "Connect fail" + QString m_str_dev_conn_fail; + QString m_str_dev_disconn_fail; +}; +#endif // DEVICEINFOITEM_H diff --git a/ukcc-bluetooth/devremovedialog.cpp b/ukcc-bluetooth/devremovedialog.cpp new file mode 100644 index 0000000..ca95c0e --- /dev/null +++ b/ukcc-bluetooth/devremovedialog.cpp @@ -0,0 +1,152 @@ +#include "devremovedialog.h" + +#include +#include +#include + +DevRemoveDialog::DevRemoveDialog(REMOVE_INTERFACE_TYPE mode,QWidget *parent):QDialog(parent) +{ + initGsettings(); + this->setFixedSize(380,200); + this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + this->setAttribute(Qt::WA_TranslucentBackground); + this->m_mode = mode; + initUI(); +} + +DevRemoveDialog::~DevRemoveDialog() +{ + +} + +void DevRemoveDialog::initUI() +{ + tipLabel = new QLabel(this); + tipLabel->setGeometry(56,25,320,60); + tipLabel->setAlignment(Qt::AlignVCenter|Qt::AlignLeft); + tipLabel->setWordWrap(true); + + if (REMOVE_HAS_PIN_DEV == this->m_mode) + { + txtLabel = new QLabel(this); + txtLabel->setGeometry(55,80,320,65); + txtLabel->setAlignment(Qt::AlignTop|Qt::AlignLeft); + txtLabel->setWordWrap(true); + + QPalette txtPal; + txtPal.setColor(QPalette::WindowText,QColor("#818181")); + txtLabel->setPalette(txtPal); + + QString txtStr = tr("After it is removed, the PIN code must be matched for the next connection."); + QString newTxtStr = QFontMetrics(this->font()).elidedText(txtStr,Qt::ElideRight,txtLabel->width()); + QFont txtFont ; + txtFont.setPointSize(this->fontInfo().pointSize()+3); + txtLabel->setFont(txtFont); + txtLabel->setText(newTxtStr); + if (newTxtStr != txtStr) + txtLabel->setToolTip(tr("After it is removed, the PIN code must be matched for the next connection.")); + } + + iconLabel = new QLabel(this); + iconLabel->setGeometry(16,45,22,22); + iconLabel->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(22,22)); + + closeBtn = new QPushButton(this); + closeBtn->setGeometry(350,8,20,20); + closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic")); + closeBtn->setFlat(true); + closeBtn->setProperty("isWindowButton",0x2); + closeBtn->setProperty("useIconHighlihtEffect",0x8); + connect(closeBtn,&QPushButton::clicked,this,[=]{ + this->close(); + }); + + acceptBtn = new QPushButton(this); + acceptBtn->setGeometry(242,148,120,36); + acceptBtn->setText(tr("Remove")); + connect(acceptBtn,&QPushButton::clicked,this,[=]{ + emit accepted(); + this->close(); + }); + + rejectBtn = new QPushButton(this); + rejectBtn->setGeometry(110,148,120,36); + rejectBtn->setText(tr("Cancel")); + connect(rejectBtn,&QPushButton::clicked,this,[=]{ + this->close(); + }); +} + +void DevRemoveDialog::initGsettings() +{ + if (QGSettings::isSchemaInstalled("org.ukui.style")) { + gsettings = new QGSettings("org.ukui.style"); + + if(gsettings->get("style-name").toString() == "ukui-default" + || gsettings->get("style-name").toString() == "ukui-light") + isblack = false; + else + isblack = true; + } + + connect(gsettings,&QGSettings::changed,this,&DevRemoveDialog::gsettingsSlot); +} + +void DevRemoveDialog::setDialogText(const QString &str) +{ + QString txtStr; + if (REMOVE_MANY_TIMES_CONN_FAIL_DEV == this->m_mode) + txtStr = QString(tr("Connection failed! Please remove it before connecting.")); + else + txtStr = QString(tr("Are you sure to remove %1 ?")).arg(str); + + QString newTxtStr = QFontMetrics(this->font()).elidedText(txtStr,Qt::ElideRight,tipLabel->width()); + QFont tipFont ; + tipFont.setPointSize(this->fontInfo().pointSize()+3); + tipLabel->setFont(tipFont); + tipLabel->setText(newTxtStr); + + if (newTxtStr != txtStr) + tipLabel->setToolTip(tr("Are you sure to remove %1 ?").arg(str)); +} + +void DevRemoveDialog::gsettingsSlot(const QString &key) +{ + if (key == "styleName") { + QPalette palette; + if(gsettings->get("style-name").toString() == "ukui-default" || + gsettings->get("style-name").toString() == "ukui-light") { + + palette.setBrush(QPalette::Base,QBrush(Qt::white)); + palette.setColor(QPalette::Text,QColor(Qt::black)); + + isblack = false; + + } else { + + palette.setBrush(QPalette::Base,QBrush(Qt::black)); + palette.setColor(QPalette::Text,QColor(Qt::white)); + + isblack = true; + } + + this->setPalette(palette); + } +} + +void DevRemoveDialog::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + + QPainter painter(this); + painter.setPen(Qt::transparent); + + if (isblack) + painter.setBrush(Qt::black); + else + painter.setBrush(Qt::white); + + painter.setRenderHint(QPainter::Antialiasing); + + painter.drawRoundedRect(this->rect(),12,12); +} diff --git a/ukcc-bluetooth/devremovedialog.h b/ukcc-bluetooth/devremovedialog.h new file mode 100644 index 0000000..3c3371c --- /dev/null +++ b/ukcc-bluetooth/devremovedialog.h @@ -0,0 +1,62 @@ +#ifndef DEVREMOVEDIALOG_H +#define DEVREMOVEDIALOG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class DevRemoveDialog final : public QDialog +{ + Q_OBJECT +public: + enum REMOVE_INTERFACE_TYPE + { + REMOVE_NO_PIN_DEV = 0, + REMOVE_HAS_PIN_DEV = 1, + REMOVE_MANY_TIMES_CONN_FAIL_DEV = 2 + }; + Q_ENUM(REMOVE_INTERFACE_TYPE) + + explicit DevRemoveDialog(REMOVE_INTERFACE_TYPE mode , QWidget *parent = nullptr); + + ~DevRemoveDialog(); + + void initUI(); + + void initGsettings(); + + void setDialogText(const QString & ); + +private slots: + void gsettingsSlot(const QString &); + +protected: + void paintEvent(QPaintEvent *); + +private: + bool isblack = false; + + QLabel *tipLabel = nullptr; + + QLabel *txtLabel = nullptr; + + QLabel *iconLabel = nullptr; + + QGSettings *gsettings = nullptr; + + QPushButton *closeBtn = nullptr; + + QPushButton *acceptBtn = nullptr; + + QPushButton *rejectBtn = nullptr; + + REMOVE_INTERFACE_TYPE m_mode = REMOVE_HAS_PIN_DEV; +}; + +#endif // DEVREMOVEDIALOG_H diff --git a/ukcc-bluetooth/devrenamedialog.cpp b/ukcc-bluetooth/devrenamedialog.cpp new file mode 100644 index 0000000..c697319 --- /dev/null +++ b/ukcc-bluetooth/devrenamedialog.cpp @@ -0,0 +1,182 @@ +#include "devrenamedialog.h" + +DevRenameDialog::DevRenameDialog(QWidget *parent):QDialog(parent) +{ + this->setFixedSize(480,192); + this->adjustSize(); + this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); + this->setAttribute(Qt::WA_TranslucentBackground); + + initUI(); + initGsettings(); +} + +DevRenameDialog::~DevRenameDialog() +{ + +} + +void DevRenameDialog::setDevName(const QString &str) +{ + lineEdit->setText(str); + adapterOldName = str; + //test name + //lineEdit->setText("strdddd123456788991111000000"); + //adapterOldName = "strdddd123456788991111000000"; +} + +void DevRenameDialog::initGsettings() +{ + if (QGSettings::isSchemaInstalled("org.ukui.style")) { + gsettings = new QGSettings("org.ukui.style"); + + if(gsettings->get("style-name").toString() == "ukui-default" + || gsettings->get("style-name").toString() == "ukui-light") + isblack = false; + else + isblack = true; + + _fontSize = gsettings->get("system-font-size").toString().toInt(); + + } + + connect(gsettings,&QGSettings::changed,this,&DevRenameDialog::gsettingsSlot); +} + +void DevRenameDialog::gsettingsSlot(const QString &key) +{ + if (key == "styleName") { + QPalette palette; + if(gsettings->get("style-name").toString() == "ukui-default" || + gsettings->get("style-name").toString() == "ukui-light") { + + palette.setBrush(QPalette::Base,QBrush(Qt::white)); + palette.setColor(QPalette::Text,QColor(Qt::black)); + + isblack = false; + + } else { + + palette.setBrush(QPalette::Base,QBrush(Qt::black)); + palette.setColor(QPalette::Text,QColor(Qt::white)); + + isblack = true; + } + + this->setPalette(palette); + } +} + +void DevRenameDialog::initUI() +{ + QLabel *iconLabel = new QLabel(this); + iconLabel->setGeometry(10,6,20,20); + iconLabel->setPixmap(QIcon::fromTheme("bluetooth").pixmap(20,20)); + + QLabel *titleLabel = new QLabel(this); + titleLabel->setGeometry(36,5,100,20); + titleLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); + titleLabel->setText(tr("Rename")); + + closeBtn = new QPushButton(this); + closeBtn->setGeometry(453,8,20,20); + //closeBtn->setIcon(QIcon::fromTheme("application-exit-symbolic")); + closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic")); + closeBtn->setFlat(true); + //closeBtn->setFixedSize(QSize(20,20)); + closeBtn->setProperty("isWindowButton",0x2); + closeBtn->setProperty("useIconHighlihtEffect",0x8); + connect(closeBtn,&QPushButton::clicked,this,[=]{ + this->close(); + }); + + QLabel *textLabel = new QLabel(this); + textLabel->setGeometry(24,64,60,20); + textLabel->setText(tr("Name")); + textLabel->setAlignment(Qt::AlignHCenter|Qt::AlignRight); + textLabel->adjustSize(); + + int wigth = textLabel->width(); + wigth = wigth - 60; + lineEdit = new QLineEdit(this); + lineEdit->setMaxLength(INPUT_STRNAME_MAX); + lineEdit->setGeometry(100 + wigth,55,355 - wigth,36); + //输入变化时进行长度提示 + connect(lineEdit,&QLineEdit::textEdited,this,&DevRenameDialog::lineEditSlot); + + tipLabel = new TitleLabel(this); + tipLabel->setGeometry(96 + wigth,94,300,25); + tipLabel->setText(tr("The value contains 1 to 32 characters")); + tipLabel->setVisible(false); + tipLabel->setStyleSheet("color: rgba(255, 0, 0, 0.85);\ + opacity: 1;"); + + acceptBtn = new QPushButton(tr("OK"),this); + acceptBtn->setGeometry(359,130,96,36); + connect(acceptBtn,&QPushButton::clicked,this,[=]{ + + if ((lineEdit->text().length() >= INPUT_STRNAME_MIN) && + (lineEdit->text().length() <= INPUT_STRNAME_MAX) && + (lineEdit->text() != adapterOldName)) + + emit nameChanged(lineEdit->text()); + + this->close(); + }); + + rejectBtn = new QPushButton(tr("Cancel"),this); + rejectBtn->setGeometry(247,130,96,36); + connect(rejectBtn,&QPushButton::clicked,this,[=]{ + this->close(); + }); +} + + +void DevRenameDialog::lineEditSlot(const QString &str) +{ + if (str.length() >= INPUT_STRNAME_MIN && str.length() <= INPUT_STRNAME_MAX) { + acceptBtn->setDisabled(false); + tipLabel->setVisible(false); + } else if (INPUT_STRNAME_MIN > str.length()) { + acceptBtn->setDisabled(true); + tipLabel->setVisible(true); + }else { + tipLabel->setVisible(true); + acceptBtn->setDisabled(true); + } +} + +void DevRenameDialog::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + + QPainter painter(this); + painter.setPen(Qt::transparent); + + if (isblack) + painter.setBrush(Qt::black); + else + painter.setBrush(Qt::white); + + painter.setRenderHint(QPainter::Antialiasing); + + painter.drawRoundedRect(this->rect(),12,12); +} + +void DevRenameDialog::keyPressEvent(QKeyEvent * event) +{ + Q_UNUSED(event) + switch(event->key()) + { + case Qt::Key_Return: + case Qt::Key_Enter: + //if(acceptBtn->isEnabled())//setEnable状态后,emit click 信号不相应,无需判断 + emit acceptBtn->click(); + break; + case Qt::Key_Escape: + //if(rejectBtn->isEnabled())//setEnable状态后,emit click 信号不相应,无需判断 + emit rejectBtn->click(); + break; + } + +} diff --git a/ukcc-bluetooth/devrenamedialog.h b/ukcc-bluetooth/devrenamedialog.h new file mode 100644 index 0000000..641d72a --- /dev/null +++ b/ukcc-bluetooth/devrenamedialog.h @@ -0,0 +1,67 @@ +#ifndef DEVRENAMEDIALOG_H +#define DEVRENAMEDIALOG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define INPUT_STRNAME_MIN 1 +#define INPUT_STRNAME_MAX 32 + +class DevRenameDialog : public QDialog +{ + Q_OBJECT +public: + explicit DevRenameDialog(QWidget *parent = nullptr); + + ~DevRenameDialog(); + + void setDevName(const QString &); + + void initGsettings(); + +private slots: + void gsettingsSlot(const QString &); + +protected: + void paintEvent(QPaintEvent *); + void keyPressEvent(QKeyEvent *); + +public slots: + void lineEditSlot(const QString &); + +signals: + void nameChanged(QString); + +private: + void initUI(); + + int _fontSize; + + bool isblack = false; + + QString adapterOldName; + + QLabel *tipLabel = nullptr; + + QGSettings *gsettings = nullptr; + + QPushButton *closeBtn = nullptr; + + QPushButton *acceptBtn = nullptr; + + QPushButton *rejectBtn = nullptr; + + QLineEdit *lineEdit = nullptr; +}; + +#endif // DEVRENAMEDIALOG_H diff --git a/ukcc-bluetooth/loadinglabel.cpp b/ukcc-bluetooth/loadinglabel.cpp new file mode 100644 index 0000000..7b2d907 --- /dev/null +++ b/ukcc-bluetooth/loadinglabel.cpp @@ -0,0 +1,46 @@ +#include "loadinglabel.h" + +LoadingLabel::LoadingLabel(QObject *parent) +{ + m_timer = new QTimer(this); + m_timer->setInterval(100); + connect(m_timer,&QTimer::timeout,this,&LoadingLabel::refreshIconNum); +} + +LoadingLabel::~LoadingLabel() +{ +// delete m_timer; +} + +void LoadingLabel::setTimerStop() +{ + m_timer->stop(); +} + +void LoadingLabel::setTimerStart() +{ + m_timer->start(); +} + +void LoadingLabel::setTimeReresh(int m) +{ + m_timer->setInterval(m); +} + +void LoadingLabel::paintEvent(QPaintEvent *e) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.setPen(Qt::transparent); + + painter.drawPixmap(0,0,this->width(),this->height(),QIcon::fromTheme("ukui-loading-"+QString("%1").arg(i)).pixmap(this->width(),this->height())); +} + +void LoadingLabel::refreshIconNum() +{ +// qDebug() << Q_FUNC_INFO << QString::number(i,10); + this->update(); + if(i == 0) + i = 8; + i--; +} diff --git a/ukcc-bluetooth/loadinglabel.h b/ukcc-bluetooth/loadinglabel.h new file mode 100644 index 0000000..d7aa521 --- /dev/null +++ b/ukcc-bluetooth/loadinglabel.h @@ -0,0 +1,32 @@ +#ifndef LOADINGLABEL_H +#define LOADINGLABEL_H + +#include +#include +#include +#include +#include +#include + +class LoadingLabel : public QWidget +{ + Q_OBJECT +public: + explicit LoadingLabel(QObject *parent = nullptr); + ~LoadingLabel(); + void setTimerStop(); + void setTimerStart(); + void setTimeReresh(int); + +private Q_SLOTS: + void refreshIconNum(); + +protected: + void paintEvent(QPaintEvent *e); + +private: + QTimer *m_timer; + int i = 8; +}; + +#endif // LOADINGLABEL_H diff --git a/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm b/ukcc-bluetooth/translations/ukcc-bluetooth_bo_CN.qm new file mode 100644 index 0000000000000000000000000000000000000000..6bcd41ff924464012aa894505145f851d8b91526 GIT binary patch literal 1903 zcmbVNPe>GD6#rJ;wRY9d#Dj;5Pr--|iBWVYLB~a0%yf0xq#$=@=UaDZow41~Qo0p% zkq9a9AVhVkLq*adq6mTx7SW-uL3pU3Lv-oTrGD=l*V$EegJ5UBKl|SAz4v>+H+%f4 z+4kng%FTD}yI-bmzxbpv#_r(>Fc!MPSnwF0JB*#dRoxs54j#dIh7CUZgA2xz4`0Fb zQQ-I3I%73mHD7<;#qImr{?RyNwJUYYvFGr6;;q4h!J*F|fqN*pIPealCoakl&r}$|;p}>}qOP*`k55UULW!EOC&`o{DmH7(b6FkNj;GW`r2x4HTp|HFHFAtjG z<-sDncf&HtO<<6(!Cgg4vLu!LQLB)4=44(sa#9%c!j^g-i=Uw>=d83WRLHOeg_TG4 z%M1_Ci)dBv2GnyFd`HkW&2QC+o2^L6-faPils%04+OY*bu3k82=#@I#s>+}!DJ9kgFyJ#+pP0=PNCncH zw$chGNLa8lCR8z03MHJx?@JqH(SQ`i?sLnSwKy$ zkQdWZnxeB?q_cWnPh&g_qP<#Wt%^XRl!#hDE~V36o3Li8dAEUNYJY?$HY7Ev7S~J?Bg*W}8$*7vF^8R~+&zEBgIMWTL7ha##tZ{7qX&ZTDkt z@etr@M2#H1)D~37X!wc@_}SNt3{^oXDu%ee4u2X(V&4<9j{*)TgNjJ|)Bvt-WHP}= zA#~~m + + + + BlueToothMain + + Show icon on taskbar + འགན་བྱང་དུ་སོ་སྔོན་རིས་རྟགས་འཆར་བ། + /bluetooth/Show icon on taskbar + + + Discoverable by nearby Bluetooth devices + ཉེ་འཁོར་གྱི་སོ་སྔོན་སྒྲིག་ཆས་ཀྱི་བཤེར་རུང་བ། + /bluetooth/Discoverable + + + My Devices + སྒྲིག་ཆས། + + + Bluetooth + སོ་སྔོན། + + + Other Devices + སྒྲིག་ཆས་གཞན་དག + /bluetooth/Other Devices + + + Bluetooth adapter + སོ་སྔོན་འཚམ་སྒྲིག་ཆས། + /Bluetooth/Bluetooth adapter + + + Turn on + སྒོ་འབྱེད། + /bluetooth/Turn on Bluetooth + + + All + + + + Audio + དྲ་བྱང་། + + + Peripherals + + + + PC + + + + Phone + + + + Other + གཞན་དག + + + Bluetooth driver abnormal + + + + Auto discover Bluetooth audio devices + + /bluetooth/Automatically discover Bluetooth audio devices + + + + BlueToothMainWindow + + Bluetooth adapter is abnormal ! + སོ་སྔོན་བཀོད་སྒྲིག་ཡོ་ཆས་རྒྱུན་ལྡན་མིན། + + + Bluetooth + སོ་སྔོན། + + + Turn on : + སྒོ་འབྱེད། + + + Show icon on taskbar + འགན་བྱང་དུ་སོ་སྔོན་རིས་རྟགས་འཆར་བ། + + + Discoverable by nearby Bluetooth devices + ཉེ་འཁོར་གྱི་སོ་སྔོན་སྒྲིག་ཆས་ཀྱི་བཤེར་རུང་བ། + + + My Devices + སྒྲིག་ཆས། + + + Other Devices + སྒྲིག་ཆས་གཞན་དག + + + Audio + དྲ་བྱང་། + + + Other + གཞན་དག + + + + Bluetooth + + Bluetooth + སོ་སྔོན། + + + + BluetoothNameLabel + + Tip + གསལ་འདེབས། + + + Double-click to change the device name + ཟུང་རྡེབ་བྱས་ཏེ་སྒྲིག་ཆས་ཀྱི་མིང་བཅོས་རོགས། + + + The length of the device name does not exceed %1 characters ! + སྒྲིག་ཆས་ཀྱི་མིང་གི་རིང་ཚད་ཡིག་རྟགས་ཀྱི %1 ལས་བརྒལ་མི་རུང་། + + + Can now be found as "%1" + "%1" ལ་མ་གཏོགས་གཟིགས་དབང་མི་འདུག + + + Click to change the device name + + + + + DevRemoveDialog + + After it is removed, the PIN code must be matched for the next connection. + + + + Remove + བསུབ་པ། + + + Cancel + མེད་པར་བཟོ་བ + + + Are you sure to remove %1 ? + + + + Connection failed! Please remove it before connecting. + + + + + DevRenameDialog + + Rename + མིང་བསྐྱར་འདོགས། + + + Name + མིང་། + + + OK + གཏན་འཁེལ་བྱེད་པ། + + + Cancel + མེད་པར་བཟོ་བ + + + The value contains 1 to 32 characters + + + + + DeviceInfoItem + + Connecting + + + + Disconnecting + + + + Connected + འབྲེལ་མཐུད་བྱས་ཟིན། + + + Connect fail + + + + Disconnect fail + + + + send file + + + + remove + + + + Not Connected + + + + disconnect + + + + + MainWidget + + + མེད། + + + diff --git a/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.qm b/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.qm new file mode 100644 index 0000000000000000000000000000000000000000..23ac309c9993d315d78fd9b3439f18ce3c845765 GIT binary patch literal 2797 zcmbVOduSVV9RDS`Jet1jD0AX)zZNs<>^i${vQ=m8Luu`rrcG$Ab*q=VUy`HAUA?=+ zhJtfg?O>~2k*;M5I(#sY$#8#Yhi*fdGT&t~1X&qF87Nq_P@&b;@9)z5($rlBmNvg| z_x(J+ue(0{k+|WDxz{JYF57tinG>H}Z9vGf3nBYM2sv)T*@%$!X@r_9k@3?DpWHOE zH}8b|-=KyAbr3Uzn$Ir7jr&m7`=0`S5p^v*2DoXId3%(!+{MqWGQ74>*4beCWD2g6w<0aWb z16`BzQ{#uv^*C9uy*@5Vib;6s!CyL0`e(G$!&lXw|3E$Uab3ZpqzOubsFeQ6=9$f2Ex3^59mZS0T)p4@n<_v_F4DuV(_~% za8Z?L27FLf)EIA8y!HOML+>4H8k(uJ{To9n8Y&SRXA4ZMP3Ugp@*CVD?aM92#`a&c8b_(&G2TPcO)z@fJWY2+*MynKx8<%1+@klryc-LcgE8`(`u8z@Zv&geEZMkS#i z!wL!!UJersy(`vh=@Ja)RD>yu#p-r%jJU;zDs8MZwp8RxuQ2GmyU^nqU8c_ zz8CeEjm--0_~%~uXA=2$kGCNoYC+yX%L7*C`-%DxSiq8wB@L@229GJR(y;Gq@nS&{ z368}zo%SQf>p}#)hZNNakjbD95wc7KT~g#KYO5GlvD08_lK7|+Hu|$}Q0_fWeWlxt z>X`oB^(w(hC62W?e1S%#JkSEwnG$mTE3re2!T~cQ5aWq-OZj_f5qhdeJ7t92wM33ilHQe6eb;brr0dalacT(m8N)VjMKx$U zT3HdM>7fgf;Nb;Gi>JfeR>Re_;WgV=t%A9&bQ2k2!AiS~UQt|8>NU_Jhm;nb#Ej8% z?E8}f87OZBL_{-$t6%7@$ileOb0LRKLFClfEFCc>RBXKHjNQm-(2%2OhAhk=C38hb zcuSVaLN7dAZl4@E)rYchZsUIw!>3ttYvwq$pk~1?|IASf8SyT#eDX8`kMR)f)2%T7 E0!Los?EnA( literal 0 HcmV?d00001 diff --git a/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.ts b/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.ts new file mode 100644 index 0000000..a24be37 --- /dev/null +++ b/ukcc-bluetooth/translations/ukcc-bluetooth_zh_CN.ts @@ -0,0 +1,331 @@ + + + + + BlueToothMain + + + Bluetooth + 蓝牙 + + + + Turn on + Turn on : + 开启 + /bluetooth/Turn on Bluetooth + + + + Bluetooth adapter + 蓝牙适配器 + /Bluetooth/Bluetooth adapter + + + + Show icon on taskbar + 在任务栏显示蓝牙图标 + /bluetooth/Show icon on taskbar + + + + Discoverable by nearby Bluetooth devices + 可被附近的蓝牙设备发现 + /bluetooth/Discoverable + + + + Auto discover Bluetooth audio devices + 自动发现蓝牙音频设备 + /bluetooth/Automatically discover Bluetooth audio devices + + + + My Devices + 我的设备 + + + + Other Devices + 其他设备 + /bluetooth/Other Devices + + + + Bluetooth driver abnormal + 蓝牙驱动异常 + + + No Bluetooth adapter detected! + 未检测到蓝牙适配器! + + + + All + 所有 + + + + Audio + 音频设备 + + + + Peripherals + 键鼠设备 + + + + PC + 电脑 + + + + Phone + 手机 + + + + Other + 其他 + + + Bluetooth adapter is not detected! + 未检测到蓝牙适配器! + + + + BlueToothMainWindow + + Bluetooth adapter is abnormal ! + 蓝牙适配器异常! + + + Bluetooth adapter not detected ! + 未检测到蓝牙适配器! + + + Bluetooth + 蓝牙 + + + Turn on : + Turn on + 开启 + + + Adapter List + 蓝牙适配器 + + + Show icon on taskbar + 在任务栏显示蓝牙图标 + + + Discoverable by nearby Bluetooth devices + 可被附近的蓝牙设备发现 + + + My Devices + 我的设备 + + + Other Devices + 蓝牙设备 + + + All + 所有 + + + Audio + 音频设备 + + + Peripherals + 键鼠设备 + + + PC + 电脑 + + + Phone + 手机 + + + Other + 其他 + + + + Bluetooth + + + Bluetooth + 蓝牙 + + + + BluetoothNameLabel + + + Click to change the device name + Double-click to change the device name + 点击修改设备名称 + + + + + Can now be found as "%1" + 现在可被发现为"%1" + + + + Tip + 提示 + + + + The length of the device name does not exceed %1 characters ! + 设备名称的长度不超过 %1 个字符! + + + + DevRemoveDialog + + + + After it is removed, the PIN code must be matched for the next connection. + 移除后,下一次连接可能需匹配PIN码。 + + + + Remove + 移除 + + + + Cancel + 取消 + + + + Connection failed! Please remove it before connecting. + 连接失败,请先移除后再次连接! + + + + + Are you sure to remove %1 ? + 确定移除"%1"? + + + + DevRenameDialog + + + Rename + 修改名称 + + + + Name + 设备名称 + + + + The value contains 1 to 32 characters + 长度必须为 1-32 个字符 + + + The input character length exceeds the limit + 输入字符长度超过限制! + + + + OK + 确定 + + + + Cancel + 取消 + + + + DeviceInfoItem + + + Connecting + 正在连接 + + + + Disconnecting + 正在断连 + + + + Connected + 已连接 + + + + Not Connected + 未连接 + + + + + disconnect + 断开连接 + + + Paired + 已匹配 + + + + Connect fail + 连接失败 + + + + Disconnect fail + 断连失败 + + + Send files + 发送文件 + + + Remove + 移除 + + + cancel + 取消 + + + + + remove + 移除 + + + + + send file + 发送文件 + + + Sure to remove, + 确定删除, + + + After removal, the next connection requires matching PIN code! + 移除后,下一次连接需要匹配的PIN码! + + + diff --git a/ukcc-bluetooth/ukcc-bluetooth.json b/ukcc-bluetooth/ukcc-bluetooth.json new file mode 100644 index 0000000..1e81138 --- /dev/null +++ b/ukcc-bluetooth/ukcc-bluetooth.json @@ -0,0 +1,3 @@ +{ + "Keys" : [ ] +} diff --git a/ukcc-bluetooth/ukcc-bluetooth.pro b/ukcc-bluetooth/ukcc-bluetooth.pro new file mode 100644 index 0000000..a339027 --- /dev/null +++ b/ukcc-bluetooth/ukcc-bluetooth.pro @@ -0,0 +1,85 @@ +QT += gui dbus + +include(../environment.pri) + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets dbus + +TEMPLATE = lib +CONFIG += plugin \ + += c++11 \ + link_pkgconfig + +PKGCONFIG += gsettings-qt \ + kysdk-qtwidgets + +LIBS += -lukcc + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS +exists(/etc/apt/ota_version) +{ + DEFINES += DEVICE_IS_INTEL +} + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + bluetooth.cpp \ + bluetoothdbusservice.cpp \ + bluetoothmain.cpp \ + #bluetoothmainwindow.cpp \ + bluetoothnamelabel.cpp \ + devicebase.cpp \ + deviceinfoitem.cpp \ + devremovedialog.cpp \ + devrenamedialog.cpp \ + loadinglabel.cpp \ + ukccbluetoothconfig.cpp + +HEADERS += \ + bluetooth.h \ + bluetoothdbusservice.h \ + bluetoothmain.h \ + #bluetoothmainwindow.h \ + bluetoothnamelabel.h \ + config.h \ + devicebase.h \ + deviceinfoitem.h \ + devremovedialog.h \ + devrenamedialog.h \ + loadinglabel.h \ + ukccbluetoothconfig.h + +DISTFILES += ukcc-bluetooth.json + +TRANSLATIONS += \ + translations/ukcc-bluetooth_zh_CN.ts \ + translations/ukcc-bluetooth_bo_CN.ts + +system("lrelease translations/*.ts") + +# Default rules for deployment. +unix { +# target.path = $$[QT_INSTALL_PLUGINS]/generic + target.path = $$FILES_INSTALL_DIR +} + +qm_files.files += translations/*.qm +qm_files.path += $${SHARE_TRANSLATIONS_INSTALL_DIR} + +ts_files.files += translations/*.ts +ts_files.path += $${SHARE_TRANSLATIONS_INSTALL_DIR} + +INSTALLS += qm_files \ + ts_files \ + target + +RESOURCES += \ + ukcc-bluetooth.qrc + diff --git a/ukcc-bluetooth/ukcc-bluetooth.qrc b/ukcc-bluetooth/ukcc-bluetooth.qrc new file mode 100644 index 0000000..4d8ed66 --- /dev/null +++ b/ukcc-bluetooth/ukcc-bluetooth.qrc @@ -0,0 +1,3 @@ + + + diff --git a/ukcc-bluetooth/ukccbluetoothconfig.cpp b/ukcc-bluetooth/ukccbluetoothconfig.cpp new file mode 100644 index 0000000..e98a839 --- /dev/null +++ b/ukcc-bluetooth/ukccbluetoothconfig.cpp @@ -0,0 +1,70 @@ +#include "ukccbluetoothconfig.h" + +bool ukccbluetoothconfig::m_isIntel = false; + +ukccbluetoothconfig::ukccbluetoothconfig() +{ + +} + +void ukccbluetoothconfig::launchBluetoothServiceStart(const QString &processName) +{ + qDebug () << Q_FUNC_INFO << __LINE__; + QProcess *process = new QProcess(); + QString cmd = processName; + //cmd.append(" -o"); + qDebug () << Q_FUNC_INFO << cmd << __LINE__; + process->startDetached(cmd); +} + +void ukccbluetoothconfig::killAppProcess(const quint64 &processId) +{ +// QString strCommand = "ps -ef|grep " + processName + " |grep -v grep |awk '{print $2}'"; +// QList processId; +// checkProcessRunning(processName,processId); +// for(quint64 tempId : processId) +// { + qDebug () << Q_FUNC_INFO << "========================" << processId; + QProcess *process = new QProcess(); + QString cmd = QString("kill -9 %1").arg(processId); + process->startDetached(cmd); +// } +} + +bool ukccbluetoothconfig::checkProcessRunning(const QString &processName, QList &listProcessId) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + + bool res(false); + QString strCommand; + //if(processName == BluetoothServiceExePath) + // strCommand = "ps -ef|grep '" + processName + " -o' |grep -v grep |awk '{print $2}'"; + //else + strCommand = "ps -ef|grep '" + processName + "' |grep -v grep |awk '{print $2}'"; + qDebug() << Q_FUNC_INFO << strCommand << __LINE__; + + QByteArray ba = strCommand.toLatin1(); + const char* strFind_ComName = ba.data(); + //const char* strFind_ComName = convertQString2char(strCommand); + FILE * pPipe = popen(strFind_ComName, "r"); + if (pPipe) + { + std::string com; + char name[512] = { 0 }; + while (fgets(name, sizeof(name), pPipe) != NULL) + { + int nLen = strlen(name); + if (nLen > 0 + && name[nLen - 1] == '\n') + //&& name[0] == '/') + { + name[nLen - 1] = '\0'; + listProcessId.append(atoi(name)); + res = true; + break; + } + } + pclose(pPipe); + } + return res; +} diff --git a/ukcc-bluetooth/ukccbluetoothconfig.h b/ukcc-bluetooth/ukccbluetoothconfig.h new file mode 100644 index 0000000..de26ddd --- /dev/null +++ b/ukcc-bluetooth/ukccbluetoothconfig.h @@ -0,0 +1,21 @@ +#ifndef UKCCBLUETOOTHCONFIG_H +#define UKCCBLUETOOTHCONFIG_H + +#include +#include + +#include "config.h" + +class ukccbluetoothconfig +{ +public: + ukccbluetoothconfig(); + + static void launchBluetoothServiceStart(const QString &processName); + static void killAppProcess(const quint64 &processId); + static bool checkProcessRunning(const QString &processName, QList &listProcessId); + + static bool m_isIntel; +}; + +#endif // UKCCBLUETOOTHCONFIG_H diff --git a/ukui-bluetooth.pro b/ukui-bluetooth.pro new file mode 100644 index 0000000..84c8558 --- /dev/null +++ b/ukui-bluetooth.pro @@ -0,0 +1,24 @@ +###################################################################### +# Automatically generated by qmake (3.1) Thu Mar 4 22:02:53 2021 +###################################################################### + +TEMPLATE = subdirs +INCLUDEPATH += . + +SUBDIRS += ukui-bluetooth \ + ukcc-bluetooth \ + profileDaemon \ + service + +# The following define makes your compiler warn you if you use any +# feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +#TRANSLATIONS += translations/ukui-bluetooth_zh_CN.ts diff --git a/ukui-bluetooth/activeConn/activeconnectionwidget.cpp b/ukui-bluetooth/activeConn/activeconnectionwidget.cpp new file mode 100644 index 0000000..61a4cd3 --- /dev/null +++ b/ukui-bluetooth/activeConn/activeconnectionwidget.cpp @@ -0,0 +1,126 @@ +#include "activeconnectionwidget.h" +#include "config/xatom-helper.h" +#include "config/config.h" + +ActiveConnectionWidget::ActiveConnectionWidget(QString address, QString name, QString type, int rssi) : + devAddr(address), + devName(name), + devType(type), + devRSSI(rssi) +{ + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + settings = new QGSettings("org.ukui.style"); + connect(settings,&QGSettings::changed,this,&ActiveConnectionWidget::GSettingsChanges); + } + + //窗管协议 + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); + + QPalette palette; + if(settings->get("style-name").toString() == "ukui-default" || settings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(255,255,255)); + }else{ + palette.setColor(QPalette::Background,QColor(0,0,0)); + } + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("Bluetooth Connection")); + + this->setAttribute(Qt::WA_DeleteOnClose); + this->setPalette(palette); + this->setAutoFillBackground(true); + this->setFixedSize(420, 154); + + window_icon = new QLabel(this); + window_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); + + window_title = new QLabel(tr("Bluetooth Connections"),this); + window_title->setFixedSize(300,20); + + window_close = new QPushButton(this); + window_close->setIcon(QIcon::fromTheme("window-close-symbolic")); + window_close->setProperty("isWindowButton", 0x2); + window_close->setProperty("useIconHighlightEffect", 0x8); + window_close->setFlat(true); + connect(window_close, &QPushButton::clicked, this, &ActiveConnectionWidget::onClick_close_btn); + + tip_txt = new QLabel(this); + tip_txt->setFixedWidth(380); + QFontMetrics fontMetrics(tip_txt->font()); + QString tip = QString(tr("Found audio device \"") + devName + tr("\", connect it or not?")); + QString _tip = fontMetrics.elidedText(tip, + Qt::ElideMiddle, + tip_txt->width()); + if (tip != _tip) + tip_txt->setToolTip(tip); + tip_txt->setText(_tip); + + connect_btn = new QPushButton(tr("Connect"),this); + connect(connect_btn, &QPushButton::clicked, this, &ActiveConnectionWidget::onClick_connect_btn); + cancel_btn = new QPushButton(tr("Cancel"),this); + connect(cancel_btn, &QPushButton::clicked, this, &ActiveConnectionWidget::onClick_cancel_btn); + + window_icon->setGeometry(8,8,22,22); + window_title->setGeometry(36, 9, 300, 20); + window_close->setGeometry(385,4,30,30); + tip_txt->setGeometry(24,48,380,28); + cancel_btn->setGeometry(188,94,96,36); + connect_btn->setGeometry(300,94,96,36); + + QRect desktop; + QDesktopWidget *desktop_widget = QApplication::desktop(); + desktop = desktop_widget->availableGeometry(); + this->move(QPoint(desktop.right()-this->width(),desktop.bottom()-this->height())); +} + +ActiveConnectionWidget::~ActiveConnectionWidget() +{ + qDebug() << Q_FUNC_INFO; +} + +void ActiveConnectionWidget::onClick_close_btn() +{ + qDebug() << Q_FUNC_INFO << "close"; + onClick_cancel_btn(); +} + +void ActiveConnectionWidget::onClick_connect_btn() +{ + qDebug() << Q_FUNC_INFO << "accpet"; + emit replyActiveConnection(devAddr, true); + this->hide(); + this->deleteLater(); +} + +void ActiveConnectionWidget::onClick_cancel_btn() +{ + qDebug() << Q_FUNC_INFO << "cancel"; + emit replyActiveConnection(devAddr, false); + this->hide(); + this->deleteLater(); +} + +void ActiveConnectionWidget::GSettingsChanges(const QString &key) +{ + QPalette palette; + qDebug() << Q_FUNC_INFO << key; + if(key == "styleName"){ + if(settings->get("style-name").toString() == "ukui-default" || settings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(Qt::white)); + }else{ + palette.setColor(QPalette::Background,QColor(Qt::black)); + } + this->setPalette(palette); + this->update(); + } + if (key == "systemFontSize") { + QFontMetrics fontMetrics(tip_txt->font()); + QString tip = fontMetrics.elidedText(QString(tr("Found audio device \"") + devName + tr("\", connect it or not?")), + Qt::ElideMiddle, + tip_txt->width()); + tip_txt->setText(tip); + } +} diff --git a/ukui-bluetooth/activeConn/activeconnectionwidget.h b/ukui-bluetooth/activeConn/activeconnectionwidget.h new file mode 100644 index 0000000..ce089c8 --- /dev/null +++ b/ukui-bluetooth/activeConn/activeconnectionwidget.h @@ -0,0 +1,53 @@ +#ifndef ACTIVECONNECTIONWIDGET_H +#define ACTIVECONNECTIONWIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class ActiveConnectionWidget : public QWidget +{ + Q_OBJECT +public: + explicit ActiveConnectionWidget(QString address, QString name, QString type, int rssi); + ~ActiveConnectionWidget(); +private: + double scale; + + int devRSSI; + + QString devAddr; + QString devName; + QString devType; + + QGSettings *settings = nullptr; + + QLabel *window_icon = nullptr; + QLabel *window_title = nullptr; + QLabel *tip_txt = nullptr; + + QPushButton *window_close = nullptr; + QPushButton *connect_btn = nullptr; + QPushButton *cancel_btn = nullptr; + +private slots: + void onClick_close_btn(); + + void onClick_connect_btn(); + + void onClick_cancel_btn(); + + void GSettingsChanges(const QString &key); + +signals: + void replyActiveConnection(QString,bool); +}; + +#endif // ACTIVECONNECTIONWIDGET_H diff --git a/ukui-bluetooth/component/bluetoothsettinglabel.cpp b/ukui-bluetooth/component/bluetoothsettinglabel.cpp new file mode 100644 index 0000000..cb27087 --- /dev/null +++ b/ukui-bluetooth/component/bluetoothsettinglabel.cpp @@ -0,0 +1,102 @@ +#include "bluetoothsettinglabel.h" + +BluetoothSettingLabel::BluetoothSettingLabel(QWidget *parent) : QLabel(parent) +{ + _MStatus = Normal; + this->setFixedSize(420,50); + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,[=]{ + this->update(); + }); + } + const QByteArray transparency_id(TRANSPARENCY_SETTINGS); + if(QGSettings::isSchemaInstalled(transparency_id)){ + transparency_gsettings = new QGSettings(transparency_id); + } + if(QGSettings::isSchemaInstalled(transparency_id)){ + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + connect(transparency_gsettings, &QGSettings::changed, this, [=] { + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + this->update(); + }); + } +} + +BluetoothSettingLabel::~BluetoothSettingLabel() { + +} + +QColor BluetoothSettingLabel::getPainterBrushColor() +{ + QColor color; + switch (_MStatus) { + case Status::Normal: + if(StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(0, 0, 0); + else { + color = QColor(255,255,255); + } + break; + case Status::Hover: + color = QColor("#2FB3E8"); + break; + case Status::Click: + color = QColor("#1699CF"); + break; + default: + if(StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(0, 0, 0); + else { + color = QColor(255,255,255); + } + break; + } + return color; +} + +void BluetoothSettingLabel::enterEvent(QEvent *event) { + Q_UNUSED(event); + _MStatus = Hover; + setCursor(Qt::PointingHandCursor); + this->update(); +} + +void BluetoothSettingLabel::leaveEvent(QEvent *event) { + Q_UNUSED(event); + _MStatus = Normal; + this->update(); +} + +void BluetoothSettingLabel::mousePressEvent(QMouseEvent *ev) { + Q_UNUSED(ev); + _MStatus = Click; + this->update(); +} + +void BluetoothSettingLabel::mouseReleaseEvent(QMouseEvent *ev) { + Q_UNUSED(ev); + _MStatus = Normal; + this->update(); +// Config::OpenBluetoothSettings(); + emit clickSignal(); + emit hideFeature(); +} + +void BluetoothSettingLabel::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + QPainter painter(this); + painter.save(); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(QColor(Qt::transparent)); + painter.drawRoundedRect(this->rect(),12,12,Qt::AbsoluteSize); + //painter.drawRect(this->rect()); + painter.restore(); + if(StyleSettings->get("style-name").toString() == "ukui-light") + painter.setPen(QColor(Qt::black)); + else + painter.setPen(QColor(Qt::white)); + painter.setPen(getPainterBrushColor()); + painter.drawText(25,10,420,50,Qt::AlignLeft,tr("Bluetooth Settings")); +} diff --git a/ukui-bluetooth/component/bluetoothsettinglabel.h b/ukui-bluetooth/component/bluetoothsettinglabel.h new file mode 100644 index 0000000..5c9947b --- /dev/null +++ b/ukui-bluetooth/component/bluetoothsettinglabel.h @@ -0,0 +1,49 @@ +#ifndef BLUETOOTHSETTINGLABEL_H +#define BLUETOOTHSETTINGLABEL_H + +#include +#include +#include +#include +#include "config/config.h" + +#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + +class BluetoothSettingLabel : public QLabel +{ + Q_OBJECT +public: + BluetoothSettingLabel(QWidget *parent); + ~BluetoothSettingLabel(); + + enum Status{ + Hover = 0, + Normal, + Click + }; + Q_ENUM(Status) + +private: + + QGSettings *StyleSettings = nullptr; + QGSettings *transparency_gsettings = nullptr; + double tran =1; + Status _MStatus; + + void drawBackground(QPainter &painter); + QColor getPainterBrushColor(); + +signals: + void hideFeature(); + void clickSignal(); + +protected: + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); + void mousePressEvent(QMouseEvent *ev); + void mouseReleaseEvent(QMouseEvent *ev); + void paintEvent(QPaintEvent *event); +}; + +#endif // BLUETOOTHSETTINGLABEL_H diff --git a/ukui-bluetooth/component/kyfiledialog.cpp b/ukui-bluetooth/component/kyfiledialog.cpp new file mode 100644 index 0000000..814303d --- /dev/null +++ b/ukui-bluetooth/component/kyfiledialog.cpp @@ -0,0 +1,75 @@ +#include "kyfiledialog.h" + +//被注释部分主要用于文件夹的选择,用于目录传输功能,暂不深度开发 +KyFileDialog::KyFileDialog(QWidget *parent) + : QFileDialog(parent) +{ + openButton = NULL; + listView = NULL; + treeView = NULL; + _selectedFiles.clear(); + + this->setWindowIcon(QIcon::fromTheme("preferences-system-bluetooth")); + this->setWindowTitle(QString(tr("Bluetooth File"))); + this->setOption(QFileDialog::DontUseNativeDialog, true); + this->setFileMode(QFileDialog::ExistingFiles); +// QList btns = this->findChildren(); + +// for (int i = 0; i < btns.size(); ++i) { +// QString text = btns[i]->text(); +// if (text.toLower().contains("open") || text.toLower().contains("choose") +// || btns[i]->text() == "打开(&O)" || btns[i]->text() == "选择(&C)") +// { +// openButton = btns[i]; +// break; +// } +// } + +// if (!openButton) { +// qDebug() << "-- NULL --"; +// return; +// } + +// openButton->installEventFilter(this); +// openButton->disconnect(SIGNAL(clicked())); +// connect(openButton, SIGNAL(clicked()), this, SLOT(chooseClicked())); + + //多选 + listView = findChild("listView"); + if (listView) + listView->setSelectionMode(QAbstractItemView::ExtendedSelection); + + treeView = findChild(); + if (treeView) + treeView->setSelectionMode(QAbstractItemView::ExtendedSelection); +} + +QStringList KyFileDialog::getselectedFiles() +{ + return _selectedFiles; +} + +void KyFileDialog::chooseClicked() +{ + QModelIndexList indexList = listView->selectionModel()->selectedIndexes(); + foreach (QModelIndex index, indexList) + { + if (index.column()== 0) + _selectedFiles.append(this->directory().absolutePath() + "/" + index.data().toString()); + } + QDialog::accept(); +} + +//文件和文件夹均可选择 +//bool KyFileDialog::eventFilter( QObject* watched, QEvent* event ) +//{ +// QPushButton *btn = qobject_cast(watched); +// if (btn) +// { +// if(event->type()==QEvent::EnabledChange) { +// if (!btn->isEnabled()) +// btn->setEnabled(true); +// } +// } +// return QWidget::eventFilter(watched, event); +//} diff --git a/ukui-bluetooth/component/kyfiledialog.h b/ukui-bluetooth/component/kyfiledialog.h new file mode 100644 index 0000000..3a45b19 --- /dev/null +++ b/ukui-bluetooth/component/kyfiledialog.h @@ -0,0 +1,38 @@ +#ifndef KYFILEDIALOG_H +#define KYFILEDIALOG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//此类意在改写QFileDialog无法同时选定文件和文件夹的问题 +class KyFileDialog : public QFileDialog +{ + Q_OBJECT +public: + explicit KyFileDialog(QWidget *parent = Q_NULLPTR); + + QStringList getselectedFiles(); + + //取消禁止选择文件 +// bool eventFilter( QObject* watched, QEvent* event ); + + public slots: + void chooseClicked(); + + private: + QListView *listView; + QTreeView *treeView; + QPushButton *openButton; + QStringList _selectedFiles; +}; + +#endif // KYFILEDIALOG_H diff --git a/ukui-bluetooth/component/qdevitem.cpp b/ukui-bluetooth/component/qdevitem.cpp new file mode 100644 index 0000000..2f6138f --- /dev/null +++ b/ukui-bluetooth/component/qdevitem.cpp @@ -0,0 +1,422 @@ +#include "qdevitem.h" +#include + +QDevItem::QDevItem(QString address, QStringList deviceinfo, bool connected, QWidget *parent): + QFrame(parent), + _Address(address), + _Connected(connected), + _Name(deviceinfo.at(0)), + _Battery(deviceinfo.at(2)), + _MType(deviceinfo.at(1)) +{ + initMap(); + qDebug() << " get dev Battery : " << deviceinfo.at(0) << _Battery; + + if(QGSettings::isSchemaInstalled("org.ukui.style")) { + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,[=]{ + this->update(); + }); + } + const QByteArray transparency_id(TRANSPARENCY_SETTINGS); + if(QGSettings::isSchemaInstalled(transparency_id)){ + transparency_gsettings = new QGSettings(transparency_id); + } + if(QGSettings::isSchemaInstalled(transparency_id)){ + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + } + + this->setFixedSize(404,50); + this->setObjectName(address); + _MStatus = Status::Nomal; + _clicked = false; + _pressFlag = false; + + InitMemberVariables(); +} + +QDevItem::~QDevItem() +{ + +} + +void QDevItem::initMap() { + typeMap = new QMap(); + typeMap->insert(QString("phone"), QIcon::fromTheme("phone-symbolic")); + typeMap->insert(QString("computer"), QIcon::fromTheme("video-display-symbolic")); + typeMap->insert(QString("headset"), QIcon::fromTheme("audio-headset-symbolic")); + typeMap->insert(QString("headphones"), QIcon::fromTheme("audio-headphones-symbolic")); + typeMap->insert(QString("audiovideo"), QIcon::fromTheme("audio-speakers-symbolic")); + typeMap->insert(QString("keyboard"), QIcon::fromTheme("input-keyboard-symbolic")); + typeMap->insert(QString("mouse"), QIcon::fromTheme("input-mouse-symbolic")); +} + +void QDevItem::SendMessage(bool connected) +{ + QString text; + if (connected) { + text = QString(tr("The connection with the Bluetooth device “%1” is successful!").arg(_Name)); + + } else { + text = QString(tr("Bluetooth device “%1” disconnected!").arg(_Name)); + } + Config::SendNotifyMessage(text); +} + +void QDevItem::connectedChangedSlot(bool connected) { + qDebug() << Q_FUNC_INFO << connected; + if (_clicked) { + _iconTimer->stop(); + _clicked = false; + } + if (_Connected == connected) + return; + _Connected = connected; + qDebug() << Q_FUNC_INFO << __LINE__; + update(); + SendMessage(connected); +} + +void QDevItem::InitMemberVariables() +{ + _iconTimer = new QTimer(this); + + connect(_iconTimer,&QTimer::timeout,this,[=]{ + if (iconFlag == 0) + iconFlag = 7; + iconFlag--; + update(); + }); +} + +void QDevItem::enterEvent(QEvent *event) +{ + Q_UNUSED(event); + _leaved = false; + _MStatus = Status::Hover; + update(); +} + +void QDevItem::leaveEvent(QEvent *event) +{ + Q_UNUSED(event); + _leaved = true; + _MStatus = Status::Nomal; + update(); +} + +void QDevItem::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + _pressFlag = true; + _MStatus = Status::Click; + this->update(); + } +} + +void QDevItem::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton && _pressFlag) { + if (_leaved) + _MStatus = Status::Nomal; + else + _MStatus = Status::Hover; + MouseClickedFunc(); + } +} + +void QDevItem::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(QColor(Qt::transparent)); + + DrawBackground(painter); + DrawStatusIcon(painter); + DrawText(painter); + DrawBattery(painter); +} + +/************************************************ + * @brief 根据设备状态返回自定义控件的背景色 + * @param null + * @return 返回类型为QColor +*************************************************/ +QColor QDevItem::getPainterBrushColor() +{ + QColor color; + switch (_MStatus) { + case Status::Nomal: + if(StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(255,255,255,0); + else { + color = QColor(QPalette::Base); + color.setAlpha(0); + } + break; + case Status::Hover: + if(StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(217,217,217,tran); + else + color = QColor(55, 55, 59, tran); + break; + case Status::Click: + if(StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(209, 209, 209,tran); + else + color = QColor(102, 102, 102, tran); + break; + default: + if(StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(255,255,255,0); + else{ + color = QColor(QPalette::Base); + color.setAlpha(0); + } + break; + } + + return color; +} + +/************************************************ + * @brief 根据设备状态返回自定义控件的设备状态的颜色 + * @param null + * @return 返回类型为QColor +*************************************************/ +QColor QDevItem::getDevStatusColor() +{ + QColor color; + if (_Connected) { + if (_MStatus == Status::Click) + color = QColor("#1699CF"); + else + color = QColor("#2FB3E8"); + } else { + if(StyleSettings->get("style-name").toString() == "ukui-light") { + if (_MStatus == Status::Click) + color = QColor("#E0E0E0"); + else + color = QColor("#EFEFEF"); + } else { + if (_MStatus == Status::Click) + color = QColor("#444444"); + else + color = QColor("#666666"); + } + color.setAlpha(tran); + } + + return color; +} + +/************************************************ + * @brief 根据设备类型返回对应的主题图标 + * @param null + * @return 返回类型为QPixmap的图标 +*************************************************/ +QPixmap QDevItem::getDevTypeIcon() +{ + QIcon icon; + if (_clicked) { + icon = QIcon::fromTheme("ukui-loading-" + QString::number(iconFlag)); + } else { + if (typeMap->keys().contains(_MType)) + icon = typeMap->value(_MType); + else + icon = QIcon::fromTheme("bluetooth-symbolic"); + } + return icon.pixmap(18,18); +} + +/************************************************ + * @brief 绘制自定义控件的背景色 + * @param painter + * @return null +*************************************************/ +void QDevItem::DrawBackground(QPainter &painter) +{ + painter.save(); + painter.setBrush(getPainterBrushColor()); + painter.drawRoundedRect(this->rect(),8,8,Qt::AbsoluteSize); + painter.restore(); +} + +/************************************************ + * @brief 绘制自定义控件的设备状态图标 + * @param painter + * @return null +*************************************************/ +void QDevItem::DrawStatusIcon(QPainter &painter) +{ + QPixmap batteryPixmap; + + painter.save(); + painter.setBrush(getDevStatusColor()); + painter.drawEllipse(16,7,36,36); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + + if(StyleSettings->get("style-name").toString() == "ukui-light") { + painter.setPen(QColor(Qt::black)); + batteryPixmap = getDevTypeIcon(); + } else { + if (StyleSettings->get("icon-theme-name").toString() == "ukui-icon-theme-classical") + batteryPixmap = getDevTypeIcon(); + else { + painter.setPen(QColor(Qt::white)); + batteryPixmap = loadSvg(getDevTypeIcon(), PixmapColor::WHITE); + } + } + + style()->drawItemPixmap(&painter, QRect(25, 16, 18, 18), Qt::AlignCenter, batteryPixmap); + painter.restore(); +} + +/************************************************ + * @brief 绘制自定义控件的文字 + * @param painter + * @return null +*************************************************/ +void QDevItem::DrawText(QPainter &painter) +{ + QString nName; + nName = _Name; + painter.save(); + if(StyleSettings->get("style-name").toString() == "ukui-light") + painter.setPen(QColor(Qt::black)); + else + painter.setPen(QColor(Qt::white)); + int fontSize = StyleSettings->get("system-font-size").toInt(); + if (fontSize > 15) + fontSize = 15; + if (fontSize < 10) + fontSize = 10; + float shownum = 0; + for (int i = 0; i < _Name.size(); i++) { + QChar ch = _Name.at(i); + ushort uNum = ch.unicode(); + if ((uNum >= 0x4E00 && uNum <= 0x9FA5)) + shownum += 1.7; + else if (ch == 'm' || ch == 'M') + shownum += 1.5; + else + shownum += 1; + if (shownum + 1.5 >= FontTable[fontSize - 10]) { + nName.remove(i, _Name.size() - i); + nName.append("..."); + this->setToolTip(_Name); + break; + } + } + + painter.drawText(62,12,260,28,Qt::AlignLeft, nName); + painter.restore(); +} + +/************************************************ + * @brief 绘制电池 + * @param painter + * @return null +*************************************************/ +void QDevItem::DrawBattery(QPainter &painter) +{ + int battery = _Battery.toInt(); + + if (battery == -1 || !_Connected) + return; + + painter.save(); + + QString batteryIcon = QString("battery-level-") + QString::number(battery / 10 * 10) + QString("-symbolic"); + QString batteryString = _Battery + QString("%"); + QPixmap batteryPixmap; + + if(StyleSettings->get("style-name").toString() == "ukui-light") { + painter.setPen(QColor(Qt::black)); + batteryPixmap = loadSvg(QIcon::fromTheme(batteryIcon).pixmap(20,20), PixmapColor::BLACK); + } else { + painter.setPen(QColor(Qt::white)); + batteryPixmap = loadSvg(QIcon::fromTheme(batteryIcon).pixmap(20,20), PixmapColor::WHITE); + } + + painter.drawText(344,12,52,28,Qt::AlignLeft, batteryString); + style()->drawItemPixmap(&painter, QRect(320, 14, 20, 20), Qt::AlignCenter, batteryPixmap); + painter.restore(); +} + +/************************************************ + * @brief 当鼠标在该自定义控件点击时,执行该函数 + * @param null + * @return null +*************************************************/ +void QDevItem::MouseClickedFunc() +{ + _clicked = true; + _pressFlag = false; + + emit devConnect(!_Connected); + + //设置_iconTimer定时器开始,来实现loading效果 + if (!_iconTimer->isActive()) { + _iconTimer->start(110); + + //以下这个只执行一次的定时器,用来设置点击后加载动画的持续时间 + QTimer::singleShot(7000,this,[=]{ + if (_clicked) { + _iconTimer->stop(); + _clicked = false; + update(); + } + }); + } +} + + + +const QPixmap QDevItem::loadSvg(const QPixmap &source, const PixmapColor &cgColor) +{ + QImage img = source.toImage(); + for (int x = 0; x < img.width(); x++) { + for (int y = 0; y < img.height(); y++) { + auto color = img.pixelColor(x, y); + if (color.alpha() > 0) { + switch (cgColor) { + case PixmapColor::WHITE: + color.setRed(255); + color.setGreen(255); + color.setBlue(255); + img.setPixelColor(x, y, color); + break; + case PixmapColor::BLACK: + color.setRed(0); + color.setGreen(0); + color.setBlue(0); + img.setPixelColor(x, y, color); + break; + case PixmapColor::GRAY: + color.setRed(152); + color.setGreen(163); + color.setBlue(164); + img.setPixelColor(x, y, color); + break; + case PixmapColor::BLUE: + color.setRed(61); + color.setGreen(107); + color.setBlue(229); + img.setPixelColor(x, y, color); + break; + default: + return source; + break; + } + } + } + } + return QPixmap::fromImage(img); +} + +bool QDevItem::isConnected() { + return _Connected; +} diff --git a/ukui-bluetooth/component/qdevitem.h b/ukui-bluetooth/component/qdevitem.h new file mode 100644 index 0000000..74d29a5 --- /dev/null +++ b/ukui-bluetooth/component/qdevitem.h @@ -0,0 +1,92 @@ +#ifndef QDEVITEM_H +#define QDEVITEM_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config/config.h" + +#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + +class QDevItem : public QFrame +{ + Q_OBJECT +public: + enum Status{ + Hover = 0, + Nomal, + Click, + }; + Q_ENUM(Status) + + enum PixmapColor { + WHITE = 0, + BLACK, + GRAY, + BLUE, + }; + Q_ENUM(PixmapColor) + + int FontTable[6] = {32, 30, 26, 24, 23, 22}; + + QDevItem(QString address, QStringList deviceinfo, bool connected, QWidget *parent = nullptr); + ~QDevItem(); + const QPixmap loadSvg(const QPixmap &source, const PixmapColor &color); + + void InitMemberVariables(); + bool isConnected(); + +signals: + void devConnect(bool); + +protected: + void enterEvent(QEvent *); + void leaveEvent(QEvent *); + void mousePressEvent(QMouseEvent *); + void mouseReleaseEvent(QMouseEvent *); + void paintEvent(QPaintEvent *); + +private: + QMap *typeMap = nullptr; + QColor getPainterBrushColor(); + QColor getDevStatusColor(); + QPixmap getDevTypeIcon(); + void initMap(); + void DrawBackground(QPainter &); + void DrawStatusIcon(QPainter &); + void DrawBattery(QPainter &painter); + void DrawText(QPainter &); + void MouseClickedFunc(); + void DevConnectFunc(); + void SendMessage(bool connected); + + Status _MStatus; + double tran =1; + bool _clicked; + bool _pressFlag; + int iconFlag = 7; + bool _Connected; + bool _leaved = false; + + QTimer *_iconTimer = nullptr; + BluezQt::DevicePtr _MDev = nullptr; + QString _Address; + QString _Name; + QString _Battery; + QGSettings *StyleSettings = nullptr; + QGSettings *transparency_gsettings = nullptr; + QString _MType; + +public slots: + void connectedChangedSlot(bool connected); +}; + +#endif // QDEVITEM_H diff --git a/ukui-bluetooth/component/switchaction.cpp b/ukui-bluetooth/component/switchaction.cpp new file mode 100644 index 0000000..fb951b8 --- /dev/null +++ b/ukui-bluetooth/component/switchaction.cpp @@ -0,0 +1,30 @@ +#include "switchaction.h" + +SwitchAction::SwitchAction(QWidget *parent) : QWidget(parent) +{ + this->setFixedSize(240,40); + + QHBoxLayout *main_layout = new QHBoxLayout(this); + main_layout->setSpacing(0); + main_layout->setContentsMargins(32,0,16,0); + + QLabel *tip_label = new QLabel(tr("Bluetooth"),this); + main_layout->addWidget(tip_label,1,Qt::AlignLeft|Qt::AlignVCenter); + + switch_btn = new SwitchButton(this); + connect(switch_btn,&SwitchButton::checkedChanged,this,[=](bool value){ + sendBtnStatus(value); + }); + + main_layout->addWidget(switch_btn); +} + +SwitchAction::~SwitchAction() +{ + +} + +void SwitchAction::setBtnStatus(bool value) +{ + switch_btn->setChecked(value); +} diff --git a/ukui-bluetooth/component/switchaction.h b/ukui-bluetooth/component/switchaction.h new file mode 100644 index 0000000..e1c06c0 --- /dev/null +++ b/ukui-bluetooth/component/switchaction.h @@ -0,0 +1,27 @@ +#ifndef SWITCHACTION_H +#define SWITCHACTION_H + +#include +#include +#include +#include +#include + +#include "switchbutton.h" + +class SwitchAction : public QWidget +{ + Q_OBJECT +public: + explicit SwitchAction(QWidget *parent = nullptr); + ~SwitchAction(); + + void setBtnStatus(bool value); +signals: + void sendBtnStatus(bool value); +private: + SwitchButton *switch_btn = nullptr; + QGSettings *StyleSettings = nullptr; +}; + +#endif // SWITCHACTION_H diff --git a/ukui-bluetooth/component/switchbutton.cpp b/ukui-bluetooth/component/switchbutton.cpp new file mode 100644 index 0000000..1afe188 --- /dev/null +++ b/ukui-bluetooth/component/switchbutton.cpp @@ -0,0 +1,306 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "switchbutton.h" + +#include +#define THEME_QT_SCHEMA "org.ukui.style" +#define THEME_GTK_SCHEMA "org.mate.interface" + +SwitchButton::SwitchButton(QWidget *parent) : + QWidget(parent) +{ +// this->resize(QSize(52, 24)); + this->setFixedSize(QSize(50, 24)); + + checked = false; + hover = false; + disabled = false; + + space = 4; +// rectRadius = 5; + + step = width() / 40; + startX = 0; + endX= 0; + + timer = new QTimer(this); + timer->setInterval(5); + connect(timer, SIGNAL(timeout()), this, SLOT(updatevalue())); + if (QGSettings::isSchemaInstalled(THEME_GTK_SCHEMA) && QGSettings::isSchemaInstalled(THEME_QT_SCHEMA)) { + QByteArray qtThemeID(THEME_QT_SCHEMA); + QByteArray gtkThemeID(THEME_GTK_SCHEMA); + + m_gtkThemeSetting = new QGSettings(gtkThemeID,QByteArray(),this); + m_qtThemeSetting = new QGSettings(qtThemeID,QByteArray(),this); + + QString style = m_qtThemeSetting->get("styleName").toString(); + changeColor(style); + + connect(m_qtThemeSetting,&QGSettings::changed, [this] (const QString &key) { + QString style = m_qtThemeSetting->get("styleName").toString(); + if (key == "styleName") { + changeColor(style); + } + }); + } +} + +SwitchButton::~SwitchButton() +{ +} + +void SwitchButton::paintEvent(QPaintEvent *){ + //启用反锯齿 + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, true); + + drawBg(&painter); + drawSlider(&painter); +} + +void SwitchButton::changeColor(const QString &themes) { + if (hover) { + return ; + } + + if (themes == "ukui-dark" || themes == "ukui-black" || themes == "ukui-default") { + bgColorOff = QColor(OFF_BG_DARK_COLOR); + bgColorOn = QColor(ON_BG_DARK_COLOR); + rectColorEnabled = QColor(ENABLE_RECT_DARK_COLOR); + rectColorDisabled = QColor(DISABLE_RECT_DARK_COLOR); + sliderColorDisabled = QColor(DISABLE_RECT_DARK_COLOR); + sliderColorEnabled = QColor(ENABLE_RECT_DARK_COLOR); + bgHoverOnColor = QColor(ON_HOVER_BG_DARK_COLOR); + bgHoverOffColor = QColor(OFF_HOVER_BG_DARK_COLOR); + bgColorDisabled = QColor(DISABLE_DARK_COLOR); + } else { + bgColorOff = QColor(OFF_BG_LIGHT_COLOR); + bgColorOn = QColor(ON_BG_LIGHT_COLOR); + rectColorEnabled = QColor(ENABLE_RECT_LIGHT_COLOR); + rectColorDisabled = QColor(DISABLE_RECT_LIGHT_COLOR); + sliderColorDisabled = QColor(DISABLE_RECT_LIGHT_COLOR); + sliderColorEnabled = QColor(ENABLE_RECT_LIGHT_COLOR); + bgHoverOnColor = QColor(ON_HOVER_BG_LIGHT_COLOR); + bgHoverOffColor = QColor(OFF_HOVER_BG_LIGHT_COLOR); + bgColorDisabled = QColor(DISABLE_LIGHT_COLOR); + } +} + +void SwitchButton::drawBg(QPainter *painter){ + painter->save(); +// painter->setPen(Qt::NoPen); + + if (disabled) { + painter->setPen(Qt::NoPen); + painter->setBrush(bgColorDisabled); + } else { + if (!checked){ + painter->setPen(Qt::NoPen); + painter->setBrush(bgColorOff); + } + else { + painter->setPen(Qt::NoPen); + painter->setBrush(bgColorOn); + } + } + //circle out +// QRect rect(space, space, width() - space * 2, height() - space * 2); +// painter->drawRoundedRect(rect, rectRadius, rectRadius); + + //circle in + + QRect rect(0, 0, width(), height()); + //半径为高度的一半 + int radius = rect.height() / 2; + //圆的宽度为高度 + int circleWidth = rect.height(); + + QPainterPath path; + path.moveTo(radius, rect.left()); + path.arcTo(QRectF(rect.left(), rect.top(), circleWidth, circleWidth), 90, 180); + path.lineTo(rect.width() - radius, rect.height()); + path.arcTo(QRectF(rect.width() - rect.height(), rect.top(), circleWidth, circleWidth), 270, 180); + path.lineTo(radius, rect.top()); + + painter->drawPath(path); + + painter->restore(); +} + +void SwitchButton::drawSlider(QPainter *painter){ + painter->save(); + painter->setPen(Qt::NoPen); + + if (!disabled){ + painter->setBrush(sliderColorEnabled); + } + else + painter->setBrush(sliderColorDisabled); + //circle out +// QRect rect(0, 0, width() - space, height() - space); +// int sliderwidth = rect.height(); +// QRect sliderRect(startX, space / 2, sliderwidth, sliderwidth); +// painter->drawEllipse(sliderRect); + + //circle in + + if (disabled) { + if (checked) { + QRect smallRect(8, height() / 2 - 2, 10 , 4); + painter->drawRoundedRect(smallRect,3,3); + } else { + QRect smallRect(width() - 8 * 2, height() / 2 - 2, 10 , 4); + painter->drawRoundedRect(smallRect,3,3); + } + } + + QRect rect(0, 0, width(), height()); + int sliderWidth = rect.height() - space * 2; + QRect sliderRect(startX + space, space, sliderWidth, sliderWidth); + painter->drawEllipse(sliderRect); + + painter->restore(); +} + +void SwitchButton::mousePressEvent(QMouseEvent *event){ + if (timer->isActive()) { + return ; + } + + if (!disabled){ + checked = !checked; + emit checkedChanged(checked); + + step = width() / 40; + + if (checked){ + //circle out + // endX = width() - height() + space; + //circle in + endX = width() - height(); + } + else { + endX = 0; + } + timer->start(); + } + else { + endX = 0; + } + return QWidget::mousePressEvent(event); +} + +void SwitchButton::resizeEvent(QResizeEvent *){ + // + step = width() / 40; + + if (checked){ + //circle out +// startX = width() - height() + space; + //circle in + startX = width() - height(); + } + else + startX = 0; + + update(); +} + +void SwitchButton::enterEvent(QEvent *event) { + bgColorOn = bgHoverOnColor; + bgColorOff = bgHoverOffColor; + + hover = true; + update(); + return QWidget::enterEvent(event); +} + +void SwitchButton::leaveEvent(QEvent *event) { + hover = false; + + QString style = m_qtThemeSetting->get("styleName").toString(); + changeColor(style); + + update(); + return QWidget::leaveEvent(event); +} + +void SwitchButton::updatevalue(){ + if (disabled) { + return ; + } + + if (checked) + if (startX < endX){ + startX = startX + step; + } + else { + startX = endX; + timer->stop(); + } + else { + if (startX > endX){ + startX = startX - step; + } + else { + startX = endX; + timer->stop(); + } + } + update(); +} + +void SwitchButton::setChecked(bool checked){ + if (this->checked != checked){ + this->checked = checked; + emit checkedChanged(checked); + update(); + } + + step = width() / 40; + + if (checked){ + //circle out +// endX = width() - height() + space; + //circle in + endX = width() - height(); + } + else { + endX = 0; + } + timer->start(); +} + +bool SwitchButton::isChecked(){ + return this->checked; +} + +void SwitchButton::setDisabledFlag(bool value) +{ + disabled = value; + update(); +} + +bool SwitchButton::getDisabledFlag() +{ + return disabled; +} + + diff --git a/ukui-bluetooth/component/switchbutton.h b/ukui-bluetooth/component/switchbutton.h new file mode 100644 index 0000000..d5db608 --- /dev/null +++ b/ukui-bluetooth/component/switchbutton.h @@ -0,0 +1,111 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#ifndef SWITCHBUTTON_H +#define SWITCHBUTTON_H + +#include +#include +#include +#include +#include +#include + +#define OFF_BG_DARK_COLOR "#404040" +#define OFF_HOVER_BG_DARK_COLOR "#666666" +#define ON_BG_DARK_COLOR "#3790FA" +#define ON_HOVER_BG_DARK_COLOR "#40A9FB" +#define DISABLE_DARK_COLOR "#474747" +#define DISABLE_RECT_DARK_COLOR "#6E6E6E" +#define ENABLE_RECT_DARK_COLOR "#FFFFFF" + +#define OFF_BG_LIGHT_COLOR "#E0E0E0" +#define OFF_HOVER_BG_LIGHT_COLOR "#B3B3B3" +#define ON_BG_LIGHT_COLOR "#3790FA" +#define ON_HOVER_BG_LIGHT_COLOR "#40A9FB" +#define DISABLE_LIGHT_COLOR "#E9E9E9" +#define DISABLE_RECT_LIGHT_COLOR "#B3B3B3" +#define ENABLE_RECT_LIGHT_COLOR "#FFFFFF" + + +class SwitchButton : public QWidget +{ + Q_OBJECT + +public: + SwitchButton(QWidget *parent = 0); + ~SwitchButton(); + + void setChecked(bool checked); + + bool isChecked(); + void setDisabledFlag(bool); + bool getDisabledFlag(); +protected: + void mousePressEvent(QMouseEvent *); + void resizeEvent(QResizeEvent *); + void paintEvent(QPaintEvent *); + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); + + void drawBg(QPainter * painter); + void drawSlider(QPainter * painter); + void changeColor(const QString &themes); + +private: + bool checked; + bool disabled; + + QColor bgColorOff; + QColor bgColorOn; + QColor bgHoverOnColor; + QColor bgHoverOffColor; + QColor bgColorDisabled; + + QColor sliderColorEnabled; + QColor sliderColorDisabled; + + + QColor rectColorEnabled; + QColor rectColorDisabled; + + QGSettings *m_qtThemeSetting; + QGSettings *m_gtkThemeSetting; + + int space; //滑块离背景间隔 + int rectRadius; //圆角角度 + + int step; //移动步长 + int startX; + int endX; + + bool hover; + QTimer * timer; + + +private slots: + void updatevalue(); + + +Q_SIGNALS: + void checkedChanged(bool checked); + +}; + +#endif // SWITCHBUTTON_H diff --git a/ukui-bluetooth/config/config.cpp b/ukui-bluetooth/config/config.cpp new file mode 100644 index 0000000..7e124dc --- /dev/null +++ b/ukui-bluetooth/config/config.cpp @@ -0,0 +1,59 @@ +#include "config.h" + +Config::Config(QObject *parent, QString name) + :QObject(parent) + ,setting_name(name) +{ + if (QGSettings::isSchemaInstalled(setting_name.toUtf8())) { + gsetting = new QGSettings(setting_name.toUtf8()); + } +} + +Config::~Config() +{ + delete gsetting; +} + +void Config::SendNotifyMessage(QString message) +{ + QDBusInterface iface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + QDBusConnection::sessionBus()); + QList args; + args<start(cmd,arg); +} + +bool global_ishuawei = false; diff --git a/ukui-bluetooth/config/config.h b/ukui-bluetooth/config/config.h new file mode 100644 index 0000000..235b7e9 --- /dev/null +++ b/ukui-bluetooth/config/config.h @@ -0,0 +1,30 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#include +#include +#include +#include +#include +#include + +//全局变量,是否是华为机器, 默认false, 在config.cpp文件定义 +extern bool global_ishuawei; + +class Config : public QObject +{ + Q_OBJECT +public: + Config(QObject *parent = nullptr,QString name = "org.ukui.bluetooth"); + ~Config(); + + static void SendNotifyMessage(QString); + static void OpenBluetoothSettings(); + static bool isHUAWEI(); +private: + QString setting_name; + QGSettings *gsetting = nullptr; + friend class MainProgram; + friend class TrayWidget; +}; +#endif // CONFIG_H diff --git a/ukui-bluetooth/config/xatom-helper.cpp b/ukui-bluetooth/config/xatom-helper.cpp new file mode 100644 index 0000000..bbf460c --- /dev/null +++ b/ukui-bluetooth/config/xatom-helper.cpp @@ -0,0 +1,216 @@ +/* + * KWin Style UKUI + * + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: Yue Lan + * + */ + +#include "xatom-helper.h" + +#include + +#include + +#include +#include +#include +#include + +static XAtomHelper *global_instance = nullptr; + +XAtomHelper *XAtomHelper::getInstance() +{ + if (!global_instance) + global_instance = new XAtomHelper; + return global_instance; +} + +bool XAtomHelper::isFrameLessWindow(int winId) +{ + auto hints = getInstance()->getWindowMotifHint(winId); + if (hints.flags == MWM_HINTS_DECORATIONS && hints.functions == 1) { + return true; + } + return false; +} + +bool XAtomHelper::isWindowDecorateBorderOnly(int winId) +{ + return isWindowMotifHintDecorateBorderOnly(getInstance()->getWindowMotifHint(winId)); +} + +bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint) +{ + bool isDeco = false; + if (hint.flags & MWM_HINTS_DECORATIONS && hint.flags != MWM_HINTS_DECORATIONS) { + if (hint.decorations == MWM_DECOR_BORDER) + isDeco = true; + } + return isDeco; +} + +bool XAtomHelper::isUKUICsdSupported() +{ + // fixme: + return false; +} + +bool XAtomHelper::isUKUIDecorationWindow(int winId) +{ + if (m_ukuiDecorationAtion == None) + return false; + + Atom type; + int format; + ulong nitems; + ulong bytes_after; + uchar *data; + + bool isUKUIDecoration = false; + + XGetWindowProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, + 0, LONG_MAX, false, + m_ukuiDecorationAtion, &type, + &format, &nitems, + &bytes_after, &data); + + if (type == m_ukuiDecorationAtion) { + if (nitems == 1) { + isUKUIDecoration = data[0]; + } + } + + return isUKUIDecoration; +} + +UnityCorners XAtomHelper::getWindowBorderRadius(int winId) +{ + UnityCorners corners; + + Atom type; + int format; + ulong nitems; + ulong bytes_after; + uchar *data; + + if (m_unityBorderRadiusAtom != None) { + XGetWindowProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, + 0, LONG_MAX, false, + XA_CARDINAL, &type, + &format, &nitems, + &bytes_after, &data); + + if (type == XA_CARDINAL) { + if (nitems == 4) { + corners.topLeft = static_cast(data[0]); + corners.topRight = static_cast(data[1*sizeof (ulong)]); + corners.bottomLeft = static_cast(data[2*sizeof (ulong)]); + corners.bottomRight = static_cast(data[3*sizeof (ulong)]); + } + XFree(data); + } + } + + return corners; +} + +void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data) +{ + if (m_unityBorderRadiusAtom == None) + return; + + ulong corners[4] = {data.topLeft, data.topRight, data.bottomLeft, data.bottomRight}; + + XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, + 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof (corners)/sizeof (corners[0])); +} + +void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight) +{ + if (m_unityBorderRadiusAtom == None) + return; + + ulong corners[4] = {(ulong)topLeft, (ulong)topRight, (ulong)bottomLeft, (ulong)bottomRight}; + + XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, + 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof (corners)/sizeof (corners[0])); +} + +void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set) +{ + if (m_ukuiDecorationAtion == None) + return; + + XChangeProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, m_ukuiDecorationAtion, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &set, 1); +} + +void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints) +{ + if (m_unityBorderRadiusAtom == None) + return; + + XChangeProperty(QX11Info::display(), winId, m_motifWMHintsAtom, m_motifWMHintsAtom, + 32, XCB_PROP_MODE_REPLACE, (const unsigned char *)&hints, sizeof (MotifWmHints)/ sizeof (ulong)); +} + +MotifWmHints XAtomHelper::getWindowMotifHint(int winId) +{ + MotifWmHints hints; + + if (m_unityBorderRadiusAtom == None) + return hints; + + uchar *data; + Atom type; + int format; + ulong nitems; + ulong bytes_after; + + XGetWindowProperty(QX11Info::display(), winId, m_motifWMHintsAtom, + 0, sizeof (MotifWmHints)/sizeof (long), false, AnyPropertyType, &type, + &format, &nitems, &bytes_after, &data); + + if (type == None) { + return hints; + } else { + hints = *(MotifWmHints *)data; + XFree(data); + } + return hints; +} + +XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent) +{ + if (!QX11Info::isPlatformX11()) + return; + + m_motifWMHintsAtom = XInternAtom(QX11Info::display(), "_MOTIF_WM_HINTS", true); + m_unityBorderRadiusAtom = XInternAtom(QX11Info::display(), "_UNITY_GTK_BORDER_RADIUS", false); + m_ukuiDecorationAtion = XInternAtom(QX11Info::display(), "_KWIN_UKUI_DECORAION", false); +} + +Atom XAtomHelper::registerUKUICsdNetWmSupportAtom() +{ + // fixme: + return None; +} + +void XAtomHelper::unregisterUKUICsdNetWmSupportAtom() +{ + // fixme: +} diff --git a/ukui-bluetooth/config/xatom-helper.h b/ukui-bluetooth/config/xatom-helper.h new file mode 100644 index 0000000..b8e56f5 --- /dev/null +++ b/ukui-bluetooth/config/xatom-helper.h @@ -0,0 +1,111 @@ +/* + * KWin Style UKUI + * + * Copyright (C) 2020, KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: Yue Lan + * + */ + +#ifndef XATOMHELPER_H +#define XATOMHELPER_H + +#include + +//#include +//#include + +struct UnityCorners { + ulong topLeft = 0; + ulong topRight = 0; + ulong bottomLeft = 0; + ulong bottomRight = 0; +}; + +typedef struct { + ulong flags = 0; + ulong functions = 0; + ulong decorations = 0; + long input_mode = 0; + ulong status = 0; +} MotifWmHints, MwmHints; + +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_INPUT_MODE (1L << 2) +#define MWM_HINTS_STATUS (1L << 3) + +#define MWM_FUNC_ALL (1L << 0) +#define MWM_FUNC_RESIZE (1L << 1) +#define MWM_FUNC_MOVE (1L << 2) +#define MWM_FUNC_MINIMIZE (1L << 3) +#define MWM_FUNC_MAXIMIZE (1L << 4) +#define MWM_FUNC_CLOSE (1L << 5) + +#define MWM_DECOR_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) +#define MWM_DECOR_RESIZEH (1L << 2) +#define MWM_DECOR_TITLE (1L << 3) +#define MWM_DECOR_MENU (1L << 4) +#define MWM_DECOR_MINIMIZE (1L << 5) +#define MWM_DECOR_MAXIMIZE (1L << 6) + +#define MWM_INPUT_MODELESS 0 +#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 +#define MWM_INPUT_SYSTEM_MODAL 2 +#define MWM_INPUT_FULL_APPLICATION_MODAL 3 +#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL + +#define MWM_TEAROFF_WINDOW (1L<<0) + +namespace UKUI { +class Decoration; +} + +class XAtomHelper : public QObject +{ + friend class UKUI::Decoration; + Q_OBJECT +public: + static XAtomHelper *getInstance(); + + static bool isFrameLessWindow(int winId); + + bool isWindowDecorateBorderOnly(int winId); + bool isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint); + bool isUKUICsdSupported(); + bool isUKUIDecorationWindow(int winId); + + UnityCorners getWindowBorderRadius(int winId); + void setWindowBorderRadius(int winId, const UnityCorners &data); + void setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight); + void setUKUIDecoraiontHint(int winId, bool set = true); + + void setWindowMotifHint(int winId, const MotifWmHints &hints); + MotifWmHints getWindowMotifHint(int winId); + +private: + explicit XAtomHelper(QObject *parent = nullptr); + + ulong registerUKUICsdNetWmSupportAtom(); + void unregisterUKUICsdNetWmSupportAtom(); + + ulong m_motifWMHintsAtom = 0l; + ulong m_unityBorderRadiusAtom = 0l; + ulong m_ukuiDecorationAtion = 0l; +}; + +#endif // XATOMHELPER_H diff --git a/ukui-bluetooth/daemon/bluetoothdbus.cpp b/ukui-bluetooth/daemon/bluetoothdbus.cpp new file mode 100644 index 0000000..a0f06c0 --- /dev/null +++ b/ukui-bluetooth/daemon/bluetoothdbus.cpp @@ -0,0 +1,486 @@ +#include "bluetoothdbus.h" +#include "config/config.h" +#include + +BluetoothDbus::BluetoothDbus(QObject *parent) +{ + Q_UNUSED(parent); + qDebug() << Q_FUNC_INFO << __LINE__; + connectDBusSignals(); + getDefaultAdapterPower(); + getDefaultAdapterPairedDevices(); + qDebug() << Q_FUNC_INFO << __LINE__; +} + +BluetoothDbus::~BluetoothDbus() +{ + +} + +void BluetoothDbus::connectDBusSignals() { + qDebug() << Q_FUNC_INFO << __LINE__; + TRANSFER_DBUS_SIGNAL("showTrayWidgetUISignal", showTrayWidgetUISignal()); + + //适配器相关dbus + CONNECT_DBUS_SIGNAL("defaultAdapterPowerChanged", defaultAdapterPowerChangedSLot(bool)); + CONNECT_DBUS_SIGNAL("defaultAdapterChanged", defaultAdapterChangedSLot(QString)); + CONNECT_DBUS_SIGNAL("adapterRemoveSignal", adapterRemoveSignalSLot(QString)); + CONNECT_DBUS_SIGNAL("adapterAddSignal", adapterAddSignalSLot(QString)); + + //连接、移除相关dbus + CONNECT_DBUS_SIGNAL("devConnectStatusSignal", devConnectStatusSignalSLot(QString, bool)); + CONNECT_DBUS_SIGNAL("devNameChangedSignal", devNameChangedSignalSLot(QString, QString)); + CONNECT_DBUS_SIGNAL("devBatteryChangedSignal", devBatteryChangedSignalSLot(QString, QString)); + CONNECT_DBUS_SIGNAL("devRemoveSignal", devRemoveSignalSLot(QString)); + CONNECT_DBUS_SIGNAL("devErrorSignal", devErrorSignalSLot(QString)); + TRANSFER_DBUS_SIGNAL("ActiveConnection", activeConnectionSignal(QString,QString,QString,int,int)); + + //匹配相关dbus + CONNECT_DBUS_SIGNAL("devPairSignal", devPairSignalSLot(QString, bool)); + TRANSFER_DBUS_SIGNAL("displayPasskey", displayPasskeySignal(QString,QString)); + TRANSFER_DBUS_SIGNAL("requestConfirmation", requestConfirmationSignal(QString,QString)); + TRANSFER_DBUS_SIGNAL("pairAgentCanceled", pairAgentCanceledSignal()); + + //文件传输相关dbus + CONNECT_DBUS_SIGNAL("fileReceivingSignal", receiveFilesSlot(QString,QString,QString,QString,quint64)); + TRANSFER_DBUS_SIGNAL("obexAgentCanceled", obexAgentCanceledSignal()); + TRANSFER_DBUS_SIGNAL("fileReceiveMore", fileReceiveMore(QString, quint64, QString)); + TRANSFER_DBUS_SIGNAL("sendTransferFilesMesg", sendTransferFilesMesgSignal(QStringList)); + TRANSFER_DBUS_SIGNAL("sendTransferDeviceMesg", sendTransferDeviceMesgSignal(QString)); + TRANSFER_DBUS_SIGNAL("transferredChanged", transferredChangedSignal(quint64,QString)); + TRANSFER_DBUS_SIGNAL("statusChanged", statusChangedSignal(QString,QString,QString)); + TRANSFER_DBUS_SIGNAL("initTransferPath", initTransferPathSignal(QString)); + qDebug() << Q_FUNC_INFO << __LINE__; +} + +void BluetoothDbus::defaultAdapterPowerChangedSLot(bool value) { + qDebug() << Q_FUNC_INFO << __LINE__ << value; + powered = value; + emit powerChangedSignal(powered); +} + +void BluetoothDbus::adapterRemoveSignalSLot(QString address) { + qDebug() << Q_FUNC_INFO << __LINE__ << address; + getTrayIconShow(); +} + +void BluetoothDbus::adapterAddSignalSLot(QString address) { + qDebug() << Q_FUNC_INFO << __LINE__ << address; + getDefaultAdapterPairedDevices(); + emit showTrayIcon(true); + emit adapterAddSignal(address); +} + +void BluetoothDbus::defaultAdapterChangedSLot(QString value) { + qDebug() << Q_FUNC_INFO << __LINE__ << value; + getDefaultAdapterPower(); + getDefaultAdapterPairedDevices(); + emit AdapterChangedSignal(value); +} + +void BluetoothDbus::devPairSignalSLot(QString address, bool paired) { + qDebug() << "devPairSignalSLot" << address << paired; + if (paired && !pairedDevice.contains(address)) { + if (!pairedList.contains(address)) + pairedList.append(address); + addNewPairedDevice(address); + emit sessionDevPairSignal(pairedDevice.value(address).at(0),paired); + } + if (!paired && pairedDevice.contains(address)) { + QString name = pairedDevice.value(address).at(0); + if (pairedList.contains(address)) + pairedList.removeAll(address); + pairedDevice.remove(address); + emit sessionDevPairSignal(name, paired); + } +} + +void BluetoothDbus::devConnectStatusSignalSLot(QString address, bool connected) { + qDebug() << "devConnectStatusSignalSLot" << address << connected; + if (connected + && !connectedDevice.values().contains(address) + && pairedDevice.keys().contains(address)) + connectedDevice.insert(pairedDevice.value(address).at(0), address); + + if (!connected + && connectedDevice.values().contains(address) + && pairedDevice.keys().contains(address)) + connectedDevice.remove(pairedDevice.value(address).at(0)); + + emit devConnectStatusSignal(address, connected); +} + +void BluetoothDbus::devNameChangedSignalSLot(QString address, QString name) { + qDebug() << "devNameChangedSignalSLot" << address << name; + if (!pairedDevice.contains(address)) + return; + if (connectedDevice.values().contains(address) + && pairedDevice.keys().contains(address)) { + connectedDevice.remove(pairedDevice.value(address).at(0)); + } + getDevConnectStatus(address); + QStringList updateList; + updateList.append(name); + updateList.append(pairedDevice.value(address).at(1)); + updateList.append(pairedDevice.value(address).at(2)); + pairedDevice.remove(address); + pairedDevice.insert(address, updateList); + emit devNameChangedSignal(); +} + +void BluetoothDbus::devBatteryChangedSignalSLot(QString address, QString battery) { + if (Config::isHUAWEI()) + return; + if (!pairedDevice.contains(address)) + return; + if (connectedDevice.values().contains(address) + && pairedDevice.keys().contains(address)) { + connectedDevice.remove(pairedDevice.value(address).at(0)); + } + qDebug() << "devBatteryChangedSignalSLot" << address << battery; + QStringList updateList; + updateList.append(pairedDevice.value(address).at(0)); + updateList.append(pairedDevice.value(address).at(1)); + updateList.append(battery); + pairedDevice.remove(address); + pairedDevice.insert(address, updateList); + emit devBatteryChangedSignal(); +} + +void BluetoothDbus::devRemoveSignalSLot(QString address) { + qDebug() << "devRemoveSignalSLot" << address; + if (pairedList.contains(address)) + pairedList.removeAll(address); + if (pairedDevice.keys().contains(address)) + pairedDevice.remove(address); + emit devRemoveSignal(address); +} + +void BluetoothDbus::devErrorSignalSLot(QString a) { + qDebug() << "-----------------------" << a; +} + +void BluetoothDbus::receiveFilesSlot(QString destination, QString filename, QString type, QString source, quint64 size) { + emit receiveFilesSignal(destination, + pairedDevice.value(destination).at(0), + filename, + type, + source, + size); +} + +void BluetoothDbus::getTrayIconShow() { + qDebug() << Q_FUNC_INFO << __LINE__; + QDBusMessage _m = CREATE_METHOD_CALL("getAdapterDevAddressList"); + QDBusMessage _response1 = CALL_METHOD(_m); + if (_response1.type() == QDBusMessage::ReplyMessage) + { + + emit showTrayIcon(!(_response1.arguments().takeFirst().toStringList().size() == 0)); + qDebug() << Q_FUNC_INFO << __LINE__ << !(_response1.arguments().takeFirst().toStringList().size() == 0); + } +} + +void BluetoothDbus::addNewPairedDevice(QString address) { + QStringList device; + QDBusMessage _m1 = CREATE_METHOD_CALL("getDevName"); + _m1 << address; + QDBusMessage _response1 = CALL_METHOD(_m1); + if (_response1.type() == QDBusMessage::ReplyMessage) + { + device.append(_response1.arguments().takeFirst().toString()); + } + + QDBusMessage _m2 = CREATE_METHOD_CALL("getDevType"); + _m2 << address; + QDBusMessage _response2 = CALL_METHOD(_m2); + if (_response2.type() == QDBusMessage::ReplyMessage) + { + device.append(_response2.arguments().takeFirst().toString()); + } + + QDBusMessage _m3 = CREATE_METHOD_CALL("getDevBattery"); + _m3 << address; + QDBusMessage _response3 = CALL_METHOD(_m3); + if (_response3.type() == QDBusMessage::ReplyMessage) + { + if (Config::isHUAWEI()) + device.append(QString("-1")); + else + device.append(_response3.arguments().takeFirst().toString()); + } + pairedDevice.insert(address, device); + getDevConnectStatus(address); +} + +void BluetoothDbus::sendFiles(QString address, QString filename) { + QDBusMessage m = CREATE_METHOD_CALL("sendFiles"); + m << address << filename; + + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + qDebug() << " sendFiles Settings succeed!"; +} + +void BluetoothDbus::openBluetoothSettings() { + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "openBluetoothSettings"); + + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + qDebug() << " open Bluetooth Settings succeed!"; +} + +void BluetoothDbus::closeSessionSignal() { + QDBusMessage closeSig = QDBusMessage::createSignal(SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "closeSessionSignal"); + QDBusConnection::sessionBus().send(closeSig); +} + +void BluetoothDbus::replyRequestConfirmation(bool accept) { + qDebug() << " reply :" << accept; + + QDBusMessage m = CREATE_METHOD_CALL("sendReplyRequestConfirmation"); + m << accept; + qDebug() << Q_FUNC_INFO << m.arguments().at(0).value() <<__LINE__<<"QQQQ"; + // 发送Message + QDBusMessage response = QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + +// QDBusMessage displayPasskeySignal = QDBusMessage::createSignal("/com/ukui/bluetooth", +// "com.ukui.bluetooth", +// "replyRequestConfirmation"); +// displayPasskeySignal << QVariant::fromValue(accept).toBool(); +// bool ret = QDBusConnection::sessionBus().send(displayPasskeySignal); +// qDebug() << "ret--------------BluetoothDbus::replyRequestConfirmation" << ret; +} + +void BluetoothDbus::replyFileReceivingSignal(bool accept) { + qDebug() << " areply :" << accept; + QDBusMessage reply = QDBusMessage::createSignal(SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "replyFileReceivingSignal"); + reply << accept; + bool ret = QDBusConnection::sessionBus().send(reply); + qDebug() << "ret" << ret; +} + +void BluetoothDbus::devConnect(const QString address) { + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "devConnect"); + m << address; + + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + qDebug() << " devConnect method called succeed!"; +} + +void BluetoothDbus::devDisconnect(const QString address) { + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "devDisconnect"); + m << address; + + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + qDebug() << " devDisconnect method called succeed!"; +} + +void BluetoothDbus::setDefaultAdapterPower(bool power) { + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "setDefaultAdapterPower"); + m << power; + qDebug() << " setDefaultAdapterPower " << power << __LINE__; + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +bool BluetoothDbus::getDevPairStatus(QString address) { + QDBusMessage ispair = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "getDevPairStatus"); + QDBusMessage response = QDBusConnection::sessionBus().call(ispair, QDBus::NoBlock); + if (response.type() == QDBusMessage::ReplyMessage) + { + qDebug() << address << " pair status : " << response.arguments().takeFirst().toBool(); + return response.arguments().takeFirst().toBool(); + } else { + qDebug() << " getDevPairStatus method called failed!"; + return false; + } +} + +void BluetoothDbus::getDefaultAdapterPower() { + qDebug() << "get default powered "; + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "getDefaultAdapterPower"); + QDBusMessage response = QDBusConnection::sessionBus().call(m); + if (response.type() == QDBusMessage::ReplyMessage) + { + powered = response.arguments().takeFirst().toBool(); + qDebug() << "init powered over : " << powered; + } else { + qDebug() << " powered method called failed!"; + } +} + +void BluetoothDbus::getDevConnectStatus(QString address) { + qDebug() << "get device connect status "; + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "getDevConnectStatus"); + m << address; + QDBusMessage response = QDBusConnection::sessionBus().call(m); + if (response.type() == QDBusMessage::ReplyMessage) + { + bool connected = response.arguments().takeFirst().toBool(); + if (connected && pairedDevice.keys().contains(address)) { + if (connectedDevice.values().contains(address)) + connectedDevice.remove(connectedDevice.key(address)); + connectedDevice.insert(pairedDevice.value(address).at(0), address); + } + if (!connected + && connectedDevice.values().contains(address) + && pairedDevice.keys().contains(address)) + connectedDevice.remove(pairedDevice.value(address).at(0)); + qDebug() << "init connect status : " << connected << address << pairedDevice; + } else { + qDebug() << " init connect status method called failed!"; + } +} + +void BluetoothDbus::cancelFileReceiving() { + qDebug() << "cancel receiving"; + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "cancelFileReceiving"); + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BluetoothDbus::closeSession() { + qDebug() << "close session"; + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "sendCloseSession"); + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BluetoothDbus::continueSendFiles(QString filename) { + qDebug() << "continue send files signal"; + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "continueSendFiles"); + m << filename; + QDBusConnection::sessionBus().call(m); +} + +void BluetoothDbus::clearOldSession() { + qDebug() << "clear oldsession signal"; + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "setclearOldSession"); + QDBusConnection::sessionBus().call(m, QDBus::NoBlock); +} + +void BluetoothDbus::replyFileReceiving(bool v) { + qDebug() << "reply file revceive signal"; + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "sendReplyFileReceivingSignal"); + m << v; + QDBusMessage response = QDBusConnection::sessionBus().call(m); +} + +void BluetoothDbus::getDefaultAdapterPairedDevices() { + qDebug() << "get Default Adapter Paired Devices"; + pairedList.clear(); + pairedDevice.clear(); + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "getDefaultAdapterPairedDevAddress"); + QDBusMessage response = QDBusConnection::sessionBus().call(m); + if (response.type() == QDBusMessage::ReplyMessage) + { + QStringList ret = response.arguments().takeFirst().toStringList(); + qDebug() << ret; + for (int i = 0; i < ret.size(); i++) { + if (!pairedList.contains(ret.at(i))) + pairedList.append(ret.at(i)); + addNewPairedDevice(ret.at(i)); + } + qDebug() << "init paired devices over : " << pairedDevice; + } else { + qDebug() << "value method called failed!"; + } +} + +QMap BluetoothDbus::getSendableDevices() { + QMap AbleDev; + AbleDev = pairedDevice; + for (auto item : pairedList) { + qDebug() << "<<<<" << AbleDev; + if(!getDevSupportFileSend(item)) + AbleDev.remove(item); + qDebug() << "<<<< is contain" << item << AbleDev.contains(item); + } + qDebug() << "-----" << AbleDev; + return AbleDev; +} + +bool BluetoothDbus::getDevSupportFileSend(QString address) { + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "getDevSupportFileSend"); + m << address; + QDBusMessage response = QDBusConnection::sessionBus().call(m); + if (response.type() == QDBusMessage::ReplyMessage) + { + qDebug() << "<<______>>"; + return response.arguments().takeFirst().toBool(); + } + return false; +} + +void BluetoothDbus::activeConnectionReply(QString dev, bool v) { + qDebug() << Q_FUNC_INFO << dev << v; + QDBusMessage m = QDBusMessage::createMethodCall(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + "activeConnectionReply"); + m << dev << v; + QDBusMessage response = QDBusConnection::sessionBus().call(m, QDBus::NoBlock); + if (response.type() == QDBusMessage::ReplyMessage) + { + qDebug() << "Send Reply"; + } +} + +bool BluetoothDbus::isPowered() { + return powered; +} + +QList BluetoothDbus::getPairedDevicesList() { + return pairedList; +} + +QMap BluetoothDbus::getPairedDevices() { + return pairedDevice; +} + +bool BluetoothDbus::isConnected(QString name) { + qDebug() << connectedDevice; + return connectedDevice.keys().contains(name); +} diff --git a/ukui-bluetooth/daemon/bluetoothdbus.h b/ukui-bluetooth/daemon/bluetoothdbus.h new file mode 100644 index 0000000..15df3e1 --- /dev/null +++ b/ukui-bluetooth/daemon/bluetoothdbus.h @@ -0,0 +1,132 @@ +#ifndef BLUETOOTHDBUS_H +#define BLUETOOTHDBUS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SYSTEMD_SERVICE "com.ukui.bluetooth" +#define SYSTEMD_PATH "/com/ukui/bluetooth" +#define SYSTEMD_INTERFACE SYSTEMD_SERVICE + +#define CONNECT_DBUS_SIGNAL(signame, func) \ + QDBusConnection::sessionBus().connect(SYSTEMD_SERVICE, \ + SYSTEMD_PATH, \ + SYSTEMD_INTERFACE, \ + signame, \ + this,\ + SLOT(func)) + +#define TRANSFER_DBUS_SIGNAL(signame, func) \ + QDBusConnection::sessionBus().connect(SYSTEMD_SERVICE, \ + SYSTEMD_PATH, \ + SYSTEMD_INTERFACE, \ + signame, \ + this,\ + SIGNAL(func)) + +#define CREATE_METHOD_CALL(funcName) \ + QDBusMessage::createMethodCall(SYSTEMD_SERVICE, \ + SYSTEMD_PATH, \ + SYSTEMD_INTERFACE, \ + funcName) + +#define CALL_METHOD(dbusmsg) QDBusConnection::sessionBus().call(dbusmsg); + +class BluetoothDbus : public QObject +{ + Q_OBJECT +public: + explicit BluetoothDbus(QObject *parent = nullptr); + ~BluetoothDbus(); + void setDeviceList(QStringList devicelist); + void setDeviceType(QStringList typelist); + +public: + //DBus调用函数 + void getDefaultAdapterPower(); + void getDefaultAdapterPairedDevices(); + void getDevConnectStatus(QString address); + void getTrayIconShow(); + void setDefaultAdapterPower(bool power); + + void closeSession(); + void clearOldSession(); + void closeSessionSignal(); + void openBluetoothSettings(); + void devConnect(const QString address); + void devDisconnect(const QString address); + void sendFiles(QString address, QString filename); + + void cancelFileReceiving(); + void replyFileReceiving(bool v); + void continueSendFiles(QString filename); + void replyRequestConfirmation(bool accept); + void replyFileReceivingSignal(bool accept); + void activeConnectionReply(QString dev, bool v); + + //返回信息 + bool isPowered(); + bool isConnected(QString name); + bool getDevPairStatus(QString address); + QMap getPairedDevices(); + QMap getSendableDevices(); + QList getPairedDevicesList(); + +signals: + void showTrayIcon(bool); + void adapterAddSignal(QString); + void adapterRemoveSignal(QString); + void powerChangedSignal(bool); + void displayPasskeySignal(QString,QString); + void receiveFilesSignal(QString, QString,QString,QString,QString,quint64); + void requestConfirmationSignal(QString,QString); + void transferredChangedSignal(quint64,QString); + void statusChangedSignal(QString,QString,QString); + void initTransferPathSignal(QString); + void pairAgentCanceledSignal(); + void obexAgentCanceledSignal(); + void devRemoveSignal(QString); + void devNameChangedSignal(); + void devBatteryChangedSignal(); + void sessionDevPairSignal(QString, bool); + void sendTransferFilesMesgSignal(QStringList); + void sendTransferDeviceMesgSignal(QString); + void AdapterChangedSignal(QString); + void devConnectStatusSignal(QString, bool); + void fileReceiveMore(QString, quint64, QString); + void showTrayWidgetUISignal(); + void activeConnectionSignal(QString,QString,QString,int,int); + +private: + void connectDBusSignals(); + void addNewPairedDevice(QString address); + bool powered = false; + QList pairedList; + QMap pairedDevice; + QMap connectedDevice; + +private slots: + bool getDevSupportFileSend(QString address); + void adapterAddSignalSLot(QString address); + void adapterRemoveSignalSLot(QString address); + void defaultAdapterPowerChangedSLot(bool value); + void defaultAdapterChangedSLot(QString value); + void devPairSignalSLot(QString address, bool paired); + void devConnectStatusSignalSLot(QString address, bool connected); + void devRemoveSignalSLot(QString address); + void devErrorSignalSLot(QString); + void devNameChangedSignalSLot(QString address, QString name); + void devBatteryChangedSignalSLot(QString address, QString battery); + void receiveFilesSlot(QString destination, QString filename, QString type, QString source, quint64 size); +}; + +#endif // BLUETOOTHDBUS_H diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp new file mode 100644 index 0000000..b753bc8 --- /dev/null +++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.cpp @@ -0,0 +1,568 @@ +#include "filereceivingpopupwidget.h" +#include "config/xatom-helper.h" + +FileReceivingPopupWidget::FileReceivingPopupWidget(QString address, QString devname, + QString filename, QString type, + QString root, quint64 size): + target_address(address), + target_name(devname), + target_source(filename), + target_type(type), + root_address(root), + target_size(size) +{ + isIntel = QFile::exists("/etc/apt/ota_version"); + // 添加窗管协议 + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; + if (isIntel) + hints.functions = MWM_FUNC_CLOSE; + else + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); + + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,&FileReceivingPopupWidget::GSettingsChanges); + } + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("Bluetooth file transfer")); + this->setAttribute(Qt::WA_DeleteOnClose); + + QPalette palette; + if(StyleSettings->get("style-name").toString() == "ukui-default" || StyleSettings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(255,255,255)); + }else{ + palette.setColor(QPalette::Background,QColor(0,0,0)); + } + this->setPalette(palette); + + if(QGSettings::isSchemaInstalled("org.ukui.bluetooth")){ + settings = new QGSettings("org.ukui.bluetooth"); + + file_path = settings->get("file-save-path").toString(); + + connect(settings, &QGSettings::changed,this,&FileReceivingPopupWidget::GSettings_value_chanage); + }else{ + file_path = QDir::homePath(); + } + + QIcon fileicon; + if (target_type.split("/").at(0) == "image"){ + fileicon = QIcon::fromTheme("image"); + if (fileicon.isNull()) { + fileicon = QIcon::fromTheme("text"); + } + }else if (target_type.split("/").at(0) == "video") + fileicon = QIcon::fromTheme("video-x-generic"); + else if (target_type.split("/").at(0) == "audio" || + target_type.split("/").at(0) == "application" || + target_type.split("/").at(0) == "text" || + target_type.split("/").at(0) == "inode"){ + if (QIcon::hasThemeIcon(target_type.split("/").join("-"))) { + fileicon = QIcon::fromTheme(target_type.split("/").join("-")); + qDebug() << target_type.split("/").join("-"); + } else { + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme("text-plain"); + } + }else + fileicon = QIcon::fromTheme("text"); + + if (isIntel) + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive..."),this); + else + file_source = new QLabel(tr("File from \"")+target_name+tr("\", waiting for receive."),this); + file_source->setAlignment(Qt::AlignTop); + QFont ft; + ft.setPixelSize(14); + QFont ft1; + ft1.setPixelSize(18); + file_source->setFont(ft1); + file_source->setWordWrap(true); + + file_icon = new QLabel(this); + file_icon->setPixmap(fileicon.pixmap(64,64)); + file_icon->setAlignment(Qt::AlignCenter); + + QFontMetrics fontMetrics(file_source->font()); + QString fileName = fontMetrics.elidedText(target_source, Qt::ElideMiddle, 280); + file_name = new QLabel(fileName,this); + file_name->setToolTip(target_source); + file_name->setFont(ft); + file_name->setAlignment(Qt::AlignVCenter|Qt::AlignLeft); + + int unitcount = 0; //将单位B转化为对应的KB、MB等单位 + double calc_size = target_size; + while(calc_size >= 1024) { + calc_size /= 1024; + unitcount++; + } + + file_size = new QLabel(QString::asprintf("%.1f", calc_size) + unitString[unitcount],this); + + file_size->setFont(ft); + file_size->setAlignment(Qt::AlignVCenter|Qt::AlignLeft); + file_size->setWordWrap(true); + + transfer_progress = new QProgressBar(this); + transfer_progress->setFixedHeight(8); + transfer_progress->setTextVisible(false); + transfer_progress->setVisible(false); + + cancel_btn = new QPushButton(tr("Cancel"),this); + connect(cancel_btn,&QPushButton::clicked,this,[=]{ + emit this->rejected(); + this->close(); + }); + + accept_btn = new QPushButton(tr("Accept"),this); + connect(accept_btn,&QPushButton::clicked,this,[=]{ + OnClickedAcceptBtn(); + }); + + warn_icon = new QLabel(this); + warn_icon->setPixmap(QIcon::fromTheme("kylin-dialog-warning").pixmap(22,22)); + if (warn_icon->pixmap()->isNull()) + warn_icon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(22,22)); + warn_icon->setVisible(false); + + view_btn = new QPushButton(tr("View"),this); + view_btn->setVisible(false); + + receivedFiles.clear(); + receiveTimer = new QTimer(this); + connect(receiveTimer,SIGNAL(timeout()), this, SLOT(transferCompelete())); + + if (isIntel) + initIntelLayout(); + else + initLayout(); + + QDesktopWidget *desktop_widget = QApplication::desktop(); + desktop = desktop_widget->availableGeometry(); + qDebug() << Q_FUNC_INFO << this->width() << this->height(); + qDebug() << Q_FUNC_INFO <width() << desktop.bottom()-this->height(); + this->move(QPoint(desktop.right()-this->width(),desktop.bottom()-this->height())); + + window_pop_up_animation(); + this->activateWindow(); + this->show(); +} + +FileReceivingPopupWidget::~FileReceivingPopupWidget() +{ + delete settings; +} + +void FileReceivingPopupWidget::initLayout() { + this->setFixedSize(520,276); + close_btn = new QPushButton(this); + close_btn->setIcon(QIcon::fromTheme("window-close-symbolic")); + close_btn->setProperty("isWindowButton", 0x2); + close_btn->setProperty("useIconHighlightEffect", 0x8); + close_btn->setFlat(true); + + icon_label = new QLabel(this); + icon_label->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); + + window_Title = new QLabel(tr("Bluetooth File"),this); + window_Title->setFixedSize(100,20); + connect(close_btn,&QPushButton::clicked,this,[=]{ + emit this->rejected(); + this->close(); + }); + + close_btn->setGeometry(480,4,30,30); + icon_label->setGeometry(8,8,22,22); + window_Title->setGeometry(36, 9, 100, 20); + view_btn->setGeometry(390,215,120,36); + file_source->setGeometry(32,52,460,54); + file_icon->setGeometry(32,104,64,64); + file_name->setGeometry(112,111,293,28); + file_size->setGeometry(112,136,293,20); + transfer_progress->setGeometry(32,184,454,8); + cancel_btn->setGeometry(278,215,96,36); + accept_btn->setGeometry(390,215,96,36); + warn_icon->setGeometry(32,54,22,22); + + int size = StyleSettings->get("system-font-size").toInt() - 11; + QFont ft; + ft.setPixelSize(18 + size); + file_source->setFont(ft); + QString fileSource; + QFontMetrics fontMetrics(file_source->font()); + QString fileName = fontMetrics.elidedText(target_source, Qt::ElideMiddle, 280); + if (isIntel) + fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", waiting for receive...")), Qt::ElideMiddle, file_source->width()); + else + fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", waiting for receive.")), Qt::ElideMiddle, file_source->width()); + file_source->setToolTip(target_name); + file_name->setText(fileName); + ft.setPixelSize(14 + size); + file_name->setFont(ft); + file_size->setFont(ft); + window_Title->setFont(ft); +} + +void FileReceivingPopupWidget::initIntelLayout() { + this->setWindowFlags(Qt::Dialog); + this->setFixedSize(478,280); + QFont ft; + ft.setPixelSize(16); + file_size->setFont(ft); + file_name->setFont(ft); + + accept_btn->setGeometry(342,200,112,56); + cancel_btn->setGeometry(214,200,112,56); + file_name->setGeometry(104,75,293,23); + file_size->setGeometry(104,107,293,23); + view_btn->setGeometry(342,200,120,36); + file_source->setGeometry(24,24,430,54); + file_icon->setGeometry(24,71,64,64); + transfer_progress->setGeometry(24,159,430,8); + warn_icon->setGeometry(32,34,22,22); +} + +void FileReceivingPopupWidget::updateUI(QString name, quint64 size, QString type) { + fileNums += 1; + qDebug() << Q_FUNC_INFO << name << size << type; + move_file(); + QFontMetrics fontMetrics(file_source->font()); + QString fileName = fontMetrics.elidedText(name, Qt::ElideMiddle, 280); + configuration_transfer_progress_bar(size); + int unitcount = 0; //将单位B转化为对应的KB、MB等单位 + double calc_size = size; + while(calc_size >= 1024) { + calc_size /= 1024; + unitcount++; + } + qDebug() << type; + target_type = type; + target_source = name; + QIcon fileicon; + if (target_type.split("/").at(0) == "image"){ + fileicon = QIcon::fromTheme("image"); + if (fileicon.isNull()) { + fileicon = QIcon::fromTheme("text"); + } + }else if (target_type.split("/").at(0) == "video") + fileicon = QIcon::fromTheme("video-x-generic"); + else if (target_type.split("/").at(0) == "audio" || + target_type.split("/").at(0) == "application" || + target_type.split("/").at(0) == "text" || + target_type.split("/").at(0) == "inode"){ + if (QIcon::hasThemeIcon(target_type.split("/").join("-"))) { + fileicon = QIcon::fromTheme(target_type.split("/").join("-")); + qDebug() << target_type.split("/").join("-"); + } else { + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme("text-plain"); + } + }else + fileicon = QIcon::fromTheme("text"); + qDebug() << Q_FUNC_INFO << __LINE__; + file_icon->setPixmap(fileicon.pixmap(64,64)); + file_name->setText(fileName); + file_size->setText(QString::asprintf("%.1f", calc_size) + unitString[unitcount]); + file_source->setText(tr("File from \"")+target_name+tr("\", is receiving... \(has recieved ")+QString::number(fileNums)+tr(" files\)")); + this->update(); +} + +void FileReceivingPopupWidget::configuration_transfer_progress_bar(quint64 value) +{ + transfer_progress->setMinimum(0); + transfer_progress->setMaximum(value); + transfer_progress->setValue(0); +} + +void FileReceivingPopupWidget::window_pop_up_animation() +{ + qDebug() << Q_FUNC_INFO << desktop << desktop.right() << desktop.bottom() <geometry(); + +// QPropertyAnimation *window_action = new QPropertyAnimation(this,"geometry"); +// window_action->setDuration(100); +// QRect this_rect = this->rect(); +// this_rect.setHeight(0); +// this_rect.setWidth(0); +// window_action->setStartValue(QRect(desktop.right()-1,desktop.bottom()-this->height(),desktop.right(),desktop.bottom())); +// window_action->setEndValue(QRect(desktop.right()-this->width(),desktop.bottom()-this->height(),desktop.right(),desktop.bottom())); +// window_action->setStartValue(QPoint(desktop.right()-1,desktop.bottom()-this->height())); +// window_action->setEndValue(QPoint(desktop.right()-this->width(),desktop.bottom()-this->height())); +// qDebug() << Q_FUNC_INFO << this_rect << this->geometry() << QRect(desktop.right()-1,desktop.bottom()-this->height(),desktop.right(),desktop.bottom()) <width(),desktop.bottom()-this->height(),desktop.right(),desktop.bottom()); + // window_action->start(); +} + +bool FileReceivingPopupWidget::move_file() +{ + QString s = QDir::homePath()+"/.cache/obexd/"+target_source; + QString d = file_path+"/"+target_source; + + receivedFiles.append(target_source); + + if(!QFile::exists(file_path)){ + int status; + status = mkdir(file_path.toStdString().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + qDebug() << Q_FUNC_INFO << status; + if(status == -1) + return -1; + } + + GError *error; + GFile *source = g_file_new_for_path(s.toStdString().c_str()); + GFile *destination = g_file_new_for_path(d.toStdString().c_str()); + bool flag = g_file_move(source,destination,G_FILE_COPY_OVERWRITE,NULL,NULL,NULL,&error); + qDebug() << Q_FUNC_INFO << "move file" << "target_path =" << s << " source_path =" << d << "flag =" << flag; + return flag; +} + +void FileReceivingPopupWidget::OnClickedAcceptBtn() +{ + transfer_progress->setVisible(true); + accept_btn->setVisible(false); + + QParallelAnimationGroup *actions = new QParallelAnimationGroup(this); + + QPropertyAnimation *progress_action = new QPropertyAnimation(transfer_progress,"geometry"); + QRect transfer_progress_rect = transfer_progress->geometry(); + transfer_progress_rect.setWidth(0); + progress_action->setStartValue(transfer_progress_rect); + progress_action->setEndValue(transfer_progress->geometry()); + progress_action->setDuration(200); + + QPropertyAnimation *cancel_btn_action = new QPropertyAnimation(cancel_btn,"pos"); + cancel_btn_action->setStartValue(cancel_btn->geometry().topLeft()); + if (isIntel) + cancel_btn_action->setEndValue(QPoint(342,200)); + else + cancel_btn_action->setEndValue(QPoint(390,215)); + cancel_btn_action->setDuration(100); + + actions->addAnimation(progress_action); + actions->addAnimation(cancel_btn_action); + actions->start(); + connect(actions,&QParallelAnimationGroup::finished,this,[=]{ + this->accepted(); + }); +} + +void FileReceivingPopupWidget::update_transfer_progress_bar(quint64 value, QString path) +{ + qDebug() << path << _objectPath; + if (path != _objectPath) + return; + transfer_progress->setValue(value); + transfer_progress->repaint(); +} + +void FileReceivingPopupWidget::transferCompelete() { + if (!isIntel) { + close_btn->disconnect(); + close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ + this->close(); + }); + } + cancel_btn->setVisible(false); + + bool x = move_file(); + qDebug() << Q_FUNC_INFO << __LINE__ << x; + if(x){ + QProcess *process = new QProcess(this); + QString cmd = "peony"; + QStringList arg; + qDebug() << Q_FUNC_INFO; + arg << "--show-items"; + for (int i = 0; i < receivedFiles.size(); i++) + arg << file_path+"/"+receivedFiles.at(i); + process->startDetached(cmd,arg); + this->close(); + } + emit clearOldSession(); +} + +void FileReceivingPopupWidget::file_transfer_completed(QString status, QString dev, QString path) +{ + qDebug() << dev << path << _objectPath; + if (path != _objectPath) + return; + if (isCanceled) { + this->close(); + this->deleteLater(); + return; + } + qDebug() << Q_FUNC_INFO <isActive()) { + receiveTimer->stop(); + } else { + QFontMetrics fontMetrics(file_source->font()); + QString fileSource; + fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", is receiving...")), Qt::ElideMiddle, file_source->width()); + file_source->setText(fileSource); + } + + QString filePathName = QDir::homePath()+"/.cache/obexd/"+target_source; + GError *error; + qDebug() << Q_FUNC_INFO << filePathName; + GFile *file = g_file_new_for_path(filePathName.toStdString().c_str()); + GFileInfo *file_info = g_file_query_info(file,"*",G_FILE_QUERY_INFO_NONE,NULL,&error); + qDebug() << Q_FUNC_INFO << g_file_info_get_size(file_info) << g_file_info_get_content_type(file_info); + qDebug() << Q_FUNC_INFO << __LINE__; + + QString str = g_file_info_get_content_type(file_info); + qDebug() << Q_FUNC_INFO << __LINE__; + QIcon fileicon; + if (str.split("/").at(0) == "image"){ + fileicon = QIcon::fromTheme("image"); + if (fileicon.isNull()) { + fileicon = QIcon::fromTheme("text"); + } + }else if (str.split("/").at(0) == "video") + fileicon = QIcon::fromTheme("video-x-generic"); + else if (str.split("/").at(0) == "audio" || + str.split("/").at(0) == "application" || + str.split("/").at(0) == "text" || + str.split("/").at(0) == "inode"){ + if (QIcon::hasThemeIcon(str.split("/").join("-"))) { + fileicon = QIcon::fromTheme(str.split("/").join("-")); + } else { + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(QString("application-")+target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme(QString("application-wps-office.")+target_source.split(".").at(1)); + if (fileicon.isNull()) + fileicon = QIcon::fromTheme("text"); + } + }else + fileicon = QIcon::fromTheme("text"); + qDebug() << Q_FUNC_INFO << __LINE__; + file_icon->setPixmap(fileicon.pixmap(64,64)); + this->update(); + + cancel_btn->disconnect(); + cancel_btn->connect(cancel_btn,&QPushButton::clicked,this,[=]{ + emit this->cancel(); + isCanceled = true; + }); + if (!isIntel) { + close_btn->disconnect(); + close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ + emit this->cancel(); + isCanceled = true; + }); + } + }else if(status == QString("Complete")){ + receiveTimer->start(2000); + qDebug() << Q_FUNC_INFO << __LINE__ ; + }else if(status == QString("Error")){ + accept_btn->setVisible(true); + accept_btn->setText(tr("OK")); + accept_btn->disconnect(); + accept_btn->connect(accept_btn,&QPushButton::clicked,this,[=]{ + this->close(); + }); + if (!isIntel) { + close_btn->disconnect(); + close_btn->connect(close_btn,&QPushButton::clicked,this,[=]{ + this->close(); + }); + } + cancel_btn->setVisible(false); + view_btn->setVisible(false); + transfer_progress->setVisible(false); + file_icon->setVisible(false); + file_name->setVisible(false); + file_size->setVisible(false); + + QFontMetrics fontMetrics(file_source->font()); + QString fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", received failed !")), Qt::ElideMiddle, file_source->width()); + file_source->setText(fileSource); + file_source->setAlignment(Qt::AlignTop); + file_source->setGeometry(62,52,430,60); + warn_icon->setVisible(true); + if (isIntel) { + warn_icon->setFixedSize(64,64); + warn_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-failed.svg")); + file_source->setText(tr("File Transmission Failed !")); + file_source->setStyleSheet("QLabel{\ + font-family: NotoSansCJKsc;\ + font-size: 16px;\ + line-height: 19px;\ + text-align: center;\ + color: #FB5050;}"); + warn_icon->setGeometry(207,57,64,64); + file_source->setGeometry(191,129,200,24); + } + this->activateWindow(); + this->show(); + } +} + +void FileReceivingPopupWidget::cancelReceivingFiles() { + file_transfer_completed(QString("Error"), target_address, _objectPath); +} + +void FileReceivingPopupWidget::GSettings_value_chanage(const QString &key) +{ + if(key == "file-save-path"){ + file_path = settings->get("file-save-path").toString(); + } +} + +void FileReceivingPopupWidget::GSettingsChanges(const QString &key) +{ + qDebug() << Q_FUNC_INFO << key; + if(key == "styleName"){ + QPalette palette; + if(StyleSettings->get("style-name").toString() == "ukui-default" || StyleSettings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(255,255,255)); + }else{ + palette.setColor(QPalette::Background,QColor(0,0,0)); + } + this->setPalette(palette); + this->update(); + } + if (key == "systemFontSize") { + int size = StyleSettings->get("system-font-size").toInt() - 11; + QFont ft; + ft.setPixelSize(18 + size); + file_source->setFont(ft); + QFontMetrics fontMetrics(file_source->font()); + QString fileName = fontMetrics.elidedText(target_source, Qt::ElideMiddle, 280); + QString fileSource; + if (!cancel_btn->isVisible()) { + fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", received failed !")), Qt::ElideMiddle, file_source->width()); + file_source->setAlignment(Qt::AlignTop); + file_source->setGeometry(62,52,430,60); + } else + fileSource = fontMetrics.elidedText(QString(tr("File from \"")+target_name+tr("\", waiting for receive...")), Qt::ElideMiddle, file_source->width()); + file_source->setText(fileSource); + file_source->setToolTip(target_name); + file_name->setText(fileName); + ft.setPixelSize(14 + size); + file_name->setFont(ft); + file_size->setFont(ft); + window_Title->setFont(ft); + } +} + +void FileReceivingPopupWidget::initTransferPath(QString path) { + if (_objectPath.isNull()) + _objectPath = path; + qDebug() << Q_FUNC_INFO << _objectPath; +} diff --git a/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h new file mode 100644 index 0000000..aae9528 --- /dev/null +++ b/ukui-bluetooth/fileReceive/filereceivingpopupwidget.h @@ -0,0 +1,108 @@ +#ifndef FILERECEIVINGPOPUPWIDGET_H +#define FILERECEIVINGPOPUPWIDGET_H + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + +class FileReceivingPopupWidget : public QWidget +{ + Q_OBJECT +public: + explicit FileReceivingPopupWidget(QString address, QString devname = "", QString filename = "", QString type = "", QString root = "", quint64 size = 0); + ~FileReceivingPopupWidget(); + void configuration_transfer_progress_bar(quint64); + void window_pop_up_animation(); + bool move_file(); +public slots: + void updateUI(QString name, quint64 size, QString type); + void OnClickedAcceptBtn(); + void update_transfer_progress_bar(quint64, QString path); + void file_transfer_completed(QString status, QString dev, QString path); + void cancelReceivingFiles(); + void GSettings_value_chanage(const QString &key); + void GSettingsChanges(const QString &key); + void transferCompelete(); + void initTransferPath(QString path); +signals: + void cancel(); + void rejected(); + void accepted(); + void clearOldSession(); +private: + bool isCanceled = false; + bool isIntel = false; + QGSettings *StyleSettings = nullptr; + QGSettings *settings = nullptr; + QGSettings *transparency_gsettings = nullptr; + + QPushButton *close_btn = nullptr; + QPushButton *cancel_btn = nullptr; + QPushButton *accept_btn = nullptr; + QPushButton *view_btn = nullptr; + + QLabel *icon_label = nullptr; + QLabel *file_source = nullptr; + QLabel *window_Title = nullptr; + QLabel *file_name = nullptr; + QLabel *file_size = nullptr; + QLabel *file_icon = nullptr; + QLabel *warn_icon = nullptr; + QProgressBar *transfer_progress = nullptr; + + QRect desktop; + QString unitString[5] = {"B", "KB", "MB", "GB", "TB"}; + QString target_address; + QString target_name; + QString target_source; + QString target_type; + QString root_address; + QString file_path; + quint64 target_size; + QString _objectPath; + QTimer *receiveTimer; + int fileNums = 0; + QList receivedFiles; + + void initLayout(); + void initIntelLayout(); + +}; + +#endif // FILERECEIVINGPOPUPWIDGET_H diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp new file mode 100644 index 0000000..dcc3ece --- /dev/null +++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.cpp @@ -0,0 +1,633 @@ +#include "bluetoothfiletransferwidget.h" +#include "config/xatom-helper.h" + +bool BluetoothFileTransferWidget::isShow = false; +BluetoothFileTransferWidget::BluetoothFileTransferWidget(QStringList files, QMap devicelist, QString dev_address): +// QWidget(parent), + selectedFiles(files) +{ + fileNums = selectedFiles.size(); + isShow = true; + send_state = _SEND_NONE; + + is_Intel = QFile::exists("/etc/apt/ota_version"); + + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + GSettings = new QGSettings("org.ukui.style"); + connect(GSettings,&QGSettings::changed,this,&BluetoothFileTransferWidget::GSettingsChanges); + } + + //窗管协议 + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; + if (is_Intel) + hints.functions = MWM_FUNC_CLOSE; + else + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); + + qDebug() << Q_FUNC_INFO << __LINE__; + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("Bluetooth file transfer")); + this->setAttribute(Qt::WA_DeleteOnClose); + + QPalette palette; + if(GSettings->get("style-name").toString() == "ukui-default" || GSettings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(255,255,255)); + }else{ + palette.setColor(QPalette::Background,QColor(0,0,0)); + } + this->setPalette(palette); + this->setAutoFillBackground(true); + + QDesktopWidget *deskdop = QApplication::desktop(); + move((deskdop->width()-this->width())/2, (deskdop->height()-this->height())/2); + + tip_text = new QLabel(tr("Transferring to \"")+dev_name+"\"",this); + + tip_text->setWordWrap(true); + tip_text->setVisible(false); + + initFileInfo(); + + target_icon = new QLabel(this); + target_icon->setPixmap(file_icon.at(0).pixmap(64,64)); + + int ii = file_size.at(0).indexOf('i'); + QString _tmp_size = file_size.at(0); + _tmp_size.remove(ii, ii); + if (_tmp_size.at(_tmp_size.size() - 1) != 'B') + _tmp_size.append("B"); + + target_size = new QLabel(_tmp_size,this); + + QFontMetrics fontMetrics(target_size->font()); + QString fileName; + QString Name = selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1); + if (fileNums > 1) { + fileName = fontMetrics.elidedText("\"" + + Name + +"\"", Qt::ElideMiddle, 280); + fileName.append(tr(" and ")+QString::number(fileNums)+tr(" files more")); + }else + fileName = fontMetrics.elidedText(Name, Qt::ElideMiddle, 280); + target_name = new QLabel(fileName,this); + target_name->setToolTip(Name); + + + transNum = new QLabel("1/"+QString::number(fileNums), this); + transNum->setVisible(false); + + m_progressbar = new QProgressBar(this); + m_progressbar->setOrientation(Qt::Horizontal); + m_progressbar->setTextVisible(false); + m_progressbar->setVisible(false); + + Tiptop = new QLabel(tr("Select Device"),this); + Tiptop->setFixedSize(100,20); + + dev_widget = new DeviceSeleterWidget(devicelist, this,dev_address); + + ok_btn = new QPushButton(tr("OK"),this); + ok_btn->setFixedSize(100,36); + if(dev_widget->get_seleter_device().isNull()){ + ok_btn->setEnabled(false); + } + connect(dev_widget, &DeviceSeleterWidget::sign_select, this, [=] { + ok_btn->setEnabled(true); + }); + connect(dev_widget, &DeviceSeleterWidget::unsign_select, this, [=] { + ok_btn->setEnabled(false); + }); + connect(ok_btn,&QPushButton::clicked,this,&BluetoothFileTransferWidget::onClicked_OK_Btn); + + cancel_btn = new QPushButton(tr("Cancel"),this); + cancel_btn->setFixedSize(100,36); + connect(cancel_btn,&QPushButton::clicked,this,[=]{ + emit this->close_the_pre_session(); + this->close(); + }); + + tranfer_status_icon = new QLabel(this); + tranfer_status_icon->setPixmap(QIcon::fromTheme("kylin-dialog-warning").pixmap(22,22)); + if (tranfer_status_icon->pixmap()->isNull()) + tranfer_status_icon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(22,22)); + tranfer_status_icon->setFixedSize(22,22); + tranfer_status_icon->setVisible(false); + + tranfer_status_text = new QLabel(this); + tranfer_status_text->setText(tr("File Transmission Failed !")); + tranfer_status_text->setVisible(false); + + if (is_Intel) + initIntelLayout(); + else + initLayout(); + + init_m_progressbar_value(_filesize.at(0)); +} + +BluetoothFileTransferWidget::~BluetoothFileTransferWidget() +{ + isShow = false; +} + +void BluetoothFileTransferWidget::initLayout() { + this->setFixedSize(520,620); + title_icon = new QLabel(this); + title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22,22)); + title_icon->resize(22,22); + + title_text = new QLabel(tr("Bluetooth file transfer"),this); + + close_btn = new QPushButton(this); + close_btn->setIcon(QIcon::fromTheme("window-close-symbolic")); + close_btn->setProperty("isWindowButton", 0x2); + close_btn->setProperty("useIconHighlightEffect", 0x8); + close_btn->setFlat(true); + close_btn->setFixedSize(30,30); + connect(close_btn,&QPushButton::clicked,this,[=]{ + emit close_the_pre_session(); + this->close(); + }); + + //布局 + dev_widget->resize(456,356); + title_icon->setGeometry(8,8,22,22); + title_text->setGeometry(36,8,200,20); + close_btn->setGeometry(484,4,30,30); + tranfer_status_text->setGeometry(62,53,376,27); + tranfer_status_icon->setGeometry(32,55,22,22); + cancel_btn->setGeometry(280,560,100,36); + ok_btn->setGeometry(392,560,100,36); + dev_widget->setGeometry(32,175,456,356); + Tiptop->setGeometry(32,144,100,20); + target_size->setGeometry(112,88,88,30); + tip_text->setGeometry(32,52,452,56); + target_icon->setGeometry(32,56,64,64); + target_name->setGeometry(112,63,400,30); + transNum->setGeometry(459,168,52,20); + if (fileNums > 1) + m_progressbar->setGeometry(32,185,406,8); + else + m_progressbar->setGeometry(32,185,454,8); + + //字体 + int size = GSettings->get("system-font-size").toInt() - 11; + QFont ft; + ft.setPixelSize(14+size); + title_text->setFont(ft); + target_size->setFont(ft); + target_name->setFont(ft); + transNum->setFont(ft); + Tiptop->setFont(ft); + ft.setPixelSize(18+size); + tip_text->setFont(ft); + tranfer_status_text->setFont(ft); +} + +void BluetoothFileTransferWidget::initIntelLayout() { + this->setWindowFlags(Qt::Dialog); + this->setFixedSize(478,530); + cancel_btn->setFixedSize(112,56); + ok_btn->setFixedSize(112,56); + target_name->setFixedHeight(30); + target_size->setFixedWidth(88); + dev_widget->resize(430,296); + + ok_btn->setGeometry(342,450,112,56); + cancel_btn->setGeometry(214,450,112,56); + tranfer_status_text->setGeometry(62,33,376,27); + tranfer_status_icon->setGeometry(32,35,22,22); + dev_widget->setGeometry(24,139,430,296); + Tiptop->setGeometry(32,111,100,20); + target_size->setGeometry(104,60,88,30); + tip_text->setGeometry(24,24,430,56); + target_icon->setGeometry(24,24,64,64); + target_name->setGeometry(104,28,400,30); + transNum->setGeometry(410,148,52,20); + if (fileNums > 1) + m_progressbar->setGeometry(24,155,372,8); + else + m_progressbar->setGeometry(24,155,420,8); + + int size = GSettings->get("system-font-size").toInt() - 11; + QFont ft; + ft.setPixelSize(14+size); + target_size->setFont(ft); + target_name->setFont(ft); + transNum->setFont(ft); + Tiptop->setFont(ft); + ft.setPixelSize(18+size); + tip_text->setFont(ft); + tranfer_status_text->setFont(ft); + this->show(); + this->activateWindow(); +} + +void BluetoothFileTransferWidget::initFileInfo() { + for (int i = 0; i < fileNums; i++) { + Get_fie_type(i); + } + qDebug() << Q_FUNC_INFO << __LINE__; +} + +void BluetoothFileTransferWidget::Get_fie_type(int i) +{ + GError *error; + qDebug() << Q_FUNC_INFO << selectedFiles.at(i); + GFile *file = g_file_new_for_path(selectedFiles.at(i).toStdString().c_str()); + GFileInfo *file_info = g_file_query_info(file,"*",G_FILE_QUERY_INFO_NONE,NULL,&error); + qDebug() << Q_FUNC_INFO << g_file_info_get_size(file_info) << g_file_info_get_content_type(file_info); + qDebug() << Q_FUNC_INFO << __LINE__; + + file_size.push_back(g_format_size_full(g_file_info_get_size(file_info),G_FORMAT_SIZE_IEC_UNITS)); + _filesize.push_back(g_file_info_get_size(file_info)); + if (g_file_info_get_size(file_info) == 0) { + QMessageBox *mbox = new QMessageBox(QMessageBox::Warning,tr("Warning"),tr("The selected file is empty, please select the file again !"),QMessageBox::Ok); + QDesktopWidget *desktop = QApplication::desktop(); + mbox->move((desktop->width()-mbox->width())/2,(desktop->height()-mbox->height())/2); + mbox->exec(); + this->deleteLater(); + } + QString str = g_file_info_get_content_type(file_info); + filetype.push_back(str); + qDebug() << Q_FUNC_INFO << __LINE__; + QIcon fileicon; + if (str.split("/").at(0) == "image"){ + fileicon = QIcon(selectedFiles.at(i)); + if (fileicon.isNull()) { + fileicon = QIcon::fromTheme("text"); + } + }else if (str.split("/").at(0) == "video") + fileicon = QIcon::fromTheme("video-x-generic"); + else if (str.split("/").at(0) == "audio" || + str.split("/").at(0) == "application" || + str.split("/").at(0) == "text" || + str.split("/").at(0) == "inode"){ + if (QIcon::hasThemeIcon(str.split("/").join("-"))) { + fileicon = QIcon::fromTheme(str.split("/").join("-")); + } else { + fileicon = QIcon::fromTheme("text"); + } + }else + fileicon = QIcon::fromTheme("text"); + qDebug() << Q_FUNC_INFO << __LINE__; + file_icon.push_back(fileicon); +} + +void BluetoothFileTransferWidget::Initialize_and_start_animation() +{ + this->setFixedSize(520,276); + + + + QString nName; + nName = dev_widget->get_seleter_dev_name(); + float shownum = 0; + for (int i = 0; i < dev_widget->get_seleter_dev_name().size(); i++) { + QChar ch = dev_widget->get_seleter_dev_name().at(i); + ushort uNum = ch.unicode(); + if ((uNum >= 0x4E00 && uNum <= 0x9FA5)) + shownum += 1.7; + else if (ch == 'm' || ch == 'M') + shownum += 1.5; + else + shownum += 1; + if (shownum + 1.5 >= 30) { + nName.remove(i, dev_widget->get_seleter_dev_name().size() - i); + nName.append("..."); + tip_text->setToolTip(dev_widget->get_seleter_dev_name()); + break; + } + } + + tip_text->setText(tr("Transferring to \"")+nName+"\""); + tip_text->update(); + + ok_btn->setVisible(false); + cancel_btn->setVisible(true); + m_progressbar->setVisible(true); + transNum->setVisible(fileNums - 1); + Tiptop->setVisible(false); + dev_widget->setVisible(false); + tip_text->setVisible(true); + if (is_Intel) { + cancel_btn->setGeometry(342, 200, 112, 56); + target_icon->setGeometry(24,67,64,64); + target_name->setGeometry(104,71,400,30); + target_size->setGeometry(104,103,88,30); + } else { + cancel_btn->setGeometry(376, 213, 100, 36); + target_icon->setGeometry(32,105,64,64); + target_name->setGeometry(112,112,400,30); + target_size->setGeometry(112,137,88,30); + } + + main_animation_group = new QParallelAnimationGroup(this); + + QPropertyAnimation *progress_action = new QPropertyAnimation(m_progressbar,"geometry"); + QRect transfer_progress_rect = m_progressbar->geometry(); + transfer_progress_rect.setWidth(0); + progress_action->setStartValue(transfer_progress_rect); + progress_action->setEndValue(m_progressbar->geometry()); + progress_action->setDuration(200); + + main_animation_group->addAnimation(progress_action); + main_animation_group->start(); + connect(main_animation_group,&QParallelAnimationGroup::finished,this,[=]{ + if (is_Intel) + this->setFixedSize(478,280); + else + this->setFixedSize(520,276); + }); +} + +void BluetoothFileTransferWidget::init_m_progressbar_value(quint64 value) +{ +#if 0 + qDebug() << Q_FUNC_INFO << value; + m_progressbar->setMinimum(0); + m_progressbar->setMaximum(value); + m_progressbar->setValue(0); +#else + qDebug() << Q_FUNC_INFO << value; + m_curr_filesize = value ; + qDebug() << Q_FUNC_INFO << "m_curr_filesize:" << m_curr_filesize; + + m_progressbar->setMinimum(0); + m_progressbar->setMaximum(QPROGRESSBAR_MAX_IMUM); + m_progressbar->setValue(0); +#endif +} + +void BluetoothFileTransferWidget::insertNewFileList(QStringList fileList) { + QList fileIconList; + QList _fileSizeList; + QList fileSizeList; + QList filetypeList; + for (int i = 0; i < fileList.size(); i++) { + GError *error; + qDebug() << Q_FUNC_INFO << fileList.at(i); + GFile *file = g_file_new_for_path(fileList.at(i).toStdString().c_str()); + GFileInfo *file_info = g_file_query_info(file,"*",G_FILE_QUERY_INFO_NONE,NULL,&error); + qDebug() << Q_FUNC_INFO << g_file_info_get_size(file_info) << g_file_info_get_content_type(file_info); + qDebug() << Q_FUNC_INFO << __LINE__; + + fileSizeList.push_back(g_format_size_full(g_file_info_get_size(file_info),G_FORMAT_SIZE_IEC_UNITS)); + _fileSizeList.push_back(g_file_info_get_size(file_info)); + QString str = g_file_info_get_content_type(file_info); + filetypeList.push_back(str); + qDebug() << Q_FUNC_INFO << __LINE__; + QIcon fileicon; + if (str.split("/").at(0) == "image"){ + fileicon = QIcon(fileList.at(i)); + if (fileicon.isNull()) { + fileicon = QIcon::fromTheme("text"); + } + }else if (str.split("/").at(0) == "video") + fileicon = QIcon::fromTheme("video-x-generic"); + else if (str.split("/").at(0) == "audio" || + str.split("/").at(0) == "application" || + str.split("/").at(0) == "text" || + str.split("/").at(0) == "inode"){ + if (QIcon::hasThemeIcon(str.split("/").join("-"))) { + fileicon = QIcon::fromTheme(str.split("/").join("-")); + } else { + fileicon = QIcon::fromTheme("text"); + } + }else + fileicon = QIcon::fromTheme("text"); + qDebug() << Q_FUNC_INFO << __LINE__; + fileIconList.push_back(fileicon); + } + filetype.append(filetypeList); + file_icon.append(fileIconList); + file_size.append(fileSizeList); + _filesize.append(_fileSizeList); + selectedFiles.append(fileList); + fileNums += fileList.size(); + QFontMetrics fontMetrics(target_size->font()); + if (selectedFiles.size() == 1) + target_name->setText(fontMetrics.elidedText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1), Qt::ElideMiddle, 280)); + else if(selectedFiles.size() > 1) + { + target_name->setText(fontMetrics.elidedText("\"" + +selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1) + +"\"", Qt::ElideMiddle, 280).append(tr(" and ")+QString::number(fileNums)+tr(" files more"))); + } + target_name->setToolTip(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1)); + int transfing = fileNums - selectedFiles.size() + 1; + transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); + if (is_Intel) + if (fileNums > 1) + m_progressbar->setGeometry(24,155,372,8); + else + m_progressbar->setGeometry(24,155,420,8); + else + if (fileNums > 1) + m_progressbar->setGeometry(32,185,406,8); + else + m_progressbar->setGeometry(32,185,454,8); + transNum->setVisible(fileNums - 1); + this->update(); + this->show(); + this->activateWindow(); +} + + +void BluetoothFileTransferWidget::get_transfer_status(QString status, QString dev, QString path) +{ + if (path != _objectPath && path != QString("")) + return; + qDebug() << Q_FUNC_INFO << status << dev; + if(status == QString("Complete")){ + if (selectedFiles.size() > 1) { + emit continueSendFiles(selectedFiles.at(1) + QString(" ") + filetype.at(1)); + selectedFiles.pop_front(); + file_size.pop_front(); + file_icon.pop_front(); + _filesize.pop_front(); + QFontMetrics fontMetrics(target_size->font()); + if (selectedFiles.size() == 1) + target_name->setText(fontMetrics.elidedText(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1), Qt::ElideMiddle, 280)); + else if(selectedFiles.size() > 1) + { + target_name->setText(fontMetrics.elidedText("\"" + +selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1) + +"\"", Qt::ElideMiddle, 280).append(tr(" and ")+QString::number(fileNums)+tr(" files more"))); + } + else + { + tranfer_error(); + this->show(); + this->send_state = _SEND_FAILURE ; + } + target_name->setToolTip(selectedFiles.at(0).split("/").at(selectedFiles.at(0).split("/").length()-1)); + init_m_progressbar_value(_filesize.at(0)); + + int ii = file_size.at(0).indexOf('i'); + QString _tmp_size = file_size.at(0); + _tmp_size.remove(ii, ii); + if (_tmp_size.at(_tmp_size.size() - 1) != 'B') + _tmp_size.append("B"); + + target_size->setText(_tmp_size); + target_icon->setPixmap(file_icon.at(0).pixmap(64,64)); + int transfing = fileNums - selectedFiles.size() + 1; + transNum->setText(QString::number(transfing)+"/"+QString::number(fileNums)); + this->show(); + this->activateWindow(); + return; + } + selectedFiles.clear(); + file_size.clear(); + file_icon.clear(); + if(main_animation_group->state() == QAbstractAnimation::Running){ + connect(main_animation_group,&QParallelAnimationGroup::finished,this,[=]{ + tip_text->setVisible(false); + m_progressbar->setVisible(false); + transNum->setVisible(false); + }); + } + tip_text->setVisible(false); + m_progressbar->setVisible(false); + transNum->setVisible(false); + + if(is_Intel) { + cancel_btn->setText(tr("OK")); + tranfer_status_icon->setFixedSize(64,64); + tranfer_status_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-success.svg")); + tranfer_status_text->setText(tr("File Transmition Succeed!")); + tranfer_status_text->setFixedWidth(500); + QFont ft; + ft.setPixelSize(16); + tranfer_status_text->setFont(ft); + if (is_Intel) { + tranfer_status_icon->setGeometry(207,57,64,64); + tranfer_status_text->setGeometry(191,129,200,24); + } else { + tranfer_status_icon->setGeometry(220,86,64,64); + tranfer_status_text->setGeometry(12,150,500,24); + } + } else { + tranfer_status_icon->setPixmap(QIcon::fromTheme("ukui-dialog-success").pixmap(22,22)); + tranfer_status_text->setText(tr("File Transmition Succeed!")); + } + tranfer_status_icon->setVisible(true); + tranfer_status_text->setVisible(true); + target_icon->setVisible(false); + target_name->setVisible(false); + target_size->setVisible(false); + + cancel_btn->setText(tr("Close")); + this->show(); + this->activateWindow(); + this->send_state = _SEND_COMPLETE ; + }else if(status == QString("Active")){ + this->send_state = _SENDING ; + }else if(status == QString("Error")){ + tranfer_error(); + this->send_state = _SEND_FAILURE ; + this->show(); + } +} + +void BluetoothFileTransferWidget::tranfer_error() +{ + tip_text->setVisible(false); + m_progressbar->setVisible(false); + transNum->setVisible(false); + target_icon->setVisible(false); + target_name->setVisible(false); + target_size->setVisible(false); + Tiptop->setVisible(false); + dev_widget->setVisible(false); + + if (is_Intel){ + tranfer_status_icon->setFixedSize(64,64); + tranfer_status_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/file-transfer-failed.svg")); + tranfer_status_text->setFixedWidth(500); + QFont ft; + ft.setPixelSize(16); + tranfer_status_text->setFont(ft); + tranfer_status_icon->setGeometry(207,57,64,64); + tranfer_status_text->setGeometry(191,129,200,24); + } + + tranfer_status_icon->setVisible(true); + tranfer_status_text->setVisible(true); + + cancel_btn->setText(tr("OK")); + this->show(); + this->activateWindow(); +} + +int BluetoothFileTransferWidget::get_send_data_state() +{ + return this->send_state; +} + +void BluetoothFileTransferWidget::set_m_progressbar_value(quint64 value, QString path) +{ + if (path != _objectPath) + return; + if(--active_flag <= 0) + { + int size = (value * QPROGRESSBAR_MAX_IMUM)/m_curr_filesize; + m_progressbar->setValue(size); + } + m_progressbar->repaint(); +} + +void BluetoothFileTransferWidget::GSettingsChanges(const QString &key) +{ + qDebug() << Q_FUNC_INFO << key; + if(key == "styleName"){ + QPalette palette; + if(GSettings->get("style-name").toString() == "ukui-default" || GSettings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(255,255,255)); + target_icon->setProperty("setIconHighlightEffectDefaultColor", QColor(0,0,0)); + target_icon->setProperty("useIconHighlightEffect", 0x10); + }else{ + palette.setColor(QPalette::Background,QColor(0,0,0)); + target_icon->setProperty("setIconHighlightEffectDefaultColor", QColor(255,255,255)); + target_icon->setProperty("useIconHighlightEffect", 0x10); + } + this->setPalette(palette); + this->update(); + } + if (key == "systemFontSize") { + int size = GSettings->get("system-font-size").toInt() - 11; + QFont ft; + ft.setPixelSize(14+size); + title_text->setFont(ft); + target_size->setFont(ft); + target_name->setFont(ft); + transNum->setFont(ft); + Tiptop->setFont(ft); + ft.setPixelSize(18+size); + tip_text->setFont(ft); + tranfer_status_text->setFont(ft); + } +} + +void BluetoothFileTransferWidget::onClicked_OK_Btn() +{ + QString dev_addr = dev_widget->get_seleter_device(); + qDebug() << Q_FUNC_INFO << dev_addr; + + if(dev_widget->get_seleter_device() == ""){ + + }else{ + Initialize_and_start_animation(); + emit this->sender_dev_name(dev_addr, filetype.at(0)); + } +} + +void BluetoothFileTransferWidget::initTransferPath(QString path) { + if (_objectPath.isNull()) + _objectPath = path; + qDebug() << Q_FUNC_INFO << _objectPath; +} diff --git a/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h new file mode 100644 index 0000000..ec058d1 --- /dev/null +++ b/ukui-bluetooth/fileSend/bluetoothfiletransferwidget.h @@ -0,0 +1,148 @@ +#ifndef BLUETOOTHFILETRANSFERWIDGET_H +#define BLUETOOTHFILETRANSFERWIDGET_H + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include "deviceseleterwidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" +#define QPROGRESSBAR_MAX_IMUM 1000 +class DeviceSeleterWidget; + +enum FILE_TYPE{ + Normal, + mp3, + mp4, + image, +}; + +class BluetoothFileTransferWidget : public QWidget +{ + Q_OBJECT +public: + enum Status { + /** Indicates that the transfer is queued. */ + Queued, + /** Indicates that the transfer is active. */ + Active, + /** Indicates that the transfer is suspended. */ + Suspended, + /** Indicates that the transfer have completed successfully. */ + Complete, + /** Indicates that the transfer have failed with error. */ + Error, + /** Indicates that the transfer status is unknown. */ + Unknown + }; + Q_ENUM(Status) + + explicit BluetoothFileTransferWidget(QStringList files, QMap devicelist, QString dev_address = ""); + ~BluetoothFileTransferWidget(); + + typedef enum _SEND_DATA_STATE + { + _SEND_NONE = 0, + _SEND_COMPLETE, + _SENDING, + _SEND_FAILURE + + }SEND_DATA_STATE; + + static bool isShow; + + void Get_fie_type(int i); + void initFileInfo(); + void Get_file_size(float); + void Initialize_and_start_animation(); + void init_m_progressbar_value(quint64); + void tranfer_error(); + void initTransferPath(QString path); + void insertNewFileList(QStringList fileList); + + int get_send_data_state(); + +signals: + void sender_dev_name(QString, QString); + void close_the_pre_session(); + void continueSendFiles(QString); +public slots: + void onClicked_OK_Btn(); + void set_m_progressbar_value(quint64, QString); + void get_transfer_status(QString, QString, QString); + void GSettingsChanges(const QString &key); +private: + QGSettings *GSettings = nullptr; + QGSettings *transparency_gsettings = nullptr; + QLabel *tip_text = nullptr; + QLabel *title_icon = nullptr; + QLabel *title_text = nullptr; + QLabel *target_icon = nullptr; + QLabel *target_name = nullptr; + QLabel *target_size = nullptr; + QLabel *Tiptop = nullptr; + QLabel *transNum = nullptr; + int fileNums = 0; + + QLabel *tranfer_status_icon = nullptr; + QLabel *tranfer_status_text = nullptr; + DeviceSeleterWidget *dev_widget = nullptr; + QParallelAnimationGroup *main_animation_group = nullptr; + QProgressBar *m_progressbar = nullptr; + QPushButton *close_btn = nullptr; + QPushButton *cancel_btn = nullptr; + QPushButton *ok_btn = nullptr; + + QList file_icon; + int active_flag = 2; + QStringList selectedFiles; + QList file_size; + QList _filesize; + QList filetype; + QString dev_name; + QString _objectPath; + SEND_DATA_STATE send_state = _SEND_NONE; + bool is_Intel = false; + + quint64 m_curr_filesize; + void initLayout(); + void initIntelLayout(); +}; + +#endif // BLUETOOTHFILETRANSFERWIDGET_H diff --git a/ukui-bluetooth/fileSend/deviceselectitem.cpp b/ukui-bluetooth/fileSend/deviceselectitem.cpp new file mode 100644 index 0000000..cbd5760 --- /dev/null +++ b/ukui-bluetooth/fileSend/deviceselectitem.cpp @@ -0,0 +1,222 @@ +#include "deviceselectitem.h" + +DeviceSelectItem::DeviceSelectItem(QString name, QString address, QIcon icon, QWidget *parent) : + QLabel(parent), + MName(name), + MAddress(address), + MIcon(icon), + _MStatus(Normal) +{ + this->setProperty("useSystemStyleBlur", true); + this->setAttribute(Qt::WA_TranslucentBackground); + + if (QFile::exists("/etc/apt/ota_version")) + this->setFixedSize(400,50); + else + this->setFixedSize(430, 50); + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,[=]{ + this->update(); + }); + } + + const QByteArray transparency_id(TRANSPARENCY_SETTINGS); + if(QGSettings::isSchemaInstalled(transparency_id)){ + transparency_gsettings = new QGSettings(transparency_id); + } + if(QGSettings::isSchemaInstalled(transparency_id)){ + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + connect(transparency_gsettings, &QGSettings::changed, this, [=] { + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + this->update(); + }); + } + this->setToolTip(MName); +} + +DeviceSelectItem::~DeviceSelectItem(){ + +} + +void DeviceSelectItem::setUnselectedState() { + _MStatus = Normal; + choosed = false; + this->update(); +} + +void DeviceSelectItem::setSelectedState() { + _MStatus = Choose; + choosed = true; + QStringList device; + device.append(MName); + device.append(MAddress); + emit clicked(device); + this->update(); +} + +QString DeviceSelectItem::getAddress() { + return MAddress; +} + +QColor DeviceSelectItem::getPainterBrushColor() +{ + QColor color; + switch (_MStatus) { + case Status::Normal: + if(StyleSettings->get("style-name").toString() == "ukui-default" + || StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(255,255,255,0); + else + color = QColor(0,0,0,0); + break; + case Status::Hover: + if(StyleSettings->get("style-name").toString() == "ukui-default" + || StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(217,217,217,tran); + else + color = QColor(55, 55, 59, tran); + break; + case Status::Click: + if(StyleSettings->get("style-name").toString() == "ukui-default" + || StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(209, 209, 209,tran); + else + color = QColor(102, 102, 102, tran); + break; + case Status::Choose: + color = QColor(55, 144, 250,tran); + break; + default: + if(StyleSettings->get("style-name").toString() == "ukui-default" + || StyleSettings->get("style-name").toString() == "ukui-light") + color = QColor(255,255,255,0); + else + color = QColor(0,0,0,0); + break; + } + return color; +} + +const QPixmap DeviceSelectItem::loadSvg(const QPixmap &source, const PixmapColor &cgColor) +{ + QImage img = source.toImage(); + for (int x = 0; x < img.width(); x++) { + for (int y = 0; y < img.height(); y++) { + auto color = img.pixelColor(x, y); + if (color.alpha() > 0) { + switch (cgColor) { + case PixmapColor::WHITE: + color.setRed(255); + color.setGreen(255); + color.setBlue(255); + img.setPixelColor(x, y, color); + break; + case PixmapColor::BLACK: + color.setRed(0); + color.setGreen(0); + color.setBlue(0); + img.setPixelColor(x, y, color); + break; + case PixmapColor::GRAY: + color.setRed(152); + color.setGreen(163); + color.setBlue(164); + img.setPixelColor(x, y, color); + break; + case PixmapColor::BLUE: + color.setRed(61); + color.setGreen(107); + color.setBlue(229); + img.setPixelColor(x, y, color); + break; + default: + return source; + break; + } + } + } + } + return QPixmap::fromImage(img); +} + +void DeviceSelectItem::enterEvent(QEvent *event) { + Q_UNUSED(event); + if (choosed) + _MStatus = Choose; + else + _MStatus = Hover; + this->update(); +} + +void DeviceSelectItem::leaveEvent(QEvent *event) { + Q_UNUSED(event); + if (choosed) + _MStatus = Choose; + else + _MStatus = Normal; + this->update(); +} + +void DeviceSelectItem::mousePressEvent(QMouseEvent *ev) { + Q_UNUSED(ev); + _MStatus = Click; + this->update(); +} + +void DeviceSelectItem::mouseReleaseEvent(QMouseEvent *ev) { + Q_UNUSED(ev); + choosed = !choosed; + if (choosed) { + _MStatus = Choose; + QStringList device; + device.append(MName); + device.append(MAddress); + emit clicked(device); + } else { + _MStatus = Hover; + emit unclicked(); + } + this->update(); +} + +void DeviceSelectItem::paintEvent(QPaintEvent *) { + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(QColor(Qt::transparent)); + painter.setBrush(getPainterBrushColor()); + painter.drawRoundedRect(this->rect(),6,6,Qt::AbsoluteSize); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + if(StyleSettings->get("style-name").toString() == "ukui-default" || StyleSettings->get("style-name").toString() == "ukui-light") { + painter.setPen(QColor(Qt::black)); + style()->drawItemPixmap(&painter, QRect(8, 13, 24, 24), Qt::AlignCenter, MIcon.pixmap(24,24)); + } else { + painter.setPen(QColor(Qt::white)); + style()->drawItemPixmap(&painter, QRect(8, 13, 24, 24), Qt::AlignCenter, loadSvg(MIcon.pixmap(24,24), PixmapColor::WHITE)); + } + QString nName; + nName = MName; + int fontSize = StyleSettings->get("system-font-size").toInt(); + if (fontSize > 15) + fontSize = 15; + if (fontSize < 10) + fontSize = 10; + float shownum = 0; + for (int i = 0; i < MName.size(); i++) { + QChar ch = MName.at(i); + ushort uNum = ch.unicode(); + if ((uNum >= 0x4E00 && uNum <= 0x9FA5)) + shownum += 1.7; + else if (ch == 'm' || ch == 'M') + shownum += 1.5; + else + shownum += 1; + if (shownum + 1.5 >= FontTable[fontSize - 10]) { + nName.remove(i, MName.size() - i); + nName.append("..."); + this->setToolTip(MName); + break; + } + } + painter.drawText(40,13,380,28,Qt::AlignLeft, nName); +} diff --git a/ukui-bluetooth/fileSend/deviceselectitem.h b/ukui-bluetooth/fileSend/deviceselectitem.h new file mode 100644 index 0000000..fb3c29c --- /dev/null +++ b/ukui-bluetooth/fileSend/deviceselectitem.h @@ -0,0 +1,68 @@ +#ifndef DEVICESELECTITEM_H +#define DEVICESELECTITEM_H + +#include +#include +#include +#include +#include +#include +#include + +#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + +class DeviceSelectItem : public QLabel +{ + Q_OBJECT +public: + DeviceSelectItem(QString name, QString address, QIcon icon, QWidget *parent); + ~DeviceSelectItem(); + + void setUnselectedState(); + void setSelectedState(); + QString getAddress(); + + enum Status{ + Hover = 0, + Normal, + Click, + Choose + }; + Q_ENUM(Status) + + enum PixmapColor { + WHITE = 0, + BLACK, + GRAY, + BLUE, + }; + Q_ENUM(PixmapColor) + int FontTable[6] = {48, 44, 42, 40, 34, 32}; +private: + QIcon MIcon; + QString MName; + QString MAddress; + Status _MStatus; + + QGSettings *StyleSettings = nullptr; + QGSettings *transparency_gsettings = nullptr; + double tran =1; + bool choosed = false; + + QColor getPainterBrushColor(); + const QPixmap loadSvg(const QPixmap &source, const PixmapColor &cgColor); + +protected: + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); + void mousePressEvent(QMouseEvent *ev); + void mouseReleaseEvent(QMouseEvent *ev); + void paintEvent(QPaintEvent *); + +signals: + void clicked(QStringList); + void unclicked(); +}; + +#endif // DEVICESELECTITEM_H diff --git a/ukui-bluetooth/fileSend/deviceseleterwidget.cpp b/ukui-bluetooth/fileSend/deviceseleterwidget.cpp new file mode 100644 index 0000000..95899f5 --- /dev/null +++ b/ukui-bluetooth/fileSend/deviceseleterwidget.cpp @@ -0,0 +1,175 @@ +#include "deviceseleterwidget.h" + +DeviceSeleterWidget::DeviceSeleterWidget(QMap pairdeviceList, QWidget *parent, QString dev): + QWidget(parent), + select_dev(dev), + deviceList(pairdeviceList) +{ + isIntel = QFile::exists("/etc/apt/ota_version"); + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + GSettings = new QGSettings("org.ukui.style"); + connect(GSettings,&QGSettings::changed,this,&DeviceSeleterWidget::GSettingsChanges); + } + if(QGSettings::isSchemaInstalled("org.ukui.bluetooth")){ + settings = new QGSettings("org.ukui.bluetooth"); + } + + const QByteArray transparency_id(TRANSPARENCY_SETTINGS); + if(QGSettings::isSchemaInstalled(transparency_id)){ + transparency_gsettings = new QGSettings(transparency_id); + } + if(QGSettings::isSchemaInstalled(transparency_id)){ + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + connect(transparency_gsettings, &QGSettings::changed, this, [=] { + tran=transparency_gsettings->get(TRANSPARENCY_KEY).toDouble()*255; + this->update(); + }); + } + this->resize(456,356); + + QPalette palette; + if(GSettings->get("style-name").toString() == "ukui-default" || GSettings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(240,240,240,tran)); + } else{ + palette.setColor(QPalette::Background,QColor(40,40,40,tran)); + } + if (!isIntel) + this->setPalette(palette); + + if (select_dev == "") + select_dev.clear(); + + QVBoxLayout *main_layout = new QVBoxLayout(this); + main_layout->setSpacing(5); + main_layout->setContentsMargins(3,3,3,3); + + m_scroll = new QScrollArea(this); + m_scroll->setWidgetResizable(true); + m_scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_scroll->setProperty("drawScrollBarGroove",false); + m_scroll->verticalScrollBar()->setProperty("drawScrollBarGroove",false); +// m_scroll->setFixedSize(376,240); + main_layout->addWidget(m_scroll); + dev_widget = new QWidget(this); + m_scroll->setWidget(dev_widget); + + device_list_layout = new QVBoxLayout(dev_widget); + device_list_layout->setSpacing(5); + device_list_layout->setContentsMargins(8,8,8,8); + dev_widget->setLayout(device_list_layout); + + InitUI(); +} + +DeviceSeleterWidget::~DeviceSeleterWidget() +{ + +} + +void DeviceSeleterWidget::InitUI() +{ + bool exit_device = false; + for(int i=0; i < deviceList.values().size(); i++){ +// qDebug() << Q_FUNC_INFO << device_list.at(i)->type() << device_list.at(i)->name(); + BluezQt::Device::Type type = BluezQt::Device::stringToType(deviceList.values().at(i).at(1)); + if((type == BluezQt::Device::Phone)||(type == BluezQt::Device::Computer)){ + QIcon icon; + switch (type){ + case BluezQt::Device::Type::Phone: + icon = QIcon::fromTheme("phone-apple-iphone-symbolic"); + break; + case BluezQt::Device::Type::Computer: + icon = QIcon::fromTheme("video-display-symbolic"); + break; + case BluezQt::Device::Type::Uncategorized: + default: + icon = QIcon::fromTheme("bluetooth-symbolic"); + break; + } + + DeviceSelectItem *item = new DeviceSelectItem(deviceList.values().at(i).at(0), deviceList.key(deviceList.values().at(i)),icon, dev_widget); + connect(item,&DeviceSelectItem::clicked,this,&DeviceSeleterWidget::itemToolbuttonClicked); + connect(item, &DeviceSelectItem::unclicked, this, [=] { + emit unsign_select(); + select_name.clear(); + select_dev.clear(); + }); + if (select_dev == deviceList.key(deviceList.values().at(i))) { + item->setSelectedState(); + exit_device = true; + } + device_list_layout->addWidget(item, Qt::AlignTop |Qt::AlignLeft); + toolbutton_list.append(item); + } + } + if (!exit_device) { + select_dev.clear(); + select_name.clear(); + } + + if(toolbutton_list.size() == 0){ + QLabel *tip_label = new QLabel(this); + tip_label->setFixedSize(440, 50); + tip_label->setAlignment(Qt::AlignCenter); + tip_label->setText(tr("No device currently available \n Please go to pair the device")); + device_list_layout->addWidget(tip_label,Qt::AlignCenter); + }else{ + device_list_layout->addStretch(); + } +} + +QString DeviceSeleterWidget::get_seleter_device() +{ + qDebug() << Q_FUNC_INFO; + return select_dev; +} + +QString DeviceSeleterWidget::get_seleter_dev_name() +{ + return select_name; +} + +void DeviceSeleterWidget::itemToolbuttonClicked(QStringList device) +{ + for (int i = 0; i < toolbutton_list.size(); i++) { + if (select_dev.isNull()) + break; + if (toolbutton_list.at(i)->getAddress() == device.at(1)) + continue; + toolbutton_list.at(i)->setUnselectedState(); + } + select_name = device.at(0); + select_dev = device.at(1); + + emit sign_select(); +} + +void DeviceSeleterWidget::GSettingsChanges(const QString &key) +{ + qDebug() << Q_FUNC_INFO << key; + if(key == "styleName"){ + QPalette palette; + if(GSettings->get("style-name").toString() == "ukui-default" || GSettings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(240,240,240,tran)); + } else{ + palette.setColor(QPalette::Background,QColor(40,40,40,tran)); + } + if (!isIntel) + this->setPalette(palette); + else + update(); + } +} + +void DeviceSeleterWidget::paintEvent(QPaintEvent *event) { + if (!isIntel) + return; + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + QColor penCol; + penCol = QColor("#818181"); + QPainterPath rectPathPen; + rectPathPen.addRoundedRect(this->rect(),12,12); + painter.setPen(penCol); + painter.drawPath(rectPathPen); +} diff --git a/ukui-bluetooth/fileSend/deviceseleterwidget.h b/ukui-bluetooth/fileSend/deviceseleterwidget.h new file mode 100644 index 0000000..f28aa4e --- /dev/null +++ b/ukui-bluetooth/fileSend/deviceseleterwidget.h @@ -0,0 +1,63 @@ +#ifndef DEVICESELETERWIDGET_H +#define DEVICESELETERWIDGET_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "./deviceselectitem.h" + +#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + +class DeviceSeleterWidget : public QWidget +{ + Q_OBJECT +public: + explicit DeviceSeleterWidget(QMap pairdeviceList, QWidget *parent = nullptr, QString dev = ""); + ~DeviceSeleterWidget(); + void InitUI(); + QString get_seleter_device(); + QString get_seleter_dev_name(); +signals: + void sign_select(); + void unsign_select(); + +private slots: + void itemToolbuttonClicked(QStringList device); + void GSettingsChanges(const QString &key); +private: + QGSettings *GSettings = nullptr; + QGSettings *settings = nullptr; + QGSettings *transparency_gsettings = nullptr; + QString select_dev; + QString select_name; + bool isIntel = false; + double tran =1; + + QList toolbutton_list; + QLabel *Tiptop = nullptr; + QScrollArea *m_scroll = nullptr; + QWidget *dev_widget = nullptr; + QVBoxLayout *device_list_layout = nullptr; + QMap deviceList; +protected: + void paintEvent(QPaintEvent *event); +}; + +#endif // DEVICESELETERWIDGET_H diff --git a/ukui-bluetooth/main/main.cpp b/ukui-bluetooth/main/main.cpp new file mode 100644 index 0000000..30e6ec1 --- /dev/null +++ b/ukui-bluetooth/main/main.cpp @@ -0,0 +1,89 @@ +#include "mainprogram.h" + +#include +#include +#include +#include +#include +#include +#include +#include + + +static QString executeLinuxCmd(QString strCmd) +{ + QProcess p; + p.start("bash", QStringList() <<"-c" << strCmd); + p.waitForFinished(); + QString strResult = p.readAllStandardOutput(); + return strResult.toLower(); +} + +static bool IsHuawei() +{ + QString str = executeLinuxCmd("cat /proc/cpuinfo | grep Hardware"); + if(str.length() == 0) + { + return false; + } + + if(str.indexOf("huawei") != -1 || str.indexOf("pangu") != -1 || + str.indexOf("kirin") != -1) + { + return true; + } + else + { + return false; + } + return false; +} + + +int main(int argc, char *argv[]) +{ + initUkuiLog4qt("ukui-bluetooth"); + + global_ishuawei = IsHuawei(); + qDebug() << "Ishuawei: "<< global_ishuawei; + + // QApplication::setStyle(QStyleFactory::create("ukui-default")); + QApplication::setQuitOnLastWindowClosed(false); + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + + #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + #endif + + QtSingleApplication app(argc, argv); + + if (app.isRunning()) { + qDebug() << "ukui-bluetooth is Already running ! ! !"; + return EXIT_SUCCESS; + } else { + QString locale = QLocale::system().name(); + // QString locale = "es"; + QTranslator translator; + if(locale == "zh_CN" || locale == "es" || locale == "fr" || locale == "de" || locale == "ru") {//中文 西班牙语 法语 德语 俄语 + if(!translator.load("ukui-bluetooth_" + locale + ".qm", + ":/translations/")) + qDebug() << "Load translation file:"<< "ukui-bluetooth_" + locale + ".qm" << " failed!"; + else + app.installTranslator(&translator); + } + + //加载Qt对话框默认的国际化 + QTranslator qtTranslator; + qtTranslator.load("qt_" + locale, + QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + app.installTranslator(&qtTranslator); + MainProgram *w; + bool intel = QFile::exists("/etc/apt/ota_version"); + w = new MainProgram(intel); + if( w->exit_flag ){ + return 0; + } + return app.exec(); + } +} diff --git a/ukui-bluetooth/main/mainprogram.cpp b/ukui-bluetooth/main/mainprogram.cpp new file mode 100644 index 0000000..d2e5528 --- /dev/null +++ b/ukui-bluetooth/main/mainprogram.cpp @@ -0,0 +1,377 @@ +#include "mainprogram.h" + +MainProgram::MainProgram(bool intel, QObject *parent) : + QObject(parent), + _mIntel(intel) +{ + _sessionDbus = new BluetoothDbus(this); + _mConfig = new Config(this); + initGSettingInfo(); + UI = TrayWidget::self(_sessionDbus, _mIntel); + replyTimer = new QTimer(this); + if (!_mIntel) + UI->setWidgetPosition(); + + //非华为机器才存在文件功能 + if(!global_ishuawei) + { + connect(_sessionDbus, &BluetoothDbus::receiveFilesSignal, this, &MainProgram::receiveFileSlot); + connect(_sessionDbus, &BluetoothDbus::sendTransferDeviceMesgSignal, this, &MainProgram::sendTransferDeviceMesgSlot); + connect(_sessionDbus, &BluetoothDbus::sendTransferFilesMesgSignal, this, &MainProgram::sendTransferFilesMesgSlot); + connect(_sessionDbus, &BluetoothDbus::activeConnectionSignal, this, &MainProgram::activeConnectionSlot); + } + + connect(_sessionDbus, &BluetoothDbus::showTrayWidgetUISignal, this, [=]() { + UI->showUI(); + }); + connect(_sessionDbus, &BluetoothDbus::displayPasskeySignal, this, &MainProgram::displayPasskeySlot); + connect(_sessionDbus, &BluetoothDbus::requestConfirmationSignal, this, &MainProgram::requestConfirmationSlot); + connect(_sessionDbus, &BluetoothDbus::sessionDevPairSignal, this, [=](QString _name, bool paired) { + Q_UNUSED(_name); + Q_UNUSED(paired); + UI->layoutAddOnePairedDev(_name, paired); + }); + connect(_sessionDbus, &BluetoothDbus::devNameChangedSignal, this, [=]() { + UI->updatePairedDev(); + }); + connect(_sessionDbus, &BluetoothDbus::devBatteryChangedSignal, this, [=]() { + UI->updatePairedDev(); + }); +} + +MainProgram::~MainProgram() +{ +} + +static qint64 getFileSize(QString filename) +{ + QFileInfo info(filename); + if (info.exists()) + return info.size(); + else + return 0; +} + +void MainProgram::initGSettingInfo() +{ + _mGsetting.clear(); + _mGsetting["switch"] = _mConfig->gsetting->get("switch"); + _mGsetting["finally-connect-the-device"] = _mConfig->gsetting->get("finally-connect-the-device"); + _mGsetting["adapter-address"] = _mConfig->gsetting->get("adapter-address"); + _mGsetting["file-save-path"] = _mConfig->gsetting->get("file-save-path"); + _mGsetting["adapter-address-list"] = _mConfig->gsetting->get("adapter-address-list"); + + if(_mConfig->gsetting->get("file-save-path").toString().isEmpty()){ + _mConfig->gsetting->set("file-save-path",QVariant::fromValue(QDir::homePath())); + } + + connect(_mConfig->gsetting,SIGNAL(changed(QString)),this,SLOT(gsettingsChangedSlot(QString))); +} + +void MainProgram::gsettingsChangedSlot(const QString &key) +{ + if (_mGsetting.contains("key")) { + _mGsetting[key] = _mConfig->gsetting->get(key); + } +} + +void MainProgram::sendFiles(QString address, QString type) { + _sessionDbus->sendFiles(address, selectedFiles.at(0) + QString(" ") + type); +} + +void MainProgram::closeSession() { + _sessionDbus->closeSession(); +} + +void MainProgram::receiveFileSlot(QString address, QString devname, + QString filename, QString type, + QString source, quint64 size) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + receiving_widget = new FileReceivingPopupWidget(address, devname, filename, type, source, size); + qDebug() << Q_FUNC_INFO << __LINE__; + connect(_sessionDbus, &BluetoothDbus::initTransferPathSignal, receiving_widget, &FileReceivingPopupWidget::initTransferPath); + connect(receiving_widget, &FileReceivingPopupWidget::clearOldSession, _sessionDbus, &BluetoothDbus::clearOldSession); + connect(_sessionDbus, &BluetoothDbus::fileReceiveMore, receiving_widget, &FileReceivingPopupWidget::updateUI); + connect(_sessionDbus, &BluetoothDbus::obexAgentCanceledSignal, receiving_widget, &FileReceivingPopupWidget::cancelReceivingFiles); + + connect(receiving_widget,&FileReceivingPopupWidget::accepted,this,[=]{ + qDebug() << Q_FUNC_INFO << __LINE__; + _sessionDbus->replyFileReceiving(true); + receiving_widget->configuration_transfer_progress_bar(size); + connect(_sessionDbus,&BluetoothDbus::transferredChangedSignal,receiving_widget,&FileReceivingPopupWidget::update_transfer_progress_bar); + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,receiving_widget,&FileReceivingPopupWidget::file_transfer_completed); + connect(receiving_widget,&FileReceivingPopupWidget::cancel,this,[=]{ + _sessionDbus->cancelFileReceiving(); + receiving_widget->deleteLater(); + receiving_widget = nullptr; + qDebug() << Q_FUNC_INFO << "cancel" << __LINE__; + }); + }); + + connect(receiving_widget,&FileReceivingPopupWidget::rejected,this,[=]{ + _sessionDbus->replyFileReceiving(false); + receiving_widget->deleteLater(); + receiving_widget = nullptr; + }); + + receiving_widget->show(); +} + +void MainProgram::sendTransferDeviceMesgSlot(QString address) +{ + selectedFiles.clear(); + KyFileDialog fd; + QList list = fd.sidebarUrls(); + int sidebarNum = 8;//最大添加U盘数,可以自己定义 + QString home = QDir::homePath().section("/", -1, -1); + QString mnt = "/media/" + home + "/"; + QDir mntDir(mnt); + mntDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); + QFileInfoList filist = mntDir.entryInfoList(); + QList mntUrlList; + for (int i = 0; i < sidebarNum && i < filist.size(); ++i) { + QFileInfo fi = filist.at(i); + //华为990、9a0需要屏蔽最小系统挂载的目录 + if (fi.fileName() == "2691-6AB8") + continue; + mntUrlList << QUrl("file://" + fi.filePath()); + } + + QFileSystemWatcher fsw(&fd); + fsw.addPath("/media/" + home + "/"); + connect(&fsw, &QFileSystemWatcher::directoryChanged, &fd, + [=, &sidebarNum, &mntUrlList, &list, &fd](const QString path) { + QDir wmntDir(path); + wmntDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); + QFileInfoList wfilist = wmntDir.entryInfoList(); + mntUrlList.clear(); + for (int i = 0; i < sidebarNum && i < wfilist.size(); ++i) { + QFileInfo fi = wfilist.at(i); + //华为990、9a0需要屏蔽最小系统挂载的目录 + if (fi.fileName() == "2691-6AB8") + continue; + mntUrlList << QUrl("file://" + fi.filePath()); + } + fd.setSidebarUrls(list + mntUrlList); + fd.update(); + }); + + connect(&fd, &QFileDialog::finished, &fd, [=, &list, &fd]() { + fd.setSidebarUrls(list); + }); + + //自己QFileDialog的用法,这里只是列子 + //fd.setNameFilter(QLatin1String("All Files (*)")); + + fd.setDirectory(QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).at(0)); + + //这行要添加,设置左侧导航 + fd.setSidebarUrls(list + mntUrlList); + if (fd.exec() == QDialog::Accepted) { + qDebug()<move((desktop->width()-mbox->width())/2,(desktop->height()-mbox->height())/2); + mbox->exec(); + return; + } + } + + if (BluetoothFileTransferWidget::isShow == false) { + fileSendWidget = new BluetoothFileTransferWidget(selectedFiles,_sessionDbus->getSendableDevices(),address); + connect(_sessionDbus, &BluetoothDbus::initTransferPathSignal, fileSendWidget, &BluetoothFileTransferWidget::initTransferPath); + connect(fileSendWidget,&BluetoothFileTransferWidget::destroyed, this,&MainProgram::closeSession); + connect(fileSendWidget,&BluetoothFileTransferWidget::sender_dev_name,this,&MainProgram::sendFiles); + connect(_sessionDbus,&BluetoothDbus::transferredChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::set_m_progressbar_value); + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::get_transfer_status); + connect(fileSendWidget,&BluetoothFileTransferWidget::continueSendFiles,_sessionDbus,&BluetoothDbus::continueSendFiles); + fileSendWidget->show(); + } + else + { + qDebug() << Q_FUNC_INFO << fileSendWidget->get_send_data_state() << __LINE__; + + if (BluetoothFileTransferWidget::_SEND_FAILURE == fileSendWidget->get_send_data_state() || + BluetoothFileTransferWidget::_SEND_COMPLETE == fileSendWidget->get_send_data_state() ) + { + _sessionDbus->closeSession(); + fileSendWidget->close(); + delete fileSendWidget; + fileSendWidget = new BluetoothFileTransferWidget(selectedFiles,_sessionDbus->getSendableDevices(),address); + connect(_sessionDbus, &BluetoothDbus::initTransferPathSignal, fileSendWidget, &BluetoothFileTransferWidget::initTransferPath); + connect(fileSendWidget,&BluetoothFileTransferWidget::sender_dev_name,this,&MainProgram::sendFiles); + connect(fileSendWidget,&BluetoothFileTransferWidget::destroyed, this,&MainProgram::closeSession); + connect(_sessionDbus,&BluetoothDbus::transferredChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::set_m_progressbar_value); + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::get_transfer_status); + connect(fileSendWidget,&BluetoothFileTransferWidget::continueSendFiles,_sessionDbus,&BluetoothDbus::continueSendFiles); + fileSendWidget->show(); + } else { + fileSendWidget->insertNewFileList(selectedFiles); + } + } + } +} + +void MainProgram::sendTransferFilesMesgSlot(QStringList targetList) +{ + qDebug() << "Select file:" << targetList; + //selectedFiles = targetList; + selectedFiles.clear(); + for (int i = 0 ; i < targetList.size() ; i++) + { + QString str = targetList.at(i); + str = str.replace(QString("file://"), QString("")); + selectedFiles.append(str); + } + qDebug() << "Select file:" << selectedFiles; + if(selectedFiles.size() != 0){ + if (BluetoothFileTransferWidget::isShow == false) { + fileSendWidget = new BluetoothFileTransferWidget(selectedFiles,_sessionDbus->getSendableDevices(),""); + connect(_sessionDbus, &BluetoothDbus::initTransferPathSignal, fileSendWidget, &BluetoothFileTransferWidget::initTransferPath); + connect(fileSendWidget,&BluetoothFileTransferWidget::sender_dev_name,this,&MainProgram::sendFiles); + connect(fileSendWidget,&BluetoothFileTransferWidget::close_the_pre_session,this,&MainProgram::closeSession); + connect(_sessionDbus,&BluetoothDbus::transferredChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::set_m_progressbar_value); + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::get_transfer_status); + connect(fileSendWidget,&BluetoothFileTransferWidget::continueSendFiles,_sessionDbus,&BluetoothDbus::continueSendFiles); + fileSendWidget->show(); + } + else + { + if (BluetoothFileTransferWidget::_SEND_FAILURE == fileSendWidget->get_send_data_state() || + BluetoothFileTransferWidget::_SEND_COMPLETE == fileSendWidget->get_send_data_state() ) + { + _sessionDbus->closeSession(); + fileSendWidget->close(); + delete fileSendWidget; + fileSendWidget = new BluetoothFileTransferWidget(selectedFiles,_sessionDbus->getSendableDevices(),""); + connect(_sessionDbus, &BluetoothDbus::initTransferPathSignal, fileSendWidget, &BluetoothFileTransferWidget::initTransferPath); + connect(fileSendWidget,&BluetoothFileTransferWidget::sender_dev_name,this,&MainProgram::sendFiles); + connect(fileSendWidget,&BluetoothFileTransferWidget::close_the_pre_session,this,&MainProgram::closeSession); + connect(_sessionDbus,&BluetoothDbus::transferredChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::set_m_progressbar_value); + connect(_sessionDbus,&BluetoothDbus::statusChangedSignal,fileSendWidget,&BluetoothFileTransferWidget::get_transfer_status); + connect(fileSendWidget,&BluetoothFileTransferWidget::continueSendFiles,_sessionDbus,&BluetoothDbus::continueSendFiles); + fileSendWidget->show(); + } else { + fileSendWidget->insertNewFileList(selectedFiles); + } + } + } +} + +void MainProgram::displayPasskeySlot(QString name, QString passkey) +{ + qDebug() << Q_FUNC_INFO << name << passkey; + if(m_Passkey == passkey) + return; + + if(Keypincodewidget != nullptr){ + if (Keypincodewidget) { + Keypincodewidget->updateUIInfo(name,passkey); + return; + } + } + + Keypincodewidget = new PinCodeWidget(name,passkey,false); + connect(Keypincodewidget, &PinCodeWidget::msgShowedOver, this, [=] { + Keypincodewidget->deleteLater(); + Keypincodewidget = nullptr; + }); + + disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); + + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { + if(nullptr != Keypincodewidget) + Keypincodewidget->pairFailureShow(); + disconnect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, nullptr, nullptr); + }); + connect(_sessionDbus, &BluetoothDbus::sessionDevPairSignal, Keypincodewidget, [=](QString _name, bool paired){ + qDebug() << Q_FUNC_INFO << __LINE__; + if (name != _name || nullptr == Keypincodewidget) + return; + if (paired) + { + Keypincodewidget->setHidden(true); + emit Keypincodewidget->msgShowedOver(); + } + }); + //保持在最前 + Keypincodewidget->show(); + Keypincodewidget->activateWindow(); +} + +void MainProgram::requestConfirmationSlot(QString name, QString passkey) +{ + qDebug() << Q_FUNC_INFO << name << passkey; + + if(pincodewidget != nullptr){ + qDebug() << Q_FUNC_INFO << __LINE__; + return; + } + m_Passkey = passkey; + pincodewidget = new PinCodeWidget(name,passkey); + connect(pincodewidget, &PinCodeWidget::msgShowedOver, this, [=] { + if (pincodewidget != nullptr) { + qDebug() << Q_FUNC_INFO << __LINE__; + pincodewidget->deleteLater(); + pincodewidget = nullptr; + } + }); + connect(_sessionDbus, &BluetoothDbus::pairAgentCanceledSignal, this, [=]() { + qDebug() << Q_FUNC_INFO << __LINE__; + if (pincodewidget != nullptr) { + if (pincodewidget->canceled) + return; + pincodewidget->canceled = true; + pincodewidget->pairFailureShow(); + pincodewidget = nullptr; + } + }); + + connect(pincodewidget,&PinCodeWidget::accepted,this,[=]{ + _sessionDbus->replyRequestConfirmation(true); + }); + + connect(pincodewidget,&PinCodeWidget::rejected,this,[=]{ + _sessionDbus->replyRequestConfirmation(false); + }); + connect(pincodewidget, &PinCodeWidget::destroyed, this, [=] { + pincodewidget = nullptr; + }); + + //保持在最前 + pincodewidget->show(); + pincodewidget->activateWindow(); +} + +void MainProgram::activeConnectionSlot(QString address, QString name, QString type, int rssi, int timeout) { + if (activeConnectionWidget != nullptr) + return; + activeConnectionWidget = new ActiveConnectionWidget(address, name, type, rssi); + connect(activeConnectionWidget, &ActiveConnectionWidget::replyActiveConnection, this, [=](QString dev, bool v) { + if (replyTimer->isActive()) + replyTimer->stop(); + _sessionDbus->activeConnectionReply(dev, v); + disconnect(activeConnectionWidget, &ActiveConnectionWidget::replyActiveConnection, NULL, NULL); + activeConnectionWidget = nullptr; + }); + + replyTimer->disconnect(); + connect(replyTimer, &QTimer::timeout, this, [=](){ + if (nullptr == activeConnectionWidget) + return; + disconnect(activeConnectionWidget, &ActiveConnectionWidget::replyActiveConnection, NULL, NULL); + activeConnectionWidget->hide(); + activeConnectionWidget->deleteLater(); + activeConnectionWidget = nullptr; + }); + + activeConnectionWidget->show(); + replyTimer->start(timeout * 1000); +} diff --git a/ukui-bluetooth/main/mainprogram.h b/ukui-bluetooth/main/mainprogram.h new file mode 100644 index 0000000..c33c63f --- /dev/null +++ b/ukui-bluetooth/main/mainprogram.h @@ -0,0 +1,81 @@ +#ifndef MAINPROGRAM_H +#define MAINPROGRAM_H + +#include "daemon/bluetoothdbus.h" +#include "config/config.h" +#include "mainwidget/traywidget.h" +#include "fileSend/bluetoothfiletransferwidget.h" +#include "component/kyfiledialog.h" +#include "pin/pincodewidget.h" +#include "activeConn/activeconnectionwidget.h" +#include "fileReceive/filereceivingpopupwidget.h" +#include "fileSend/bluetoothfiletransferwidget.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +//#include +#define LIST_PATH "/etc/pairDevice.list" + +class KDbusInterface; + +class MainProgram : public QObject +{ + Q_OBJECT +public: + explicit MainProgram(bool intel, QObject *parent = nullptr); + ~MainProgram(); + bool exit_flag = false; + +private slots: + void closeSession(); + void sendFiles(QString address, QString type); + +private slots: + void gsettingsChangedSlot(const QString &); + void sendTransferFilesMesgSlot(QStringList); + void sendTransferDeviceMesgSlot(QString address); + void activeConnectionSlot(QString address, QString name, QString type, int rssi, int timeout); + void receiveFileSlot(QString address, QString name, QString filename, QString type, QString source, quint64 size); + void displayPasskeySlot(QString name, QString passkey); + void requestConfirmationSlot(QString name, QString passkey); + +private: + void initGSettingInfo(); + + bool _mIntel; + QTimer *replyTimer; + QStringList selectedFiles; + QMap _mGsetting; + ActiveConnectionWidget *activeConnectionWidget = nullptr; + FileReceivingPopupWidget *receiving_widget = nullptr; + Config *_mConfig = nullptr; + BluetoothDbus *_sessionDbus = nullptr; + BluetoothFileTransferWidget *fileSendWidget = nullptr; + QList *deviceAddressList = nullptr; + QList *deviceTypeList = nullptr; + PinCodeWidget *pincodewidget = nullptr; + PinCodeWidget *Keypincodewidget = nullptr; + QString m_Passkey; + + TrayWidget *UI = nullptr; +}; + +#endif // MAINPROGRAM_H diff --git a/ukui-bluetooth/mainwidget/trayicon.cpp b/ukui-bluetooth/mainwidget/trayicon.cpp new file mode 100644 index 0000000..bba9cfe --- /dev/null +++ b/ukui-bluetooth/mainwidget/trayicon.cpp @@ -0,0 +1,94 @@ +#include "trayicon.h" + +TrayIcon::TrayIcon(QWidget *parent) + : QWidget(parent) +{ + if(QGSettings::isSchemaInstalled("org.ukui.bluetooth")){ + settings = new QGSettings("org.ukui.bluetooth"); + connect(settings, &QGSettings::changed,this,&TrayIcon::GSettings_value_chanage); + } + + bluetooth_tray_icon = new QSystemTrayIcon(this); + tray_Menu = new QMenu(this); + QAction *settins_action = new QAction(tr("Set Bluetooth Item"),tray_Menu); + settins_action->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) ); + tray_Menu->addAction(settins_action); + connect(tray_Menu, &QMenu::triggered, this, [=]{ + emit openBluetoothSettings(); + }); + + //Create taskbar tray icon and connect to signal slot + //创建任务栏托盘图标,并连接信号槽 + bluetooth_tray_icon = new QSystemTrayIcon(this); + bluetooth_tray_icon->setContextMenu(tray_Menu); + bluetooth_tray_icon->setToolTip(tr("Bluetooth")); + bluetooth_tray_icon->setVisible(settings->get("tray-show").toBool()); + + if(settings->get("switch").toString() == "false"){ + if(QIcon::hasThemeIcon("bluetooth-error")) + bluetooth_tray_icon->setIcon(QIcon::fromTheme("bluetooth-error")); + else + bluetooth_tray_icon->setIcon(QIcon::fromTheme("bluetooth-active-symbolic")); + }else{ + bluetooth_tray_icon->setIcon(QIcon::fromTheme("bluetooth-active-symbolic")); + } + + connect(bluetooth_tray_icon,&QSystemTrayIcon::activated, + [=](QSystemTrayIcon::ActivationReason reason){ + switch (reason) + { + case QSystemTrayIcon::MiddleClick: + case QSystemTrayIcon::DoubleClick: /* 来自于双击激活。 */ + case QSystemTrayIcon::Trigger: /* 来自于单击激活。 */ + InitTrayWidget(); + break; + case QSystemTrayIcon::Unknown: + case QSystemTrayIcon::Context: + break; + } + }); +} + +TrayIcon::~TrayIcon() +{ + delete settings; +} + +void TrayIcon::InitTrayWidget() +{ + emit showTayWidget(); +} + +void TrayIcon::SetTrayIcon(bool open) +{ + qDebug() << Q_FUNC_INFO << open; + if(!open){ + if(QIcon::hasThemeIcon("bluetooth-error")) + bluetooth_tray_icon->setIcon(QIcon::fromTheme("bluetooth-error")); + else + bluetooth_tray_icon->setIcon(QIcon::fromTheme("bluetooth-active-symbolic")); + }else{ + bluetooth_tray_icon->setIcon(QIcon::fromTheme("bluetooth-active-symbolic")); + } +} + +void TrayIcon::GSettings_value_chanage(const QString &key) +{ + qDebug() << Q_FUNC_INFO << key; + if(key != "trayShow") + return; + if (!hasAdapter) + return; + if(bluetooth_tray_icon->isVisible() != settings->get(key).toBool()){ + bluetooth_tray_icon->setVisible(settings->get(key).toBool()); + } +} + +void TrayIcon::SetAdapterFlag(bool set) { + qDebug() << Q_FUNC_INFO << __LINE__ ; + hasAdapter = set; + if (!settings->get("trayShow").toBool() && set) + return; + bluetooth_tray_icon->setVisible(set); + qDebug() << Q_FUNC_INFO << __LINE__ ; +} diff --git a/ukui-bluetooth/mainwidget/trayicon.h b/ukui-bluetooth/mainwidget/trayicon.h new file mode 100644 index 0000000..9a64da5 --- /dev/null +++ b/ukui-bluetooth/mainwidget/trayicon.h @@ -0,0 +1,49 @@ +#ifndef TRAYICON_H +#define TRAYICON_H + +#include "fileSend/bluetoothfiletransferwidget.h" +#include "daemon/bluetoothdbus.h" +#include "component/switchaction.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +class TrayIcon : public QWidget +{ + Q_OBJECT + +public: + TrayIcon(QWidget *parent = nullptr); + ~TrayIcon(); + void InitTrayWidget(); + void SetAdapterFlag(bool set); + +signals: + void showTayWidget(); + void openBluetoothSettings(); + +public slots: + void GSettings_value_chanage(const QString &key); + void SetTrayIcon(bool open); + +private: + QSystemTrayIcon *bluetooth_tray_icon = nullptr; + QMenu *tray_Menu = nullptr; + QGSettings *StyleSettings = nullptr; + QGSettings *settings = nullptr; + bool hasAdapter = true; +} ; +#endif // TRAYICON_H diff --git a/ukui-bluetooth/mainwidget/traywidget.cpp b/ukui-bluetooth/mainwidget/traywidget.cpp new file mode 100644 index 0000000..8093595 --- /dev/null +++ b/ukui-bluetooth/mainwidget/traywidget.cpp @@ -0,0 +1,572 @@ +#include "traywidget.h" + +TrayWidget* TrayWidget::_MSelf = nullptr; +TrayWidget::TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent): + QWidget(parent), + _SessionDBus(dBus), + _config(new Config(this)), + _Intel(intel) +{ + qDebug() << Q_FUNC_INFO; + +// 窗管适配 + if (_Intel) { + setProperty("useStyleWindowManager", false); + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); + installEventFilter(this); + } + if (!_Intel) { + trayicon = new TrayIcon(); + connect(this, &TrayWidget::trayIconStatusChanged, trayicon, &TrayIcon::SetTrayIcon); + connect(trayicon, &TrayIcon::showTayWidget, this, &TrayWidget::showUI); + connect(trayicon, &TrayIcon::openBluetoothSettings, this, [=]{ + _SessionDBus->openBluetoothSettings(); + }); + connect(_SessionDBus, &BluetoothDbus::showTrayIcon, this, [=](bool show) { + trayicon->SetAdapterFlag(show); + if (!show) + this->setVisible(show); + }); + setProperty("useSystemStyleBlur", true); + this->setAttribute(Qt::WA_TranslucentBackground); + this->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint); + _SessionDBus->getTrayIconShow(); + } + connect(QApplication::desktop(), &QDesktopWidget::resized, this, [=] { + setWidgetPosition(); + }); + connect(QApplication::desktop(), &QDesktopWidget::primaryScreenChanged, this, [=] { + setWidgetPosition(); + }); + + QGSettings *setttt = new QGSettings(QString("org.ukui.SettingsDaemon.plugins.xsettings").toLocal8Bit()); + connect(setttt,&QGSettings::changed, this, [=] (const QString &key) { + if (key == "scalingFactor") { + repaint(); + } + }); + + + if(QGSettings::isSchemaInstalled("org.ukui.style")) { + StyleSettings = new QGSettings("org.ukui.style"); + connect(StyleSettings,&QGSettings::changed,this,&TrayWidget::GSettingsChanges); + } + + const QByteArray transparency_id(TRANSPARENCY_SETTINGS); + if(QGSettings::isSchemaInstalled(transparency_id)) { + transparency_gsettings = new QGSettings(transparency_id); + } + if(QGSettings::isSchemaInstalled(transparency_id)) { + getTransparency(); + connect(transparency_gsettings,&QGSettings::changed,this,[=](QString key) { + qDebug() << Q_FUNC_INFO << key; + if (key == QString(TRANSPARENCY_KEY)) { + getTransparency(); + this->update(); + } + }); + } + QPalette palette; + if(StyleSettings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(255,255,255, 0)); + }else{ + QColor col(QPalette::Base); + col.setAlpha(tran); + palette.setColor(QPalette::Background, col); + } + + this->setPalette(palette); + this->setFixedSize(420,520); + this->setAutoFillBackground(true); + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + this->setWindowTitle(tr("bluetooth")); + pairedDevices = _SessionDBus->getPairedDevices(); + pairedList = _SessionDBus->getPairedDevicesList(); + InitMemberVariables(); + connectUISignalAndSlot(); + layoutAddAllPairedDev(); + if (_Intel) { + QRect availableGeometry = QApplication::screens().at(0)->geometry(); + qDebug() << availableGeometry.x() << availableGeometry.y(); + move((availableGeometry.x() + (availableGeometry.width() - width())/2), (availableGeometry.y() + (availableGeometry.height() - height())/2)); + } + emit trayIconStatusChanged(_SessionDBus->isPowered()); + _MBtn->setChecked(_SessionDBus->isPowered()); +} + +TrayWidget *TrayWidget::self( BluetoothDbus *dbus, bool intel) +{ + qDebug() << Q_FUNC_INFO; + if (!_MSelf) { + _MSelf = new TrayWidget(intel, dbus, nullptr); + } + return _MSelf; +} + +TrayWidget::~TrayWidget() +{ + +} + +void TrayWidget::getTransparency() { + double proportion = transparency_gsettings->get(TRANSPARENCY_KEY).toDouble(); + proportion = ((proportion > 0.85) ? 1 : (proportion + 0.15)); + qDebug() << Q_FUNC_INFO << proportion; + tran = proportion * 255; +} + +void TrayWidget::openBluetoothSlot(bool v) +{ + emit trayIconStatusChanged(v); + if (v != _SessionDBus->isPowered()) + _SessionDBus->setDefaultAdapterPower(v); + if (!_Intel && !pairedDevices.size()) + return; + if (_Intel) { + if (v) { + _MStackedWidget->setCurrentIndex(0); + } else { + _MStackedWidget->setCurrentIndex(1); + } + return; + } + _MStackedWidget->setVisible(v); + lineFrame->setVisible(v); + if (_MSelf) + _MSelf->setFixedHeight(v ? selfHeight : 102); + setWidgetPosition(); + update(); +} + + + +void TrayWidget::setWidgetPosition() +{ + #define MARGIN 4 + + //menu->exec(); + int width = this->width(); + int height= this->height(); + qDebug()<<"menu 's width height"< reply=iface.call("GetPrimaryScreenGeometry"); + //reply获取的参数共5个,分别是 主屏可用区域的起点x坐标,主屏可用区域的起点y坐标,主屏可用区域的宽度,主屏可用区域高度,任务栏位置 + + if (!iface.isValid() || !reply.isValid() || reply.value().size()<5) { + qCritical() << QDBusConnection::sessionBus().lastError().message(); + this->setGeometry(0,0,width,height); + } + +// qDebug()<setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-width-MARGIN, + position_list.at(1).toInt()+MARGIN, + width,height); + break; + //任务栏位于左边 + case 2: + this->setGeometry(position_list.at(0).toInt()+MARGIN, + position_list.at(1).toInt()+reply.value().at(3).toInt()-height-MARGIN, + width,height); + break; + //任务栏位于右边 + case 3: + this->setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-width-MARGIN, + position_list.at(1).toInt()+reply.value().at(3).toInt()-height-MARGIN, + width,height); + break; + //任务栏位于下方 + default: + this->setGeometry(position_list.at(0).toInt()+position_list.at(2).toInt()-width-MARGIN, + position_list.at(1).toInt()+reply.value().at(3).toInt()-height-MARGIN, + width,height); + break; + } +} + +void TrayWidget::GSettingsChanges(const QString &key) +{ + qDebug() << Q_FUNC_INFO << key; + if(key == "styleName"){ + QPalette palette; + QPalette pl; + QPalette _pl; + getTransparency(); + if(StyleSettings->get("style-name").toString() == "ukui-light"){ + _pl.setColor(QPalette::WindowText,Qt::black); + palette.setColor(QPalette::Background,QColor(255,255,255,0)); + pl.setColor(QPalette::WindowText, QColor(0,0,0,20)); + }else{ + QColor col(QPalette::Base); + col.setAlpha(tran); + _pl.setColor(QPalette::WindowText,Qt::white); + palette.setColor(QPalette::Background, col); + pl.setColor(QPalette::WindowText, QColor(255,255,255,50)); + } + this->setPalette(palette); + _MLabel->setPalette(_pl); + lineFrame->setPalette(pl); + lineFrame2->setPalette(pl); + this->update(); + } + if (key == "switch") { + if (_config.gsetting->get("switch").toString() != _SessionDBus->isPowered()) + _MBtn->setChecked(_config.gsetting->get("switch").toBool()); + } +} + +void TrayWidget::InitMemberVariables() +{ + _MBtn = new KSwitchButton(this); + _MStackedWidget = new QStackedWidget(this); + _MLabel = new QLabel(this); + _MMainLayout = new QVBoxLayout(this); + _MSettingBtn = new BluetoothSettingLabel(this); + + connect(_MSettingBtn, &BluetoothSettingLabel::clickSignal, this, [=]{ + _SessionDBus->openBluetoothSettings(); + }); + connect(_MBtn, SIGNAL(stateChanged(bool)), this, SLOT(openBluetoothSlot(bool))); + + QHBoxLayout *topLayout = new QHBoxLayout(); + topLayout->setContentsMargins(24,16,25,12); + topLayout->setSpacing(0); + + InitErrorWidget(); + InitNomalWidget(); + + _MStackedWidget->setFixedSize(420,445); + _MStackedWidget->addWidget(_NomalWidget); + if (_Intel) + _MStackedWidget->addWidget(_ErrorWidget); + _MStackedWidget->setCurrentIndex(0); + + _MLabel->resize(60,32); + QPalette _pl; + if(StyleSettings->get("style-name").toString() == "ukui-light"){ + _pl.setColor(QPalette::WindowText, Qt::black); + }else{ + _pl.setColor(QPalette::WindowText, Qt::white); + } + _MLabel->setPalette(_pl); + _MLabel->setText(tr("Bluetooth")); + + _MMainLayout->setMargin(0); + _MMainLayout->setContentsMargins(0,0,0,0); + _MMainLayout->setSpacing(0); + + topLayout->addWidget(_MLabel); + topLayout->addStretch(1); + topLayout->addWidget(_MBtn); + + lineFrame = new QFrame(this); + lineFrame->setFrameShape(QFrame::HLine); + lineFrame->setLineWidth(1); + connect(_MSettingBtn,&BluetoothSettingLabel::hideFeature,this,[=]{ + _MSelf->hide(); + }); + + _MMainLayout->addLayout(topLayout); + lineFrame2 = new QFrame(this); + lineFrame2->setFrameShape(QFrame::HLine); + lineFrame2->setLineWidth(1); + QPalette pl; + pl.setColor(QPalette::WindowText, QColor(0,0,0,20)); + if(StyleSettings->get("style-name").toString() != "ukui-light") + pl.setColor(QPalette::WindowText, QColor(255,255,255,50)); + lineFrame->setPalette(pl); + lineFrame2->setPalette(pl); + _MMainLayout->addWidget(lineFrame2); + _MMainLayout->addWidget(_MStackedWidget); + _MMainLayout->addWidget(lineFrame); + _MMainLayout->addWidget(_MSettingBtn); +} + +void TrayWidget::InitNomalWidget() +{ + _NomalWidget = new QWidget(_MStackedWidget); + _PairedWidget = new QWidget(_NomalWidget); + _PairedLayout = new QVBoxLayout(_PairedWidget); + _ScrollArea = new QScrollArea(_NomalWidget); + QVBoxLayout *_ErrorWidgetLayout = new QVBoxLayout(_NomalWidget); + QVBoxLayout *_ErrorWidgetChildLayout = new QVBoxLayout(_NomalWidget); + QLabel *_ErrorWidgetTipLabel = new QLabel(_NomalWidget); + + _ErrorWidgetLayout->setAlignment(0); + _ErrorWidgetLayout->setContentsMargins(8,12,8,0); + _ErrorWidgetLayout->setSpacing(5); + + _ErrorWidgetChildLayout->setAlignment(0); + _ErrorWidgetChildLayout->setContentsMargins(16,0,0,0); + + _ErrorWidgetTipLabel->resize(420,45); + _ErrorWidgetTipLabel->setText(tr("My Device")); + QPalette pl; + pl.setColor(QPalette::WindowText, QColor("#818181")); + _ErrorWidgetTipLabel->setPalette(pl); + + _NomalWidget->setFixedSize(420,402); + _PairedWidget->setFixedWidth(420); + _PairedWidget->setAttribute(Qt::WA_TranslucentBackground); + + //统一滑动模块的样式 + _ScrollArea->setAttribute(Qt::WA_TranslucentBackground); + _ScrollArea->setProperty("drawScrollBarGroove",false); + _ScrollArea->verticalScrollBar()->setProperty("drawScrollBarGroove",false); + + _ScrollArea->setFixedWidth(420); + _ScrollArea->setWidgetResizable(true); + _ScrollArea->setAlignment(Qt::AlignCenter); + _ScrollArea->setWidget(_PairedWidget); + _ScrollArea->setFrameShape(QFrame::NoFrame); + _ScrollArea->horizontalScrollBar()->hide(); + _ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + _ScrollArea->verticalScrollBar()->setSingleStep(17); + _ScrollArea->setPalette(QColor(Qt::transparent)); + + _PairedLayout->setAlignment(0); + _PairedLayout->setContentsMargins(0,0,0,0); + _PairedLayout->setSpacing(2); + + _ErrorWidgetChildLayout->addWidget(_ErrorWidgetTipLabel); + _ErrorWidgetLayout->addLayout(_ErrorWidgetChildLayout); + _ErrorWidgetLayout->addWidget(_ScrollArea); +} + +void TrayWidget::InitErrorWidget() +{ + _ErrorWidget = new QWidget(_MStackedWidget); + QHBoxLayout* _ErrorWidgeeLayout = new QHBoxLayout(_ErrorWidget); + QLabel* _ErrorIcon = new QLabel(_ErrorWidget); + + _ErrorWidget->setFixedSize(446,420); + + _ErrorWidgeeLayout->setAlignment(0); + _ErrorWidgeeLayout->setContentsMargins(0,0,0,0); + _ErrorWidgeeLayout->setSpacing(0); + + _ErrorIcon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/no-bluetooth.svg")); + + _ErrorWidgeeLayout->addWidget(_ErrorIcon,1,Qt::AlignCenter); + if (!_Intel) + _ErrorIcon->setVisible(false); +} + +void TrayWidget::connectUISignalAndSlot() +{ + connect(_SessionDBus,&BluetoothDbus::devRemoveSignal,this,&TrayWidget::removePairedDevUIByAddress); + connect(_SessionDBus,&BluetoothDbus::adapterAddSignal,this,&TrayWidget::updatePairedDev); + connect(_SessionDBus,&BluetoothDbus::powerChangedSignal,this,[=](bool value){ + qDebug() << Q_FUNC_INFO << value <<__LINE__; + if (!_Intel) + setWidgetPosition(); + if (value != _MBtn->isChecked()) + _MBtn->setChecked(value); + _config.gsetting->set("switch",QVariant::fromValue(value)); + emit trayIconStatusChanged(value); + _SessionDBus->getDefaultAdapterPairedDevices(); + updatePairedDev(); + }); + connect(_SessionDBus,&BluetoothDbus::AdapterChangedSignal,this,[=](QString address){ + Q_UNUSED(address) + _MBtn->setChecked(_SessionDBus->isPowered()); + updatePairedDev(); + }); +} + +void TrayWidget::SendMessage(QString name, bool connected) +{ + QString text; + if (connected) { + text = QString(tr("The connection with the Bluetooth device “%1” is successful!").arg(name)); + + } else { + text = QString(tr("Bluetooth device “%1” disconnected!").arg(name)); + } + Config::SendNotifyMessage(text); +} + +/************************************************ + * @brief 已配对的设备添加到布局中显示 + * @param null + * @return null +*************************************************/ +void TrayWidget::layoutAddAllPairedDev() +{ + bool isNull = true; + int count = 0; + qDebug() << Q_FUNC_INFO << pairedDevices.size() << __LINE__ << pairedDevices; + if (!_PairedWidget->findChildren().size()) { + for (auto item : pairedList) { + QString name = pairedDevices.value(item).at(0); + _SessionDBus->getDevConnectStatus(item); + QDevItem *dev = new QDevItem(item, pairedDevices.value(item), _SessionDBus->isConnected(name), _PairedWidget); + connect(_SessionDBus, &BluetoothDbus::devConnectStatusSignal, dev, [=](QString address, bool connected) { + qDebug() << " +++ compare " << address << item; + if (address != item) + return; + dev->connectedChangedSlot(connected); + }); + connect(dev, &QDevItem::devConnect, this, [=](bool connectdev){ + if(connectdev) + _SessionDBus->devConnect(item); + else + _SessionDBus->devDisconnect(item); + }); + _PairedLayout->addWidget(dev); + isNull = false; + count++; + } + _PairedLayout->addStretch(); + if (_Intel) + return; + isNull = isNull || !_MBtn->isChecked(); + _MStackedWidget->setVisible(!isNull); + lineFrame->setVisible(!isNull); + if (_MSelf) { + selfHeight =160 + count * 54; + if (count >= 7) + selfHeight = 515; + _MSelf->setFixedHeight((isNull ? 102 : selfHeight)); + } + update(); + setWidgetPosition(); + } +} + +void TrayWidget::layoutAddOnePairedDev(QString name, bool paired) +{ + updatePairedDev(); + if (paired) + SendMessage(name, paired); +} + +void TrayWidget::updatePairedDev() { + pairedDevices = _SessionDBus->getPairedDevices(); + pairedList = _SessionDBus->getPairedDevicesList(); + clearPairedWidget(); + layoutAddAllPairedDev(); +} + +/************************************************ + * @brief 清空现在显示的所有配对设备UI + * @param null + * @return null +*************************************************/ +void TrayWidget::clearPairedWidget() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + QLayoutItem *child; + QDevItem *tmp; + while ((child = _PairedLayout->takeAt(0)) != 0) + { + if(child->isEmpty()) + return; + if(child->widget()) + { + tmp = qobject_cast(child->widget()); + disconnect(tmp, &QDevItem::devConnect, nullptr, nullptr); + disconnect(_SessionDBus, &BluetoothDbus::devConnectStatusSignal, nullptr, nullptr); + child->widget()->setParent(NULL); + } + delete child; + delete tmp; + tmp = nullptr; + child = nullptr; + } +} + +/************************************************ + * @brief 根据BluezQt::DevicePtr清空现在显示的配对设备UI + * @param devPtr 配对设备指针 + * @return null +*************************************************/ +void TrayWidget::removePairedDevUIByAddress(QString address) +{ + qDebug() << Q_FUNC_INFO << pairedDevices << __LINE__; + if (!pairedList.contains(address)) + return; + pairedList.removeAll(address); + if (!pairedDevices.contains(address)) + return; + qDebug() << Q_FUNC_INFO << address << __LINE__; + QDevItem *item = _PairedWidget->findChild(address); + if (item) { + if(item->isConnected()) + SendMessage(pairedDevices.value(address).at(0), false); + _PairedLayout->removeWidget(item); + item->setParent(NULL); + delete item; + item = nullptr; + } + pairedDevices.remove(address); + updatePairedDev(); +} + +void TrayWidget::showUI() +{ + if (!_Intel) { + int count = pairedList.size(); + selfHeight =160 + count * 54; + if (count >= 7) + selfHeight = 515; + this->setFixedHeight(((_MBtn->isChecked()) && (count != 0) ? selfHeight : 102)); + setWidgetPosition(); + } else { + QApplication::desktop()->update(); + QRect availableGeometry = QApplication::screens().at(0)->geometry(); + qDebug() << availableGeometry.x() << availableGeometry.y(); + move((availableGeometry.x() + (availableGeometry.width() - width())/2), (availableGeometry.y() + (availableGeometry.height() - height())/2)); + } + showNormal(); +} + +bool TrayWidget::eventFilter(QObject *o, QEvent *e) +{ + if (e->type() == QEvent::ActivationChange) + { + if(QApplication::activeWindow() != this) + { + this->hide(); + } + } + return QWidget::eventFilter(o,e); +} + +void TrayWidget::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::transparent); + QColor col; + if(StyleSettings->get("style-name").toString() == "ukui-light"){ + col = QColor(255,255,255); + } else{ + col = QColor(35,36,38); + } + QPainterPath rectPath; + + if (_Intel) + rectPath.addRect(this->rect()); + else { + col.setAlpha(tran); + rectPath.addRoundedRect(this->rect(),12,12); + } + + painter.setBrush(col); + painter.drawPath(rectPath); +} diff --git a/ukui-bluetooth/mainwidget/traywidget.h b/ukui-bluetooth/mainwidget/traywidget.h new file mode 100644 index 0000000..17271a3 --- /dev/null +++ b/ukui-bluetooth/mainwidget/traywidget.h @@ -0,0 +1,104 @@ +#ifndef TRAYWIDGET_H +#define TRAYWIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "component/bluetoothsettinglabel.h" +#include "component/switchbutton.h" +#include "component/qdevitem.h" +#include "config/config.h" +#include "config/xatom-helper.h" +#include "pin/pincodewidget.h" +#include "daemon/bluetoothdbus.h" +#include "mainwidget/trayicon.h" + +#include "kswitchbutton.h" +using namespace kdk; + +#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + +class TrayWidget : public QWidget +{ + Q_OBJECT +public: + static TrayWidget * self(BluetoothDbus *dbus, bool intel = false); + ~TrayWidget(); + + void InitMemberVariables(); + void connectUISignalAndSlot(); + void setBluetoothOpen(bool v); + void updatePairedDev(); + void layoutAddOnePairedDev(QString name, bool paired); + void setWidgetPosition(); + +public slots: + void GSettingsChanges(const QString &key); + void showUI(); + +private slots: + void openBluetoothSlot(bool); + void removePairedDevUIByAddress(QString address); + void layoutAddAllPairedDev(); + +private: + void InitNomalWidget(); + void InitErrorWidget(); + void clearPairedWidget(); + void getTransparency(); + void SendMessage(QString name, bool connected); + + TrayWidget(bool intel, BluetoothDbus *dBus, QWidget *parent = nullptr); + static TrayWidget* _MSelf; + TrayIcon *trayicon; + + BluetoothDbus *_SessionDBus; + Config _config; + + KSwitchButton *_MBtn = nullptr; + QStackedWidget *_MStackedWidget = nullptr; + QLabel *_MLabel = nullptr; + QVBoxLayout *_MMainLayout = nullptr; + BluetoothSettingLabel *_MSettingBtn = nullptr; + QGSettings *StyleSettings = nullptr; + QGSettings *transparency_gsettings = nullptr; + + QWidget *_NomalWidget = nullptr; + QWidget *_ErrorWidget = nullptr; + QWidget *_PairedWidget = nullptr; + + QVBoxLayout *_PairedLayout = nullptr; + QScrollArea *_ScrollArea = nullptr; + QFrame *lineFrame = nullptr; + QFrame *lineFrame2 = nullptr; + QMap pairedDevices; + QList pairedList; + double tran =1; + bool _Intel; + int selfHeight = 0; + +signals: + void trayIconStatusChanged(bool); + void setManagerUnblocked(bool); + +protected: + void paintEvent(QPaintEvent *event); + bool eventFilter(QObject *o, QEvent *e); +}; + +#endif // TRAYWIDGET_H diff --git a/ukui-bluetooth/pin/pincodewidget.cpp b/ukui-bluetooth/pin/pincodewidget.cpp new file mode 100644 index 0000000..23f3af3 --- /dev/null +++ b/ukui-bluetooth/pin/pincodewidget.cpp @@ -0,0 +1,256 @@ +#include "pincodewidget.h" +#include "config/xatom-helper.h" +#include "config/config.h" + +PinCodeWidget::PinCodeWidget(QString name, QString pin, bool flag) + : dev_name(name), + PINCode(pin), + show_flag(flag) +{ + is_Intel = QFile::exists("/etc/apt/ota_version"); + + if (Config::isHUAWEI()) + scale = QGSettings("org.ukui.SettingsDaemon.plugins.xsettings").get("scaling-factor").toDouble(); + + if(QGSettings::isSchemaInstalled("org.ukui.style")){ + settings = new QGSettings("org.ukui.style"); + connect(settings,&QGSettings::changed,this,&PinCodeWidget::GSettingsChanges); + } + + //窗管协议 + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS; + if (is_Intel) + hints.functions = MWM_FUNC_CLOSE; + else + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); + + QPalette palette; + if(settings->get("style-name").toString() == "ukui-default" || settings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(255,255,255)); + }else{ + palette.setColor(QPalette::Background,QColor(0,0,0)); + } + this->setWindowIcon(QIcon::fromTheme("bluetooth")); + if (is_Intel) + this->setWindowTitle(tr("Bluetooth Connection")); + else + this->setWindowTitle(tr("Bluetooth pairing")); + this->setAttribute(Qt::WA_DeleteOnClose); + + this->setPalette(palette); + this->setAutoFillBackground(true); + + //QString top_text = tr("Bluetooth Connect Request From \'")+dev_name+tr("\'."); + QString tip_text; + QString Name = dev_name; + if (dev_name.size() > 30) { + Name.remove(30, dev_name.size() - 30); + Name.append("..."); + } + if(show_flag) { + if (is_Intel) + tip_text = tr("If the PIN on \'")+Name+tr("\' is the same as this PIN. Please press \'Connect\'"); + else + tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + } else + tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair:")).arg(Name); + //top_label = new QLabel(top_text,this); + //top_label->setStyleSheet("QLabel{\ + // font-size: 18px;\ + // font-family: Noto Sans CJK SC;\ + // font-weight: 500;\ + // line-height: 24px;}"); + //top_label->setWordWrap(true); + + QFont ft_14, ft_16, ft_20, ft_24, ft_40; + int ft_size = settings->get("system-font-size").toInt() - 11; + ft_14.setPixelSize((14 + ft_size) * scale); + ft_16.setPixelSize((16 + ft_size) * scale); + ft_20.setPixelSize((20 + ft_size) * scale); + ft_24.setPixelSize((24 + ft_size) * scale); + ft_40.setPixelSize((40 + ft_size) * scale); + tip_label = new QLabel(tip_text,this); + tip_label->setFont(ft_14); + tip_label->setWordWrap(true); + tip_label->setToolTip(dev_name); + + PIN_label = new QLabel(PINCode,this); + PIN_label->setFont(ft_24); + + accept_btn = new QPushButton(tr("Connect"),this); + + refuse_btn = new QPushButton(tr("Refuse"),this); + + if(show_flag){ + connect(accept_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_accept_btn); + connect(refuse_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_refuse_btn); + }else{ + connect(accept_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_close_btn); + accept_btn->setText(tr("Confirm")); + accept_btn->adjustSize(); + //accept_btn->setddVisible(false); + refuse_btn->setVisible(false); + } + + if (is_Intel) { + this->setWindowFlags(Qt::Dialog); + this->setFixedSize(510, 239); + tip_label->setFont(ft_16); + PIN_label->setFont(ft_40); + tip_label->setGeometry(24,24,450,50); + PIN_label->setGeometry(24,88,462,47); + accept_btn->setGeometry(374,159,112,56); + refuse_btn->setGeometry(246,159,112,56); + } else { + this->setFixedSize(520 * scale ,212 * scale); + title_icon = new QLabel(this); + title_icon->setPixmap(QIcon::fromTheme("preferences-system-bluetooth").pixmap(22 * scale,22 * scale)); + title_icon->resize(22 * scale,22 * scale); + + title_text = new QLabel(tr("Bluetooth Connections"),this); + title_text->setFont(ft_14); + title_text->adjustSize(); + + close_btn = new QPushButton(this); + QIcon icon = QIcon::fromTheme("window-close-symbolic"); + close_btn->setIcon(icon); + close_btn->setProperty("isWindowButton", 0x2); + close_btn->setProperty("useIconHighlightEffect", 0x8); + // close_btn->setProperty("setIconHighlightEffectDefaultColor", QColor(Qt::white)); + close_btn->setFlat(true); + connect(close_btn,&QPushButton::clicked,this,&PinCodeWidget::onClick_close_btn); + + close_btn->setGeometry(480 * scale,8 * scale,30 * scale,30 * scale); + title_icon->setGeometry(8 * scale, 8 * scale, 22 * scale, 22 * scale); + title_text->setGeometry(38 * scale, 9 * scale, 160 * scale, 20 * scale); + PIN_label->setGeometry(25 * scale,98 * scale,207 * scale,36 * scale); + tip_label->setGeometry(25 * scale,56 * scale,437 * scale,44 * scale); + accept_btn->setGeometry(388 * scale,152 * scale,108 * scale,36 * scale); + refuse_btn->setGeometry(264 * scale,152 * scale,108 * scale,36 * scale); + } + QList list = QGuiApplication::screens(); + this->move(list.at(0)->size().width()/2-this->width()/2,list.at(0)->size().height()/2-this->height()/2); +} + +PinCodeWidget::~PinCodeWidget() +{ + qDebug() << Q_FUNC_INFO << __LINE__ << dev_name << PINCode << show_flag; +} + +void PinCodeWidget::pairFailureShow() +{ + qDebug() << Q_FUNC_INFO << __LINE__; + if (is_Intel) { + warn_icon = new QLabel(this); + warn_icon->setFixedSize(64 * scale,64 * scale); + qDebug() << Q_FUNC_INFO << __LINE__; + warn_icon->setPixmap(QPixmap("/usr/share/ukui-bluetooth/connection-failed.svg")); + warn_icon->setGeometry(223 * scale,42 * scale,64 * scale,64 * scale); + warn_icon->setVisible(true); + tip_label->setText(QString(tr("Bluetooth Connect Failed"))); + tip_label->setGeometry(210 * scale,108 * scale,190 * scale,28 * scale); + tip_label->setStyleSheet("QLabel{\ + font-family: NotoSansCJKsc;\ + font-size: 16px;\ + line-height: 19px;\ + text-align: center;\ + color: #FB5050;}"); + PIN_label->setVisible(false); + accept_btn->setVisible(false); + refuse_btn->setText(tr("Close")); + refuse_btn->setGeometry(374 * scale,159 * scale,112 * scale,56 * scale); + return; + } + QMessageBox msgBox; + msgBox.setParent(this); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setWindowTitle(tr("Pair")); + msgBox.setText(tr("Connect Failed!")); + int ret = msgBox.exec(); + if(ret){ + qDebug() << Q_FUNC_INFO << this << __LINE__; + this->setHidden(true); + emit msgShowedOver(); + } +} + +void PinCodeWidget::updateUIInfo(const QString &name, const QString &pin) +{ + qDebug() << Q_FUNC_INFO << this->isActiveWindow() << __LINE__; + PINCode = pin; + PIN_label->setText(pin); + PIN_label->update(); + + QString tip_text; + QString Name = name; + if (name.size() > 30) { + Name.remove(30, name.size() - 30); + Name.append("..."); + tip_label->setToolTip(name); + } + if(show_flag) + if (is_Intel) + tip_text = tr("If the PIN on \'")+Name+tr("\' is the same as this PIN. Please press \'Connect\'"); + else + tip_text = tr("If \'")+Name+tr("\' the PIN on is the same as this PIN. Please press \'Connect\'."); + else + tip_text = QString(tr("Please enter the following PIN code on the bluetooth device '%1' and press enter to pair:")).arg(Name); + tip_label->setText(tip_text); + tip_label->update(); + + if (!this->isActiveWindow()) + this->setHidden(false); +} + +void PinCodeWidget::onClick_close_btn(bool) +{ + qDebug() << Q_FUNC_INFO << __LINE__; + if (show_flag) { + emit this->rejected(); + this->close(); + } else { + emit this->msgShowedOver(); + } +} + +void PinCodeWidget::onClick_accept_btn(bool) +{ + qDebug() << "pincodewindget.cpp : accpet"; + emit this->accepted(); + this->close(); +} + +void PinCodeWidget::onClick_refuse_btn(bool) +{ + emit this->rejected(); + this->close(); +} + +void PinCodeWidget::GSettingsChanges(const QString &key) +{ + QPalette palette; + qDebug() << Q_FUNC_INFO << key; + if(key == "styleName"){ + if(settings->get("style-name").toString() == "ukui-default" || settings->get("style-name").toString() == "ukui-light"){ + palette.setColor(QPalette::Background,QColor(Qt::white)); + }else{ + palette.setColor(QPalette::Background,QColor(Qt::black)); + } + } + if (key == "systemFontSize") { + int size = settings->get("system-font-size").toInt() - 11; + qDebug() << Q_FUNC_INFO << size; + QFont ft, ft1; + ft.setPixelSize((14 + size) * scale); + tip_label->setFont(ft); + title_text->setFont(ft); + ft1.setPixelSize((24 + size) * scale); + PIN_label->setFont(ft1); + } + this->setPalette(palette); + this->update(); +} + diff --git a/ukui-bluetooth/pin/pincodewidget.h b/ukui-bluetooth/pin/pincodewidget.h new file mode 100644 index 0000000..5587f24 --- /dev/null +++ b/ukui-bluetooth/pin/pincodewidget.h @@ -0,0 +1,72 @@ +#ifndef PINCODEWIDGET_H +#define PINCODEWIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + +class PinCodeWidget : public QWidget +{ + Q_OBJECT +public: + explicit PinCodeWidget(QString name = "", QString pin = "", bool flag = true); + ~PinCodeWidget(); + void pairFailureShow(); + void updateUIInfo(const QString &name,const QString &pin); + bool canceled = false; +public slots: + +private slots: + void onClick_close_btn(bool); + void onClick_accept_btn(bool); + void onClick_refuse_btn(bool); + void GSettingsChanges(const QString &key); +signals: + void accepted(); + void rejected(); + void msgShowedOver(); +private: + QGSettings *settings = nullptr; + QGSettings *transparency_gsettings = nullptr; + + QLabel *PIN_label = nullptr; + QLabel *tip_label = nullptr; + QLabel *top_label = nullptr; + QLabel *warn_icon = nullptr; + QLabel *title_icon = nullptr; + QLabel *title_text = nullptr; + double tran = 1; + + QVBoxLayout *main_layout = nullptr; + + QPushButton *close_btn = nullptr; + QPushButton *accept_btn = nullptr; + QPushButton *refuse_btn = nullptr; + + QString dev_name; + QString PINCode; + bool show_flag; + bool is_Intel = false; + double scale = 1.0; +}; + +#endif // PINCODEWIDGET_H diff --git a/ukui-bluetooth/translations/ukui-bluetooth_bo_CN.qm b/ukui-bluetooth/translations/ukui-bluetooth_bo_CN.qm new file mode 100644 index 0000000000000000000000000000000000000000..e4552282b157fab87ec3fc5bc12ceeaff5fbe754 GIT binary patch literal 2356 zcmcgtO=uHA6ds$Orp7pJ6)aeB>Ms#e*WA1Vu%`gP;fn&!QlL2l1QPG}->7O)nm@v)T9ez4yNNru#{z z<<<9v`8RE?&r^%fzQhS3PY4N}B4kIacLq%o%Gcrj1qr=-Nl5S+Iel^-dLILYAB*^| z2ClvRMMzyfIJMvs5*Q2K9()SIP@7t(s1j+x3v`FUtlX8YxLG=$RaMcL*3Qbd*j@*CPld!d;TEl(PG9pK5B{sL5M1 z?S&5yut;FU2Q$=XSPrkr4MX-rvL-1woTi!t_NWZBl6&3InVLLyR;{Cg+Ij_0=tb0B zbixn2X{BhkZswS4u|qWlJhHC6qLGVmo}%aJk_=Qyqp92`HqISK&B;22`z$l7=VYH6 z*Z8a0?k-*~>L=1G91!UIhBwe)k4=JUqQzNy4>`}srYFEFMP{6WmXOU!a31>v7d?8! z2-`p=`02N()Y2nU3VmFXbV}nHhi(OS_gRZ&_=K);rWI|Qo31g%)CpBL)HF!ElO+tU zI-KP!QS^eU+sw`Ll8H!iPrtNIa)Z0v_EEYSaTZJSqM^4*U(|4~rtyL+>|4Y{oZ}kT zC(zl1RVWsGPX5n$ZjNDFv$?seZBNwZ?i#^iv8WtRRGQ4?*@dHB%d>Y_Mt3x?G&~~<5*fz$4Z3_> zZl}?j(GAPXYvay{VHHb4T!o@DiVs`Q2!_7|L3C$Q$8{$bLUqi#!<-_<-Ep!-V*}9D tS87Aqsp!V8B!X%AUP+5Bmho!K2=0!lL7?82)lOmMBl0FVS8aX2-9KDg9Nqu` literal 0 HcmV?d00001 diff --git a/ukui-bluetooth/translations/ukui-bluetooth_bo_CN.ts b/ukui-bluetooth/translations/ukui-bluetooth_bo_CN.ts new file mode 100644 index 0000000..af6b9b4 --- /dev/null +++ b/ukui-bluetooth/translations/ukui-bluetooth_bo_CN.ts @@ -0,0 +1,344 @@ + + + + + BluetoothFileTransferWidget + + OK + གཏན་འཁེལ་བྱེད་པ། + + + Close + ཁ་རྒྱག་པ། + + + Cancel + མེད་པར་བཟོ་བ + + + Successfully transmitted! + ཡིག་ཆ་བསྐུར་བ་ལེགས་གྲུབ། + + + Transferring to " + བརྒྱུད་གཏོང་བྱེད་བཞིན་པ། + + + Transmission failed! + ཡིག་ཆ་བསྐུར་བ་ཕམ་ཉེས་བྱུང་། + + + Bluetooth file transfer + སོ་སྔོན་གྱིས་ཡིག་ཆ་བརྒྱུད་གཏོང་། + + + and + + + + files more + + + + Select Device + + + + File Transmission Failed ! + + + + File Transmition Succeed! + + + + + BluetoothSettingLabel + + Bluetooth Settings + + + + + Config + + ukui-bluetooth + སོ་སྔོན། + + + Bluetooth message + སོ་སྔོན་བརྡ་འཕྲིན། + + + + DeviceSeleterWidget + + Select equipment + སྒྲིག་ཆས་འདེམ་པ། + + + No device currently available + Please go to pair the device + མིག་སྔར་སྤྱོད་ཐུབ་པའི་སྒྲིག་ཆས་མེད། སྒྲིག་ཆས་ཆ་སྒྲིག་བྱེད་པར་འགྲོ་རོགས། + + + + FeaturesWidget + + Bluetooth Adapter Abnormal!!! + སོ་སྔོན་འོས་སྒྲིག་ཆས་རྒྱུན་ལྡན་མིན། + + + Connection + འབྲེལ་མཐུད། + + + Power + ཁ་རྒྱག་པ། + + + Remove + བསུབ་པ། + + + Send files + ཡིག་ཆ་སྐུར་བ། + + + The connection with the Bluetooth device “%1” is successful! + སོ་སྔོན་སྒྲིག་ཆས“%1”དང་སྦྲེལ་མཐུད་ལེགས་གྲུབ། + + + Bluetooth message + སོ་སྔོན་བརྡ་འཕྲིན། + + + ukui-bluetooth + སོ་སྔོན། + + + My Devices + སྒྲིག་ཆས། + + + Bluetooth + སོ་སྔོན། + + + bluetooth + སོ་སྔོན། + + + Connect audio + སྒྲ་ཟློས་འབྲེལ་མཐུད། + + + Bluetooth settings + སོ་སྔོན་སྒྲིག་འགོད། + + + no bluetooth adapter! + སོ་སྔོན་འོས་སྒྲིག་ཆས་མི་འདུག + + + Bluetooth device “%1” disconnected! + སོ་སྔོན་སྒྲིག་ཆས“%1”སྦྲེལ་མཐུད་བོར་བརླག་ཐེབས། + + + Disconnection + འབྲེལ་མཐུད། + + + + FileReceivingPopupWidget + + View + ཕྱི་ཚུལ། + + + Accept + སྡུད་ལེན། + + + Cancel + མེད་པར་བཟོ་བ + + + Sender canceled or transmission error + སྐུར་ཡུལ་ནས་རྩིས་མེད་བཏང་བའམ་བསྐུར་ནོར་ཐེབས་པ། + + + Bluetooth file transfer from " + %s ནས་སོ་སྔོན་གྱིས་ཡིག་ཆ་བརྒྱུད་གཏོང་བྱེད་པ། + + + Bluetooth file transfer + སོ་སྔོན་གྱིས་ཡིག་ཆ་བརྒྱུད་གཏོང་། + + + Bluetooth File + + + + File from " + + + + ", waiting for receive. + + + + ", is receiving... (has recieved + + + + files) + + + + ", is receiving... + + + + OK + གཏན་འཁེལ་བྱེད་པ། + + + ", received failed ! + + + + File Transmission Failed ! + + + + + KyFileDialog + + Bluetooth File + + + + + MainProgram + + Warning + + + + The selected file is empty, please select the file again ! + + + + + PinCodeWidget + + Pair + ཆ་སྒྲིག + + + " matches the number below. Please do not enter this code on any other accessories. + སྟེང་དུ་མངོན་པའི་གྲངས་ཀ་དང་འོག་ཏུ་མངོན་པའི་གྲངས་ངོ་འཕྲོད་མི་ཐུབ། ཁྱོས་གཞན་གྱི་སྡེབ་སྒྲིག་སྟེང་ཨང་ཚབ་ནང་འཇུག་བྱེད་མི་རུང་། + + + Connection error !!! + སྦྲེལ་མཐུད་ནོར་འཁྲུལ། + + + Is it paired with: + ཆ་སྒྲིག་བྱེད་པའི་སྒང་ཡིན། + + + Accept + སྡུད་ལེན། + + + Refush + རྩིས་མེད། + + + Failed to pair with %1 !!! + %1དང་ཆ་སྒྲིག་བྱེད་པ་ཕམ་ཉེས་བྱུང་། + + + Please make sure the number displayed on " + གཏན་འཁེལ་བྱ་རོགས། + + + Please enter the following PIN code on the bluetooth device %1 and press enter to pair ! + སོ་སྔོན་སྒྲིག་ཆས་%1སྟེང་གཤམ་གྱི་ཨང་PINནང་འཇུག་བྱས་རྗེས་ཕྱིར་ལོག་མཐེབ་མནོན་མནན་ནས་ཆ་སྒྲིག་བྱ་དགོས། + + + Bluetooth pairing + སོ་སྔོན་སྒྲིག་ཆས་ཆ་སྒྲིག + + + If you want to pair with this device, please make sure the numbers below are the same with the devices. + + + + If ' + + + + ' the PIN on is the same as this PIN. Please press 'Connect'. + + + + Please enter the following PIN code on the bluetooth device '%1' and press enter to pair ! + + + + Connect + + + + Please make sure the PIN code displayed on ' + + + + ' matches the number below. Please press 'Connect'. + + + + + QDevItem + + The connection with the Bluetooth device “%1” is successful! + སོ་སྔོན་སྒྲིག་ཆས“%1”དང་སྦྲེལ་མཐུད་ལེགས་གྲུབ། + + + Bluetooth device “%1” disconnected! + སོ་སྔོན་སྒྲིག་ཆས“%1”སྦྲེལ་མཐུད་བོར་བརླག་ཐེབས། + + + + SwitchAction + + Bluetooth + སོ་སྔོན། + + + + TrayIcon + + Bluetooth + སོ་སྔོན། + + + + TrayWidget + + bluetooth + སོ་སྔོན། + + + Bluetooth + སོ་སྔོན། + + + My Device + + + + diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.qm new file mode 100644 index 0000000000000000000000000000000000000000..7a0a7531bda81ccb89b2d54ac432a0ca63dce226 GIT binary patch literal 5146 zcmcgve{37o9e+tKj(t8mNmtgArR%FjngmttGO0|;m}ncQWJ+8o&KgA((98MRIbq*< zcW0*#+D2IrWf5viRho^$)@_wGX%g_)HnA0^Nkf3TwHrf28cbtDXh;ZY2+B60?EAfU zem=W)>`D`VwBP9bzMt>U_xXO`tv^q1e);`#XD)3UeE!J!U%j!9kWNBK_m>IjI?iS2 zXGHpVn2^Zxq0&cnGbF6BeLkN@Wicxkp$r14Y3_mGYx}j4%HoM zTGTL|+j`)a&+gS6y~HN?kGg5h>ggb!h+|UTd zZiOSIUdtaBt^_7jLu0v?N;UrXcwV>C>Pua*pE>)%>Zz5Bb3KHTm@vC>zgaZWR4t}; zlcrfo*BFhpf(sCOf1FSO(oI#sK&{V-OzhWlY{pUzJHsr04G2x#%pOjBB$UH614nI| zH!ap41eUP|Vw14yVo}Gl+ZJ5YGPI0EnzGNlC*tUy$eDI~5k%4Z)RmJRb7PMVt#t^9 z0ZbZovzFIw8@iY7SK(8dZfh$Pfji$f{XHM=fMMQ zITJh?n*S&Eo6wA;SPpOO?QWa31u`(d=VS=8l^9=IT2of8p1Q=IL115W<1-74+AcI? z3Y&@QHf8yOQ{F)fIi}i`pQ!^U-2-Y?)s1$uij_hij(t#bb^0sqZRtjqIwrq2t-D6M zTpkxW>6uk61N7U?Ad{D>*e_KUN0lG(PJb(`I8O|%sl6~ z^)VWbixw)`w->`AmC_-dEw-*hTcuPEl+pRybv0*lV*37Velhi5I*98Z-6B#oHjK1{W6f6ci~?^s3-BQs zPwcEvXu$%qro-N*IE;CXBz0rLOfw(xeGzwUG)$5tP7+5u64Cq8mA@-4Xd!G1bb-Wt z#PF42*8?z0VYRqUe_Z-#;E;RE&=j_}h<9`KvU&k|8&Z?7u4CnI;KQ}r)xqj}Ft{VP zfw~(4jy)WIA_U(U#kuCq{s!vJ*2_jmYc@1|6=ZZP-y|ne(Sq{ zhO}B1&9?!TW}mAVJQk)_aXp7*G~pxH|94I5@q_dIeA^ZwgeJ?rXIB0BPqB*irt8us Kt_LRAfA)Wk1dAR3 literal 0 HcmV?d00001 diff --git a/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts new file mode 100644 index 0000000..ee2a7da --- /dev/null +++ b/ukui-bluetooth/translations/ukui-bluetooth_zh_CN.ts @@ -0,0 +1,401 @@ + + + + + ActiveConnectionWidget + + + Bluetooth Connection + 蓝牙连接 + + + + Bluetooth Connections + 蓝牙连接 + + + + + Found audio device " + 发现音频设备 " + + + + + ", connect it or not? + " ,是否连接? + + + + Connect + 连接 + + + + Cancel + 取消 + + + + BluetoothFileTransferWidget + + + + Bluetooth file transfer + 蓝牙文件 + + + + + Transferring to " + 发送文件至 " + + + + + + and + + + + + + + files more + 个文件 + + + + Select Device + 选择设备 + + + + + + OK + 确定 + + + + Cancel + 取消 + + + + File Transmission Failed ! + 文件发送失败! + + + + Warning + 提示 + + + + The selected file is empty, please select the file again ! + 所选文件为空,请重新选择! + + + + + File Transmition Succeed! + 文件发送成功! + + + + Close + 关闭 + + + + BluetoothSettingLabel + + + Bluetooth Settings + 蓝牙设置 + + + + Config + + ukui-bluetooth + 蓝牙 + + + + Bluetooth + 蓝牙 + + + + Bluetooth Message + 蓝牙消息 + + + Bluetooth message + 蓝牙消息 + + + + DeviceSeleterWidget + + + No device currently available + Please go to pair the device + 当前没有可用的设备 +请去配对设备 + + + + FileReceivingPopupWidget + + + Bluetooth file transfer + 蓝牙文件传输 + + + + Bluetooth File + 蓝牙文件 + + + + + + + + + + + + File from " + 文件来自 " + + + + + + ", waiting for receive... + ",等待接收… + + + + + ", waiting for receive. + ",等待接收。 + + + + Cancel + 取消 + + + + Accept + 接收 + + + + View + 查看 + + + + ", is receiving... (has recieved + ",正在接收… (已接收 + + + + files) + 个文件) + + + + ", is receiving... + ",正在接收… + + + + OK + 确定 + + + + + ", received failed ! + ",接收失败! + + + + File Transmission Failed ! + 文件传输失败! + + + + KyFileDialog + + + Bluetooth File + 蓝牙文件 + + + + MainProgram + + + Warning + 提示 + + + + The selected file is empty, please select the file again ! + 所选文件为空,请重新选择! + + + + PinCodeWidget + + + Bluetooth pairing + 蓝牙设备配对 + + + + + ' is the same as this PIN. Please press 'Connect' + ”上的数字与下面相同,请点击“连接” + + + + + If ' + 如果 " + + + + Refuse + 取消 + + + + Bluetooth Connections + 蓝牙连接 + + + + Bluetooth Connect Failed + 蓝牙连接失败 + + + + Close + 关闭 + + + + Connect Failed! + 连接失败! + + + + + ' the PIN on is the same as this PIN. Please press 'Connect'. + " 上的PIN码与此PIN码相同,请按 "连接"。 + + + + Bluetooth Connection + 蓝牙连接 + + + + + If the PIN on ' + 如“ + + + + + Please enter the following PIN code on the bluetooth device '%1' and press enter to pair: + 请在蓝牙设备 "%1" 上输入相同PIN,并按"Enter"确认: + + + + Confirm + 确定 + + + + Connect + 连接 + + + + Pair + 配对 + + + + QDevItem + + + The connection with the Bluetooth device “%1” is successful! + 与蓝牙设备“%1”连接成功! + + + + Bluetooth device “%1” disconnected! + 蓝牙设备“%1”失去连接! + + + + SwitchAction + + + Bluetooth + 蓝牙 + + + + TrayIcon + + + Set Bluetooth Item + 设置蓝牙项 + + + + Bluetooth + 蓝牙 + + + + TrayWidget + + + bluetooth + 蓝牙 + + + + Bluetooth + 蓝牙 + + + + My Device + 我的设备 + + + + The connection with the Bluetooth device “%1” is successful! + 与蓝牙设备“%1”连接成功! + + + + Bluetooth device “%1” disconnected! + 蓝牙设备“%1”失去连接! + + + diff --git a/ukui-bluetooth/ukui-bluetooth.pro b/ukui-bluetooth/ukui-bluetooth.pro new file mode 100644 index 0000000..de6f18d --- /dev/null +++ b/ukui-bluetooth/ukui-bluetooth.pro @@ -0,0 +1,115 @@ +TARGET = ukui-bluetooth +DESTDIR = . +TEMPLATE = app + +include(../qtsingleapplication/qtsingleapplication.pri) +include(../environment.pri) + +QT += core gui dbus KWindowSystem x11extras + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 link_pkgconfig USE_OBEX + +PKGCONFIG += gsettings-qt \ + gio-2.0 \ + kysdk-qtwidgets + +# 适配窗口管理器圆角阴影 +LIBS +=-lpthread +LIBS +=-lX11 -lXrandr -lXinerama -lXi -lXcursor + +LIBS += -L /usr/lib/x86_64-linux-gnu -l KF5BluezQt -lgio-2.0 -lglib-2.0 -lukui-log4qt + +QMAKE_LFLAGS += -D_FORTIFY_SOURCE=2 -O2 + +inst1.files += ../data/org.bluez.Agent1.conf +inst1.path = $$CONF_INSTALL_DIR +inst2.files += ../data/org.ukui.bluetooth.gschema.xml +inst2.path = $$SCHEMAS_INSTALL_DIR +inst3.files += ../data/no-bluetooth.svg +inst3.path = $$SHARE_INSTALL_DIR +inst4.files += ../data/file-transfer-success.svg +inst4.path = $$SHARE_INSTALL_DIR +inst5.files += ../data/file-transfer-failed.svg +inst5.path = $$SHARE_INSTALL_DIR +inst6.files +=../data/connection-failed.svg +inst6.path = $$SHARE_INSTALL_DIR +target.source += $$TARGET +target.path = $$BIN_INSTALL_DIR +INSTALLS += inst1 \ + inst2 \ + inst3 \ + inst4 \ + inst5 \ + inst6 \ + target + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS +# QT_NO_WARNING_OUTPUT \ +# QT_NO_DEBUG_OUTPUT + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +unix { + UI_DIR = .ui + MOC_DIR = .moc + OBJECTS_DIR = .obj +} + +SOURCES += \ + activeConn/activeconnectionwidget.cpp \ + component/bluetoothsettinglabel.cpp \ + component/kyfiledialog.cpp \ + component/qdevitem.cpp \ + component/switchaction.cpp \ + component/switchbutton.cpp \ + config/config.cpp \ + fileSend/bluetoothfiletransferwidget.cpp \ + fileReceive/filereceivingpopupwidget.cpp \ + fileSend/deviceselectitem.cpp \ + main/main.cpp \ + main/mainprogram.cpp \ + mainwidget/trayicon.cpp \ + mainwidget/traywidget.cpp \ + pin/pincodewidget.cpp \ + fileSend/deviceseleterwidget.cpp \ + config/xatom-helper.cpp \ + daemon/bluetoothdbus.cpp +HEADERS += \ + activeConn/activeconnectionwidget.h \ + component/bluetoothsettinglabel.h \ + component/kyfiledialog.h \ + component/qdevitem.h \ + component/switchaction.h \ + component/switchbutton.h \ + config/config.h \ + fileSend/bluetoothfiletransferwidget.h \ + fileSend/deviceselectitem.h \ + fileReceive/filereceivingpopupwidget.h \ + main/mainprogram.h \ + mainwidget/trayicon.h \ + mainwidget/traywidget.h \ + pin/pincodewidget.h \ + fileSend/deviceseleterwidget.h \ + config/xatom-helper.h \ + daemon/bluetoothdbus.h + + +TRANSLATIONS += \ + translations/ukui-bluetooth_zh_CN.ts \ + translations/ukui-bluetooth_bo_CN.ts +# Default rules for deployment. +#qnx: target.path = /tmp/$${TARGET}/bin +#else: unix:!android: target.path = /opt/$${TARGET}/bin +#!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + ukui-bluetooth.qrc diff --git a/ukui-bluetooth/ukui-bluetooth.qrc b/ukui-bluetooth/ukui-bluetooth.qrc new file mode 100644 index 0000000..62a7b98 --- /dev/null +++ b/ukui-bluetooth/ukui-bluetooth.qrc @@ -0,0 +1,6 @@ + + + + ./translations/ukui-bluetooth_zh_CN.qm + +