Skip to content

Commit

Permalink
Multiple Users #3 - Work to list and switch between accounts
Browse files Browse the repository at this point in the history
 * Minor cleanup and fixes
  • Loading branch information
SneWs committed Jul 14, 2024
1 parent 6ab741b commit 0f72935
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 9 additions & 1 deletion TrayMenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,17 @@ void TrayMenuManager::buildAccountsMenu() const {
if (pThisDevice->menu() == nullptr) {
pThisDevice->setMenu(new QMenu());
}

pThisDevice->menu()->clear();
for (const auto& acc : accounts) {
auto accountAction = new QAction(acc.tailnet + " (" + acc.account + ")");
bool isActive = acc.account.endsWith('*');
QString accountName = acc.account;
if (isActive)
accountName = accountName.chopped(1);
auto accountAction = new QAction(acc.tailnet + " (" + accountName + ")");
accountAction->setCheckable(true);
accountAction->setChecked(isActive);

pThisDevice->menu()->addAction(accountAction);
accountAction->setData(acc.id);
connect(accountAction, &QAction::triggered, this, [this, accountAction](bool) {
Expand Down
9 changes: 3 additions & 6 deletions models.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ class TailAccountInfo : public QObject
// This handles fragmented lines as well from the command line output
// so even if a line starts with the ID and then break it will make sure to parse it correctly
static QList<TailAccountInfo> parseAllFound(const QString& rawData) {
qDebug() << "Will parse accounts from data:";
qDebug() << rawData;

QList<TailAccountInfo> retVal;

// Split input into individual lines
Expand All @@ -83,8 +80,7 @@ class TailAccountInfo : public QObject
// Reconstruct broken lines into complete entries
// And we skip the first line since it's the header line
for (int i = 1; i < lines.length(); i++) {
const QString& line = lines[i];
qDebug() << line;
const QString& line = lines[i].trimmed();
if (isIdLine(line)) {
if (!currentEntry.isEmpty()) {
entries.append(currentEntry);
Expand All @@ -93,7 +89,7 @@ class TailAccountInfo : public QObject
currentEntry = line;
}
else {
currentEntry += " " + line.trimmed();
currentEntry += "\t" + line.trimmed();
}
}

Expand All @@ -103,6 +99,7 @@ class TailAccountInfo : public QObject

// Iterate over each reconstructed entry and apply the regular expression
for (const QString& entry : entries) {
qDebug() << "Parsing entry: " << entry;
retVal.emplace_back(TailAccountInfo::parse(entry));
}

Expand Down

0 comments on commit 0f72935

Please sign in to comment.