From c6a3d1fc1f0150227dba76b54351b3381c938671 Mon Sep 17 00:00:00 2001
From: Brian Hill <supernova@warpmail.net>
Date: Sun, 8 Jan 2017 19:40:01 -0500
Subject: [PATCH 1/2] Suggested changes by M. Lotz
---
src/preferences/repositories/AddRepoWindow.cpp | 17 +--
src/preferences/repositories/AddRepoWindow.h | 3 +-
.../repositories/RepositoriesSettings.h | 5 +-
src/preferences/repositories/RepositoriesView.cpp | 115 ++++++++++++---------
src/preferences/repositories/RepositoriesView.h | 26 ++---
.../repositories/RepositoriesWindow.cpp | 26 +++--
src/preferences/repositories/RepositoriesWindow.h | 5 +-
src/preferences/repositories/TaskLooper.cpp | 21 ++--
src/preferences/repositories/TaskLooper.h | 3 +-
src/preferences/repositories/TaskTimer.cpp | 10 +-
src/preferences/repositories/TaskTimer.h | 3 +-
11 files changed, 143 insertions(+), 91 deletions(-)
diff --git a/src/preferences/repositories/AddRepoWindow.cpp b/src/preferences/repositories/AddRepoWindow.cpp
index 1e0f325..b163ce5 100644
a
|
b
|
|
14 | 14 | #include <Catalog.h> |
15 | 15 | #include <Clipboard.h> |
16 | 16 | #include <LayoutBuilder.h> |
| 17 | #include <Url.h> |
17 | 18 | |
18 | 19 | #include "constants.h" |
19 | 20 | |
… |
… |
AddRepoWindow::MessageReceived(BMessage* message)
|
76 | 77 | Quit(); |
77 | 78 | break; |
78 | 79 | |
79 | | case ADD_BUTTON_PRESSED: { |
| 80 | case ADD_BUTTON_PRESSED: |
| 81 | { |
80 | 82 | BString url(fText->Text()); |
81 | 83 | if (url != "") { |
82 | 84 | // URL must have a protocol |
83 | | if (url.FindFirst("://") == B_ERROR) { |
| 85 | BUrl newRepoUrl(url); |
| 86 | if (!newRepoUrl.IsValid()) { |
84 | 87 | BAlert* alert = new BAlert("error", |
85 | | B_TRANSLATE_COMMENT("The URL must start with a " |
86 | | "protocol, for example http:// or https://", |
| 88 | B_TRANSLATE_COMMENT("This is not a valid URL.", |
87 | 89 | "Add URL error message"), |
88 | 90 | kOKLabel, NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); |
89 | 91 | alert->SetFeel(B_MODAL_APP_WINDOW_FEEL); |
… |
… |
AddRepoWindow::MessageReceived(BMessage* message)
|
100 | 102 | } |
101 | 103 | break; |
102 | 104 | } |
| 105 | |
103 | 106 | default: |
104 | 107 | BWindow::MessageReceived(message); |
105 | 108 | } |
… |
… |
AddRepoWindow::_GetClipboardData()
|
124 | 127 | &stringLen); |
125 | 128 | be_clipboard->Unlock(); |
126 | 129 | |
127 | | // The string must contain a web protocol |
| 130 | // The string must be a valid url |
128 | 131 | BString clipString(string, stringLen); |
129 | | int32 ww = clipString.FindFirst("://"); |
130 | | if (ww == B_ERROR) |
| 132 | BUrl testUrl(clipString.String()); |
| 133 | if (!testUrl.IsValid()) |
131 | 134 | return B_ERROR; |
132 | 135 | else |
133 | 136 | fText->SetText(clipString); |
diff --git a/src/preferences/repositories/AddRepoWindow.h b/src/preferences/repositories/AddRepoWindow.h
index c6c1758..6c128f3 100644
a
|
b
|
public:
|
24 | 24 | virtual void FrameResized(float newWidth, float newHeight); |
25 | 25 | |
26 | 26 | private: |
| 27 | status_t _GetClipboardData(); |
| 28 | |
27 | 29 | BTextControl* fText; |
28 | 30 | BButton* fAddButton; |
29 | 31 | BButton* fCancelButton; |
30 | 32 | BMessenger fReplyMessenger; |
31 | | status_t _GetClipboardData(); |
32 | 33 | }; |
33 | 34 | |
34 | 35 | |
diff --git a/src/preferences/repositories/RepositoriesSettings.h b/src/preferences/repositories/RepositoriesSettings.h
index 8ceae1f..cea7a46 100644
a
|
b
|
public:
|
29 | 29 | BStringList& urlList); |
30 | 30 | |
31 | 31 | private: |
| 32 | BMessage _ReadFromFile(); |
| 33 | status_t _SaveToFile(BMessage settings); |
| 34 | |
32 | 35 | BPath fFilePath; |
33 | 36 | BFile fFile; |
34 | 37 | status_t fInitStatus; |
35 | | BMessage _ReadFromFile(); |
36 | | status_t _SaveToFile(BMessage settings); |
37 | 38 | }; |
38 | 39 | |
39 | 40 | |
diff --git a/src/preferences/repositories/RepositoriesView.cpp b/src/preferences/repositories/RepositoriesView.cpp
index c1cd3cf..4e7788e 100644
a
|
b
|
|
18 | 18 | #include <MessageRunner.h> |
19 | 19 | #include <ScrollBar.h> |
20 | 20 | #include <SeparatorView.h> |
| 21 | #include <Url.h> |
21 | 22 | #include <package/PackageRoster.h> |
22 | 23 | #include <package/RepositoryConfig.h> |
23 | 24 | |
… |
… |
RepositoriesView::MessageReceived(BMessage* message)
|
224 | 225 | { |
225 | 226 | switch (message->what) |
226 | 227 | { |
227 | | case REMOVE_REPOS: { |
| 228 | case REMOVE_REPOS: |
| 229 | { |
228 | 230 | RepoRow* rowItem = dynamic_cast<RepoRow*>(fListView->CurrentSelection()); |
229 | 231 | if (!rowItem || !fRemoveButton->IsEnabled()) |
230 | 232 | break; |
… |
… |
RepositoriesView::MessageReceived(BMessage* message)
|
272 | 274 | _SaveList(); |
273 | 275 | break; |
274 | 276 | } |
| 277 | |
275 | 278 | case LIST_SELECTION_CHANGED: |
276 | 279 | _UpdateButtons(); |
277 | 280 | break; |
278 | 281 | |
279 | | case ITEM_INVOKED: { |
| 282 | case ITEM_INVOKED: |
| 283 | { |
280 | 284 | // Simulates pressing whichever is the enabled button |
281 | 285 | if (fEnableButton->IsEnabled()) { |
282 | 286 | BMessage invokeMessage(ENABLE_BUTTON_PRESSED); |
… |
… |
RepositoriesView::MessageReceived(BMessage* message)
|
287 | 291 | } |
288 | 292 | break; |
289 | 293 | } |
290 | | case ENABLE_BUTTON_PRESSED: { |
| 294 | |
| 295 | case ENABLE_BUTTON_PRESSED: |
| 296 | { |
291 | 297 | BStringList names; |
292 | 298 | bool paramsOK = true; |
293 | 299 | // Check if there are multiple selections of the same repository, |
… |
… |
RepositoriesView::MessageReceived(BMessage* message)
|
314 | 320 | } |
315 | 321 | break; |
316 | 322 | } |
| 323 | |
317 | 324 | case DISABLE_BUTTON_PRESSED: |
318 | 325 | _AddSelectedRowsToQueue(); |
319 | 326 | _UpdateButtons(); |
320 | 327 | break; |
321 | 328 | |
322 | | case TASK_STARTED: { |
| 329 | case TASK_STARTED: |
| 330 | { |
323 | 331 | int16 count; |
324 | 332 | status_t result1 = message->FindInt16(key_count, &count); |
325 | 333 | RepoRow* rowItem; |
… |
… |
RepositoriesView::MessageReceived(BMessage* message)
|
328 | 336 | _TaskStarted(rowItem, count); |
329 | 337 | break; |
330 | 338 | } |
331 | | case TASK_COMPLETED_WITH_ERRORS: { |
| 339 | |
| 340 | case TASK_COMPLETED_WITH_ERRORS: |
| 341 | { |
332 | 342 | BString errorDetails; |
333 | 343 | status_t result = message->FindString(key_details, &errorDetails); |
334 | 344 | if (result == B_OK) { |
… |
… |
RepositoriesView::MessageReceived(BMessage* message)
|
350 | 360 | _UpdateButtons(); |
351 | 361 | break; |
352 | 362 | } |
353 | | case TASK_COMPLETED: { |
| 363 | |
| 364 | case TASK_COMPLETED: |
| 365 | { |
354 | 366 | BString repoName = message->GetString(key_name, |
355 | 367 | kNewRepoDefaultName.String()); |
356 | 368 | int16 count; |
… |
… |
RepositoriesView::MessageReceived(BMessage* message)
|
367 | 379 | _UpdateButtons(); |
368 | 380 | break; |
369 | 381 | } |
370 | | case TASK_CANCELED: { |
| 382 | |
| 383 | case TASK_CANCELED: |
| 384 | { |
371 | 385 | int16 count; |
372 | 386 | status_t result1 = message->FindInt16(key_count, &count); |
373 | 387 | RepoRow* rowItem; |
… |
… |
RepositoriesView::MessageReceived(BMessage* message)
|
380 | 394 | _UpdateButtons(); |
381 | 395 | break; |
382 | 396 | } |
| 397 | |
383 | 398 | case UPDATE_LIST: |
384 | 399 | _RefreshList(); |
385 | 400 | _UpdateButtons(); |
386 | 401 | break; |
387 | 402 | |
388 | | case STATUS_VIEW_COMPLETED_TIMEOUT: { |
| 403 | case STATUS_VIEW_COMPLETED_TIMEOUT: |
| 404 | { |
389 | 405 | int32 timerID; |
390 | 406 | status_t result = message->FindInt32(key_ID, &timerID); |
391 | 407 | if (result == B_OK && timerID == fLastCompletedTimerId) |
392 | 408 | _UpdateStatusView(); |
393 | 409 | break; |
394 | 410 | } |
| 411 | |
395 | 412 | default: |
396 | 413 | BView::MessageReceived(message); |
397 | 414 | } |
… |
… |
RepositoriesView::_TaskCompleted(RepoRow* rowItem, int16 count, BString& newName
|
434 | 451 | // Update row state and values |
435 | 452 | rowItem->SetTaskState(STATE_NOT_IN_QUEUE); |
436 | 453 | if (kNewRepoDefaultName.Compare(rowItem->Name()) == 0 |
437 | | && newName.Compare("") != 0) |
| 454 | && newName.Compare("") != 0) { |
438 | 455 | rowItem->SetName(newName.String()); |
| 456 | } |
439 | 457 | _UpdateFromRepoConfig(rowItem); |
440 | 458 | } |
441 | 459 | |
… |
… |
RepositoriesView::_UpdateFromRepoConfig(RepoRow* rowItem)
|
486 | 504 | void |
487 | 505 | RepositoriesView::AddManualRepository(BString url) |
488 | 506 | { |
| 507 | BUrl newRepoUrl(url); |
| 508 | if (!newRepoUrl.IsValid()) |
| 509 | return; |
| 510 | |
489 | 511 | BString name(kNewRepoDefaultName); |
490 | | BString rootUrl = _GetRootUrl(url); |
491 | | bool foundRoot = false; |
| 512 | BString newPathIdentifier = _GetPathIdentifier(newRepoUrl.Path()); |
| 513 | bool foundMatchingRoot = false; |
492 | 514 | int32 index; |
493 | 515 | int32 listCount = fListView->CountRows(); |
494 | 516 | for (index = 0; index < listCount; index++) { |
495 | 517 | RepoRow* repoItem = dynamic_cast<RepoRow*>(fListView->RowAt(index)); |
496 | | const char* urlPtr = repoItem->Url(); |
| 518 | BUrl rowRepoUrl(repoItem->Url()); |
497 | 519 | // Find an already existing URL |
498 | | if (url.ICompare(urlPtr) == 0) { |
| 520 | if (newRepoUrl == rowRepoUrl) { |
499 | 521 | (new BAlert("duplicate", |
500 | 522 | B_TRANSLATE_COMMENT("This repository URL already exists.", |
501 | 523 | "Error message"), |
502 | 524 | kOKLabel))->Go(NULL); |
503 | 525 | return; |
504 | 526 | } |
505 | | // Use the same name from another repo with the same root url |
506 | | if (foundRoot == false && rootUrl.ICompare(urlPtr, |
507 | | rootUrl.Length()) == 0) { |
508 | | foundRoot = true; |
509 | | name = repoItem->Name(); |
| 527 | // Predict the repo name from another url with matching path root |
| 528 | if (!foundMatchingRoot) { |
| 529 | BString rowPathIdentifier = _GetPathIdentifier(rowRepoUrl.Path()); |
| 530 | if (newPathIdentifier.ICompare(rowPathIdentifier) == 0) { |
| 531 | foundMatchingRoot = true; |
| 532 | name = repoItem->Name(); |
| 533 | } |
510 | 534 | } |
511 | 535 | } |
512 | 536 | RepoRow* newRepo = _AddRepo(name, url, false); |
… |
… |
RepositoriesView::AddManualRepository(BString url)
|
519 | 543 | |
520 | 544 | |
521 | 545 | BString |
522 | | RepositoriesView::_GetRootUrl(BString url) |
| 546 | RepositoriesView::_GetPathIdentifier(BString urlPath) |
523 | 547 | { |
524 | | // Find the protocol if it exists |
525 | | int32 ww = url.FindFirst("://"); |
526 | | if (ww == B_ERROR) |
527 | | ww = 0; |
528 | | else |
529 | | ww += 3; |
530 | 548 | // Find second / |
531 | | int32 rootEnd = url.FindFirst("/", ww + 1); |
532 | | if (rootEnd == B_ERROR) |
533 | | return url; |
534 | | rootEnd = url.FindFirst("/", rootEnd + 1); |
535 | | if (rootEnd == B_ERROR) |
536 | | return url; |
| 549 | int32 index = urlPath.FindFirst("/"); |
| 550 | if (index == B_ERROR) |
| 551 | return urlPath; |
| 552 | index = urlPath.FindFirst("/", index + 1); |
| 553 | if (index == B_ERROR) |
| 554 | return urlPath; |
537 | 555 | else |
538 | | return url.Truncate(rootEnd); |
| 556 | return urlPath.Truncate(index); |
539 | 557 | } |
540 | 558 | |
541 | 559 | |
542 | 560 | status_t |
543 | 561 | RepositoriesView::_EmptyList() |
544 | 562 | { |
545 | | BRow* row; |
546 | | while ((row = fListView->RowAt((int32)0, NULL)) != NULL) { |
| 563 | BRow* row = fListView->RowAt((int32)0, NULL); |
| 564 | while (row != NULL) { |
547 | 565 | fListView->RemoveRow(row); |
548 | 566 | delete row; |
| 567 | row = fListView->RowAt((int32)0, NULL); |
549 | 568 | } |
550 | 569 | return B_OK; |
551 | 570 | } |
… |
… |
RepositoriesView::_SaveList()
|
639 | 658 | RepoRow* |
640 | 659 | RepositoriesView::_AddRepo(BString name, BString url, bool enabled) |
641 | 660 | { |
642 | | // URL must have a protocol |
643 | | if (url.FindFirst("://") == B_ERROR) |
| 661 | // URL must be valid |
| 662 | BUrl repoUrl(url); |
| 663 | if (!repoUrl.IsValid()) |
644 | 664 | return NULL; |
645 | | RepoRow* addedRow = NULL; |
646 | 665 | int32 index; |
647 | 666 | int32 listCount = fListView->CountRows(); |
648 | 667 | // Find if the repo already exists in list |
649 | 668 | for (index = 0; index < listCount; index++) { |
650 | 669 | RepoRow* repoItem = dynamic_cast<RepoRow*>(fListView->RowAt(index)); |
651 | | if (url.ICompare(repoItem->Url()) == 0) { |
| 670 | BUrl itemUrl(repoItem->Url()); |
| 671 | if (repoUrl == itemUrl) { |
652 | 672 | // update name and enabled values |
653 | | if (name.Compare(repoItem->Name()) != 0) |
| 673 | if (name != repoItem->Name()) |
654 | 674 | repoItem->SetName(name.String()); |
655 | 675 | repoItem->SetEnabled(enabled); |
656 | | addedRow = repoItem; |
| 676 | return repoItem; |
657 | 677 | } |
658 | 678 | } |
659 | | if (addedRow == NULL) { |
660 | | addedRow = new RepoRow(name, url, enabled); |
661 | | fListView->AddRow(addedRow); |
662 | | } |
| 679 | RepoRow* addedRow = new RepoRow(name, url, enabled); |
| 680 | fListView->AddRow(addedRow); |
663 | 681 | return addedRow; |
664 | 682 | } |
665 | 683 | |
… |
… |
RepositoriesView::_UpdateButtons()
|
698 | 716 | RepoRow* rowItem = dynamic_cast<RepoRow*>(fListView->CurrentSelection()); |
699 | 717 | // At least one row is selected |
700 | 718 | if (rowItem) { |
701 | | bool someAreEnabled = false, |
702 | | someAreDisabled = false, |
703 | | someAreInQueue = false; |
| 719 | bool someAreEnabled = false; |
| 720 | bool someAreDisabled = false; |
| 721 | bool someAreInQueue = false; |
704 | 722 | int32 selectedCount = 0; |
705 | 723 | RepoRow* rowItem = dynamic_cast<RepoRow*>(fListView->CurrentSelection()); |
706 | 724 | while (rowItem) { |
707 | 725 | selectedCount++; |
708 | 726 | uint32 taskState = rowItem->TaskState(); |
709 | 727 | if ( taskState == STATE_IN_QUEUE_WAITING |
710 | | || taskState == STATE_IN_QUEUE_RUNNING) |
| 728 | || taskState == STATE_IN_QUEUE_RUNNING) { |
711 | 729 | someAreInQueue = true; |
| 730 | } |
712 | 731 | if (rowItem->IsEnabled()) |
713 | 732 | someAreEnabled = true; |
714 | 733 | else |
diff --git a/src/preferences/repositories/RepositoriesView.h b/src/preferences/repositories/RepositoriesView.h
index 875b723..2bf5465 100644
a
|
b
|
public:
|
38 | 38 | bool IsTaskRunning() { return fRunningTaskCount > 0; } |
39 | 39 | |
40 | 40 | private: |
41 | | RepositoriesSettings fSettings; |
42 | | RepositoriesListView* fListView; |
43 | | BView* fStatusContainerView; |
44 | | BStringView* fListStatusView; |
45 | | TaskLooper* fTaskLooper; |
46 | | bool fShowCompletedStatus; |
47 | | int fRunningTaskCount, fLastCompletedTimerId; |
48 | | BButton* fAddButton; |
49 | | BButton* fRemoveButton; |
50 | | BButton* fEnableButton; |
51 | | BButton* fDisableButton; |
52 | | |
53 | 41 | // Message helpers |
54 | 42 | void _AddSelectedRowsToQueue(); |
55 | 43 | void _TaskStarted(RepoRow* rowItem, int16 count); |
… |
… |
private:
|
60 | 48 | void _UpdateFromRepoConfig(RepoRow* rowItem); |
61 | 49 | |
62 | 50 | // GUI functions |
63 | | BString _GetRootUrl(BString url); |
| 51 | BString _GetPathIdentifier(BString urlPath); |
64 | 52 | status_t _EmptyList(); |
65 | 53 | void _InitList(); |
66 | 54 | void _RefreshList(); |
… |
… |
private:
|
70 | 58 | void _FindSiblings(); |
71 | 59 | void _UpdateButtons(); |
72 | 60 | void _UpdateStatusView(); |
| 61 | |
| 62 | RepositoriesSettings fSettings; |
| 63 | RepositoriesListView* fListView; |
| 64 | BView* fStatusContainerView; |
| 65 | BStringView* fListStatusView; |
| 66 | TaskLooper* fTaskLooper; |
| 67 | bool fShowCompletedStatus; |
| 68 | int fRunningTaskCount, fLastCompletedTimerId; |
| 69 | BButton* fAddButton; |
| 70 | BButton* fRemoveButton; |
| 71 | BButton* fEnableButton; |
| 72 | BButton* fDisableButton; |
73 | 73 | }; |
74 | 74 | |
75 | 75 | |
diff --git a/src/preferences/repositories/RepositoriesWindow.cpp b/src/preferences/repositories/RepositoriesWindow.cpp
index 8087419..d2aad6c 100644
a
|
b
|
RepositoriesWindow::RepositoriesWindow()
|
43 | 43 | BScreen screen; |
44 | 44 | BRect screenFrame = screen.Frame(); |
45 | 45 | if (screenFrame.right < frame.right || screenFrame.left > frame.left |
46 | | || screenFrame.top > frame.top || screenFrame.bottom < frame.bottom) |
| 46 | || screenFrame.top > frame.top || screenFrame.bottom < frame.bottom) { |
47 | 47 | CenterOnScreen(); |
| 48 | } |
48 | 49 | else |
49 | 50 | MoveTo(frame.left, frame.top); |
50 | 51 | Show(); |
… |
… |
RepositoriesWindow::MessageReceived(BMessage* message)
|
126 | 127 | { |
127 | 128 | switch (message->what) |
128 | 129 | { |
129 | | case ADD_REPO_WINDOW: { |
| 130 | case ADD_REPO_WINDOW: |
| 131 | { |
130 | 132 | BRect frame = Frame(); |
131 | 133 | fAddWindow = new AddRepoWindow(frame, fMessenger); |
132 | 134 | break; |
133 | 135 | } |
134 | | case ADD_REPO_URL: { |
| 136 | |
| 137 | case ADD_REPO_URL: |
| 138 | { |
135 | 139 | BString url; |
136 | 140 | status_t result = message->FindString(key_url, &url); |
137 | 141 | if (result == B_OK) |
138 | 142 | fView->AddManualRepository(url); |
139 | 143 | break; |
140 | 144 | } |
141 | | case ADD_WINDOW_CLOSED: { |
| 145 | |
| 146 | case ADD_WINDOW_CLOSED: |
| 147 | { |
142 | 148 | fAddWindow = NULL; |
143 | 149 | break; |
144 | 150 | } |
145 | | case DELETE_KEY_PRESSED: { |
| 151 | |
| 152 | case DELETE_KEY_PRESSED: |
| 153 | { |
146 | 154 | BMessage message(REMOVE_REPOS); |
147 | 155 | fView->MessageReceived(&message); |
148 | 156 | break; |
149 | 157 | } |
| 158 | |
150 | 159 | // captures pkgman changes while the Repositories application is running |
151 | | case B_NODE_MONITOR: { |
| 160 | case B_NODE_MONITOR: |
| 161 | { |
152 | 162 | // This preflet is making the changes, so ignore this message |
153 | 163 | if (fView->IsTaskRunning()) |
154 | 164 | break; |
… |
… |
RepositoriesWindow::MessageReceived(BMessage* message)
|
159 | 169 | { |
160 | 170 | case B_ATTR_CHANGED: |
161 | 171 | case B_ENTRY_CREATED: |
162 | | case B_ENTRY_REMOVED: { |
| 172 | case B_ENTRY_REMOVED: |
| 173 | { |
163 | 174 | PostMessage(UPDATE_LIST, fView); |
164 | 175 | break; |
165 | 176 | } |
… |
… |
RepositoriesWindow::MessageReceived(BMessage* message)
|
167 | 178 | } |
168 | 179 | break; |
169 | 180 | } |
| 181 | |
170 | 182 | default: |
171 | 183 | BWindow::MessageReceived(message); |
172 | 184 | } |
diff --git a/src/preferences/repositories/RepositoriesWindow.h b/src/preferences/repositories/RepositoriesWindow.h
index 3272bbf..6570c42 100644
a
|
b
|
public:
|
25 | 25 | virtual void MessageReceived(BMessage*); |
26 | 26 | |
27 | 27 | private: |
| 28 | void _StartWatching(); |
| 29 | void _StopWatching(); |
| 30 | |
28 | 31 | RepositoriesSettings fSettings; |
29 | 32 | RepositoriesView* fView; |
30 | 33 | AddRepoWindow* fAddWindow; |
… |
… |
private:
|
34 | 37 | status_t fPackageNodeStatus; |
35 | 38 | bool fWatchingPackageNode; |
36 | 39 | // true when package-repositories directory is being watched |
37 | | void _StartWatching(); |
38 | | void _StopWatching(); |
39 | 40 | }; |
40 | 41 | |
41 | 42 | |
diff --git a/src/preferences/repositories/TaskLooper.cpp b/src/preferences/repositories/TaskLooper.cpp
index 91f9bf1..ef9fb3d 100644
a
|
b
|
TaskLooper::MessageReceived(BMessage* message)
|
115 | 115 | { |
116 | 116 | switch (message->what) |
117 | 117 | { |
118 | | case DO_TASK: { |
| 118 | case DO_TASK: |
| 119 | { |
119 | 120 | RepoRow* rowItem; |
120 | 121 | status_t result = message->FindPointer(key_rowptr, (void**)&rowItem); |
121 | 122 | if (result == B_OK) { |
… |
… |
TaskLooper::MessageReceived(BMessage* message)
|
170 | 171 | } |
171 | 172 | break; |
172 | 173 | } |
| 174 | |
173 | 175 | case TASK_COMPLETED: |
174 | 176 | case TASK_COMPLETED_WITH_ERRORS: |
175 | | case TASK_CANCELED: { |
| 177 | case TASK_CANCELED: |
| 178 | { |
176 | 179 | Task* task; |
177 | 180 | status_t result = message->FindPointer(key_taskptr, (void**)&task); |
178 | 181 | if (result == B_OK && fTaskQueue.HasItem(task)) { |
… |
… |
TaskLooper::MessageReceived(BMessage* message)
|
183 | 186 | if (message->what == TASK_COMPLETED_WITH_ERRORS) |
184 | 187 | reply.AddString(key_details, task->resultErrorDetails); |
185 | 188 | if (task->taskType == ENABLE_REPO |
186 | | && task->name.Compare(task->resultName) != 0) |
| 189 | && task->name.Compare(task->resultName) != 0) { |
187 | 190 | reply.AddString(key_name, task->resultName); |
| 191 | } |
188 | 192 | fReplyTarget.SendMessage(&reply); |
189 | 193 | _RemoveAndDelete(task); |
190 | 194 | } |
191 | 195 | break; |
192 | 196 | } |
193 | | case TASK_KILL_REQUEST: { |
| 197 | |
| 198 | case TASK_KILL_REQUEST: |
| 199 | { |
194 | 200 | Task* task; |
195 | 201 | status_t result = message->FindPointer(key_taskptr, (void**)&task); |
196 | 202 | if (result == B_OK && fTaskQueue.HasItem(task)) { |
… |
… |
TaskLooper::_DoTask(void* data)
|
230 | 236 | JobStateListener listener; |
231 | 237 | switch (task->taskType) |
232 | 238 | { |
233 | | case DISABLE_REPO: { |
| 239 | case DISABLE_REPO: |
| 240 | { |
234 | 241 | BString nameParam(task->taskParam); |
235 | 242 | BPackageKit::BContext context(decisionProvider, listener); |
236 | 243 | BPackageKit::DropRepositoryRequest dropRequest(context, nameParam); |
… |
… |
TaskLooper::_DoTask(void* data)
|
249 | 256 | } |
250 | 257 | break; |
251 | 258 | } |
252 | | case ENABLE_REPO: { |
| 259 | |
| 260 | case ENABLE_REPO: |
| 261 | { |
253 | 262 | BString urlParam(task->taskParam); |
254 | 263 | BPackageKit::BContext context(decisionProvider, listener); |
255 | 264 | // Add repository |
diff --git a/src/preferences/repositories/TaskLooper.h b/src/preferences/repositories/TaskLooper.h
index 1a671e6..a79ab83 100644
a
|
b
|
public:
|
54 | 54 | virtual void MessageReceived(BMessage*); |
55 | 55 | |
56 | 56 | private: |
57 | | BObjectList<Task> fTaskQueue; |
58 | 57 | void _RemoveAndDelete(Task* task); |
59 | 58 | static status_t _DoTask(void* data); |
60 | 59 | static void _AppendErrorDetails(BString& details, |
61 | 60 | JobStateListener* listener); |
| 61 | |
| 62 | BObjectList<Task> fTaskQueue; |
62 | 63 | BMessenger fReplyTarget; |
63 | 64 | BMessenger fMessenger; |
64 | 65 | }; |
diff --git a/src/preferences/repositories/TaskTimer.cpp b/src/preferences/repositories/TaskTimer.cpp
index 44b3a99..f13a748 100644
a
|
b
|
TaskTimer::MessageReceived(BMessage* message)
|
65 | 65 | { |
66 | 66 | switch (message->what) |
67 | 67 | { |
68 | | case TASK_TIMEOUT: { |
| 68 | case TASK_TIMEOUT: |
| 69 | { |
69 | 70 | fMessageRunner = NULL; |
70 | 71 | if (fTimerIsRunning) { |
71 | 72 | BString text(B_TRANSLATE_COMMENT("The task for repository" |
… |
… |
TaskTimer::MessageReceived(BMessage* message)
|
94 | 95 | } |
95 | 96 | break; |
96 | 97 | } |
97 | | case TIMEOUT_ALERT_BUTTON_SELECTION: { |
| 98 | |
| 99 | case TIMEOUT_ALERT_BUTTON_SELECTION: |
| 100 | { |
98 | 101 | fTimeoutAlert = NULL; |
99 | 102 | // Timeout alert was invoked by user and timer still has not |
100 | 103 | // been stopped |
… |
… |
TaskTimer::Start(const char* name)
|
126 | 129 | |
127 | 130 | // Create a message runner that will send a TASK_TIMEOUT message if the |
128 | 131 | // timer is not stopped |
129 | | if (fMessageRunner == NULL) |
| 132 | if (fMessageRunner == NULL) { |
130 | 133 | fMessageRunner = new BMessageRunner(fMessenger, &fTimeoutMessage, |
131 | 134 | fTimeoutMicroSeconds, 1); |
| 135 | } |
132 | 136 | else |
133 | 137 | fMessageRunner->SetInterval(fTimeoutMicroSeconds); |
134 | 138 | } |
diff --git a/src/preferences/repositories/TaskTimer.h b/src/preferences/repositories/TaskTimer.h
index 00c0fec..6da0873 100644
a
|
b
|
public:
|
44 | 44 | void Stop(const char* name); |
45 | 45 | |
46 | 46 | private: |
| 47 | int32 _NextAlertStackCount(); |
| 48 | |
47 | 49 | int32 fTimeoutMicroSeconds; |
48 | 50 | bool fTimerIsRunning; |
49 | 51 | BString fRepositoryName; |
… |
… |
private:
|
54 | 56 | BAlert* fTimeoutAlert; |
55 | 57 | BInvoker fTimeoutAlertInvoker; |
56 | 58 | Task* fOwner; |
57 | | int32 _NextAlertStackCount(); |
58 | 59 | }; |
59 | 60 | |
60 | 61 | |
--
2.7.0
From ef5b06539529459829f19b8d2e1294af7927a2d5 Mon Sep 17 00:00:00 2001
From: Brian Hill <supernova@warpmail.net>
Date: Mon, 9 Jan 2017 18:20:31 -0500
Subject: [PATCH 2/2] Cleanup _EmptyList()
---
src/preferences/repositories/RepositoriesView.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/preferences/repositories/RepositoriesView.cpp b/src/preferences/repositories/RepositoriesView.cpp
index 4e7788e..b9ff009 100644
a
|
b
|
RepositoriesView::_GetPathIdentifier(BString urlPath)
|
560 | 560 | status_t |
561 | 561 | RepositoriesView::_EmptyList() |
562 | 562 | { |
563 | | BRow* row = fListView->RowAt((int32)0, NULL); |
564 | | while (row != NULL) { |
| 563 | BRow* row = fListView->RowAt((int32)0); |
| 564 | while (row) { |
565 | 565 | fListView->RemoveRow(row); |
566 | 566 | delete row; |
567 | | row = fListView->RowAt((int32)0, NULL); |
| 567 | row = fListView->RowAt((int32)0); |
568 | 568 | } |
569 | 569 | return B_OK; |
570 | 570 | } |