Ticket #9265: bluetoothUI.patch

File bluetoothUI.patch, 8.7 KB (added by TriEdgeAI, 8 years ago)
  • new file headers/private/bluetooth/BluetoothIconView.h

    diff --git a/headers/private/bluetooth/BluetoothIconView.h b/headers/private/bluetooth/BluetoothIconView.h
    new file mode 100644
    index 0000000..d8a266f
    - +  
     1/*
     2 * Copyright 2012, Haiku, Inc.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Tri-Edge AI <triedgeai@gmail.com>
     7 */
     8
     9#ifndef _BLUETOOTH_ICON_VIEW_H_
     10#define _BLUETOOTH_ICON_VIEW_H_
     11
     12#include <View.h>
     13#include <Bitmap.h>
     14#include <MimeType.h>
     15#include <IconUtils.h>
     16
     17namespace Bluetooth
     18{
     19
     20class BluetoothIconView : public BView
     21{
     22public:
     23                        BluetoothIconView();
     24    void                Draw(BRect rect);
     25   
     26private:
     27    BBitmap*            bitmap;
     28};
     29
     30}
     31
     32#endif /* _BLUETOOTH_ICON_VIEW_H_ */
  • headers/private/bluetooth/ConnectionIncoming.h

    diff --git a/headers/private/bluetooth/ConnectionIncoming.h b/headers/private/bluetooth/ConnectionIncoming.h
    index f8292f8..1ce2d44 100644
    a b  
    1 /*
     1/* 
    22 * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
    3  *
     3 * 
    44 * All rights reserved. Distributed under the terms of the MIT License.
    5  *
    6  */
     5 * 
     6 */ 
    77
    88#ifndef _CONNECTION_INCOMING_H_
    99#define _CONNECTION_INCOMING_H_
    1010
    11 
    12 //----------------------- Global includes  ----------------------
    1311#include <AppKit.h>
    1412#include <SupportKit.h>
    1513#include <InterfaceKit.h>
     14
     15#include <ConnectionView.h>
     16#include <bluetooth/RemoteDevice.h>
     17
    1618#include <iostream>
    1719#include <stdio.h>
    1820#include <stdlib.h>
    1921
    20 namespace Bluetooth {
    21 
    22 class RemoteDevice;
    23 
    24 class ConnectionView
    25         : public BView
     22namespace Bluetooth
    2623{
    27 public:
    28                         ConnectionView(BRect frame, const char *name);
    29                         ~ConnectionView();
    30     virtual void        MessageReceived(BMessage *message);
    31     void                Draw(BRect update);
    32     void                Pulse();
    33 
    34 private:
    35 
    36 
    37 };
    3824
     25class RemoteDevice;
     26class ConnectionView;
    3927
    4028class ConnectionIncoming : public BWindow
    4129{
    4230public:
    4331                        ConnectionIncoming(RemoteDevice* rDevice);
    4432                        ~ConnectionIncoming();
    45     virtual void        MessageReceived(BMessage *message);
     33                       
     34    virtual void        MessageReceived(BMessage* message);
    4635    virtual bool        QuitRequested();
    4736
    4837private:
    49     ConnectionView*             _ConnectionView;
     38    ConnectionView*     view;
    5039};
    5140
    5241}
    private:  
    5544using Bluetooth::ConnectionIncoming;
    5645#endif
    5746
    58 
    59 #endif
     47#endif /* _CONNECTION_INCOMING_H_ */
  • new file headers/private/bluetooth/ConnectionView.h

    diff --git a/headers/private/bluetooth/ConnectionView.h b/headers/private/bluetooth/ConnectionView.h
    new file mode 100644
    index 0000000..4d338f1
    - +  
     1/*
     2 * Copyright 2012, Haiku, Inc.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Tri-Edge AI <triedgeai@gmail.com>
     7 */
     8 
     9#ifndef _CONNECTION_VIEW_H_
     10#define _CONNECTION_VIEW_H_
     11 
     12#include <Window.h>
     13#include <View.h>
     14#include <StringView.h>
     15#include <GroupLayout.h>
     16#include <GroupLayoutBuilder.h>
     17#include <Font.h>
     18#include <String.h>
     19 
     20namespace Bluetooth
     21{
     22
     23class ConnectionView : public BView
     24{
     25public:
     26                        ConnectionView::ConnectionView(BRect frame,
     27                            BString device);
     28    void                Pulse();
     29private:
     30    BString             strMessage;
     31    BStringView*        vMessage;
     32};
     33
     34}
     35
     36#endif /* _CONNECTION_VIEW_H_ */
  • new file src/kits/bluetooth/UI/BluetoothIconView.cpp

    diff --git a/src/kits/bluetooth/UI/BluetoothIconView.cpp b/src/kits/bluetooth/UI/BluetoothIconView.cpp
    new file mode 100644
    index 0000000..2e3d882
    - +  
     1/*
     2 * Copyright 2012, Haiku, Inc.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Tri-Edge AI <triedgeai@gmail.com>
     7 */
     8
     9#include <BluetoothIconView.h>
     10
     11namespace Bluetooth
     12{
     13   
     14BluetoothIconView::BluetoothIconView()
     15    :
     16    BView(BRect(0, 0, 80, 80), "", B_FOLLOW_ALL, B_WILL_DRAW)
     17{
     18    bitmap = new BBitmap(BRect(0, 0, 64, 64), 0, B_RGBA32);
     19   
     20    uint8* ticon;
     21    size_t tsize;
     22   
     23    BMimeType mime("application/x-vnd.Haiku-bluetooth_server");
     24    mime.GetIcon(&ticon, &tsize);
     25   
     26    BIconUtils::GetVectorIcon(ticon, tsize, bitmap);
     27   
     28    SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     29    SetDrawingMode(B_OP_ALPHA);
     30    SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
     31}
     32
     33
     34void
     35BluetoothIconView::Draw(BRect rect)
     36{
     37    this->DrawBitmap(bitmap);
     38}
     39
     40}
  • src/kits/bluetooth/UI/ConnectionIncoming.cpp

    diff --git a/src/kits/bluetooth/UI/ConnectionIncoming.cpp b/src/kits/bluetooth/UI/ConnectionIncoming.cpp
    index 1aced3a..17c05d2 100644
    a b  
    1 /*
     1/* 
    22 * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
    3  *
     3 * 
    44 * All rights reserved. Distributed under the terms of the MIT License.
    5  *
    6  */
     5 * 
     6 */ 
    77
    88#include <ConnectionIncoming.h>
     9#include <ConnectionView.h>
    910
    10 #define B_PULSES_BY_SECOND(x) (2*x)
    11 
    12 namespace Bluetooth {
    13 
    14 ConnectionView::ConnectionView(BRect frame, const char *name): BView(BRect(0, 0, 400, 400), "MyViewName",
    15                                                                     B_FOLLOW_LEFT | B_FOLLOW_TOP,
    16                                                                     B_WILL_DRAW | B_PULSE_NEEDED)
     11namespace Bluetooth
    1712{
    1813
    19     SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    20 
    21 }
    22 
    23 ConnectionView::~ConnectionView()
    24 {
    25 
    26 }
    27 
    28 
    29 void ConnectionView::MessageReceived(BMessage *message)
    30 {
    31     switch(message->what)
    32     {
    33     default:
     14ConnectionIncoming::ConnectionIncoming(RemoteDevice* rDevice)
     15            :
     16            BWindow(BRect(600, 100, 1000, 180), "Incoming connection",
     17                B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
     18                B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
     19                    // 400x80
     20{
     21    SetPulseRate(1 * 1000 * 1000);
     22        // 1 second
    3423   
    35     break;
    36     }
    37 }
    38 
    39 
    40 void ConnectionView::Draw(BRect update)
    41 {
    42 
    43 }
    44 
    45 
    46 void ConnectionView::Pulse()
    47 {
    48     static int a = 0;
     24    if (rDevice != NULL)
     25        view = new ConnectionView(BRect(0, 0, 400, 80), rDevice->GetFriendlyName());
     26    else
     27        view = new ConnectionView(BRect(0, 0, 400, 80), "<unknown_device>");
    4928   
    50     if (a++ == B_PULSES_BY_SECOND(5)) {
    51         // BUG: for some reason the window is not being removed...
    52         Window()->PostMessage(B_QUIT_REQUESTED);
    53         Window()->Quit();
    54     }
    55 }
    56 
    57 
    58 
    59 //---------------------------------------------------------------
    60 ConnectionIncoming::ConnectionIncoming(RemoteDevice* rDevice)
    61              : BWindow(BRect(700, 100, 900, 150), "Connection completed",
    62                                    B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
    63                                    B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
    64 {
    65     _ConnectionView = new ConnectionView(BRect(0, 0, 400, 400),"mViewName");
    66 
    67     AddChild(_ConnectionView);
     29    AddChild(view);
    6830}
    6931
    7032
    7133ConnectionIncoming::~ConnectionIncoming()
    7234{
    73 
     35   
    7436}
    7537
    7638
    77 void ConnectionIncoming::MessageReceived(BMessage *message)
     39void
     40ConnectionIncoming::MessageReceived(BMessage* message)
    7841{
    79     switch(message->what)
     42    switch (message->what)
    8043    {
    8144    default:
    8245   
    void ConnectionIncoming::MessageReceived(BMessage *message)  
    8548}
    8649
    8750
    88 bool ConnectionIncoming::QuitRequested()
     51bool
     52ConnectionIncoming::QuitRequested()
    8953{
    9054    return BWindow::QuitRequested();
    9155}
  • new file src/kits/bluetooth/UI/ConnectionView.cpp

    diff --git a/src/kits/bluetooth/UI/ConnectionView.cpp b/src/kits/bluetooth/UI/ConnectionView.cpp
    new file mode 100644
    index 0000000..05fcfed
    - +  
     1/*
     2 * Copyright 2012, Haiku, Inc.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Tri-Edge AI <triedgeai@gmail.com>
     7 */
     8
     9#include <ConnectionView.h>
     10#include <BluetoothIconView.h>
     11
     12namespace Bluetooth
     13{
     14   
     15ConnectionView::ConnectionView(BRect frame, BString device)
     16    :
     17    BView(frame, "ConnectionView", 0, B_PULSE_NEEDED)
     18{
     19    BFont font;
     20   
     21    font.SetFace(B_BOLD_FACE);
     22   
     23    SetLayout(new BGroupLayout(B_HORIZONTAL));
     24    SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     25   
     26    BluetoothIconView* vIcon = new BluetoothIconView();
     27   
     28    strMessage = "A new connection is incoming..";
     29   
     30    vMessage = new BStringView(frame, "",
     31                                    strMessage,
     32                                    B_FOLLOW_LEFT);
     33                                   
     34    vMessage->SetAlignment(B_ALIGN_LEFT);
     35                                                       
     36    BStringView* vDevice = new BStringView(frame, "",
     37                                    "Remote Device: ", B_FOLLOW_LEFT);
     38   
     39    vDevice->SetFont(&font, B_FONT_FACE);
     40   
     41    BStringView* vDeviceText = new BStringView(frame, "",
     42                                    device, B_FOLLOW_RIGHT);
     43   
     44    AddChild(BGroupLayoutBuilder(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
     45            .Add(BGroupLayoutBuilder(B_VERTICAL, 0)
     46                .Add(vIcon)
     47                .SetInsets(8, 8, 8, 8)
     48            )
     49            .Add(BGroupLayoutBuilder(B_VERTICAL, B_USE_DEFAULT_SPACING)
     50                .AddGlue()
     51                .Add(vMessage)
     52                .Add(BGroupLayoutBuilder(B_HORIZONTAL, 0)
     53                    .Add(vDevice)
     54                    .Add(vDeviceText)
     55                )
     56                .AddGlue(3.0f)
     57            )
     58            .AddGlue()
     59    );
     60}
     61
     62
     63void
     64ConnectionView::Pulse()
     65{
     66    static int pulses = 0;
     67   
     68    pulses++;
     69   
     70    if (pulses >= 5) {
     71        Window()->PostMessage(B_QUIT_REQUESTED);
     72    } else {
     73        strMessage += ".";
     74        vMessage->SetText(strMessage);
     75    }
     76}
     77
     78}
     79