Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
22
#if defined(LINUX) || defined(MACOSX)
23
#include <sys/wait.h>
24
#endif
25
26
SfxBluetoothModel::SendMailResult SfxBluetoothModel::SaveAndSend( const css::uno::Reference< css::frame::XFrame >& xFrame )
27
0
{
28
0
    SaveResult      eSaveResult;
29
0
    SendMailResult  eResult = SEND_MAIL_ERROR;
30
0
    OUString   aFileName;
31
32
0
    eSaveResult  = SaveDocumentAsFormat( OUString(), xFrame, OUString(), aFileName );
33
0
    if( eSaveResult == SAVE_SUCCESSFUL )
34
0
    {
35
0
        maAttachedDocuments.push_back( aFileName );
36
0
        return Send();
37
0
    }
38
0
    else if( eSaveResult == SAVE_CANCELLED )
39
0
        eResult = SEND_MAIL_CANCELLED;
40
41
0
    return eResult;
42
0
}
43
44
SfxBluetoothModel::SendMailResult SfxBluetoothModel::Send()
45
0
{
46
#if !defined(LINUX) && !defined(MACOSX)
47
    (void) this; // avoid loplugin:staticmethods
48
    return SEND_MAIL_ERROR;
49
#else
50
0
#ifdef LINUX
51
    //KDE
52
0
    static constexpr OUString KdePackageName = u"bluedevil"_ustr;
53
0
    static constexpr OUString KdeToolName = u"bluedevil-sendfile"_ustr;
54
55
    //Gnome
56
0
    static constexpr OUString GnomePackageName = u"gnome-bluetooth"_ustr;
57
0
    static constexpr OUString GnomeToolName = u"bluetooth-sendto"_ustr;
58
59
    //XFCE and LXQT
60
0
    static constexpr OUString Xfce_Lxqt_PackageName = u"blueman"_ustr;
61
0
    static constexpr OUString Xfce_Lxqt_ToolName = u"blueman-sendto"_ustr;
62
63
    //Mate
64
0
    static constexpr OUString MatePackageName = u"blueberry"_ustr;
65
0
    static constexpr OUString MateToolName = u"blueberry-sendto"_ustr;
66
67
0
    static constexpr int CommandNotFound = 127;
68
#elif defined(MACOSX)
69
    //macOS
70
    static constexpr OUString MacToolName = u"Bluetooth File Exchange"_ustr;
71
#endif
72
73
0
    SendMailResult eResult = SEND_MAIL_OK;
74
0
    OUString aFilePath = maAttachedDocuments.back();
75
0
    OUString aSystemPath;
76
77
0
    osl::File::getSystemPathFromFileURL(aFilePath, aSystemPath);
78
79
0
    OUString aSendCommand;
80
0
    OUString aToolName;
81
0
#ifdef LINUX
82
0
    OUString aPackageName;
83
0
    const DesktopType eDesktopEnvironment = Application::GetDesktopEnvironment();
84
85
0
    if (eDesktopEnvironment == DesktopType::Plasma5 || eDesktopEnvironment == DesktopType::Plasma6)
86
0
    {
87
0
        aPackageName = KdePackageName;
88
0
        aToolName =  KdeToolName;
89
0
        aSendCommand = aToolName + " -f " + aSystemPath;
90
0
    }
91
0
    else if (eDesktopEnvironment == DesktopType::GNOME)
92
0
    {
93
0
        aPackageName = GnomePackageName;
94
0
        aToolName = GnomeToolName;
95
0
        aSendCommand = aToolName + " " + aSystemPath;
96
0
    }
97
0
    else if (eDesktopEnvironment == DesktopType::Xfce || eDesktopEnvironment == DesktopType::LXQt)
98
0
    {
99
0
        aPackageName = Xfce_Lxqt_PackageName;
100
0
        aToolName = Xfce_Lxqt_ToolName;
101
0
        aSendCommand = aToolName + " " + aSystemPath;
102
0
    }
103
0
    else if (eDesktopEnvironment == DesktopType::MATE)
104
0
    {
105
0
        aPackageName = MatePackageName;
106
0
        aToolName = MateToolName;
107
0
        aSendCommand = aToolName + " " + aSystemPath;
108
0
    }
109
#elif defined(MACOSX)
110
    aToolName = MacToolName;
111
    aSendCommand = "open -a \"" + aToolName + "\" " + aSystemPath;
112
#endif
113
114
0
    OString aRawCommand = OUStringToOString( aSendCommand, RTL_TEXTENCODING_UTF8);
115
116
0
    int status = system(aRawCommand.getStr());
117
0
    if (status == -1 ||
118
0
        !WIFEXITED(status) ||
119
0
        WEXITSTATUS(status) != 0)
120
0
    {
121
0
        eResult = SEND_MAIL_ERROR;
122
0
        OUString errMsg;
123
124
0
#ifdef LINUX
125
0
        if(WIFEXITED(status) && WEXITSTATUS(status) == CommandNotFound)
126
0
        {
127
0
            errMsg = SfxResId(STR_BLUETOOTH_PACKAGE_ERROR_LINUX)
128
0
                                .replaceAll("%TOOL", aToolName)
129
0
                                .replaceAll("%PKG", aPackageName);
130
0
        }
131
#elif defined(MACOSX)
132
        errMsg = SfxResId(STR_BLUETOOTH_ERROR_MACOS).replaceAll("%TOOL", aToolName);
133
#endif
134
135
0
        if(!errMsg.isEmpty())
136
0
        {
137
0
            weld::Window* pWin = SfxGetpApp()->GetTopWindow();
138
0
            std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
139
0
                pWin, VclMessageType::Info, VclButtonsType::Ok, errMsg));
140
0
            xBox->run();
141
0
        }
142
0
    }
143
0
    return eResult;
144
0
#endif
145
0
}
146
147
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */