Skip to content

Commit

Permalink
Added: Multi-selection action (Remove From DB).
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltanar committed Dec 14, 2016
1 parent c00b9b7 commit 1a23c80
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 53 deletions.
28 changes: 25 additions & 3 deletions Visual Novel Database/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 3 additions & 31 deletions Visual Novel Database/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ namespace Happy_Search
/// </summary>
public partial class FormMain : Form
{


//constants / definables
#pragma warning disable 1591
public const string ClientName = "Happy Search";
public const string ClientVersion = "1.4.1";
public const string ClientVersion = "1.4.2";
public const string APIVersion = "2.25";
public const int APIMaxResults = 25;
public static readonly string MaxResultsString = "\"results\":" + APIMaxResults;
Expand Down Expand Up @@ -93,6 +91,7 @@ public FormMain()
BlacklistToggleBox.SelectedIndex = 0;
otherMethodsCB.SelectedIndex = 0;
ListByCB.SelectedIndex = 0;
multiActionBox.SelectedIndex = 0;
DontTriggerEvent = false;
replyText.Text = "";
userListReply.Text = "";
Expand Down Expand Up @@ -390,7 +389,7 @@ private void SetLoginText()
{
case VndbConnection.LogInStatus.YesWithCredentials:
loginReply.ForeColor = Color.LightGreen;
loginReply.Text = $"Logged in as {Username}.";
loginReply.Text = $"Logged in as {Username}({UserID}).";
return;
case VndbConnection.LogInStatus.Yes:
loginReply.ForeColor = Color.LightGreen;
Expand Down Expand Up @@ -1430,32 +1429,5 @@ internal enum ChangeType
}
#endregion

/// <summary>
/// Toggle between wide view (see more results) and normal view
/// </summary>
private void ToggleWideView(object sender, EventArgs e)
{
_wideView = !_wideView;
if (_wideView)
{
panel1.Visible = false;
panel2.Visible = false;
tabControl2.Visible = false;
panel3.Location = new Point(6,6);
tileOLV.Location = new Point(6,65);
tileOLV.Height += 300;
toggleViewButton.Text = "▼ Show Options ▼";
}
else
{
panel1.Visible = true;
panel2.Visible = true;
tabControl2.Visible = true;
panel3.Location = new Point(6, 306);
tileOLV.Location = new Point(6, 365);
tileOLV.Height -= 300;
toggleViewButton.Text = "▲ Hide Options ▲";
}
}
}
}
92 changes: 92 additions & 0 deletions Visual Novel Database/FormMainListFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,97 @@ private async void Search_Producer()

#region Listing

/// <summary>
/// Toggle between wide view (see more results) and normal view
/// </summary>
private void ToggleWideView(object sender, EventArgs e)
{
_wideView = !_wideView;
if (_wideView)
{
panel1.Visible = false;
panel2.Visible = false;
tabControl2.Visible = false;
panel3.Location = new Point(6, 6);
tileOLV.Location = new Point(6, 65);
tileOLV.Height += 300;
toggleViewButton.Text = "▼ Show Options ▼";
}
else
{
panel1.Visible = true;
panel2.Visible = true;
tabControl2.Visible = true;
panel3.Location = new Point(6, 306);
tileOLV.Location = new Point(6, 365);
tileOLV.Height -= 300;
toggleViewButton.Text = "▲ Hide Options ▲";
}
}

/// <summary>
/// Handle selected multi-selection action.
/// </summary>
private async void MultiActionSelect(object sender, EventArgs e)
{
if (multiActionBox.SelectedIndex < 1) return;
if (tileOLV.SelectedObjects.Count < 1)
{
WriteText(replyText, "No titles selected.");
multiActionBox.SelectedIndex = 0;
return;
}
var titles = tileOLV.SelectedObjects.Cast<ListedVN>().ToArray();
switch (multiActionBox.SelectedIndex)
{
case 1:
tileOLV.SelectedObjects = null;
break;
case 2:
string message = $"You've selected {titles.Length} titles.\nAre you sure you wish to remove them from local database?";
var messageBox = MessageBox.Show(message, "Confirm Action", MessageBoxButtons.YesNo);
if (messageBox != DialogResult.Yes)
{
multiActionBox.SelectedIndex = 0;
return;
}
WriteWarning(replyText, "Removing titles...");
await Task.Run(() => RemoveTitlesFromDB(titles));
await ReloadListsFromDbAsync();
LoadVNListToGui();
WriteText(replyText, "Titles Removed.");
break;
}
multiActionBox.SelectedIndex = 0;
}

/// <summary>
/// Remove titles and associated images from local database.
/// </summary>
/// <param name="titles">Titles to be removed</param>
private void RemoveTitlesFromDB(ListedVN[] titles)
{
foreach (var title in titles)
{
var screenItems = JsonConvert.DeserializeObject<ScreenItem[]>(title.Screens);
foreach (var screen in screenItems)
{
try
{
File.Delete(screen.StoredLocation());
}
catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException) { }
}
try
{
File.Delete($"{VNImagesFolder}\\{title.VNID}{Path.GetExtension(title.ImageURL)}");
}
catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException) { }
}
DBConn.BeginTransaction();
foreach (var title in titles) DBConn.RemoveVisualNovel(title.VNID);
DBConn.EndTransaction();
}

/// <summary>
/// Change ListBy TextBox in accordance to selected function.
Expand Down Expand Up @@ -705,6 +796,7 @@ private void Help_ListResults(object sender, EventArgs e)
/// </summary>
private void VisualNovelLeftClick(object sender, CellClickEventArgs e)
{
if (ModifierKeys.HasFlag(Keys.Control)) return;
var listView = (ObjectListView)sender;
if (listView.SelectedIndices.Count <= 0) return;
var vnItem = (ListedVN)listView.SelectedObjects[0];
Expand Down
13 changes: 7 additions & 6 deletions Visual Novel Database/ObjectListItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ public class VNTileRenderer : AbstractRenderer
private const int LinesOfTextAbovePicture = 1;
private const int LinesOfTextBelowPicture = 3;
private Pen _borderPen = new Pen(Color.FromArgb(0x33, 0x33, 0x33));
private Pen _selectedBorderPen = Pens.Gold;
private static readonly Brush TextBrush = new SolidBrush(Color.FromArgb(0x22, 0x22, 0x22));
private static readonly Font BoldFont = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold);
private static readonly Font NormalFont = new Font("Microsoft Sans Serif", 8.25f);
Expand Down Expand Up @@ -547,9 +548,7 @@ public override bool RenderItem(DrawListViewItemEventArgs e, Graphics g, Rectang
g.Clear(olv.BackColor);
g.SmoothingMode = ObjectListView.SmoothingMode;
g.TextRenderingHint = ObjectListView.TextRenderingHint;

_borderPen = e.Item.Selected ? Pens.Blue : new Pen(Color.FromArgb(0x33, 0x33, 0x33));
DrawVNTile(g, itemBounds, rowObject, olv);
DrawVNTile(g, itemBounds, rowObject, olv, e.Item.Selected);
// Finally render the buffered graphics
buffered.Render();
buffered.Dispose();
Expand All @@ -564,8 +563,9 @@ public override bool RenderItem(DrawListViewItemEventArgs e, Graphics g, Rectang
/// <param name="g">A Graphics for rendering</param>
/// <param name="itemBounds">The bounds of the item</param>
/// <param name="rowObject">The model object to be drawn</param>
/// <param name="olv">OLV where tile is drawn.</param>
public void DrawVNTile(Graphics g, Rectangle itemBounds, object rowObject, ObjectListView olv)
/// <param name="olv">OLV where tile is drawn</param>
/// <param name="isSelected">Whether tile is selected</param>
public void DrawVNTile(Graphics g, Rectangle itemBounds, object rowObject, ObjectListView olv, bool isSelected)
{
var backBrush = DefaultTileBrush;
//tile size 230,375
Expand Down Expand Up @@ -606,7 +606,8 @@ public void DrawVNTile(Graphics g, Rectangle itemBounds, object rowObject, Objec
break;
}
g.FillPath(backBrush, path);
g.DrawPath(_borderPen, path);
if (isSelected) path.Widen(_selectedBorderPen);
g.DrawPath(isSelected ? _selectedBorderPen : _borderPen, path);
g.Clip = new Region(itemBounds);

// Draw the photo
Expand Down
7 changes: 4 additions & 3 deletions Visual Novel Database/Other_Forms/LoginForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using Happy_Search.Properties;
using Microsoft.Win32;
Expand Down Expand Up @@ -127,7 +128,7 @@ private async void LoginWithPasswordButtonClick(object sender, EventArgs e)
char[] password = PasswordBox.Text.ToCharArray();
ClearSavedCredentials(null, null);
if (rememberBox.Checked) FormMain.SaveCredentials(username, password);
APILoginWithCredentials(new KeyValuePair<string, char[]>(username, password),userID);
await APILoginWithCredentials(new KeyValuePair<string, char[]>(username, password),userID);
}


Expand All @@ -136,7 +137,7 @@ private async void LoginWithPasswordButtonClick(object sender, EventArgs e)
/// </summary>
/// <param name="credentials">User's username and password</param>
/// <param name="userId">VNDB User ID</param>
private void APILoginWithCredentials(KeyValuePair<string, char[]> credentials, int userId)
private async Task APILoginWithCredentials(KeyValuePair<string, char[]> credentials, int userId)
{
if (_parentForm.Conn.Status == VndbConnection.APIStatus.Error)
{
Expand All @@ -149,7 +150,7 @@ private void APILoginWithCredentials(KeyValuePair<string, char[]> credentials, i
{
case ResponseType.Ok:
_parentForm.Username = credentials.Key;
_parentForm.UserID = userId;
if (userId < 1) _parentForm.UserID = await _parentForm.GetIDFromUsername(credentials.Key);
DialogResult = DialogResult.Yes;
return;
case ResponseType.Error:
Expand Down
3 changes: 1 addition & 2 deletions Visual Novel Database/Other_Forms/VisualNovelForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,7 @@ await Task.Run(() =>

private static int DrawImageFitToHeight(Control control, int height, int locationX, ScreenItem screenItem)
{
string[] urlSplit = screenItem.Image.Split('/');
string photoString = $"{VNScreensFolder}{urlSplit[urlSplit.Length - 2]}\\{urlSplit[urlSplit.Length - 1]}";
string photoString = screenItem.StoredLocation();
if (!File.Exists(photoString))
{
SaveScreenshot(screenItem.Image, photoString);
Expand Down
7 changes: 4 additions & 3 deletions Visual Novel Database/Program Data/Changelog and more.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Next Milestone == ??

Changelog
---------
Added: Multi-selection actions (Remove from DB)/
Fixed: Login with username and password (instead of user id and password) fixed.
Changed: Layout changes incl. Suggest Producers is now in Producer Search Window.
Added: Toggle between normal view and wide view (more results).
Fixed: SQL Handling of different number formats.
Expand Down Expand Up @@ -97,16 +99,15 @@ better vn character display?
-
allow adding titles to multiple groups via comma separation
see current groups when adding title to groups
-
add alias to database fetching, add get all alias info in other functions, add alias check for local search by name.
-
ability to remove titles from database
multi-select titles and batch functions
cancel current function



Incomplete
---------------
multi-select titles and batch functions

Completed (Feature List)
---------------
Expand Down
20 changes: 15 additions & 5 deletions Visual Novel Database/Program Data/Help/searchingandfiltering.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ <h1>Searching and Filtering</h1>
</ul>
<p>In the explanations below, all titles listed are in local database, not in VNDB, unless stated otherwise.</p>
<h2>Listing</h2>
<h3>List by Name:</h3>
<p>By clicking the Go button, list all titles that match specified name or original name (alias to be added later).<br/>
By clicking the Update button, get all titles that match specified name, original name or alias, from VNDB.</p>
<h3>List by Name:</h3>
<p>
By clicking the Go button, list all titles that match specified name or original name (alias to be added later).<br />
By clicking the Update button, get all titles that match specified name, original name or alias, from VNDB.
</p>
<h3>List by Year:</h3>
<p>By clicking the Go button, list all titles released in specified year.<br/>
By clicking the Update button, get all titles released in specified year, from VNDB.</p>
<p>
By clicking the Go button, list all titles released in specified year.<br />
By clicking the Update button, get all titles released in specified year, from VNDB.
</p>
<h3>List by Producer:</h3>
<p>By clicking the Go button, lists all titles by specified producer entered by user.</p>
<p>By clicking the Update button, get all titles by specified producer, from VNDB.</p>
Expand Down Expand Up @@ -54,5 +58,11 @@ <h3>Blacklisted</h3>
<h2>Other</h2>
<h3>View Picker</h3>
<p>Select whether to view results in tile view (default) or detailed view.</p>
<h3>Multi Actions</h3>
<p>Perform actions on all selected titles. Titles can be selected by Ctrl+clicking them and they are identified by a golden border.</p>
<ul>
<li>Deselect All - Clears selection of titles.</li>
<li>Remove From DB - Remove titles from local database, also removes associated images.</li>
</ul>
</body>
</html>
Loading

0 comments on commit 1a23c80

Please sign in to comment.