mirror of
https://github.com/vicr123/theshell.git
synced 2025-01-23 04:11:49 -05:00
New audio engine, new notifications
This commit is contained in:
parent
3e61975a2e
commit
922f7aaeb0
19 changed files with 469 additions and 189 deletions
|
@ -25,13 +25,28 @@ AudioManager::AudioManager(QObject *parent) : QObject(parent)
|
|||
void AudioManager::changeVolume(int volume) {
|
||||
pa_volume_t avgVol = pa_cvolume_avg(&defaultSinkVolume);
|
||||
int onePercent = (PA_VOLUME_NORM - PA_VOLUME_MUTED) / 100;
|
||||
avgVol += onePercent * volume;
|
||||
pa_volume_t newVol = avgVol + (onePercent * volume);
|
||||
if (newVol < PA_VOLUME_MUTED) newVol = PA_VOLUME_MUTED;
|
||||
if (newVol > PA_VOLUME_MAX) newVol = PA_VOLUME_MAX;
|
||||
|
||||
pa_cvolume newVol = defaultSinkVolume;
|
||||
for (int i = 0; i < newVol.channels; i++) {
|
||||
newVol.values[i] = avgVol;
|
||||
if (volume < 0) {
|
||||
if (newVol > avgVol) {
|
||||
newVol = PA_VOLUME_MUTED;
|
||||
}
|
||||
}
|
||||
pa_context_set_sink_volume_by_index(pulseContext, defaultSinkIndex, &newVol, NULL, NULL);
|
||||
if (avgVol < PA_VOLUME_NORM) {
|
||||
if (newVol > PA_VOLUME_NORM) {
|
||||
newVol = PA_VOLUME_NORM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pa_cvolume newCVol = defaultSinkVolume;
|
||||
for (int i = 0; i < newCVol.channels; i++) {
|
||||
newCVol.values[i] = newVol;
|
||||
}
|
||||
pa_context_set_sink_mute_by_index(pulseContext, defaultSinkIndex, false, NULL, NULL);
|
||||
pa_context_set_sink_volume_by_index(pulseContext, defaultSinkIndex, &newCVol, NULL, NULL);
|
||||
}
|
||||
|
||||
void AudioManager::setMasterVolume(int volume) {
|
||||
|
@ -164,24 +179,45 @@ void AudioManager::pulseGetSources(pa_context *c, const pa_source_info *i, int e
|
|||
}
|
||||
|
||||
void AudioManager::quietStreams() {
|
||||
for (int source : originalStreamVolumes.keys()) {
|
||||
//Set volume to 50% of original
|
||||
pa_cvolume originalVolume = originalStreamVolumes.value(source);
|
||||
for (int i = 0; i < originalVolume.channels; i++) {
|
||||
originalVolume.values[i] /= 2;
|
||||
if (pulseAvailable) {
|
||||
for (int source : originalStreamVolumes.keys()) {
|
||||
//Set volume to 50% of original
|
||||
pa_cvolume originalVolume = originalStreamVolumes.value(source);
|
||||
for (int i = 0; i < originalVolume.channels; i++) {
|
||||
originalVolume.values[i] /= 2;
|
||||
}
|
||||
pa_context_set_sink_input_volume(pulseContext, source, &originalVolume, NULL, NULL);
|
||||
}
|
||||
pa_context_set_sink_input_volume(pulseContext, source, &originalVolume, NULL, NULL);
|
||||
quietMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioManager::restoreStreams() {
|
||||
for (int source : originalStreamVolumes.keys()) {
|
||||
//Restore volume of each stream
|
||||
pa_cvolume originalVolume = originalStreamVolumes.value(source);
|
||||
for (int i = 0; i < originalVolume.channels; i++) {
|
||||
originalVolume.values[i] *= 2;
|
||||
}
|
||||
pa_context_set_sink_input_volume(pulseContext, source, &originalVolume, NULL, NULL);
|
||||
if (pulseAvailable) {
|
||||
//Sounds much better if we delay by a second
|
||||
QTimer::singleShot(1000, [=]() {
|
||||
for (int source : originalStreamVolumes.keys()) {
|
||||
//Restore volume of each stream
|
||||
pa_cvolume originalVolume = originalStreamVolumes.value(source);
|
||||
if (originalVolume.channels > 0) {
|
||||
tVariantAnimation* anim = new tVariantAnimation;
|
||||
anim->setStartValue(originalVolume.values[0] / 2);
|
||||
anim->setEndValue(originalVolume.values[0]);
|
||||
anim->setDuration(500);
|
||||
connect(anim, &tVariantAnimation::valueChanged, [=](QVariant value) {
|
||||
pa_cvolume originalVolume = originalStreamVolumes.value(source);
|
||||
for (int i = 0; i < originalVolume.channels; i++) {
|
||||
originalVolume.values[i] = value.toUInt();
|
||||
}
|
||||
pa_context_set_sink_input_volume(pulseContext, source, &originalVolume, NULL, NULL);
|
||||
});
|
||||
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
anim->start();
|
||||
}
|
||||
|
||||
}
|
||||
quietMode = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QMap>
|
||||
#include <QTimer>
|
||||
#include <tvariantanimation.h>
|
||||
#include <pulse/context.h>
|
||||
#include <pulse/glib-mainloop.h>
|
||||
#include <pulse/volume.h>
|
||||
|
|
|
@ -52,6 +52,11 @@ InfoPaneDropdown::InfoPaneDropdown(NotificationDBus* notificationEngine, UPowerD
|
|||
ui->resetButton->setProperty("type", "destructive");
|
||||
ui->upArrow->setPixmap(QIcon::fromTheme("go-up").pixmap(16, 16));
|
||||
|
||||
QPalette powerStretchPalette = ui->PowerStretchSwitch->palette();
|
||||
powerStretchPalette.setColor(QPalette::Highlight, QColor(255, 100, 0));
|
||||
powerStretchPalette.setColor(QPalette::WindowText, Qt::white);
|
||||
ui->PowerStretchSwitch->setPalette(powerStretchPalette);
|
||||
|
||||
//Set up battery chart
|
||||
batteryChart = new QChart();
|
||||
batteryChart->setBackgroundVisible(false);
|
||||
|
@ -237,6 +242,7 @@ InfoPaneDropdown::InfoPaneDropdown(NotificationDBus* notificationEngine, UPowerD
|
|||
ui->settingsList->addItem(new QListWidgetItem(QIcon::fromTheme("emblem-warning"), "Danger"));
|
||||
ui->settingsList->addItem(new QListWidgetItem(QIcon::fromTheme("help-about"), "About"));
|
||||
ui->settingsList->item(ui->settingsList->count() - 1)->setSelected(true);
|
||||
ui->settingsTabs->setCurrentIndex(ui->settingsTabs->count() - 1);
|
||||
|
||||
//Set up timer ringtones
|
||||
ringtone = new QMediaPlayer(this, QMediaPlayer::LowLatency);
|
||||
|
@ -288,15 +294,57 @@ void InfoPaneDropdown::on_WifiSwitch_toggled(bool checked)
|
|||
|
||||
void InfoPaneDropdown::processTimer() {
|
||||
QTime time = QTime::currentTime();
|
||||
if (ui->redshiftPause->isChecked() && time.secsTo(ui->startRedshift->time()) <= 0 && time.secsTo(ui->endRedshift->time()) >= 0) {
|
||||
if (!isRedshiftOn) {
|
||||
{
|
||||
int currentMsecs = time.msecsSinceStartOfDay();
|
||||
int startMsecs = ui->startRedshift->time().msecsSinceStartOfDay();
|
||||
int endMsecs = ui->endRedshift->time().msecsSinceStartOfDay();
|
||||
int endIntensity = ui->redshiftIntensity->value();
|
||||
const int oneHour = 3600000;
|
||||
QProcess* redshiftAdjust = new QProcess;
|
||||
connect(redshiftAdjust, SIGNAL(finished(int)), redshiftAdjust, SLOT(deleteLater()));
|
||||
if (ui->redshiftPause->isChecked()) {
|
||||
//Calculate redshift value
|
||||
//Transition to redshift is 1 hour from the start.
|
||||
|
||||
int intensity;
|
||||
if (startMsecs > endMsecs) { //Start time is later then end time
|
||||
if (currentMsecs < endMsecs || currentMsecs > startMsecs) {
|
||||
intensity = endIntensity;
|
||||
} else if (currentMsecs < startMsecs && currentMsecs > startMsecs - oneHour) {
|
||||
int timeFrom = currentMsecs - (startMsecs - oneHour);
|
||||
float percentage = ((float) timeFrom / (float) oneHour);
|
||||
int progress = (6500 - endIntensity) * percentage;
|
||||
intensity = 6500 - progress;
|
||||
} else if (currentMsecs > endMsecs && currentMsecs < endMsecs + oneHour) {
|
||||
int timeFrom = endMsecs - (currentMsecs - oneHour);
|
||||
float percentage = ((float) timeFrom / (float) oneHour);
|
||||
int progress = (6500 - endIntensity) * percentage;
|
||||
intensity = 6500 - progress;
|
||||
} else {
|
||||
intensity = 6500;
|
||||
}
|
||||
} else { //Start time is earlier then end time
|
||||
if (currentMsecs < endMsecs && currentMsecs > startMsecs) {
|
||||
intensity = endIntensity;
|
||||
} else if (currentMsecs < startMsecs && currentMsecs > startMsecs - oneHour) {
|
||||
int timeFrom = currentMsecs - (startMsecs - oneHour);
|
||||
float percentage = ((float) timeFrom / (float) oneHour);
|
||||
int progress = (6500 - endIntensity) * percentage;
|
||||
intensity = 6500 - progress;
|
||||
} else if (currentMsecs > endMsecs && currentMsecs < endMsecs + oneHour) {
|
||||
int timeFrom = endMsecs - (currentMsecs - oneHour);
|
||||
float percentage = ((float) timeFrom / (float) oneHour);
|
||||
int progress = (6500 - endIntensity) * percentage;
|
||||
intensity = 6500 - progress;
|
||||
} else {
|
||||
intensity = 6500;
|
||||
}
|
||||
}
|
||||
redshiftAdjust->start("redshift -O " + QString::number(intensity));
|
||||
isRedshiftOn = true;
|
||||
QProcess::startDetached("redshift -O " + QString::number(ui->redshiftIntensity->value()));
|
||||
}
|
||||
} else {
|
||||
if (isRedshiftOn) {
|
||||
} else {
|
||||
redshiftAdjust->start("redshift -O 6500");
|
||||
isRedshiftOn = false;
|
||||
QProcess::startDetached("redshift -O 6500");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,7 +461,7 @@ void InfoPaneDropdown::show(dropdownType showWith) {
|
|||
XA_CARDINAL, 32, PropModeReplace, (unsigned char*) &desktop, 1); //Set visible on all desktops
|
||||
|
||||
QDialog::show();
|
||||
|
||||
this->setFocusPolicy(Qt::StrongFocus);
|
||||
this->setFixedWidth(screenGeometry.width());
|
||||
this->setFixedHeight(screenGeometry.height());
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <sys/sysinfo.h>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QTimeEdit>
|
||||
|
||||
class UPowerDBus;
|
||||
|
||||
|
|
|
@ -567,14 +567,14 @@
|
|||
<second>0</second>
|
||||
<year>1969</year>
|
||||
<month>11</month>
|
||||
<day>4</day>
|
||||
<day>1</day>
|
||||
</datetime>
|
||||
</property>
|
||||
<property name="date">
|
||||
<date>
|
||||
<year>1969</year>
|
||||
<month>11</month>
|
||||
<day>4</day>
|
||||
<day>1</day>
|
||||
</date>
|
||||
</property>
|
||||
<property name="displayFormat">
|
||||
|
@ -2133,8 +2133,8 @@
|
|||
<widget class="QTimeEdit" name="endRedshift">
|
||||
<property name="dateTime">
|
||||
<datetime>
|
||||
<hour>23</hour>
|
||||
<minute>59</minute>
|
||||
<hour>6</hour>
|
||||
<minute>0</minute>
|
||||
<second>0</second>
|
||||
<year>2000</year>
|
||||
<month>1</month>
|
||||
|
@ -2146,7 +2146,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<item row="7" column="1">
|
||||
<widget class="QCheckBox" name="sunlightRedshift">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
|
@ -2156,14 +2156,14 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_18">
|
||||
<property name="text">
|
||||
<string>Redshift Intensity</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<item row="8" column="1">
|
||||
<widget class="QSlider" name="redshiftIntensity">
|
||||
<property name="minimum">
|
||||
<number>1000</number>
|
||||
|
@ -2185,7 +2185,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2">
|
||||
<item row="9" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_9">
|
||||
|
@ -2202,6 +2202,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="label_57">
|
||||
<property name="text">
|
||||
<string>If the start time is later than the end time, Redshift will be activated at the end time on the next day.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_3">
|
||||
|
@ -3106,7 +3113,7 @@
|
|||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>theShell 5.2</string>
|
||||
<string>theShell 5.3</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
6
main.cpp
6
main.cpp
|
@ -71,10 +71,10 @@ void QtHandler(QtMsgType type, const QMessageLogContext &context, const QString
|
|||
case QtInfoMsg:
|
||||
case QtWarningMsg:
|
||||
case QtCriticalMsg:
|
||||
std::cout << msg.toStdString() + "\n";
|
||||
std::cerr << msg.toStdString() + "\n";
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
std::cout << msg.toStdString() + "\n";
|
||||
std::cerr << msg.toStdString() + "\n";
|
||||
raise_signal(msg);
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ int main(int argc, char *argv[])
|
|||
signal(SIGABRT, *catch_signal); //Catch SIGABRT
|
||||
signal(SIGILL, *catch_signal); //Catch SIGILL
|
||||
|
||||
//qInstallMessageHandler(QtHandler);
|
||||
qInstallMessageHandler(QtHandler);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
|
|
|
@ -56,16 +56,15 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
UPowerDBus* updbus = new UPowerDBus(ndbus, this);
|
||||
connect(updbus, &UPowerDBus::updateDisplay, [=](QString display) {
|
||||
ui->batteryLabel->setText(display);
|
||||
if (updbus->hasBattery()) {
|
||||
ui->batteryFrame->setVisible(true);
|
||||
ui->batteryLabel->setText(display);
|
||||
} else {
|
||||
ui->batteryFrame->setVisible(false);
|
||||
}
|
||||
});
|
||||
updbus->DeviceChanged();
|
||||
|
||||
if (updbus->hasBattery()) {
|
||||
ui->batteryFrame->setVisible(true);
|
||||
} else {
|
||||
ui->batteryFrame->setVisible(false);
|
||||
}
|
||||
|
||||
DBusEvents = new DbusEvents(ndbus);
|
||||
|
||||
infoPane = new InfoPaneDropdown(ndbus, updbus);
|
||||
|
@ -420,7 +419,7 @@ void MainWindow::doUpdate() {
|
|||
}
|
||||
}
|
||||
|
||||
delete[] atoms;
|
||||
XFree(atoms);
|
||||
}
|
||||
|
||||
if (!skipTaskbar) {
|
||||
|
|
|
@ -594,6 +594,12 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="desktopsFrame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
|
|
|
@ -120,7 +120,9 @@ bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *mes
|
|||
Hotkeys->show(QIcon::fromTheme("video-display"), "Brightness", (int) currentBrightness);
|
||||
} else if (button->detail == XKeysymToKeycode(QX11Info::display(), XF86XK_AudioRaiseVolume)) { //Increase Volume by 5%
|
||||
volume = volume + 5;
|
||||
if (volume > 100) volume = 100;
|
||||
if (volume - 5 < 100 && volume > 100) {
|
||||
volume = 100;
|
||||
}
|
||||
AudioMan->changeVolume(5);
|
||||
|
||||
QSoundEffect* volumeSound = new QSoundEffect();
|
||||
|
|
|
@ -80,7 +80,7 @@ uint NotificationDBus::Notify(QString app_name, uint replaces_id,
|
|||
}
|
||||
|
||||
|
||||
NotificationDialog *d = new NotificationDialog(summary, body, actions, replaces_id, hints, expire_timeout, type);
|
||||
NotificationDialog *d = new NotificationDialog(app_name, summary, body, actions, replaces_id, hints, expire_timeout, type);
|
||||
d->dbusParent = this;
|
||||
|
||||
connect(d, SIGNAL(closing(int, int)), this, SLOT(sendCloseNotification(int, int)));
|
||||
|
@ -131,7 +131,7 @@ uint NotificationDBus::Notify(QString app_name, uint replaces_id,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
dialogs.at(replaces_id - 1)->setParams(summary, body);
|
||||
dialogs.at(replaces_id - 1)->setParams(app_name, summary, body);
|
||||
dialogs.at(replaces_id - 1)->show();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
extern QIcon getIconFromTheme(QString name, QColor textColor);
|
||||
|
||||
NotificationDialog::NotificationDialog(QString title, QString body, QStringList actions, int id, QVariantMap hints, int timeout, notificationType type, QWidget *parent) :
|
||||
NotificationDialog::NotificationDialog(QString appName, QString title, QString body, QStringList actions, int id, QVariantMap hints, int timeout, notificationType type, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NotificationDialog)
|
||||
{
|
||||
|
@ -12,7 +12,6 @@ NotificationDialog::NotificationDialog(QString title, QString body, QStringList
|
|||
this->hints = hints;
|
||||
this->setAttribute(Qt::WA_X11NetWmWindowTypeNotification, true);
|
||||
|
||||
|
||||
/*QBrush background = this->palette().background();
|
||||
QPalette pal = this->palette();
|
||||
pal.setBrush(QPalette::Background, pal.foreground());
|
||||
|
@ -23,7 +22,7 @@ NotificationDialog::NotificationDialog(QString title, QString body, QStringList
|
|||
//pal().foreground().setColor(background);
|
||||
this->setPalette(pal);*/
|
||||
|
||||
|
||||
ui->appName->setText(appName);
|
||||
switch (type) {
|
||||
case normalType:
|
||||
ui->notificationType->setCurrentIndex(0);
|
||||
|
@ -64,48 +63,98 @@ NotificationDialog::NotificationDialog(QString title, QString body, QStringList
|
|||
|
||||
QColor color = this->palette().color(QPalette::Window);
|
||||
|
||||
QIcon appIcon;
|
||||
bool foundAppIcon = false;
|
||||
QString filename = hints.value("desktop-entry", "").toString() + ".desktop";
|
||||
|
||||
QDir appFolder("/usr/share/applications/");
|
||||
QDirIterator* iterator = new QDirIterator(appFolder, QDirIterator::Subdirectories);
|
||||
|
||||
while (iterator->hasNext()) {
|
||||
iterator->next();
|
||||
QFileInfo info = iterator->fileInfo();
|
||||
if (info.fileName() == filename || info.baseName().toLower() == appName.toLower()) {
|
||||
QFile file(info.filePath());
|
||||
file.open(QFile::ReadOnly);
|
||||
QString appinfo(file.readAll());
|
||||
|
||||
QStringList desktopLines;
|
||||
QString currentDesktopLine;
|
||||
for (QString desktopLine : appinfo.split("\n")) {
|
||||
if (desktopLine.startsWith("[") && currentDesktopLine != "") {
|
||||
desktopLines.append(currentDesktopLine);
|
||||
currentDesktopLine = "";
|
||||
}
|
||||
currentDesktopLine.append(desktopLine + "\n");
|
||||
}
|
||||
desktopLines.append(currentDesktopLine);
|
||||
|
||||
for (QString desktopPart : desktopLines) {
|
||||
for (QString line : desktopPart.split("\n")) {
|
||||
if (line.startsWith("icon=", Qt::CaseInsensitive)) {
|
||||
QString iconname = line.split("=")[1];
|
||||
if (QFile(iconname).exists()) {
|
||||
appIcon = QIcon(iconname);
|
||||
} else {
|
||||
appIcon = QIcon::fromTheme(iconname, QIcon::fromTheme("application-x-executable"));
|
||||
}
|
||||
foundAppIcon = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete iterator;
|
||||
|
||||
if (foundAppIcon) {
|
||||
ui->appIcon->setPixmap(appIcon.pixmap(16, 16));
|
||||
} else {
|
||||
ui->appIcon->setVisible(false);
|
||||
}
|
||||
|
||||
// Don't forget to add extra categories to the notificationdbus class too!
|
||||
|
||||
QSize iconSize(24, 24);
|
||||
if (hints.keys().contains("category")) {
|
||||
QString category = hints.value("category").toString();
|
||||
if (category == "network.connected") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("network-connect").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("network-connect").pixmap(iconSize));
|
||||
} else if (category == "network.disconnected") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("network-disconnect").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("network-disconnect").pixmap(iconSize));
|
||||
} else if (category == "email.arrived") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("mail-receive").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("mail-receive").pixmap(iconSize));
|
||||
} else if (category == "battery.charging") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-charging.svg", color).pixmap(24, 24));
|
||||
ui->label->setPixmap(getIconFromTheme("battery-charging.svg", color).pixmap(iconSize));
|
||||
} else if (category == "battery.charged") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-charged.svg", color).pixmap(24, 24));
|
||||
ui->label->setPixmap(getIconFromTheme("battery-charged.svg", color).pixmap(iconSize));
|
||||
} else if (category == "battery.discharging") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-not-charging.svg", color).pixmap(24, 24));
|
||||
ui->label->setPixmap(getIconFromTheme("battery-not-charging.svg", color).pixmap(iconSize));
|
||||
} else if (category == "battery.low") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-low.svg", color).pixmap(24, 24));
|
||||
ui->label->setPixmap(getIconFromTheme("battery-low.svg", color).pixmap(iconSize));
|
||||
} else if (category == "battery.critical") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-critical.svg", color).pixmap(24, 24));
|
||||
ui->label->setPixmap(getIconFromTheme("battery-critical.svg", color).pixmap(iconSize));
|
||||
} else if (category == "device.added") {
|
||||
ui->label->setPixmap(getIconFromTheme("connect.svg", color).pixmap(24, 24));
|
||||
ui->label->setPixmap(getIconFromTheme("connect.svg", color).pixmap(iconSize));
|
||||
} else if (category == "device.removed") {
|
||||
ui->label->setPixmap(getIconFromTheme("disconnect.svg", color).pixmap(24, 24));
|
||||
ui->label->setPixmap(getIconFromTheme("disconnect.svg", color).pixmap(iconSize));
|
||||
} else if (category == "call.incoming") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("call-start").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("call-start").pixmap(iconSize));
|
||||
} else {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(iconSize));
|
||||
}
|
||||
} else {
|
||||
if (hints.keys().contains("urgency")) {
|
||||
QChar urgency = hints.value("urgency").toChar();
|
||||
if (urgency == 0) {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-information").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-information").pixmap(iconSize));
|
||||
} else if (urgency == 1) {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(iconSize));
|
||||
} else if (urgency == 2) {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-error").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-error").pixmap(iconSize));
|
||||
}
|
||||
} else {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(iconSize));
|
||||
}
|
||||
}
|
||||
if (timeout == -1) { //Timeout default
|
||||
|
@ -117,7 +166,8 @@ NotificationDialog::NotificationDialog(QString title, QString body, QStringList
|
|||
}
|
||||
}
|
||||
|
||||
void NotificationDialog::setParams(QString title, QString body) {
|
||||
void NotificationDialog::setParams(QString appName, QString title, QString body) {
|
||||
ui->appName->setText(appName);
|
||||
ui->title->setText(title);
|
||||
ui->body->setText(body);
|
||||
}
|
||||
|
|
|
@ -28,13 +28,13 @@ public:
|
|||
callType,
|
||||
};
|
||||
|
||||
explicit NotificationDialog(QString title, QString body, QStringList actions, int id, QVariantMap hints, int timeout, notificationType type = normalType, QWidget *parent = 0);
|
||||
explicit NotificationDialog(QString appName, QString title, QString body, QStringList actions, int id, QVariantMap hints, int timeout, notificationType type = normalType, QWidget *parent = 0);
|
||||
~NotificationDialog();
|
||||
|
||||
void show();
|
||||
void close(int reason);
|
||||
|
||||
void setParams(QString title, QString body);
|
||||
void setParams(QString appName, QString title, QString body);
|
||||
void setGeometry(int x, int y, int w, int h);
|
||||
void setGeometry(QRect geometry);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>786</width>
|
||||
<height>90</height>
|
||||
<height>105</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -17,138 +17,195 @@
|
|||
<iconset theme="theshell" resource="resources.qrc">
|
||||
<normaloff>:/icons/icon.svg</normaloff>:/icons/icon.svg</iconset>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Icon</string>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Icon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="title">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>System</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="notificationType">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="body">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Your battery is running low. You might want to plug in your PC.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="title1">
|
||||
<property name="text">
|
||||
<string>Summary</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="body1">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>30</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Body</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="actionsLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="window-close">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="notificationType">
|
||||
<property name="currentIndex">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Notification from</string>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="appIcon">
|
||||
<property name="text">
|
||||
<string>appIcon</string>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="appName">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
<property name="text">
|
||||
<string>Application Name</string>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="title">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>System</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="body">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Your battery is running low. You might want to plug in your PC.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="title1">
|
||||
<property name="text">
|
||||
<string>Summary</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="body1">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>30</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Body</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="actionsLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="window-close">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
"- Added icon in bar for wireless reception\n"\
|
||||
"- theShell now uses the-libs for integration with other the-applications.\n"\
|
||||
"- Dragging down on an item in the bar to open the status center has been added\n"\
|
||||
"- New notification animation\n"\
|
||||
"- When a timer elapses, other audio is made quiter until the timer is dismissed\n"\
|
||||
"- Redshift now works overnight\n"\
|
||||
"\n"\
|
||||
"New in theShell 5.2: \n"\
|
||||
"- New Onboarding experience. Every time theShell updates, you'll get a changelog.\n" \
|
||||
|
|
BIN
powerlow.wav
Normal file
BIN
powerlow.wav
Normal file
Binary file not shown.
|
@ -10,6 +10,7 @@
|
|||
<file>media-remove.wav</file>
|
||||
<file>media-insert.wav</file>
|
||||
<file>screenshot.wav</file>
|
||||
<file>powerlow.wav</file>
|
||||
</qresource>
|
||||
<qresource prefix="/icons/dark">
|
||||
<file>images/dark/flight.svg</file>
|
||||
|
|
|
@ -104,12 +104,58 @@ void screenshotWindow::on_copyButton_clicked()
|
|||
{
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
clipboard->setPixmap(screenshotPixmap);
|
||||
this->close();
|
||||
|
||||
QRect newGeometry = ui->label->geometry();
|
||||
newGeometry.moveTop(-this->height() / 2);
|
||||
|
||||
QParallelAnimationGroup* animGroup = new QParallelAnimationGroup();
|
||||
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(ui->label, "geometry");
|
||||
anim->setStartValue(ui->label->geometry());
|
||||
anim->setEndValue(newGeometry);
|
||||
anim->setDuration(500);
|
||||
anim->setEasingCurve(QEasingCurve::InQuint);
|
||||
animGroup->addAnimation(anim);
|
||||
|
||||
QPropertyAnimation* closeAnim = new QPropertyAnimation(this, "windowOpacity");
|
||||
closeAnim->setStartValue(1);
|
||||
closeAnim->setEndValue(0);
|
||||
closeAnim->setDuration(500);
|
||||
closeAnim->setEasingCurve(QEasingCurve::InQuint);
|
||||
animGroup->addAnimation(closeAnim);
|
||||
|
||||
connect(animGroup, SIGNAL(finished()), animGroup, SLOT(deleteLater()));
|
||||
connect(animGroup, SIGNAL(finished()), this, SLOT(close()));
|
||||
animGroup->start();
|
||||
}
|
||||
|
||||
void screenshotWindow::on_saveButton_clicked()
|
||||
{
|
||||
QFile screenshotFile(QDir::homePath() + "/screenshot" + QDateTime::currentDateTime().toString("hh-mm-ss-yyyy-MM-dd") + ".png");
|
||||
screenshotPixmap.save(&screenshotFile, "PNG");
|
||||
|
||||
QRect newGeometry = ui->label->geometry();
|
||||
newGeometry.moveTop(-this->height() / 2);
|
||||
|
||||
QParallelAnimationGroup* animGroup = new QParallelAnimationGroup();
|
||||
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(ui->label, "geometry");
|
||||
anim->setStartValue(ui->label->geometry());
|
||||
anim->setEndValue(newGeometry);
|
||||
anim->setDuration(500);
|
||||
anim->setEasingCurve(QEasingCurve::InQuint);
|
||||
animGroup->addAnimation(anim);
|
||||
|
||||
QPropertyAnimation* closeAnim = new QPropertyAnimation(this, "windowOpacity");
|
||||
closeAnim->setStartValue(1);
|
||||
closeAnim->setEndValue(0);
|
||||
closeAnim->setDuration(500);
|
||||
closeAnim->setEasingCurve(QEasingCurve::InQuint);
|
||||
animGroup->addAnimation(closeAnim);
|
||||
|
||||
connect(animGroup, SIGNAL(finished()), animGroup, SLOT(deleteLater()));
|
||||
connect(animGroup, SIGNAL(finished()), this, SLOT(close()));
|
||||
animGroup->start();
|
||||
}
|
||||
|
||||
void screenshotWindow::close() {
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
#include <QSoundEffect>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QGraphicsOpacityEffect>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace Ui {
|
||||
class screenshotWindow;
|
||||
|
|
|
@ -49,11 +49,7 @@ void UPowerDBus::devicesChanged() {
|
|||
batteryPath = device;
|
||||
}
|
||||
}
|
||||
if (allDevices.length() == 0) {
|
||||
hasBat = false;
|
||||
} else {
|
||||
hasBat = true;
|
||||
}
|
||||
DeviceChanged();
|
||||
} else {
|
||||
emit updateDisplay("Can't get battery information.");
|
||||
}
|
||||
|
@ -171,7 +167,11 @@ void UPowerDBus::DeviceChanged() {
|
|||
tenMinuteBatteryWarning = true;
|
||||
halfHourBatteryWarning = true;
|
||||
hourBatteryWarning = true;
|
||||
showRed = true;
|
||||
|
||||
QSoundEffect* chargingSound = new QSoundEffect();
|
||||
chargingSound->setSource(QUrl("qrc:/sounds/powerlow.wav"));
|
||||
chargingSound->play();
|
||||
connect(chargingSound, SIGNAL(playingChanged()), chargingSound, SLOT(deleteLater()));
|
||||
} else if (timeToEmpty <= 1800 && halfHourBatteryWarning == false) { //Half hour left! Low!
|
||||
QVariantMap hints;
|
||||
hints.insert("urgency", 2);
|
||||
|
@ -189,7 +189,11 @@ void UPowerDBus::DeviceChanged() {
|
|||
|
||||
halfHourBatteryWarning = true;
|
||||
hourBatteryWarning = true;
|
||||
showRed = true;
|
||||
|
||||
QSoundEffect* chargingSound = new QSoundEffect();
|
||||
chargingSound->setSource(QUrl("qrc:/sounds/powerlow.wav"));
|
||||
chargingSound->play();
|
||||
connect(chargingSound, SIGNAL(playingChanged()), chargingSound, SLOT(deleteLater()));
|
||||
} else if (timeToEmpty <= 3600 && hourBatteryWarning == false) { //One hour left! Warning!
|
||||
QVariantMap hints;
|
||||
hints.insert("urgency", 2);
|
||||
|
@ -204,6 +208,15 @@ void UPowerDBus::DeviceChanged() {
|
|||
"You have about an hour of battery remaining."
|
||||
" You may want to plug in your PC now.", actions, hints, 10000);
|
||||
hourBatteryWarning = true;
|
||||
|
||||
QSoundEffect* chargingSound = new QSoundEffect();
|
||||
chargingSound->setSource(QUrl("qrc:/sounds/powerlow.wav"));
|
||||
chargingSound->play();
|
||||
connect(chargingSound, SIGNAL(playingChanged()), chargingSound, SLOT(deleteLater()));
|
||||
}
|
||||
|
||||
if (halfHourBatteryWarning || tenMinuteBatteryWarning) {
|
||||
showRed = true;
|
||||
}
|
||||
} else {
|
||||
timeRemain = QDateTime(QDate(0, 0, 0));
|
||||
|
@ -325,7 +338,13 @@ void UPowerDBus::DeviceChanged() {
|
|||
}
|
||||
}
|
||||
|
||||
emit updateDisplay(displayOutput.join(" · "));
|
||||
if (displayOutput.count() == 0) {
|
||||
hasBat = false;
|
||||
emit updateDisplay("");
|
||||
} else {
|
||||
hasBat = true;
|
||||
emit updateDisplay(displayOutput.join(" · "));
|
||||
}
|
||||
}
|
||||
|
||||
bool UPowerDBus::hasBattery() {
|
||||
|
|
Loading…
Reference in a new issue