FreeRDP
Loading...
Searching...
No Matches
QuickConnectHistoryGateway.java
1/*
2 Quick connect history gateway
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.services;
12
13import com.freerdp.freerdpcore.data.HistoryDao;
14import com.freerdp.freerdpcore.data.HistoryEntity;
15import com.freerdp.freerdpcore.domain.BookmarkBase;
16
17import java.util.ArrayList;
18import java.util.List;
19
21{
22 private final HistoryDao dao;
23
24 public QuickConnectHistoryGateway(HistoryDao dao)
25 {
26 this.dao = dao;
27 }
28
29 public ArrayList<BookmarkBase> findHistory(String filter)
30 {
31 String query = (filter != null && !filter.isEmpty()) ? ("%" + filter + "%") : "%";
32 List<HistoryEntity> entities = dao.findHistory(query);
33
34 ArrayList<BookmarkBase> result = new ArrayList<>(entities.size());
35 for (HistoryEntity entity : entities)
36 {
37 BookmarkBase bookmark = new BookmarkBase();
38 bookmark.setType(BookmarkBase.TYPE_QUICKCONNECT);
39 bookmark.setLabel(entity.item);
40 bookmark.setHostname(entity.item);
41 result.add(bookmark);
42 }
43 return result;
44 }
45
46 public void addHistoryItem(String item)
47 {
48 dao.insertOrReplace(new HistoryEntity(item));
49 }
50
51 public boolean historyItemExists(String item)
52 {
53 return dao.exists(item) > 0;
54 }
55
56 public void removeHistoryItem(String hostname)
57 {
58 dao.deleteByItem(hostname);
59 }
60}