summaryrefslogtreecommitdiffstats
path: root/src/SampleWindow.cc
blob: d30f10fec3b31ea27f45a573942268cad242edaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* $Id$ */

/***
  This file is part of paman.
 
  paman is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.
 
  paman 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 Lesser General Public License
  along with paman; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA.
***/

#include <iostream>

#include "paman.hh"
#include "SampleWindow.hh"

#define GLADE_NAME "sampleWindow"

SampleWindow::SampleWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade) :
    Gtk::Window(cobject),
    nameLabel(NULL),
    indexLabel(NULL),
    volumeLabel(NULL),
    sampleTypeLabel(NULL),
    durationLabel(NULL),
    sizeLabel(NULL),
    lazyLabel(NULL),
    filenameLabel(NULL),
    closeButton(NULL) {

    refGlade->get_widget("nameLabel", nameLabel);
    refGlade->get_widget("indexLabel", indexLabel);
    refGlade->get_widget("volumeLabel", volumeLabel);
    refGlade->get_widget("sampleTypeLabel", sampleTypeLabel);
    refGlade->get_widget("durationLabel", durationLabel);
    refGlade->get_widget("sizeLabel", sizeLabel);
    refGlade->get_widget("lazyLabel", lazyLabel);
    refGlade->get_widget("filenameLabel", filenameLabel);
    refGlade->get_widget("closeButton", closeButton);

    closeButton->signal_clicked().connect(sigc::mem_fun(*this, &SampleWindow::onCloseButton));
}

SampleWindow* SampleWindow::create() {
    SampleWindow *w = NULL;
    Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(GLADE_FILE, GLADE_NAME);
    refXml->get_widget_derived(GLADE_NAME, w);
    return w;
}

void SampleWindow::updateInfo(const SampleInfo &i) {
    char t[60], ss[PA_SAMPLE_SPEC_SNPRINT_MAX];

    nameLabel->set_text(i.name);
    snprintf(t, sizeof(t), "#%u", i.index);
    indexLabel->set_text(t);

    snprintf(t, sizeof(t), "%0.0f%%", (double) pa_sw_volume_to_linear(pa_cvolume_avg(&i.volume)) * 100);
    volumeLabel->set_text(t);

    if (i.bytes > 0) {

        pa_sample_spec_snprint(ss, sizeof(ss), &i.sample_spec);
        sampleTypeLabel->set_text(ss);

        snprintf(t, sizeof(t), "%0.1fs", (double) i.duration/1000000);
        durationLabel->set_text(t);

        pa_bytes_snprint(t, sizeof(t), i.bytes);
        sizeLabel->set_text(t);
    } else {
        sampleTypeLabel->set_markup("<i>n/a</i>");
        durationLabel->set_markup("<i>n/a</i>");
        sizeLabel->set_markup("<i>n/a</i>");
    }

    lazyLabel->set_text(i.lazy ? "yes" : "no");

    if (i.filename_valid)
        filenameLabel->set_text(i.filename);
    else
        filenameLabel->set_markup("<i>n/a</i>");
    
    set_title("Sample: "+i.name);
}

void SampleWindow::onCloseButton() {
    hide();
}

bool SampleWindow::on_delete_event(GdkEventAny*) {
    hide();
    return false;
}