/src/libreoffice/sfx2/source/dialog/bluthsnd.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include <com/sun/star/frame/XFrame.hpp> |
11 | | |
12 | | #include <bluthsndapi.hxx> |
13 | | #include <osl/file.hxx> |
14 | | #include <sfx2/app.hxx> |
15 | | #include <sfx2/sfxresid.hxx> |
16 | | #include <sfx2/strings.hrc> |
17 | | #include <vcl/DesktopType.hxx> |
18 | | #include <vcl/svapp.hxx> |
19 | | #include <vcl/vclenum.hxx> |
20 | | #include <vcl/weld/MessageDialog.hxx> |
21 | | #include <vcl/weld/weld.hxx> |
22 | | |
23 | | #if defined(LINUX) || defined(MACOSX) |
24 | | #include <sys/wait.h> |
25 | | #endif |
26 | | |
27 | | SfxBluetoothModel::SendMailResult SfxBluetoothModel::SaveAndSend( const css::uno::Reference< css::frame::XFrame >& xFrame ) |
28 | 0 | { |
29 | 0 | SaveResult eSaveResult; |
30 | 0 | SendMailResult eResult = SEND_MAIL_ERROR; |
31 | 0 | OUString aFileName; |
32 | |
|
33 | 0 | eSaveResult = SaveDocumentAsFormat( OUString(), xFrame, OUString(), aFileName ); |
34 | 0 | if( eSaveResult == SAVE_SUCCESSFUL ) |
35 | 0 | { |
36 | 0 | maAttachedDocuments.push_back( aFileName ); |
37 | 0 | return Send(); |
38 | 0 | } |
39 | 0 | else if( eSaveResult == SAVE_CANCELLED ) |
40 | 0 | eResult = SEND_MAIL_CANCELLED; |
41 | | |
42 | 0 | return eResult; |
43 | 0 | } |
44 | | |
45 | | SfxBluetoothModel::SendMailResult SfxBluetoothModel::Send() |
46 | 0 | { |
47 | | #if !defined(LINUX) && !defined(MACOSX) |
48 | | (void) this; // avoid loplugin:staticmethods |
49 | | return SEND_MAIL_ERROR; |
50 | | #else |
51 | 0 | #ifdef LINUX |
52 | | //KDE |
53 | 0 | static constexpr OUString KdePackageName = u"bluedevil"_ustr; |
54 | 0 | static constexpr OUString KdeToolName = u"bluedevil-sendfile"_ustr; |
55 | | |
56 | | //Gnome |
57 | 0 | static constexpr OUString GnomePackageName = u"gnome-bluetooth"_ustr; |
58 | 0 | static constexpr OUString GnomeToolName = u"bluetooth-sendto"_ustr; |
59 | | |
60 | | //XFCE and LXQT |
61 | 0 | static constexpr OUString Xfce_Lxqt_PackageName = u"blueman"_ustr; |
62 | 0 | static constexpr OUString Xfce_Lxqt_ToolName = u"blueman-sendto"_ustr; |
63 | | |
64 | | //Mate |
65 | 0 | static constexpr OUString MatePackageName = u"blueberry"_ustr; |
66 | 0 | static constexpr OUString MateToolName = u"blueberry-sendto"_ustr; |
67 | |
|
68 | 0 | static constexpr int CommandNotFound = 127; |
69 | | #elif defined(MACOSX) |
70 | | //macOS |
71 | | static constexpr OUString MacToolName = u"Bluetooth File Exchange"_ustr; |
72 | | #endif |
73 | |
|
74 | 0 | SendMailResult eResult = SEND_MAIL_OK; |
75 | 0 | OUString aFilePath = maAttachedDocuments.back(); |
76 | 0 | OUString aSystemPath; |
77 | |
|
78 | 0 | osl::File::getSystemPathFromFileURL(aFilePath, aSystemPath); |
79 | |
|
80 | 0 | OUString aSendCommand; |
81 | 0 | OUString aToolName; |
82 | 0 | #ifdef LINUX |
83 | 0 | OUString aPackageName; |
84 | 0 | const DesktopType eDesktopEnvironment = Application::GetDesktopEnvironment(); |
85 | |
|
86 | 0 | if (eDesktopEnvironment == DesktopType::Plasma5 || eDesktopEnvironment == DesktopType::Plasma6) |
87 | 0 | { |
88 | 0 | aPackageName = KdePackageName; |
89 | 0 | aToolName = KdeToolName; |
90 | 0 | aSendCommand = aToolName + " -f " + aSystemPath; |
91 | 0 | } |
92 | 0 | else if (eDesktopEnvironment == DesktopType::GNOME) |
93 | 0 | { |
94 | 0 | aPackageName = GnomePackageName; |
95 | 0 | aToolName = GnomeToolName; |
96 | 0 | aSendCommand = aToolName + " " + aSystemPath; |
97 | 0 | } |
98 | 0 | else if (eDesktopEnvironment == DesktopType::Xfce || eDesktopEnvironment == DesktopType::LXQt) |
99 | 0 | { |
100 | 0 | aPackageName = Xfce_Lxqt_PackageName; |
101 | 0 | aToolName = Xfce_Lxqt_ToolName; |
102 | 0 | aSendCommand = aToolName + " " + aSystemPath; |
103 | 0 | } |
104 | 0 | else if (eDesktopEnvironment == DesktopType::MATE) |
105 | 0 | { |
106 | 0 | aPackageName = MatePackageName; |
107 | 0 | aToolName = MateToolName; |
108 | 0 | aSendCommand = aToolName + " " + aSystemPath; |
109 | 0 | } |
110 | | #elif defined(MACOSX) |
111 | | aToolName = MacToolName; |
112 | | aSendCommand = "open -a \"" + aToolName + "\" " + aSystemPath; |
113 | | #endif |
114 | |
|
115 | 0 | OString aRawCommand = OUStringToOString( aSendCommand, RTL_TEXTENCODING_UTF8); |
116 | |
|
117 | 0 | int status = system(aRawCommand.getStr()); |
118 | 0 | if (status == -1 || |
119 | 0 | !WIFEXITED(status) || |
120 | 0 | WEXITSTATUS(status) != 0) |
121 | 0 | { |
122 | 0 | eResult = SEND_MAIL_ERROR; |
123 | 0 | OUString errMsg; |
124 | |
|
125 | 0 | #ifdef LINUX |
126 | 0 | if(WIFEXITED(status) && WEXITSTATUS(status) == CommandNotFound) |
127 | 0 | { |
128 | 0 | errMsg = SfxResId(STR_BLUETOOTH_PACKAGE_ERROR_LINUX) |
129 | 0 | .replaceAll("%TOOL", aToolName) |
130 | 0 | .replaceAll("%PKG", aPackageName); |
131 | 0 | } |
132 | | #elif defined(MACOSX) |
133 | | errMsg = SfxResId(STR_BLUETOOTH_ERROR_MACOS).replaceAll("%TOOL", aToolName); |
134 | | #endif |
135 | |
|
136 | 0 | if(!errMsg.isEmpty()) |
137 | 0 | { |
138 | 0 | weld::Window* pWin = SfxGetpApp()->GetTopWindow(); |
139 | 0 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( |
140 | 0 | pWin, VclMessageType::Info, VclButtonsType::Ok, errMsg)); |
141 | 0 | xBox->run(); |
142 | 0 | } |
143 | 0 | } |
144 | 0 | return eResult; |
145 | 0 | #endif |
146 | 0 | } |
147 | | |
148 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |