[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [confine] /: GUI displays Users and Profiles on System
From:       Gilbert Assaf <gassaf () gmx ! de>
Date:       2016-01-04 15:27:27
Message-ID: E1aG72d-0004T7-Pm () scm ! kde ! org
[Download RAW message or body]

Git commit b24ff57707418c994e97196425ffd192223f1619 by Gilbert Assaf.
Committed on 04/01/2016 at 15:27.
Pushed by gassaf into branch 'master'.

GUI displays Users and Profiles on System

M  +4    -2    CMakeLists.txt
M  +32   -2    src/mainwindow.cpp
M  +28   -2    src/mainwindow.h
A  +61   -0    src/mainwindow.ui
M  +7    -3    src/profile.cpp
M  +2    -1    src/profile.h
M  +6    -6    src/user.cpp
M  +1    -1    src/user.h
M  +27   -6    src/usermanager.cpp
M  +2    -1    src/usermanager.h

http://commits.kde.org/confine/b24ff57707418c994e97196425ffd192223f1619

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fb6e3f7..a3cc132 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,9 +31,11 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
 feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
  
 set(confine_SRCS src/main.cpp src/mainwindow.cpp src/profilemanager.cpp \
                src/profile.cpp src/usermanager.cpp src/user.cpp)
- 
+
+qt5_wrap_ui(confine_UI src/mainwindow.ui)
+
 # just plain add_executable
-add_executable(confine ${confine_SRCS})
+add_executable(confine ${confine_SRCS} ${confine_UI})
  
 # module-based linking
 target_link_libraries(confine
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 51770d7..13025eb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,9 +1,39 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015  <copyright holder> <email>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 #include "mainwindow.h"
 #include "profilemanager.h"
-#include <QDebug>
+#include "usermanager.h"
 
+#include <KLocalizedString>
 
 MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent)
 {
-    setupGUI();
+    UserManager um;
+
+    ui.setupUi(this);
+    ui.tabWidget->setTabText(0, i18n("Users"));
+    ui.tabWidget->setTabText(1, i18n("Profiles"));
+    ui.userList->addItems(um.getUserNames());
+    ui.profileList->addItems(um.getProfileNames());
+    ui.tabWidget->setCurrentIndex(0);
 }
diff --git a/src/mainwindow.h b/src/mainwindow.h
index eb14da1..cb1a0d1 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -1,13 +1,39 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright 2015  <copyright holder> <email>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 #ifndef MAINWINDOW_H
 #define MAINWINDOW_H
  
 #include <KXmlGuiWindow>
- 
+
+#include <ui_mainwindow.h>
 
 class MainWindow : public KXmlGuiWindow
 {
   public:
-    MainWindow(QWidget *parent=0);
+    explicit MainWindow(QWidget *parent=0);
+    
+private:
+  Ui::MainWindow ui;
 };
  
 #endif
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
new file mode 100644
index 0000000..2338f7b
--- /dev/null
+++ b/src/mainwindow.ui
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
+     <widget class="QTabWidget" name="tabWidget">
+      <property name="currentIndex">
+       <number>1</number>
+      </property>
+      <widget class="QWidget" name="tab">
+       <attribute name="title">
+        <string>Tab 1</string>
+       </attribute>
+       <layout class="QGridLayout" name="gridLayout_2">
+        <item row="0" column="0">
+         <widget class="QListWidget" name="userList"/>
+        </item>
+       </layout>
+      </widget>
+      <widget class="QWidget" name="tab_2">
+       <attribute name="title">
+        <string>Tab 2</string>
+       </attribute>
+       <layout class="QGridLayout" name="gridLayout_3">
+        <item row="0" column="0">
+         <widget class="QListWidget" name="profileList"/>
+        </item>
+       </layout>
+      </widget>
+     </widget>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>30</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/profile.cpp b/src/profile.cpp
index ddd3cd1..df234b6 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -31,9 +31,9 @@ Profile::Profile()
 
 }
 
-Profile::Profile(QString& profileDir)
+Profile::Profile(QString& profileDir) : name(profileDir), directory(profileDir)
 {
-    Profile(profileDir, profileDir);
+
 }
 
 Profile::Profile(QString& profileDir, QString& profileName) : name(profileName), \
directory(profileDir) @@ -48,9 +48,13 @@ Profile::~Profile()
 
 QString Profile::getDirectory() const
 {
-  return directory;
+    return directory;
 }
 
+QString Profile::getName() const
+{
+    return name;
+}
 
 QStringList Profile::getKDEActionRestrictions()
 {
diff --git a/src/profile.h b/src/profile.h
index d49766d..339cb9d 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -29,12 +29,13 @@ class Profile
 {
 public:
 Profile();
-Profile(QString& profileDir);
+explicit Profile(QString& profileDir);
 Profile(QString& profileDir, QString& profileName);
 ~Profile();
 QStringList getKDEActionRestrictions();
 void setKDEActionRestriction(QString& key, QString& value);
 QString getDirectory() const;
+QString getName() const;
 
 private:
   QString name;
diff --git a/src/user.cpp b/src/user.cpp
index 3eecb82..7a56cef 100644
--- a/src/user.cpp
+++ b/src/user.cpp
@@ -44,7 +44,7 @@ User::~User()
 
 }
 
-QString User::getName()
+QString User::getName() const
 {
     return name;
 }
@@ -76,7 +76,7 @@ void User::setEnvironmentVariableFile(QString& varFile)
 
 void User::addProfile(const Profile& profile)
 {
-  profiles.append(profile);
+    profiles.append(profile);
 }
 
 void User::save()
@@ -97,15 +97,15 @@ void User::save()
     if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
         return;
     }
-    
+
     QString configDirs;
     QStringList helperList;
     Q_FOREACH(const Profile & pf, profiles) {
-      helperList << pf.getDirectory();
+        helperList << pf.getDirectory();
     }
-    
+
     configDirs = helperList.join(QLatin1Char(':'));
-    
+
     QStringList fileContent;
     bool hasConfigDirs = false;
     bool hasConfigHome = false;
diff --git a/src/user.h b/src/user.h
index 07a497c..3c0612c 100644
--- a/src/user.h
+++ b/src/user.h
@@ -32,7 +32,7 @@ class User
 public:   
   User(QString& userName, QString& userShell, QString& userHomeDir);
   ~User();
-  QString getName();
+  QString getName() const;
   QString getHomeDir();
   QString getXDG_CONFIG_DIRS();
   QString getXDG_CONFIG_HOME();
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index 4061b9e..60e2d4f 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -91,15 +91,36 @@ void UserManager::getXDGConfig(User& user)
 
     QStringList configDirsList = configDirs.split(QLatin1Char(':'));
     Q_FOREACH(const QString & singleDir, configDirsList) {
-      QString dir(singleDir);
-      if(!profiles.contains(dir)){
-	Profile pf(dir);
-	profiles.insert(dir, pf);
-      }
-      user.addProfile(profiles.value(dir));
+        if (singleDir.isEmpty()) {
+            continue;
+        }
+        QString dir(singleDir);
+        if (!profiles.contains(dir)) {
+            qDebug() << dir;
+            Profile pf(dir);
+            profiles.insert(dir, pf);
+        }
+        user.addProfile(profiles.value(dir));
     }
 
     user.setXDG_CONFIG_HOME(configHome);
 }
 
+QStringList UserManager::getUserNames()
+{
+    QStringList userNames;
+    Q_FOREACH(const User & user, users) {
+        userNames << user.getName();
+    }
+    return userNames;
+}
+
+QStringList UserManager::getProfileNames()
+{
+    QStringList profileNames;
+    Q_FOREACH(const Profile & profile, profiles.values()) {
+        profileNames << profile.getName();
+    }
 
+    return profileNames;
+}
diff --git a/src/usermanager.h b/src/usermanager.h
index 7912d43..e95bc9a 100644
--- a/src/usermanager.h
+++ b/src/usermanager.h
@@ -36,7 +36,8 @@ UserManager();
 ~UserManager();
 void getXDGConfig(User& user);
 void setXDGConfig(User& user, QString& configDirs, QString& configHome);
-
+QStringList getUserNames();
+QStringList getProfileNames();
 
 private:
   QList<User> users;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic