aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libLumina/LuminaOS-DragonFly.cpp119
-rw-r--r--lumina-fm/MainUI.cpp8
-rw-r--r--lumina-fm/widgets/DDListWidgets.h18
-rw-r--r--lumina-fm/widgets/DirWidget.cpp12
-rw-r--r--lumina-fm/widgets/DirWidget.h2
5 files changed, 120 insertions, 39 deletions
diff --git a/libLumina/LuminaOS-DragonFly.cpp b/libLumina/LuminaOS-DragonFly.cpp
index d1a5f6c0..e44db402 100644
--- a/libLumina/LuminaOS-DragonFly.cpp
+++ b/libLumina/LuminaOS-DragonFly.cpp
@@ -7,11 +7,61 @@
#ifdef __DragonFly__
#include "LuminaOS.h"
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/sensors.h>
//can't read xbrightness settings - assume invalid until set
static int screenbrightness = -1;
static int audiovolume = -1;
-static int ncpu = -1;
+
+static bool get_sysctlbyname_int(const char *name, int *res) {
+ int r = 0;
+ size_t len = sizeof(r);
+ if (sysctlbyname(name, &r, &len, NULL, 0) == 0) {
+ *res = r;
+ return true;
+ }
+ return false;
+}
+
+#if 0
+static bool get_sysctlbyname_qstr(const char *name, QString &str) {
+ size_t len = 0;
+ sysctlbyname(name, NULL, &len, NULL, 0);
+ if (len > 0) {
+ void *buf = malloc(len);
+ if (buf) {
+ int res = sysctlbyname(name, buf, &len, NULL, 0);
+ if (res == 0) {
+ str = QString((char*) buf);
+ }
+ free(buf);
+ return (res == 0);
+ }
+ }
+ return false;
+}
+#endif
+
+// returns -1 on error.
+static int get_sysctlbyname_int(const char *name) {
+ int res = -1;
+ if (get_sysctlbyname_int(name, &res)) {
+ return res;
+ }
+ return -1;
+}
+
+static bool get_sysctlbyname_uint(const char *name, unsigned int *res) {
+ unsigned int r = 0;
+ size_t len = sizeof(r);
+ if (sysctlbyname(name, &r, &len, NULL, 0) == 0) {
+ *res = r;
+ return true;
+ }
+ return false;
+}
QString LOS::OSName(){ return "DragonFly BSD"; }
@@ -188,25 +238,24 @@ void LOS::systemSuspend(){
//Battery Availability
bool LOS::hasBattery(){
- int val = LUtils::getCmdOutput("sysctl -n hw.acpi.battery.units").join("").toInt();
- return (val >= 1);
+ return (get_sysctlbyname_int("hw.acpi.battery.units") >= 1);
}
//Battery Charge Level
int LOS::batteryCharge(){ //Returns: percent charge (0-100), anything outside that range is counted as an error
- int charge = LUtils::getCmdOutput("sysctl -n hw.acpi.battery.life").join("").toInt();
+ int charge = get_sysctlbyname_int("hw.acpi.battery.life");
if(charge > 100){ charge = -1; } //invalid charge
return charge;
}
//Battery Charging State
bool LOS::batteryIsCharging(){
- return (LUtils::getCmdOutput("sysctl -n hw.acpi.battery.state").join("").simplified() == "2");
+ return (get_sysctlbyname_int("hw.acpi.battery.state") == 0);
}
//Battery Time Remaining
int LOS::batterySecondsLeft(){ //Returns: estimated number of seconds remaining
- int time = LUtils::getCmdOutput("sysctl -n hw.acpi.battery.time").join("").toInt();
+ int time = get_sysctlbyname_int("hw.acpi.battery.time");
if (time > 0) {
// time is in minutes
time *= 60;
@@ -236,24 +285,42 @@ QString LOS::FileSystemCapacity(QString dir) { //Return: percentage capacity as
return capacity;
}
-QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example)
- QStringList temps;
+static float sensor_value_to_degC(int64_t value) {
+ return (value - 273150000) / 1000000.0;
+}
- // Determine number of CPUs
- if (ncpu == -1) {
- ncpu = LUtils::getCmdOutput("sysctl -n hw.ncpu").join("").toInt();
- }
+//Returns: List containing the temperature of any CPU's ("50C" for example)
+QStringList LOS::CPUTemperatures(){
+ QStringList temps;
- // We couldn't get number of CPUs. Give up!
- if (ncpu == -1) {
- return temps;
+ int mib[5];
+ mib[0] = CTL_HW;
+ mib[1] = HW_SENSORS;
+
+ for (int dev=0; dev < MAXSENSORDEVICES; ++dev) {
+ struct sensordev sensordev;
+ size_t sdlen = sizeof(sensordev);
+
+ mib[2] = dev;
+ if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) {
+ continue;
+ }
+ mib[3] = SENSOR_TEMP;
+ for (int numt=0; numt < sensordev.maxnumt[SENSOR_TEMP]; ++numt) {
+ mib[4] = numt;
+ struct sensor sensor;
+ size_t slen = sizeof(sensor);
+ if (sysctl(mib, 5, &sensor, &slen, NULL, 0) == -1) {
+ continue;
+ }
+
+ // XXX: Filter out non-cpu temperatures
+
+ int degC = (int)sensor_value_to_degC(sensor.value);
+ temps << QString::number(degC) + "C" + "(" + QString(sensordev.xname) + ")";
+ }
}
- for (int cpu = 0; cpu < ncpu; ++cpu) {
- QString cmd = QString("sysctl -n hw.sensors.cpu") + QString::number(cpu) + QString(".temp0");
- QString info = LUtils::getCmdOutput(cmd).join("");
- temps << info.section(" ", 0, 1);
- }
return temps;
}
@@ -263,10 +330,16 @@ int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU c
int LOS::MemoryUsagePercent(){
//SYSCTL: vm.stats.vm.v_<something>_count
- QStringList info = LUtils::getCmdOutput("sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_wire_count vm.stats.vm.v_active_count");
- if(info.length()<3){ return -1; } //error in fetching information
+ unsigned int v_page_count = 0;
+ unsigned int v_wire_count = 0;
+ unsigned int v_active_count = 0;
+
+ if (!get_sysctlbyname_uint("vm.stats.vm.v_page_count", &v_page_count)) return -1;
+ if (!get_sysctlbyname_uint("vm.stats.vm.v_wire_count", &v_wire_count)) return -1;
+ if (!get_sysctlbyname_uint("vm.stats.vm.v_active_count", &v_active_count)) return -1;
+
//List output: [total, wired, active]
- double perc = 100.0* (info[1].toLong()+info[2].toLong())/(info[0].toDouble());
+ double perc = 100.0 * ((long)v_wire_count+(long)v_active_count)/((double)v_page_count);
return qRound(perc);
}
diff --git a/lumina-fm/MainUI.cpp b/lumina-fm/MainUI.cpp
index 9d921b7c..9ae681f0 100644
--- a/lumina-fm/MainUI.cpp
+++ b/lumina-fm/MainUI.cpp
@@ -778,9 +778,11 @@ void MainUI::RemoveFiles(QStringList list){
}
//Verify permanent removal of file/dir
- if(QMessageBox::Yes != QMessageBox::question(this, tr("Verify Removal"), tr("WARNING: This will permanently delete the file(s) from the system!")+"\n"+tr("Are you sure you want to continue?")+"\n\n"+names.join("\n"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){
- return; //cancelled
- }
+ QMessageBox dlgQ(QMessageBox::Question, tr("Verify Removal"), tr("WARNING: This will permanently delete the file(s) from the system!")+"\n"+tr("Are you sure you want to continue?"), QMessageBox::Yes | QMessageBox::No, this);
+ dlgQ.setDetailedText(tr("Items to be removed:")+"\n\n"+names.join("\n"));
+ dlgQ.exec();
+ if(dlgQ.result() != QMessageBox::Yes){ return; } //cancelled
+
//Now remove the file/dir
qDebug() << " - Delete: "<<paths;
FODialog dlg(this);
diff --git a/lumina-fm/widgets/DDListWidgets.h b/lumina-fm/widgets/DDListWidgets.h
index c211206b..d47c7ee4 100644
--- a/lumina-fm/widgets/DDListWidgets.h
+++ b/lumina-fm/widgets/DDListWidgets.h
@@ -20,6 +20,7 @@
#include <QDrag>
#include <QFileInfo>
#include <QDebug>
+#include <QMouseEvent>
//==============
// LIST WIDGET
@@ -84,11 +85,14 @@ protected:
ev->setDropAction(Qt::CopyAction);
}
ev->accept(); //allow this to be dropped here
- }
+ }else{
+ ev->ignore();
+ }
}
void dropEvent(QDropEvent *ev){
- if(this->whatsThis().isEmpty()){ return; } //not supported
+ if(this->whatsThis().isEmpty()){ ev->ignore(); return; } //not supported
+ //qDebug() << "Drop Event:";
ev->accept(); //handled here
QString dirpath = this->whatsThis();
//See if the item under the drop point is a directory or not
@@ -102,6 +106,11 @@ protected:
//qDebug() << "Drop Event:" << dirpath;
emit DataDropped( dirpath, QString(ev->mimeData()->data(MIME)).split("\n") );
}
+
+ void mouseReleaseEvent(QMouseEvent *ev){
+ if(ev->button() != Qt::RightButton && ev->button() != Qt::LeftButton){ ev->ignore(); }
+ else{ QListWidget::mouseReleaseEvent(ev); } //pass it along to the widget
+ }
};
//================
@@ -185,5 +194,10 @@ protected:
//qDebug() << "Drop Event:" << dirpath;
emit DataDropped( dirpath, QString(ev->mimeData()->data(MIME)).split("\n") );
}
+
+ void mouseReleaseEvent(QMouseEvent *ev){
+ if(ev->button() != Qt::RightButton && ev->button() != Qt::LeftButton){ ev->ignore(); }
+ else{ QTreeWidget::mouseReleaseEvent(ev); } //pass it along to the widget
+ }
};
#endif \ No newline at end of file
diff --git a/lumina-fm/widgets/DirWidget.cpp b/lumina-fm/widgets/DirWidget.cpp
index 651ceb75..0e0c404b 100644
--- a/lumina-fm/widgets/DirWidget.cpp
+++ b/lumina-fm/widgets/DirWidget.cpp
@@ -796,14 +796,6 @@ void DirWidget::openTerminal(){
emit LaunchTerminal(CDIR);
}
-void DirWidget::NewFile(){
-
-}
-
-void DirWidget::NewDir(){
-
-}
-
//Browser Functions
void DirWidget::OpenContextMenu(){
//First generate the context menu based on the selection
@@ -856,7 +848,9 @@ void DirWidget::startSync(){
// PROTECTED
//====================
void DirWidget::mouseReleaseEvent(QMouseEvent *ev){
- if(ev->button()==Qt::BackButton){
+ static Qt::MouseButtons backmap = Qt::BackButton | Qt::ExtraButton5;
+ //qDebug() << "Mouse Click:" << ev->button();
+ if(backmap.testFlag(ev->button())){
ev->accept();
on_actionBack_triggered();
//}else if(ev->button()==Qt::ForwardButton()){
diff --git a/lumina-fm/widgets/DirWidget.h b/lumina-fm/widgets/DirWidget.h
index a7fe3cc3..2c971fd8 100644
--- a/lumina-fm/widgets/DirWidget.h
+++ b/lumina-fm/widgets/DirWidget.h
@@ -123,8 +123,6 @@ private slots:
void fileCheckSums();
void fileProperties();
void openTerminal();
- void NewFile();
- void NewDir();
//Browser Functions
bgstack15